-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update ERA100 to apply to commented dictionary items with trailing co…
…mments (#6822) Closes #6821 ERA100 was not raising on commented parts of dictionaries if it included another comment (such as a noqa clause). In cases where this comment was a noqa clause, RUF100 to be emitted since the noqa would have no effect. Here, we update ERA100 to raise even when there are trailing comments. This resolves the linked issue _and_ increases the scope of ERA100. We could narrow the regular expression to only apply to noqa comments if we do not want to expand ERA100 however I think this change is within the spirit of the rule.
- Loading branch information
Showing
6 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#import os # noqa | ||
#import os # noqa: ERA001 | ||
|
||
dictionary = { | ||
# "key1": 123, # noqa: ERA001 | ||
# "key2": 456, # noqa | ||
# "key3": 789, | ||
} | ||
|
||
|
||
#import os # noqa: E501 |
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
50 changes: 50 additions & 0 deletions
50
crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_5.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,50 @@ | ||
--- | ||
source: crates/ruff/src/rules/ruff/mod.rs | ||
--- | ||
RUF100_5.py:7:5: ERA001 [*] Found commented-out code | ||
| | ||
5 | # "key1": 123, # noqa: ERA001 | ||
6 | # "key2": 456, # noqa | ||
7 | # "key3": 789, | ||
| ^^^^^^^^^^^^^^ ERA001 | ||
8 | } | ||
| | ||
= help: Remove commented-out code | ||
|
||
ℹ Possible fix | ||
4 4 | dictionary = { | ||
5 5 | # "key1": 123, # noqa: ERA001 | ||
6 6 | # "key2": 456, # noqa | ||
7 |- # "key3": 789, | ||
8 7 | } | ||
9 8 | | ||
10 9 | | ||
|
||
RUF100_5.py:11:1: ERA001 [*] Found commented-out code | ||
| | ||
11 | #import os # noqa: E501 | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ ERA001 | ||
| | ||
= help: Remove commented-out code | ||
|
||
ℹ Possible fix | ||
8 8 | } | ||
9 9 | | ||
10 10 | | ||
11 |-#import os # noqa: E501 | ||
|
||
RUF100_5.py:11:13: RUF100 [*] Unused `noqa` directive (unused: `E501`) | ||
| | ||
11 | #import os # noqa: E501 | ||
| ^^^^^^^^^^^^ RUF100 | ||
| | ||
= help: Remove unused `noqa` directive | ||
|
||
ℹ Suggested fix | ||
8 8 | } | ||
9 9 | | ||
10 10 | | ||
11 |-#import os # noqa: E501 | ||
11 |+#import os | ||
|
||
|