Skip to content

tidy: move rustdoc js stuff into a tidy extra check #142924

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

lolbinarycat
Copy link
Contributor

Most of these were factored out of CI scripts, but eslint in particular was previously implemented with its own special cased logic.

A new option has been added to bootstrap, build.tidy-extra-checks, which serves as a default value for the --extra-checks flag. This is mostly for the benefit of rustdoc js maintainers, but should also help bootstrap py maintainers.

Additionally, --extra-checks=cpp has been documented.

I'm not super happy with how long the extra check names are in comparison to the others (in particular typecheck), but I couldn't think of anything better (I didn't want to name it tsc on the off chance we want to switch to a different typechecking engine in the future).

It would be nice to convert the extra checks arg into a proper enum, both for warning on unknown values and to provide better shell completion.

r? @GuillaumeGomez

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc A-tidy Area: The tidy tool S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Jun 23, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 23, 2025

This PR modifies bootstrap.example.toml.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

There are changes to the tidy tool.

cc @jieyouxu

This PR modifies src/bootstrap/src/core/config.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jun 24, 2025

☔ The latest upstream changes (presumably #142929) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Moving this from CI scripts to tidy is definitely an improvement. Left a few comments.

@@ -382,7 +382,7 @@ pub enum Subcommand {
bless: bool,
#[arg(long)]
/// comma-separated list of other files types to check (accepts py, py:lint,
/// py:fmt, shell)
/// py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck, js:es-check)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to separate type checking and eslint? It's essentially the same category of "checking code" to me, at least in the world of JavaScript. Unless it runs for too long, I'd just collapse both into "lint" or "check". When you develop on JS, you'd set your bootstrap.toml file to contain both anyway, I imagine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsc generally checks correctness, while eslint mostly checks style... thought i suppose if you want fast typechecking, it would be best to run tsc directly...

also calling an extra check "check" feels unhelpful.

# Runs checks to ensure that there are no issues in our JS code.
es-check es2019 ../src/librustdoc/html/static/js/*.js && \
tsc --project ../src/librustdoc/html/static/js/tsconfig.json
src/tools/tidy --extra-checks=js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is now part of tidy, I think that we can move it out of this CI runner and just put it into mingw-check-tidy, to have centralized execution of all tidy checks on one place.

@@ -224,6 +248,18 @@ fn check_impl(
shellcheck_runner(&merge_args(&cfg_args, &file_args_shc))?;
}

if js_lint {
rustdoc_js::lint(librustdoc_path, tools_path, src_path)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we say that the checks would be run if the JS files were modified too? Having them never run unless an extra arguments is passed is very inconvenient.

Copy link
Contributor Author

@lolbinarycat lolbinarycat Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it wasn't too long ago that they were never run locally.

i was gonna have a warning for modifying files and not enabling their extra checks....

i suppose i could add a new "auto" value to --extra-checks, and make that the default.

i would prefer a design which still lets people manually disable these checks if they want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if you modify JS files, seems like you do want these checks by default, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you don't have the tools installed, and have limited or no network connectivity, but still want to run tidy?

I agree that running the tools based on modification is a good default, but there's very little cost to letting people disable it.

I think I would want to add 3 new special values, actually:

  1. all, run everything, possibly used in CI (currently shellcheck isn't run in CI, so we would need to do that first).
  2. auto, run checks for modified files
  3. none, run no extra checks, same as the empty string

This would give a robust system that would be easy to add any future checks into, and would also help improve the existing checks, instead of just improving js checks.

@@ -171,7 +170,17 @@ fn main() {
};
check!(unstable_book, &src_path, collected);

check!(ext_tool_checks, &root_path, &output_directory, bless, extra_checks, pos_args);
check!(
ext_tool_checks,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being added to a single check module? AFAICS ext_tools is running external programs serially, so the wall-time of all those tools adds up. The check! macro exists to run things in threads so they can run in parallel to cut down on walltime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in ext_tools because that's where --extra-checks is parsed. I definitely agree that the parsing logic and stuff could use a big upgrade, and that tools should be run concurrently, but I think that can be done within ext_tools. It doesn't even technically need threads, just to spawn processes then wait for them all simultaneously. I could get working on a system for that if you want. It would probably involve making a struct or trait to represent an extra-check instead of having it be ad-hoc. This would also be a good opportunity to refactor the parsing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the macro also limits concurrency to obey -j, so having thread per check is the easiest way to get that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, should I inline every --extra-check as its own call to check!, probably doubling the size of main() in the process, or do you have a better idea?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, before doing more work I think it'd make sense to check how long it takes to run all the commands and compare that to the overall runtime of tidy. If it's the longest chain then parallelizing makes sense.

@lolbinarycat lolbinarycat force-pushed the tidy-js-extra-checks branch from 575be8c to b023137 Compare June 24, 2025 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc A-tidy Area: The tidy tool S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants