Skip to content

Commit cb71972

Browse files
authored
Merge pull request #691 from fwcd/fwcd/var-decl-attr-trailing-trivia
Add trailing space to attributes in `VariableDecl`
2 parents ce5be96 + ef4af42 commit cb71972

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Sources/SwiftSyntaxBuilder/ConvenienceInitializers/VariableDeclConvenienceInitializers.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ extension VariableDecl {
2525
) {
2626
self.init(
2727
leadingTrivia: leadingTrivia,
28-
attributes: attributes,
28+
attributes: attributes?.createAttributeList().withTrailingTrivia(.space),
2929
modifiers: modifiers,
30-
letOrVarKeyword: attributes != nil ? letOrVarKeyword.withLeadingTrivia(.space) : letOrVarKeyword
30+
letOrVarKeyword: letOrVarKeyword
3131
) {
3232
PatternBinding(
3333
pattern: name,
@@ -48,9 +48,9 @@ extension VariableDecl {
4848
) {
4949
self.init(
5050
leadingTrivia: leadingTrivia,
51-
attributes: attributes,
51+
attributes: attributes?.createAttributeList().withTrailingTrivia(.space),
5252
modifiers: modifiers,
53-
letOrVarKeyword: .var.withLeadingTrivia(attributes != nil ? .space : .zero)
53+
letOrVarKeyword: .var
5454
) {
5555
PatternBinding(
5656
pattern: name,

Tests/SwiftSyntaxBuilderTest/VariableTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ final class VariableTests: XCTestCase {
150150
}
151151
"""
152152
),
153+
#line: (
154+
VariableDecl(
155+
attributes: CustomAttribute("WithArgs") {
156+
TupleExprElement(expression: "value")
157+
},
158+
modifiers: [Token.public],
159+
.let,
160+
name: "z",
161+
type: "Float"
162+
),
163+
"""
164+
@WithArgs(value) public let z: Float
165+
"""
166+
),
153167
]
154168

155169
for (line, testCase) in testCases {

0 commit comments

Comments
 (0)