-
Notifications
You must be signed in to change notification settings - Fork 1.8k
apply range suppressions to filter diagnostics #21623
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ee58f87
Prototype filtering diagnostics by range suppressions
amyreese dd5d45c
Refactor suppressions checking into check_noqa
amyreese df36084
Short circuit if no suppressions loaded
amyreese 67be3d9
Add test covering expected diagnostics from range suppressions
amyreese 36fbd22
Gate suppression parsing/checking on `--preview`
amyreese 7723b63
english
amyreese 2f57e20
More integration test cases
amyreese 5ebadd4
Added cli tests (currently failing)
amyreese fe83037
Load and pass suppressions through when adding noqa comments
amyreese 2100298
Update comment
amyreese 8f104fa
Add is_empty to Suppressions, don't abort early in check_noqa
amyreese 4ecc005
Move suppression loading out of check_path, preview check in from_tokens
amyreese 49514a1
Use diagnostic diff macro in tests
amyreese 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
56 changes: 56 additions & 0 deletions
56
crates/ruff_linter/resources/test/fixtures/ruff/suppressions.py
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,56 @@ | ||
| def f(): | ||
| # These should both be ignored by the range suppression. | ||
| # ruff: disable[E741, F841] | ||
| I = 1 | ||
| # ruff: enable[E741, F841] | ||
|
|
||
|
|
||
| def f(): | ||
| # These should both be ignored by the implicit range suppression. | ||
| # Should also generate an "unmatched suppression" warning. | ||
| # ruff:disable[E741,F841] | ||
| I = 1 | ||
|
|
||
|
|
||
| def f(): | ||
| # Neither warning is ignored, and an "unmatched suppression" | ||
| # should be generated. | ||
| I = 1 | ||
| # ruff: enable[E741, F841] | ||
|
|
||
|
|
||
| def f(): | ||
| # One should be ignored by the range suppression, and | ||
| # the other logged to the user. | ||
| # ruff: disable[E741] | ||
| I = 1 | ||
| # ruff: enable[E741] | ||
|
|
||
|
|
||
| def f(): | ||
| # Test interleaved range suppressions. The first and last | ||
| # lines should each log a different warning, while the | ||
| # middle line should be completely silenced. | ||
| # ruff: disable[E741] | ||
| l = 0 | ||
| # ruff: disable[F841] | ||
| O = 1 | ||
| # ruff: enable[E741] | ||
| I = 2 | ||
| # ruff: enable[F841] | ||
|
|
||
|
|
||
| def f(): | ||
| # Neither of these are ignored and warnings are | ||
| # logged to user | ||
| # ruff: disable[E501] | ||
| I = 1 | ||
| # ruff: enable[E501] | ||
|
|
||
|
|
||
| def f(): | ||
| # These should both be ignored by the range suppression, | ||
| # and an unusued noqa diagnostic should be logged. | ||
| # ruff:disable[E741,F841] | ||
| I = 1 # noqa: E741,F841 | ||
| # ruff:enable[E741,F841] |
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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 try to avoid reading fixture files in CLI tests as it makes the tests depend on each other and it can also become harder to reason about what we're testing here. Would it be possible to extract the specific case you want to test from
noqa.py?The tests here also don't need to be exhaustive. We can add more exhaustive tests to
add_noqa(I think we have some integration tests, right?)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.
This was a copy-paste of the tests directly above and below it that exercise
--add-noqa.