mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
38 lines
1.1 KiB
Swift
38 lines
1.1 KiB
Swift
import SourceKittenFramework
|
|
|
|
public struct FallthroughRule: ConfigurationProviderRule, OptInRule, AutomaticTestableRule {
|
|
|
|
public var configuration = SeverityConfiguration(.warning)
|
|
|
|
public init() {}
|
|
|
|
public static let description = RuleDescription(
|
|
identifier: "fallthrough",
|
|
name: "Fallthrough",
|
|
description: "Fallthrough should be avoided.",
|
|
kind: .idiomatic,
|
|
nonTriggeringExamples: [
|
|
"switch foo {\n" +
|
|
"case .bar, .bar2, .bar3:\n" +
|
|
" something()\n" +
|
|
"}"
|
|
],
|
|
triggeringExamples: [
|
|
"switch foo {\n" +
|
|
"case .bar:\n" +
|
|
" ↓fallthrough\n" +
|
|
"case .bar2:\n" +
|
|
" something()\n" +
|
|
"}"
|
|
]
|
|
)
|
|
|
|
public func validate(file: File) -> [StyleViolation] {
|
|
return file.match(pattern: "fallthrough", with: [.keyword]).map {
|
|
StyleViolation(ruleDescription: type(of: self).description,
|
|
severity: configuration.severity,
|
|
location: Location(file: file, characterOffset: $0.location))
|
|
}
|
|
}
|
|
}
|