mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:53 +00:00
Use a derive macro for Violations (#14557)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
6fd10e2fe7
commit
14ba469fc0
629 changed files with 2555 additions and 2562 deletions
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue