diff --git a/ruff_cli/src/commands/linter.rs b/ruff_cli/src/commands/linter.rs index d392171c20..2620912f81 100644 --- a/ruff_cli/src/commands/linter.rs +++ b/ruff_cli/src/commands/linter.rs @@ -15,7 +15,7 @@ pub fn linter(format: HelpFormat) { .upstream_categories() .unwrap() .iter() - .map(|UpstreamCategory(prefix, ..)| prefix) + .map(|UpstreamCategory(prefix, ..)| prefix.as_ref()) .join("/"), prefix => prefix.to_string(), }; @@ -31,7 +31,7 @@ pub fn linter(format: HelpFormat) { categories: linter_info.upstream_categories().map(|cats| { cats.iter() .map(|UpstreamCategory(prefix, name, ..)| LinterCategoryInfo { - prefix, + prefix: prefix.as_ref(), name, }) .collect() diff --git a/ruff_dev/src/generate_rules_table.rs b/ruff_dev/src/generate_rules_table.rs index dfa78d8c84..df1277086c 100644 --- a/ruff_dev/src/generate_rules_table.rs +++ b/ruff_dev/src/generate_rules_table.rs @@ -53,7 +53,7 @@ pub fn main(args: &Args) -> Result<()> { .upstream_categories() .unwrap() .iter() - .map(|UpstreamCategory(prefix, ..)| prefix) + .map(|UpstreamCategory(prefix, ..)| prefix.as_ref()) .join(", "), prefix => prefix.to_string(), }; @@ -94,11 +94,11 @@ pub fn main(args: &Args) -> Result<()> { } if let Some(categories) = linter.upstream_categories() { - for UpstreamCategory(prefix, name, selector) in categories { - table_out.push_str(&format!("#### {name} ({prefix})")); + for UpstreamCategory(prefix, name) in categories { + table_out.push_str(&format!("#### {name} ({})", prefix.as_ref())); table_out.push('\n'); table_out.push('\n'); - generate_table(&mut table_out, selector); + generate_table(&mut table_out, prefix); } } else { generate_table(&mut table_out, &linter); diff --git a/src/registry.rs b/src/registry.rs index 08531c5373..515d5f1ba0 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -644,21 +644,21 @@ pub trait RuleNamespace: Sized { fn url(&self) -> Option<&'static str>; } -/// The prefix, name and selector for an upstream linter category. -pub struct UpstreamCategory(pub &'static str, pub &'static str, pub RuleCodePrefix); +/// The prefix and name for an upstream linter category. +pub struct UpstreamCategory(pub RuleCodePrefix, pub &'static str); impl Linter { pub fn upstream_categories(&self) -> Option<&'static [UpstreamCategory]> { match self { Linter::Pycodestyle => Some(&[ - UpstreamCategory("E", "Error", RuleCodePrefix::E), - UpstreamCategory("W", "Warning", RuleCodePrefix::W), + UpstreamCategory(RuleCodePrefix::E, "Error"), + UpstreamCategory(RuleCodePrefix::W, "Warning"), ]), Linter::Pylint => Some(&[ - UpstreamCategory("PLC", "Convention", RuleCodePrefix::PLC), - UpstreamCategory("PLE", "Error", RuleCodePrefix::PLE), - UpstreamCategory("PLR", "Refactor", RuleCodePrefix::PLR), - UpstreamCategory("PLW", "Warning", RuleCodePrefix::PLW), + UpstreamCategory(RuleCodePrefix::PLC, "Convention"), + UpstreamCategory(RuleCodePrefix::PLE, "Error"), + UpstreamCategory(RuleCodePrefix::PLR, "Refactor"), + UpstreamCategory(RuleCodePrefix::PLW, "Warning"), ]), _ => None, }