Skip to content

Commit 71cedaa

Browse files
committed
Format consume expressions.
1 parent 1ade941 commit 71cedaa

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,6 +2504,13 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
25042504
return .visitChildren
25052505
}
25062506

2507+
override func visit(_ node: ConsumeExprSyntax) -> SyntaxVisitorContinueKind {
2508+
// The `consume` keyword cannot be separated from the following token or it will be parsed as
2509+
// an identifier.
2510+
after(node.consumeKeyword, tokens: .space)
2511+
return .visitChildren
2512+
}
2513+
25072514
override func visit(_ node: InheritanceClauseSyntax) -> SyntaxVisitorContinueKind {
25082515
// Normally, the open-break is placed before the open token. In this case, it's intentionally
25092516
// ordered differently so that the inheritance list can start on the current line and only
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
final class ConsumeExprTests: PrettyPrintTestCase {
2+
func testConsume() {
3+
assertPrettyPrintEqual(
4+
input: """
5+
let x = consume y
6+
""",
7+
expected: """
8+
let x =
9+
consume y
10+
11+
""",
12+
linelength: 16)
13+
}
14+
}

0 commit comments

Comments
 (0)