diff --git a/Sources/FormattingHelpers.swift b/Sources/FormattingHelpers.swift index 28a34e5a..f8c78bcd 100644 --- a/Sources/FormattingHelpers.swift +++ b/Sources/FormattingHelpers.swift @@ -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, diff --git a/Tests/RulesTests+Hoisting.swift b/Tests/RulesTests+Hoisting.swift index 11163729..6e4b4575 100644 --- a/Tests/RulesTests+Hoisting.swift +++ b/Tests/RulesTests+Hoisting.swift @@ -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,