@@ -13,8 +13,8 @@ import SwiftSyntax
1313///
1414/// - SeeAlso: https://google.github.io/swift#enum-cases
1515public final class FullyIndirectEnum : SyntaxFormatRule {
16- public override func visit( _ node: EnumDeclSyntax ) -> DeclSyntax {
1716
17+ public override func visit( _ node: EnumDeclSyntax ) -> DeclSyntax {
1818 let enumMembers = node. members. members
1919 guard allAreIndirectCases ( members: enumMembers) else { return node }
2020 diagnose ( . reassignIndirectKeyword( name: node. identifier. text) , on: node. identifier)
@@ -25,7 +25,7 @@ public final class FullyIndirectEnum: SyntaxFormatRule {
2525 if let caseMember = member. decl as? EnumCaseDeclSyntax {
2626 guard let caseModifiers = caseMember. modifiers else { continue }
2727 guard let firstModifier = caseModifiers. first else { continue }
28- let newCase = caseMember. withModifiers ( removeIndirectModifier ( curModifiers : caseModifiers ) )
28+ let newCase = caseMember. withModifiers ( caseModifiers . remove ( name : " indirect " ) )
2929 let formattedCase = formatCase ( unformattedCase: newCase,
3030 leadingTrivia: firstModifier. leadingTrivia)
3131 let newMember = SyntaxFactory . makeMemberDeclListItem ( decl: formattedCase, semicolon: nil )
@@ -65,28 +65,13 @@ public final class FullyIndirectEnum: SyntaxFormatRule {
6565 for member in members {
6666 if let caseMember = member. decl as? EnumCaseDeclSyntax {
6767 guard let caseModifiers = caseMember. modifiers else { return false }
68- if isIndirectCase ( modifiers : caseModifiers ) { continue }
68+ if caseModifiers . has ( modifier : " indirect " ) { continue }
6969 else { return false }
7070 }
7171 }
7272 return true
7373 }
7474
75- func isIndirectCase( modifiers: ModifierListSyntax ) -> Bool {
76- for modifier in modifiers {
77- if modifier. name. tokenKind == . identifier( " indirect " ) { return true }
78- }
79- return false
80- }
81-
82- func removeIndirectModifier( curModifiers: ModifierListSyntax ) -> ModifierListSyntax {
83- var newMods : [ DeclModifierSyntax ] = [ ]
84- for modifier in curModifiers {
85- if modifier. name. tokenKind != . identifier( " indirect " ) { newMods. append ( modifier) }
86- }
87- return SyntaxFactory . makeModifierList ( newMods)
88- }
89-
9075 // Transfers given leading trivia to the first token in the case declaration
9176 func formatCase( unformattedCase: EnumCaseDeclSyntax ,
9277 leadingTrivia: Trivia ? ) -> EnumCaseDeclSyntax {
0 commit comments