Skip to content

Commit

Permalink
Merge pull request #279 from cbjeukendrup/UseSingleLinePropertyGetter…
Browse files Browse the repository at this point in the history
…_not_with_async_throws

UseSingleLinePropertyGetter: respect `async` and `throws` on getters
  • Loading branch information
allevato committed Mar 18, 2022
1 parent f646a1f commit 55fc4e2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/SwiftFormatRules/UseSingleLinePropertyGetter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public final class UseSingleLinePropertyGetter: SyntaxFormatRule {
accessorBlock.accessors.count == 1,
acc.accessorKind.tokenKind == .contextualKeyword("get"),
acc.attributes == nil,
acc.modifier == nil
acc.modifier == nil,
acc.asyncKeyword == nil,
acc.throwsKeyword == nil
else { return Syntax(node) }

diagnose(.removeExtraneousGetBlock, on: acc)
Expand Down
30 changes: 30 additions & 0 deletions Tests/SwiftFormatRulesTests/UseSingleLinePropertyGetterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ final class UseSingleLinePropertyGetterTests: LintOrFormatRuleTestCase {
var j: Int {
mutating get { return 0 }
}
var k: Int {
get async {
return 4
}
}
var l: Int {
get throws {
return 4
}
}
var m: Int {
get async throws {
return 4
}
}
""",
expected: """
var g: Int { return 4 }
Expand All @@ -31,6 +46,21 @@ final class UseSingleLinePropertyGetterTests: LintOrFormatRuleTestCase {
var j: Int {
mutating get { return 0 }
}
var k: Int {
get async {
return 4
}
}
var l: Int {
get throws {
return 4
}
}
var m: Int {
get async throws {
return 4
}
}
""")
}
}

0 comments on commit 55fc4e2

Please sign in to comment.