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.
# ) # ) # 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.
- Assistant
Investigating the ERA001 vs RUF100 conflict for this edge case in the Ruff codebase.
- Assistant
Reproducing the issue, then implementing a fix.
- Assistant
Implementing the fix: strip trailing
noqadirectives before ERA001 detection so suppression and RUF100 stay consistent. - Assistant
Fix verified. Running unit tests and prek on changed files.
- Assistant
This is a real inconsistency between
ERA001andRUF100, and the root cause is how trailingnoqacomments affect detection.What was happening
For
# ) # noqa: ERA001,comment_contains_codestripped the line to) # noqa: ERA001. That no longer matched the bracket-only heuristic (^[()\[\]{}\s]+$), soERA001did not fire on that line.RUF100then reported thenoqaas unused — while the previous line# )still triggeredERA001.For
# "key1": 123, # noqa: ERA001, the partial-dict regex already allows a trailing# ..., so detection and suppression stayed in sync. Bracket-only lines like# )did not.The fix
comment_contains_codenow strips trailing inlinenoqadirectives before analyzing the comment body. That makes# ) # noqa: ERA001evaluate as# ), so:ERA001still fires on the suppressed line (and is correctly suppressed by )
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.