Skip to content

Commit

Permalink
Merge pull request #691 from fwcd/fwcd/var-decl-attr-trailing-trivia
Browse files Browse the repository at this point in the history
Add trailing space to attributes in `VariableDecl`
  • Loading branch information
fwcd authored Sep 2, 2022
2 parents ce5be96 + ef4af42 commit cb71972
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ extension VariableDecl {
) {
self.init(
leadingTrivia: leadingTrivia,
attributes: attributes,
attributes: attributes?.createAttributeList().withTrailingTrivia(.space),
modifiers: modifiers,
letOrVarKeyword: attributes != nil ? letOrVarKeyword.withLeadingTrivia(.space) : letOrVarKeyword
letOrVarKeyword: letOrVarKeyword
) {
PatternBinding(
pattern: name,
Expand All @@ -48,9 +48,9 @@ extension VariableDecl {
) {
self.init(
leadingTrivia: leadingTrivia,
attributes: attributes,
attributes: attributes?.createAttributeList().withTrailingTrivia(.space),
modifiers: modifiers,
letOrVarKeyword: .var.withLeadingTrivia(attributes != nil ? .space : .zero)
letOrVarKeyword: .var
) {
PatternBinding(
pattern: name,
Expand Down
14 changes: 14 additions & 0 deletions Tests/SwiftSyntaxBuilderTest/VariableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ final class VariableTests: XCTestCase {
}
"""
),
#line: (
VariableDecl(
attributes: CustomAttribute("WithArgs") {
TupleExprElement(expression: "value")
},
modifiers: [Token.public],
.let,
name: "z",
type: "Float"
),
"""
@WithArgs(value) public let z: Float
"""
),
]

for (line, testCase) in testCases {
Expand Down

0 comments on commit cb71972

Please sign in to comment.