forked from realm/SwiftLint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LineLengthRule.swift
46 lines (40 loc) · 1.45 KB
/
LineLengthRule.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// LineLengthRule.swift
// SwiftLint
//
// Created by JP Simard on 2015-05-16.
// Copyright (c) 2015 Realm. All rights reserved.
//
import SourceKittenFramework
public struct LineLengthRule: ParameterizedRule {
public init() {}
public let identifier = "line_length"
public let parameters = [
RuleParameter(severity: .VeryLow, value: 100),
RuleParameter(severity: .Low, value: 120),
RuleParameter(severity: .Medium, value: 150),
RuleParameter(severity: .High, value: 200),
RuleParameter(severity: .VeryHigh, value: 250)
]
public func validateFile(file: File) -> [StyleViolation] {
return compact(file.contents.lines().map { line in
for parameter in reverse(self.parameters) {
if count(line.content) > parameter.value {
return StyleViolation(type: .Length,
location: Location(file: file.path, line: line.index),
severity: parameter.severity,
reason: "Line should be 100 characters or less: currently " +
"\(count(line.content)) characters")
}
}
return nil
})
}
public let example = RuleExample(
ruleName: "Line Length Rule",
ruleDescription: "Lines should be less than 100 characters.",
nonTriggeringExamples: [],
triggeringExamples: [],
showExamples: false
)
}