Skip to content

Commit 6603bd6

Browse files
authored
Merge pull request #775 from shawnhyam/improve-macro-decl-formatting
Improve formatting of macro decls with attributes.
2 parents ae1ef61 + 38d8e10 commit 6603bd6

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,12 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
13271327
}
13281328

13291329
override func visit(_ node: MacroExpansionDeclSyntax) -> SyntaxVisitorContinueKind {
1330+
arrangeAttributeList(node.attributes)
1331+
1332+
before(
1333+
node.trailingClosure?.leftBrace,
1334+
tokens: .break(.same, newlines: .elective(ignoresDiscretionary: true)))
1335+
13301336
arrangeFunctionCallArgumentList(
13311337
node.arguments,
13321338
leftDelimiter: node.leftParen,

Tests/SwiftFormatTests/PrettyPrint/MacroCallTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,16 @@ final class MacroCallTests: PrettyPrintTestCase {
114114

115115
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45)
116116
}
117+
118+
func testMacroDeclWithAttributesAndArguments() {
119+
let input = """
120+
@nonsenseAttribute
121+
@available(iOS 17.0, *)
122+
#Preview("Name") {
123+
EmptyView()
124+
}
125+
126+
"""
127+
assertPrettyPrintEqual(input: input, expected: input, linelength: 45)
128+
}
117129
}

0 commit comments

Comments
 (0)