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.
This commit is contained in:
Martin Fischer 2023-02-03 05:05:02 +01:00 committed by Charlie Marsh
parent 187ed874e9
commit a3ffaa5d9b
3 changed files with 18 additions and 18 deletions

View File

@ -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,
})

View File

@ -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');

View File

@ -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,
}