-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathForceTryRule.swift
36 lines (30 loc) · 1.01 KB
/
ForceTryRule.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
//
// ForceTryRule.swift
// SwiftLint
//
// Created by JP Simard on 2015-11-17.
// Copyright (c) 2015 Realm. All rights reserved.
//
import SourceKittenFramework
public struct ForceTryRule: ConfigurationProviderRule {
public var configuration = SeverityConfiguration(.Error)
public init() {}
public static let description = RuleDescription(
identifier: "force_try",
name: "Force Try",
description: "Force tries should be avoided.",
nonTriggeringExamples: [
"func a() throws {}; do { try a() } catch {}"
],
triggeringExamples: [
"func a() throws {}; ↓try! a()"
]
)
public func validateFile(file: File) -> [StyleViolation] {
return file.matchPattern("try!", withSyntaxKinds: [.Keyword]).map {
StyleViolation(ruleDescription: self.dynamicType.description,
severity: configuration.severity,
location: Location(file: file, characterOffset: $0.location))
}
}
}