[`eradicate`] Fix `ERA001`/`RUF100` conflict when `noqa` is on commented-out code (#25414)
## Summary Fixes #25386. For commented-out code with a trailing `# noqa: ERA001`, Ruff could report both `ERA001` on one line and `RUF100` (unused `ERA001`) on the next — which is inconsistent. `ERA001` uses `comment_contains_code()` to decide if a comment is code. That function was analyzing the full comment body, including trailing `# noqa: ERA001`. The allowlist treats `noqa` as non-code, so lines like `# ) # noqa: ERA001` were skipped by `ERA001` while a nearby line without `noqa` still triggered `ERA001`. That made the `noqa` look unused to `RUF100`. The fix strips a trailing inline `# noqa...` before ERA001’s code detection, so the comment is evaluated on its code portion only (e.g. `)`). Suppression and detection then agree: `noqa: ERA001` is used when it suppresses a real `ERA001` match. the repro now shows ERA001 diagnostics without incorrectly flagging the paired noqa: ERA001 as unused. ## Test Plan - Added unit tests in `detection.rs` for `# ) # noqa: ERA001` and `# \t( # noqa: ERA001` - Extended `RUF100_5.py` with regression cases from #25386 - Ran `cargo test -p ruff_linter ruf100_5` (snapshot updated) - Ran `cargo test -p ruff_linter comment_contains_code_with_multiline` - Ran `uvx prek run --files` on the three changed files
V
Venkata Srivaibhav Nukaraju committed
b427926f2014abf7204cc433d6cb5204c8bbc49c
Parent: db5aa0a
Committed by GitHub <noreply@github.com>
on 5/28/2026, 2:34:06 PM