diff --git a/Sources/ParsingHelpers.swift b/Sources/ParsingHelpers.swift index 83fec559..0c8e5594 100644 --- a/Sources/ParsingHelpers.swift +++ b/Sources/ParsingHelpers.swift @@ -1421,7 +1421,8 @@ extension Formatter { return last(.nonSpaceOrLinebreak, before: i) != .keyword("for") case .identifier("async"): if let nextToken = next(.nonSpaceOrCommentOrLinebreak, after: nextIndex), - [.operator("->", .infix), .keyword("throws"), .keyword("rethrows")].contains(nextToken) + [.operator("->", .infix), .keyword("throws"), .keyword("rethrows"), + .startOfScope("{")].contains(nextToken) { return true } diff --git a/Tests/Rules/WrapArgumentsTests.swift b/Tests/Rules/WrapArgumentsTests.swift index c7b7be36..f7d57158 100644 --- a/Tests/Rules/WrapArgumentsTests.swift +++ b/Tests/Rules/WrapArgumentsTests.swift @@ -1156,6 +1156,30 @@ final class WrapArgumentsTests: XCTestCase { testFormatting(for: input, rule: .wrapArguments, options: options) } + func testWrapArgumentsDoesNotAffectAsyncFunctionDeclaration() { + let input = """ + func foo( + bar _: Int, + baz _: String + ) async {} + """ + let options = FormatOptions(wrapArguments: .afterFirst, wrapParameters: .preserve) + testFormatting(for: input, rule: .wrapArguments, options: options) + } + + func testWrapParametersUsedForAsyncFunctionDeclaration() { + let input = """ + func testAsync(first: String, + second: String, + third: String) async { + debugPrint("") + } + """ + let options = FormatOptions(wrapArguments: .beforeFirst, wrapParameters: .afterFirst) + testFormatting(for: input, rule: .wrapArguments, options: options, + exclude: [.unusedArguments, .wrapMultilineStatementBraces]) + } + // MARK: afterFirst func testWrapArgumentsConvertBeforeFirstToAfterFirst() {