mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
34 lines
1.1 KiB
Swift
34 lines
1.1 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: ConfigurationProviderRule {
|
|
public var configuration = RuleLevelsConfig(warning: 400, error: 1000)
|
|
|
|
public init() {}
|
|
|
|
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 configuration.params where lineCount > parameter.value {
|
|
return [StyleViolation(ruleDescription: self.dynamicType.description,
|
|
severity: parameter.severity,
|
|
location: Location(file: file.path, line: lineCount),
|
|
reason: "File should contain \(configuration.warning.value) lines or less: " +
|
|
"currently contains \(lineCount)")]
|
|
}
|
|
return []
|
|
}
|
|
}
|