File tree Expand file tree Collapse file tree 3 files changed +29
-6
lines changed Expand file tree Collapse file tree 3 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -144,13 +144,13 @@ fn format_trailing_comments<'a>(
144144 if source_text. contains_newline_between ( start, comment. span . start ) {
145145 return & comments[ ..index] ;
146146 }
147- // If this comment is a line comment, then it is a end of line comment, so we stop here and return the comments with this comment
148- else if comment. is_line ( ) {
147+ // If this comment is a line comment or an end of line comment, so we stop here and return the comments with this comment
148+ else if comment. is_line ( ) || source_text . is_end_of_line_comment ( comment ) {
149149 return & comments[ ..=index] ;
150150 }
151151 // Store the index of the comment before the operator, if no line comment or no new line is found, then return all comments before operator
152152 else if source_text. bytes_contain ( start, comment. span . start , operator) {
153- index_before_operator = Some ( index + 1 ) ;
153+ index_before_operator = Some ( index) ;
154154 }
155155
156156 // Update the start position for the next iteration
@@ -161,9 +161,7 @@ fn format_trailing_comments<'a>(
161161 } ;
162162
163163 let comments = get_comments ( f) ;
164- FormatTrailingComments :: Comments ( comments) . fmt ( f) ?;
165-
166- Ok ( ( ) )
164+ FormatTrailingComments :: Comments ( comments) . fmt ( f)
167165}
168166
169167impl < ' a > FormatConditionalLike < ' a , ' _ > {
Original file line number Diff line number Diff line change 1+ test /* comment1 */ ? /* comment2 */ consequent /* comment3 */ : /* comment4 */ alternative
2+
3+ test
4+ /* comment1 */ ? /* comment2 */ consequent
5+ /* comment3 */ : /* comment4 */ alternative
Original file line number Diff line number Diff line change 1+ -- -
2+ source : crates / oxc_formatter / tests / fixtures / mod .rs
3+ -- -
4+ ==================== Input ====================
5+ test /* comment1 */ ? /* comment2 */ consequent /* comment3 */ : /* comment4 */ alternative
6+
7+ test
8+ /* comment1 */ ? /* comment2 */ consequent
9+ /* comment3 */ : /* comment4 */ alternative
10+
11+ ==================== Output ====================
12+ test /* comment1 */
13+ ? /* comment2 */ consequent /* comment3 */
14+ : /* comment4 */ alternative ;
15+
16+ test
17+ ? /* comment1 */ /* comment2 */ consequent
18+ : /* comment3 */ /* comment4 */ alternative ;
19+
20+ ===================== End =====================
You can’t perform that action at this time.
0 commit comments