Skip to content

Commit d08cde0

Browse files
authored
[eradicate] Avoid flagging ruff:ignore comments as code (ERA001) (#25537)
Summary -- Fixes #25535 by treating `ruff:ignore` and `ruff:file-ignore` comments in the same way as `ruff:enable` and `ruff:disable` comments. Test Plan -- New tests based on the issue
1 parent 4828dec commit d08cde0

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

crates/ruff_linter/resources/test/fixtures/eradicate/ERA001.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ class A():
9292

9393

9494
# Regression tests for https://github.com/astral-sh/ruff/issues/19713,
95-
# https://github.com/astral-sh/ruff/issues/24186
95+
# https://github.com/astral-sh/ruff/issues/24186,
96+
# https://github.com/astral-sh/ruff/issues/25535
9697

9798
# ty: ignore
99+
# ruff: ignore[ARG001]
100+
# ruff: file-ignore[ARG001]
98101

99102
# mypy: ignore-errors
100103
# pyright: ignore-errors

crates/ruff_linter/src/rules/eradicate/detection.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static ALLOWLIST_REGEX: LazyLock<Regex> = LazyLock::new(|| {
2222
# Case-sensitive
2323
pyright
2424
| pyrefly
25-
| ruff\s*:\s*(disable|enable)
25+
| ruff\s*:\s*(disable|enable|ignore|file-ignore)
2626
| mypy:
2727
| type:\s*ignore
2828
| ty:\s*ignore
@@ -155,6 +155,9 @@ mod tests {
155155
assert!(!comment_contains_code("\t# testing: Foo Bar Baz", &[]));
156156
assert!(!comment_contains_code("# ruff: disable[E501]", &[]));
157157
assert!(!comment_contains_code("#ruff:enable[E501, F84]", &[]));
158+
assert!(!comment_contains_code("# ruff: ignore[ARG001]", &[]));
159+
assert!(!comment_contains_code("#ruff:ignore[ARG001]", &[]));
160+
assert!(!comment_contains_code("#ruff:file-ignore[ARG001]", &[]));
158161
assert!(!comment_contains_code(
159162
"# pylint: disable=redefined-outer-name",
160163
&[]

0 commit comments

Comments
 (0)