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)
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.
- I have thought about edge cases and made sure my fix handles them as well.
- Assistant
I’ll locate the ERA001 and noqa/RUF100 implementations and their tests, then reproduce the two-line case with the repository’s test tooling before deciding whether detection or suppression bookkeeping needs adjustment.
- Assistant
ripgrepis unavailable, so I’ll use recursivegrepandfindto identify the rule source and snapshots. - Assistant
I found dedicated integration coverage where ERA001 and RUF100 interact. Next I’ll inspect token diagnostic creation, ERA’s range choice, and noqa directive matching to understand why a directive on the following comment line cannot suppress the first diagnostic yet is still judged unused.
- Assistant
The likely invariant is that appending
# noqa: ERA001must not change whether the underlying comment is considered code; it should only suppress the resulting diagnostic. I’ll inspect ERA’s normalization pipeline and run the exact sample through the local CLI to confirm that the second)is rejected specifically because the directive text participates in detection. - Assistant
Reproduction matches the report. Detection normalizes the outer
#, leaving) # noqa: ERA001; the “brackets-only” positive case accepts)but not a trailing nested comment. I’ll inspect Ruff’s canonical noqa parser before editing, so the fix can recognize directive syntax consistently rather than relying on an ad-hoc string split. - Assistant
The canonical lexer is private and offset-based, while ERA’s detector intentionally accepts only a line slice. Since this bug is confined to the existing brackets-positive heuristic, the smallest general fix is to let bracket-only commented code carry a trailing nested comment, just as ERA already does for its partial-dictionary positive case. This preserves allowlisting and tokenizer safeguards for prose. I’ll make that source-only change (without modifying tests, per instruction), format it, then rerun focused unit/integration tests and the exact CLI reproduction.
- Assistant
The exact sample now reports only the unsuppressed first-line ERA001; the second line is recognized as code, suppressed by its directive, and RUF100 sees the directive as used. Existing detector unit tests and ERA/RUF interaction coverage pass. I’ll now run the complete eradicate rule test module plus the complete Ruff-rule test module (which includes all RUF100 variants), then inspect the final diff and repository status for unintended changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.