mirror of https://github.com/astral-sh/ruff
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:
parent
187ed874e9
commit
a3ffaa5d9b
|
|
@ -2,7 +2,7 @@ use itertools::Itertools;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
use ruff::registry::{Linter, LinterCategory, RuleNamespace};
|
use ruff::registry::{Linter, RuleNamespace, UpstreamCategory};
|
||||||
|
|
||||||
use crate::args::HelpFormat;
|
use crate::args::HelpFormat;
|
||||||
|
|
||||||
|
|
@ -12,10 +12,10 @@ pub fn linter(format: HelpFormat) {
|
||||||
for linter in Linter::iter() {
|
for linter in Linter::iter() {
|
||||||
let prefix = match linter.common_prefix() {
|
let prefix = match linter.common_prefix() {
|
||||||
"" => linter
|
"" => linter
|
||||||
.categories()
|
.upstream_categories()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|LinterCategory(prefix, ..)| prefix)
|
.map(|UpstreamCategory(prefix, ..)| prefix)
|
||||||
.join("/"),
|
.join("/"),
|
||||||
prefix => prefix.to_string(),
|
prefix => prefix.to_string(),
|
||||||
};
|
};
|
||||||
|
|
@ -28,9 +28,9 @@ pub fn linter(format: HelpFormat) {
|
||||||
.map(|linter_info| LinterInfo {
|
.map(|linter_info| LinterInfo {
|
||||||
prefix: linter_info.common_prefix(),
|
prefix: linter_info.common_prefix(),
|
||||||
name: linter_info.name(),
|
name: linter_info.name(),
|
||||||
categories: linter_info.categories().map(|cats| {
|
categories: linter_info.upstream_categories().map(|cats| {
|
||||||
cats.iter()
|
cats.iter()
|
||||||
.map(|LinterCategory(prefix, name, ..)| LinterCategoryInfo {
|
.map(|UpstreamCategory(prefix, name, ..)| LinterCategoryInfo {
|
||||||
prefix,
|
prefix,
|
||||||
name,
|
name,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use ruff::registry::{Linter, LinterCategory, Rule, RuleNamespace};
|
use ruff::registry::{Linter, Rule, RuleNamespace, UpstreamCategory};
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
use crate::utils::replace_readme_section;
|
use crate::utils::replace_readme_section;
|
||||||
|
|
@ -50,10 +50,10 @@ pub fn main(args: &Args) -> Result<()> {
|
||||||
for linter in Linter::iter() {
|
for linter in Linter::iter() {
|
||||||
let codes_csv: String = match linter.common_prefix() {
|
let codes_csv: String = match linter.common_prefix() {
|
||||||
"" => linter
|
"" => linter
|
||||||
.categories()
|
.upstream_categories()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|LinterCategory(prefix, ..)| prefix)
|
.map(|UpstreamCategory(prefix, ..)| prefix)
|
||||||
.join(", "),
|
.join(", "),
|
||||||
prefix => prefix.to_string(),
|
prefix => prefix.to_string(),
|
||||||
};
|
};
|
||||||
|
|
@ -93,8 +93,8 @@ pub fn main(args: &Args) -> Result<()> {
|
||||||
table_out.push('\n');
|
table_out.push('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(categories) = linter.categories() {
|
if let Some(categories) = linter.upstream_categories() {
|
||||||
for LinterCategory(prefix, name, selector) in categories {
|
for UpstreamCategory(prefix, name, selector) in categories {
|
||||||
table_out.push_str(&format!("#### {name} ({prefix})"));
|
table_out.push_str(&format!("#### {name} ({prefix})"));
|
||||||
table_out.push('\n');
|
table_out.push('\n');
|
||||||
table_out.push('\n');
|
table_out.push('\n');
|
||||||
|
|
|
||||||
|
|
@ -645,20 +645,20 @@ pub trait RuleNamespace: Sized {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The prefix, name and selector for an upstream linter category.
|
/// 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 {
|
impl Linter {
|
||||||
pub fn categories(&self) -> Option<&'static [LinterCategory]> {
|
pub fn upstream_categories(&self) -> Option<&'static [UpstreamCategory]> {
|
||||||
match self {
|
match self {
|
||||||
Linter::Pycodestyle => Some(&[
|
Linter::Pycodestyle => Some(&[
|
||||||
LinterCategory("E", "Error", RuleCodePrefix::E),
|
UpstreamCategory("E", "Error", RuleCodePrefix::E),
|
||||||
LinterCategory("W", "Warning", RuleCodePrefix::W),
|
UpstreamCategory("W", "Warning", RuleCodePrefix::W),
|
||||||
]),
|
]),
|
||||||
Linter::Pylint => Some(&[
|
Linter::Pylint => Some(&[
|
||||||
LinterCategory("PLC", "Convention", RuleCodePrefix::PLC),
|
UpstreamCategory("PLC", "Convention", RuleCodePrefix::PLC),
|
||||||
LinterCategory("PLE", "Error", RuleCodePrefix::PLE),
|
UpstreamCategory("PLE", "Error", RuleCodePrefix::PLE),
|
||||||
LinterCategory("PLR", "Refactor", RuleCodePrefix::PLR),
|
UpstreamCategory("PLR", "Refactor", RuleCodePrefix::PLR),
|
||||||
LinterCategory("PLW", "Warning", RuleCodePrefix::PLW),
|
UpstreamCategory("PLW", "Warning", RuleCodePrefix::PLW),
|
||||||
]),
|
]),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue