astral-sh/ruff · error
RuleSelector::specificity doesn't yet support codes with so
Error message
RuleSelector::specificity doesn't yet support codes with so many characters
What it means
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.
Source
Thrown at crates/ruff_linter/src/rule_selector.rs:462
}
impl RuleSelector {
pub fn specificity(&self) -> Specificity {
match self {
RuleSelector::All => Specificity::All,
RuleSelector::Category(..) => Specificity::Category,
RuleSelector::T => Specificity::LinterGroup,
RuleSelector::C => Specificity::LinterGroup,
RuleSelector::Linter(..) => Specificity::Linter,
RuleSelector::Rule { .. } => Specificity::Rule,
RuleSelector::Prefix { prefix, .. } => {
let prefix: &'static str = prefix.short_code();
match prefix.len() {
1 => Specificity::Prefix1Char,
2 => Specificity::Prefix2Chars,
3 => Specificity::Prefix3Chars,
4 => Specificity::Prefix4Chars,
_ => panic!(
"RuleSelector::specificity doesn't yet support codes with so many characters"
),
}
}
}
}
/// Parse [`RuleSelector`] from a string; but do not follow redirects.
#[cfg(feature = "schemars")]
fn parse_no_redirect(s: &str) -> Result<Self, ParseError> {
// **Changes should be reflected in `from_str` as well**
match s {
"ALL" => Ok(Self::All),
"C" => Ok(Self::C),
"T" => Ok(Self::T),
_ => {
let (linter, code) =
Linter::parse_code(s).ok_or_else(|| ParseError::Unknown(s.to_string()))?;View on GitHub (pinned to 26f38c119c)
Solutions
- Extend the length match arms in specificity to cover longer prefixes
- Use a shorter, well-formed rule prefix in the selector
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/ruff_linter/src/rule_selector.rs:462 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05).
Data as JSON: /api/errors/f25ecfd63c6e1661.
Report an issue: GitHub.