Skip to content

Commit c19d81b

Browse files
committed
tidy extra checks that interact with --bless now all recommend using it
1 parent a9d884d commit c19d81b

File tree

1 file changed

+25
-6
lines changed
  • src/tools/tidy/src/extra_checks

1 file changed

+25
-6
lines changed

src/tools/tidy/src/extra_checks/mod.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ fn check_impl(
124124
};
125125
}
126126

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+
127133
let python_lint = extra_check!(Py, Lint);
128134
let python_fmt = extra_check!(Py, Fmt);
129135
let shell_lint = extra_check!(Shell, Lint);
@@ -158,17 +164,21 @@ fn check_impl(
158164

159165
let res = run_ruff(root_path, outdir, py_path, &cfg_args, &file_args, args);
160166

161-
if res.is_err() && show_diff {
167+
if res.is_err() && show_diff && !bless {
162168
eprintln!("\npython linting failed! Printing diff suggestions:");
163169

164-
let _ = run_ruff(
170+
let diff_res = run_ruff(
165171
root_path,
166172
outdir,
167173
py_path,
168174
&cfg_args,
169175
&file_args,
170176
&["check".as_ref(), "--diff".as_ref()],
171177
);
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+
}
172182
}
173183
// Rethrow error
174184
res?;
@@ -199,7 +209,7 @@ fn check_impl(
199209
&["format".as_ref(), "--diff".as_ref()],
200210
);
201211
}
202-
eprintln!("rerun tidy with `--extra-checks=py:fmt --bless` to reformat Python code");
212+
rerun_with_bless("py:fmt", "reformat Python code");
203213
}
204214

205215
// Rethrow error
@@ -232,7 +242,7 @@ fn check_impl(
232242
let args = merge_args(&cfg_args_clang_format, &file_args_clang_format);
233243
let res = py_runner(py_path.as_ref().unwrap(), false, None, "clang-format", &args);
234244

235-
if res.is_err() && show_diff {
245+
if res.is_err() && show_diff && !bless {
236246
eprintln!("\nclang-format linting failed! Printing diff suggestions:");
237247

238248
let mut cfg_args_clang_format_diff = cfg_args.clone();
@@ -272,6 +282,7 @@ fn check_impl(
272282
);
273283
}
274284
}
285+
rerun_with_bless("cpp:fmt", "reformat C++ code");
275286
}
276287
// Rethrow error
277288
res?;
@@ -302,7 +313,11 @@ fn check_impl(
302313
} else {
303314
eprintln!("spellchecking files");
304315
}
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?;
306321
}
307322

308323
if js_lint || js_typecheck {
@@ -315,7 +330,11 @@ fn check_impl(
315330
} else {
316331
eprintln!("linting javascript files and applying suggestions");
317332
}
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?;
319338
rustdoc_js::es_check(outdir, librustdoc_path)?;
320339
}
321340

0 commit comments

Comments
 (0)