From f144b9684d9f31c100a06d6c0269cfc3a5d3228b Mon Sep 17 00:00:00 2001 From: InSync Date: Sun, 5 Jan 2025 15:47:01 +0700 Subject: [PATCH] Add a test for overshadowing redirects (#15259) Co-authored-by: Micha Reiser --- crates/ruff_linter/src/rule_redirects.rs | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crates/ruff_linter/src/rule_redirects.rs b/crates/ruff_linter/src/rule_redirects.rs index 2975f7c734..a209c4616a 100644 --- a/crates/ruff_linter/src/rule_redirects.rs +++ b/crates/ruff_linter/src/rule_redirects.rs @@ -136,3 +136,28 @@ static REDIRECTS: LazyLock> = LazyLock::new( ("TCH010", "TC010"), ]) }); + +#[cfg(test)] +mod tests { + use crate::codes::{Rule, RuleGroup}; + use crate::rule_redirects::REDIRECTS; + use strum::IntoEnumIterator; + + /// Tests for rule codes that overlap with a redirect. + #[test] + fn overshadowing_redirects() { + for rule in Rule::iter() { + let (code, group) = (rule.noqa_code(), rule.group()); + + if matches!(group, RuleGroup::Removed) { + continue; + } + + if let Some(redirect_target) = REDIRECTS.get(&*code.to_string()) { + panic!( + "Rule {code} is overshadowed by a redirect, which points to {redirect_target}." + ); + } + } + } +}