-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix RUF100 to detect unused file-level noqa directives with specific codes (#17042) #17061
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 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
05d4958
(fix) RUF100 to detect unused file-level noqa directives
maxmynter cdb89eb
(tests) Test unused file level directives are flagged
maxmynter 7ab4d6c
(fixup) Flip control flow to avoid unnecessary boolean not
maxmynter ecbe562
Preview guard changes to file-level RUF100
maxmynter 3e6a0a8
(test) Remove one unused in two file level noqa on a line
maxmynter f8947c4
Add add hoc support for flake8 noqa's
maxmynter 685d85c
(tests) Adapt for flake8 support
maxmynter 7591bcc
(fixup) Remove colon from flake8 search string
maxmynter d1447a4
Merge branch 'main' into noqa
maxmynter 4a5608b
Post merge cargo fmt / clippy
maxmynter 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # ruff: noqa: F841 -- intentional unused file directive; will be removed |
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,8 @@ | ||
| # flake8: noqa: F841, E501 -- used followed by unused code | ||
| # ruff: noqa: E701, F541 -- unused followed by used code | ||
|
|
||
|
|
||
| def a(): | ||
| # Violating noqa'd F841 (unused) and F541 (no-placeholder f-string) | ||
| x = f"Hello, world" | ||
| return 6 |
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
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
13 changes: 13 additions & 0 deletions
13
...rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruff_noqa_filedirective_unused.snap
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,13 @@ | ||
| --- | ||
| source: crates/ruff_linter/src/rules/ruff/mod.rs | ||
| --- | ||
| RUF100_6.py:1:1: RUF100 [*] Unused `noqa` directive (non-enabled: `F841`) | ||
| | | ||
| 1 | # ruff: noqa: F841 -- intentional unused file directive; will be removed | ||
| | ^^^^^^^^^^^^^^^^^^ RUF100 | ||
| | | ||
| = help: Remove unused `noqa` directive | ||
|
|
||
| ℹ Safe fix | ||
| 1 |-# ruff: noqa: F841 -- intentional unused file directive; will be removed | ||
| 1 |+ |
33 changes: 33 additions & 0 deletions
33
...apshots/ruff_linter__rules__ruff__tests__ruff_noqa_filedirective_unused_last_of_many.snap
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,33 @@ | ||
| --- | ||
| source: crates/ruff_linter/src/rules/ruff/mod.rs | ||
| --- | ||
| RUF100_7.py:1:1: RUF100 [*] Unused `noqa` directive (unused: `E501`) | ||
| | | ||
| 1 | # flake8: noqa: F841, E501 -- used followed by unused code | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF100 | ||
| 2 | # ruff: noqa: E701, F541 -- unused followed by used code | ||
| | | ||
| = help: Remove unused `noqa` directive | ||
|
|
||
| ℹ Safe fix | ||
| 1 |-# flake8: noqa: F841, E501 -- used followed by unused code | ||
| 1 |+# flake8: noqa: F841 -- used followed by unused code | ||
| 2 2 | # ruff: noqa: E701, F541 -- unused followed by used code | ||
| 3 3 | | ||
| 4 4 | | ||
|
|
||
| RUF100_7.py:2:1: RUF100 [*] Unused `noqa` directive (non-enabled: `E701`) | ||
| | | ||
| 1 | # flake8: noqa: F841, E501 -- used followed by unused code | ||
| 2 | # ruff: noqa: E701, F541 -- unused followed by used code | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^ RUF100 | ||
| | | ||
| = help: Remove unused `noqa` directive | ||
|
|
||
| ℹ Safe fix | ||
| 1 1 | # flake8: noqa: F841, E501 -- used followed by unused code | ||
| 2 |-# ruff: noqa: E701, F541 -- unused followed by used code | ||
| 2 |+# ruff: noqa: F541 -- unused followed by used code | ||
| 3 3 | | ||
| 4 4 | | ||
| 5 5 | def a(): |
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.