forked from realm/SwiftLint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LeadingWhitespaceRule.swift
37 lines (32 loc) · 1.18 KB
/
LeadingWhitespaceRule.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
//
// LeadingWhitespaceRule.swift
// SwiftLint
//
// Created by JP Simard on 2015-05-16.
// Copyright (c) 2015 Realm. All rights reserved.
//
import SourceKittenFramework
public struct LeadingWhitespaceRule: Rule {
public init() {}
public let identifier = "leading_whitespace"
public func validateFile(file: File) -> [StyleViolation] {
let countOfLeadingWhitespace = file.contents.countOfLeadingCharactersInSet(
NSCharacterSet.whitespaceAndNewlineCharacterSet()
)
if countOfLeadingWhitespace != 0 {
return [StyleViolation(type: .LeadingWhitespace,
location: Location(file: file.path, line: 1),
severity: .Medium,
reason: "File shouldn't start with whitespace: " +
"currently starts with \(countOfLeadingWhitespace) whitespace characters")]
}
return []
}
public let example = RuleExample(
ruleName: "Leading Whitespace Rule",
ruleDescription: "This rule checks that there's no leading whitespace in your file.",
nonTriggeringExamples: [ "//\n" ],
triggeringExamples: [ "\n", " //\n" ],
showExamples: false
)
}