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()
|
||||
.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()
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue