Skip to content

Commit b96ea09

Browse files
committed
Fix spacings around !and ?
1 parent 8e6ae6e commit b96ea09

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,14 @@ let basicFormatFile = SourceFile {
157157
switch (token.tokenKind, token.nextToken(viewMode: .sourceAccurate)?.tokenKind) {
158158
case (.asKeyword, .exclamationMark), // Ensures there is not space in `as!`
159159
(.asKeyword, .postfixQuestionMark), // Ensures there is not space in `as?`
160+
(.exclamationMark, .comma), // Ensures there is not space in `raw: raw!, otherValue: value`
160161
(.exclamationMark, .leftParen), // Ensures there is not space in `myOptionalClosure!()`
161162
(.exclamationMark, .period), // Ensures there is not space in `myOptionalBar!.foo()`
162163
(.initKeyword, .leftParen), // Ensures there is not space in `init()`
163164
(.initKeyword, .postfixQuestionMark), // Ensures there is not space in `init?`
165+
(.postfixQuestionMark, .comma), // Ensures there is not space in `(raw: String?, otherValue: String)`
164166
(.postfixQuestionMark, .leftParen), // Ensures there is not space in `init?()`
167+
(.postfixQuestionMark, .period), // Ensures there is not space in `someOptional?.foo`
165168
(.postfixQuestionMark, .rightAngle), // Ensures there is not space in `ContiguousArray<RawSyntax?>`
166169
(.postfixQuestionMark, .rightParen), // Ensures there is not space in `myOptionalClosure?()`
167170
(.tryKeyword, .exclamationMark), // Ensures there is not space in `try!`

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,14 @@ open class BasicFormat: SyntaxRewriter {
170170
switch (token.tokenKind, token.nextToken(viewMode: .sourceAccurate)?.tokenKind) {
171171
case (.asKeyword, .exclamationMark), // Ensures there is not space in `as!`
172172
(.asKeyword, .postfixQuestionMark), // Ensures there is not space in `as?`
173+
(.exclamationMark, .comma), // Ensures there is not space in `raw: raw!, otherValue: value`
173174
(.exclamationMark, .leftParen), // Ensures there is not space in `myOptionalClosure!()`
174175
(.exclamationMark, .period), // Ensures there is not space in `myOptionalBar!.foo()`
175176
(.initKeyword, .leftParen), // Ensures there is not space in `init()`
176177
(.initKeyword, .postfixQuestionMark), // Ensures there is not space in `init?`
178+
(.postfixQuestionMark, .comma), // Ensures there is not space in `(raw: String?, otherValue: String)`
177179
(.postfixQuestionMark, .leftParen), // Ensures there is not space in `init?()`
180+
(.postfixQuestionMark, .period), // Ensures there is not space in `someOptional?.foo`
178181
(.postfixQuestionMark, .rightAngle), // Ensures there is not space in `ContiguousArray<RawSyntax?>`
179182
(.postfixQuestionMark, .rightParen), // Ensures there is not space in `myOptionalClosure?()`
180183
(.tryKeyword, .exclamationMark), // Ensures there is not space in `try!`

Tests/SwiftSyntaxBuilderTest/FunctionTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ final class FunctionTests: XCTestCase {
151151
}
152152
"""
153153
),
154+
#line: (
155+
FunctionDecl(
156+
"""
157+
public func foo(myOptionalValue: String?, myOtherOptionalValue: String?) {
158+
}
159+
"""
160+
),
161+
"""
162+
public func foo(myOptionalValue: String?, myOtherOptionalValue: String?) {
163+
}
164+
"""
165+
),
154166
#line: (
155167
FunctionDeclSyntax(
156168
modifiers: [DeclModifier(name: .public), DeclModifier(name: .static)],

Tests/SwiftSyntaxBuilderTest/VariableTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ final class VariableTests: XCTestCase {
4747
}
4848
"""
4949
),
50+
#line: (
51+
VariableDecl("var foo: String? { myOptional?.someProperty }"),
52+
"""
53+
var foo: String? {
54+
myOptional?.someProperty
55+
}
56+
"""
57+
),
58+
#line: (
59+
VariableDecl("let absoluteRaw = AbsoluteRawSyntax(raw: raw!, info: info)"),
60+
"""
61+
let absoluteRaw = AbsoluteRawSyntax(raw: raw!, info: info)
62+
"""
63+
),
5064
]
5165

5266
for (line, testCase) in testCases {

0 commit comments

Comments
 (0)