Skip to content

Commit 2bd8d2e

Browse files
committed
tidy: only run eslint on JS files if specified with "--extra-checks"
1 parent 9972ebf commit 2bd8d2e

File tree

4 files changed

+62
-104
lines changed

4 files changed

+62
-104
lines changed

src/tools/tidy/src/ext_tool_checks.rs

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use std::path::{Path, PathBuf};
2222
use std::process::Command;
2323
use std::{fmt, fs, io};
2424

25+
use crate::walk::walk_no_read;
26+
2527
const MIN_PY_REV: (u32, u32) = (3, 9);
2628
const MIN_PY_REV_STR: &str = "≥3.9";
2729

@@ -56,8 +58,8 @@ fn check_impl(
5658
extra_checks: Option<&str>,
5759
pos_args: &[String],
5860
) -> Result<(), Error> {
59-
let show_diff = std::env::var("TIDY_PRINT_DIFF")
60-
.map_or(false, |v| v.eq_ignore_ascii_case("true") || v == "1");
61+
let show_diff =
62+
std::env::var("TIDY_PRINT_DIFF").is_ok_and(|v| v.eq_ignore_ascii_case("true") || v == "1");
6163

6264
// Split comma-separated args up
6365
let lint_args = match extra_checks {
@@ -72,6 +74,8 @@ fn check_impl(
7274
let shell_lint = lint_args.contains(&"shell:lint") || shell_all;
7375
let cpp_all = lint_args.contains(&"cpp");
7476
let cpp_fmt = lint_args.contains(&"cpp:fmt") || cpp_all;
77+
let js_all = lint_args.contains(&"js");
78+
let js_lint = lint_args.contains(&"js:lint") || js_all;
7579

7680
let mut py_path = None;
7781

@@ -224,6 +228,44 @@ fn check_impl(
224228
shellcheck_runner(&merge_args(&cfg_args, &file_args_shc))?;
225229
}
226230

231+
if js_lint {
232+
eprintln!("running `eslint` on JS files");
233+
let src_path = root_path.join("src");
234+
let eslint_version_path =
235+
src_path.join("ci/docker/host-x86_64/mingw-check-tidy/eslint.version");
236+
let eslint_version = fs::read_to_string(&eslint_version_path)
237+
.map_err(|error| {
238+
Error::Generic(format!(
239+
"failed to read `eslint` version file `{}`: {error:?}",
240+
eslint_version_path.display()
241+
))
242+
})?
243+
.trim()
244+
.to_string();
245+
let mut files_to_check = Vec::new();
246+
let librustdoc_path = src_path.join("librustdoc");
247+
let tools_path = src_path.join("tools");
248+
walk_no_read(
249+
&[&librustdoc_path.join("html/static/js")],
250+
|path, is_dir| is_dir || path.extension() != Some(OsStr::new("js")),
251+
&mut |path| {
252+
files_to_check.push(path.path().into());
253+
},
254+
);
255+
run_eslint(&eslint_version, &files_to_check, librustdoc_path.join("html/static"))?;
256+
257+
run_eslint(
258+
&eslint_version,
259+
&[tools_path.join("rustdoc-js/tester.js")],
260+
tools_path.join("rustdoc-js"),
261+
)?;
262+
run_eslint(
263+
&eslint_version,
264+
&[tools_path.join("rustdoc-gui/tester.js")],
265+
tools_path.join("rustdoc-gui"),
266+
)?;
267+
}
268+
227269
Ok(())
228270
}
229271

@@ -532,6 +574,24 @@ fn find_with_extension(
532574
Ok(output)
533575
}
534576

577+
fn run_eslint(eslint_version: &str, args: &[PathBuf], config_folder: PathBuf) -> Result<(), Error> {
578+
match Command::new("npx")
579+
.arg(format!("eslint@{eslint_version}"))
580+
.arg("-c")
581+
.arg(config_folder.join(".eslintrc.js"))
582+
.args(args)
583+
.output()
584+
{
585+
Ok(output) if output.status.success() => Ok(()),
586+
Ok(_) => Err(Error::FailedCheck("eslint")),
587+
Err(_) => Err(Error::MissingReq(
588+
"`npx`",
589+
"`eslint` JS linter",
590+
Some("`npx` comes bundled with `node` and `npm`".to_string()),
591+
)),
592+
}
593+
}
594+
535595
#[derive(Debug)]
536596
enum Error {
537597
Io(io::Error),

src/tools/tidy/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ pub mod mir_opt_tests;
8282
pub mod pal;
8383
pub mod rustdoc_css_themes;
8484
pub mod rustdoc_gui_tests;
85-
pub mod rustdoc_js;
8685
pub mod rustdoc_json;
8786
pub mod rustdoc_templates;
8887
pub mod style;

src/tools/tidy/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ fn main() {
3535
let library_path = root_path.join("library");
3636
let compiler_path = root_path.join("compiler");
3737
let librustdoc_path = src_path.join("librustdoc");
38-
let tools_path = src_path.join("tools");
3938
let crashes_path = tests_path.join("crashes");
4039

4140
let args: Vec<String> = env::args().skip(1).collect();
@@ -109,7 +108,6 @@ fn main() {
109108
check!(rustdoc_gui_tests, &tests_path);
110109
check!(rustdoc_css_themes, &librustdoc_path);
111110
check!(rustdoc_templates, &librustdoc_path);
112-
check!(rustdoc_js, &librustdoc_path, &tools_path, &src_path);
113111
check!(rustdoc_json, &src_path);
114112
check!(known_bug, &crashes_path);
115113
check!(unknown_revision, &tests_path);

src/tools/tidy/src/rustdoc_js.rs

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)