File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Sources/SwiftFormat/PrettyPrint
Tests/SwiftFormatTests/PrettyPrint Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -67,9 +67,9 @@ struct Comment {
6767
6868 switch kind {
6969 case .line, .docLine:
70+ self.length = text.count
7071 self.text = [text]
7172 self.text[0].removeFirst(kind.prefixLength)
72- self.length = self.text.reduce(0, { $0 + $1.count + kind.prefixLength + 1 })
7373
7474 case .block, .docBlock:
7575 var fulltext: String = text
Original file line number Diff line number Diff line change @@ -1009,6 +1009,29 @@ final class CommentTests: PrettyPrintTestCase {
10091009 )
10101010 }
10111011
1012+ // Tests that "end of line" comments are flagged only when they exceed the configured line length.
1013+ func testDiagnoseMoveEndOfLineCommentAroundBoundary( ) {
1014+ assertPrettyPrintEqual (
1015+ input: """
1016+ x // 789
1017+ x // 7890
1018+ x 1️⃣// 78901
1019+
1020+ """ ,
1021+ expected: """
1022+ x // 789
1023+ x // 7890
1024+ x // 78901
1025+
1026+ """ ,
1027+ linelength: 10 ,
1028+ whitespaceOnly: true ,
1029+ findings: [
1030+ FindingSpec ( " 1️⃣ " , message: " move end-of-line comment that exceeds the line length " )
1031+ ]
1032+ )
1033+ }
1034+
10121035 func testLineWithDocLineComment( ) {
10131036 // none of these should be merged if/when there is comment formatting
10141037 let input =
You can’t perform that action at this time.
0 commit comments