forked from realm/SwiftLint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ForceCastRule.swift
34 lines (29 loc) · 983 Bytes
/
ForceCastRule.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
//
// ForceCastRule.swift
// SwiftLint
//
// Created by JP Simard on 2015-05-16.
// Copyright (c) 2015 Realm. All rights reserved.
//
import SourceKittenFramework
public struct ForceCastRule: Rule {
public init() {}
public let identifier = "force_cast"
public func validateFile(file: File) -> [StyleViolation] {
return file.matchPattern("as!", withSyntaxKinds: [.Keyword]).map { range in
return StyleViolation(type: .ForceCast,
location: Location(file: file, offset: range.location),
severity: .High,
reason: "Force casts should be avoided")
}
}
public let example = RuleExample(
ruleName: "Force Cast Rule",
ruleDescription: "This rule checks whether you don't do force casts.",
nonTriggeringExamples: [
"NSNumber() as? Int\n",
"// NSNumber() as! Int\n",
],
triggeringExamples: [ "NSNumber() as! Int\n" ]
)
}