mirror of https://github.com/astral-sh/ruff
refactor: Simplify UpstreamCategory
There's no need to hardcode the prefix string since it can be derived from the RuleCodePrefix.
This commit is contained in:
parent
a3ffaa5d9b
commit
0f8f250bea
|
|
@ -15,7 +15,7 @@ pub fn linter(format: HelpFormat) {
|
||||||
.upstream_categories()
|
.upstream_categories()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|UpstreamCategory(prefix, ..)| prefix)
|
.map(|UpstreamCategory(prefix, ..)| prefix.as_ref())
|
||||||
.join("/"),
|
.join("/"),
|
||||||
prefix => prefix.to_string(),
|
prefix => prefix.to_string(),
|
||||||
};
|
};
|
||||||
|
|
@ -31,7 +31,7 @@ pub fn linter(format: HelpFormat) {
|
||||||
categories: linter_info.upstream_categories().map(|cats| {
|
categories: linter_info.upstream_categories().map(|cats| {
|
||||||
cats.iter()
|
cats.iter()
|
||||||
.map(|UpstreamCategory(prefix, name, ..)| LinterCategoryInfo {
|
.map(|UpstreamCategory(prefix, name, ..)| LinterCategoryInfo {
|
||||||
prefix,
|
prefix: prefix.as_ref(),
|
||||||
name,
|
name,
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ pub fn main(args: &Args) -> Result<()> {
|
||||||
.upstream_categories()
|
.upstream_categories()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|UpstreamCategory(prefix, ..)| prefix)
|
.map(|UpstreamCategory(prefix, ..)| prefix.as_ref())
|
||||||
.join(", "),
|
.join(", "),
|
||||||
prefix => prefix.to_string(),
|
prefix => prefix.to_string(),
|
||||||
};
|
};
|
||||||
|
|
@ -94,11 +94,11 @@ pub fn main(args: &Args) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(categories) = linter.upstream_categories() {
|
if let Some(categories) = linter.upstream_categories() {
|
||||||
for UpstreamCategory(prefix, name, selector) in categories {
|
for UpstreamCategory(prefix, name) in categories {
|
||||||
table_out.push_str(&format!("#### {name} ({prefix})"));
|
table_out.push_str(&format!("#### {name} ({})", prefix.as_ref()));
|
||||||
table_out.push('\n');
|
table_out.push('\n');
|
||||||
table_out.push('\n');
|
table_out.push('\n');
|
||||||
generate_table(&mut table_out, selector);
|
generate_table(&mut table_out, prefix);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
generate_table(&mut table_out, &linter);
|
generate_table(&mut table_out, &linter);
|
||||||
|
|
|
||||||
|
|
@ -644,21 +644,21 @@ pub trait RuleNamespace: Sized {
|
||||||
fn url(&self) -> Option<&'static str>;
|
fn url(&self) -> Option<&'static str>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The prefix, name and selector for an upstream linter category.
|
/// The prefix and name for an upstream linter category.
|
||||||
pub struct UpstreamCategory(pub &'static str, pub &'static str, pub RuleCodePrefix);
|
pub struct UpstreamCategory(pub RuleCodePrefix, pub &'static str);
|
||||||
|
|
||||||
impl Linter {
|
impl Linter {
|
||||||
pub fn upstream_categories(&self) -> Option<&'static [UpstreamCategory]> {
|
pub fn upstream_categories(&self) -> Option<&'static [UpstreamCategory]> {
|
||||||
match self {
|
match self {
|
||||||
Linter::Pycodestyle => Some(&[
|
Linter::Pycodestyle => Some(&[
|
||||||
UpstreamCategory("E", "Error", RuleCodePrefix::E),
|
UpstreamCategory(RuleCodePrefix::E, "Error"),
|
||||||
UpstreamCategory("W", "Warning", RuleCodePrefix::W),
|
UpstreamCategory(RuleCodePrefix::W, "Warning"),
|
||||||
]),
|
]),
|
||||||
Linter::Pylint => Some(&[
|
Linter::Pylint => Some(&[
|
||||||
UpstreamCategory("PLC", "Convention", RuleCodePrefix::PLC),
|
UpstreamCategory(RuleCodePrefix::PLC, "Convention"),
|
||||||
UpstreamCategory("PLE", "Error", RuleCodePrefix::PLE),
|
UpstreamCategory(RuleCodePrefix::PLE, "Error"),
|
||||||
UpstreamCategory("PLR", "Refactor", RuleCodePrefix::PLR),
|
UpstreamCategory(RuleCodePrefix::PLR, "Refactor"),
|
||||||
UpstreamCategory("PLW", "Warning", RuleCodePrefix::PLW),
|
UpstreamCategory(RuleCodePrefix::PLW, "Warning"),
|
||||||
]),
|
]),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue