mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
refactor: Add Copy implementation to Rule (#3556)
This commit is contained in:
parent
aa51ecedc5
commit
eff84442bc
59 changed files with 835 additions and 965 deletions
|
@ -167,7 +167,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 rule_to_codes: HashMap<&Path, Vec<(&Ident, &str, &Vec<Attribute>)>> = HashMap::new();
|
||||
let mut linter_code_for_rule_match_arms = quote!();
|
||||
|
||||
for (linter, map) in &linters {
|
||||
|
@ -227,7 +227,7 @@ pub fn map_codes(func: &ItemFn) -> syn::Result<TokenStream> {
|
|||
}
|
||||
|
||||
impl crate::registry::Linter {
|
||||
pub fn code_for_rule(&self, rule: &Rule) -> Option<&'static str> {
|
||||
pub fn code_for_rule(&self, rule: Rule) -> Option<&'static str> {
|
||||
match (self, rule) {
|
||||
#linter_code_for_rule_match_arms
|
||||
_ => None,
|
||||
|
|
|
@ -24,8 +24,7 @@ pub fn register_rules(input: &Input) -> proc_macro2::TokenStream {
|
|||
rule_explanation_match_arms.extend(quote! {#(#attr)* Self::#name => #path::explanation(),});
|
||||
|
||||
// Enable conversion from `DiagnosticKind` to `Rule`.
|
||||
from_impls_for_diagnostic_kind
|
||||
.extend(quote! {#(#attr)* stringify!(#name) => &Rule::#name,});
|
||||
from_impls_for_diagnostic_kind.extend(quote! {#(#attr)* stringify!(#name) => Rule::#name,});
|
||||
}
|
||||
|
||||
quote! {
|
||||
|
@ -34,6 +33,7 @@ pub fn register_rules(input: &Input) -> proc_macro2::TokenStream {
|
|||
Debug,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Copy,
|
||||
Clone,
|
||||
Hash,
|
||||
PartialOrd,
|
||||
|
@ -57,17 +57,13 @@ pub fn register_rules(input: &Input) -> proc_macro2::TokenStream {
|
|||
}
|
||||
|
||||
/// Returns the autofix status of this rule.
|
||||
pub fn autofixable(&self) -> Option<ruff_diagnostics::AutofixKind> {
|
||||
pub const fn autofixable(&self) -> Option<ruff_diagnostics::AutofixKind> {
|
||||
match self { #rule_autofixable_match_arms }
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AsRule {
|
||||
fn rule(&self) -> &'static Rule;
|
||||
}
|
||||
|
||||
impl AsRule for ruff_diagnostics::DiagnosticKind {
|
||||
fn rule(&self) -> &'static Rule {
|
||||
fn rule(&self) -> Rule {
|
||||
match self.name.as_str() {
|
||||
#from_impls_for_diagnostic_kind
|
||||
_ => unreachable!("invalid rule name: {}", self.name),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue