Use a derive macro for Violations (#14557)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Micha Reiser 2024-11-27 10:41:40 +01:00 committed by GitHub
parent 6fd10e2fe7
commit 14ba469fc0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
629 changed files with 2555 additions and 2562 deletions

View file

@ -420,8 +420,7 @@ fn register_rules<'a>(input: impl Iterator<Item = &'a Rule>) -> TokenStream {
rule_fixable_match_arms.extend(
quote! {#(#attrs)* Self::#name => <#path as ruff_diagnostics::Violation>::FIX_AVAILABILITY,},
);
rule_explanation_match_arms
.extend(quote! {#(#attrs)* Self::#name => #path::explanation(),});
rule_explanation_match_arms.extend(quote! {#(#attrs)* Self::#name => #path::explain(),});
// Enable conversion from `DiagnosticKind` to `Rule`.
from_impls_for_diagnostic_kind
@ -457,6 +456,7 @@ fn register_rules<'a>(input: impl Iterator<Item = &'a Rule>) -> TokenStream {
/// Returns the documentation for this rule.
pub fn explanation(&self) -> Option<&'static str> {
use ruff_diagnostics::ViolationMetadata;
match self { #rule_explanation_match_arms }
}
@ -466,6 +466,7 @@ fn register_rules<'a>(input: impl Iterator<Item = &'a Rule>) -> TokenStream {
}
}
impl AsRule for ruff_diagnostics::DiagnosticKind {
fn rule(&self) -> Rule {
match self.name.as_str() {