@@ -9,9 +9,9 @@ use ignore::DirEntry;
9
9
10
10
use crate :: walk:: walk_no_read;
11
11
12
- fn run_eslint ( args : & [ PathBuf ] , config_folder : PathBuf , bad : & mut bool ) {
12
+ fn run_eslint ( eslint_version : & str , args : & [ PathBuf ] , config_folder : PathBuf , bad : & mut bool ) {
13
13
let mut child = match Command :: new ( "npx" )
14
- . arg ( "eslint" )
14
+ . arg ( format ! ( "eslint@{eslint_version}" ) )
15
15
. arg ( "-c" )
16
16
. arg ( config_folder. join ( ".eslintrc.js" ) )
17
17
. args ( args)
@@ -36,19 +36,8 @@ fn run_eslint(args: &[PathBuf], config_folder: PathBuf, bad: &mut bool) {
36
36
* bad = true ;
37
37
}
38
38
39
- fn get_eslint_version_inner ( global : bool ) -> Option < String > {
40
- let mut command = Command :: new ( "npm" ) ;
41
- command. arg ( "list" ) . arg ( "--parseable" ) . arg ( "--long" ) . arg ( "--depth=0" ) ;
42
- if global {
43
- command. arg ( "--global" ) ;
44
- }
45
- let output = command. output ( ) . ok ( ) ?;
46
- let lines = String :: from_utf8_lossy ( & output. stdout ) ;
47
- lines. lines ( ) . find_map ( |l| l. split ( ':' ) . nth ( 1 ) ?. strip_prefix ( "eslint@" ) ) . map ( |v| v. to_owned ( ) )
48
- }
49
-
50
- fn get_eslint_version ( ) -> Option < String > {
51
- get_eslint_version_inner ( false ) . or_else ( || get_eslint_version_inner ( true ) )
39
+ fn has_npx ( ) -> bool {
40
+ Command :: new ( "npxa" ) . arg ( "--version" ) . output ( ) . is_ok_and ( |output| output. status . success ( ) )
52
41
}
53
42
54
43
pub fn check ( librustdoc_path : & Path , tools_path : & Path , src_path : & Path , bad : & mut bool ) {
@@ -62,26 +51,10 @@ pub fn check(librustdoc_path: &Path, tools_path: &Path, src_path: &Path, bad: &m
62
51
return ;
63
52
}
64
53
} ;
65
- match get_eslint_version ( ) {
66
- Some ( version) => {
67
- if version != eslint_version {
68
- * bad = true ;
69
- eprintln ! (
70
- "⚠️ Installed version of eslint (`{version}`) is different than the \
71
- one used in the CI (`{eslint_version}`)",
72
- ) ;
73
- eprintln ! (
74
- "You can install this version using `npm update eslint` or by using \
75
- `npm install eslint@{eslint_version}`",
76
- ) ;
77
- return ;
78
- }
79
- }
80
- None => {
81
- eprintln ! ( "`eslint` doesn't seem to be installed. Skipping tidy check for JS files." ) ;
82
- eprintln ! ( "You can install it using `npm install eslint@{eslint_version}`" ) ;
83
- return ;
84
- }
54
+ if !has_npx ( ) {
55
+ eprintln ! ( "`npx` doesn't seem to be installed. Skipping tidy check for JS files." ) ;
56
+ eprintln ! ( "Installing `node` should also install `npm` and `npx` on your system." ) ;
57
+ return ;
85
58
}
86
59
let mut files_to_check = Vec :: new ( ) ;
87
60
walk_no_read (
@@ -92,8 +65,18 @@ pub fn check(librustdoc_path: &Path, tools_path: &Path, src_path: &Path, bad: &m
92
65
} ,
93
66
) ;
94
67
println ! ( "Running eslint on rustdoc JS files" ) ;
95
- run_eslint ( & files_to_check, librustdoc_path. join ( "html/static" ) , bad) ;
68
+ run_eslint ( & eslint_version , & files_to_check, librustdoc_path. join ( "html/static" ) , bad) ;
96
69
97
- run_eslint ( & [ tools_path. join ( "rustdoc-js/tester.js" ) ] , tools_path. join ( "rustdoc-js" ) , bad) ;
98
- run_eslint ( & [ tools_path. join ( "rustdoc-gui/tester.js" ) ] , tools_path. join ( "rustdoc-gui" ) , bad) ;
70
+ run_eslint (
71
+ & eslint_version,
72
+ & [ tools_path. join ( "rustdoc-js/tester.js" ) ] ,
73
+ tools_path. join ( "rustdoc-js" ) ,
74
+ bad,
75
+ ) ;
76
+ run_eslint (
77
+ & eslint_version,
78
+ & [ tools_path. join ( "rustdoc-gui/tester.js" ) ] ,
79
+ tools_path. join ( "rustdoc-gui" ) ,
80
+ bad,
81
+ ) ;
99
82
}
0 commit comments