Skip to content

Commit a239e1e

Browse files
committed
tidy: implement js:typecheck and js:es-lint extra checks
1 parent 798a0be commit a239e1e

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

src/tools/tidy/src/ext_tool_checks.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,14 @@ fn check_impl(
252252
rustdoc_js::lint(librustdoc_path, tools_path, src_path)?;
253253
}
254254

255+
if js_typecheck {
256+
rustdoc_js::typecheck(librustdoc_path)?;
257+
}
258+
259+
if js_es_check {
260+
rustdoc_js::es_check(librustdoc_path)?;
261+
}
262+
255263
Ok(())
256264
}
257265

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

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ use ignore::DirEntry;
99

1010
use crate::walk::walk_no_read;
1111

12+
fn rustdoc_js_files(librustdoc_path: &Path) -> Vec<PathBuf> {
13+
let mut files = Vec::new();
14+
walk_no_read(
15+
&[&librustdoc_path.join("html/static/js")],
16+
|path, is_dir| is_dir || !path.extension().is_some_and(|ext| ext == OsStr::new("js")),
17+
&mut |path: &DirEntry| {
18+
files.push(path.path().into());
19+
},
20+
);
21+
return files;
22+
}
23+
1224
fn run_eslint(args: &[PathBuf], config_folder: PathBuf) -> Result<(), super::Error> {
1325
let mut child = Command::new("npx")
1426
.arg("eslint")
@@ -83,18 +95,48 @@ pub(super) fn lint(
8395
));
8496
}
8597
}
86-
let mut files_to_check = Vec::new();
87-
walk_no_read(
88-
&[&librustdoc_path.join("html/static/js")],
89-
|path, is_dir| is_dir || !path.extension().is_some_and(|ext| ext == OsStr::new("js")),
90-
&mut |path: &DirEntry| {
91-
files_to_check.push(path.path().into());
92-
},
93-
);
98+
let files_to_check = rustdoc_js_files(librustdoc_path);
9499
println!("Running eslint on rustdoc JS files");
95100
run_eslint(&files_to_check, librustdoc_path.join("html/static"))?;
96101

97102
run_eslint(&[tools_path.join("rustdoc-js/tester.js")], tools_path.join("rustdoc-js"))?;
98103
run_eslint(&[tools_path.join("rustdoc-gui/tester.js")], tools_path.join("rustdoc-gui"))?;
99104
Ok(())
100105
}
106+
107+
pub(super) fn typecheck(librustdoc_path: &Path) -> Result<(), super::Error> {
108+
// use npx to ensure correct version
109+
let mut child = Command::new("npx")
110+
.arg("tsc")
111+
.arg("-p")
112+
.arg(librustdoc_path.join("html/static/js/tsconfig.json"))
113+
.spawn()?;
114+
match child.wait() {
115+
Ok(exit_status) => {
116+
if exit_status.success() {
117+
return Ok(());
118+
}
119+
Err(super::Error::FailedCheck("tsc command failed"))
120+
}
121+
Err(error) => Err(super::Error::Generic(format!("tsc command failed: {error:?}"))),
122+
}
123+
}
124+
125+
pub(super) fn es_check(librustdoc_path: &Path) -> Result<(), super::Error> {
126+
let files_to_check = rustdoc_js_files(librustdoc_path);
127+
// use npx to ensure correct version
128+
let mut cmd = Command::new("npx");
129+
cmd.arg("es-check").arg("es2019");
130+
for f in files_to_check {
131+
cmd.arg(f);
132+
}
133+
match cmd.spawn()?.wait() {
134+
Ok(exit_status) => {
135+
if exit_status.success() {
136+
return Ok(());
137+
}
138+
Err(super::Error::FailedCheck("es-check command failed"))
139+
}
140+
Err(error) => Err(super::Error::Generic(format!("es-check command failed: {error:?}"))),
141+
}
142+
}

0 commit comments

Comments
 (0)