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)
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:
Assistant
I'll start by exploring the repository structure to understand the codebase.
Assistant
This is the ruff repository. The issue is about ERA001 (commented-out code) vs RUF100 (unused noqa directive). Let me explore the relevant source files.
Assistant
I need to make only one tool call at a time.
Assistant
Now let me look at the detection module:
Assistant
Now let me reproduce the issue first. Let me create a test file:
Assistant
Let me build ruff in the background while I explore the code more. First, let me start the build:
Assistant
I've reproduced the issue. Now let me understand how noqa comments are parsed elsewhere in the codebase:
Assistant
Let me look at how noqa directives are lexed to understand the full picture:
Assistant
Let me look at the noqa lexer behavior with a test, and check the git history for recent ERA001 changes:
Assistant
Let me look at the existing ERA001 test fixtures to understand the test format:
Assistant
I see there's already a test case
#import os # noqa: ERA001in the fixture. Let me check the snapshot to see what the expected behavior is.Let me look at the snapshot.
Assistant
Let me check the SimpleTokenizer to understand how
importis tokenized:Assistant
Let me look at how
is_noqa_uncasedworks and understand the noqa detection:Assistant
Let me write a test script to confirm my understanding of the current behavior with various inputs:
Assistant
Let me check what
is_python_whitespaceincludes:Assistant
Let me check what
eat_whitespacedoes in the noqa lexer:Assistant
Now I understand the issue well. Let me test a few edge cases to understand the baseline behavior:
Assistant
Let me look at
lex_codeto understand how codes are parsed:Assistant
Let me look at how noqa directives are collected for RUF100 and how lexer errors are handled:
Assistant
I now have a clear understanding. The issue is a contradiction:
# \t)→ detected as commented-out code (ERA001 fires) because)matches the "brackets-only" positive case# \t) # noqa: ERA001→ NOT detected as code because the trailing# noqa: ERA001text prevents the brackets regex from matching AND) # noqa: ERA001doesn't parse as valid Python
So the noqa on line 2 is "unused" (RUF100), creating the contradiction. Let me verify my understanding of the trimming behavior with a Rust-level test:
Assistant
Now let me implement the fix. Let me open the detection.rs file:
Assistant
Now let me implement the fix. First, I'll add a static regex for detecting a
# noqadirective within a comment:Assistant
Now let me modify the
comment_contains_codefunction to strip the trailing noqa directive:Assistant
Now let me add the
strip_trailing_noqahelper function aftercomment_contains_code:Assistant
Now let me rebuild and test the fix:
Assistant
Build succeeded. Now let me test the original issue case:
Assistant
The contradiction is resolved. Line 1 still gets ERA001 (correct, it's commented-out code with no noqa), and line 2's noqa now properly suppresses the ERA001 (so no RUF100). Let me see the full output:
Assistant
Now let me verify the edge cases I tested earlier:
Assistant
Let me test the existing fixture cases that have noqa directives to ensure they still work correctly:
Assistant
All cases behave correctly:
- Lines with actual code + noqa: ERA001 fires (suppressed by noqa) — no contradiction
- Line 5
# foo bar # noqa: ERA001(not code): correctly gets RUF100 (noqa unused) — no contradiction sincefoo bargenuinely isn't code
Now let me run the existing ERA001 test suite to make sure nothing broke:
Assistant
All tests pass. Let me test more edge cases to ensure robustness:
Assistant
Excellent! All edge cases work correctly:
- Lines 1-5: actual code with various noqa forms → ERA001 fires (suppressed), no RUF100
- Line 6: noqa lists both ERA001 (used) and F401 (non-enabled) → RUF100 correctly reports F401
- Lines 7-8: non-code comments with noqa → RUF100 (correct, no contradiction)
Let me verify
comment_contains_codeis only used by ERA001 and check for any other usages:Assistant
comment_contains_codeis only used by ERA001. Let me run a broader set of related tests (RUF100, noqa) to ensure nothing breaks:Assistant
Let me find and run the RUF100 integration tests:
Assistant
There's a RUF100_5.py fixture that uses ERA001. Let me examine it:
Assistant
Let me look at the RUF100 test setup and run it:
Assistant
The
ruf100_5test enables RUF100, E501, and ERA001 together — exactly the interaction my change affects. Let me run it:Assistant
The
ruf100_5test passes. Let me run all RUF100 tests and the full ruff rule tests to be thorough:Assistant
All 163 ruff rule tests pass. Let me also run the noqa checker tests since this touches the ERA001/RUF100 interaction:
Assistant
Let me search for any other test fixtures that combine ERA001 with noqa directives that might be affected:
Assistant
Let me verify a few more complex code-with-noqa cases that my fix should now handle consistently:
Assistant
The behavior is now fully consistent across all code forms. Let me review my final diff:
Assistant
The diff is clean. Let me verify the regex match slicing is safe and idiomatic by checking how the codebase uses regex matches elsewhere:
Assistant
Let me check the clippy configuration to ensure my code complies:
Assistant
The workspace uses pedantic clippy lints.
indexing_slicing/string_sliceare not enabled. Let me run clippy on the ruff_linter crate to be sure my code passes:Assistant
No clippy warnings related to my file. Let me run clippy again and capture the full output tail to make sure it compiled cleanly.
Assistant
Clippy passes cleanly. Let me test with the exact config from the issue to be thorough:
Assistant
The contradiction is fully resolved with the exact issue config. Let me run a broader test sweep to ensure nothing is broken across the linter:
Assistant
All 2775 lib tests pass. Let me check for any integration test files that might be relevant:
Assistant
All tests pass. Let me do a final review of the complete modified section:
Assistant
The fix is clean and complete. Let me verify the final git status to confirm only the intended file is changed (temp files are in /tmp, not the repo):
Assistant
Let me do a final confirmation run of the exact issue reproduction to verify the fix:
Assistant
The fix is confirmed working. Let me verify one more important edge case — an invalid noqa form (comma after
noqa) to ensure consistency with RUF100:Assistant
Let me verify the alignment with RUF100 by testing whether
# noqa, F401is recognized as a valid noqa (this confirms my terminator choice matches RUF100's recognition):Assistant
This confirms my fix is precisely aligned with RUF100's noqa recognition:
# noqa, F401(comma) → RUF100 reports it as invalid (not recognized), and my regex correctly does NOT strip it (comma isn't a valid terminator)# noqa: F401and# noqa F401→ valid noqas, my regex strips them
The alignment is exact: both RUF100 and my stripping recognize a noqa only when
noqais followed by:,#, whitespace, or end-of-comment. The line-2 RUF100 quirk is pre-existing F401/RUF100 interaction (unrelated — it's actual code, not a comment, so ERA001 never processes it).Let me run the final test sweep before submitting:
Assistant
cargo test only takes one TESTNAME filter. Let me run them separately or use a broader filter.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.