{"record":{"id":"f25ecfd63c6e1661","repo":"astral-sh/ruff","slug":"ruleselector-specificity-doesn-t-yet-support-code","errorCode":null,"errorMessage":"RuleSelector::specificity doesn't yet support codes with so many characters","messagePattern":"RuleSelector::specificity doesn't yet support codes with so many characters","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/rule_selector.rs","lineNumber":462,"sourceCode":"}\n\nimpl RuleSelector {\n    pub fn specificity(&self) -> Specificity {\n        match self {\n            RuleSelector::All => Specificity::All,\n            RuleSelector::Category(..) => Specificity::Category,\n            RuleSelector::T => Specificity::LinterGroup,\n            RuleSelector::C => Specificity::LinterGroup,\n            RuleSelector::Linter(..) => Specificity::Linter,\n            RuleSelector::Rule { .. } => Specificity::Rule,\n            RuleSelector::Prefix { prefix, .. } => {\n                let prefix: &'static str = prefix.short_code();\n                match prefix.len() {\n                    1 => Specificity::Prefix1Char,\n                    2 => Specificity::Prefix2Chars,\n                    3 => Specificity::Prefix3Chars,\n                    4 => Specificity::Prefix4Chars,\n                    _ => panic!(\n                        \"RuleSelector::specificity doesn't yet support codes with so many characters\"\n                    ),\n                }\n            }\n        }\n    }\n\n    /// Parse [`RuleSelector`] from a string; but do not follow redirects.\n    #[cfg(feature = \"schemars\")]\n    fn parse_no_redirect(s: &str) -> Result<Self, ParseError> {\n        // **Changes should be reflected in `from_str` as well**\n        match s {\n            \"ALL\" => Ok(Self::All),\n            \"C\" => Ok(Self::C),\n            \"T\" => Ok(Self::T),\n            _ => {\n                let (linter, code) =\n                    Linter::parse_code(s).ok_or_else(|| ParseError::Unknown(s.to_string()))?;","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/rule_selector.rs#L444-L480","documentation":"Panics inside RuleSelector::specificity because a Prefix selector's code is longer than any length the match on prefix.len() covers. The specificity ladder is only implemented for prefixes up to a fixed character count, so an over-long rule prefix reaches an unhandled arm.","triggerScenarios":"Thrown at crates/ruff_linter/src/rule_selector.rs:462 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Extend the length match arms in specificity to cover longer prefixes","Use a shorter, well-formed rule prefix in the selector"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}