Skip to content

Commit 53ef343

Browse files
authored
Merge pull request swiftlang#202 from google/format-tweaks-fix-blank-lines-after-comments
Fix extra blank lines after trailing comments in member decl blocks.
2 parents 28801b4 + feeec26 commit 53ef343

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ private final class TokenStreamCreator: SyntaxVisitor {
811811
// reason.
812812
if node.members.count > 1 {
813813
for i in 0..<(node.members.count - 1) {
814-
after(node.members[i].lastToken, tokens: .newline)
814+
after(node.members[i].lastToken, tokens: .break(size: maxlinelength))
815815
}
816816
}
817817
super.visit(node)

Tests/SwiftFormatPrettyPrintTests/CommentTests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,39 @@ public class CommentTests: PrettyPrintTestCase {
384384

385385
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45)
386386
}
387+
388+
public func testDoesNotInsertExtraNewlinesAfterTrailingComments() {
389+
let input =
390+
"""
391+
struct Foo {
392+
var foo: Int // foo
393+
var bar: Int // bar
394+
}
395+
396+
enum Foo {
397+
case foo
398+
case bar // bar
399+
case baz // baz
400+
case quux
401+
}
402+
"""
403+
404+
let expected =
405+
"""
406+
struct Foo {
407+
var foo: Int // foo
408+
var bar: Int // bar
409+
}
410+
411+
enum Foo {
412+
case foo
413+
case bar // bar
414+
case baz // baz
415+
case quux
416+
}
417+
418+
"""
419+
420+
assertPrettyPrintEqual(input: input, expected: expected, linelength: 100)
421+
}
387422
}

0 commit comments

Comments
 (0)