Skip to content

Commit b55de29

Browse files
committed
BasicFormat should add a space between '{' and identifier
1 parent 93e905c commit b55de29

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Sources/SwiftBasicFormat/BasicFormat.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ open class BasicFormat: SyntaxRewriter {
197197
(.keyword(.set), .leftParen), // var mYar: Int { set(value) {} }
198198
(.keyword(.subscript), .leftParen), // subscript(x: Int)
199199
(.keyword(.super), .period), // super.someProperty
200-
(.leftBrace, _),
201200
(.leftParen, _),
202201
(.leftSquareBracket, _),
203202
(.multilineStringQuote, .rawStringDelimiter), // closing raw string delimiter should never be separate by a space
@@ -246,6 +245,10 @@ open class BasicFormat: SyntaxRewriter {
246245
return false
247246
case (_, .rightAngle) where first?.tokenKind != .leftAngle: // `<` and `>` need to be separated by a space because otherwise they become an operator
248247
return false
248+
case (.leftBrace, .identifier):
249+
break
250+
case (.leftBrace, _):
251+
return false
249252
default:
250253
break
251254
}

Tests/SwiftBasicFormatTest/BasicFormatTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,19 @@ 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+
337+
assertFormatted(
338+
source: source,
339+
expected: """
340+
_ = { foo in
341+
}
342+
"""
343+
)
344+
}
330345
}

0 commit comments

Comments
 (0)