mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
43 lines
1.3 KiB
Swift
43 lines
1.3 KiB
Swift
//
|
|
// FileLengthRule.swift
|
|
// SwiftLint
|
|
//
|
|
// Created by JP Simard on 2015-05-16.
|
|
// Copyright (c) 2015 Realm. All rights reserved.
|
|
//
|
|
|
|
import SourceKittenFramework
|
|
|
|
public struct FileLengthRule: ParameterizedRule {
|
|
public init() {
|
|
self.init(parameters: [
|
|
RuleParameter(severity: .Warning, value: 400),
|
|
RuleParameter(severity: .Error, value: 1000)
|
|
])
|
|
}
|
|
|
|
public init(parameters: [RuleParameter<Int>]) {
|
|
self.parameters = parameters
|
|
}
|
|
|
|
public let parameters: [RuleParameter<Int>]
|
|
|
|
public static let description = RuleDescription(
|
|
identifier: "file_length",
|
|
name: "File Line Length",
|
|
description: "Files should not span too many lines."
|
|
)
|
|
|
|
public func validateFile(file: File) -> [StyleViolation] {
|
|
let lineCount = file.lines.count
|
|
for parameter in parameters.reverse() where lineCount > parameter.value {
|
|
return [StyleViolation(ruleDescription: self.dynamicType.description,
|
|
severity: parameter.severity,
|
|
location: Location(file: file.path, line: lineCount),
|
|
reason: "File should contain \(parameters.first!.value) lines or less: " +
|
|
"currently contains \(lineCount)")]
|
|
}
|
|
return []
|
|
}
|
|
}
|