Skip to content

Commit e085ee9

Browse files
authored
Merge pull request swiftlang#193 from dabelknap/mutating-accessors
Don't remove 'get' statements with modifiers or attributes
2 parents 3257332 + 92898da commit e085ee9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Sources/SwiftFormatRules/UseSingleLinePropertyGetter.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public final class UseSingleLinePropertyGetter: SyntaxFormatRule {
2929
let acc = accessorList.first,
3030
let body = acc.body,
3131
accessorList.count == 1,
32-
acc.accessorKind.tokenKind == .contextualKeyword("get")
32+
acc.accessorKind.tokenKind == .contextualKeyword("get"),
33+
acc.attributes == nil,
34+
acc.modifier == nil
3335
else { return node }
3436

3537
diagnose(.removeExtraneousGetBlock, on: acc)

Tests/SwiftFormatRulesTests/UseSingleLinePropertyGetterTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class UseSingleLinePropertyGetterTests: DiagnosingTestCase {
1919
get { return 0 }
2020
set { print("no set, only get") }
2121
}
22+
var j: Int {
23+
mutating get { return 0 }
24+
}
2225
""",
2326
expected: """
2427
var g: Int { return 4 }
@@ -29,6 +32,9 @@ public class UseSingleLinePropertyGetterTests: DiagnosingTestCase {
2932
get { return 0 }
3033
set { print("no set, only get") }
3134
}
35+
var j: Int {
36+
mutating get { return 0 }
37+
}
3238
""")
3339
}
3440

0 commit comments

Comments
 (0)