Skip to content

Commit 03c22c1

Browse files
committed
BasicFormat should add spacing around { and }
We now properly strip trailing whitespace. Add in spacing after `{` and before `}`.
1 parent 36f24a8 commit 03c22c1

File tree

7 files changed

+21
-8
lines changed

7 files changed

+21
-8
lines changed

Sources/SwiftBasicFormat/BasicFormat.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ open class BasicFormat: SyntaxRewriter {
213213
(.keyword(.set), .leftParen), // var mYar: Int { set(value) {} }
214214
(.keyword(.subscript), .leftParen), // subscript(x: Int)
215215
(.keyword(.super), .period), // super.someProperty
216-
(.leftBrace, _),
216+
(.leftBrace, .rightBrace), // {}
217217
(.leftParen, _),
218218
(.leftSquareBracket, _),
219219
(.multilineStringQuote, .rawStringDelimiter), // closing raw string delimiter should never be separate by a space
@@ -245,7 +245,6 @@ open class BasicFormat: SyntaxRewriter {
245245
(_, .exclamationMark),
246246
(_, .postfixOperator),
247247
(_, .postfixQuestionMark),
248-
(_, .rightBrace),
249248
(_, .rightParen),
250249
(_, .rightSquareBracket),
251250
(_, .semicolon),

Tests/SwiftBasicFormatTest/BasicFormatTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,18 @@ final class BasicFormatTest: XCTestCase {
327327
using: BasicFormat(indentationWidth: .spaces(2))
328328
)
329329
}
330+
331+
func testClosureExprParam() {
332+
let source = """
333+
_ = {foo in}
334+
"""
335+
336+
assertFormatted(
337+
source: source,
338+
expected: """
339+
_ = { foo in
340+
}
341+
"""
342+
)
343+
}
330344
}

Tests/SwiftParserTest/ExpressionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,7 @@ final class StatementExpressionTests: XCTestCase {
18971897
],
18981898
fixedSource: #"""
18991899
"""
1900-
\({(<#expression#>)})
1900+
\({(<#expression#>) })
19011901
"""
19021902
"""#
19031903
)

Tests/SwiftParserTest/translated/ForeachAsyncTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ final class ForeachAsyncTests: XCTestCase {
138138
fixedSource: """
139139
func for_each(r: AsyncRange<Int>, iir: AsyncIntRange<Int>) async {
140140
var sum = 0
141-
for await i in r {sum = sum + i;
141+
for await i in r { sum = sum + i;
142142
}
143143
}
144144
"""

Tests/SwiftParserTest/translated/ForeachTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ final class ForeachTests: XCTestCase {
102102
fixedSource: """
103103
func for_each(r: Range<Int>, iir: IntRange<Int>) {
104104
var sum = 0
105-
for i in r {sum = sum + i;
105+
for i in r { sum = sum + i;
106106
}
107107
}
108108
"""

Tests/SwiftParserTest/translated/RecoveryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2348,7 +2348,7 @@ final class RecoveryTests: XCTestCase {
23482348
),
23492349
],
23502350
fixedSource: """
2351-
func F() { init< >()} )}
2351+
func F() { init< >() } )}
23522352
struct InitializerWithName {
23532353
init() {}
23542354
}

Tests/SwiftSyntaxBuilderTest/ClosureExprTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class ClosureExprTests: XCTestCase {
2929
assertBuildResult(
3030
buildable,
3131
"""
32-
{area in
32+
{ area in
3333
}
3434
"""
3535
)
@@ -52,7 +52,7 @@ final class ClosureExprTests: XCTestCase {
5252
assertBuildResult(
5353
buildable,
5454
"""
55-
{area async throws in
55+
{ area async throws in
5656
}
5757
"""
5858
)

0 commit comments

Comments
 (0)