mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-18 17:41:12 +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
|
@ -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