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.
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)
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:
Assistant
Let me start by understanding the issue. The problem is about two rules conflicting:
- ERA001 - detects commented-out code
- RUF100 - detects unused
noqadirectives
The scenario is:
python# ) # ) # noqa: ERA001- Line 1:
# )is detected as commented-out code (ERA001) - Line 2:
# ) # noqa: ERA001- the is detected as unused (RUF100) because it's a comment that is not code
Assistant
Let me first reproduce the issue by creating a test file and running ruff on it.
Assistant
Now let me run ruff on this file with the configuration from the issue.
Assistant
The build is in progress. Let me wait for it to complete
Assistant
Now let me create a proper config and test
Assistant
Good, I've reproduced the issue. Now let me understand it better. Let me test if ERA001 fires on line 4 without the noqa
Assistant
So ERA001 fires on line 4 without noqa. The issue is that RUF100 says noqa is unused even though ERA001 would fire on line 4. Let me explore the relevant source
Assistant
Let me look at the ERA001 (eradicate) rule and the RUF100 (ruff) rule.
Assistant
Let me make a single tool call.
Assistant
Let me look at the eradicate rules and the ruff RUF100 rule.
Assistant
Let me look at the ERA001 rule and the RUF100 rule:
Assistant
Now let me look at the detection logic
comment_contains_codeto understand how it detects commented-out code.Assistant
Now let me look at the RUF100 rule (
unused_noqa.rs):Assistant
Let me find the actual detection logic for unused noqa directives. Let me search for where the unused noqa detection happens.
Assistant
Let me look at the noqa checker which implements RUF100
Assistant
Now I understand the issue. Let me verify my hypothesis by testing what
comment_contains_codereturns for the problematic line.Assistant
Let me look at how
NoqaDirectivesextracts directives from comments to understand the pattern.Assistant
Let me look at
noqa.rsfor how noqa directives are extracted.Assistant
Let me search for
lex_inline_noqato understand how inline noqa directives are extractedAssistant
Let me look at the lex_inline_noqa function.
Assistant
Let me continue reading the lex_inline_noqa function.
Assistant
Now I understand the issue better. Let me look at how the noqa suffix is handled elsewhere, and think about the fix.
The problem is in
comment_contains_codeincrates/ruff_linter/src/rules/eradicate/detection.rs. When the line is# ) # noqa: ERA001, after stripping the#prefix, we get) # noqa: ERA001. The# noqa: ERA001suffix causes the function to return false, even though)alone would be detected as commented-out code.Let me look for any utility that strips noqa from a line.
Assistant
Let me look at
is_noqa_uncasedand see if there's already a way to strip noqa fromAssistant
Now I have a good understanding of the issue. Let me implement the fix in
comment_contains_code. The problem is that when a line contains# noqa: ERA001as a suffix, the# noqapart preventscomment_contains_codefrom recognizing the preceding content as code.Let me look at the function once more and then make the edit.
Assistant
Let me use the correct open command.
Assistant
Now let me implement the fix. I'll modify
comment_contains_codeto strip trailing# noqadirectives before checking if the comment contains code.Assistant
Let me fix the duplicate line and add the
strip_trailing_noqafunction.Assistant
Now let me add the
strip_trailing_noqafunction before `comment_containsAssistant
Let me build and test the change.
Assistant
Let me test with the original example
Assistant
Now let me verify that ERA001 is firing on line 4 but being suppressed by the noqa
Assistant
The fix is working. Now let me test edge cases to make sure:
# noqa: ERA001alone should NOT be detected as commented-out code# x = 1 # noqa: ERA001should be detected as commented-out code- The ALLOWLIST_REGEX still works properly
Assistant
Let me check if
# x = 1 # noqa: ERA001is actually being detected.Assistant
Line 2 has a noqa directive that suppresses ERA001. Let me verify:
Assistant
Let me run the existing tests to make sure nothing is broken
Assistant
Let me also run the broader set of tests related to ERA and RUF100.
Assistant
Let me also run the RUF100 tests
Assistant
Let me run the broader ruff test suite
Assistant
Let me check if there are specific RUF100 snapshot tests
Assistant
Let me look at the RUF100 test fixtures to understand what cases are already
Assistant
Let me run the RUF100 test specifically to ensure snapshots pass
Assistant
Let me also ensure all ERA/eradicate tests pass
Assistant
Let me search for the right test names
Assistant
Let me now run a broader set of tests to make sure nothing is broken
Assistant
All 2775 tests pass. Let me now do a final verification of the fix with the exact case from the issue
Assistant
The fix is working correctly. Let me verify the final state of the changed
Assistant
Let me also run the integration tests for ERA001 and RUF100 to make sure the snapshot tests pass
Assistant
Let me check what the actual integration test names are
Assistant
Let me check if any snapshots need to be updated by running the full test suite
Assistant
All tests pass. Let me also check if there are any other test suites I should run.
Assistant
Let me improve the
strip_trailing_noqafunction to handle edge cases where there might be multiple#in the line. I should look for the# noqapattern specifically, not just the last#.Assistant
Let me build and test
Assistant
Now let me verify with various edge cases
Assistant
Let me verify with both ERA and RUF to confirm the noqa is being used
Assistant
The results look correct. Let me now run the full test suite to make sure everything passes.
Assistant
Let me do a final verification with the exact scenario from the issue
Assistant
The fix is working correctly. Let me review the final state of my changes.
Assistant
The fix is complete. Let me now submit.
Checklist Review
-
Reproduced the error: ✅ Yes, I confirmed the original behavior where
ERA001fired on line 3 andRUF100fired on line 4 saying thenoqa: ERA001was unused. -
Confirmed fix resolves the error: ✅ After the fix,
RUF100no longer fires on line 4. The# noqa: ERA001is now correctly recognized as being used (it suppresses ERA001 on line 4, where the)is correctly detected as commented-out code). -
Thought about edge cases: ✅ I considered:
- Standalone
# noqa: ERA001(no code) → still correctly not flagged as code # ) # noqa(blanket noqa) → correctly detected as code, noqa suppresses# x = 1 # noqa: ERA001→ correctly detected as code, noqa suppresses# ) # not noqa→ not a valid noqa, existing behavior preserved# ) # noqa: ERA001 # another comment→ correctly strips the noqa from the line- Multiple
#in the line → function searches all occurrences
- Standalone
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.