many-to-one 9/9: Update table generation

This commit is contained in:
Martin Fischer 2023-02-03 06:23:35 +01:00 committed by Charlie Marsh
parent 05176890ee
commit 03ae0118b7
2 changed files with 19 additions and 5 deletions

View file

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