-
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
654ebf7
Check file-level pragmas for PGH004
ajesipow 3f22083
Remove unnecessary line change
ajesipow 4c3dc41
Remove unnecessary line change
ajesipow 0f7ff38
Extra behaviour only when preview enabled
ajesipow 7ca4429
Add separate preview test for conformity with rest of the codebase
ajesipow 600aed1
Adapt test files for multiple file-level blanket NoQAs
ajesipow d5a668c
Add BlanketNoqaDirectives to extract file level exemptions on multipl…
ajesipow 8574036
Merge branch 'main' into pgh004-file-level
charliermarsh f599caa
Add newline
charliermarsh 24037e4
Tweak message
charliermarsh 4e80490
Add to docs
charliermarsh 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
7 changes: 7 additions & 0 deletions
7
crates/ruff_linter/resources/test/fixtures/pygrep_hooks/PGH004_2.py
This file contains 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,7 @@ | ||
# noqa | ||
# ruff : noqa | ||
# ruff: noqa: F401 | ||
|
||
|
||
# flake8: noqa | ||
import math as m |
This file contains 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 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 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 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
10 changes: 10 additions & 0 deletions
10
...s/pygrep_hooks/snapshots/ruff_linter__rules__pygrep_hooks__tests__PGH004_PGH004_2.py.snap
This file contains 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,10 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pygrep_hooks/mod.rs | ||
--- | ||
PGH004_2.py:1:1: PGH004 Use specific rule codes when using `noqa` | ||
| | ||
1 | # noqa | ||
| ^^^^^^ PGH004 | ||
2 | # ruff : noqa | ||
3 | # ruff: noqa: F401 | ||
| |
25 changes: 25 additions & 0 deletions
25
...hooks/snapshots/ruff_linter__rules__pygrep_hooks__tests__preview__PGH004_PGH004_2.py.snap
This file contains 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,25 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pygrep_hooks/mod.rs | ||
--- | ||
PGH004_2.py:1:1: PGH004 Use specific rule codes when using `noqa` | ||
| | ||
1 | # noqa | ||
| ^^^^^^ PGH004 | ||
2 | # ruff : noqa | ||
3 | # ruff: noqa: F401 | ||
| | ||
|
||
PGH004_2.py:2:1: PGH004 Use specific rule codes when using `noqa` | ||
| | ||
1 | # noqa | ||
2 | # ruff : noqa | ||
| ^^^^^^^^^^^^^ PGH004 | ||
3 | # ruff: noqa: F401 | ||
| | ||
|
||
PGH004_2.py:6:1: PGH004 Use specific rule codes when using `noqa` | ||
| | ||
6 | # flake8: noqa | ||
| ^^^^^^^^^^^^^^ PGH004 | ||
7 | import math as m | ||
| |
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.
I left this as a
Vec
, but we could consider using aHashSet
instead as we're checking if certainNoqaCode
s are contained in a few places (one being the loop on line 54 incheckers/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 theHashSet
in the first place).We'd also have to derive
Hash
onNoqaCode
.