diff --git a/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift b/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift index 966ccc399..d371892d8 100644 --- a/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift +++ b/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift @@ -2385,6 +2385,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor { } override func visit(_ node: AttributedTypeSyntax) -> SyntaxVisitorContinueKind { + before(node.firstToken(viewMode: .sourceAccurate), tokens: .open) arrangeAttributeList(node.attributes) for specifier in node.specifiers { after( @@ -2392,6 +2393,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor { tokens: .break(.continue, newlines: .elective(ignoresDiscretionary: true)) ) } + after(node.lastToken(viewMode: .sourceAccurate), tokens: .close) return .visitChildren } diff --git a/Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift b/Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift index 4419d6f05..73950b917 100644 --- a/Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift +++ b/Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift @@ -623,4 +623,25 @@ final class AttributeTests: PrettyPrintTestCase { assertPrettyPrintEqual(input: input, expected: expected, linelength: 45) } + + func testAttributeLineBreakInInheritanceClause() { + let input = + """ + public class MyClass: Foo, @unchecked Sendable, Bar { + // … + } + + """ + let expected = + """ + public class MyClass: Foo, + @unchecked Sendable, Bar + { + // … + } + + """ + + assertPrettyPrintEqual(input: input, expected: expected, linelength: 45) + } } diff --git a/Tests/SwiftFormatTests/PrettyPrint/FunctionDeclTests.swift b/Tests/SwiftFormatTests/PrettyPrint/FunctionDeclTests.swift index 08935ab19..1bfa566f1 100644 --- a/Tests/SwiftFormatTests/PrettyPrint/FunctionDeclTests.swift +++ b/Tests/SwiftFormatTests/PrettyPrint/FunctionDeclTests.swift @@ -1129,8 +1129,8 @@ final class FunctionDeclTests: PrettyPrintTestCase { .InnerMember, ) {} func foo( - cmp: @escaping (R) -> - () + cmp: + @escaping (R) -> () ) {} func foo( cmp: