@@ -11,27 +11,27 @@ import SwiftSyntax
1111///
1212/// - SeeAlso: https://google.github.io/swift#naming-conventions-are-not-access-control
1313public final class NoLeadingUnderscores : SyntaxLintRule {
14-
14+
1515 public override func visit( _ node: AssociatedtypeDeclSyntax ) {
1616 diagnoseUnderscoreViolation ( name: node. identifier)
1717 }
18-
18+
1919 public override func visit( _ node: ClassDeclSyntax ) {
2020 diagnoseUnderscoreViolation ( name: node. identifier)
2121 super. visit ( node) // Visit children despite override
2222 }
23-
23+
2424 public override func visit( _ node: EnumDeclSyntax ) {
2525 diagnoseUnderscoreViolation ( name: node. identifier)
2626 super. visit ( node)
2727 }
28-
28+
2929 public override func visit( _ node: EnumCaseDeclSyntax ) {
3030 for element in node. elements {
3131 diagnoseUnderscoreViolation ( name: element. identifier)
3232 }
3333 }
34-
34+
3535 public override func visit( _ node: FunctionDeclSyntax ) {
3636 diagnoseUnderscoreViolation ( name: node. identifier)
3737 // Check parameter names of function
@@ -52,16 +52,16 @@ public final class NoLeadingUnderscores: SyntaxLintRule {
5252 }
5353 super. visit ( node)
5454 }
55-
55+
5656 public override func visit( _ node: PrecedenceGroupDeclSyntax ) {
5757 diagnoseUnderscoreViolation ( name: node. identifier)
5858 }
59-
59+
6060 public override func visit( _ node: ProtocolDeclSyntax ) {
6161 diagnoseUnderscoreViolation ( name: node. identifier)
6262 super. visit ( node)
6363 }
64-
64+
6565 public override func visit( _ node: StructDeclSyntax ) {
6666 diagnoseUnderscoreViolation ( name: node. identifier)
6767 // Check generic parameter names
@@ -72,11 +72,11 @@ public final class NoLeadingUnderscores: SyntaxLintRule {
7272 }
7373 super. visit ( node)
7474 }
75-
75+
7676 public override func visit( _ node: TypealiasDeclSyntax ) {
7777 diagnoseUnderscoreViolation ( name: node. identifier)
7878 }
79-
79+
8080 public override func visit( _ node: InitializerDeclSyntax ) {
8181 // Check parameter names of initializer
8282 let parameters = node. parameters. parameterList
@@ -90,26 +90,23 @@ public final class NoLeadingUnderscores: SyntaxLintRule {
9090 }
9191 super. visit ( node)
9292 }
93-
93+
9494 public override func visit( _ node: VariableDeclSyntax ) {
95- for binding in node. bindings {
96- if let pat = binding. pattern as? IdentifierPatternSyntax {
97- diagnoseUnderscoreViolation ( name: pat. identifier)
98- }
95+ for id in node. identifiers {
96+ diagnoseUnderscoreViolation ( name: id. identifier)
9997 }
10098 super. visit ( node)
10199 }
102-
100+
103101 func diagnoseUnderscoreViolation( name: TokenSyntax ) {
104102 let leadingChar = name. text. first
105- if leadingChar == " _ " {
106- diagnose ( . doNotLeadWithUnderscore( identifier: name. text) , on: name)
107- }
103+ guard leadingChar == " _ " else { return }
104+ diagnose ( . doNotLeadWithUnderscore( identifier: name. text) , on: name)
108105 }
109106}
110107
111108extension Diagnostic . Message {
112109 static func doNotLeadWithUnderscore( identifier: String ) -> Diagnostic . Message {
113- return . init( . warning, " Identifier \( identifier) should not lead with '_' " )
110+ return . init( . warning, " identifier \( identifier) should not lead with '_' " )
114111 }
115112}
0 commit comments