-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[pygrep_hooks
] Check blanket ignores via file-level pragmas (PGH004
)
#11540
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PGH004 | 5 | 5 | 0 | 0 | 0 |
The stable behavior should be unchanged, the added behavior should only be present in preview. |
Thanks for the swift feedback. I added a check for Would you like me to also update the docs for |
@@ -85,7 +86,19 @@ pub(crate) fn blanket_noqa( | |||
diagnostics: &mut Vec<Diagnostic>, | |||
noqa_directives: &NoqaDirectives, | |||
locator: &Locator, | |||
exemption: &Option<FileExemption>, |
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.
One downside here is that this is only going to flag the first # ruff: noqa
in the file. I assume if you add multiple such comments, only the first is flagged as a diagnostic?
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.
We might need to do something like NoqaDirectives
, whereby we parse all of these upfront, then use the parsed exemptions in crates/ruff_linter/src/checkers/noqa.rs
(and here).
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.
@ajesipow - Do you want to give that a try?
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.
Thanks for the ping @charliermarsh.
I haven't found the time yet after work this week, but today is a public holiday over here so I'll look into it today :)
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 just pushed the changes and adapted the tests again accordingly.
Looking forward to your feedback again.
/// The file is exempt from all rules. | ||
All, | ||
/// The file is exempt from the given rules. | ||
Codes(Vec<NoqaCode>), | ||
Codes(Vec<&'a NoqaCode>), |
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 left this as a Vec
, but we could consider using a HashSet
instead as we're checking if certain NoqaCode
s are contained in a few places (one being the loop on line 54 in checkers/noqa.rs
).
It's probably fine though as I'd expect there will usually only be very few elements here and checking the small Vec
is likely faster compared to the overhead of hashing every time (and building the HashSet
in the first place).
We'd also have to derive Hash
on NoqaCode
.
Thanks @ajesipow, I will 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.
Thank you!
pygrep_hooks
] Check blanket ignores via file-level pragmas (PGH004
)
CodSpeed Performance ReportMerging #11540 will degrade performances by 5.63%Comparing Summary
Benchmarks breakdown
|
* main: CI: add job to run tests under minimum supported rust version (msrv) (#11737) Lexer should consider BOM for the start offset (#11732) Use cursor offset for lexer checkpoint (#11734) red-knot: Change `resolve_global_symbol` to take `Module` as an argument (#11723) red-knot: Use `parse_unchecked` to get all parse errors (#11725) Respect per-file ignores for blanket and redirected noqa rules (#11728) [`pygrep_hooks`] Check blanket ignores via file-level pragmas (`PGH004`) (#11540)
Summary
Should resolve #11454.
This is my first PR to
ruff
, so I may have missed something.If I understood the suggestion in the issue correctly, rule
PGH004
should be set toPreview
again.Test Plan
Created two fixtures derived from the issue.