-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add eslint as part of tidy
run
#141705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add eslint as part of tidy
run
#141705
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0527f02
Add `eslint` as part of tidy run
GuillaumeGomez 9e5dd51
Remove checks that are run with `tidy`
GuillaumeGomez f0f661d
Install eslint in host-x86_64 Dockerfile
GuillaumeGomez b1723fc
Centralize the eslint version between tidy and docker
GuillaumeGomez 8645ef7
Fix npm install error
GuillaumeGomez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
8.6.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
//! Tidy check to ensure that rustdoc templates didn't forget a `{# #}` to strip extra whitespace | ||
//! characters. | ||
|
||
use std::ffi::OsStr; | ||
use std::path::{Path, PathBuf}; | ||
use std::process::Command; | ||
|
||
use ignore::DirEntry; | ||
|
||
use crate::walk::walk_no_read; | ||
|
||
fn run_eslint(args: &[PathBuf], config_folder: PathBuf, bad: &mut bool) { | ||
let mut child = match Command::new("npx") | ||
.arg("eslint") | ||
.arg("-c") | ||
.arg(config_folder.join(".eslintrc.js")) | ||
.args(args) | ||
.spawn() | ||
{ | ||
Ok(child) => child, | ||
Err(error) => { | ||
*bad = true; | ||
eprintln!("failed to run eslint: {error:?}"); | ||
return; | ||
} | ||
}; | ||
match child.wait() { | ||
Ok(exit_status) => { | ||
if exit_status.success() { | ||
return; | ||
} | ||
eprintln!("eslint command failed"); | ||
} | ||
Err(error) => eprintln!("eslint command failed: {error:?}"), | ||
} | ||
*bad = true; | ||
} | ||
|
||
fn get_eslint_version_inner(global: bool) -> Option<String> { | ||
let mut command = Command::new("npm"); | ||
command.arg("list").arg("--parseable").arg("--long").arg("--depth=0"); | ||
if global { | ||
command.arg("--global"); | ||
} | ||
let output = command.output().ok()?; | ||
let lines = String::from_utf8_lossy(&output.stdout); | ||
lines.lines().find_map(|l| l.split(':').nth(1)?.strip_prefix("eslint@")).map(|v| v.to_owned()) | ||
} | ||
|
||
fn get_eslint_version() -> Option<String> { | ||
get_eslint_version_inner(false).or_else(|| get_eslint_version_inner(true)) | ||
} | ||
|
||
pub fn check(librustdoc_path: &Path, tools_path: &Path, src_path: &Path, bad: &mut bool) { | ||
let eslint_version_path = | ||
src_path.join("ci/docker/host-x86_64/mingw-check-tidy/eslint.version"); | ||
let eslint_version = match std::fs::read_to_string(&eslint_version_path) { | ||
Ok(version) => version.trim().to_string(), | ||
Err(error) => { | ||
*bad = true; | ||
eprintln!("failed to read `{}`: {error:?}", eslint_version_path.display()); | ||
return; | ||
} | ||
}; | ||
match get_eslint_version() { | ||
Some(version) => { | ||
if version != eslint_version { | ||
*bad = true; | ||
eprintln!( | ||
"⚠️ Installed version of eslint (`{version}`) is different than the \ | ||
one used in the CI (`{eslint_version}`)", | ||
); | ||
eprintln!( | ||
"You can install this version using `npm update eslint` or by using \ | ||
`npm install eslint@{eslint_version}`", | ||
); | ||
return; | ||
} | ||
} | ||
None => { | ||
eprintln!("`eslint` doesn't seem to be installed. Skipping tidy check for JS files."); | ||
eprintln!("You can install it using `npm install eslint@{eslint_version}`"); | ||
return; | ||
} | ||
} | ||
let mut files_to_check = Vec::new(); | ||
walk_no_read( | ||
&[&librustdoc_path.join("html/static/js")], | ||
|path, is_dir| is_dir || !path.extension().is_some_and(|ext| ext == OsStr::new("js")), | ||
&mut |path: &DirEntry| { | ||
files_to_check.push(path.path().into()); | ||
}, | ||
); | ||
println!("Running eslint on rustdoc JS files"); | ||
run_eslint(&files_to_check, librustdoc_path.join("html/static"), bad); | ||
|
||
run_eslint(&[tools_path.join("rustdoc-js/tester.js")], tools_path.join("rustdoc-js"), bad); | ||
run_eslint(&[tools_path.join("rustdoc-gui/tester.js")], tools_path.join("rustdoc-gui"), bad); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels weird to run eslint locally, but not
tsc
/es-check
. Is there a reason for this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is kinda odd, and i wouldn't mind fixing it, but we are at least fully compatible with the latest version of
tsc
, which is why i only complained about eslint.