diff --git a/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift b/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift index 8e7dc617b..a697c0e38 100644 --- a/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift +++ b/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift @@ -1327,6 +1327,12 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor { } override func visit(_ node: MacroExpansionDeclSyntax) -> SyntaxVisitorContinueKind { + arrangeAttributeList(node.attributes) + + before( + node.trailingClosure?.leftBrace, + tokens: .break(.same, newlines: .elective(ignoresDiscretionary: true))) + arrangeFunctionCallArgumentList( node.arguments, leftDelimiter: node.leftParen, diff --git a/Tests/SwiftFormatTests/PrettyPrint/MacroCallTests.swift b/Tests/SwiftFormatTests/PrettyPrint/MacroCallTests.swift index dffbef001..0616c66e3 100644 --- a/Tests/SwiftFormatTests/PrettyPrint/MacroCallTests.swift +++ b/Tests/SwiftFormatTests/PrettyPrint/MacroCallTests.swift @@ -114,4 +114,16 @@ final class MacroCallTests: PrettyPrintTestCase { assertPrettyPrintEqual(input: input, expected: expected, linelength: 45) } + + func testMacroDeclWithAttributesAndArguments() { + let input = """ + @nonsenseAttribute + @available(iOS 17.0, *) + #Preview("Name") { + EmptyView() + } + + """ + assertPrettyPrintEqual(input: input, expected: input, linelength: 45) + } }