File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Tests/SwiftFormatRulesTests Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -66,15 +66,34 @@ public final class UseEnumForNamespacing: SyntaxFormatRule {
66
66
name: TokenSyntax ,
67
67
members: MemberDeclBlockSyntax
68
68
) -> EnumDeclSyntax {
69
+ // Since we remove the "final" modifier, we need to preserve its trivia if it is the first
70
+ // modifier.
71
+ var newLeadingTrivia : Trivia ? = nil
72
+ if let firstMod = modifiers? . first, firstMod. name. text == " final " {
73
+ newLeadingTrivia = firstMod. leadingTrivia
74
+ }
75
+
69
76
let newModifiers = modifiers? . remove ( name: " final " )
70
- return EnumDeclSyntax {
77
+
78
+ let outputEnum = EnumDeclSyntax {
71
79
if let mods = newModifiers {
72
80
for mod in mods { $0. addModifier ( mod) }
73
81
}
74
82
$0. useEnumKeyword ( declarationKeyword. withKind ( . enumKeyword) )
75
83
$0. useIdentifier ( name)
76
84
$0. useMembers ( members)
77
85
}
86
+
87
+ if let trivia = newLeadingTrivia {
88
+ return replaceTrivia (
89
+ on: outputEnum,
90
+ token: outputEnum. firstToken,
91
+ leadingTrivia: trivia
92
+ ) as! EnumDeclSyntax
93
+ }
94
+ else {
95
+ return outputEnum
96
+ }
78
97
}
79
98
80
99
/// Determines if the set of declarations is consistent with a class or struct being used
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ public class UseEnumForNamespacingTests: DiagnosingTestCase {
24
24
public final class D {
25
25
static func bar()
26
26
}
27
+ final class E {
28
+ static let a = 123
29
+ }
27
30
""" ,
28
31
expected: """
29
32
enum A {
@@ -40,6 +43,9 @@ public class UseEnumForNamespacingTests: DiagnosingTestCase {
40
43
public enum D {
41
44
static func bar()
42
45
}
46
+ enum E {
47
+ static let a = 123
48
+ }
43
49
""" )
44
50
}
45
51
}
You can’t perform that action at this time.
0 commit comments