Skip to content

Commit 2ce90d3

Browse files
authored
Merge pull request #408 from allevato/closure-attrs
Ensure there is a break between closure attributes and a capture list.
2 parents ffb4aca + 26cc2ea commit 2ce90d3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,8 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
11031103
override func visit(_ node: ClosureSignatureSyntax) -> SyntaxVisitorContinueKind {
11041104
before(node.firstToken, tokens: .open)
11051105

1106-
arrangeAttributeList(node.attributes, suppressFinalBreak: node.input == nil)
1106+
arrangeAttributeList(
1107+
node.attributes, suppressFinalBreak: node.input == nil && node.capture == nil)
11071108

11081109
if let input = node.input {
11091110
// We unconditionally put a break before the `in` keyword below, so we should only put a break

Tests/SwiftFormatPrettyPrintTests/ClosureExprTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ final class ClosureExprTests: PrettyPrintTestCase {
492492
let b = { @MainActor in print("hello world") }
493493
let c = { @MainActor param in print("hi") }
494494
let d = { @MainActor (a: Int) async -> Int in print("hi") }
495+
let e = { @MainActor [weak self] in print("hi") }
495496
"""
496497

497498
let expected =
@@ -507,6 +508,9 @@ final class ClosureExprTests: PrettyPrintTestCase {
507508
@MainActor (a: Int) async -> Int in
508509
print("hi")
509510
}
511+
let e = { @MainActor [weak self] in
512+
print("hi")
513+
}
510514
511515
"""
512516

0 commit comments

Comments
 (0)