refactor: Make Rule::from_code return Rule instead of &'static Rule

This commit is contained in:
Martin Fischer 2023-02-03 04:36:16 +01:00 committed by Charlie Marsh
parent a30c77e752
commit 187ed874e9
4 changed files with 5 additions and 5 deletions

View File

@ -36,7 +36,7 @@ pub enum Command {
#[clap(alias = "--explain")]
Rule {
#[arg(value_parser=Rule::from_code)]
rule: &'static Rule,
rule: Rule,
/// Output format
#[arg(long, value_enum, default_value = "text")]

View File

@ -80,7 +80,7 @@ quoting the executed command, along with the relevant file contents and `pyproje
set_up_logging(&log_level)?;
match command {
Command::Rule { rule, format } => commands::rule(rule, format)?,
Command::Rule { rule, format } => commands::rule(&rule, format)?,
Command::Linter { format } => commands::linter::linter(format),
Command::Clean => commands::clean(log_level)?,
Command::GenerateShellCompletion { shell } => {

View File

@ -29,7 +29,7 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
.extend(quote! {Self::#name => <#path as Violation>::message_formats(),});
rule_autofixable_match_arms.extend(quote! {Self::#name => <#path as Violation>::AUTOFIX,});
rule_code_match_arms.extend(quote! {Self::#name => #code_str,});
rule_from_code_match_arms.extend(quote! {#code_str => Ok(&Rule::#name), });
rule_from_code_match_arms.extend(quote! {#code_str => Ok(Rule::#name), });
diagkind_code_match_arms.extend(quote! {Self::#name(..) => &Rule::#name, });
diagkind_body_match_arms.extend(quote! {Self::#name(x) => Violation::message(x), });
diagkind_fixable_match_arms
@ -96,7 +96,7 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
match self { #rule_code_match_arms }
}
pub fn from_code(code: &str) -> Result<&'static Self, FromCodeError> {
pub fn from_code(code: &str) -> Result<Self, FromCodeError> {
match code {
#rule_from_code_match_arms
_ => Err(FromCodeError::Unknown),

View File

@ -137,7 +137,7 @@ pub fn check_noqa(
valid_codes.push(code);
} else {
if let Ok(rule) = Rule::from_code(code) {
if settings.rules.enabled(rule) {
if settings.rules.enabled(&rule) {
unmatched_codes.push(code);
} else {
disabled_codes.push(code);