Files
Danny Mösch 40bd97038a Support arbitrary configurations in @SwiftSyntaxRule (#5275)
Almost all rules based on SwiftSyntax can be set up now by just adding
`@SwiftSyntaxRule` to the rule struct.
2023-10-16 19:34:43 +02:00

40 lines
1004 B
Swift

import SwiftSyntax
@SwiftSyntaxRule
struct FallthroughRule: OptInRule {
var configuration = SeverityConfiguration<Self>(.warning)
static let description = RuleDescription(
identifier: "fallthrough",
name: "Fallthrough",
description: "Fallthrough should be avoided",
kind: .idiomatic,
nonTriggeringExamples: [
Example("""
switch foo {
case .bar, .bar2, .bar3:
something()
}
""")
],
triggeringExamples: [
Example("""
switch foo {
case .bar:
↓fallthrough
case .bar2:
something()
}
""")
]
)
}
private extension FallthroughRule {
final class Visitor: ViolationsSyntaxVisitor<ConfigurationType> {
override func visitPost(_ node: FallThroughStmtSyntax) {
violations.append(node.positionAfterSkippingLeadingTrivia)
}
}
}