Skip to content

Commit e5875f3

Browse files
authored
Merge pull request #471 from ahoppen/ahoppen/attributes
Adjustments for merging `AttributeSyntax` and `CustomAttributeSyntax`
2 parents 32620cf + b065084 commit e5875f3

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,29 +1584,24 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
15841584

15851585
override func visit(_ node: AttributeSyntax) -> SyntaxVisitorContinueKind {
15861586
before(node.firstToken, tokens: .open)
1587-
if node.argument != nil {
1587+
switch node.argument {
1588+
case .argumentList(let argumentList)?:
1589+
if let leftParen = node.leftParen, let rightParen = node.rightParen {
1590+
arrangeFunctionCallArgumentList(
1591+
argumentList,
1592+
leftDelimiter: leftParen,
1593+
rightDelimiter: rightParen,
1594+
forcesBreakBeforeRightDelimiter: false)
1595+
}
1596+
case .some:
15881597
// Wrap the attribute's arguments in their own group, so arguments stay together with a higher
15891598
// affinity than the overall attribute (e.g. allows a break after the opening "(" and then
15901599
// having the entire argument list on 1 line). Necessary spaces and breaks are added inside of
15911600
// the argument, using type specific visitor methods.
15921601
after(node.leftParen, tokens: .break(.open, size: 0), .open(argumentListConsistency()))
15931602
before(node.rightParen, tokens: .break(.close, size: 0), .close)
1594-
}
1595-
after(node.lastToken, tokens: .close)
1596-
return .visitChildren
1597-
}
1598-
1599-
override func visit(_ node: CustomAttributeSyntax) -> SyntaxVisitorContinueKind {
1600-
// "Custom attributes" are better known to users as "property wrappers".
1601-
before(node.firstToken, tokens: .open)
1602-
if let argumentList = node.argumentList,
1603-
let leftParen = node.leftParen, let rightParen = node.rightParen
1604-
{
1605-
arrangeFunctionCallArgumentList(
1606-
argumentList,
1607-
leftDelimiter: leftParen,
1608-
rightDelimiter: rightParen,
1609-
forcesBreakBeforeRightDelimiter: false)
1603+
case nil:
1604+
break
16101605
}
16111606
after(node.lastToken, tokens: .close)
16121607
return .visitChildren

Sources/SwiftFormatRules/NeverUseImplicitlyUnwrappedOptionals.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public final class NeverUseImplicitlyUnwrappedOptionals: SyntaxLintRule {
4242
// Ignores IBOutlet variables
4343
if let attributes = node.attributes {
4444
for attribute in attributes {
45-
if (attribute.as(AttributeSyntax.self))?.attributeName.text == "IBOutlet" {
45+
if (attribute.as(AttributeSyntax.self))?.attributeName.as(SimpleTypeIdentifierSyntax.self)?.name.text == "IBOutlet" {
4646
return .skipChildren
4747
}
4848
}

Tests/SwiftFormatPrettyPrintTests/AttributeTests.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,6 @@ final class AttributeTests: PrettyPrintTestCase {
316316
}
317317

318318
func testPropertyWrappers() {
319-
// Property wrappers are `CustomAttributeSyntax` nodes (not `AttributeSyntax`) and their
320-
// arguments are `TupleExprElementListSyntax` (like regular function call argument lists), so
321-
// make sure that those are formatted properly.
322319
let input =
323320
"""
324321
struct X {

0 commit comments

Comments
 (0)