Fix wrapArguments incorrectly applied to async function declarations instead of wrapParameters (#2407)

Co-authored-by: calda <1811727+calda@users.noreply.github.com>
This commit is contained in:
Copilot
2026-02-26 09:17:43 +00:00
committed by Nick Lockwood
co-authored by calda
parent af019a2004
commit 43ff840745
2 changed files with 26 additions and 1 deletions
+2 -1
View File
@@ -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
}
+24
View File
@@ -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() {