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: Ruff flags commented-out code on one line but treats the
noqaon the next as unused. I'll trace how both rules handle this pattern. - Assistant
Reproducing the issue to confirm the root cause.
- Assistant
Root cause: trailing
# noqabreaks ERA001 detection on the same line (e.g.# )isn't recognized as code), while RUF100 still flags the noqa as unused. Stripping trailing pragmas before analysis should fix it. - Assistant
Adding a regression test and verifying the fix:
- Assistant
RUF100 is resolved. Running the full test suite for these rules:
- Assistant
This is a real inconsistency between ERA001 and RUF100. I fixed it.
Root cause
For a line like
# ) # noqa: ERA001, ERA001 runscomment_contains_codeon the entire line. The trailing# noqa: ERA001prevents the bracket-only heuristic (^[()\[\]{}\s]+$) from matching, so ERA001 does not fire on that line.But on the previous line
# ), there is no noqa, so ERA001 does fire.RUF100 then correctly reports the noqa as unused — because ERA001 never produced a diagnostic to suppress.
Same content, opposite conclusions.
Fix
Before analyzing whether a comment contains code, strip any trailing pragma (using the existing
find_trailing_pragma_offsethelper):pub(crate) fn comment_contains_code(line: &str, task_tags: &[String]) -> bool { // Ignore trailing pragma comments (e.g., `# x = 1 # noqa: ERA001`), so that the // content before the pragma is analyzed consistently regardless of whether a // suppression directive is present. let line = if let Some(offset) = find_trailing_pragma_offset(line) { line[..offset].trim_end() } else { line }; let line = line .trim_start_matches(|char| char == '#' || is_python_whitespace(char)) .trim_end();
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.