@@ -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 ) ;
@@ -158,17 +164,21 @@ fn check_impl(
158
164
159
165
let res = run_ruff ( root_path, outdir, py_path, & cfg_args, & file_args, args) ;
160
166
161
- if res. is_err ( ) && show_diff {
167
+ if res. is_err ( ) && show_diff && !bless {
162
168
eprintln ! ( "\n python linting failed! Printing diff suggestions:" ) ;
163
169
164
- let _ = run_ruff (
170
+ let diff_res = run_ruff (
165
171
root_path,
166
172
outdir,
167
173
py_path,
168
174
& cfg_args,
169
175
& file_args,
170
176
& [ "check" . as_ref ( ) , "--diff" . as_ref ( ) ] ,
171
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
+ }
172
182
}
173
183
// Rethrow error
174
184
res?;
@@ -199,7 +209,7 @@ fn check_impl(
199
209
& [ "format" . as_ref ( ) , "--diff" . as_ref ( ) ] ,
200
210
) ;
201
211
}
202
- eprintln ! ( "rerun tidy with `--extra-checks= py:fmt --bless` to reformat Python code") ;
212
+ rerun_with_bless ( " py:fmt" , " reformat Python code") ;
203
213
}
204
214
205
215
// Rethrow error
@@ -232,7 +242,7 @@ fn check_impl(
232
242
let args = merge_args ( & cfg_args_clang_format, & file_args_clang_format) ;
233
243
let res = py_runner ( py_path. as_ref ( ) . unwrap ( ) , false , None , "clang-format" , & args) ;
234
244
235
- if res. is_err ( ) && show_diff {
245
+ if res. is_err ( ) && show_diff && !bless {
236
246
eprintln ! ( "\n clang-format linting failed! Printing diff suggestions:" ) ;
237
247
238
248
let mut cfg_args_clang_format_diff = cfg_args. clone ( ) ;
@@ -272,6 +282,7 @@ fn check_impl(
272
282
) ;
273
283
}
274
284
}
285
+ rerun_with_bless ( "cpp:fmt" , "reformat C++ code" ) ;
275
286
}
276
287
// Rethrow error
277
288
res?;
@@ -302,7 +313,11 @@ fn check_impl(
302
313
} else {
303
314
eprintln ! ( "spellchecking files" ) ;
304
315
}
305
- 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?;
306
321
}
307
322
308
323
if js_lint || js_typecheck {
@@ -315,7 +330,11 @@ fn check_impl(
315
330
} else {
316
331
eprintln ! ( "linting javascript files and applying suggestions" ) ;
317
332
}
318
- rustdoc_js:: lint ( outdir, librustdoc_path, tools_path, bless) ?;
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?;
319
338
rustdoc_js:: es_check ( outdir, librustdoc_path) ?;
320
339
}
321
340
0 commit comments