diff --git a/ruff_cli/src/commands.rs b/ruff_cli/src/commands.rs index 04a4863f25..df2ff1479a 100644 --- a/ruff_cli/src/commands.rs +++ b/ruff_cli/src/commands.rs @@ -15,7 +15,7 @@ use ruff::cache::CACHE_DIR_NAME; use ruff::linter::add_noqa_to_path; use ruff::logging::LogLevel; use ruff::message::{Location, Message}; -use ruff::registry::RuleCode; +use ruff::registry::Rule; use ruff::resolver::{FileDiscovery, PyprojectDiscovery}; use ruff::settings::flags; use ruff::settings::types::SerializationFormat; @@ -114,7 +114,7 @@ pub fn run( .unwrap_or_else(|(path, message)| { if let Some(path) = &path { let settings = resolver.resolve(path, pyproject_strategy); - if settings.rules.enabled(&RuleCode::E902) { + if settings.rules.enabled(&Rule::E902) { Diagnostics::new(vec![Message { kind: IOError(message).into(), location: Location::default(), @@ -289,24 +289,24 @@ struct Explanation<'a> { summary: &'a str, } -/// Explain a `RuleCode` to the user. -pub fn explain(code: &RuleCode, format: SerializationFormat) -> Result<()> { +/// Explain a `Rule` to the user. +pub fn explain(rule: &Rule, format: SerializationFormat) -> Result<()> { match format { SerializationFormat::Text | SerializationFormat::Grouped => { println!( "{} ({}): {}", - code.as_ref(), - code.origin().name(), - code.kind().summary() + rule.code(), + rule.origin().name(), + rule.kind().summary() ); } SerializationFormat::Json => { println!( "{}", serde_json::to_string_pretty(&Explanation { - code: code.as_ref(), - origin: code.origin().name(), - summary: &code.kind().summary(), + code: rule.code(), + origin: rule.origin().name(), + summary: &rule.kind().summary(), })? ); } diff --git a/ruff_cli/src/printer.rs b/ruff_cli/src/printer.rs index a2ee2d785f..b0d9858460 100644 --- a/ruff_cli/src/printer.rs +++ b/ruff_cli/src/printer.rs @@ -248,7 +248,7 @@ impl<'a> Printer<'a> { ":", message.location.column(), ":", - message.kind.rule().as_ref(), + message.kind.rule().code(), message.kind.body(), ); writeln!( @@ -361,7 +361,7 @@ fn print_message(stdout: &mut T, message: &Message) -> Result<()> { ":".cyan(), message.location.column(), ":".cyan(), - message.kind.rule().as_ref().red().bold(), + message.kind.rule().code().red().bold(), message.kind.body(), ); writeln!(stdout, "{label}")?; @@ -388,7 +388,7 @@ fn print_message(stdout: &mut T, message: &Message) -> Result<()> { source: &source.contents, line_start: message.location.row(), annotations: vec![SourceAnnotation { - label: message.kind.rule().as_ref(), + label: message.kind.rule().code(), annotation_type: AnnotationType::Error, range: source.range, }], @@ -425,7 +425,7 @@ fn print_grouped_message( ":".cyan(), message.location.column(), " ".repeat(column_length - num_digits(message.location.column())), - message.kind.rule().as_ref().red().bold(), + message.kind.rule().code().red().bold(), message.kind.body(), ); writeln!(stdout, "{label}")?; @@ -452,7 +452,7 @@ fn print_grouped_message( source: &source.contents, line_start: message.location.row(), annotations: vec![SourceAnnotation { - label: message.kind.rule().as_ref(), + label: message.kind.rule().code(), annotation_type: AnnotationType::Error, range: source.range, }], diff --git a/ruff_dev/src/generate_rules_table.rs b/ruff_dev/src/generate_rules_table.rs index 50b725381d..e24d4f3273 100644 --- a/ruff_dev/src/generate_rules_table.rs +++ b/ruff_dev/src/generate_rules_table.rs @@ -30,7 +30,7 @@ fn generate_table(table_out: &mut String, prefix: &RuleCodePrefix) { let fix_token = if kind.fixable() { "🛠" } else { "" }; table_out.push_str(&format!( "| {} | {} | {} | {} |", - kind.rule().as_ref(), + kind.rule().code(), kind.as_ref(), kind.summary().replace('|', r"\|"), fix_token diff --git a/ruff_macros/src/define_rule_mapping.rs b/ruff_macros/src/define_rule_mapping.rs index 66911ec8d0..13428e18e3 100644 --- a/ruff_macros/src/define_rule_mapping.rs +++ b/ruff_macros/src/define_rule_mapping.rs @@ -1,13 +1,14 @@ use proc_macro2::Span; use quote::quote; use syn::parse::Parse; -use syn::{Ident, Path, Token}; +use syn::{Ident, LitStr, Path, Token}; pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream { let mut rule_variants = quote!(); let mut diagkind_variants = quote!(); let mut rule_kind_match_arms = quote!(); let mut rule_origin_match_arms = quote!(); + let mut rule_code_match_arms = quote!(); let mut diagkind_code_match_arms = quote!(); let mut diagkind_body_match_arms = quote!(); let mut diagkind_fixable_match_arms = quote!(); @@ -22,6 +23,8 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream { ); let origin = get_origin(code); rule_origin_match_arms.extend(quote! {Self::#code => RuleOrigin::#origin,}); + let code_str = LitStr::new(&code.to_string(), Span::call_site()); + rule_code_match_arms.extend(quote! {Self::#code => #code_str,}); diagkind_code_match_arms.extend(quote! {Self::#name(..) => &RuleCode::#code, }); diagkind_body_match_arms.extend(quote! {Self::#name(x) => Violation::message(x), }); diagkind_fixable_match_arms @@ -45,7 +48,6 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream { quote! { #[derive( - AsRefStr, // TODO(martin): Remove EnumIter, EnumString, // TODO(martin): Remove Debug, @@ -76,6 +78,10 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream { pub fn origin(&self) -> RuleOrigin { match self { #rule_origin_match_arms } } + + pub fn code(&self) -> &'static str { + match self { #rule_code_match_arms } + } } diff --git a/src/checkers/noqa.rs b/src/checkers/noqa.rs index 2a9d9c7da4..66e087da3d 100644 --- a/src/checkers/noqa.rs +++ b/src/checkers/noqa.rs @@ -56,13 +56,13 @@ pub fn check_noqa( }); match noqa { (Directive::All(..), matches) => { - matches.push(diagnostic.kind.rule().as_ref()); + matches.push(diagnostic.kind.rule().code()); ignored.push(index); continue; } (Directive::Codes(.., codes), matches) => { if noqa::includes(diagnostic.kind.rule(), codes) { - matches.push(diagnostic.kind.rule().as_ref()); + matches.push(diagnostic.kind.rule().code()); ignored.push(index); continue; } @@ -83,12 +83,12 @@ pub fn check_noqa( .or_insert_with(|| (noqa::extract_noqa_directive(lines[noqa_lineno - 1]), vec![])); match noqa { (Directive::All(..), matches) => { - matches.push(diagnostic.kind.rule().as_ref()); + matches.push(diagnostic.kind.rule().code()); ignored.push(index); } (Directive::Codes(.., codes), matches) => { if noqa::includes(diagnostic.kind.rule(), codes) { - matches.push(diagnostic.kind.rule().as_ref()); + matches.push(diagnostic.kind.rule().code()); ignored.push(index); } } @@ -125,8 +125,8 @@ pub fn check_noqa( let mut valid_codes = vec![]; let mut self_ignore = false; for code in codes { - let code = CODE_REDIRECTS.get(code).map_or(code, AsRef::as_ref); - if code == RuleCode::RUF100.as_ref() { + let code = CODE_REDIRECTS.get(code).map_or(code, |r| r.code()); + if code == RuleCode::RUF100.code() { self_ignore = true; break; } diff --git a/src/noqa.rs b/src/noqa.rs index 5835b3cf34..3cef0dbd4e 100644 --- a/src/noqa.rs +++ b/src/noqa.rs @@ -70,10 +70,10 @@ pub fn extract_noqa_directive(line: &str) -> Directive { /// Returns `true` if the string list of `codes` includes `code` (or an alias /// thereof). pub fn includes(needle: &RuleCode, haystack: &[&str]) -> bool { - let needle: &str = needle.as_ref(); + let needle: &str = needle.code(); haystack.iter().any(|candidate| { if let Some(candidate) = CODE_REDIRECTS.get(candidate) { - needle == candidate.as_ref() + needle == candidate.code() } else { &needle == candidate } @@ -138,7 +138,7 @@ fn add_noqa_inner( output.push_str(line); output.push_str(line_ending); } - Some(codes) => { + Some(rules) => { match extract_noqa_directive(line) { Directive::None => { // Add existing content. @@ -148,7 +148,7 @@ fn add_noqa_inner( output.push_str(" # noqa: "); // Add codes. - let codes: Vec<&str> = codes.iter().map(AsRef::as_ref).collect(); + let codes: Vec<&str> = rules.iter().map(|r| r.code()).collect(); let suffix = codes.join(", "); output.push_str(&suffix); output.push_str(line_ending); @@ -163,7 +163,7 @@ fn add_noqa_inner( // Add codes. let codes: Vec<&str> = - codes.iter().map(AsRef::as_ref).sorted_unstable().collect(); + rules.iter().map(|r| r.code()).sorted_unstable().collect(); let suffix = codes.join(", "); output.push_str(&suffix); output.push_str(line_ending); @@ -181,9 +181,9 @@ fn add_noqa_inner( formatted.push_str(" # noqa: "); // Add codes. - let codes: Vec<&str> = codes + let codes: Vec<&str> = rules .iter() - .map(AsRef::as_ref) + .map(|r| r.code()) .chain(existing.into_iter().filter(|code| external.contains(*code))) .sorted_unstable() .collect(); diff --git a/src/registry.rs b/src/registry.rs index 6c3a7ce863..7259c72899 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -716,26 +716,26 @@ mod tests { use strum::IntoEnumIterator; - use crate::registry::RuleCode; + use crate::registry::Rule; #[test] fn check_code_serialization() { - for check_code in RuleCode::iter() { + for rule in Rule::iter() { assert!( - RuleCode::from_str(check_code.as_ref()).is_ok(), - "{check_code:?} could not be round-trip serialized." + Rule::from_str(rule.code()).is_ok(), + "{rule:?} could not be round-trip serialized." ); } } #[test] fn fixable_codes() { - for check_code in RuleCode::iter() { - let kind = check_code.kind(); + for rule in Rule::iter() { + let kind = rule.kind(); if kind.fixable() { assert!( kind.commit().is_some(), - "{check_code:?} is fixable but has no commit message." + "{rule:?} is fixable but has no commit message." ); } } diff --git a/src/rules/eradicate/mod.rs b/src/rules/eradicate/mod.rs index d23f823662..d2c0cee556 100644 --- a/src/rules/eradicate/mod.rs +++ b/src/rules/eradicate/mod.rs @@ -4,7 +4,6 @@ pub(crate) mod rules; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -16,7 +15,7 @@ mod tests { #[test_case(RuleCode::ERA001, Path::new("ERA001.py"); "ERA001")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/eradicate") .join(path) diff --git a/src/rules/flake8_2020/mod.rs b/src/rules/flake8_2020/mod.rs index 24992fe910..22d225707d 100644 --- a/src/rules/flake8_2020/mod.rs +++ b/src/rules/flake8_2020/mod.rs @@ -3,7 +3,6 @@ pub(crate) mod rules; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -24,7 +23,7 @@ mod tests { #[test_case(RuleCode::YTT302, Path::new("YTT302.py"); "YTT302")] #[test_case(RuleCode::YTT303, Path::new("YTT303.py"); "YTT303")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_2020") .join(path) diff --git a/src/rules/flake8_bandit/mod.rs b/src/rules/flake8_bandit/mod.rs index 23fea01ef2..5c8a8fa47a 100644 --- a/src/rules/flake8_bandit/mod.rs +++ b/src/rules/flake8_bandit/mod.rs @@ -30,7 +30,7 @@ mod tests { #[test_case(RuleCode::S509, Path::new("S509.py"); "S509")] #[test_case(RuleCode::S701, Path::new("S701.py"); "S701")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_bandit") .join(path) diff --git a/src/rules/flake8_blind_except/mod.rs b/src/rules/flake8_blind_except/mod.rs index 9e21fd33e2..8728e10246 100644 --- a/src/rules/flake8_blind_except/mod.rs +++ b/src/rules/flake8_blind_except/mod.rs @@ -3,7 +3,6 @@ pub(crate) mod rules; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -15,7 +14,7 @@ mod tests { #[test_case(RuleCode::BLE001, Path::new("BLE.py"); "BLE001")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_blind_except") .join(path) diff --git a/src/rules/flake8_boolean_trap/mod.rs b/src/rules/flake8_boolean_trap/mod.rs index bf9246a146..a7917723e3 100644 --- a/src/rules/flake8_boolean_trap/mod.rs +++ b/src/rules/flake8_boolean_trap/mod.rs @@ -3,7 +3,6 @@ pub(crate) mod rules; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -17,7 +16,7 @@ mod tests { #[test_case(RuleCode::FBT002, Path::new("FBT.py"); "FBT002")] #[test_case(RuleCode::FBT003, Path::new("FBT.py"); "FBT003")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_boolean_trap") .join(path) diff --git a/src/rules/flake8_bugbear/mod.rs b/src/rules/flake8_bugbear/mod.rs index 908724070c..c2944f4eba 100644 --- a/src/rules/flake8_bugbear/mod.rs +++ b/src/rules/flake8_bugbear/mod.rs @@ -42,7 +42,7 @@ mod tests { #[test_case(RuleCode::B904, Path::new("B904.py"); "B904")] #[test_case(RuleCode::B905, Path::new("B905.py"); "B905")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_bugbear") .join(path) diff --git a/src/rules/flake8_builtins/mod.rs b/src/rules/flake8_builtins/mod.rs index 7dd4e1d91e..b54c2e9e91 100644 --- a/src/rules/flake8_builtins/mod.rs +++ b/src/rules/flake8_builtins/mod.rs @@ -4,7 +4,6 @@ pub(crate) mod types; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -18,7 +17,7 @@ mod tests { #[test_case(RuleCode::A002, Path::new("A002.py"); "A002")] #[test_case(RuleCode::A003, Path::new("A003.py"); "A003")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_builtins") .join(path) diff --git a/src/rules/flake8_comprehensions/mod.rs b/src/rules/flake8_comprehensions/mod.rs index 045f080bc4..6aab2dd95e 100644 --- a/src/rules/flake8_comprehensions/mod.rs +++ b/src/rules/flake8_comprehensions/mod.rs @@ -4,7 +4,6 @@ pub(crate) mod rules; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -32,7 +31,7 @@ mod tests { #[test_case(RuleCode::C417, Path::new("C417.py"); "C417")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_comprehensions") .join(path) diff --git a/src/rules/flake8_datetimez/mod.rs b/src/rules/flake8_datetimez/mod.rs index 65503a91ee..c0dcb98ec8 100644 --- a/src/rules/flake8_datetimez/mod.rs +++ b/src/rules/flake8_datetimez/mod.rs @@ -3,7 +3,6 @@ pub(crate) mod rules; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -23,7 +22,7 @@ mod tests { #[test_case(RuleCode::DTZ011, Path::new("DTZ011.py"); "DTZ011")] #[test_case(RuleCode::DTZ012, Path::new("DTZ012.py"); "DTZ012")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_datetimez") .join(path) diff --git a/src/rules/flake8_debugger/mod.rs b/src/rules/flake8_debugger/mod.rs index 2d4d4b4a98..a1b5b8643b 100644 --- a/src/rules/flake8_debugger/mod.rs +++ b/src/rules/flake8_debugger/mod.rs @@ -4,7 +4,6 @@ pub(crate) mod types; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -16,7 +15,7 @@ mod tests { #[test_case(RuleCode::T100, Path::new("T100.py"); "T100")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_debugger") .join(path) diff --git a/src/rules/flake8_implicit_str_concat/mod.rs b/src/rules/flake8_implicit_str_concat/mod.rs index 293d19ceab..c8e0788bd5 100644 --- a/src/rules/flake8_implicit_str_concat/mod.rs +++ b/src/rules/flake8_implicit_str_concat/mod.rs @@ -3,7 +3,6 @@ pub(crate) mod rules; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -17,7 +16,7 @@ mod tests { #[test_case(RuleCode::ISC002, Path::new("ISC.py"); "ISC002")] #[test_case(RuleCode::ISC003, Path::new("ISC.py"); "ISC003")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_implicit_str_concat") .join(path) diff --git a/src/rules/flake8_pie/mod.rs b/src/rules/flake8_pie/mod.rs index 41a7bd6ac4..b797781a3b 100644 --- a/src/rules/flake8_pie/mod.rs +++ b/src/rules/flake8_pie/mod.rs @@ -3,7 +3,6 @@ pub(crate) mod rules; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -18,7 +17,7 @@ mod tests { #[test_case(RuleCode::PIE796, Path::new("PIE796.py"); "PIE796")] #[test_case(RuleCode::PIE807, Path::new("PIE807.py"); "PIE807")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_pie") .join(path) diff --git a/src/rules/flake8_print/mod.rs b/src/rules/flake8_print/mod.rs index e28bcd0c4c..b2e3d9b074 100644 --- a/src/rules/flake8_print/mod.rs +++ b/src/rules/flake8_print/mod.rs @@ -3,7 +3,6 @@ pub(crate) mod rules; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -16,7 +15,7 @@ mod tests { #[test_case(RuleCode::T201, Path::new("T201.py"); "T201")] #[test_case(RuleCode::T203, Path::new("T203.py"); "T203")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_print") .join(path) diff --git a/src/rules/flake8_return/mod.rs b/src/rules/flake8_return/mod.rs index 0fb6931728..f3ccf170a9 100644 --- a/src/rules/flake8_return/mod.rs +++ b/src/rules/flake8_return/mod.rs @@ -23,7 +23,7 @@ mod tests { #[test_case(RuleCode::RET507, Path::new("RET507.py"); "RET507")] #[test_case(RuleCode::RET508, Path::new("RET508.py"); "RET508")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_return") .join(path) diff --git a/src/rules/flake8_simplify/mod.rs b/src/rules/flake8_simplify/mod.rs index 1ea2a3b4e7..9299b2e574 100644 --- a/src/rules/flake8_simplify/mod.rs +++ b/src/rules/flake8_simplify/mod.rs @@ -3,7 +3,6 @@ pub(crate) mod rules; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -39,7 +38,7 @@ mod tests { #[test_case(RuleCode::SIM300, Path::new("SIM300.py"); "SIM300")] #[test_case(RuleCode::SIM401, Path::new("SIM401.py"); "SIM401")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_simplify") .join(path) diff --git a/src/rules/flake8_unused_arguments/mod.rs b/src/rules/flake8_unused_arguments/mod.rs index 547b2c3af2..1422d88923 100644 --- a/src/rules/flake8_unused_arguments/mod.rs +++ b/src/rules/flake8_unused_arguments/mod.rs @@ -6,7 +6,6 @@ mod types; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -22,7 +21,7 @@ mod tests { #[test_case(RuleCode::ARG004, Path::new("ARG.py"); "ARG004")] #[test_case(RuleCode::ARG005, Path::new("ARG.py"); "ARG005")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_unused_arguments") .join(path) diff --git a/src/rules/pep8_naming/mod.rs b/src/rules/pep8_naming/mod.rs index 64583a17d4..1dd4c949d5 100644 --- a/src/rules/pep8_naming/mod.rs +++ b/src/rules/pep8_naming/mod.rs @@ -5,7 +5,6 @@ pub mod settings; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -31,7 +30,7 @@ mod tests { #[test_case(RuleCode::N817, Path::new("N817.py"); "N817")] #[test_case(RuleCode::N818, Path::new("N818.py"); "N818")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/pep8_naming") .join(path) diff --git a/src/rules/pycodestyle/mod.rs b/src/rules/pycodestyle/mod.rs index 7ff92fa886..30f8432497 100644 --- a/src/rules/pycodestyle/mod.rs +++ b/src/rules/pycodestyle/mod.rs @@ -4,7 +4,6 @@ pub mod settings; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -38,7 +37,7 @@ mod tests { #[test_case(RuleCode::W605, Path::new("W605_0.py"))] #[test_case(RuleCode::W605, Path::new("W605_1.py"))] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/pycodestyle") .join(path) diff --git a/src/rules/pydocstyle/mod.rs b/src/rules/pydocstyle/mod.rs index 4eb6f2b9e1..5e6890ac5c 100644 --- a/src/rules/pydocstyle/mod.rs +++ b/src/rules/pydocstyle/mod.rs @@ -5,7 +5,6 @@ pub mod settings; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -66,7 +65,7 @@ mod tests { #[test_case(RuleCode::D419, Path::new("D.py"); "D419")] #[test_case(RuleCode::D104, Path::new("D104/__init__.py"); "D104_1")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/pydocstyle") .join(path) diff --git a/src/rules/pyflakes/mod.rs b/src/rules/pyflakes/mod.rs index 1c9f56c298..ca922a1ff3 100644 --- a/src/rules/pyflakes/mod.rs +++ b/src/rules/pyflakes/mod.rs @@ -6,7 +6,6 @@ pub(crate) mod rules; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -106,7 +105,7 @@ mod tests { #[test_case(RuleCode::F842, Path::new("F842.py"); "F842")] #[test_case(RuleCode::F901, Path::new("F901.py"); "F901")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/pyflakes") .join(path) diff --git a/src/rules/pygrep_hooks/mod.rs b/src/rules/pygrep_hooks/mod.rs index 63b3264230..2b46ef372d 100644 --- a/src/rules/pygrep_hooks/mod.rs +++ b/src/rules/pygrep_hooks/mod.rs @@ -3,7 +3,6 @@ pub(crate) mod rules; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -20,7 +19,7 @@ mod tests { #[test_case(RuleCode::PGH003, Path::new("PGH003_0.py"); "PGH003_0")] #[test_case(RuleCode::PGH004, Path::new("PGH004_0.py"); "PGH004_0")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/pygrep-hooks") .join(path) diff --git a/src/rules/pylint/mod.rs b/src/rules/pylint/mod.rs index 36c2de76a7..f54b8d0fcc 100644 --- a/src/rules/pylint/mod.rs +++ b/src/rules/pylint/mod.rs @@ -34,7 +34,7 @@ mod tests { #[test_case(RuleCode::PLW0120, Path::new("useless_else_on_loop.py"); "PLW0120")] #[test_case(RuleCode::PLW0602, Path::new("global_variable_not_assigned.py"); "PLW0602")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/pylint") .join(path) diff --git a/src/rules/pyupgrade/mod.rs b/src/rules/pyupgrade/mod.rs index fe0d4e051f..4280f40be4 100644 --- a/src/rules/pyupgrade/mod.rs +++ b/src/rules/pyupgrade/mod.rs @@ -6,7 +6,6 @@ pub(crate) mod types; #[cfg(test)] mod tests { - use std::convert::AsRef; use std::path::Path; use anyhow::Result; @@ -56,7 +55,7 @@ mod tests { #[test_case(RuleCode::UP032, Path::new("UP032.py"); "UP032")] #[test_case(RuleCode::UP033, Path::new("UP033.py"); "UP033")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/pyupgrade") .join(path) diff --git a/src/rules/ruff/mod.rs b/src/rules/ruff/mod.rs index 2e093a945f..23a1d4901f 100644 --- a/src/rules/ruff/mod.rs +++ b/src/rules/ruff/mod.rs @@ -15,7 +15,7 @@ mod tests { use crate::settings; #[test_case(RuleCode::RUF004, Path::new("RUF004.py"); "RUF004")] fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { - let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); + let snapshot = format!("{}_{}", rule_code.code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/ruff") .join(path)