@@ -124,6 +124,12 @@ fn check_impl(
124
124
} ;
125
125
}
126
126
127
+ let rerun_with_bless = |mode : & str , action : & str | {
128
+ if !bless {
129
+ eprintln ! ( "rerun tidy with `--extra-checks={mode} --bless` to {action}" ) ;
130
+ }
131
+ } ;
132
+
127
133
let python_lint = extra_check ! ( Py , Lint ) ;
128
134
let python_fmt = extra_check ! ( Py , Fmt ) ;
129
135
let shell_lint = extra_check ! ( Shell , Lint ) ;
@@ -147,21 +153,32 @@ fn check_impl(
147
153
}
148
154
149
155
if python_lint {
150
- eprintln ! ( "linting python files" ) ;
151
156
let py_path = py_path. as_ref ( ) . unwrap ( ) ;
152
- let res = run_ruff ( root_path, outdir, py_path, & cfg_args, & file_args, & [ "check" . as_ref ( ) ] ) ;
157
+ let args: & [ & OsStr ] = if bless {
158
+ eprintln ! ( "linting python files and applying suggestions" ) ;
159
+ & [ "check" . as_ref ( ) , "--fix" . as_ref ( ) ]
160
+ } else {
161
+ eprintln ! ( "linting python files" ) ;
162
+ & [ "check" . as_ref ( ) ]
163
+ } ;
164
+
165
+ let res = run_ruff ( root_path, outdir, py_path, & cfg_args, & file_args, args) ;
153
166
154
- if res. is_err ( ) && show_diff {
167
+ if res. is_err ( ) && show_diff && !bless {
155
168
eprintln ! ( "\n python linting failed! Printing diff suggestions:" ) ;
156
169
157
- let _ = run_ruff (
170
+ let diff_res = run_ruff (
158
171
root_path,
159
172
outdir,
160
173
py_path,
161
174
& cfg_args,
162
175
& file_args,
163
176
& [ "check" . as_ref ( ) , "--diff" . as_ref ( ) ] ,
164
177
) ;
178
+ // `ruff check --diff` will return status 0 if there are no suggestions.
179
+ if diff_res. is_err ( ) {
180
+ rerun_with_bless ( "py:lint" , "apply ruff suggestions" ) ;
181
+ }
165
182
}
166
183
// Rethrow error
167
184
res?;
@@ -192,7 +209,7 @@ fn check_impl(
192
209
& [ "format" . as_ref ( ) , "--diff" . as_ref ( ) ] ,
193
210
) ;
194
211
}
195
- eprintln ! ( "rerun tidy with `--extra-checks= py:fmt --bless` to reformat Python code") ;
212
+ rerun_with_bless ( " py:fmt" , " reformat Python code") ;
196
213
}
197
214
198
215
// Rethrow error
@@ -225,7 +242,7 @@ fn check_impl(
225
242
let args = merge_args ( & cfg_args_clang_format, & file_args_clang_format) ;
226
243
let res = py_runner ( py_path. as_ref ( ) . unwrap ( ) , false , None , "clang-format" , & args) ;
227
244
228
- if res. is_err ( ) && show_diff {
245
+ if res. is_err ( ) && show_diff && !bless {
229
246
eprintln ! ( "\n clang-format linting failed! Printing diff suggestions:" ) ;
230
247
231
248
let mut cfg_args_clang_format_diff = cfg_args. clone ( ) ;
@@ -265,6 +282,7 @@ fn check_impl(
265
282
) ;
266
283
}
267
284
}
285
+ rerun_with_bless ( "cpp:fmt" , "reformat C++ code" ) ;
268
286
}
269
287
// Rethrow error
270
288
res?;
@@ -290,24 +308,38 @@ fn check_impl(
290
308
args. extend_from_slice ( SPELLCHECK_DIRS ) ;
291
309
292
310
if bless {
293
- eprintln ! ( "spellcheck files and fix " ) ;
311
+ eprintln ! ( "spellchecking files and fixing typos " ) ;
294
312
args. push ( "--write-changes" ) ;
295
313
} else {
296
- eprintln ! ( "spellcheck files" ) ;
314
+ eprintln ! ( "spellchecking files" ) ;
297
315
}
298
- spellcheck_runner ( root_path, & outdir, & cargo, & args) ?;
316
+ let res = spellcheck_runner ( root_path, & outdir, & cargo, & args) ;
317
+ if res. is_err ( ) {
318
+ rerun_with_bless ( "spellcheck" , "fix typos" ) ;
319
+ }
320
+ res?;
299
321
}
300
322
301
323
if js_lint || js_typecheck {
302
324
rustdoc_js:: npm_install ( root_path, outdir, npm) ?;
303
325
}
304
326
305
327
if js_lint {
306
- rustdoc_js:: lint ( outdir, librustdoc_path, tools_path, bless) ?;
328
+ if bless {
329
+ eprintln ! ( "linting javascript files" ) ;
330
+ } else {
331
+ eprintln ! ( "linting javascript files and applying suggestions" ) ;
332
+ }
333
+ let res = rustdoc_js:: lint ( outdir, librustdoc_path, tools_path, bless) ;
334
+ if res. is_err ( ) {
335
+ rerun_with_bless ( "js:lint" , "apply eslint suggestions" ) ;
336
+ }
337
+ res?;
307
338
rustdoc_js:: es_check ( outdir, librustdoc_path) ?;
308
339
}
309
340
310
341
if js_typecheck {
342
+ eprintln ! ( "typechecking javascript files" ) ;
311
343
rustdoc_js:: typecheck ( outdir, librustdoc_path) ?;
312
344
}
313
345
0 commit comments