Skip to content

Commit 6656208

Browse files
committed
Fix spacing for * operator
1 parent cf78077 commit 6656208

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

CodeGeneration/Sources/generate-swiftbasicformat/BasicFormatFile.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ let basicFormatFile = SourceFile {
128128
(.rightAngle, .identifier(_)),
129129
(.rightAngle, .postfixQuestionMark):
130130
return false
131+
case (.spacedBinaryOperator(let `operator`), .leftParen):
132+
return `operator` != "*"
131133
default:
132134
break
133135
}
@@ -155,10 +157,13 @@ let basicFormatFile = SourceFile {
155157
(.initKeyword, .leftParen),
156158
(.initKeyword, .postfixQuestionMark),
157159
(.leftAngle, .identifier(_)),
160+
(.rightAngle, .leftParen),
158161
(.rightAngle, .postfixQuestionMark),
159162
(.tryKeyword, .exclamationMark),
160163
(.tryKeyword, .postfixQuestionMark):
161164
return false
165+
case (.spacedBinaryOperator(let `operator`), .comma):
166+
return `operator` != "*"
162167
default:
163168
break
164169
}

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ open class BasicFormat: SyntaxRewriter {
129129
(.rightAngle, .identifier(_ )),
130130
(.rightAngle, .postfixQuestionMark):
131131
return false
132+
case (.spacedBinaryOperator(let `operator`), .leftParen):
133+
return `operator` != "*"
132134
default:
133135
break
134136
}
@@ -161,10 +163,13 @@ open class BasicFormat: SyntaxRewriter {
161163
(.initKeyword, .leftParen),
162164
(.initKeyword, .postfixQuestionMark),
163165
(.leftAngle, .identifier(_ )),
166+
(.rightAngle, .leftParen),
164167
(.rightAngle, .postfixQuestionMark),
165168
(.tryKeyword, .exclamationMark),
166169
(.tryKeyword, .postfixQuestionMark):
167170
return false
171+
case (.spacedBinaryOperator(let `operator`), .comma):
172+
return `operator` != "*"
168173
default:
169174
break
170175
}

Tests/SwiftSyntaxBuilderTest/FunctionTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ final class FunctionTests: XCTestCase {
3737
)
3838
}
3939

40+
func testFunctionDeclEnsurePropperSpacing() {
41+
let buildable = FunctionDecl(
42+
"""
43+
@available(*, deprecated, message: "Use function on Baz")
44+
private func visitChildren<SyntaxType: SyntaxProtocol>(_ node: SyntaxType) {
45+
}
46+
"""
47+
)
48+
49+
AssertBuildResult(
50+
buildable,
51+
"""
52+
@available(*, deprecated, message: "Use function on Baz")
53+
private func visitChildren<SyntaxType: SyntaxProtocol>(_ node: SyntaxType) {
54+
}
55+
"""
56+
)
57+
}
58+
4059
func testArguments() {
4160
let buildable = FunctionCallExpr(callee: ExprSyntax("test")) {
4261
for param in (1...5) {

0 commit comments

Comments
 (0)