mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-02 09:52:18 +00:00
many-to-one 9/9: Update table generation
This commit is contained in:
parent
05176890ee
commit
03ae0118b7
2 changed files with 19 additions and 5 deletions
|
@ -23,7 +23,7 @@ pub struct Args {
|
|||
pub(crate) dry_run: bool,
|
||||
}
|
||||
|
||||
fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>) {
|
||||
fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>, linter: &Linter) {
|
||||
table_out.push_str("| Code | Name | Message | Fix |");
|
||||
table_out.push('\n');
|
||||
table_out.push_str("| ---- | ---- | ------- | --- |");
|
||||
|
@ -38,8 +38,9 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>)
|
|||
|
||||
#[allow(clippy::or_fun_call)]
|
||||
table_out.push_str(&format!(
|
||||
"| {} | {} | {} | {} |",
|
||||
rule.noqa_code(),
|
||||
"| {}{} | {} | {} | {} |",
|
||||
linter.common_prefix(),
|
||||
linter.code_for_rule(&rule).unwrap(),
|
||||
rule.explanation()
|
||||
.is_some()
|
||||
.then_some(format_args!("[{rule_name}]({URL_PREFIX}/{rule_name}/)",))
|
||||
|
@ -111,10 +112,10 @@ pub fn main(args: &Args) -> Result<()> {
|
|||
));
|
||||
table_out.push('\n');
|
||||
table_out.push('\n');
|
||||
generate_table(&mut table_out, prefix);
|
||||
generate_table(&mut table_out, prefix, &linter);
|
||||
}
|
||||
} else {
|
||||
generate_table(&mut table_out, &linter);
|
||||
generate_table(&mut table_out, &linter, &linter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -179,6 +179,7 @@ pub fn map_codes(func: &ItemFn) -> syn::Result<TokenStream> {
|
|||
|
||||
#[allow(clippy::type_complexity)]
|
||||
let mut rule_to_codes: HashMap<&Path, Vec<(&Ident, &String, &Vec<Attribute>)>> = HashMap::new();
|
||||
let mut linter_code_for_rule_match_arms = quote!();
|
||||
|
||||
for (linter, map) in &linters {
|
||||
for (code, (rule, attrs)) in map {
|
||||
|
@ -186,6 +187,9 @@ pub fn map_codes(func: &ItemFn) -> syn::Result<TokenStream> {
|
|||
.entry(rule)
|
||||
.or_default()
|
||||
.push((linter, code, attrs));
|
||||
linter_code_for_rule_match_arms.extend(quote! {
|
||||
#(#attrs)* (Self::#linter, #rule) => Some(#code),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,6 +220,15 @@ pub fn map_codes(func: &ItemFn) -> syn::Result<TokenStream> {
|
|||
}
|
||||
}
|
||||
|
||||
impl crate::registry::Linter {
|
||||
pub fn code_for_rule(&self, rule: &Rule) -> Option<&'static str> {
|
||||
match (self, rule) {
|
||||
#linter_code_for_rule_match_arms
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct NoqaCode(&'static str, &'static str);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue