mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
many-to-one 4/9: Rename define_rule_mapping! to register_rules!
Currently the define_rule_mapping! macro generates both the Rule enum as well as the RuleCodePrefix enum and the mapping between the two. After this commit series the macro will only generate the Rule enum and the RuleCodePrefix enum and the mapping will be generated by a new map_codes proc macro, so we rename the macro now to fit its new purpose.
This commit is contained in:
parent
1b8d2df3bf
commit
65a3461519
4 changed files with 12 additions and 12 deletions
|
@ -10,7 +10,7 @@ use crate::fix::Fix;
|
|||
use crate::rules;
|
||||
use crate::violation::Violation;
|
||||
|
||||
ruff_macros::define_rule_mapping!(
|
||||
ruff_macros::register_rules!(
|
||||
// pycodestyle errors
|
||||
E101 => rules::pycodestyle::rules::MixedSpacesAndTabs,
|
||||
#[cfg(feature = "logical_lines")]
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
use syn::{parse_macro_input, DeriveInput, ItemFn};
|
||||
|
||||
mod config;
|
||||
mod define_rule_mapping;
|
||||
mod define_violation;
|
||||
mod derive_message_formats;
|
||||
mod register_rules;
|
||||
mod rule_code_prefix;
|
||||
mod rule_namespace;
|
||||
|
||||
|
@ -19,9 +19,9 @@ pub fn derive_config(input: proc_macro::TokenStream) -> proc_macro::TokenStream
|
|||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn define_rule_mapping(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let mapping = parse_macro_input!(item as define_rule_mapping::Mapping);
|
||||
define_rule_mapping::define_rule_mapping(&mapping).into()
|
||||
pub fn register_rules(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let mapping = parse_macro_input!(item as register_rules::Input);
|
||||
register_rules::register_rules(&mapping).into()
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
|
|
|
@ -5,7 +5,7 @@ use quote::quote;
|
|||
use syn::parse::Parse;
|
||||
use syn::{Attribute, Ident, LitStr, Path, Token};
|
||||
|
||||
pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
|
||||
pub fn register_rules(input: &Input) -> proc_macro2::TokenStream {
|
||||
let mut rule_variants = quote!();
|
||||
let mut diagnostic_kind_variants = quote!();
|
||||
let mut rule_message_formats_match_arms = quote!();
|
||||
|
@ -19,7 +19,7 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
|
|||
let mut diagnostic_kind_commit_match_arms = quote!();
|
||||
let mut from_impls_for_diagnostic_kind = quote!();
|
||||
|
||||
for (code, path, name, attr) in &mapping.entries {
|
||||
for (code, path, name, attr) in &input.entries {
|
||||
let code_str = LitStr::new(&code.to_string(), Span::call_site());
|
||||
rule_variants.extend(quote! {
|
||||
#[doc = #code_str]
|
||||
|
@ -55,7 +55,7 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
|
|||
});
|
||||
}
|
||||
|
||||
let code_to_name: HashMap<_, _> = mapping
|
||||
let code_to_name: HashMap<_, _> = input
|
||||
.entries
|
||||
.iter()
|
||||
.map(|(code, _, name, _)| (code.to_string(), name))
|
||||
|
@ -64,7 +64,7 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
|
|||
let rule_code_prefix = super::rule_code_prefix::expand(
|
||||
&Ident::new("Rule", Span::call_site()),
|
||||
&Ident::new("RuleCodePrefix", Span::call_site()),
|
||||
mapping.entries.iter().map(|(code, .., attr)| (code, attr)),
|
||||
input.entries.iter().map(|(code, .., attr)| (code, attr)),
|
||||
|code| code_to_name[code],
|
||||
);
|
||||
|
||||
|
@ -161,11 +161,11 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Mapping {
|
||||
pub struct Input {
|
||||
entries: Vec<(Ident, Path, Ident, Vec<Attribute>)>,
|
||||
}
|
||||
|
||||
impl Parse for Mapping {
|
||||
impl Parse for Input {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
let mut entries = Vec::new();
|
||||
while !input.is_empty() {
|
Loading…
Add table
Add a link
Reference in a new issue