diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF102.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF102.py index a7385d177f..607735fb5f 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF102.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF102.py @@ -16,3 +16,5 @@ from collections import defaultdict # noqa: INVALID100, INVALID200, F401 from itertools import chain # noqa: E402, INVALID300, F401 # Test for mixed code types import json # noqa: E402, INVALID400, V100 +# Test for rule redirects +import pandas as pd # noqa: TCH002 diff --git a/crates/ruff_linter/src/rules/ruff/rules/invalid_rule_code.rs b/crates/ruff_linter/src/rules/ruff/rules/invalid_rule_code.rs index 734a544b72..2f1344dce0 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/invalid_rule_code.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/invalid_rule_code.rs @@ -6,6 +6,7 @@ use crate::checkers::ast::LintContext; use crate::noqa::{Code, Directive}; use crate::noqa::{Codes, NoqaDirectives}; use crate::registry::Rule; +use crate::rule_redirects::get_redirect_target; use crate::{AlwaysFixableViolation, Edit, Fix}; /// ## What it does @@ -81,7 +82,8 @@ pub(crate) fn invalid_noqa_code( fn code_is_valid(code: &Code, external: &[String]) -> bool { let code_str = code.as_str(); - Rule::from_code(code_str).is_ok() || external.iter().any(|ext| code_str.starts_with(ext)) + Rule::from_code(get_redirect_target(code_str).unwrap_or(code_str)).is_ok() + || external.iter().any(|ext| code_str.starts_with(ext)) } fn all_codes_invalid_diagnostic( diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF102_RUF102.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF102_RUF102.py.snap index 0de2b9a2c8..9c2cb5a1f7 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF102_RUF102.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF102_RUF102.py.snap @@ -176,6 +176,7 @@ help: Remove the rule code 16 + from itertools import chain # noqa: E402, F401 17 | # Test for mixed code types 18 | import json # noqa: E402, INVALID400, V100 +19 | # Test for rule redirects RUF102 [*] Invalid rule code in `# noqa`: INVALID400 --> RUF102.py:18:28 @@ -184,6 +185,8 @@ RUF102 [*] Invalid rule code in `# noqa`: INVALID400 17 | # Test for mixed code types 18 | import json # noqa: E402, INVALID400, V100 | ^^^^^^^^^^ +19 | # Test for rule redirects +20 | import pandas as pd # noqa: TCH002 | help: Remove the rule code 15 | # Test for preserving valid codes when fixing @@ -191,6 +194,8 @@ help: Remove the rule code 17 | # Test for mixed code types - import json # noqa: E402, INVALID400, V100 18 + import json # noqa: E402, V100 +19 | # Test for rule redirects +20 | import pandas as pd # noqa: TCH002 RUF102 [*] Invalid rule code in `# noqa`: V100 --> RUF102.py:18:40 @@ -199,6 +204,8 @@ RUF102 [*] Invalid rule code in `# noqa`: V100 17 | # Test for mixed code types 18 | import json # noqa: E402, INVALID400, V100 | ^^^^ +19 | # Test for rule redirects +20 | import pandas as pd # noqa: TCH002 | help: Remove the rule code 15 | # Test for preserving valid codes when fixing @@ -206,3 +213,5 @@ help: Remove the rule code 17 | # Test for mixed code types - import json # noqa: E402, INVALID400, V100 18 + import json # noqa: E402, INVALID400 +19 | # Test for rule redirects +20 | import pandas as pd # noqa: TCH002 diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules.snap index 4c5525b8fa..e9b7890bf3 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__invalid_rule_code_external_rules.snap @@ -156,6 +156,7 @@ help: Remove the rule code 16 + from itertools import chain # noqa: E402, F401 17 | # Test for mixed code types 18 | import json # noqa: E402, INVALID400, V100 +19 | # Test for rule redirects RUF102 [*] Invalid rule code in `# noqa`: INVALID400 --> RUF102.py:18:28 @@ -164,6 +165,8 @@ RUF102 [*] Invalid rule code in `# noqa`: INVALID400 17 | # Test for mixed code types 18 | import json # noqa: E402, INVALID400, V100 | ^^^^^^^^^^ +19 | # Test for rule redirects +20 | import pandas as pd # noqa: TCH002 | help: Remove the rule code 15 | # Test for preserving valid codes when fixing @@ -171,3 +174,5 @@ help: Remove the rule code 17 | # Test for mixed code types - import json # noqa: E402, INVALID400, V100 18 + import json # noqa: E402, V100 +19 | # Test for rule redirects +20 | import pandas as pd # noqa: TCH002