Skip to content

Commit 1e9b89b

Browse files
committed
Format discard statements.
1 parent 71cedaa commit 1e9b89b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,13 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
25112511
return .visitChildren
25122512
}
25132513

2514+
override func visit(_ node: DiscardStmtSyntax) -> SyntaxVisitorContinueKind {
2515+
// The `discard` keyword cannot be separated from the following token or it will be parsed as
2516+
// an identifier.
2517+
after(node.discardKeyword, tokens: .space)
2518+
return .visitChildren
2519+
}
2520+
25142521
override func visit(_ node: InheritanceClauseSyntax) -> SyntaxVisitorContinueKind {
25152522
// Normally, the open-break is placed before the open token. In this case, it's intentionally
25162523
// ordered differently so that the inheritance list can start on the current line and only
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
final class DiscardStmtTests: PrettyPrintTestCase {
2+
func testDiscard() {
3+
assertPrettyPrintEqual(
4+
input: """
5+
discard self
6+
""",
7+
expected: """
8+
discard self
9+
10+
""",
11+
linelength: 9)
12+
}
13+
}

0 commit comments

Comments
 (0)