ISSUE DESCRIPTION Schrödinger's comment: it is both commented-out code and a comment…
- User
ISSUE DESCRIPTION
Schrödinger's comment: it is both commented-out code and a comment that is not code (ERA001 vs RUF100)
Summary
First, I'm impressed by the recent reduction of ERA001 false positives. I suspect that ERA001 is an exceptionally difficult rule to implement.
This is the only time I've seen this situation.
# ) # ) # noqa: ERA001Found commented-out code (ERA001) [Ln 1, Col 4] Unused
noqadirective (unused:ERA001) (RUF100) [Ln 2, Col 10]preview = false builtins = [] target-version = "py310" line-length = 88 indent-width = 4 [lint] allowed-confusables = [] dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" extend-select = [] extend-fixable = [] external = [] ignore = [] select = [ "F", "E4", "E7", "E9", "ERA", "RUF" ] [format] indent-style = "space" quote-style = "double"Version
ruff 0.15.14 (9ad2da301 2026-05-21)
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- Assistant
I'll start by exploring the repository structure and reproducing the ERA001 vs RUF100 conflict described in the issue.
- Assistant
I'll search the codebase for ERA001 and RUF100 handling to locate the conflict.
- Assistant
rg is not found, let me use grep instead.
- Assistant
Let me look at the eradicate detection code and how noqa works with multiline comments.
- Assistant
I need to dig into the ERA001 rule implementation and how noqa directives are applied.
- Assistant
I'll inspect
comment_contains_codefor nested noqas and how RUF100 attributes unused directives. - Assistant
I'll reproduce the reported issue with a minimal example.
- Assistant
The core issue is that a trailing
# noqaprevents ERA001 from matching the comment as code, leaving the directive unused. I'll verify how noqa is stripped during detection. - Assistant
Checking snapshots and fixture behavior for
# ... # noqa: ERA001patterns. - Assistant
I need to understand how nested
# noqainside commented-out code is extracted. - Assistant
Let me look at how nested noqa in comments is handled, and also check recent ERA001 related changes.
- Assistant
There's a recent fix:
[eradicate] Fix false positive for lines with leading whitespace (ERA001) (#25122). Let me look at that - the issue mentions "impressed by the recent reduction of ERA001 false ... - Assistant
I'll find existing utilities that strip or parse nested
# noqacomments for reuse. - Assistant
I'll implement stripping trailing nested
# noqabefore ERA001 code detection and verify with the unit tests. - Assistant
I'll check RUF100 fixtures for ERA001 interactions and related comments about striping.
- Assistant
There's RUF100_5.py that tests ERA001 with noqa. Let me read it.
- Assistant
Let me find the snapshot for RUF100_5
- Assistant
Let me read the snapshot.
- Assistant
So currently:
#import os # noqa- ERA suppressed, noqa used (all)
- Assistant
I'll strip trailing nested
# noqabefore ERA001 detection so the directive no longer masks commented-out code. - Assistant
I'll apply the trailing nested
# noqastrip incomment_contains_code. - Assistant
I'll compile and run the eradicate unit tests to verify the change.
- Assistant
All eradicate tests passed. Next I'll reproduce the reported case and run the RUF100 interaction tests.
- Assistant
Need to find the ruff binary.
- Assistant
Confirming multiline assignment behavior and that the original issue case is fully fixed.
- Assistant
Confirming a lone
# ) # noqa: ERA001produces no diagnostics. - Assistant
Oops I stashed the fix accidentally. Let me restore it.
- Assistant
I stashed by accident; I'll confirm the fix is still in the file.
- Assistant
I'll also allow trailing comments on bracket/multiline POSITIVE_CASES so non-noqa notes don't break detection.
- Assistant
I'll re-run the tests and reproduce the original issue after both changes.
- Assistant
I'll drop the broader POSITIVE_CASES change and keep only the targeted trailing-noqa strip.
- Assistant
Final verification of the targeted fix.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.