Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,9 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
}

override func visit(_ node: DoStmtSyntax) -> SyntaxVisitorContinueKind {
if node.throwsClause != nil {
after(node.doKeyword, tokens: .break(.same, size: 1))
}
arrangeBracesAndContents(of: node.body, contentsKeyPath: \.statements)
return .visitChildren
}
Expand Down
25 changes: 25 additions & 0 deletions Tests/SwiftFormatTests/PrettyPrint/DoStmtTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,30 @@ final class DoStmtTests: PrettyPrintTestCase {
"""
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45)
}

func testDoTypedThrowsStmt() {
let input =
"""
do throws(FooError) {
foo()
}
"""

assertPrettyPrintEqual(input: input, expected:
"""
do
throws(FooError) {
foo()
}

""", linelength: 18)
assertPrettyPrintEqual(input: input, expected:
"""
do throws(FooError) {
foo()
}

""", linelength: 25)
}
}