-
Notifications
You must be signed in to change notification settings - Fork 13.5k
tidy: add support for --extra-checks=auto:
feature
#143398
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
base: master
Are you sure you want to change the base?
tidy: add support for --extra-checks=auto:
feature
#143398
Conversation
now does proper parsing of git's output and falls back to assuming all files are modified if `git` doesn't work. accepts a closure so extensions can be checked.
currently this just uses a very simple extension-based heirustic.
This PR modifies If appropriate, please update There are changes to the cc @jieyouxu |
Thanks for working on this! To reiterate (writing this to remind myself), the use-case for this is that you want to be running some extra checks locally (which you can now configure through I'm not fully sold on the What do you think about simplifying the automatic detection syntax specification by just adding an extra option called e.g. "auto" or "auto-detect"? So that you would say "--extra-checks=auto-detect,py:lint,cpp:fmt Btw, we already have a precedent in tidy for only formatting files that were modified locally (and this cannot really be configured). In theory, if we were able to make the fmt/lint Python/C++/Shell heuristic that detects which relevant files were changed 100% bulletproof, we could just always apply the extra checks only if any of these files were modified, without adding "auto". That being said, I'm not sure that we can make the heuristic so solid... The problem that could occur is that if some relevant changed files are not detected locally, then tidy can be green locally, but red on CI (because CI checks everything, as we can't afford to just detect changed files there). That's an annoying situation. With your PR, people would at least have to opt into this behavior, it wouldn't be the default, unlike Rust file formatting. |
} | ||
if crate::files_modified(base_commit, |p| p == RUSTDOC_JSON_TYPES) { | ||
// `rustdoc-json-types` was not modified so nothing more to check here. | ||
println!("`rustdoc-json-types` was not modified."); |
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.
Shouldn't there be return;
here? Also, shouldn't the condition be opposite, i.e. if !crate::files_modified
?
src/tools/tidy/src/rustdoc_json.rs
Outdated
eprintln!("error: failed to run `git diff` in rustdoc_json check"); | ||
return; | ||
} | ||
if crate::files_modified(base_commit, |p| p == RUSTDOC_JSON_TYPES) { |
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.
Shouldn't the ==
be something like starts_with
or contains
?
.expect("bad format from `git diff --name-status`"); | ||
if status == "M" { Some(name) } else { None } | ||
}); | ||
for modified_file in modified_files { |
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.
modified_files.any(pred)
/// Returns true if any modified file matches the predicate, if we are in CI, or if unable to list modified files. | ||
pub fn files_modified(ci_info: &CiInfo, pred: impl Fn(&str) -> bool) -> bool { | ||
let Some(base_commit) = &ci_info.base_commit else { | ||
eprintln!("No base commit, assuming all files are modified"); |
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.
Could we panic here if we're on CI? This wuold be a serious issue if the commit was missing for some reason, we shouldn't just skip it.
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.
In fact, let's just return true
from files_modified
if we're on CI. We should always check everything on CI.
that was the original idea, but we can't do that because shellcheck is not run in CI, and I don't wanna have The parsing refactor is complicated, but it was particularly needed to provide actual input validation, and the |
I'm not sure if I understand, this should have nothing to do with CI or shellcheck. I'm just proposing to turn |
the reason why it matters if someone sets a blanket saying "auto just ignores shell" feels like a footgun and is also very inelegant. |
Auto would only modify the detection logic. If you don't specify shell in the extra checks, shellcheck won't be run. Saying just |
let Some(mut first) = parts.next() else { | ||
return Err(ExtraCheckParseError::Empty); | ||
}; | ||
if first == "auto" { |
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.
Could we have an all
keyword too? Could be convenient for CI to ensure we didn't miss any.
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.
While all
would be a good idea, we don't currently run shellcheck on CI, so it wouldn't be used there.
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.
A reason why we don't? Shells are currently a horror show?
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.
Yup 😆
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.
I'll try to ignore my OCD and to NOT take a look.
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.
the reason is because previous attempts at adding shellcheck introduced a bunch of subtle bugs, there's a t-infra zulip thread where i asked about this.
I don't think that's actually simpler to implement tbh, and I think the argument against it exists in your own post: it adds new trivial cases that could be mistaken as meaning something else. it is also seems less intuitive and harder to explain in documentation, how it looks like other items but behaves differently, how it means nothing on it's own, etc... it could maybe be simpler to implement if i completely rewrote my implementation from scratch, but i think in doing so i would need to give up some error reporting, so it would be a significant amount of work to redo things to get something slightly less robust. |
I didn't necessarily mean simpler to implement, but having a simpler mental model for the functionality. Now it's in a sense too powerful, as I said before, likely no one will ever need But I don't want to block this further. Please wait until #143452 is merged (perhaps in #143473), then rebase and r=me. |
Unfortunatly #134006 does something kinda odd with the extra check args that is incompatible with that model, so I think I need to rewrite that to use I don't think there's any way to avoid having that be a breaking change, though. |
I think I'm gonna submit a seperate PR changing how that works, as that should really be done first to avoid messy issues. |
in preparation for #142924
also heavily refactored the parsing of the
--extra-checks
argument to warn about improper usage.cc @GuillaumeGomez
r? @Kobzol