Skip to content

Commit a5779a2

Browse files
authored
Merge pull request #279 from cbjeukendrup/UseSingleLinePropertyGetter_not_with_async_throws
UseSingleLinePropertyGetter: respect `async` and `throws` on getters
2 parents f327c64 + 4a39e00 commit a5779a2

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Sources/SwiftFormatRules/UseSingleLinePropertyGetter.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public final class UseSingleLinePropertyGetter: SyntaxFormatRule {
2828
accessorBlock.accessors.count == 1,
2929
acc.accessorKind.tokenKind == .contextualKeyword("get"),
3030
acc.attributes == nil,
31-
acc.modifier == nil
31+
acc.modifier == nil,
32+
acc.asyncKeyword == nil,
33+
acc.throwsKeyword == nil
3234
else { return Syntax(node) }
3335

3436
diagnose(.removeExtraneousGetBlock, on: acc)

Tests/SwiftFormatRulesTests/UseSingleLinePropertyGetterTests.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ final class UseSingleLinePropertyGetterTests: LintOrFormatRuleTestCase {
1818
var j: Int {
1919
mutating get { return 0 }
2020
}
21+
var k: Int {
22+
get async {
23+
return 4
24+
}
25+
}
26+
var l: Int {
27+
get throws {
28+
return 4
29+
}
30+
}
31+
var m: Int {
32+
get async throws {
33+
return 4
34+
}
35+
}
2136
""",
2237
expected: """
2338
var g: Int { return 4 }
@@ -31,6 +46,21 @@ final class UseSingleLinePropertyGetterTests: LintOrFormatRuleTestCase {
3146
var j: Int {
3247
mutating get { return 0 }
3348
}
49+
var k: Int {
50+
get async {
51+
return 4
52+
}
53+
}
54+
var l: Int {
55+
get throws {
56+
return 4
57+
}
58+
}
59+
var m: Int {
60+
get async throws {
61+
return 4
62+
}
63+
}
3464
""")
3565
}
3666
}

0 commit comments

Comments
 (0)