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)
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
I'll start by exploring the repository structure to understand the codebase and locate relevant files.
- Assistant
Let me understand the issue better. The problem is a conflict between ERA001 (commented-out code) and RUF100 (unused noqa directive). Let me explore the ERA001 rule implementation.
- Assistant
Let me explore the ERA001 rule and the RUF100 implementation to understand the conflict.
- Assistant
Now let me look at the
comment_contains_codefunction in the detection module: - Assistant
Let me look at the detection module to understand how
comment_contains_codeworks. - Assistant
Now I understand the issue. The problem is in the
comment_contains_codefunction. For a line like# ) # noqa: ERA001, after stripping the leading#and whitespace, the content becomes) # noqa: ERA001. This content doesn't match thePOSITIVE_CASESregex for brackets (because of the extra text), andparse_modulefails. So ERA001 doesn't fire on this line, making the# noqa: ERA001directive "unused" (RUF100).The fix is to strip inline tool directives (like
# noqa: ...,# type: ignore, etc.) from the comment content before checking if it's code. Let me first create a reproduction script: - Assistant
Let me build ruff and test it.
- Assistant
Let me check if there's a pre-built ruff binary I can use.
- Assistant
Let me try building ruff first.
- Assistant
Let me try a debug build instead, or just run the relevant tests:
- Assistant
Now let me look at the issue more carefully. Let me understand how the detection logic works for these specific lines:
- Assistant
Now let me understand the exact flow. The issue is that for line
# ) # noqa: ERA001, the detection strips the leading#and whitespace, giving) # noqa: ERA001, which doesn't match the bracket regex and can't be parsed as Python. Let me look at how to fix this: - Assistant
Now I understand the issue. For
# \t) # noqa: ERA001, after stripping leading#and whitespace, the text becomes) # noqa: ERA001. The bracket regex doesn't match because of the extra content, andparse_modulefails because) # noqa: ERA001isn't valid Python. So ERA001 doesn't fire, and thenoqadirective is reported as unused.The fix should strip inline tool directives (like
# noqa: ...) from the comment content before checking if it's code. Let me look at the test fixtures: - Assistant
Let me look at the test fixture:
- Assistant
Let me look at the test expectations:
- Assistant
Let me check the snapshot to see the expected test output.
- Assistant
Now let me understand the core issue better. I need to look at the
comment_contains_codefunction. The problem is:# )→ strips leading#and whitespace →)→ matchesPOSITIVE_CASESbracket regex → ERA001 fires# ) # noqa: ERA001→ strips leading#and whitespace →) # noqa: ERA001→ doesn't match bracket regex (because of the extranoqatext), andparse_modulefails → ERA001 does NOT fire → noqa is unused (RUF100)
The fix should be to strip inline tool directives (like
# noqa: ...,# type: ignore, etc.) from the comment content before checking if it's code. Let me look at the detection module and the existing allowlist handling: - Assistant
Let me use the bash terminal to open the file.
- Assistant
Now I understand the issue. Let me look at how the
ALLOWLIST_REGEXpatterns are structured to figure out the best way to strip inline directives: - Assistant
Let me use the bash command to open the file instead.
- Assistant
Let me now carefully understand the issue. The core problem is in the
comment_contains_codefunction:# )→ strips#and whitespace →)→ matches POSITIVE_CASES bracket regex → ERA001 fires# ) # noqa: ERA001→ strips#and whitespace →) # noqa: ERA001→ doesn't match bracket regex → parse_module fails → ERA001 does NOT fire → noqa is unused (RUF100)
The fix should strip inline tool directives (like
# noqa: ...) from the comment content before checking if it's code. This way, the ERA001 detection would fire on both lines, and the# noqa: ERA001directive would correctly suppress it.Let me check how this should work by looking at the ALLOWLIST_REGEX patterns and implementing the fix:
- Assistant
Now let me implement the fix. I need to modify the
comment_contains_codefunction to strip inline tool directives (like# noqa: ...) from the comment content before checking if it's code: - Assistant
Now I need to implement the fix. The approach is to strip inline tool directives (like
# noqa: ...) from the comment content before checking if it's code. Let me modify thecomment_contains_codefunction: - Assistant
Now let me run the tests to verify that the existing tests still pass:
- Assistant
All 13 tests pass. Now let me verify the fix handles the specific issue case correctly by writing a quick test:
- Assistant
Let me add a test case that covers the specific issue to make sure the fix works correctly. First, let me check where the tests are:
- Assistant
Now let me add a test to verify the fix for the specific issue. Let me add it to the existing allowlist test:
- Assistant
Let me add test cases for the inline directive stripping behavior:
- Assistant
Let me add a test for the inline directive stripping behavior:
- Assistant
Now let me run the tests to verify everything works:
- Assistant
The test failed. Let me debug to understand why:
- Assistant
I see the issue. The directive string has a leading space (because there's a space after
#). TheALLOWLIST_REGEXuses^anchor, so# noqa: ERA001produces" noqa: ERA001"which doesn't match because of the leading space. I need to trim the directive before matching: - Assistant
Let me fix the
strip_inline_directivefunction to trim the directive before matching: - Assistant
Wait, I see there's an extra
}at line 97. Let me fix that: - Assistant
I see the extra
}at line 97. Let me remove it: - Assistant
Now let me run the tests again:
- Assistant
All 11 tests pass. Let me also run the full eradicate test suite including the snapshot test:
- Assistant
All 14 eradicate tests pass. Now let me check if the snapshot test still matches - the snapshot might need updating if any of the fixture lines now produce different results:
- Assistant
Let me check if the snapshot was updated:
- Assistant
Good, no snapshot changes. Let me also check the current diff to make sure everything looks right:
- Assistant
I notice there's a duplicate assert on line 456. Let me fix that:
- Assistant
Let me remove the duplicate line:
- Assistant
Let me run all eradicate tests again to make sure everything is good:
- Assistant
All 14 eradicate tests pass. Now let me also run RUF100-related tests since this issue involves the interaction between ERA001 and RUF100:
- Assistant
All RUF100 tests pass too. Let me also run a broader set of tests to make sure nothing else is broken:
- Assistant
All 2776 tests pass. Let me now add a test case to the ERA001 fixture to cover the exact issue scenario:
- Assistant
Now let me add a regression test case to the fixture for the specific issue (brackets with inline noqa). Let me add it at the end:
- Assistant
Let me add the regression test case at the end of the fixture file:
- Assistant
Now let me update the snapshot by running the test:
- Assistant
I see two issues with my test fixture:
def bar():has no body, causing a syntax error- The
# ) # noqa: ERA001line's ERA001 diagnostic is correctly suppressed by noqa, so it doesn't appear
Let me fix the fixture:
- Assistant
Good. Now let me update the snapshot:
- Assistant
The snapshot diff shows exactly what we want:
- Line 116
# )is detected as ERA001 (commented-out code) - Line 117
# ) # noqa: ERA001is NOT shown in diagnostics because it's correctly suppressed by the noqa directive
Let me use insta's update mechanism:
- Line 116
- Assistant
Good, the snapshot was updated. Let me verify it:
- Assistant
All tests pass. Let me verify the snapshot changes:
- Assistant
The snapshot only adds the new test case - line 116
# )is detected as ERA001, while line 117# ) # noqa: ERA001is correctly suppressed by the noqa directive. No existing diagnostics changed. Let me now run the full test suite to confirm everything is good: - Assistant
All tests pass. Let me verify the full count:
- Assistant
All 2776 tests pass. Let me review my final diff to make sure everything is clean:
- Assistant
Let me review the full diff one last time:
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
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →