Skip to content

Commit 53eae80

Browse files
authored
Merge pull request #774 from bnbarham/cherry-fixed-do-typed-throws
[6.0] Add a break after `do` when it has typed throws
2 parents 4b62459 + d6a9a7a commit 53eae80

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift

+3
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,9 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
707707
}
708708

709709
override func visit(_ node: DoStmtSyntax) -> SyntaxVisitorContinueKind {
710+
if node.throwsClause != nil {
711+
after(node.doKeyword, tokens: .break(.same, size: 1))
712+
}
710713
arrangeBracesAndContents(of: node.body, contentsKeyPath: \.statements)
711714
return .visitChildren
712715
}

Tests/SwiftFormatTests/PrettyPrint/DoStmtTests.swift

+25
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,30 @@ final class DoStmtTests: PrettyPrintTestCase {
5757
"""
5858
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45)
5959
}
60+
61+
func testDoTypedThrowsStmt() {
62+
let input =
63+
"""
64+
do throws(FooError) {
65+
foo()
66+
}
67+
"""
68+
69+
assertPrettyPrintEqual(input: input, expected:
70+
"""
71+
do
72+
throws(FooError) {
73+
foo()
74+
}
75+
76+
""", linelength: 18)
77+
assertPrettyPrintEqual(input: input, expected:
78+
"""
79+
do throws(FooError) {
80+
foo()
81+
}
82+
83+
""", linelength: 25)
84+
}
6085
}
6186

0 commit comments

Comments
 (0)