Skip to content

Commit 6b77fa9

Browse files
committed
Fix line breaking for attributes in inheritance clauses by grouping them with their type
1 parent e70ab31 commit 6b77fa9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,9 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
23572357
}
23582358

23592359
override func visit(_ node: InheritedTypeSyntax) -> SyntaxVisitorContinueKind {
2360+
before(node.firstToken(viewMode: .sourceAccurate), tokens: .open)
23602361
after(node.trailingComma, tokens: .break(.same))
2362+
after(node.lastToken(viewMode: .sourceAccurate), tokens: .close)
23612363
return .visitChildren
23622364
}
23632365

Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,4 +623,25 @@ final class AttributeTests: PrettyPrintTestCase {
623623

624624
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45)
625625
}
626+
627+
func testAttributeLineBreakInInheritanceClause() {
628+
let input =
629+
"""
630+
public class MyClass: Foo, @unchecked Sendable, Bar {
631+
// …
632+
}
633+
634+
"""
635+
let expected =
636+
"""
637+
public class MyClass: Foo,
638+
@unchecked Sendable, Bar
639+
{
640+
// …
641+
}
642+
643+
"""
644+
645+
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45)
646+
}
626647
}

0 commit comments

Comments
 (0)