Fix bug in hoistAwait rule

This commit is contained in:
Nick Lockwood
2024-01-31 08:33:28 +00:00
parent 402367fbe9
commit 6498522350
2 changed files with 9 additions and 0 deletions
+2
View File
@@ -1058,6 +1058,8 @@ extension Formatter {
if [.startOfScope("("), .startOfScope("[")].contains(prevToken), isEffectCapturingAt(i) {
return
}
case .keyword("try") where keyword == "await":
break loop
case let .keyword(name) where ["is", "as", "try", "await"].contains(name):
break
case .operator(_, .prefix), .stringBody,
+7
View File
@@ -562,6 +562,13 @@ class HoistingTests: RulesTests {
options: FormatOptions(swiftVersion: "5.5"))
}
func testNoHoistAwaitBeforeTry() {
let input = "try foo(await bar())"
let output = "try await foo(bar())"
testFormatting(for: input, output, rule: FormatRules.hoistAwait,
options: FormatOptions(swiftVersion: "5.5"))
}
func testNoHoistAwaitInCapturingFunction() {
let input = "foo(await bar)"
testFormatting(for: input, rule: FormatRules.hoistAwait,