mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 01:51:30 +00:00
many-to-one 2/9: Newtype Rule::noqa_code return type
Rule::noqa_code previously return a single &'static str, which was possible because we had one enum listing all rule code prefixes. This commit series will however split up the RuleCodePrefix enum into several enums ... so we'll end up with two &'static str ... this commit wraps the return type of Rule::noqa_code into a newtype so that we can easily change it to return two &'static str in the 6th commit of this series.
This commit is contained in:
parent
d451c7a506
commit
179ead0157
8 changed files with 64 additions and 37 deletions
|
@ -34,8 +34,8 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
|
|||
rule_autofixable_match_arms
|
||||
.extend(quote! {#(#attr)* Self::#name => <#path as Violation>::AUTOFIX,});
|
||||
rule_explanation_match_arms.extend(quote! {#(#attr)* Self::#name => #path::explanation(),});
|
||||
rule_code_match_arms.extend(quote! {#(#attr)* Self::#name => #code_str,});
|
||||
rule_from_code_match_arms.extend(quote! {#(#attr)* #code_str => Ok(Rule::#name), });
|
||||
rule_code_match_arms.extend(quote! {#(#attr)* Self::#name => NoqaCode(#code_str),});
|
||||
rule_from_code_match_arms.extend(quote! {#(#attr)* #code_str => Ok(&Rule::#name), });
|
||||
diagnostic_kind_code_match_arms
|
||||
.extend(quote! {#(#attr)* Self::#name(..) => &Rule::#name, });
|
||||
diagnostic_kind_body_match_arms
|
||||
|
@ -106,7 +106,7 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
|
|||
match self { #rule_autofixable_match_arms }
|
||||
}
|
||||
|
||||
pub fn noqa_code(&self) -> &'static str {
|
||||
pub fn noqa_code(&self) -> NoqaCode {
|
||||
match self { #rule_code_match_arms }
|
||||
}
|
||||
|
||||
|
@ -118,6 +118,21 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct NoqaCode(&'static str);
|
||||
|
||||
impl std::fmt::Display for NoqaCode {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<&str> for NoqaCode {
|
||||
fn eq(&self, other: &&str) -> bool {
|
||||
self.0 == *other
|
||||
}
|
||||
}
|
||||
|
||||
impl DiagnosticKind {
|
||||
/// The rule of the diagnostic.
|
||||
pub fn rule(&self) -> &'static Rule {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue