Skip to content

Commit 2b4af9b

Browse files
committed
Fix trailing whitespace after some function decls.
1 parent aeec597 commit 2b4af9b

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,11 @@ private final class TokenStreamCreator: SyntaxVisitor {
835835
node.genericWhereClause?.firstToken,
836836
tokens: .break, .open(.inconsistent, 0), .break(size: 0), .open(.consistent, 0)
837837
)
838-
after(node.genericWhereClause?.lastToken, tokens: .break, .close, .close)
838+
if node.body != nil {
839+
after(node.genericWhereClause?.lastToken, tokens: .break, .close, .close)
840+
} else {
841+
after(node.genericWhereClause?.lastToken, tokens: .close, .close)
842+
}
839843

840844
if let body = node.body {
841845
if node.genericWhereClause == nil {

Tests/SwiftFormatPrettyPrintTests/FunctionDeclTests.swift

+30
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,36 @@ public class FunctionDeclTests: PrettyPrintTestCase {
301301
assertPrettyPrintEqual(input: input, expected: expected, linelength: 50)
302302
}
303303

304+
public func testBodilessFunctionDecl() {
305+
let input =
306+
"""
307+
func myFun()
308+
309+
func myFun(arg1: Int)
310+
311+
func myFun() -> Int
312+
313+
func myFun<T>(arg1: Int)
314+
315+
func myFun<T>(arg1: Int) where T: S
316+
"""
317+
318+
let expected =
319+
"""
320+
func myFun()
321+
322+
func myFun(arg1: Int)
323+
324+
func myFun() -> Int
325+
326+
func myFun<T>(arg1: Int)
327+
328+
func myFun<T>(arg1: Int) where T: S
329+
330+
"""
331+
332+
assertPrettyPrintEqual(input: input, expected: expected, linelength: 50)
333+
}
304334

305335
public func testFunctionFullWrap() {
306336
let input =

0 commit comments

Comments
 (0)