Skip to content

Commit 12aa1c4

Browse files
committed
Keep attributed getters intact in UseSingleLinePropertyGetter
1 parent 83d46d6 commit 12aa1c4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Sources/SwiftFormat/Rules/UseSingleLinePropertyGetter.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public final class UseSingleLinePropertyGetter: SyntaxFormatRule {
2828
let body = acc.body,
2929
accessors.count == 1,
3030
acc.accessorSpecifier.tokenKind == .keyword(.get),
31+
acc.attributes.isEmpty,
3132
acc.modifier == nil,
3233
acc.effectSpecifiers == nil
3334
else { return node }

Tests/SwiftFormatTests/Rules/UseSingleLinePropertyGetterTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,30 @@ final class UseSingleLinePropertyGetterTests: LintOrFormatRuleTestCase {
253253
]
254254
)
255255
}
256+
257+
func testGetterWithAttributedAccessorShouldBePreserved() {
258+
assertFormatting(
259+
UseSingleLinePropertyGetter.self,
260+
input: """
261+
struct Foo {
262+
var value: Int {
263+
@_lifetime(borrow self)
264+
get {
265+
return 1
266+
}
267+
}
268+
}
269+
""",
270+
expected: """
271+
struct Foo {
272+
var value: Int {
273+
@_lifetime(borrow self)
274+
get {
275+
return 1
276+
}
277+
}
278+
}
279+
"""
280+
)
281+
}
256282
}

0 commit comments

Comments
 (0)