mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 01:51:30 +00:00
refactor: Avoid implicit precondition
This commit is contained in:
parent
ac6c3affdd
commit
fa191cceeb
2 changed files with 3 additions and 5 deletions
|
@ -64,9 +64,8 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
|
||||||
let rule_code_prefix = super::rule_code_prefix::expand(
|
let rule_code_prefix = super::rule_code_prefix::expand(
|
||||||
&Ident::new("Rule", Span::call_site()),
|
&Ident::new("Rule", Span::call_site()),
|
||||||
&Ident::new("RuleCodePrefix", Span::call_site()),
|
&Ident::new("RuleCodePrefix", Span::call_site()),
|
||||||
mapping.entries.iter().map(|(code, ..)| code),
|
mapping.entries.iter().map(|(code, .., attr)| (code, attr)),
|
||||||
|code| code_to_name[code],
|
|code| code_to_name[code],
|
||||||
mapping.entries.iter().map(|(.., attr)| attr),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
|
|
|
@ -7,9 +7,8 @@ use syn::{Attribute, Ident};
|
||||||
pub fn expand<'a>(
|
pub fn expand<'a>(
|
||||||
rule_type: &Ident,
|
rule_type: &Ident,
|
||||||
prefix_ident: &Ident,
|
prefix_ident: &Ident,
|
||||||
variants: impl Iterator<Item = &'a Ident>,
|
variants: impl Iterator<Item = (&'a Ident, &'a Vec<Attribute>)>,
|
||||||
variant_name: impl Fn(&str) -> &'a Ident,
|
variant_name: impl Fn(&str) -> &'a Ident,
|
||||||
attr: impl Iterator<Item = &'a Vec<Attribute>>,
|
|
||||||
) -> proc_macro2::TokenStream {
|
) -> proc_macro2::TokenStream {
|
||||||
// Build up a map from prefix to matching RuleCodes.
|
// Build up a map from prefix to matching RuleCodes.
|
||||||
let mut prefix_to_codes: BTreeMap<String, BTreeMap<String, Vec<Attribute>>> =
|
let mut prefix_to_codes: BTreeMap<String, BTreeMap<String, Vec<Attribute>>> =
|
||||||
|
@ -17,7 +16,7 @@ pub fn expand<'a>(
|
||||||
|
|
||||||
let mut pl_codes = BTreeMap::new();
|
let mut pl_codes = BTreeMap::new();
|
||||||
|
|
||||||
for (variant, attr) in variants.zip(attr) {
|
for (variant, attr) in variants {
|
||||||
let code_str = variant.to_string();
|
let code_str = variant.to_string();
|
||||||
let code_prefix_len = code_str
|
let code_prefix_len = code_str
|
||||||
.chars()
|
.chars()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue