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.
python# ) # ) # noqa: ERA001Found commented-out code (ERA001) [Ln 1, Col 4] Unused
noqadirective (unused:ERA001) (RUF100) [Ln 2, Col 10]tomlpreview = 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:
- Assistant
I’ll first locate the ERA001 and
noqahandling implementations and their tests, then reproduce the contradictory diagnostics with the repository’s CLI or targeted test harness. After identifying whether suppression metadata or comment classification is at fault, I’ll make the narrowest source change and run the affected test suites. - Assistant
ripgrepis unavailable in this environment, so I’ll usegrep/findto locate the rule and fixture coverage. - Assistant
I found the token-level ERA001 implementation. I’ll inspect it alongside the token checker and
noqaextraction/suppression pipeline to understand why the directive on the second line cannot suppress the first-line diagnostic yet is itself considered unused. - Assistant
The ERA rule independently classifies each full source line, so the key anomaly likely comes from its heuristic rather than suppression routing: a bare closing parenthesis is normally non-code, but nearby comments may alter logical-line parsing. I’ll inspect
comment_contains_codeand ERA fixtures, then run the exact sample through the local Ruff binary. - Assistant
The reproduction matches the report. The classifier deliberately treats bracket-only fragments (including
)) as code to support commented multiline calls, but its bracket-only positive regex rejects the same fragment when followed by an inline comment such as# noqa. That makes ERA001 disappear before normalnoqasuppression can record it as used.The narrow fix is to let the bracket-fragment heuristic accept a trailing inline comment, consistent with another existing positive pattern (partial dictionaries) and Python syntax. I’ll inspect fixture expectations and parser/noqa range behavior before editing, especially variants such as
# ) # explanationand nested hashes. - Assistant
The fixture already demonstrates the intended convention with
# try: # with comment, and partial-dictionary detection explicitly permits trailing comments. I’ll apply the same optional trailing-comment suffix only to the bracket-only pattern. This preserves all prose/parser heuristics while making# ) # noqa: ERA001first classify as ERA001, after which the existing line-based suppression machinery will suppress it and mark the directive used. - Assistant
The edit command failed because only
python3is installed; consequently, the passing tests were still against the unchanged source. I’ll now perform the edit withpython3, verify the diff, and rerun both targeted unit tests and the exact CLI reproduction. - Assistant
The exact sample is now resolved: only the unsuppressed first-line ERA001 remains, with no RUF100. The focused ERA tests pass.
I’ll do additional black-box edge checks to ensure prose containing brackets remains ignored, bracket fragments with ordinary trailing comments are detected, and blanket/specific
noqaforms both suppress correctly. Then I’ll run the linter’s broadernoqa-related tests and inspect the final repository state. - Assistant
The broader
noqasuite passes (91 tests). My mixed edge input surfaced two pre-existing ERA heuristics: prose ending in a second# commentcan parse as Python after the second hash, and[section]parses as an expression. Neither matches the changed bracket-only regex because they contain identifiers. To avoid conflating those existing classifications with this fix, I’ll run isolated controls matching the established non-code fixture (# This is a (real) comment.) and bracket-only variants, and verify fix-mode does not remove a now-used directive. - Assistant
The isolated controls confirm the intended boundary: established prose remains ignored; an unsuppressed bracket fragment with trailing explanation is ERA001; specific and blanket directives suppress it; and
--fixleaves the used directive intact. I’ll run the completeruff_linterlibrary test suite as the final regression check before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.