mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-06-16 10:34:34 +00:00
Fix bug in hoistAwait rule
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user