Skip to content

Commit 9a3623b

Browse files
committed
Fix colon followed by right paren spacing
1 parent 1b5fe6b commit 9a3623b

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/ExprNodes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public let EXPR_NODES: [Node] = [
9595
Child(name: "Name",
9696
kind: .node(kind: "Token")),
9797
Child(name: "Colon",
98-
kind: .token(choices: [.token(tokenKind: "ColonToken")]))
98+
kind: .token(choices: [.token(tokenKind: "ColonToken")], requiresTrailingSpace: false))
9999
]),
100100

101101
Node(name: "DeclNameArgumentList",

CodeGeneration/Sources/generate-swiftsyntax/templates/basicformat/BasicFormatFile.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,15 @@ let basicFormatFile = SourceFileSyntax {
246246
StmtSyntax(
247247
"""
248248
switch (token.tokenKind, token.nextToken(viewMode: .sourceAccurate)?.tokenKind) {
249-
case (.keyword(.as), .exclamationMark), // Ensures there is not space in `as!`
250-
(.keyword(.as), .postfixQuestionMark), // Ensures there is not space in `as?`
251-
(.exclamationMark, .leftParen), // Ensures there is not space in `myOptionalClosure!()`
249+
case (.exclamationMark, .leftParen), // Ensures there is not space in `myOptionalClosure!()`
252250
(.exclamationMark, .period), // Ensures there is not space in `myOptionalBar!.foo()`
251+
(.keyword(.as), .exclamationMark), // Ensures there is not space in `as!`
252+
(.keyword(.as), .postfixQuestionMark), // Ensures there is not space in `as?`
253+
(.keyword(.try), .exclamationMark), // Ensures there is not space in `try!`
254+
(.keyword(.try), .postfixQuestionMark), // Ensures there is not space in `try?`:
253255
(.postfixQuestionMark, .leftParen), // Ensures there is not space in `init?()` or `myOptionalClosure?()`s
254256
(.postfixQuestionMark, .rightAngle), // Ensures there is not space in `ContiguousArray<RawSyntax?>`
255-
(.postfixQuestionMark, .rightParen), // Ensures there is not space in `myOptionalClosure?()`
256-
(.keyword(.try), .exclamationMark), // Ensures there is not space in `try!`
257-
(.keyword(.try), .postfixQuestionMark): // Ensures there is not space in `try?`:
257+
(.postfixQuestionMark, .rightParen): // Ensures there is not space in `myOptionalClosure?()`
258258
return false
259259
default:
260260
break

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ open class BasicFormat: SyntaxRewriter {
178178
switch keyPath {
179179
case \AvailabilityArgumentSyntax.entry:
180180
return false
181+
case \DeclNameArgumentSyntax.colon:
182+
return false
181183
case \DictionaryExprSyntax.content:
182184
return false
183185
case \DynamicReplacementArgumentsSyntax.forLabel:
@@ -194,15 +196,15 @@ open class BasicFormat: SyntaxRewriter {
194196
return requiresTrailingSpace
195197
}
196198
switch (token.tokenKind, token.nextToken(viewMode: .sourceAccurate)?.tokenKind) {
197-
case (.keyword(.as), .exclamationMark), // Ensures there is not space in `as!`
198-
(.keyword(.as), .postfixQuestionMark), // Ensures there is not space in `as?`
199-
(.exclamationMark, .leftParen), // Ensures there is not space in `myOptionalClosure!()`
199+
case (.exclamationMark, .leftParen), // Ensures there is not space in `myOptionalClosure!()`
200200
(.exclamationMark, .period), // Ensures there is not space in `myOptionalBar!.foo()`
201+
(.keyword(.as), .exclamationMark), // Ensures there is not space in `as!`
202+
(.keyword(.as), .postfixQuestionMark), // Ensures there is not space in `as?`
203+
(.keyword(.try), .exclamationMark), // Ensures there is not space in `try!`
204+
(.keyword(.try), .postfixQuestionMark), // Ensures there is not space in `try?`:
201205
(.postfixQuestionMark, .leftParen), // Ensures there is not space in `init?()` or `myOptionalClosure?()`s
202206
(.postfixQuestionMark, .rightAngle), // Ensures there is not space in `ContiguousArray<RawSyntax?>`
203-
(.postfixQuestionMark, .rightParen), // Ensures there is not space in `myOptionalClosure?()`
204-
(.keyword(.try), .exclamationMark), // Ensures there is not space in `try!`
205-
(.keyword(.try), .postfixQuestionMark): // Ensures there is not space in `try?`:
207+
(.postfixQuestionMark, .rightParen): // Ensures there is not space in `myOptionalClosure?()`
206208
return false
207209
default:
208210
break

Tests/SwiftSyntaxBuilderTest/VariableTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ final class VariableTests: XCTestCase {
8989
let bar = try! !functionThatThrows()
9090
"""
9191
),
92+
#line: (
93+
DeclSyntax("var bar: Foo { bar.map(Foo.init(raw:)) }"),
94+
"""
95+
var bar: Foo {
96+
bar.map(Foo.init(raw:))
97+
}
98+
"""
99+
),
100+
#line: (
101+
DeclSyntax("var bar: Foo { bar.map(Foo.init(raw:otherParam:)) }"),
102+
"""
103+
var bar: Foo {
104+
bar.map(Foo.init(raw:otherParam:))
105+
}
106+
"""
107+
),
92108
]
93109

94110
for (line, testCase) in testCases {

gyb_syntax_support/ExprNodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
Node('DeclNameArgument', name_for_diagnostics=None, kind='Syntax',
7272
children=[
7373
Child('Name', kind='Token'),
74-
Child('Colon', kind='ColonToken'),
74+
Child('Colon', kind='ColonToken', requires_trailing_space=False),
7575
]),
7676
Node('DeclNameArgumentList', name_for_diagnostics=None, kind='SyntaxCollection',
7777
element='DeclNameArgument'),

0 commit comments

Comments
 (0)