mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-06-16 10:34:34 +00:00
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:
committed by
Nick Lockwood
co-authored by
calda
parent
af019a2004
commit
43ff840745
@@ -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
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user