Skip to content

Commit b99faac

Browse files
committed
tidy: running of eslint is now and extra check
1 parent 42245d3 commit b99faac

File tree

11 files changed

+80
-44
lines changed

11 files changed

+80
-44
lines changed

src/bootstrap/src/core/config/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ pub enum Subcommand {
382382
bless: bool,
383383
#[arg(long)]
384384
/// comma-separated list of other files types to check (accepts py, py:lint,
385-
/// py:fmt, shell)
385+
/// py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck, js:es-check)
386386
extra_checks: Option<String>,
387387
#[arg(long)]
388388
/// rerun tests even if the inputs are unchanged

src/etc/completions/x.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ complete -c x -n "__fish_x_using_subcommand doc" -l skip-std-check-if-no-downloa
293293
complete -c x -n "__fish_x_using_subcommand doc" -s h -l help -d 'Print help (see more with \'--help\')'
294294
complete -c x -n "__fish_x_using_subcommand test" -l test-args -d 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)' -r
295295
complete -c x -n "__fish_x_using_subcommand test" -l compiletest-rustc-args -d 'extra options to pass the compiler when running compiletest tests' -r
296-
complete -c x -n "__fish_x_using_subcommand test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell)' -r
296+
complete -c x -n "__fish_x_using_subcommand test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck, js:es-check)' -r
297297
complete -c x -n "__fish_x_using_subcommand test" -l compare-mode -d 'mode describing what file the actual ui output will be compared to' -r
298298
complete -c x -n "__fish_x_using_subcommand test" -l pass -d 'force {check,build,run}-pass tests to this mode' -r
299299
complete -c x -n "__fish_x_using_subcommand test" -l run -d 'whether to execute run-* tests' -r

src/etc/completions/x.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Register-ArgumentCompleter -Native -CommandName 'x' -ScriptBlock {
339339
'x;test' {
340340
[CompletionResult]::new('--test-args', '--test-args', [CompletionResultType]::ParameterName, 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)')
341341
[CompletionResult]::new('--compiletest-rustc-args', '--compiletest-rustc-args', [CompletionResultType]::ParameterName, 'extra options to pass the compiler when running compiletest tests')
342-
[CompletionResult]::new('--extra-checks', '--extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell)')
342+
[CompletionResult]::new('--extra-checks', '--extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck, js:es-check)')
343343
[CompletionResult]::new('--compare-mode', '--compare-mode', [CompletionResultType]::ParameterName, 'mode describing what file the actual ui output will be compared to')
344344
[CompletionResult]::new('--pass', '--pass', [CompletionResultType]::ParameterName, 'force {check,build,run}-pass tests to this mode')
345345
[CompletionResult]::new('--run', '--run', [CompletionResultType]::ParameterName, 'whether to execute run-* tests')

src/etc/completions/x.py.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ complete -c x.py -n "__fish_x.py_using_subcommand doc" -l skip-std-check-if-no-d
293293
complete -c x.py -n "__fish_x.py_using_subcommand doc" -s h -l help -d 'Print help (see more with \'--help\')'
294294
complete -c x.py -n "__fish_x.py_using_subcommand test" -l test-args -d 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)' -r
295295
complete -c x.py -n "__fish_x.py_using_subcommand test" -l compiletest-rustc-args -d 'extra options to pass the compiler when running compiletest tests' -r
296-
complete -c x.py -n "__fish_x.py_using_subcommand test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell)' -r
296+
complete -c x.py -n "__fish_x.py_using_subcommand test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck, js:es-check)' -r
297297
complete -c x.py -n "__fish_x.py_using_subcommand test" -l compare-mode -d 'mode describing what file the actual ui output will be compared to' -r
298298
complete -c x.py -n "__fish_x.py_using_subcommand test" -l pass -d 'force {check,build,run}-pass tests to this mode' -r
299299
complete -c x.py -n "__fish_x.py_using_subcommand test" -l run -d 'whether to execute run-* tests' -r

src/etc/completions/x.py.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock {
339339
'x.py;test' {
340340
[CompletionResult]::new('--test-args', '--test-args', [CompletionResultType]::ParameterName, 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)')
341341
[CompletionResult]::new('--compiletest-rustc-args', '--compiletest-rustc-args', [CompletionResultType]::ParameterName, 'extra options to pass the compiler when running compiletest tests')
342-
[CompletionResult]::new('--extra-checks', '--extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell)')
342+
[CompletionResult]::new('--extra-checks', '--extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck, js:es-check)')
343343
[CompletionResult]::new('--compare-mode', '--compare-mode', [CompletionResultType]::ParameterName, 'mode describing what file the actual ui output will be compared to')
344344
[CompletionResult]::new('--pass', '--pass', [CompletionResultType]::ParameterName, 'force {check,build,run}-pass tests to this mode')
345345
[CompletionResult]::new('--run', '--run', [CompletionResultType]::ParameterName, 'whether to execute run-* tests')

src/etc/completions/x.py.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ _arguments "${_arguments_options[@]}" : \
338338
_arguments "${_arguments_options[@]}" : \
339339
'*--test-args=[extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)]:ARGS:_default' \
340340
'*--compiletest-rustc-args=[extra options to pass the compiler when running compiletest tests]:ARGS:_default' \
341-
'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, shell)]:EXTRA_CHECKS:_default' \
341+
'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, shell, cpp, cpp\:fmt, js, js\:lint, js\:typecheck, js\:es-check)]:EXTRA_CHECKS:_default' \
342342
'--compare-mode=[mode describing what file the actual ui output will be compared to]:COMPARE MODE:_default' \
343343
'--pass=[force {check,build,run}-pass tests to this mode]:check | build | run:_default' \
344344
'--run=[whether to execute run-* tests]:auto | always | never:_default' \

src/etc/completions/x.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ _arguments "${_arguments_options[@]}" : \
338338
_arguments "${_arguments_options[@]}" : \
339339
'*--test-args=[extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)]:ARGS:_default' \
340340
'*--compiletest-rustc-args=[extra options to pass the compiler when running compiletest tests]:ARGS:_default' \
341-
'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, shell)]:EXTRA_CHECKS:_default' \
341+
'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, shell, cpp, cpp\:fmt, js, js\:lint, js\:typecheck, js\:es-check)]:EXTRA_CHECKS:_default' \
342342
'--compare-mode=[mode describing what file the actual ui output will be compared to]:COMPARE MODE:_default' \
343343
'--pass=[force {check,build,run}-pass tests to this mode]:check | build | run:_default' \
344344
'--run=[whether to execute run-* tests]:auto | always | never:_default' \

src/tools/tidy/src/ext_tool_checks.rs

Lines changed: 29 additions & 1 deletion
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+
mod rustdoc_js;
26+
2527
const MIN_PY_REV: (u32, u32) = (3, 9);
2628
const MIN_PY_REV_STR: &str = "≥3.9";
2729

@@ -39,19 +41,34 @@ const PIP_REQ_PATH: &[&str] = &["src", "tools", "tidy", "config", "requirements.
3941
pub fn check(
4042
root_path: &Path,
4143
outdir: &Path,
44+
librustdoc_path: &Path,
45+
tools_path: &Path,
46+
src_path: &Path,
4247
bless: bool,
4348
extra_checks: Option<&str>,
4449
pos_args: &[String],
4550
bad: &mut bool,
4651
) {
47-
if let Err(e) = check_impl(root_path, outdir, bless, extra_checks, pos_args) {
52+
if let Err(e) = check_impl(
53+
root_path,
54+
outdir,
55+
librustdoc_path,
56+
tools_path,
57+
src_path,
58+
bless,
59+
extra_checks,
60+
pos_args,
61+
) {
4862
tidy_error!(bad, "{e}");
4963
}
5064
}
5165

5266
fn check_impl(
5367
root_path: &Path,
5468
outdir: &Path,
69+
librustdoc_path: &Path,
70+
tools_path: &Path,
71+
src_path: &Path,
5572
bless: bool,
5673
extra_checks: Option<&str>,
5774
pos_args: &[String],
@@ -65,13 +82,20 @@ fn check_impl(
6582
None => vec![],
6683
};
6784

85+
// FIXME(lolbinarycat): this is getting complex, we should probably
86+
// have more proper handling, including a warning/error
87+
// for unknown extra check names.
6888
let python_all = lint_args.contains(&"py");
6989
let python_lint = lint_args.contains(&"py:lint") || python_all;
7090
let python_fmt = lint_args.contains(&"py:fmt") || python_all;
7191
let shell_all = lint_args.contains(&"shell");
7292
let shell_lint = lint_args.contains(&"shell:lint") || shell_all;
7393
let cpp_all = lint_args.contains(&"cpp");
7494
let cpp_fmt = lint_args.contains(&"cpp:fmt") || cpp_all;
95+
let js_all = lint_args.contains(&"js");
96+
let js_lint = js_all || lint_args.contains(&"js:lint");
97+
let js_typecheck = js_all || lint_args.contains(&"js:typecheck");
98+
let js_es_check = js_all || lint_args.contains(&"js:es-check");
7599

76100
let mut py_path = None;
77101

@@ -224,6 +248,10 @@ fn check_impl(
224248
shellcheck_runner(&merge_args(&cfg_args, &file_args_shc))?;
225249
}
226250

251+
if js_lint {
252+
rustdoc_js::lint(librustdoc_path, tools_path, src_path)?;
253+
}
254+
227255
Ok(())
228256
}
229257

src/tools/tidy/src/rustdoc_js.rs renamed to src/tools/tidy/src/ext_tool_checks/rustdoc_js.rs

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,22 @@ use ignore::DirEntry;
99

1010
use crate::walk::walk_no_read;
1111

12-
fn run_eslint(args: &[PathBuf], config_folder: PathBuf, bad: &mut bool) {
13-
let mut child = match Command::new("npx")
12+
fn run_eslint(args: &[PathBuf], config_folder: PathBuf) -> Result<(), super::Error> {
13+
let mut child = Command::new("npx")
1414
.arg("eslint")
1515
.arg("-c")
1616
.arg(config_folder.join(".eslintrc.js"))
1717
.args(args)
18-
.spawn()
19-
{
20-
Ok(child) => child,
21-
Err(error) => {
22-
*bad = true;
23-
eprintln!("failed to run eslint: {error:?}");
24-
return;
25-
}
26-
};
18+
.spawn()?;
2719
match child.wait() {
2820
Ok(exit_status) => {
2921
if exit_status.success() {
30-
return;
22+
return Ok(());
3123
}
32-
eprintln!("eslint command failed");
24+
Err(super::Error::FailedCheck("eslint command failed"))
3325
}
34-
Err(error) => eprintln!("eslint command failed: {error:?}"),
26+
Err(error) => Err(super::Error::Generic(format!("eslint command failed: {error:?}"))),
3527
}
36-
*bad = true;
3728
}
3829

3930
fn get_eslint_version_inner(global: bool) -> Option<String> {
@@ -51,15 +42,18 @@ fn get_eslint_version() -> Option<String> {
5142
get_eslint_version_inner(false).or_else(|| get_eslint_version_inner(true))
5243
}
5344

54-
pub fn check(librustdoc_path: &Path, tools_path: &Path, src_path: &Path, bad: &mut bool) {
45+
pub(super) fn lint(
46+
librustdoc_path: &Path,
47+
tools_path: &Path,
48+
src_path: &Path,
49+
) -> Result<(), super::Error> {
5550
let eslint_version_path =
5651
src_path.join("ci/docker/host-x86_64/mingw-check-tidy/eslint.version");
5752
let eslint_version = match std::fs::read_to_string(&eslint_version_path) {
5853
Ok(version) => version.trim().to_string(),
5954
Err(error) => {
60-
*bad = true;
6155
eprintln!("failed to read `{}`: {error:?}", eslint_version_path.display());
62-
return;
56+
return Err(error.into());
6357
}
6458
};
6559
// Having the correct `eslint` version installed via `npm` isn't strictly necessary, since we're invoking it via `npx`,
@@ -68,22 +62,25 @@ pub fn check(librustdoc_path: &Path, tools_path: &Path, src_path: &Path, bad: &m
6862
match get_eslint_version() {
6963
Some(version) => {
7064
if version != eslint_version {
71-
*bad = true;
72-
eprintln!(
65+
// unfortunatly we can't use `Error::Version` here becuse `str::trim` isn't const and
66+
// Version::required must be a static str
67+
return Err(super::Error::Generic(format!(
7368
"⚠️ Installed version of eslint (`{version}`) is different than the \
74-
one used in the CI (`{eslint_version}`)",
75-
);
76-
eprintln!(
77-
"You can install this version using `npm update eslint` or by using \
78-
`npm install eslint@{eslint_version}`",
79-
);
80-
return;
69+
one used in the CI (`{eslint_version}`)\n\
70+
You can install this version using `npm update eslint` or by using \
71+
`npm install eslint@{eslint_version}`\n
72+
"
73+
)));
8174
}
8275
}
8376
None => {
84-
eprintln!("`eslint` doesn't seem to be installed. Skipping tidy check for JS files.");
85-
eprintln!("You can install it using `npm install eslint@{eslint_version}`");
86-
return;
77+
//eprintln!("`eslint` doesn't seem to be installed. Skipping tidy check for JS files.");
78+
//eprintln!("You can install it using `npm install eslint@{eslint_version}`");
79+
return Err(super::Error::MissingReq(
80+
"eslint",
81+
"js lint checks",
82+
Some(format!("You can install it using `npm install eslint@{eslint_version}`")),
83+
));
8784
}
8885
}
8986
let mut files_to_check = Vec::new();
@@ -95,8 +92,9 @@ pub fn check(librustdoc_path: &Path, tools_path: &Path, src_path: &Path, bad: &m
9592
},
9693
);
9794
println!("Running eslint on rustdoc JS files");
98-
run_eslint(&files_to_check, librustdoc_path.join("html/static"), bad);
95+
run_eslint(&files_to_check, librustdoc_path.join("html/static"))?;
9996

100-
run_eslint(&[tools_path.join("rustdoc-js/tester.js")], tools_path.join("rustdoc-js"), bad);
101-
run_eslint(&[tools_path.join("rustdoc-gui/tester.js")], tools_path.join("rustdoc-gui"), bad);
97+
run_eslint(&[tools_path.join("rustdoc-js/tester.js")], tools_path.join("rustdoc-js"))?;
98+
run_eslint(&[tools_path.join("rustdoc-gui/tester.js")], tools_path.join("rustdoc-gui"))?;
99+
Ok(())
102100
}

src/tools/tidy/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ fn tidy_error(args: &str) -> std::io::Result<()> {
6363
Ok(())
6464
}
6565

66+
// tidy-alphabetical-start
6667
pub mod alphabetical;
6768
pub mod bins;
6869
pub mod debug_artifacts;
@@ -82,7 +83,6 @@ pub mod mir_opt_tests;
8283
pub mod pal;
8384
pub mod rustdoc_css_themes;
8485
pub mod rustdoc_gui_tests;
85-
pub mod rustdoc_js;
8686
pub mod rustdoc_json;
8787
pub mod rustdoc_templates;
8888
pub mod style;
@@ -97,3 +97,4 @@ pub mod unknown_revision;
9797
pub mod unstable_book;
9898
pub mod walk;
9999
pub mod x_version;
100+
// tidy-alphabetical-end

0 commit comments

Comments
 (0)