Skip to content

Commit 27954ec

Browse files
authored
Rollup merge of #146332 - lolbinarycat:tidy-extra-checks-regularize, r=Kobzol
tidy: make behavior of extra-checks more uniform
2 parents 7429420 + 8222f7d commit 27954ec

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

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

Lines changed: 42 additions & 10 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);
@@ -147,21 +153,32 @@ fn check_impl(
147153
}
148154

149155
if python_lint {
150-
eprintln!("linting python files");
151156
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);
153166

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

157-
let _ = run_ruff(
170+
let diff_res = run_ruff(
158171
root_path,
159172
outdir,
160173
py_path,
161174
&cfg_args,
162175
&file_args,
163176
&["check".as_ref(), "--diff".as_ref()],
164177
);
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+
}
165182
}
166183
// Rethrow error
167184
res?;
@@ -192,7 +209,7 @@ fn check_impl(
192209
&["format".as_ref(), "--diff".as_ref()],
193210
);
194211
}
195-
eprintln!("rerun tidy with `--extra-checks=py:fmt --bless` to reformat Python code");
212+
rerun_with_bless("py:fmt", "reformat Python code");
196213
}
197214

198215
// Rethrow error
@@ -225,7 +242,7 @@ fn check_impl(
225242
let args = merge_args(&cfg_args_clang_format, &file_args_clang_format);
226243
let res = py_runner(py_path.as_ref().unwrap(), false, None, "clang-format", &args);
227244

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

231248
let mut cfg_args_clang_format_diff = cfg_args.clone();
@@ -265,6 +282,7 @@ fn check_impl(
265282
);
266283
}
267284
}
285+
rerun_with_bless("cpp:fmt", "reformat C++ code");
268286
}
269287
// Rethrow error
270288
res?;
@@ -290,24 +308,38 @@ fn check_impl(
290308
args.extend_from_slice(SPELLCHECK_DIRS);
291309

292310
if bless {
293-
eprintln!("spellcheck files and fix");
311+
eprintln!("spellchecking files and fixing typos");
294312
args.push("--write-changes");
295313
} else {
296-
eprintln!("spellcheck files");
314+
eprintln!("spellchecking files");
297315
}
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?;
299321
}
300322

301323
if js_lint || js_typecheck {
302324
rustdoc_js::npm_install(root_path, outdir, npm)?;
303325
}
304326

305327
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?;
307338
rustdoc_js::es_check(outdir, librustdoc_path)?;
308339
}
309340

310341
if js_typecheck {
342+
eprintln!("typechecking javascript files");
311343
rustdoc_js::typecheck(outdir, librustdoc_path)?;
312344
}
313345

src/tools/tidy/src/extra_checks/rustdoc_js.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn run_eslint(
5757
if exit_status.success() {
5858
return Ok(());
5959
}
60-
Err(super::Error::FailedCheck("eslint command failed"))
60+
Err(super::Error::FailedCheck("eslint"))
6161
}
6262
Err(error) => Err(super::Error::Generic(format!("eslint command failed: {error:?}"))),
6363
}
@@ -94,7 +94,7 @@ pub(super) fn typecheck(outdir: &Path, librustdoc_path: &Path) -> Result<(), sup
9494
if exit_status.success() {
9595
return Ok(());
9696
}
97-
Err(super::Error::FailedCheck("tsc command failed"))
97+
Err(super::Error::FailedCheck("tsc"))
9898
}
9999
Err(error) => Err(super::Error::Generic(format!("tsc command failed: {error:?}"))),
100100
}
@@ -112,7 +112,7 @@ pub(super) fn es_check(outdir: &Path, librustdoc_path: &Path) -> Result<(), supe
112112
if exit_status.success() {
113113
return Ok(());
114114
}
115-
Err(super::Error::FailedCheck("es-check command failed"))
115+
Err(super::Error::FailedCheck("es-check"))
116116
}
117117
Err(error) => Err(super::Error::Generic(format!("es-check command failed: {error:?}"))),
118118
}

0 commit comments

Comments
 (0)