1
+ use std:: string:: String ;
2
+
1
3
use dprint_core:: formatting:: PrintItems ;
2
4
use jrsonnet_rowan_parser:: { nodes:: TriviaKind , AstToken } ;
3
5
@@ -12,6 +14,7 @@ pub enum CommentLocation {
12
14
EndOfItems ,
13
15
}
14
16
17
+ #[ allow( clippy:: too_many_lines, clippy:: cognitive_complexity) ]
15
18
pub fn format_comments ( comments : & ChildTrivia , loc : CommentLocation , out : & mut PrintItems ) {
16
19
for c in comments {
17
20
let Ok ( c) = c else {
@@ -62,14 +65,14 @@ pub fn format_comments(comments: &ChildTrivia, loc: CommentLocation, out: &mut P
62
65
}
63
66
} )
64
67
. collect :: < Vec < _ > > ( ) ;
65
- while lines. last ( ) . map ( |l| l . is_empty ( ) ) . unwrap_or ( false ) {
68
+ while lines. last ( ) . is_some_and ( String :: is_empty) {
66
69
lines. pop ( ) ;
67
70
}
68
71
if lines. len ( ) == 1 && !doc {
69
72
if matches ! ( loc, CommentLocation :: ItemInline ) {
70
73
p ! ( out, str ( " " ) ) ;
71
74
}
72
- p ! ( out, str ( "/* " ) string( lines[ 0 ] . trim( ) . to_string( ) ) str ( " */" ) nl)
75
+ p ! ( out, str ( "/* " ) string( lines[ 0 ] . trim( ) . to_string( ) ) str ( " */" ) nl) ;
73
76
} else if !lines. is_empty ( ) {
74
77
fn common_ws_prefix < ' a > ( a : & ' a str , b : & str ) -> & ' a str {
75
78
let offset = a
@@ -95,7 +98,7 @@ pub fn format_comments(comments: &ChildTrivia, loc: CommentLocation, out: &mut P
95
98
}
96
99
for line in lines
97
100
. iter_mut ( )
98
- . skip ( if immediate_start { 1 } else { 0 } )
101
+ . skip ( usize :: from ( immediate_start) )
99
102
. filter ( |l| !l. is_empty ( ) )
100
103
{
101
104
* line = line
@@ -127,13 +130,13 @@ pub fn format_comments(comments: &ChildTrivia, loc: CommentLocation, out: &mut P
127
130
}
128
131
line = new_line. to_string ( ) ;
129
132
}
130
- p ! ( out, string( line. to_string( ) ) nl)
133
+ p ! ( out, string( line. to_string( ) ) nl) ;
131
134
}
132
135
}
133
136
if doc {
134
137
p ! ( out, str ( " " ) ) ;
135
138
}
136
- p ! ( out, str ( "*/" ) nl)
139
+ p ! ( out, str ( "*/" ) nl) ;
137
140
}
138
141
}
139
142
// TODO: Keep common padding for multiple continous lines of single-line comments
@@ -154,20 +157,20 @@ pub fn format_comments(comments: &ChildTrivia, loc: CommentLocation, out: &mut P
154
157
// ```
155
158
TriviaKind :: SingleLineHashComment => {
156
159
if matches ! ( loc, CommentLocation :: ItemInline ) {
157
- p ! ( out, str ( " " ) )
160
+ p ! ( out, str ( " " ) ) ;
158
161
}
159
162
p ! ( out, str ( "# " ) string( c. text( ) . strip_prefix( '#' ) . expect( "hash comment starts with #" ) . trim( ) . to_string( ) ) ) ;
160
163
if !matches ! ( loc, CommentLocation :: ItemInline ) {
161
- p ! ( out, nl)
164
+ p ! ( out, nl) ;
162
165
}
163
166
}
164
167
TriviaKind :: SingleLineSlashComment => {
165
168
if matches ! ( loc, CommentLocation :: ItemInline ) {
166
- p ! ( out, str ( " " ) )
169
+ p ! ( out, str ( " " ) ) ;
167
170
}
168
171
p ! ( out, str ( "// " ) string( c. text( ) . strip_prefix( "//" ) . expect( "comment starts with //" ) . trim( ) . to_string( ) ) ) ;
169
172
if !matches ! ( loc, CommentLocation :: ItemInline ) {
170
- p ! ( out, nl)
173
+ p ! ( out, nl) ;
171
174
}
172
175
}
173
176
// Garbage in - garbage out
0 commit comments