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.
# ) # ) # 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.
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:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /ruff, current file: none) bash-$
Assistant
Now let's update
comment_contains_codeto strip trailing noqa suffix before analysis.Assistant
Now let's check the file compiles and verify the fix with the reproduction script.
Assistant
Now let's rebuild and test.
Assistant
The RUF100 false positive is gone. Now line 5 is correctly detected as ERA001 and the noqa suppresses it appropriately, while line 4 still triggers since it has no noqa. Let's verify line 5 without noqa also gets flagged (to confirm detection works), and check edge cases.
Assistant
Both lines are flagged without the noqa, confirming detection works consistently, and with the noqa on line 5, only line 5 is suppressed. Let's run the existing eradicate test suite and the ERA001 fixture file, plus run detection unit tests.
Assistant
All eradicate tests pass. Let's also check the RUF100 tests since they reference an eradicate-related snapshot file.
Assistant
All passing. Now let's run the broader test suite for the linter crate to be safe (or at least related rule modules), and add a changelog/test fixture entry if the project uses one. Let's check if there's a fixture file for ERA001 test we should extend (not required since we can't add tests, but let's check existing conventions).
Assistant
All pass. Let's view the full diff for review.
Assistant
Now let's also run full existing test suite for the
ruff_lintercrate briefly (only affected modules) to double check nothing else broke, and clean up temp files.Assistant
All 2775 tests pass (4 ignored, unrelated). Let's clean up temporary test files.
Assistant
Let's view the final diff once more for a clean review.
Assistant
Checklist Review
-
If an error was reported in the issue description, I have successfully reproduced it. Yes — I created a script mirroring the issue's structure (two consecutive comment lines, the second ending with
# noqa: ERA001) and confirmed withcargo run -p ruffthat ERA001 fires on the first line while RUF100 flags the noqa on the second line as unused, exactly matching the reported behavior. -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. Yes — after the fix, running the same reproduction script shows ERA001 firing on both commented lines equally (when no noqa is present), and when the noqa is added to the second line, it correctly suppresses the diagnostic there instead of leaving it "unused." The RUF100 false positive no longer appears.
-
I have thought about edge cases and made sure my fix handles them as well. Yes — I analyzed:
- Standalone
# noqa: ...comments (unaffected, since they don't contain an embedded#, so the stripping regex doesn't spuriously trigger; they're already filtered viaALLOWLIST_REGEX). - Existing fixture case
#import os # noqa: ERA001— still detected as code since stripping just removes the suffix before parsing, same result as before. - Dictionary-entry case
# "key1": 123, # noqa: ERA001— still matches after stripping (the existing regex's optional trailing-comment allowance becomes redundant but harmless). - Comments that merely contain the substring
noqainside a quoted string (not preceded by whitespace before#) — correctly not stripped, preserving prior behavior. - Case-insensitivity and optional rule codes in the
noqadirective are both handled by the regex.
- Standalone
-
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. Yes — ran
cargo test -p ruff_lintertargetingeradicate,ruf100, andcomment_contains_code, and finally the fullruff_lintercrate test suite (2775 passed, 4 ignored/unrelated, 0 failed).
The fix is minimal and localized to
crates/ruff_linter/src/rules/eradicate/detection.rs, stripping a trailing inlinenoqadirective before determining whether a comment resembles commented-out code, which resolves the ERA001/RUF100 conflict described in the issue without affecting other behavior.-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →