File tree 2 files changed +42
-0
lines changed
Sources/SwiftFormat/PrettyPrint
Tests/SwiftFormatTests/PrettyPrint
2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -479,6 +479,9 @@ public class PrettyPrinter {
479
479
}
480
480
}
481
481
outputBuffer. write ( comment. print ( indent: currentIndentation) )
482
+ if wasEndOfLine, ( comment. kind == . line || comment. kind == . docLine) {
483
+ outputBuffer. writeNewlines ( . hard, shouldIndentBlankLines: configuration. indentBlankLines)
484
+ }
482
485
483
486
case . verbatim( let verbatim) :
484
487
outputBuffer. writeVerbatim ( verbatim. print ( indent: currentIndentation) , length)
Original file line number Diff line number Diff line change @@ -1107,4 +1107,43 @@ final class CommentTests: PrettyPrintTestCase {
1107
1107
1108
1108
assertPrettyPrintEqual ( input: input, expected: input, linelength: 80 )
1109
1109
}
1110
+
1111
+ func testCommentWithAttributes( ) {
1112
+ let input =
1113
+ """
1114
+ @foo // comment
1115
+ @bar
1116
+ import Baz
1117
+
1118
+ """
1119
+ let expected =
1120
+ """
1121
+ @foo // comment
1122
+ @bar import Baz
1123
+
1124
+ """
1125
+
1126
+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 80 )
1127
+ }
1128
+
1129
+ func testLineAndBlockCommentsWithAttributes( ) {
1130
+ let input =
1131
+ """
1132
+ @foo // comment
1133
+ @bar /* comment */
1134
+ @zoo // comment
1135
+ import Baz
1136
+
1137
+ """
1138
+ let expected =
1139
+ """
1140
+ @foo // comment
1141
+ @bar /* comment */ @zoo // comment
1142
+ import Baz
1143
+
1144
+ """
1145
+
1146
+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 80 )
1147
+ }
1148
+
1110
1149
}
You can’t perform that action at this time.
0 commit comments