From 43ff8407451bc8a455494189eee61d84fc6d847e Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sun, 22 Feb 2026 09:31:58 -0800 Subject: [PATCH] Fix `wrapArguments` incorrectly applied to `async` function declarations instead of `wrapParameters` (#2407) Co-authored-by: calda <1811727+calda@users.noreply.github.com> --- Sources/ParsingHelpers.swift | 3 ++- Tests/Rules/WrapArgumentsTests.swift | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) 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() {