@@ -9,6 +9,18 @@ use ignore::DirEntry;
99
1010use 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+
1224fn 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