Skip to content

Commit 77f33ff

Browse files
authored
Merge pull request swiftlang#24 from allevato/sr-11205
Do not indent the trailing line comment in a member decl list as a continuation.
2 parents 75bffbb + aeaec3e commit 77f33ff

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,12 @@ private final class TokenStreamCreator: SyntaxVisitor {
838838
}
839839

840840
func visit(_ node: MemberDeclListSyntax) -> SyntaxVisitorContinueKind {
841-
insertTokens(.break(.reset, size: 0), .newline, betweenElementsOf: node)
841+
return .visitChildren
842+
}
843+
844+
func visit(_ node: MemberDeclListItemSyntax) -> SyntaxVisitorContinueKind {
845+
before(node.firstToken, tokens: .open)
846+
after(node.lastToken, tokens: .close, .break(.reset, size: 0))
842847
return .visitChildren
843848
}
844849

Tests/SwiftFormatPrettyPrintTests/CommentTests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,35 @@ public class CommentTests: PrettyPrintTestCase {
435435
// comment
436436
&& false
437437
}
438+
439+
struct Foo {
440+
typealias Bar
441+
// comment
442+
= SomeOtherType
443+
}
438444
"""
439445

440446
assertPrettyPrintEqual(input: input, expected: input + "\n", linelength: 60)
441447
}
448+
449+
public func testLineCommentAtEndOfMemberDeclList() {
450+
let input =
451+
"""
452+
enum Foo {
453+
case bar
454+
// This should be indented the same as the previous line
455+
}
456+
"""
457+
458+
let expected =
459+
"""
460+
enum Foo {
461+
case bar
462+
// This should be indented the same as the previous line
463+
}
464+
465+
"""
466+
467+
assertPrettyPrintEqual(input: input, expected: expected, linelength: 100)
468+
}
442469
}

Tests/SwiftFormatPrettyPrintTests/XCTestManifests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ extension CommentTests {
108108
("testDocumentationBlockComments", testDocumentationBlockComments),
109109
("testDocumentationComments", testDocumentationComments),
110110
("testDoesNotInsertExtraNewlinesAfterTrailingComments", testDoesNotInsertExtraNewlinesAfterTrailingComments),
111+
("testLineCommentAtEndOfMemberDeclList", testLineCommentAtEndOfMemberDeclList),
111112
("testLineComments", testLineComments),
112113
]
113114
}

0 commit comments

Comments
 (0)