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
Investigating the ERA001/RUF100 conflict: ERA001 fires on line 1 while the
noqa: ERA001on line 2 is flagged as unused. - Assistant
Checking how noqa stripping is handled elsewhere and reviewing PR #25122.
- Assistant
Implementing the fix: strip trailing pragma comments (e.g.
# noqa) before ERA001 code detection so suppression and detection stay consistent. - Assistant
RUF100 is resolved. Updating the test comment to remove the placeholder issue number and adding a combined ERA001+RUF100 test.
- Assistant
This was a real inconsistency between ERA001 and RUF100.
Root cause
ERA001 decided whether a line was commented-out code before stripping trailing pragmas. For:
python# ) # noqa: ERA001the content after the
#was evaluated as) # noqa: ERA001, which is not treated as code (the# noqasuffix breaks the bracket-only heuristic). So:- Line 1 (
# )) → ERA001 fires - Line 2 (
# ) # noqa: ERA001) → ERA001 does not fire, so RUF100 reports thenoqaas unused
Fix
comment_contains_codenow strips trailing pragma comments (viafind_trailing_pragma_offset) before detection. After the fix:- Line 2 is correctly detected as commented-out code
# noqa: ERA001suppresses ERA001 on that line- RUF100 no longer fires for the unused
noqa
With your config, you now get one diagnostic instead of two:
- Line 1 (
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.