From a3ffaa5d9bcc00fb03f6e03b2c7278117ba7d6f3 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Fri, 3 Feb 2023 05:05:02 +0100 Subject: [PATCH] refactor: Rename LinterCategory to UpstreamCategory LinterCategory was somewhat misnamed since it's not actually a category for linters but rather a category for upstream lints. Since we want to introduce our own categories, naming the type UpstreamCategory is more clear. --- ruff_cli/src/commands/linter.rs | 10 +++++----- ruff_dev/src/generate_rules_table.rs | 10 +++++----- src/registry.rs | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ruff_cli/src/commands/linter.rs b/ruff_cli/src/commands/linter.rs index a083c54126..d392171c20 100644 --- a/ruff_cli/src/commands/linter.rs +++ b/ruff_cli/src/commands/linter.rs @@ -2,7 +2,7 @@ use itertools::Itertools; use serde::Serialize; use strum::IntoEnumIterator; -use ruff::registry::{Linter, LinterCategory, RuleNamespace}; +use ruff::registry::{Linter, RuleNamespace, UpstreamCategory}; use crate::args::HelpFormat; @@ -12,10 +12,10 @@ pub fn linter(format: HelpFormat) { for linter in Linter::iter() { let prefix = match linter.common_prefix() { "" => linter - .categories() + .upstream_categories() .unwrap() .iter() - .map(|LinterCategory(prefix, ..)| prefix) + .map(|UpstreamCategory(prefix, ..)| prefix) .join("/"), prefix => prefix.to_string(), }; @@ -28,9 +28,9 @@ pub fn linter(format: HelpFormat) { .map(|linter_info| LinterInfo { prefix: linter_info.common_prefix(), name: linter_info.name(), - categories: linter_info.categories().map(|cats| { + categories: linter_info.upstream_categories().map(|cats| { cats.iter() - .map(|LinterCategory(prefix, name, ..)| LinterCategoryInfo { + .map(|UpstreamCategory(prefix, name, ..)| LinterCategoryInfo { prefix, name, }) diff --git a/ruff_dev/src/generate_rules_table.rs b/ruff_dev/src/generate_rules_table.rs index d8c05f8a36..dfa78d8c84 100644 --- a/ruff_dev/src/generate_rules_table.rs +++ b/ruff_dev/src/generate_rules_table.rs @@ -2,7 +2,7 @@ use anyhow::Result; use itertools::Itertools; -use ruff::registry::{Linter, LinterCategory, Rule, RuleNamespace}; +use ruff::registry::{Linter, Rule, RuleNamespace, UpstreamCategory}; use strum::IntoEnumIterator; use crate::utils::replace_readme_section; @@ -50,10 +50,10 @@ pub fn main(args: &Args) -> Result<()> { for linter in Linter::iter() { let codes_csv: String = match linter.common_prefix() { "" => linter - .categories() + .upstream_categories() .unwrap() .iter() - .map(|LinterCategory(prefix, ..)| prefix) + .map(|UpstreamCategory(prefix, ..)| prefix) .join(", "), prefix => prefix.to_string(), }; @@ -93,8 +93,8 @@ pub fn main(args: &Args) -> Result<()> { table_out.push('\n'); } - if let Some(categories) = linter.categories() { - for LinterCategory(prefix, name, selector) in categories { + if let Some(categories) = linter.upstream_categories() { + for UpstreamCategory(prefix, name, selector) in categories { table_out.push_str(&format!("#### {name} ({prefix})")); table_out.push('\n'); table_out.push('\n'); diff --git a/src/registry.rs b/src/registry.rs index c1d54c999f..08531c5373 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -645,20 +645,20 @@ pub trait RuleNamespace: Sized { } /// The prefix, name and selector for an upstream linter category. -pub struct LinterCategory(pub &'static str, pub &'static str, pub RuleCodePrefix); +pub struct UpstreamCategory(pub &'static str, pub &'static str, pub RuleCodePrefix); impl Linter { - pub fn categories(&self) -> Option<&'static [LinterCategory]> { + pub fn upstream_categories(&self) -> Option<&'static [UpstreamCategory]> { match self { Linter::Pycodestyle => Some(&[ - LinterCategory("E", "Error", RuleCodePrefix::E), - LinterCategory("W", "Warning", RuleCodePrefix::W), + UpstreamCategory("E", "Error", RuleCodePrefix::E), + UpstreamCategory("W", "Warning", RuleCodePrefix::W), ]), Linter::Pylint => Some(&[ - LinterCategory("PLC", "Convention", RuleCodePrefix::PLC), - LinterCategory("PLE", "Error", RuleCodePrefix::PLE), - LinterCategory("PLR", "Refactor", RuleCodePrefix::PLR), - LinterCategory("PLW", "Warning", RuleCodePrefix::PLW), + UpstreamCategory("PLC", "Convention", RuleCodePrefix::PLC), + UpstreamCategory("PLE", "Error", RuleCodePrefix::PLE), + UpstreamCategory("PLR", "Refactor", RuleCodePrefix::PLR), + UpstreamCategory("PLW", "Warning", RuleCodePrefix::PLW), ]), _ => None, }