Schrödinger's comment: it is both commented-out code and a comment that is not code…
- User
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)
Interface
No new interfaces are introduced.
- Assistant
Let me reproduce the issue first.
- Assistant
Now update
detection.rsto strip a trailing noqa directive before analysis: - Assistant
Now add test cases to the fixtures. First check the current ERA001 snapshot:
- Assistant
The noqa suppression is honored in fixture tests. Let me find the issue number for the regression test reference:
- Assistant
Now add the RUF100 interplay case:
- Assistant
Also add unit tests to
detection.rs: - Assistant
Now run the ERA and RUF100 tests:
- Assistant
Both fixes verified. Now run the full
ruff_lintertest suite to catch regressions elsewhere: - Assistant
All 2775 tests pass with only the two expected snapshot updates. Verify the original reproduction end-to-end:
- Assistant
The Schrödinger case is resolved: line 1 fires ERA001, line 2's noqa now suppresses it, and RUF100 no longer reports the directive as unused. Now clippy and prek:
- Assistant
The fix is complete. Here's a summary:
Problem
For
# ) # noqa: ERA001, the trailing# noqadirective was fed into ERA001's code-detection heuristics as part of the comment text.) # noqa: ERA001no longer matched the brackets-only positive case (nor parsed as Python), so ERA001 didn't fire — and RUF100 then reported thenoqaas unused. Meanwhile the identical line without the directive was flagged, making the suppression impossible to write correctly.Fix
crates/ruff_linter/src/rules/eradicate/detection.rs—comment_contains_codenow strips a trailing inlinenoqadirective (located with the existing noqa lexer, rather than a new ad-hoc regex) before running detection, so a line is analyzed identically to its unsuppressed form. This fixes the whole class of cases where the directive text broke a heuristic — brackets (), multiline assignments (), line continuations, etc.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.