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
2 changes: 1 addition & 1 deletion Sources/SwiftFormat/PrettyPrint/Comment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ struct Comment {

switch kind {
case .line, .docLine:
self.length = text.count
self.text = [text]
self.text[0].removeFirst(kind.prefixLength)
self.length = self.text.reduce(0, { $0 + $1.count + kind.prefixLength + 1 })

case .block, .docBlock:
var fulltext: String = text
Expand Down
23 changes: 23 additions & 0 deletions Tests/SwiftFormatTests/PrettyPrint/CommentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,29 @@ final class CommentTests: PrettyPrintTestCase {
)
}

// Tests that "end of line" comments are flagged only when they exceed the configured line length.
func testDiagnoseMoveEndOfLineCommentAroundBoundary() {
assertPrettyPrintEqual(
input: """
x // 789
x // 7890
x 1️⃣// 78901

""",
expected: """
x // 789
x // 7890
x // 78901

""",
linelength: 10,
whitespaceOnly: true,
findings: [
FindingSpec("1️⃣", message: "move end-of-line comment that exceeds the line length")
]
)
}

func testLineWithDocLineComment() {
// none of these should be merged if/when there is comment formatting
let input =
Expand Down
Loading