rule 3/8: Remove AsRef<str> impl for Rule
This commit is contained in:
committed by
Charlie Marsh
parent
3810250bb6
commit
dbcab5128c
@@ -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(),
|
||||
})?
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<T: Write>(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<T: Write>(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<T: Write>(
|
||||
":".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<T: Write>(
|
||||
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,
|
||||
}],
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
14
src/noqa.rs
14
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();
|
||||
|
||||
@@ -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."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user