Skip to content

Commit

Permalink
Merge pull request #781 from ahoppen/6.0/improve-macro-decl-formatting
Browse files Browse the repository at this point in the history
[6.0] Improve formatting of macro decls with attributes
  • Loading branch information
ahoppen committed Jul 26, 2024
2 parents 53eae80 + 53a2680 commit 50884c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions Tests/SwiftFormatTests/PrettyPrint/MacroCallTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 50884c3

Please sign in to comment.