diff --git a/src/autofix/fixer.rs b/src/autofix/fixer.rs index 04e42573a3..d55e03b00b 100644 --- a/src/autofix/fixer.rs +++ b/src/autofix/fixer.rs @@ -9,6 +9,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::registry::Check; use crate::source_code_locator::SourceCodeLocator; +use crate::violations; #[derive(Debug, Copy, Clone, Hash)] pub enum Mode { diff --git a/src/checkers/ast.rs b/src/checkers/ast.rs index e6daabaf81..25b912981c 100644 --- a/src/checkers/ast.rs +++ b/src/checkers/ast.rs @@ -42,7 +42,8 @@ use crate::{ flake8_debugger, flake8_errmsg, flake8_implicit_str_concat, flake8_import_conventions, flake8_pie, flake8_print, flake8_pytest_style, flake8_return, flake8_simplify, flake8_tidy_imports, flake8_unused_arguments, mccabe, noqa, pandas_vet, pep8_naming, - pycodestyle, pydocstyle, pyflakes, pygrep_hooks, pylint, pyupgrade, ruff, visibility, + pycodestyle, pydocstyle, pyflakes, pygrep_hooks, pylint, pyupgrade, ruff, violations, + visibility, }; const GLOBAL_SCOPE_INDEX: usize = 0; @@ -312,7 +313,7 @@ where if !exists { if self.settings.enabled.contains(&CheckCode::PLE0117) { self.checks.push(Check::new( - CheckKind::NonlocalWithoutBinding(name.to_string()), + violations::NonlocalWithoutBinding(name.to_string()), *range, )); } @@ -573,7 +574,7 @@ where ScopeKind::Class(_) | ScopeKind::Module ) { self.checks.push(Check::new( - CheckKind::ReturnOutsideFunction, + violations::ReturnOutsideFunction, Range::from_located(stmt), )); } @@ -656,7 +657,7 @@ where if self.settings.enabled.contains(&CheckCode::E401) { if names.len() > 1 { self.checks.push(Check::new( - CheckKind::MultipleImportsOnOneLine, + violations::MultipleImportsOnOneLine, Range::from_located(stmt), )); } @@ -665,7 +666,7 @@ where if self.settings.enabled.contains(&CheckCode::E402) { if self.seen_import_boundary && stmt.location.column() == 0 { self.checks.push(Check::new( - CheckKind::ModuleImportNotAtTopOfFile, + violations::ModuleImportNotAtTopOfFile, Range::from_located(stmt), )); } @@ -886,7 +887,7 @@ where if self.settings.enabled.contains(&CheckCode::E402) { if self.seen_import_boundary && stmt.location.column() == 0 { self.checks.push(Check::new( - CheckKind::ModuleImportNotAtTopOfFile, + violations::ModuleImportNotAtTopOfFile, Range::from_located(stmt), )); } @@ -965,7 +966,9 @@ where if self.settings.enabled.contains(&CheckCode::F407) { if !ALL_FEATURE_NAMES.contains(&&*alias.node.name) { self.checks.push(Check::new( - CheckKind::FutureFeatureNotDefined(alias.node.name.to_string()), + violations::FutureFeatureNotDefined( + alias.node.name.to_string(), + ), Range::from_located(alias), )); } @@ -974,7 +977,7 @@ where if self.settings.enabled.contains(&CheckCode::F404) && !self.futures_allowed { self.checks.push(Check::new( - CheckKind::LateFutureImport, + violations::LateFutureImport, Range::from_located(stmt), )); } @@ -994,10 +997,12 @@ where [*(self.scope_stack.last().expect("No current scope found"))]; if !matches!(scope.kind, ScopeKind::Module) { self.checks.push(Check::new( - CheckKind::ImportStarNotPermitted(helpers::format_import_from( - level.as_ref(), - module.as_deref(), - )), + violations::ImportStarNotPermitted( + helpers::format_import_from( + level.as_ref(), + module.as_deref(), + ), + ), Range::from_located(stmt), )); } @@ -1005,7 +1010,7 @@ where if self.settings.enabled.contains(&CheckCode::F403) { self.checks.push(Check::new( - CheckKind::ImportStarUsed(helpers::format_import_from( + violations::ImportStarUsed(helpers::format_import_from( level.as_ref(), module.as_deref(), )), @@ -1804,7 +1809,7 @@ where Err(e) => { if self.settings.enabled.contains(&CheckCode::F521) { self.checks.push(Check::new( - CheckKind::StringDotFormatInvalidFormat( + violations::StringDotFormatInvalidFormat( pyflakes::format::error_to_string(&e), ), location, @@ -2396,7 +2401,7 @@ where let scope = self.current_scope(); if matches!(scope.kind, ScopeKind::Class(_) | ScopeKind::Module) { self.checks.push(Check::new( - CheckKind::YieldOutsideFunction(DeferralKeyword::Yield), + violations::YieldOutsideFunction(DeferralKeyword::Yield), Range::from_located(expr), )); } @@ -2407,7 +2412,7 @@ where let scope = self.current_scope(); if matches!(scope.kind, ScopeKind::Class(_) | ScopeKind::Module) { self.checks.push(Check::new( - CheckKind::YieldOutsideFunction(DeferralKeyword::YieldFrom), + violations::YieldOutsideFunction(DeferralKeyword::YieldFrom), Range::from_located(expr), )); } @@ -2418,7 +2423,7 @@ where let scope = self.current_scope(); if matches!(scope.kind, ScopeKind::Class(_) | ScopeKind::Module) { self.checks.push(Check::new( - CheckKind::YieldOutsideFunction(DeferralKeyword::Await), + violations::YieldOutsideFunction(DeferralKeyword::Await), Range::from_located(expr), )); } @@ -2469,7 +2474,7 @@ where }) => { if self.settings.enabled.contains(&CheckCode::F509) { self.checks.push(Check::new( - CheckKind::PercentFormatUnsupportedFormatCharacter(c), + violations::PercentFormatUnsupportedFormatCharacter(c), location, )); } @@ -2477,7 +2482,7 @@ where Err(e) => { if self.settings.enabled.contains(&CheckCode::F501) { self.checks.push(Check::new( - CheckKind::PercentFormatInvalidFormat(e.to_string()), + violations::PercentFormatInvalidFormat(e.to_string()), location, )); } @@ -3068,7 +3073,7 @@ where if self.bindings[*index].used.is_none() { if self.settings.enabled.contains(&CheckCode::F841) { let mut check = Check::new( - CheckKind::UnusedVariable(name.to_string()), + violations::UnusedVariable(name.to_string()), name_range, ); if self.patch(&CheckCode::F841) { @@ -3354,7 +3359,7 @@ impl<'a> Checker<'a> { overridden = Some((*scope_index, *existing_binding_index)); if self.settings.enabled.contains(&CheckCode::F402) { self.checks.push(Check::new( - CheckKind::ImportShadowedByLoopVar( + violations::ImportShadowedByLoopVar( name.to_string(), existing.range.location.row(), ), @@ -3374,7 +3379,7 @@ impl<'a> Checker<'a> { overridden = Some((*scope_index, *existing_binding_index)); if self.settings.enabled.contains(&CheckCode::F811) { self.checks.push(Check::new( - CheckKind::RedefinedWhileUnused( + violations::RedefinedWhileUnused( name.to_string(), existing.range.location.row(), ), @@ -3500,7 +3505,7 @@ impl<'a> Checker<'a> { from_list.sort(); self.checks.push(Check::new( - CheckKind::ImportStarUsage(id.to_string(), from_list), + violations::ImportStarUsage(id.to_string(), from_list), Range::from_located(expr), )); } @@ -3531,7 +3536,7 @@ impl<'a> Checker<'a> { } self.checks.push(Check::new( - CheckKind::UndefinedName(id.clone()), + violations::UndefinedName(id.clone()), Range::from_located(expr), )); } @@ -3702,7 +3707,7 @@ impl<'a> Checker<'a> { && self.settings.enabled.contains(&CheckCode::F821) { self.checks.push(Check::new( - CheckKind::UndefinedName(id.to_string()), + violations::UndefinedName(id.to_string()), Range::from_located(expr), )); } @@ -3763,7 +3768,7 @@ impl<'a> Checker<'a> { } else { if self.settings.enabled.contains(&CheckCode::F722) { self.checks.push(Check::new( - CheckKind::ForwardAnnotationSyntaxError(expression.to_string()), + violations::ForwardAnnotationSyntaxError(expression.to_string()), range, )); } @@ -3869,7 +3874,7 @@ impl<'a> Checker<'a> { let binding = &self.bindings[*index]; if matches!(binding.kind, BindingKind::Global) { checks.push(Check::new( - CheckKind::GlobalVariableNotAssigned((*name).to_string()), + violations::GlobalVariableNotAssigned((*name).to_string()), binding.range, )); } @@ -3898,7 +3903,7 @@ impl<'a> Checker<'a> { for &name in names { if !scope.values.contains_key(name) { checks.push(Check::new( - CheckKind::UndefinedExport(name.to_string()), + violations::UndefinedExport(name.to_string()), all_binding.range, )); } @@ -3936,7 +3941,7 @@ impl<'a> Checker<'a> { if let Some(indices) = self.redefinitions.get(index) { for index in indices { checks.push(Check::new( - CheckKind::RedefinedWhileUnused( + violations::RedefinedWhileUnused( (*name).to_string(), binding.range.location.row(), ), @@ -3967,7 +3972,7 @@ impl<'a> Checker<'a> { for &name in names { if !scope.values.contains_key(name) { checks.push(Check::new( - CheckKind::ImportStarUsage( + violations::ImportStarUsage( name.to_string(), from_list.clone(), ), @@ -4082,7 +4087,7 @@ impl<'a> Checker<'a> { let multiple = unused_imports.len() > 1; for (full_name, range) in unused_imports { let mut check = Check::new( - CheckKind::UnusedImport(full_name.to_string(), ignore_init, multiple), + violations::UnusedImport(full_name.to_string(), ignore_init, multiple), *range, ); if matches!(child.node, StmtKind::ImportFrom { .. }) @@ -4104,7 +4109,7 @@ impl<'a> Checker<'a> { let multiple = unused_imports.len() > 1; for (full_name, range) in unused_imports { let mut check = Check::new( - CheckKind::UnusedImport(full_name.to_string(), ignore_init, multiple), + violations::UnusedImport(full_name.to_string(), ignore_init, multiple), *range, ); if matches!(child.node, StmtKind::ImportFrom { .. }) diff --git a/src/checkers/imports.rs b/src/checkers/imports.rs index 11715c195b..b2a1d61c0a 100644 --- a/src/checkers/imports.rs +++ b/src/checkers/imports.rs @@ -6,12 +6,12 @@ use rustpython_parser::ast::Suite; use crate::ast::visitor::Visitor; use crate::directives::IsortDirectives; -use crate::isort; use crate::isort::track::ImportTracker; use crate::registry::Check; use crate::settings::{flags, Settings}; use crate::source_code_locator::SourceCodeLocator; use crate::source_code_style::SourceCodeStyleDetector; +use crate::{isort, violations}; fn check_import_blocks( tracker: ImportTracker, diff --git a/src/checkers/lines.rs b/src/checkers/lines.rs index 6cd8d5397f..5c5ad7214b 100644 --- a/src/checkers/lines.rs +++ b/src/checkers/lines.rs @@ -5,6 +5,7 @@ use crate::pygrep_hooks::plugins::{blanket_noqa, blanket_type_ignore}; use crate::pyupgrade::checks::unnecessary_coding_comment; use crate::registry::{Check, CheckCode}; use crate::settings::{flags, Settings}; +use crate::violations; pub fn check_lines( contents: &str, @@ -82,6 +83,7 @@ mod tests { use super::check_lines; use crate::registry::CheckCode; use crate::settings::{flags, Settings}; + use crate::violations; #[test] fn e501_non_ascii_char() { diff --git a/src/checkers/noqa.rs b/src/checkers/noqa.rs index 42af3c73e4..991a01ab07 100644 --- a/src/checkers/noqa.rs +++ b/src/checkers/noqa.rs @@ -7,10 +7,10 @@ use rustpython_parser::ast::Location; use crate::ast::types::Range; use crate::autofix::Fix; -use crate::noqa; use crate::noqa::{is_file_exempt, Directive}; use crate::registry::{Check, CheckCode, CheckKind, UnusedCodes, CODE_REDIRECTS}; use crate::settings::{flags, Settings}; +use crate::{noqa, violations}; pub fn check_noqa( checks: &mut Vec, @@ -42,7 +42,7 @@ pub fn check_noqa( // Remove any ignored checks. for (index, check) in checks.iter().enumerate() { - if check.kind == CheckKind::BlanketNOQA { + if check.kind == violations::BlanketNOQA { continue; } @@ -101,7 +101,7 @@ pub fn check_noqa( Directive::All(spaces, start, end) => { if matches.is_empty() { let mut check = Check::new( - CheckKind::UnusedNOQA(None), + violations::UnusedNOQA(None), Range::new(Location::new(row + 1, start), Location::new(row + 1, end)), ); if matches!(autofix, flags::Autofix::Enabled) @@ -152,7 +152,7 @@ pub fn check_noqa( && unmatched_codes.is_empty()) { let mut check = Check::new( - CheckKind::UnusedNOQA(Some(UnusedCodes { + violations::UnusedNOQA(Some(UnusedCodes { disabled: disabled_codes .iter() .map(|code| (*code).to_string()) diff --git a/src/checkers/tokens.rs b/src/checkers/tokens.rs index b5d3f4230c..e69bd5ca87 100644 --- a/src/checkers/tokens.rs +++ b/src/checkers/tokens.rs @@ -7,7 +7,9 @@ use crate::registry::{Check, CheckCode}; use crate::ruff::checks::Context; use crate::settings::flags; use crate::source_code_locator::SourceCodeLocator; -use crate::{eradicate, flake8_implicit_str_concat, flake8_quotes, pycodestyle, ruff, Settings}; +use crate::{ + eradicate, flake8_implicit_str_concat, flake8_quotes, pycodestyle, ruff, violations, Settings, +}; pub fn check_tokens( locator: &SourceCodeLocator, diff --git a/src/cli.rs b/src/cli.rs index 4c3a051686..23bf3a2ad0 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -4,12 +4,12 @@ use clap::{command, Parser}; use regex::Regex; use rustc_hash::FxHashMap; -use crate::fs; use crate::logging::LogLevel; use crate::registry::{CheckCode, CheckCodePrefix}; use crate::settings::types::{ FilePattern, PatternPrefixPair, PerFileIgnore, PythonVersion, SerializationFormat, }; +use crate::{fs, violations}; #[derive(Debug, Parser)] #[command(author, about = "Ruff: An extremely fast Python linter.")] diff --git a/src/commands.rs b/src/commands.rs index f3babf2913..cb9a32c46b 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -26,7 +26,7 @@ use crate::registry::{CheckCode, CheckKind}; use crate::resolver::{FileDiscovery, PyprojectDiscovery}; use crate::settings::flags; use crate::settings::types::SerializationFormat; -use crate::{cache, fs, one_time_warning, packages, resolver}; +use crate::{cache, fs, one_time_warning, packages, resolver, violations}; /// Run the linter over a collection of files. pub fn run( @@ -119,7 +119,7 @@ pub fn run( let settings = resolver.resolve(path, pyproject_strategy); if settings.enabled.contains(&CheckCode::E902) { Diagnostics::new(vec![Message { - kind: CheckKind::IOError(message), + kind: violations::IOError(message), location: Location::default(), end_location: Location::default(), fix: None, diff --git a/src/directives.rs b/src/directives.rs index 27c9eef777..3623008c64 100644 --- a/src/directives.rs +++ b/src/directives.rs @@ -6,7 +6,7 @@ use rustpython_ast::Location; use rustpython_parser::lexer::{LexResult, Tok}; use crate::registry::LintSource; -use crate::Settings; +use crate::{violations, Settings}; bitflags! { pub struct Flags: u32 { diff --git a/src/eradicate/checks.rs b/src/eradicate/checks.rs index a47604a769..da7942f3f5 100644 --- a/src/eradicate/checks.rs +++ b/src/eradicate/checks.rs @@ -5,7 +5,7 @@ use crate::autofix::Fix; use crate::eradicate::detection::comment_contains_code; use crate::registry::{CheckCode, CheckKind}; use crate::settings::flags; -use crate::{Check, Settings, SourceCodeLocator}; +use crate::{violations, Check, Settings, SourceCodeLocator}; fn is_standalone_comment(line: &str) -> bool { for char in line.chars() { @@ -32,7 +32,7 @@ pub fn commented_out_code( // Verify that the comment is on its own line, and that it contains code. if is_standalone_comment(&line) && comment_contains_code(&line, &settings.task_tags[..]) { - let mut check = Check::new(CheckKind::CommentedOutCode, Range::new(start, end)); + let mut check = Check::new(violations::CommentedOutCode, Range::new(start, end)); if matches!(autofix, flags::Autofix::Enabled) && settings.fixable.contains(&CheckCode::ERA001) { diff --git a/src/eradicate/mod.rs b/src/eradicate/mod.rs index ba8f7d0bf6..7ab7d5d4bc 100644 --- a/src/eradicate/mod.rs +++ b/src/eradicate/mod.rs @@ -11,7 +11,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::ERA001, Path::new("ERA001.py"); "ERA001")] fn checks(check_code: CheckCode, path: &Path) -> Result<()> { diff --git a/src/flake8_2020/mod.rs b/src/flake8_2020/mod.rs index 12d65add56..726c862181 100644 --- a/src/flake8_2020/mod.rs +++ b/src/flake8_2020/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::YTT101, Path::new("YTT101.py"); "YTT101")] #[test_case(CheckCode::YTT102, Path::new("YTT102.py"); "YTT102")] diff --git a/src/flake8_2020/plugins.rs b/src/flake8_2020/plugins.rs index 821df3532a..7429024696 100644 --- a/src/flake8_2020/plugins.rs +++ b/src/flake8_2020/plugins.rs @@ -5,6 +5,7 @@ use crate::ast::helpers::match_module_member; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; +use crate::violations; fn is_sys(checker: &Checker, expr: &Expr, target: &str) -> bool { match_module_member( @@ -35,14 +36,14 @@ pub fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) { && checker.settings.enabled.contains(&CheckCode::YTT303) { checker.checks.push(Check::new( - CheckKind::SysVersionSlice1Referenced, + violations::SysVersionSlice1Referenced, Range::from_located(value), )); } else if *i == BigInt::from(3) && checker.settings.enabled.contains(&CheckCode::YTT101) { checker.checks.push(Check::new( - CheckKind::SysVersionSlice3Referenced, + violations::SysVersionSlice3Referenced, Range::from_located(value), )); } @@ -55,14 +56,14 @@ pub fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) { } => { if *i == BigInt::from(2) && checker.settings.enabled.contains(&CheckCode::YTT102) { checker.checks.push(Check::new( - CheckKind::SysVersion2Referenced, + violations::SysVersion2Referenced, Range::from_located(value), )); } else if *i == BigInt::from(0) && checker.settings.enabled.contains(&CheckCode::YTT301) { checker.checks.push(Check::new( - CheckKind::SysVersion0Referenced, + violations::SysVersion0Referenced, Range::from_located(value), )); } @@ -99,7 +100,7 @@ pub fn compare(checker: &mut Checker, left: &Expr, ops: &[Cmpop], comparators: & && checker.settings.enabled.contains(&CheckCode::YTT201) { checker.checks.push(Check::new( - CheckKind::SysVersionInfo0Eq3Referenced, + violations::SysVersionInfo0Eq3Referenced, Range::from_located(left), )); } @@ -119,7 +120,7 @@ pub fn compare(checker: &mut Checker, left: &Expr, ops: &[Cmpop], comparators: & { if checker.settings.enabled.contains(&CheckCode::YTT203) { checker.checks.push(Check::new( - CheckKind::SysVersionInfo1CmpInt, + violations::SysVersionInfo1CmpInt, Range::from_located(left), )); } @@ -145,7 +146,7 @@ pub fn compare(checker: &mut Checker, left: &Expr, ops: &[Cmpop], comparators: & { if checker.settings.enabled.contains(&CheckCode::YTT204) { checker.checks.push(Check::new( - CheckKind::SysVersionInfoMinorCmpInt, + violations::SysVersionInfoMinorCmpInt, Range::from_located(left), )); } @@ -171,13 +172,13 @@ pub fn compare(checker: &mut Checker, left: &Expr, ops: &[Cmpop], comparators: & if s.len() == 1 { if checker.settings.enabled.contains(&CheckCode::YTT302) { checker.checks.push(Check::new( - CheckKind::SysVersionCmpStr10, + violations::SysVersionCmpStr10, Range::from_located(left), )); } } else if checker.settings.enabled.contains(&CheckCode::YTT103) { checker.checks.push(Check::new( - CheckKind::SysVersionCmpStr3, + violations::SysVersionCmpStr3, Range::from_located(left), )); } @@ -195,7 +196,7 @@ pub fn name_or_attribute(checker: &mut Checker, expr: &Expr) { &checker.import_aliases, ) { checker.checks.push(Check::new( - CheckKind::SixPY3Referenced, + violations::SixPY3Referenced, Range::from_located(expr), )); } diff --git a/src/flake8_annotations/mod.rs b/src/flake8_annotations/mod.rs index 408376bbc7..a605b3935a 100644 --- a/src/flake8_annotations/mod.rs +++ b/src/flake8_annotations/mod.rs @@ -11,7 +11,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::{flake8_annotations, Settings}; + use crate::{flake8_annotations, violations, Settings}; #[test] fn defaults() -> Result<()> { diff --git a/src/flake8_annotations/plugins.rs b/src/flake8_annotations/plugins.rs index 1726ffd903..3aaee8fe67 100644 --- a/src/flake8_annotations/plugins.rs +++ b/src/flake8_annotations/plugins.rs @@ -10,7 +10,7 @@ use crate::flake8_annotations::fixes; use crate::flake8_annotations::helpers::match_function_def; use crate::registry::{CheckCode, CheckKind}; use crate::visibility::Visibility; -use crate::{visibility, Check}; +use crate::{violations, visibility, Check}; #[derive(Default)] struct ReturnStatementVisitor<'a> { @@ -58,7 +58,7 @@ where { if checker.match_typing_expr(annotation, "Any") { checker.checks.push(Check::new( - CheckKind::DynamicallyTypedExpression(func()), + violations::DynamicallyTypedExpression(func()), Range::from_located(annotation), )); }; @@ -94,7 +94,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V { if checker.settings.enabled.contains(&CheckCode::ANN001) { checker.checks.push(Check::new( - CheckKind::MissingTypeFunctionArgument(arg.node.arg.to_string()), + violations::MissingTypeFunctionArgument(arg.node.arg.to_string()), Range::from_located(arg), )); } @@ -117,7 +117,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V { if checker.settings.enabled.contains(&CheckCode::ANN002) { checker.checks.push(Check::new( - CheckKind::MissingTypeArgs(arg.node.arg.to_string()), + violations::MissingTypeArgs(arg.node.arg.to_string()), Range::from_located(arg), )); } @@ -140,7 +140,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V { if checker.settings.enabled.contains(&CheckCode::ANN003) { checker.checks.push(Check::new( - CheckKind::MissingTypeKwargs(arg.node.arg.to_string()), + violations::MissingTypeKwargs(arg.node.arg.to_string()), Range::from_located(arg), )); } @@ -166,7 +166,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V Visibility::Public => { if checker.settings.enabled.contains(&CheckCode::ANN201) { checker.checks.push(Check::new( - CheckKind::MissingReturnTypePublicFunction(name.to_string()), + violations::MissingReturnTypePublicFunction(name.to_string()), helpers::identifier_range(stmt, checker.locator), )); } @@ -174,7 +174,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V Visibility::Private => { if checker.settings.enabled.contains(&CheckCode::ANN202) { checker.checks.push(Check::new( - CheckKind::MissingReturnTypePrivateFunction(name.to_string()), + violations::MissingReturnTypePrivateFunction(name.to_string()), helpers::identifier_range(stmt, checker.locator), )); } @@ -212,7 +212,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V { if checker.settings.enabled.contains(&CheckCode::ANN001) { checker.checks.push(Check::new( - CheckKind::MissingTypeFunctionArgument(arg.node.arg.to_string()), + violations::MissingTypeFunctionArgument(arg.node.arg.to_string()), Range::from_located(arg), )); } @@ -236,7 +236,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V { if checker.settings.enabled.contains(&CheckCode::ANN002) { checker.checks.push(Check::new( - CheckKind::MissingTypeArgs(arg.node.arg.to_string()), + violations::MissingTypeArgs(arg.node.arg.to_string()), Range::from_located(arg), )); } @@ -260,7 +260,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V { if checker.settings.enabled.contains(&CheckCode::ANN003) { checker.checks.push(Check::new( - CheckKind::MissingTypeKwargs(arg.node.arg.to_string()), + violations::MissingTypeKwargs(arg.node.arg.to_string()), Range::from_located(arg), )); } @@ -275,14 +275,14 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V if visibility::is_classmethod(checker, cast::decorator_list(stmt)) { if checker.settings.enabled.contains(&CheckCode::ANN102) { checker.checks.push(Check::new( - CheckKind::MissingTypeCls(arg.node.arg.to_string()), + violations::MissingTypeCls(arg.node.arg.to_string()), Range::from_located(arg), )); } } else { if checker.settings.enabled.contains(&CheckCode::ANN101) { checker.checks.push(Check::new( - CheckKind::MissingTypeSelf(arg.node.arg.to_string()), + violations::MissingTypeSelf(arg.node.arg.to_string()), Range::from_located(arg), )); } @@ -308,14 +308,14 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V if visibility::is_classmethod(checker, cast::decorator_list(stmt)) { if checker.settings.enabled.contains(&CheckCode::ANN206) { checker.checks.push(Check::new( - CheckKind::MissingReturnTypeClassMethod(name.to_string()), + violations::MissingReturnTypeClassMethod(name.to_string()), helpers::identifier_range(stmt, checker.locator), )); } } else if visibility::is_staticmethod(checker, cast::decorator_list(stmt)) { if checker.settings.enabled.contains(&CheckCode::ANN205) { checker.checks.push(Check::new( - CheckKind::MissingReturnTypeStaticMethod(name.to_string()), + violations::MissingReturnTypeStaticMethod(name.to_string()), helpers::identifier_range(stmt, checker.locator), )); } @@ -327,7 +327,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V && has_any_typed_arg) { let mut check = Check::new( - CheckKind::MissingReturnTypeSpecialMethod(name.to_string()), + violations::MissingReturnTypeSpecialMethod(name.to_string()), helpers::identifier_range(stmt, checker.locator), ); if checker.patch(check.kind.code()) { @@ -344,7 +344,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V } else if visibility::is_magic(stmt) { if checker.settings.enabled.contains(&CheckCode::ANN204) { checker.checks.push(Check::new( - CheckKind::MissingReturnTypeSpecialMethod(name.to_string()), + violations::MissingReturnTypeSpecialMethod(name.to_string()), helpers::identifier_range(stmt, checker.locator), )); } @@ -353,7 +353,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V Visibility::Public => { if checker.settings.enabled.contains(&CheckCode::ANN201) { checker.checks.push(Check::new( - CheckKind::MissingReturnTypePublicFunction(name.to_string()), + violations::MissingReturnTypePublicFunction(name.to_string()), helpers::identifier_range(stmt, checker.locator), )); } @@ -361,7 +361,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V Visibility::Private => { if checker.settings.enabled.contains(&CheckCode::ANN202) { checker.checks.push(Check::new( - CheckKind::MissingReturnTypePrivateFunction(name.to_string()), + violations::MissingReturnTypePrivateFunction(name.to_string()), helpers::identifier_range(stmt, checker.locator), )); } diff --git a/src/flake8_bandit/checks/assert_used.rs b/src/flake8_bandit/checks/assert_used.rs index 2cb5a3c4a7..8b19c75c9f 100644 --- a/src/flake8_bandit/checks/assert_used.rs +++ b/src/flake8_bandit/checks/assert_used.rs @@ -2,8 +2,9 @@ use rustpython_ast::{Located, StmtKind}; use crate::ast::types::Range; use crate::registry::{Check, CheckKind}; +use crate::violations; /// S101 pub fn assert_used(stmt: &Located) -> Check { - Check::new(CheckKind::AssertUsed, Range::from_located(stmt)) + Check::new(violations::AssertUsed, Range::from_located(stmt)) } diff --git a/src/flake8_bandit/checks/bad_file_permissions.rs b/src/flake8_bandit/checks/bad_file_permissions.rs index ce6a4d4f91..08119a7aad 100644 --- a/src/flake8_bandit/checks/bad_file_permissions.rs +++ b/src/flake8_bandit/checks/bad_file_permissions.rs @@ -6,6 +6,7 @@ use rustpython_ast::{Constant, Expr, ExprKind, Keyword, Operator}; use crate::ast::helpers::{compose_call_path, match_module_member, SimpleCallArgs}; use crate::ast::types::Range; use crate::registry::{Check, CheckKind}; +use crate::violations; const WRITE_WORLD: u16 = 0o2; const EXECUTE_GROUP: u16 = 0o10; @@ -97,7 +98,7 @@ pub fn bad_file_permissions( if let Some(int_value) = get_int_value(mode_arg) { if (int_value & WRITE_WORLD > 0) || (int_value & EXECUTE_GROUP > 0) { return Some(Check::new( - CheckKind::BadFilePermissions(int_value), + violations::BadFilePermissions(int_value), Range::from_located(mode_arg), )); } diff --git a/src/flake8_bandit/checks/exec_used.rs b/src/flake8_bandit/checks/exec_used.rs index e206e821a7..c843f9a976 100644 --- a/src/flake8_bandit/checks/exec_used.rs +++ b/src/flake8_bandit/checks/exec_used.rs @@ -2,6 +2,7 @@ use rustpython_ast::{Expr, ExprKind}; use crate::ast::types::Range; use crate::registry::{Check, CheckKind}; +use crate::violations; /// S102 pub fn exec_used(expr: &Expr, func: &Expr) -> Option { @@ -11,5 +12,5 @@ pub fn exec_used(expr: &Expr, func: &Expr) -> Option { if id != "exec" { return None; } - Some(Check::new(CheckKind::ExecUsed, Range::from_located(expr))) + Some(Check::new(violations::ExecUsed, Range::from_located(expr))) } diff --git a/src/flake8_bandit/checks/hardcoded_bind_all_interfaces.rs b/src/flake8_bandit/checks/hardcoded_bind_all_interfaces.rs index c160425899..49dc24c86a 100644 --- a/src/flake8_bandit/checks/hardcoded_bind_all_interfaces.rs +++ b/src/flake8_bandit/checks/hardcoded_bind_all_interfaces.rs @@ -1,10 +1,11 @@ use crate::ast::types::Range; use crate::registry::{Check, CheckKind}; +use crate::violations; /// S104 pub fn hardcoded_bind_all_interfaces(value: &str, range: &Range) -> Option { if value == "0.0.0.0" { - Some(Check::new(CheckKind::HardcodedBindAllInterfaces, *range)) + Some(Check::new(violations::HardcodedBindAllInterfaces, *range)) } else { None } diff --git a/src/flake8_bandit/checks/hardcoded_password_default.rs b/src/flake8_bandit/checks/hardcoded_password_default.rs index e37e4d1155..cbf02e439c 100644 --- a/src/flake8_bandit/checks/hardcoded_password_default.rs +++ b/src/flake8_bandit/checks/hardcoded_password_default.rs @@ -3,6 +3,7 @@ use rustpython_ast::{ArgData, Arguments, Expr, Located}; use crate::ast::types::Range; use crate::flake8_bandit::helpers::{matches_password_name, string_literal}; use crate::registry::{Check, CheckKind}; +use crate::violations; fn check_password_kwarg(arg: &Located, default: &Expr) -> Option { let string = string_literal(default)?; @@ -11,7 +12,7 @@ fn check_password_kwarg(arg: &Located, default: &Expr) -> Option return None; } Some(Check::new( - CheckKind::HardcodedPasswordDefault(string.to_string()), + violations::HardcodedPasswordDefault(string.to_string()), Range::from_located(default), )) } diff --git a/src/flake8_bandit/checks/hardcoded_password_func_arg.rs b/src/flake8_bandit/checks/hardcoded_password_func_arg.rs index 448cb25709..9c8b7a6bf1 100644 --- a/src/flake8_bandit/checks/hardcoded_password_func_arg.rs +++ b/src/flake8_bandit/checks/hardcoded_password_func_arg.rs @@ -3,6 +3,7 @@ use rustpython_ast::Keyword; use crate::ast::types::Range; use crate::flake8_bandit::helpers::{matches_password_name, string_literal}; use crate::registry::{Check, CheckKind}; +use crate::violations; /// S106 pub fn hardcoded_password_func_arg(keywords: &[Keyword]) -> Vec { @@ -15,7 +16,7 @@ pub fn hardcoded_password_func_arg(keywords: &[Keyword]) -> Vec { return None; } Some(Check::new( - CheckKind::HardcodedPasswordFuncArg(string.to_string()), + violations::HardcodedPasswordFuncArg(string.to_string()), Range::from_located(keyword), )) }) diff --git a/src/flake8_bandit/checks/hardcoded_password_string.rs b/src/flake8_bandit/checks/hardcoded_password_string.rs index 8b31e71a8e..0a69503921 100644 --- a/src/flake8_bandit/checks/hardcoded_password_string.rs +++ b/src/flake8_bandit/checks/hardcoded_password_string.rs @@ -3,6 +3,7 @@ use rustpython_ast::{Constant, Expr, ExprKind}; use crate::ast::types::Range; use crate::flake8_bandit::helpers::{matches_password_name, string_literal}; use crate::registry::{Check, CheckKind}; +use crate::violations; fn is_password_target(target: &Expr) -> bool { let target_name = match &target.node { @@ -34,7 +35,7 @@ pub fn compare_to_hardcoded_password_string(left: &Expr, comparators: &[Expr]) - return None; } Some(Check::new( - CheckKind::HardcodedPasswordString(string.to_string()), + violations::HardcodedPasswordString(string.to_string()), Range::from_located(comp), )) }) @@ -47,7 +48,7 @@ pub fn assign_hardcoded_password_string(value: &Expr, targets: &[Expr]) -> Optio for target in targets { if is_password_target(target) { return Some(Check::new( - CheckKind::HardcodedPasswordString(string.to_string()), + violations::HardcodedPasswordString(string.to_string()), Range::from_located(value), )); } diff --git a/src/flake8_bandit/checks/hardcoded_tmp_directory.rs b/src/flake8_bandit/checks/hardcoded_tmp_directory.rs index d082a4aab8..901e5dcd78 100644 --- a/src/flake8_bandit/checks/hardcoded_tmp_directory.rs +++ b/src/flake8_bandit/checks/hardcoded_tmp_directory.rs @@ -2,12 +2,13 @@ use rustpython_ast::Expr; use crate::ast::types::Range; use crate::registry::{Check, CheckKind}; +use crate::violations; /// S108 pub fn hardcoded_tmp_directory(expr: &Expr, value: &str, prefixes: &[String]) -> Option { if prefixes.iter().any(|prefix| value.starts_with(prefix)) { Some(Check::new( - CheckKind::HardcodedTempFile(value.to_string()), + violations::HardcodedTempFile(value.to_string()), Range::from_located(expr), )) } else { diff --git a/src/flake8_bandit/checks/hashlib_insecure_hash_functions.rs b/src/flake8_bandit/checks/hashlib_insecure_hash_functions.rs index 5d27c0fdc4..975ffc404c 100644 --- a/src/flake8_bandit/checks/hashlib_insecure_hash_functions.rs +++ b/src/flake8_bandit/checks/hashlib_insecure_hash_functions.rs @@ -5,6 +5,7 @@ use crate::ast::helpers::{match_module_member, SimpleCallArgs}; use crate::ast::types::Range; use crate::flake8_bandit::helpers::string_literal; use crate::registry::{Check, CheckKind}; +use crate::violations; const WEAK_HASHES: [&str; 4] = ["md4", "md5", "sha", "sha1"]; @@ -41,7 +42,7 @@ pub fn hashlib_insecure_hash_functions( if WEAK_HASHES.contains(&hash_func_name.to_lowercase().as_str()) { return Some(Check::new( - CheckKind::HashlibInsecureHashFunction(hash_func_name.to_string()), + violations::HashlibInsecureHashFunction(hash_func_name.to_string()), Range::from_located(name_arg), )); } @@ -56,7 +57,7 @@ pub fn hashlib_insecure_hash_functions( } return Some(Check::new( - CheckKind::HashlibInsecureHashFunction((*func_name).to_string()), + violations::HashlibInsecureHashFunction((*func_name).to_string()), Range::from_located(func), )); } diff --git a/src/flake8_bandit/checks/request_with_no_cert_validation.rs b/src/flake8_bandit/checks/request_with_no_cert_validation.rs index 8dd9fef4f7..a7c1c0a126 100644 --- a/src/flake8_bandit/checks/request_with_no_cert_validation.rs +++ b/src/flake8_bandit/checks/request_with_no_cert_validation.rs @@ -5,6 +5,7 @@ use rustpython_parser::ast::Constant; use crate::ast::helpers::{collect_call_paths, dealias_call_path, match_call_path, SimpleCallArgs}; use crate::ast::types::Range; use crate::registry::{Check, CheckKind}; +use crate::violations; const REQUESTS_HTTP_VERBS: [&str; 7] = ["get", "options", "head", "post", "put", "patch", "delete"]; const HTTPX_METHODS: [&str; 11] = [ @@ -41,7 +42,7 @@ pub fn request_with_no_cert_validation( } = &verify_arg.node { return Some(Check::new( - CheckKind::RequestWithNoCertValidation("requests".to_string()), + violations::RequestWithNoCertValidation("requests".to_string()), Range::from_located(verify_arg), )); } @@ -58,7 +59,7 @@ pub fn request_with_no_cert_validation( } = &verify_arg.node { return Some(Check::new( - CheckKind::RequestWithNoCertValidation("httpx".to_string()), + violations::RequestWithNoCertValidation("httpx".to_string()), Range::from_located(verify_arg), )); } diff --git a/src/flake8_bandit/checks/request_without_timeout.rs b/src/flake8_bandit/checks/request_without_timeout.rs index 18d258d7ef..252a30c4cd 100644 --- a/src/flake8_bandit/checks/request_without_timeout.rs +++ b/src/flake8_bandit/checks/request_without_timeout.rs @@ -5,6 +5,7 @@ use rustpython_parser::ast::Constant; use crate::ast::helpers::{collect_call_paths, dealias_call_path, match_call_path, SimpleCallArgs}; use crate::ast::types::Range; use crate::registry::{Check, CheckKind}; +use crate::violations; const HTTP_VERBS: [&str; 7] = ["get", "options", "head", "post", "put", "patch", "delete"]; @@ -29,13 +30,13 @@ pub fn request_without_timeout( _ => None, } { return Some(Check::new( - CheckKind::RequestWithoutTimeout(Some(timeout)), + violations::RequestWithoutTimeout(Some(timeout)), Range::from_located(timeout_arg), )); } } else { return Some(Check::new( - CheckKind::RequestWithoutTimeout(None), + violations::RequestWithoutTimeout(None), Range::from_located(func), )); } diff --git a/src/flake8_bandit/checks/unsafe_yaml_load.rs b/src/flake8_bandit/checks/unsafe_yaml_load.rs index 9c3e6e51f0..44c725b08c 100644 --- a/src/flake8_bandit/checks/unsafe_yaml_load.rs +++ b/src/flake8_bandit/checks/unsafe_yaml_load.rs @@ -4,6 +4,7 @@ use rustpython_ast::{Expr, ExprKind, Keyword}; use crate::ast::helpers::{match_module_member, SimpleCallArgs}; use crate::ast::types::Range; use crate::registry::{Check, CheckKind}; +use crate::violations; /// S506 pub fn unsafe_yaml_load( @@ -35,13 +36,13 @@ pub fn unsafe_yaml_load( _ => None, }; return Some(Check::new( - CheckKind::UnsafeYAMLLoad(loader), + violations::UnsafeYAMLLoad(loader), Range::from_located(loader_arg), )); } } else { return Some(Check::new( - CheckKind::UnsafeYAMLLoad(None), + violations::UnsafeYAMLLoad(None), Range::from_located(func), )); } diff --git a/src/flake8_bandit/mod.rs b/src/flake8_bandit/mod.rs index f7ccc5beba..f55ac00107 100644 --- a/src/flake8_bandit/mod.rs +++ b/src/flake8_bandit/mod.rs @@ -11,7 +11,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::{flake8_bandit, Settings}; + use crate::{flake8_bandit, violations, Settings}; #[test_case(CheckCode::S101, Path::new("S101.py"); "S101")] #[test_case(CheckCode::S102, Path::new("S102.py"); "S102")] diff --git a/src/flake8_blind_except/mod.rs b/src/flake8_blind_except/mod.rs index a9ded38787..fd48692b75 100644 --- a/src/flake8_blind_except/mod.rs +++ b/src/flake8_blind_except/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::BLE001, Path::new("BLE.py"); "BLE001")] fn checks(check_code: CheckCode, path: &Path) -> Result<()> { diff --git a/src/flake8_blind_except/plugins.rs b/src/flake8_blind_except/plugins.rs index 03c4d97846..3fd595f087 100644 --- a/src/flake8_blind_except/plugins.rs +++ b/src/flake8_blind_except/plugins.rs @@ -3,6 +3,7 @@ use rustpython_ast::{Expr, ExprKind, Stmt, StmtKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// BLE001 pub fn blind_except( @@ -36,7 +37,7 @@ pub fn blind_except( } }) { checker.checks.push(Check::new( - CheckKind::BlindExcept(id.to_string()), + violations::BlindExcept(id.to_string()), Range::from_located(type_), )); } diff --git a/src/flake8_boolean_trap/mod.rs b/src/flake8_boolean_trap/mod.rs index a067814fa1..da482c2335 100644 --- a/src/flake8_boolean_trap/mod.rs +++ b/src/flake8_boolean_trap/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::FBT001, Path::new("FBT.py"); "FBT001")] #[test_case(CheckCode::FBT002, Path::new("FBT.py"); "FBT002")] diff --git a/src/flake8_boolean_trap/plugins.rs b/src/flake8_boolean_trap/plugins.rs index 3c37db9fe6..73dff14e7f 100644 --- a/src/flake8_boolean_trap/plugins.rs +++ b/src/flake8_boolean_trap/plugins.rs @@ -4,6 +4,7 @@ use rustpython_parser::ast::{Constant, Expr}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; const FUNC_NAME_ALLOWLIST: &[&str] = &[ "assertEqual", @@ -76,7 +77,7 @@ pub fn check_positional_boolean_in_def(checker: &mut Checker, arguments: &Argume continue; } checker.checks.push(Check::new( - CheckKind::BooleanPositionalArgInFunctionDefinition, + violations::BooleanPositionalArgInFunctionDefinition, Range::from_located(arg), )); } @@ -90,7 +91,7 @@ pub fn check_boolean_default_value_in_function_definition( add_if_boolean( checker, arg, - CheckKind::BooleanDefaultValueInFunctionDefinition, + violations::BooleanDefaultValueInFunctionDefinition, ); } } @@ -107,7 +108,7 @@ pub fn check_boolean_positional_value_in_function_call( add_if_boolean( checker, arg, - CheckKind::BooleanPositionalValueInFunctionCall, + violations::BooleanPositionalValueInFunctionCall, ); } } diff --git a/src/flake8_bugbear/mod.rs b/src/flake8_bugbear/mod.rs index 2ca9f309ed..f868246103 100644 --- a/src/flake8_bugbear/mod.rs +++ b/src/flake8_bugbear/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::{flake8_bugbear, Settings}; + use crate::{flake8_bugbear, violations, Settings}; #[test_case(CheckCode::B002, Path::new("B002.py"); "B002")] #[test_case(CheckCode::B003, Path::new("B003.py"); "B003")] diff --git a/src/flake8_bugbear/plugins/abstract_base_class.rs b/src/flake8_bugbear/plugins/abstract_base_class.rs index ebeaf4e61b..01a9aa6d41 100644 --- a/src/flake8_bugbear/plugins/abstract_base_class.rs +++ b/src/flake8_bugbear/plugins/abstract_base_class.rs @@ -5,6 +5,7 @@ use crate::ast::helpers::match_module_member; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; +use crate::violations; fn is_abc_class( bases: &[Expr], @@ -118,7 +119,7 @@ pub fn abstract_base_class( .any(|d| is_overload(d, &checker.from_imports, &checker.import_aliases)) { checker.checks.push(Check::new( - CheckKind::EmptyMethodWithoutAbstractDecorator(name.to_string()), + violations::EmptyMethodWithoutAbstractDecorator(name.to_string()), Range::from_located(stmt), )); } @@ -126,7 +127,7 @@ pub fn abstract_base_class( if checker.settings.enabled.contains(&CheckCode::B024) { if !has_abstract_method { checker.checks.push(Check::new( - CheckKind::AbstractBaseClassWithoutAbstractMethod(name.to_string()), + violations::AbstractBaseClassWithoutAbstractMethod(name.to_string()), Range::from_located(stmt), )); } diff --git a/src/flake8_bugbear/plugins/assert_false.rs b/src/flake8_bugbear/plugins/assert_false.rs index f6664d1dc7..714a81829a 100644 --- a/src/flake8_bugbear/plugins/assert_false.rs +++ b/src/flake8_bugbear/plugins/assert_false.rs @@ -5,6 +5,7 @@ use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; use crate::source_code_generator::SourceCodeGenerator; +use crate::violations; fn assertion_error(msg: Option<&Expr>) -> Stmt { Stmt::new( @@ -45,7 +46,7 @@ pub fn assert_false(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg: Option return; }; - let mut check = Check::new(CheckKind::DoNotAssertFalse, Range::from_located(test)); + let mut check = Check::new(violations::DoNotAssertFalse, Range::from_located(test)); if checker.patch(check.kind.code()) { let mut generator: SourceCodeGenerator = checker.style.into(); generator.unparse_stmt(&assertion_error(msg)); diff --git a/src/flake8_bugbear/plugins/assert_raises_exception.rs b/src/flake8_bugbear/plugins/assert_raises_exception.rs index 4fa7a41ec2..2738f00155 100644 --- a/src/flake8_bugbear/plugins/assert_raises_exception.rs +++ b/src/flake8_bugbear/plugins/assert_raises_exception.rs @@ -4,6 +4,7 @@ use crate::ast::helpers::match_module_member; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// B017 pub fn assert_raises_exception(checker: &mut Checker, stmt: &Stmt, items: &[Withitem]) { @@ -34,7 +35,7 @@ pub fn assert_raises_exception(checker: &mut Checker, stmt: &Stmt, items: &[With } checker.checks.push(Check::new( - CheckKind::NoAssertRaisesException, + violations::NoAssertRaisesException, Range::from_located(stmt), )); } diff --git a/src/flake8_bugbear/plugins/assignment_to_os_environ.rs b/src/flake8_bugbear/plugins/assignment_to_os_environ.rs index f9ea3a06e5..576858d80b 100644 --- a/src/flake8_bugbear/plugins/assignment_to_os_environ.rs +++ b/src/flake8_bugbear/plugins/assignment_to_os_environ.rs @@ -3,6 +3,7 @@ use rustpython_ast::{Expr, ExprKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// B003 pub fn assignment_to_os_environ(checker: &mut Checker, targets: &[Expr]) { @@ -23,7 +24,7 @@ pub fn assignment_to_os_environ(checker: &mut Checker, targets: &[Expr]) { return; } checker.checks.push(Check::new( - CheckKind::AssignmentToOsEnviron, + violations::AssignmentToOsEnviron, Range::from_located(target), )); } diff --git a/src/flake8_bugbear/plugins/cached_instance_method.rs b/src/flake8_bugbear/plugins/cached_instance_method.rs index 98586c816f..d7478a9f68 100644 --- a/src/flake8_bugbear/plugins/cached_instance_method.rs +++ b/src/flake8_bugbear/plugins/cached_instance_method.rs @@ -4,6 +4,7 @@ use crate::ast::helpers::{collect_call_paths, dealias_call_path, match_call_path use crate::ast::types::{Range, ScopeKind}; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; fn is_cache_func(checker: &Checker, expr: &Expr) -> bool { let call_path = dealias_call_path(collect_call_paths(expr), &checker.import_aliases); @@ -34,7 +35,7 @@ pub fn cached_instance_method(checker: &mut Checker, decorator_list: &[Expr]) { }, ) { checker.checks.push(Check::new( - CheckKind::CachedInstanceMethod, + violations::CachedInstanceMethod, Range::from_located(decorator), )); } diff --git a/src/flake8_bugbear/plugins/cannot_raise_literal.rs b/src/flake8_bugbear/plugins/cannot_raise_literal.rs index 8c3e69b99e..d42baf0109 100644 --- a/src/flake8_bugbear/plugins/cannot_raise_literal.rs +++ b/src/flake8_bugbear/plugins/cannot_raise_literal.rs @@ -3,6 +3,7 @@ use rustpython_ast::{Expr, ExprKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// B016 pub fn cannot_raise_literal(checker: &mut Checker, expr: &Expr) { @@ -10,7 +11,7 @@ pub fn cannot_raise_literal(checker: &mut Checker, expr: &Expr) { return; }; checker.checks.push(Check::new( - CheckKind::CannotRaiseLiteral, + violations::CannotRaiseLiteral, Range::from_located(expr), )); } diff --git a/src/flake8_bugbear/plugins/duplicate_exceptions.rs b/src/flake8_bugbear/plugins/duplicate_exceptions.rs index 6251d7f2f3..ec80d6abab 100644 --- a/src/flake8_bugbear/plugins/duplicate_exceptions.rs +++ b/src/flake8_bugbear/plugins/duplicate_exceptions.rs @@ -8,6 +8,7 @@ use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; use crate::source_code_generator::SourceCodeGenerator; +use crate::violations; fn type_pattern(elts: Vec<&Expr>) -> Expr { Expr::new( @@ -44,7 +45,7 @@ fn duplicate_handler_exceptions<'a>( // TODO(charlie): Handle "BaseException" and redundant exception aliases. if !duplicates.is_empty() { let mut check = Check::new( - CheckKind::DuplicateHandlerException( + violations::DuplicateHandlerException( duplicates .into_iter() .map(|call_path| call_path.join(".")) @@ -108,7 +109,7 @@ pub fn duplicate_exceptions(checker: &mut Checker, handlers: &[Excepthandler]) { for (name, exprs) in duplicates { for expr in exprs { checker.checks.push(Check::new( - CheckKind::DuplicateTryBlockException(name.join(".")), + violations::DuplicateTryBlockException(name.join(".")), Range::from_located(expr), )); } diff --git a/src/flake8_bugbear/plugins/f_string_docstring.rs b/src/flake8_bugbear/plugins/f_string_docstring.rs index 86dc439973..0098942b5e 100644 --- a/src/flake8_bugbear/plugins/f_string_docstring.rs +++ b/src/flake8_bugbear/plugins/f_string_docstring.rs @@ -3,6 +3,7 @@ use rustpython_ast::{ExprKind, Stmt, StmtKind}; use crate::ast::helpers; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// B021 pub fn f_string_docstring(checker: &mut Checker, body: &[Stmt]) { @@ -16,7 +17,7 @@ pub fn f_string_docstring(checker: &mut Checker, body: &[Stmt]) { return; }; checker.checks.push(Check::new( - CheckKind::FStringDocstring, + violations::FStringDocstring, helpers::identifier_range(stmt, checker.locator), )); } diff --git a/src/flake8_bugbear/plugins/function_call_argument_default.rs b/src/flake8_bugbear/plugins/function_call_argument_default.rs index 8d972208a2..80642b3c20 100644 --- a/src/flake8_bugbear/plugins/function_call_argument_default.rs +++ b/src/flake8_bugbear/plugins/function_call_argument_default.rs @@ -10,6 +10,7 @@ use crate::ast::visitor::Visitor; use crate::checkers::ast::Checker; use crate::flake8_bugbear::plugins::mutable_argument_default::is_mutable_func; use crate::registry::{Check, CheckKind}; +use crate::violations; const IMMUTABLE_FUNCS: [(&str, &str); 7] = [ ("", "tuple"), @@ -58,7 +59,7 @@ where && !is_nan_or_infinity(func, args) { self.checks.push(( - CheckKind::FunctionCallArgumentDefault(compose_call_path(expr)), + violations::FunctionCallArgumentDefault(compose_call_path(expr)), Range::from_located(expr), )); } diff --git a/src/flake8_bugbear/plugins/function_uses_loop_variable.rs b/src/flake8_bugbear/plugins/function_uses_loop_variable.rs index ccb4e1bc03..92048beabc 100644 --- a/src/flake8_bugbear/plugins/function_uses_loop_variable.rs +++ b/src/flake8_bugbear/plugins/function_uses_loop_variable.rs @@ -7,6 +7,7 @@ use crate::ast::visitor; use crate::ast::visitor::Visitor; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; #[derive(Default)] struct LoadedNamesVisitor<'a> { @@ -212,7 +213,7 @@ where if !checker.flake8_bugbear_seen.contains(&expr) { checker.flake8_bugbear_seen.push(expr); checker.checks.push(Check::new( - CheckKind::FunctionUsesLoopVariable(name.to_string()), + violations::FunctionUsesLoopVariable(name.to_string()), range, )); } diff --git a/src/flake8_bugbear/plugins/getattr_with_constant.rs b/src/flake8_bugbear/plugins/getattr_with_constant.rs index 9c4e5b8604..3d81842d0c 100644 --- a/src/flake8_bugbear/plugins/getattr_with_constant.rs +++ b/src/flake8_bugbear/plugins/getattr_with_constant.rs @@ -7,6 +7,7 @@ use crate::python::identifiers::IDENTIFIER_REGEX; use crate::python::keyword::KWLIST; use crate::registry::{Check, CheckKind}; use crate::source_code_generator::SourceCodeGenerator; +use crate::violations; fn attribute(value: &Expr, attr: &str) -> Expr { Expr::new( @@ -44,7 +45,7 @@ pub fn getattr_with_constant(checker: &mut Checker, expr: &Expr, func: &Expr, ar return; } - let mut check = Check::new(CheckKind::GetAttrWithConstant, Range::from_located(expr)); + let mut check = Check::new(violations::GetAttrWithConstant, Range::from_located(expr)); if checker.patch(check.kind.code()) { let mut generator: SourceCodeGenerator = checker.style.into(); generator.unparse_expr(&attribute(obj, value), 0); diff --git a/src/flake8_bugbear/plugins/jump_statement_in_finally.rs b/src/flake8_bugbear/plugins/jump_statement_in_finally.rs index f713e2ea1d..ce500f2ad7 100644 --- a/src/flake8_bugbear/plugins/jump_statement_in_finally.rs +++ b/src/flake8_bugbear/plugins/jump_statement_in_finally.rs @@ -3,12 +3,13 @@ use rustpython_ast::{Stmt, StmtKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; fn walk_stmt(checker: &mut Checker, body: &[Stmt], f: fn(&Stmt) -> bool) { for stmt in body { if f(stmt) { checker.checks.push(Check::new( - CheckKind::JumpStatementInFinally(match &stmt.node { + violations::JumpStatementInFinally(match &stmt.node { StmtKind::Break { .. } => "break".to_string(), StmtKind::Continue { .. } => "continue".to_string(), StmtKind::Return { .. } => "return".to_string(), diff --git a/src/flake8_bugbear/plugins/loop_variable_overrides_iterator.rs b/src/flake8_bugbear/plugins/loop_variable_overrides_iterator.rs index ccd2838df7..bf7278b581 100644 --- a/src/flake8_bugbear/plugins/loop_variable_overrides_iterator.rs +++ b/src/flake8_bugbear/plugins/loop_variable_overrides_iterator.rs @@ -6,6 +6,7 @@ use crate::ast::visitor; use crate::ast::visitor::Visitor; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; #[derive(Default)] struct NameFinder<'a> { @@ -56,7 +57,7 @@ pub fn loop_variable_overrides_iterator(checker: &mut Checker, target: &Expr, it for (name, expr) in target_names { if iter_names.contains_key(name) { checker.checks.push(Check::new( - CheckKind::LoopVariableOverridesIterator(name.to_string()), + violations::LoopVariableOverridesIterator(name.to_string()), Range::from_located(expr), )); } diff --git a/src/flake8_bugbear/plugins/mutable_argument_default.rs b/src/flake8_bugbear/plugins/mutable_argument_default.rs index 3085175404..b4a3e9b0c3 100644 --- a/src/flake8_bugbear/plugins/mutable_argument_default.rs +++ b/src/flake8_bugbear/plugins/mutable_argument_default.rs @@ -5,6 +5,7 @@ use crate::ast::helpers::{collect_call_paths, dealias_call_path, match_call_path use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; const MUTABLE_FUNCS: &[(&str, &str)] = &[ ("", "dict"), @@ -165,7 +166,7 @@ pub fn mutable_argument_default(checker: &mut Checker, arguments: &Arguments) { }) { checker.checks.push(Check::new( - CheckKind::MutableArgumentDefault, + violations::MutableArgumentDefault, Range::from_located(default), )); } diff --git a/src/flake8_bugbear/plugins/raise_without_from_inside_except.rs b/src/flake8_bugbear/plugins/raise_without_from_inside_except.rs index 0ddd886202..a303a00d2b 100644 --- a/src/flake8_bugbear/plugins/raise_without_from_inside_except.rs +++ b/src/flake8_bugbear/plugins/raise_without_from_inside_except.rs @@ -5,6 +5,7 @@ use crate::ast::visitor::Visitor; use crate::checkers::ast::Checker; use crate::python::string::is_lower; use crate::registry::{Check, CheckKind}; +use crate::violations; struct RaiseVisitor { checks: Vec, @@ -20,7 +21,7 @@ impl<'a> Visitor<'a> for RaiseVisitor { ExprKind::Name { id, .. } if is_lower(id) => {} _ => { self.checks.push(Check::new( - CheckKind::RaiseWithoutFromInsideExcept, + violations::RaiseWithoutFromInsideExcept, Range::from_located(stmt), )); } diff --git a/src/flake8_bugbear/plugins/redundant_tuple_in_exception_handler.rs b/src/flake8_bugbear/plugins/redundant_tuple_in_exception_handler.rs index a02ac662ee..16db47779c 100644 --- a/src/flake8_bugbear/plugins/redundant_tuple_in_exception_handler.rs +++ b/src/flake8_bugbear/plugins/redundant_tuple_in_exception_handler.rs @@ -5,6 +5,7 @@ use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; use crate::source_code_generator::SourceCodeGenerator; +use crate::violations; /// B013 pub fn redundant_tuple_in_exception_handler(checker: &mut Checker, handlers: &[Excepthandler]) { @@ -19,7 +20,7 @@ pub fn redundant_tuple_in_exception_handler(checker: &mut Checker, handlers: &[E continue; }; let mut check = Check::new( - CheckKind::RedundantTupleInExceptionHandler(elt.to_string()), + violations::RedundantTupleInExceptionHandler(elt.to_string()), Range::from_located(type_), ); if checker.patch(check.kind.code()) { diff --git a/src/flake8_bugbear/plugins/setattr_with_constant.rs b/src/flake8_bugbear/plugins/setattr_with_constant.rs index e8fd62217c..b6583dfed7 100644 --- a/src/flake8_bugbear/plugins/setattr_with_constant.rs +++ b/src/flake8_bugbear/plugins/setattr_with_constant.rs @@ -8,6 +8,7 @@ use crate::python::keyword::KWLIST; use crate::registry::{Check, CheckKind}; use crate::source_code_generator::SourceCodeGenerator; use crate::source_code_style::SourceCodeStyleDetector; +use crate::violations; fn assignment(obj: &Expr, name: &str, value: &Expr, stylist: &SourceCodeStyleDetector) -> String { let stmt = Stmt::new( @@ -60,7 +61,7 @@ pub fn setattr_with_constant(checker: &mut Checker, expr: &Expr, func: &Expr, ar // (i.e., it's directly within an `StmtKind::Expr`). if let StmtKind::Expr { value: child } = &checker.current_stmt().node { if expr == child.as_ref() { - let mut check = Check::new(CheckKind::SetAttrWithConstant, Range::from_located(expr)); + let mut check = Check::new(violations::SetAttrWithConstant, Range::from_located(expr)); if checker.patch(check.kind.code()) { check.amend(Fix::replacement( assignment(obj, name, value, checker.style), diff --git a/src/flake8_bugbear/plugins/star_arg_unpacking_after_keyword_arg.rs b/src/flake8_bugbear/plugins/star_arg_unpacking_after_keyword_arg.rs index 03765992d9..1c6a4b4d41 100644 --- a/src/flake8_bugbear/plugins/star_arg_unpacking_after_keyword_arg.rs +++ b/src/flake8_bugbear/plugins/star_arg_unpacking_after_keyword_arg.rs @@ -3,6 +3,7 @@ use rustpython_ast::{Expr, ExprKind, Keyword}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// B026 pub fn star_arg_unpacking_after_keyword_arg( @@ -21,7 +22,7 @@ pub fn star_arg_unpacking_after_keyword_arg( continue; } checker.checks.push(Check::new( - CheckKind::StarArgUnpackingAfterKeywordArg, + violations::StarArgUnpackingAfterKeywordArg, Range::from_located(arg), )); } diff --git a/src/flake8_bugbear/plugins/strip_with_multi_characters.rs b/src/flake8_bugbear/plugins/strip_with_multi_characters.rs index 3f67df1c42..8e4ed13961 100644 --- a/src/flake8_bugbear/plugins/strip_with_multi_characters.rs +++ b/src/flake8_bugbear/plugins/strip_with_multi_characters.rs @@ -4,6 +4,7 @@ use rustpython_ast::{Constant, Expr, ExprKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// B005 pub fn strip_with_multi_characters(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) { @@ -26,7 +27,7 @@ pub fn strip_with_multi_characters(checker: &mut Checker, expr: &Expr, func: &Ex if value.len() > 1 && value.chars().unique().count() != value.len() { checker.checks.push(Check::new( - CheckKind::StripWithMultiCharacters, + violations::StripWithMultiCharacters, Range::from_located(expr), )); } diff --git a/src/flake8_bugbear/plugins/unary_prefix_increment.rs b/src/flake8_bugbear/plugins/unary_prefix_increment.rs index ba440513ce..099ebabb65 100644 --- a/src/flake8_bugbear/plugins/unary_prefix_increment.rs +++ b/src/flake8_bugbear/plugins/unary_prefix_increment.rs @@ -3,6 +3,7 @@ use rustpython_ast::{Expr, ExprKind, Unaryop}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// B002 pub fn unary_prefix_increment(checker: &mut Checker, expr: &Expr, op: &Unaryop, operand: &Expr) { @@ -16,7 +17,7 @@ pub fn unary_prefix_increment(checker: &mut Checker, expr: &Expr, op: &Unaryop, return; } checker.checks.push(Check::new( - CheckKind::UnaryPrefixIncrement, + violations::UnaryPrefixIncrement, Range::from_located(expr), )); } diff --git a/src/flake8_bugbear/plugins/unreliable_callable_check.rs b/src/flake8_bugbear/plugins/unreliable_callable_check.rs index 67fc2d959b..9ce65db10f 100644 --- a/src/flake8_bugbear/plugins/unreliable_callable_check.rs +++ b/src/flake8_bugbear/plugins/unreliable_callable_check.rs @@ -3,6 +3,7 @@ use rustpython_ast::{Constant, Expr, ExprKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// B004 pub fn unreliable_callable_check(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) { @@ -26,7 +27,7 @@ pub fn unreliable_callable_check(checker: &mut Checker, expr: &Expr, func: &Expr return; } checker.checks.push(Check::new( - CheckKind::UnreliableCallableCheck, + violations::UnreliableCallableCheck, Range::from_located(expr), )); } diff --git a/src/flake8_bugbear/plugins/unused_loop_control_variable.rs b/src/flake8_bugbear/plugins/unused_loop_control_variable.rs index f86185cc7b..67d845d842 100644 --- a/src/flake8_bugbear/plugins/unused_loop_control_variable.rs +++ b/src/flake8_bugbear/plugins/unused_loop_control_variable.rs @@ -7,6 +7,7 @@ use crate::ast::visitor::Visitor; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// Identify all `ExprKind::Name` nodes in an AST. struct NameFinder<'a> { @@ -62,7 +63,7 @@ pub fn unused_loop_control_variable(checker: &mut Checker, target: &Expr, body: } let mut check = Check::new( - CheckKind::UnusedLoopControlVariable(name.to_string()), + violations::UnusedLoopControlVariable(name.to_string()), Range::from_located(expr), ); if checker.patch(check.kind.code()) { diff --git a/src/flake8_bugbear/plugins/useless_comparison.rs b/src/flake8_bugbear/plugins/useless_comparison.rs index 333ba121b1..3fa676ecdb 100644 --- a/src/flake8_bugbear/plugins/useless_comparison.rs +++ b/src/flake8_bugbear/plugins/useless_comparison.rs @@ -3,11 +3,12 @@ use rustpython_ast::{Expr, ExprKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; pub fn useless_comparison(checker: &mut Checker, expr: &Expr) { if matches!(expr.node, ExprKind::Compare { .. }) { checker.checks.push(Check::new( - CheckKind::UselessComparison, + violations::UselessComparison, Range::from_located(expr), )); } diff --git a/src/flake8_bugbear/plugins/useless_contextlib_suppress.rs b/src/flake8_bugbear/plugins/useless_contextlib_suppress.rs index 67ab2f501a..1d2918a7bc 100644 --- a/src/flake8_bugbear/plugins/useless_contextlib_suppress.rs +++ b/src/flake8_bugbear/plugins/useless_contextlib_suppress.rs @@ -4,6 +4,7 @@ use crate::ast::helpers::{collect_call_paths, match_call_path}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// B005 pub fn useless_contextlib_suppress(checker: &mut Checker, expr: &Expr, args: &[Expr]) { @@ -15,7 +16,7 @@ pub fn useless_contextlib_suppress(checker: &mut Checker, expr: &Expr, args: &[E ) && args.is_empty() { checker.checks.push(Check::new( - CheckKind::UselessContextlibSuppress, + violations::UselessContextlibSuppress, Range::from_located(expr), )); } diff --git a/src/flake8_bugbear/plugins/useless_expression.rs b/src/flake8_bugbear/plugins/useless_expression.rs index 94741e3509..9acf62d1db 100644 --- a/src/flake8_bugbear/plugins/useless_expression.rs +++ b/src/flake8_bugbear/plugins/useless_expression.rs @@ -3,6 +3,7 @@ use rustpython_ast::{Constant, ExprKind, Stmt, StmtKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; // B018 pub fn useless_expression(checker: &mut Checker, body: &[Stmt]) { @@ -11,7 +12,7 @@ pub fn useless_expression(checker: &mut Checker, body: &[Stmt]) { match &value.node { ExprKind::List { .. } | ExprKind::Dict { .. } | ExprKind::Set { .. } => { checker.checks.push(Check::new( - CheckKind::UselessExpression, + violations::UselessExpression, Range::from_located(value), )); } @@ -19,7 +20,7 @@ pub fn useless_expression(checker: &mut Checker, body: &[Stmt]) { Constant::Str { .. } | Constant::Ellipsis => {} _ => { checker.checks.push(Check::new( - CheckKind::UselessExpression, + violations::UselessExpression, Range::from_located(value), )); } diff --git a/src/flake8_bugbear/plugins/zip_without_explicit_strict.rs b/src/flake8_bugbear/plugins/zip_without_explicit_strict.rs index f7942de92c..7170196b1b 100644 --- a/src/flake8_bugbear/plugins/zip_without_explicit_strict.rs +++ b/src/flake8_bugbear/plugins/zip_without_explicit_strict.rs @@ -3,6 +3,7 @@ use rustpython_ast::{Expr, ExprKind, Keyword}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// B905 pub fn zip_without_explicit_strict( @@ -23,7 +24,7 @@ pub fn zip_without_explicit_strict( }) { checker.checks.push(Check::new( - CheckKind::ZipWithoutExplicitStrict, + violations::ZipWithoutExplicitStrict, Range::from_located(expr), )); } diff --git a/src/flake8_builtins/checks.rs b/src/flake8_builtins/checks.rs index a817215096..647ad8dfaa 100644 --- a/src/flake8_builtins/checks.rs +++ b/src/flake8_builtins/checks.rs @@ -4,6 +4,7 @@ use crate::ast::types::Range; use crate::flake8_builtins::types::ShadowingType; use crate::python::builtins::BUILTINS; use crate::registry::{Check, CheckKind}; +use crate::violations; /// Check builtin name shadowing. pub fn builtin_shadowing( @@ -14,9 +15,9 @@ pub fn builtin_shadowing( if BUILTINS.contains(&name) { Some(Check::new( match node_type { - ShadowingType::Variable => CheckKind::BuiltinVariableShadowing(name.to_string()), - ShadowingType::Argument => CheckKind::BuiltinArgumentShadowing(name.to_string()), - ShadowingType::Attribute => CheckKind::BuiltinAttributeShadowing(name.to_string()), + ShadowingType::Variable => violations::BuiltinVariableShadowing(name.to_string()), + ShadowingType::Argument => violations::BuiltinArgumentShadowing(name.to_string()), + ShadowingType::Attribute => violations::BuiltinAttributeShadowing(name.to_string()), }, Range::from_located(located), )) diff --git a/src/flake8_builtins/mod.rs b/src/flake8_builtins/mod.rs index 89f567ca99..0bab186a11 100644 --- a/src/flake8_builtins/mod.rs +++ b/src/flake8_builtins/mod.rs @@ -11,7 +11,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::A001, Path::new("A001.py"); "A001")] #[test_case(CheckCode::A002, Path::new("A002.py"); "A002")] diff --git a/src/flake8_comprehensions/checks.rs b/src/flake8_comprehensions/checks.rs index 1a9c5a408d..01b862f00a 100644 --- a/src/flake8_comprehensions/checks.rs +++ b/src/flake8_comprehensions/checks.rs @@ -8,6 +8,7 @@ use crate::ast::types::Range; use crate::flake8_comprehensions::fixes; use crate::registry::{Check, CheckKind}; use crate::source_code_locator::SourceCodeLocator; +use crate::violations; fn function_name(func: &Expr) -> Option<&str> { if let ExprKind::Name { id, .. } = &func.node { @@ -58,7 +59,7 @@ pub fn unnecessary_generator_list( ) -> Option { let argument = exactly_one_argument_with_matching_function("list", func, args, keywords)?; if let ExprKind::GeneratorExp { .. } = argument { - let mut check = Check::new(CheckKind::UnnecessaryGeneratorList, location); + let mut check = Check::new(violations::UnnecessaryGeneratorList, location); if fix { match fixes::fix_unnecessary_generator_list(locator, expr) { Ok(fix) => { @@ -84,7 +85,7 @@ pub fn unnecessary_generator_set( ) -> Option { let argument = exactly_one_argument_with_matching_function("set", func, args, keywords)?; if let ExprKind::GeneratorExp { .. } = argument { - let mut check = Check::new(CheckKind::UnnecessaryGeneratorSet, location); + let mut check = Check::new(violations::UnnecessaryGeneratorSet, location); if fix { match fixes::fix_unnecessary_generator_set(locator, expr) { Ok(fix) => { @@ -112,7 +113,7 @@ pub fn unnecessary_generator_dict( if let ExprKind::GeneratorExp { elt, .. } = argument { match &elt.node { ExprKind::Tuple { elts, .. } if elts.len() == 2 => { - let mut check = Check::new(CheckKind::UnnecessaryGeneratorDict, location); + let mut check = Check::new(violations::UnnecessaryGeneratorDict, location); if fix { match fixes::fix_unnecessary_generator_dict(locator, expr) { Ok(fix) => { @@ -141,7 +142,7 @@ pub fn unnecessary_list_comprehension_set( ) -> Option { let argument = exactly_one_argument_with_matching_function("set", func, args, keywords)?; if let ExprKind::ListComp { .. } = &argument { - let mut check = Check::new(CheckKind::UnnecessaryListComprehensionSet, location); + let mut check = Check::new(violations::UnnecessaryListComprehensionSet, location); if fix { match fixes::fix_unnecessary_list_comprehension_set(locator, expr) { Ok(fix) => { @@ -175,7 +176,7 @@ pub fn unnecessary_list_comprehension_dict( if elts.len() != 2 { return None; } - let mut check = Check::new(CheckKind::UnnecessaryListComprehensionDict, location); + let mut check = Check::new(violations::UnnecessaryListComprehensionDict, location); if fix { match fixes::fix_unnecessary_list_comprehension_dict(locator, expr) { Ok(fix) => { @@ -203,7 +204,10 @@ pub fn unnecessary_literal_set( ExprKind::Tuple { .. } => "tuple", _ => return None, }; - let mut check = Check::new(CheckKind::UnnecessaryLiteralSet(kind.to_string()), location); + let mut check = Check::new( + violations::UnnecessaryLiteralSet(kind.to_string()), + location, + ); if fix { match fixes::fix_unnecessary_literal_set(locator, expr) { Ok(fix) => { @@ -239,7 +243,7 @@ pub fn unnecessary_literal_dict( return None; } let mut check = Check::new( - CheckKind::UnnecessaryLiteralDict(kind.to_string()), + violations::UnnecessaryLiteralDict(kind.to_string()), location, ); if fix { @@ -277,7 +281,7 @@ pub fn unnecessary_collection_call( _ => return None, }; let mut check = Check::new( - CheckKind::UnnecessaryCollectionCall(id.to_string()), + violations::UnnecessaryCollectionCall(id.to_string()), location, ); if fix { @@ -307,7 +311,7 @@ pub fn unnecessary_literal_within_tuple_call( _ => return None, }; let mut check = Check::new( - CheckKind::UnnecessaryLiteralWithinTupleCall(argument_kind.to_string()), + violations::UnnecessaryLiteralWithinTupleCall(argument_kind.to_string()), location, ); if fix { @@ -337,7 +341,7 @@ pub fn unnecessary_literal_within_list_call( _ => return None, }; let mut check = Check::new( - CheckKind::UnnecessaryLiteralWithinListCall(argument_kind.to_string()), + violations::UnnecessaryLiteralWithinListCall(argument_kind.to_string()), location, ); if fix { @@ -364,7 +368,7 @@ pub fn unnecessary_list_call( if !matches!(argument, ExprKind::ListComp { .. }) { return None; } - let mut check = Check::new(CheckKind::UnnecessaryListCall, location); + let mut check = Check::new(violations::UnnecessaryListCall, location); if fix { match fixes::fix_unnecessary_list_call(locator, expr) { Ok(fix) => { @@ -397,7 +401,7 @@ pub fn unnecessary_call_around_sorted( } let mut check = Check::new( - CheckKind::UnnecessaryCallAroundSorted(outer.to_string()), + violations::UnnecessaryCallAroundSorted(outer.to_string()), location, ); if fix { @@ -419,7 +423,7 @@ pub fn unnecessary_double_cast_or_process( ) -> Option { fn new_check(inner: &str, outer: &str, location: Range) -> Check { Check::new( - CheckKind::UnnecessaryDoubleCastOrProcess(inner.to_string(), outer.to_string()), + violations::UnnecessaryDoubleCastOrProcess(inner.to_string(), outer.to_string()), location, ) } @@ -490,7 +494,7 @@ pub fn unnecessary_subscript_reversal( return None; }; Some(Check::new( - CheckKind::UnnecessarySubscriptReversal(id.to_string()), + violations::UnnecessarySubscriptReversal(id.to_string()), location, )) } @@ -522,7 +526,7 @@ pub fn unnecessary_comprehension( _ => return None, }; let mut check = Check::new( - CheckKind::UnnecessaryComprehension(expr_kind.to_string()), + violations::UnnecessaryComprehension(expr_kind.to_string()), location, ); if fix { @@ -539,7 +543,7 @@ pub fn unnecessary_comprehension( /// C417 pub fn unnecessary_map(func: &Expr, args: &[Expr], location: Range) -> Option { fn new_check(kind: &str, location: Range) -> Check { - Check::new(CheckKind::UnnecessaryMap(kind.to_string()), location) + Check::new(violations::UnnecessaryMap(kind.to_string()), location) } let id = function_name(func)?; match id { diff --git a/src/flake8_comprehensions/mod.rs b/src/flake8_comprehensions/mod.rs index 476c7a8d8a..9efa9a25df 100644 --- a/src/flake8_comprehensions/mod.rs +++ b/src/flake8_comprehensions/mod.rs @@ -11,7 +11,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::C400, Path::new("C400.py"); "C400")] #[test_case(CheckCode::C401, Path::new("C401.py"); "C401")] diff --git a/src/flake8_datetimez/mod.rs b/src/flake8_datetimez/mod.rs index 5818473ffe..6f93ff116f 100644 --- a/src/flake8_datetimez/mod.rs +++ b/src/flake8_datetimez/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::DTZ001, Path::new("DTZ001.py"); "DTZ001")] #[test_case(CheckCode::DTZ002, Path::new("DTZ002.py"); "DTZ002")] diff --git a/src/flake8_datetimez/plugins.rs b/src/flake8_datetimez/plugins.rs index 4e35c242cd..400fdd8b43 100644 --- a/src/flake8_datetimez/plugins.rs +++ b/src/flake8_datetimez/plugins.rs @@ -6,6 +6,7 @@ use crate::ast::helpers::{ use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; pub fn call_datetime_without_tzinfo( checker: &mut Checker, @@ -23,7 +24,7 @@ pub fn call_datetime_without_tzinfo( if args.len() < 8 && !has_non_none_keyword(keywords, "tzinfo") { checker .checks - .push(Check::new(CheckKind::CallDatetimeWithoutTzinfo, location)); + .push(Check::new(violations::CallDatetimeWithoutTzinfo, location)); return; } @@ -31,7 +32,7 @@ pub fn call_datetime_without_tzinfo( if args.len() >= 8 && is_const_none(&args[7]) { checker .checks - .push(Check::new(CheckKind::CallDatetimeWithoutTzinfo, location)); + .push(Check::new(violations::CallDatetimeWithoutTzinfo, location)); } } @@ -46,7 +47,7 @@ pub fn call_datetime_today(checker: &mut Checker, func: &Expr, location: Range) ) { checker .checks - .push(Check::new(CheckKind::CallDatetimeToday, location)); + .push(Check::new(violations::CallDatetimeToday, location)); } } @@ -61,7 +62,7 @@ pub fn call_datetime_utcnow(checker: &mut Checker, func: &Expr, location: Range) ) { checker .checks - .push(Check::new(CheckKind::CallDatetimeUtcnow, location)); + .push(Check::new(violations::CallDatetimeUtcnow, location)); } } @@ -75,7 +76,7 @@ pub fn call_datetime_utcfromtimestamp(checker: &mut Checker, func: &Expr, locati &checker.from_imports, ) { checker.checks.push(Check::new( - CheckKind::CallDatetimeUtcfromtimestamp, + violations::CallDatetimeUtcfromtimestamp, location, )); } @@ -102,7 +103,7 @@ pub fn call_datetime_now_without_tzinfo( // no args / no args unqualified if args.is_empty() && keywords.is_empty() { checker.checks.push(Check::new( - CheckKind::CallDatetimeNowWithoutTzinfo, + violations::CallDatetimeNowWithoutTzinfo, location, )); return; @@ -111,7 +112,7 @@ pub fn call_datetime_now_without_tzinfo( // none args if !args.is_empty() && is_const_none(&args[0]) { checker.checks.push(Check::new( - CheckKind::CallDatetimeNowWithoutTzinfo, + violations::CallDatetimeNowWithoutTzinfo, location, )); return; @@ -120,7 +121,7 @@ pub fn call_datetime_now_without_tzinfo( // wrong keywords / none keyword if !keywords.is_empty() && !has_non_none_keyword(keywords, "tz") { checker.checks.push(Check::new( - CheckKind::CallDatetimeNowWithoutTzinfo, + violations::CallDatetimeNowWithoutTzinfo, location, )); } @@ -148,7 +149,7 @@ pub fn call_datetime_fromtimestamp( if args.len() < 2 && keywords.is_empty() { checker .checks - .push(Check::new(CheckKind::CallDatetimeFromtimestamp, location)); + .push(Check::new(violations::CallDatetimeFromtimestamp, location)); return; } @@ -156,7 +157,7 @@ pub fn call_datetime_fromtimestamp( if args.len() > 1 && is_const_none(&args[1]) { checker .checks - .push(Check::new(CheckKind::CallDatetimeFromtimestamp, location)); + .push(Check::new(violations::CallDatetimeFromtimestamp, location)); return; } @@ -164,7 +165,7 @@ pub fn call_datetime_fromtimestamp( if !keywords.is_empty() && !has_non_none_keyword(keywords, "tz") { checker .checks - .push(Check::new(CheckKind::CallDatetimeFromtimestamp, location)); + .push(Check::new(violations::CallDatetimeFromtimestamp, location)); } } @@ -198,7 +199,7 @@ pub fn call_datetime_strptime_without_zone( let (Some(grandparent), Some(parent)) = (checker.current_expr_grandparent(), checker.current_expr_parent()) else { checker.checks.push(Check::new( - CheckKind::CallDatetimeStrptimeWithoutZone, + violations::CallDatetimeStrptimeWithoutZone, location, )); return; @@ -221,7 +222,7 @@ pub fn call_datetime_strptime_without_zone( } checker.checks.push(Check::new( - CheckKind::CallDatetimeStrptimeWithoutZone, + violations::CallDatetimeStrptimeWithoutZone, location, )); } @@ -232,7 +233,7 @@ pub fn call_date_today(checker: &mut Checker, func: &Expr, location: Range) { if match_call_path(&call_path, "datetime.date", "today", &checker.from_imports) { checker .checks - .push(Check::new(CheckKind::CallDateToday, location)); + .push(Check::new(violations::CallDateToday, location)); } } @@ -247,6 +248,6 @@ pub fn call_date_fromtimestamp(checker: &mut Checker, func: &Expr, location: Ran ) { checker .checks - .push(Check::new(CheckKind::CallDateFromtimestamp, location)); + .push(Check::new(violations::CallDateFromtimestamp, location)); } } diff --git a/src/flake8_debugger/checks.rs b/src/flake8_debugger/checks.rs index f1225294b6..ac5a3908fb 100644 --- a/src/flake8_debugger/checks.rs +++ b/src/flake8_debugger/checks.rs @@ -5,6 +5,7 @@ use crate::ast::helpers::{collect_call_paths, dealias_call_path, match_call_path use crate::ast::types::Range; use crate::flake8_debugger::types::DebuggerUsingType; use crate::registry::{Check, CheckKind}; +use crate::violations; const DEBUGGERS: &[(&str, &str)] = &[ ("pdb", "set_trace"), @@ -31,7 +32,7 @@ pub fn debugger_call( .any(|(module, member)| match_call_path(&call_path, module, member, from_imports)) { Some(Check::new( - CheckKind::Debugger(DebuggerUsingType::Call(call_path.join("."))), + violations::Debugger(DebuggerUsingType::Call(call_path.join("."))), Range::from_located(expr), )) } else { @@ -53,7 +54,7 @@ pub fn debugger_import(stmt: &Stmt, module: Option<&str>, name: &str) -> Option< .find(|(module_name, member)| module_name == &module && member == &name) { return Some(Check::new( - CheckKind::Debugger(DebuggerUsingType::Import(format!("{module_name}.{member}"))), + violations::Debugger(DebuggerUsingType::Import(format!("{module_name}.{member}"))), Range::from_located(stmt), )); } @@ -62,7 +63,7 @@ pub fn debugger_import(stmt: &Stmt, module: Option<&str>, name: &str) -> Option< .any(|(module_name, ..)| module_name == &name) { return Some(Check::new( - CheckKind::Debugger(DebuggerUsingType::Import(name.to_string())), + violations::Debugger(DebuggerUsingType::Import(name.to_string())), Range::from_located(stmt), )); } diff --git a/src/flake8_debugger/mod.rs b/src/flake8_debugger/mod.rs index 05c8d29729..1077be6ea7 100644 --- a/src/flake8_debugger/mod.rs +++ b/src/flake8_debugger/mod.rs @@ -11,7 +11,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::T100, Path::new("T100.py"); "T100")] fn checks(check_code: CheckCode, path: &Path) -> Result<()> { diff --git a/src/flake8_errmsg/mod.rs b/src/flake8_errmsg/mod.rs index f47de47101..ced18169fa 100644 --- a/src/flake8_errmsg/mod.rs +++ b/src/flake8_errmsg/mod.rs @@ -9,7 +9,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::{flake8_errmsg, settings}; + use crate::{flake8_errmsg, settings, violations}; #[test] fn defaults() -> Result<()> { diff --git a/src/flake8_errmsg/plugins.rs b/src/flake8_errmsg/plugins.rs index 35d1f5a942..3e6c7b58d8 100644 --- a/src/flake8_errmsg/plugins.rs +++ b/src/flake8_errmsg/plugins.rs @@ -3,6 +3,7 @@ use rustpython_ast::{Constant, Expr, ExprKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; +use crate::violations; /// EM101, EM102, EM103 pub fn string_in_exception(checker: &mut Checker, exc: &Expr) { @@ -17,7 +18,7 @@ pub fn string_in_exception(checker: &mut Checker, exc: &Expr) { if checker.settings.enabled.contains(&CheckCode::EM101) { if string.len() > checker.settings.flake8_errmsg.max_string_length { checker.checks.push(Check::new( - CheckKind::RawStringInException, + violations::RawStringInException, Range::from_located(first), )); } @@ -27,7 +28,7 @@ pub fn string_in_exception(checker: &mut Checker, exc: &Expr) { ExprKind::JoinedStr { .. } => { if checker.settings.enabled.contains(&CheckCode::EM102) { checker.checks.push(Check::new( - CheckKind::FStringInException, + violations::FStringInException, Range::from_located(first), )); } @@ -38,7 +39,7 @@ pub fn string_in_exception(checker: &mut Checker, exc: &Expr) { if let ExprKind::Attribute { value, attr, .. } = &func.node { if attr == "format" && matches!(value.node, ExprKind::Constant { .. }) { checker.checks.push(Check::new( - CheckKind::DotFormatInException, + violations::DotFormatInException, Range::from_located(first), )); } diff --git a/src/flake8_implicit_str_concat/checks.rs b/src/flake8_implicit_str_concat/checks.rs index cc12907160..d2f0727b5a 100644 --- a/src/flake8_implicit_str_concat/checks.rs +++ b/src/flake8_implicit_str_concat/checks.rs @@ -5,6 +5,7 @@ use rustpython_parser::lexer::{LexResult, Tok}; use crate::ast::types::Range; use crate::registry::{Check, CheckKind}; use crate::source_code_locator::SourceCodeLocator; +use crate::violations; /// ISC001, ISC002 pub fn implicit(tokens: &[LexResult], locator: &SourceCodeLocator) -> Vec { @@ -15,7 +16,7 @@ pub fn implicit(tokens: &[LexResult], locator: &SourceCodeLocator) -> Vec if matches!(a_tok, Tok::String { .. }) && matches!(b_tok, Tok::String { .. }) { if a_end.row() == b_start.row() { checks.push(Check::new( - CheckKind::SingleLineImplicitStringConcatenation, + violations::SingleLineImplicitStringConcatenation, Range { location: *a_start, end_location: *b_end, @@ -30,7 +31,7 @@ pub fn implicit(tokens: &[LexResult], locator: &SourceCodeLocator) -> Vec }); if contents.trim_end().ends_with('\\') { checks.push(Check::new( - CheckKind::MultiLineImplicitStringConcatenation, + violations::MultiLineImplicitStringConcatenation, Range { location: *a_start, end_location: *b_end, @@ -63,7 +64,7 @@ pub fn explicit(expr: &Expr) -> Option { } ) { return Some(Check::new( - CheckKind::ExplicitStringConcatenation, + violations::ExplicitStringConcatenation, Range::from_located(expr), )); } diff --git a/src/flake8_implicit_str_concat/mod.rs b/src/flake8_implicit_str_concat/mod.rs index 5c0af90c92..0cec6df033 100644 --- a/src/flake8_implicit_str_concat/mod.rs +++ b/src/flake8_implicit_str_concat/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::ISC001, Path::new("ISC.py"); "ISC001")] #[test_case(CheckCode::ISC002, Path::new("ISC.py"); "ISC002")] diff --git a/src/flake8_import_conventions/checks.rs b/src/flake8_import_conventions/checks.rs index 5baae84634..9617ac02cb 100644 --- a/src/flake8_import_conventions/checks.rs +++ b/src/flake8_import_conventions/checks.rs @@ -3,6 +3,7 @@ use rustpython_ast::Stmt; use crate::ast::types::Range; use crate::registry::{Check, CheckKind}; +use crate::violations; /// ICN001 pub fn check_conventional_import( @@ -24,7 +25,7 @@ pub fn check_conventional_import( } if !is_valid_import { return Some(Check::new( - CheckKind::ImportAliasIsNotConventional( + violations::ImportAliasIsNotConventional( name.to_string(), expected_alias.to_string(), ), diff --git a/src/flake8_import_conventions/mod.rs b/src/flake8_import_conventions/mod.rs index b51aec7794..37839319eb 100644 --- a/src/flake8_import_conventions/mod.rs +++ b/src/flake8_import_conventions/mod.rs @@ -11,7 +11,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::{flake8_import_conventions, Settings}; + use crate::{flake8_import_conventions, violations, Settings}; #[test] fn defaults() -> Result<()> { diff --git a/src/flake8_pie/mod.rs b/src/flake8_pie/mod.rs index d917732a6e..d66d4241fe 100644 --- a/src/flake8_pie/mod.rs +++ b/src/flake8_pie/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::PIE790, Path::new("PIE790.py"); "PIE790")] #[test_case(CheckCode::PIE794, Path::new("PIE794.py"); "PIE794")] diff --git a/src/flake8_pie/plugins.rs b/src/flake8_pie/plugins.rs index d5cdc6ac1a..6562d8d0fc 100644 --- a/src/flake8_pie/plugins.rs +++ b/src/flake8_pie/plugins.rs @@ -7,6 +7,7 @@ use crate::autofix::helpers::delete_stmt; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; +use crate::violations; /// PIE790 pub fn no_unnecessary_pass(checker: &mut Checker, body: &[Stmt]) { @@ -26,8 +27,10 @@ pub fn no_unnecessary_pass(checker: &mut Checker, body: &[Stmt]) { } ) { if matches!(pass_stmt.node, StmtKind::Pass) { - let mut check = - Check::new(CheckKind::NoUnnecessaryPass, Range::from_located(pass_stmt)); + let mut check = Check::new( + violations::NoUnnecessaryPass, + Range::from_located(pass_stmt), + ); if checker.patch(&CheckCode::PIE790) { match delete_stmt(pass_stmt, None, &[], checker.locator) { Ok(fix) => { @@ -76,7 +79,7 @@ pub fn dupe_class_field_definitions(checker: &mut Checker, bases: &[Expr], body: if seen_targets.contains(target) { let mut check = Check::new( - CheckKind::DupeClassFieldDefinitions(target.to_string()), + violations::DupeClassFieldDefinitions(target.to_string()), Range::from_located(stmt), ); if checker.patch(&CheckCode::PIE794) { @@ -97,7 +100,8 @@ pub fn prefer_list_builtin(checker: &mut Checker, expr: &Expr) { if args.args.is_empty() { if let ExprKind::List { elts, .. } = &body.node { if elts.is_empty() { - let mut check = Check::new(CheckKind::PreferListBuiltin, Range::from_located(expr)); + let mut check = + Check::new(violations::PreferListBuiltin, Range::from_located(expr)); if checker.patch(&CheckCode::PIE807) { check.amend(Fix::replacement( "list".to_string(), diff --git a/src/flake8_print/mod.rs b/src/flake8_print/mod.rs index 228d414cd7..bca4b4da08 100644 --- a/src/flake8_print/mod.rs +++ b/src/flake8_print/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::T201, Path::new("T201.py"); "T201")] #[test_case(CheckCode::T203, Path::new("T203.py"); "T203")] diff --git a/src/flake8_print/plugins/print_call.rs b/src/flake8_print/plugins/print_call.rs index 9621f5860e..206255445a 100644 --- a/src/flake8_print/plugins/print_call.rs +++ b/src/flake8_print/plugins/print_call.rs @@ -6,6 +6,7 @@ use crate::ast::types::Range; use crate::autofix::helpers; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// T201, T203 pub fn print_call(checker: &mut Checker, func: &Expr, keywords: &[Keyword]) { @@ -27,9 +28,9 @@ pub fn print_call(checker: &mut Checker, func: &Expr, keywords: &[Keyword]) { } } } - Check::new(CheckKind::PrintFound, Range::from_located(func)) + Check::new(violations::PrintFound, Range::from_located(func)) } else if match_call_path(&call_path, "pprint", "pprint", &checker.from_imports) { - Check::new(CheckKind::PPrintFound, Range::from_located(func)) + Check::new(violations::PPrintFound, Range::from_located(func)) } else { return; } diff --git a/src/flake8_pytest_style/mod.rs b/src/flake8_pytest_style/mod.rs index a56922899e..bab8fd877d 100644 --- a/src/flake8_pytest_style/mod.rs +++ b/src/flake8_pytest_style/mod.rs @@ -13,7 +13,7 @@ mod tests { use crate::flake8_pytest_style::types; use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::PT001, Path::new("PT001.py"), Settings::default(), "PT001_default"; "PT001_0")] #[test_case( diff --git a/src/flake8_pytest_style/plugins/assertion.rs b/src/flake8_pytest_style/plugins/assertion.rs index 65ea8a3199..28dcec732a 100644 --- a/src/flake8_pytest_style/plugins/assertion.rs +++ b/src/flake8_pytest_style/plugins/assertion.rs @@ -11,6 +11,7 @@ use crate::ast::visitor::Visitor; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// Visitor that tracks assert statements and checks if they reference /// the exception name. @@ -51,7 +52,7 @@ where if let Some(current_assert) = self.current_assert { if id.as_str() == self.exception_name { self.errors.push(Check::new( - CheckKind::AssertInExcept(id.to_string()), + violations::AssertInExcept(id.to_string()), Range::from_located(current_assert), )); } @@ -99,7 +100,7 @@ pub fn unittest_assertion( ExprKind::Attribute { attr, .. } => { if let Ok(unittest_assert) = UnittestAssert::try_from(attr.as_str()) { let mut check = Check::new( - CheckKind::UnittestAssertion(unittest_assert.to_string()), + violations::UnittestAssertion(unittest_assert.to_string()), Range::from_located(func), ); if checker.patch(check.kind.code()) { @@ -124,7 +125,7 @@ pub fn unittest_assertion( pub fn assert_falsy(assert_stmt: &Stmt, test_expr: &Expr) -> Option { if is_falsy_constant(test_expr) { Some(Check::new( - CheckKind::AssertAlwaysFalse, + violations::AssertAlwaysFalse, Range::from_located(assert_stmt), )) } else { @@ -152,7 +153,7 @@ pub fn assert_in_exception_handler(handlers: &[Excepthandler]) -> Vec { pub fn composite_condition(assert_stmt: &Stmt, test_expr: &Expr) -> Option { if is_composite_condition(test_expr) { Some(Check::new( - CheckKind::CompositeAssertion, + violations::CompositeAssertion, Range::from_located(assert_stmt), )) } else { diff --git a/src/flake8_pytest_style/plugins/fail.rs b/src/flake8_pytest_style/plugins/fail.rs index 6af19fdfb6..8234ecc404 100644 --- a/src/flake8_pytest_style/plugins/fail.rs +++ b/src/flake8_pytest_style/plugins/fail.rs @@ -5,6 +5,7 @@ use crate::ast::helpers::SimpleCallArgs; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; pub fn fail_call(checker: &mut Checker, call: &Expr, args: &[Expr], keywords: &[Keyword]) { if is_pytest_fail(call, checker) { @@ -14,13 +15,13 @@ pub fn fail_call(checker: &mut Checker, call: &Expr, args: &[Expr], keywords: &[ if let Some(msg) = msg { if is_empty_or_null_string(msg) { checker.checks.push(Check::new( - CheckKind::FailWithoutMessage, + violations::FailWithoutMessage, Range::from_located(call), )); } } else { checker.checks.push(Check::new( - CheckKind::FailWithoutMessage, + violations::FailWithoutMessage, Range::from_located(call), )); } diff --git a/src/flake8_pytest_style/plugins/fixture.rs b/src/flake8_pytest_style/plugins/fixture.rs index 6b893ce910..bbf90c0cef 100644 --- a/src/flake8_pytest_style/plugins/fixture.rs +++ b/src/flake8_pytest_style/plugins/fixture.rs @@ -11,6 +11,7 @@ use crate::ast::visitor::Visitor; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; +use crate::violations; #[derive(Default)] /// Visitor that skips functions @@ -79,7 +80,7 @@ fn pytest_fixture_parentheses( actual: &str, ) { let mut check = Check::new( - CheckKind::IncorrectFixtureParenthesesStyle(preferred.to_string(), actual.to_string()), + violations::IncorrectFixtureParenthesesStyle(preferred.to_string(), actual.to_string()), Range::from_located(decorator), ); if checker.patch(check.kind.code()) { @@ -112,7 +113,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E if checker.settings.enabled.contains(&CheckCode::PT002) && !args.is_empty() { checker.checks.push(Check::new( - CheckKind::FixturePositionalArgs(func_name.to_string()), + violations::FixturePositionalArgs(func_name.to_string()), Range::from_located(decorator), )); } @@ -125,7 +126,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E if let Some(scope_keyword) = scope_keyword { if keyword_is_literal(scope_keyword, "function") { checker.checks.push(Check::new( - CheckKind::ExtraneousScopeFunction, + violations::ExtraneousScopeFunction, Range::from_located(scope_keyword), )); } @@ -156,7 +157,7 @@ fn check_fixture_returns(checker: &mut Checker, func: &Stmt, func_name: &str, bo && func_name.starts_with('_') { checker.checks.push(Check::new( - CheckKind::IncorrectFixtureNameUnderscore(func_name.to_string()), + violations::IncorrectFixtureNameUnderscore(func_name.to_string()), Range::from_located(func), )); } else if checker.settings.enabled.contains(&CheckCode::PT004) @@ -165,7 +166,7 @@ fn check_fixture_returns(checker: &mut Checker, func: &Stmt, func_name: &str, bo && !func_name.starts_with('_') { checker.checks.push(Check::new( - CheckKind::MissingFixtureNameUnderscore(func_name.to_string()), + violations::MissingFixtureNameUnderscore(func_name.to_string()), Range::from_located(func), )); } @@ -176,7 +177,7 @@ fn check_fixture_returns(checker: &mut Checker, func: &Stmt, func_name: &str, bo if let ExprKind::Yield { .. } = value.node { if visitor.yield_statements.len() == 1 { let mut check = Check::new( - CheckKind::UselessYieldFixture(func_name.to_string()), + violations::UselessYieldFixture(func_name.to_string()), Range::from_located(stmt), ); if checker.patch(check.kind.code()) { @@ -203,7 +204,7 @@ fn check_test_function_args(checker: &mut Checker, args: &Arguments) { let name = arg.node.arg.to_string(); if name.starts_with('_') { checker.checks.push(Check::new( - CheckKind::FixtureParamWithoutValue(name), + violations::FixtureParamWithoutValue(name), Range::from_located(arg), )); } @@ -214,7 +215,7 @@ fn check_test_function_args(checker: &mut Checker, args: &Arguments) { fn check_fixture_decorator_name(checker: &mut Checker, decorator: &Expr) { if is_pytest_yield_fixture(decorator, checker) { checker.checks.push(Check::new( - CheckKind::DeprecatedYieldFixture, + violations::DeprecatedYieldFixture, Range::from_located(decorator), )); } @@ -234,7 +235,7 @@ fn check_fixture_addfinalizer(checker: &mut Checker, args: &Arguments, body: &[S if let Some(addfinalizer) = visitor.addfinalizer_call { checker.checks.push(Check::new( - CheckKind::FixtureFinalizerCallback, + violations::FixtureFinalizerCallback, Range::from_located(addfinalizer), )); } @@ -248,7 +249,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Expr]) { if checker.settings.enabled.contains(&CheckCode::PT024) { if name == "asyncio" { checker.checks.push(Check::new( - CheckKind::UnnecessaryAsyncioMarkOnFixture, + violations::UnnecessaryAsyncioMarkOnFixture, Range::from_located(mark), )); } @@ -257,7 +258,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Expr]) { if checker.settings.enabled.contains(&CheckCode::PT025) { if name == "usefixtures" { checker.checks.push(Check::new( - CheckKind::ErroneousUseFixturesOnFixture, + violations::ErroneousUseFixturesOnFixture, Range::from_located(mark), )); } diff --git a/src/flake8_pytest_style/plugins/imports.rs b/src/flake8_pytest_style/plugins/imports.rs index 8765181819..5ddd982d3f 100644 --- a/src/flake8_pytest_style/plugins/imports.rs +++ b/src/flake8_pytest_style/plugins/imports.rs @@ -2,6 +2,7 @@ use rustpython_ast::Stmt; use crate::ast::types::Range; use crate::registry::{Check, CheckKind}; +use crate::violations; fn is_pytest_or_subpackage(imported_name: &str) -> bool { imported_name == "pytest" || imported_name.starts_with("pytest.") @@ -13,7 +14,7 @@ pub fn import(import_from: &Stmt, name: &str, asname: Option<&str>) -> Option(checker: &Checker, decorators: &'a [Expr]) -> Option<&'a Expr> { decorators @@ -80,7 +81,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) { match names_type { types::ParametrizeNameType::Tuple => { let mut check = Check::new( - CheckKind::ParametrizeNamesWrongType(names_type), + violations::ParametrizeNamesWrongType(names_type), Range::from_located(expr), ); if checker.patch(check.kind.code()) { @@ -110,7 +111,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) { } types::ParametrizeNameType::List => { let mut check = Check::new( - CheckKind::ParametrizeNamesWrongType(names_type), + violations::ParametrizeNamesWrongType(names_type), Range::from_located(expr), ); if checker.patch(check.kind.code()) { @@ -152,7 +153,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) { types::ParametrizeNameType::Tuple => {} types::ParametrizeNameType::List => { let mut check = Check::new( - CheckKind::ParametrizeNamesWrongType(names_type), + violations::ParametrizeNamesWrongType(names_type), Range::from_located(expr), ); if checker.patch(check.kind.code()) { @@ -174,7 +175,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) { } types::ParametrizeNameType::CSV => { let mut check = Check::new( - CheckKind::ParametrizeNamesWrongType(names_type), + violations::ParametrizeNamesWrongType(names_type), Range::from_located(expr), ); if checker.patch(check.kind.code()) { @@ -201,7 +202,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) { types::ParametrizeNameType::List => {} types::ParametrizeNameType::Tuple => { let mut check = Check::new( - CheckKind::ParametrizeNamesWrongType(names_type), + violations::ParametrizeNamesWrongType(names_type), Range::from_located(expr), ); if checker.patch(check.kind.code()) { @@ -223,7 +224,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) { } types::ParametrizeNameType::CSV => { let mut check = Check::new( - CheckKind::ParametrizeNamesWrongType(names_type), + violations::ParametrizeNamesWrongType(names_type), Range::from_located(expr), ); if checker.patch(check.kind.code()) { @@ -257,7 +258,7 @@ fn check_values(checker: &mut Checker, expr: &Expr) { ExprKind::List { elts, .. } => { if values_type != types::ParametrizeValuesType::List { checker.checks.push(Check::new( - CheckKind::ParametrizeValuesWrongType(values_type, values_row_type), + violations::ParametrizeValuesWrongType(values_type, values_row_type), Range::from_located(expr), )); } @@ -266,7 +267,7 @@ fn check_values(checker: &mut Checker, expr: &Expr) { ExprKind::Tuple { elts, .. } => { if values_type != types::ParametrizeValuesType::Tuple { checker.checks.push(Check::new( - CheckKind::ParametrizeValuesWrongType(values_type, values_row_type), + violations::ParametrizeValuesWrongType(values_type, values_row_type), Range::from_located(expr), )); } @@ -278,7 +279,7 @@ fn check_values(checker: &mut Checker, expr: &Expr) { fn handle_single_name(checker: &mut Checker, expr: &Expr, value: &Expr) { let mut check = Check::new( - CheckKind::ParametrizeNamesWrongType(types::ParametrizeNameType::CSV), + violations::ParametrizeNamesWrongType(types::ParametrizeNameType::CSV), Range::from_located(expr), ); @@ -305,7 +306,7 @@ fn handle_value_rows( ExprKind::Tuple { .. } => { if values_row_type != types::ParametrizeValuesRowType::Tuple { checker.checks.push(Check::new( - CheckKind::ParametrizeValuesWrongType(values_type, values_row_type), + violations::ParametrizeValuesWrongType(values_type, values_row_type), Range::from_located(elt), )); } @@ -313,7 +314,7 @@ fn handle_value_rows( ExprKind::List { .. } => { if values_row_type != types::ParametrizeValuesRowType::List { checker.checks.push(Check::new( - CheckKind::ParametrizeValuesWrongType(values_type, values_row_type), + violations::ParametrizeValuesWrongType(values_type, values_row_type), Range::from_located(elt), )); } diff --git a/src/flake8_pytest_style/plugins/patch.rs b/src/flake8_pytest_style/plugins/patch.rs index 98c6a48f8d..a30af0477d 100644 --- a/src/flake8_pytest_style/plugins/patch.rs +++ b/src/flake8_pytest_style/plugins/patch.rs @@ -6,6 +6,7 @@ use crate::ast::types::Range; use crate::ast::visitor; use crate::ast::visitor::Visitor; use crate::registry::{Check, CheckKind}; +use crate::violations; const PATCH_NAMES: &[&str] = &[ "mocker.patch", @@ -72,7 +73,7 @@ fn check_patch_call( if !visitor.uses_args { return Some(Check::new( - CheckKind::PatchWithLambda, + violations::PatchWithLambda, Range::from_located(call), )); } diff --git a/src/flake8_pytest_style/plugins/raises.rs b/src/flake8_pytest_style/plugins/raises.rs index bb3d2b23e1..f3d452cbb6 100644 --- a/src/flake8_pytest_style/plugins/raises.rs +++ b/src/flake8_pytest_style/plugins/raises.rs @@ -9,6 +9,7 @@ use crate::ast::helpers::{ use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; +use crate::violations; fn is_pytest_raises( func: &Expr, @@ -33,7 +34,7 @@ pub fn raises_call(checker: &mut Checker, func: &Expr, args: &[Expr], keywords: if checker.settings.enabled.contains(&CheckCode::PT010) { if args.is_empty() && keywords.is_empty() { checker.checks.push(Check::new( - CheckKind::RaisesWithoutException, + violations::RaisesWithoutException, Range::from_located(func), )); } @@ -91,7 +92,7 @@ pub fn complex_raises(checker: &mut Checker, stmt: &Stmt, items: &[Withitem], bo if is_too_complex { checker.checks.push(Check::new( - CheckKind::RaisesWithMultipleStatements, + violations::RaisesWithMultipleStatements, Range::from_located(stmt), )); } @@ -118,7 +119,7 @@ fn exception_needs_match(checker: &mut Checker, exception: &Expr) { if is_broad_exception { checker.checks.push(Check::new( - CheckKind::RaisesTooBroad(call_path.join(".")), + violations::RaisesTooBroad(call_path.join(".")), Range::from_located(exception), )); } diff --git a/src/flake8_quotes/checks.rs b/src/flake8_quotes/checks.rs index 6f9a9e1555..9c54aea444 100644 --- a/src/flake8_quotes/checks.rs +++ b/src/flake8_quotes/checks.rs @@ -4,6 +4,7 @@ use crate::ast::types::Range; use crate::flake8_quotes::settings::{Quote, Settings}; use crate::registry::{Check, CheckKind}; use crate::source_code_locator::SourceCodeLocator; +use crate::violations; fn good_single(quote: &Quote) -> char { match quote { @@ -72,7 +73,7 @@ pub fn quotes( } Some(Check::new( - CheckKind::BadQuotesDocstring(settings.docstring_quotes.clone()), + violations::BadQuotesDocstring(settings.docstring_quotes.clone()), Range::new(start, end), )) } else if is_multiline { @@ -87,7 +88,7 @@ pub fn quotes( } Some(Check::new( - CheckKind::BadQuotesMultilineString(settings.multiline_quotes.clone()), + violations::BadQuotesMultilineString(settings.multiline_quotes.clone()), Range::new(start, end), )) } else { @@ -102,7 +103,7 @@ pub fn quotes( && !string_contents.contains(bad_single(&settings.inline_quotes)) { return Some(Check::new( - CheckKind::AvoidQuoteEscape, + violations::AvoidQuoteEscape, Range::new(start, end), )); } @@ -112,7 +113,7 @@ pub fn quotes( // If we're not using the preferred type, only allow use to avoid escapes. if !string_contents.contains(good_single(&settings.inline_quotes)) { return Some(Check::new( - CheckKind::BadQuotesInlineString(settings.inline_quotes.clone()), + violations::BadQuotesInlineString(settings.inline_quotes.clone()), Range::new(start, end), )); } diff --git a/src/flake8_quotes/mod.rs b/src/flake8_quotes/mod.rs index 7eba2bcae9..f12cb63ffe 100644 --- a/src/flake8_quotes/mod.rs +++ b/src/flake8_quotes/mod.rs @@ -11,7 +11,7 @@ mod tests { use crate::flake8_quotes::settings::Quote; use crate::linter::test_path; use crate::registry::CheckCode; - use crate::{flake8_quotes, Settings}; + use crate::{flake8_quotes, violations, Settings}; #[test_case(Path::new("doubles.py"))] #[test_case(Path::new("doubles_escaped.py"))] diff --git a/src/flake8_return/mod.rs b/src/flake8_return/mod.rs index bbc91b72af..4bd9750a2d 100644 --- a/src/flake8_return/mod.rs +++ b/src/flake8_return/mod.rs @@ -11,7 +11,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::Settings; + use crate::{violations, Settings}; #[test_case(CheckCode::RET501, Path::new("RET501.py"); "RET501")] #[test_case(CheckCode::RET502, Path::new("RET502.py"); "RET502")] diff --git a/src/flake8_return/plugins.rs b/src/flake8_return/plugins.rs index 25fcc06937..a237c25150 100644 --- a/src/flake8_return/plugins.rs +++ b/src/flake8_return/plugins.rs @@ -9,7 +9,7 @@ use crate::checkers::ast::Checker; use crate::flake8_return::helpers::result_exists; use crate::flake8_return::visitor::{ReturnVisitor, Stack}; use crate::registry::{Branch, CheckCode, CheckKind}; -use crate::Check; +use crate::{violations, Check}; /// RET501 fn unnecessary_return_none(checker: &mut Checker, stack: &Stack) { @@ -26,7 +26,7 @@ fn unnecessary_return_none(checker: &mut Checker, stack: &Stack) { ) { continue; } - let mut check = Check::new(CheckKind::UnnecessaryReturnNone, Range::from_located(stmt)); + let mut check = Check::new(violations::UnnecessaryReturnNone, Range::from_located(stmt)); if checker.patch(&CheckCode::RET501) { check.amend(Fix::replacement( "return".to_string(), @@ -44,7 +44,7 @@ fn implicit_return_value(checker: &mut Checker, stack: &Stack) { if expr.is_some() { continue; } - let mut check = Check::new(CheckKind::ImplicitReturnValue, Range::from_located(stmt)); + let mut check = Check::new(violations::ImplicitReturnValue, Range::from_located(stmt)); if checker.patch(&CheckCode::RET502) { check.amend(Fix::replacement( "return None".to_string(), @@ -62,7 +62,7 @@ fn implicit_return(checker: &mut Checker, last_stmt: &Stmt) { StmtKind::If { body, orelse, .. } => { if body.is_empty() || orelse.is_empty() { checker.checks.push(Check::new( - CheckKind::ImplicitReturn, + violations::ImplicitReturn, Range::from_located(last_stmt), )); return; @@ -100,7 +100,7 @@ fn implicit_return(checker: &mut Checker, last_stmt: &Stmt) { | StmtKind::Raise { .. } | StmtKind::Try { .. } => {} _ => { - let mut check = Check::new(CheckKind::ImplicitReturn, Range::from_located(last_stmt)); + let mut check = Check::new(violations::ImplicitReturn, Range::from_located(last_stmt)); if checker.patch(&CheckCode::RET503) { let mut content = String::new(); content.push_str(&indentation(checker, last_stmt)); @@ -191,7 +191,7 @@ fn unnecessary_assign(checker: &mut Checker, stack: &Stack, expr: &Expr) { if !stack.refs.contains_key(id.as_str()) { checker.checks.push(Check::new( - CheckKind::UnnecessaryAssign, + violations::UnnecessaryAssign, Range::from_located(expr), )); return; @@ -208,7 +208,7 @@ fn unnecessary_assign(checker: &mut Checker, stack: &Stack, expr: &Expr) { } checker.checks.push(Check::new( - CheckKind::UnnecessaryAssign, + violations::UnnecessaryAssign, Range::from_located(expr), )); } @@ -223,7 +223,7 @@ fn superfluous_else_node(checker: &mut Checker, stmt: &Stmt, branch: Branch) -> if matches!(child.node, StmtKind::Return { .. }) { if checker.settings.enabled.contains(&CheckCode::RET505) { checker.checks.push(Check::new( - CheckKind::SuperfluousElseReturn(branch), + violations::SuperfluousElseReturn(branch), Range::from_located(stmt), )); } @@ -232,7 +232,7 @@ fn superfluous_else_node(checker: &mut Checker, stmt: &Stmt, branch: Branch) -> if matches!(child.node, StmtKind::Break) { if checker.settings.enabled.contains(&CheckCode::RET508) { checker.checks.push(Check::new( - CheckKind::SuperfluousElseBreak(branch), + violations::SuperfluousElseBreak(branch), Range::from_located(stmt), )); } @@ -241,7 +241,7 @@ fn superfluous_else_node(checker: &mut Checker, stmt: &Stmt, branch: Branch) -> if matches!(child.node, StmtKind::Raise { .. }) { if checker.settings.enabled.contains(&CheckCode::RET506) { checker.checks.push(Check::new( - CheckKind::SuperfluousElseRaise(branch), + violations::SuperfluousElseRaise(branch), Range::from_located(stmt), )); } @@ -250,7 +250,7 @@ fn superfluous_else_node(checker: &mut Checker, stmt: &Stmt, branch: Branch) -> if matches!(child.node, StmtKind::Continue) { if checker.settings.enabled.contains(&CheckCode::RET507) { checker.checks.push(Check::new( - CheckKind::SuperfluousElseContinue(branch), + violations::SuperfluousElseContinue(branch), Range::from_located(stmt), )); } diff --git a/src/flake8_simplify/mod.rs b/src/flake8_simplify/mod.rs index ea5f7e60d7..69300f5b4e 100644 --- a/src/flake8_simplify/mod.rs +++ b/src/flake8_simplify/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::SIM101, Path::new("SIM101.py"); "SIM101")] #[test_case(CheckCode::SIM102, Path::new("SIM102.py"); "SIM102")] diff --git a/src/flake8_simplify/plugins/ast_bool_op.rs b/src/flake8_simplify/plugins/ast_bool_op.rs index c584c02bf2..d628aa616c 100644 --- a/src/flake8_simplify/plugins/ast_bool_op.rs +++ b/src/flake8_simplify/plugins/ast_bool_op.rs @@ -10,6 +10,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; +use crate::violations; /// Return `true` if two `Expr` instances are equivalent names. fn is_same_expr<'a>(a: &'a Expr, b: &'a Expr) -> Option<&'a str> { @@ -62,7 +63,7 @@ pub fn duplicate_isinstance_call(checker: &mut Checker, expr: &Expr) { for (arg_name, indices) in duplicates { if indices.len() > 1 { let mut check = Check::new( - CheckKind::DuplicateIsinstanceCall(arg_name.to_string()), + violations::DuplicateIsinstanceCall(arg_name.to_string()), Range::from_located(expr), ); if checker.patch(&CheckCode::SIM101) { @@ -171,7 +172,7 @@ pub fn compare_with_tuple(checker: &mut Checker, expr: &Expr) { .map(|value| unparse_expr(value, checker.style)) .collect(); let mut check = Check::new( - CheckKind::CompareWithTuple( + violations::CompareWithTuple( value.to_string(), str_values, unparse_expr(expr, checker.style), @@ -233,7 +234,7 @@ pub fn a_and_not_a(checker: &mut Checker, expr: &Expr) { for non_negate_expr in &non_negated_expr { if let Some(id) = is_same_expr(negate_expr, non_negate_expr) { let mut check = Check::new( - CheckKind::AAndNotA(id.to_string()), + violations::AAndNotA(id.to_string()), Range::from_located(expr), ); if checker.patch(&CheckCode::SIM220) { @@ -281,7 +282,7 @@ pub fn a_or_not_a(checker: &mut Checker, expr: &Expr) { for non_negate_expr in &non_negated_expr { if let Some(id) = is_same_expr(negate_expr, non_negate_expr) { let mut check = Check::new( - CheckKind::AOrNotA(id.to_string()), + violations::AOrNotA(id.to_string()), Range::from_located(expr), ); if checker.patch(&CheckCode::SIM220) { @@ -308,7 +309,7 @@ pub fn or_true(checker: &mut Checker, expr: &Expr) { .. } = &value.node { - let mut check = Check::new(CheckKind::OrTrue, Range::from_located(value)); + let mut check = Check::new(violations::OrTrue, Range::from_located(value)); if checker.patch(&CheckCode::SIM223) { check.amend(Fix::replacement( "True".to_string(), @@ -332,7 +333,7 @@ pub fn and_false(checker: &mut Checker, expr: &Expr) { .. } = &value.node { - let mut check = Check::new(CheckKind::AndFalse, Range::from_located(value)); + let mut check = Check::new(violations::AndFalse, Range::from_located(value)); if checker.patch(&CheckCode::SIM223) { check.amend(Fix::replacement( "False".to_string(), diff --git a/src/flake8_simplify/plugins/ast_for.rs b/src/flake8_simplify/plugins/ast_for.rs index 3b0b1865d2..c17510fce5 100644 --- a/src/flake8_simplify/plugins/ast_for.rs +++ b/src/flake8_simplify/plugins/ast_for.rs @@ -9,6 +9,7 @@ use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; use crate::source_code_generator::SourceCodeGenerator; use crate::source_code_style::SourceCodeStyleDetector; +use crate::violations; struct Loop<'a> { return_value: bool, @@ -118,7 +119,7 @@ pub fn convert_loop_to_any_all(checker: &mut Checker, stmt: &Stmt, sibling: &Stm checker.style, ); let mut check = Check::new( - CheckKind::ConvertLoopToAny(content.clone()), + violations::ConvertLoopToAny(content.clone()), Range::from_located(stmt), ); if checker.patch(&CheckCode::SIM110) { @@ -157,7 +158,7 @@ pub fn convert_loop_to_any_all(checker: &mut Checker, stmt: &Stmt, sibling: &Stm checker.style, ); let mut check = Check::new( - CheckKind::ConvertLoopToAll(content.clone()), + violations::ConvertLoopToAll(content.clone()), Range::from_located(stmt), ); if checker.patch(&CheckCode::SIM111) { diff --git a/src/flake8_simplify/plugins/ast_if.rs b/src/flake8_simplify/plugins/ast_if.rs index dfaf5944e4..631a506c89 100644 --- a/src/flake8_simplify/plugins/ast_if.rs +++ b/src/flake8_simplify/plugins/ast_if.rs @@ -5,6 +5,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; +use crate::violations; fn is_main_check(expr: &Expr) -> bool { if let ExprKind::Compare { @@ -60,7 +61,7 @@ pub fn nested_if_statements(checker: &mut Checker, stmt: &Stmt) { } checker.checks.push(Check::new( - CheckKind::NestedIfStatements, + violations::NestedIfStatements, Range::from_located(stmt), )); } @@ -88,7 +89,7 @@ pub fn return_bool_condition_directly(checker: &mut Checker, stmt: &Stmt) { } let condition = unparse_expr(test, checker.style); let mut check = Check::new( - CheckKind::ReturnBoolConditionDirectly(condition), + violations::ReturnBoolConditionDirectly(condition), Range::from_located(stmt), ); if checker.patch(&CheckCode::SIM103) { @@ -178,7 +179,7 @@ pub fn use_ternary_operator(checker: &mut Checker, stmt: &Stmt, parent: Option<& let ternary = ternary(target_var, body_value, test, orelse_value); let content = unparse_stmt(&ternary, checker.style); let mut check = Check::new( - CheckKind::UseTernaryOperator(content.clone()), + violations::UseTernaryOperator(content.clone()), Range::from_located(stmt), ); if checker.patch(&CheckCode::SIM108) { diff --git a/src/flake8_simplify/plugins/ast_with.rs b/src/flake8_simplify/plugins/ast_with.rs index 294200a53a..d5cbf4c5b4 100644 --- a/src/flake8_simplify/plugins/ast_with.rs +++ b/src/flake8_simplify/plugins/ast_with.rs @@ -3,6 +3,7 @@ use rustpython_ast::{Stmt, StmtKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// SIM117 pub fn multiple_with_statements(checker: &mut Checker, stmt: &Stmt) { @@ -14,7 +15,7 @@ pub fn multiple_with_statements(checker: &mut Checker, stmt: &Stmt) { } if matches!(body[0].node, StmtKind::With { .. }) { checker.checks.push(Check::new( - CheckKind::MultipleWithStatements, + violations::MultipleWithStatements, Range::from_located(stmt), )); } diff --git a/src/flake8_simplify/plugins/key_in_dict.rs b/src/flake8_simplify/plugins/key_in_dict.rs index 98c9997203..52772119a2 100644 --- a/src/flake8_simplify/plugins/key_in_dict.rs +++ b/src/flake8_simplify/plugins/key_in_dict.rs @@ -4,6 +4,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// SIM118 fn key_in_dict(checker: &mut Checker, left: &Expr, right: &Expr, range: Range) { @@ -34,7 +35,7 @@ fn key_in_dict(checker: &mut Checker, left: &Expr, right: &Expr, range: Range) { .slice_source_code_range(&Range::from_located(value)); let mut check = Check::new( - CheckKind::KeyInDict(left_content.to_string(), value_content.to_string()), + violations::KeyInDict(left_content.to_string(), value_content.to_string()), range, ); if checker.patch(check.kind.code()) { diff --git a/src/flake8_simplify/plugins/return_in_try_except_finally.rs b/src/flake8_simplify/plugins/return_in_try_except_finally.rs index e86bae5776..725526253d 100644 --- a/src/flake8_simplify/plugins/return_in_try_except_finally.rs +++ b/src/flake8_simplify/plugins/return_in_try_except_finally.rs @@ -3,6 +3,7 @@ use rustpython_ast::{Excepthandler, ExcepthandlerKind, Stmt, StmtKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; fn find_return(stmts: &[Stmt]) -> Option<&Stmt> { stmts @@ -26,7 +27,7 @@ pub fn return_in_try_except_finally( if let Some(finally_return) = find_return(finalbody) { if try_has_return || except_has_return { checker.checks.push(Check::new( - CheckKind::ReturnInTryExceptFinally, + violations::ReturnInTryExceptFinally, Range::from_located(finally_return), )); } diff --git a/src/flake8_simplify/plugins/unary_ops.rs b/src/flake8_simplify/plugins/unary_ops.rs index cdfb6a679a..a0b1c9244c 100644 --- a/src/flake8_simplify/plugins/unary_ops.rs +++ b/src/flake8_simplify/plugins/unary_ops.rs @@ -5,6 +5,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; fn is_exception_check(stmt: &Stmt) -> bool { let StmtKind::If {test: _, body, orelse: _} = &stmt.node else { @@ -35,7 +36,7 @@ pub fn negation_with_equal_op(checker: &mut Checker, expr: &Expr, op: &Unaryop, } let mut check = Check::new( - CheckKind::NegateEqualOp( + violations::NegateEqualOp( unparse_expr(left, checker.style), unparse_expr(&comparators[0], checker.style), ), @@ -79,7 +80,7 @@ pub fn negation_with_not_equal_op( } let mut check = Check::new( - CheckKind::NegateNotEqualOp( + violations::NegateNotEqualOp( unparse_expr(left, checker.style), unparse_expr(&comparators[0], checker.style), ), @@ -115,7 +116,7 @@ pub fn double_negation(checker: &mut Checker, expr: &Expr, op: &Unaryop, operand } let mut check = Check::new( - CheckKind::DoubleNegation(operand.to_string()), + violations::DoubleNegation(operand.to_string()), Range::from_located(operand), ); if checker.patch(check.kind.code()) { diff --git a/src/flake8_simplify/plugins/use_contextlib_suppress.rs b/src/flake8_simplify/plugins/use_contextlib_suppress.rs index 4fcb417e51..130be2590e 100644 --- a/src/flake8_simplify/plugins/use_contextlib_suppress.rs +++ b/src/flake8_simplify/plugins/use_contextlib_suppress.rs @@ -4,6 +4,7 @@ use crate::ast::helpers; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// SIM105 pub fn use_contextlib_suppress( @@ -30,7 +31,7 @@ pub fn use_contextlib_suppress( handler_names.join(", ") }; let check = Check::new( - CheckKind::UseContextlibSuppress(exception), + violations::UseContextlibSuppress(exception), Range::from_located(stmt), ); checker.checks.push(check); diff --git a/src/flake8_simplify/plugins/yoda_conditions.rs b/src/flake8_simplify/plugins/yoda_conditions.rs index 4b4d81b6d2..f54047ce75 100644 --- a/src/flake8_simplify/plugins/yoda_conditions.rs +++ b/src/flake8_simplify/plugins/yoda_conditions.rs @@ -4,6 +4,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// SIM300 pub fn yoda_conditions( @@ -41,7 +42,7 @@ pub fn yoda_conditions( .slice_source_code_range(&Range::from_located(right)); let mut check = Check::new( - CheckKind::YodaConditions(left_content.to_string(), right_content.to_string()), + violations::YodaConditions(left_content.to_string(), right_content.to_string()), Range::from_located(expr), ); diff --git a/src/flake8_tidy_imports/checks.rs b/src/flake8_tidy_imports/checks.rs index 255ff0daba..9bb16e29bc 100644 --- a/src/flake8_tidy_imports/checks.rs +++ b/src/flake8_tidy_imports/checks.rs @@ -7,6 +7,7 @@ use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::flake8_tidy_imports::settings::Strictness; use crate::registry::{Check, CheckKind}; +use crate::violations; /// TID252 pub fn banned_relative_import( @@ -20,7 +21,7 @@ pub fn banned_relative_import( }; if level? > &strictness_level { Some(Check::new( - CheckKind::BannedRelativeImport(strictness.clone()), + violations::BannedRelativeImport(strictness.clone()), Range::from_located(stmt), )) } else { @@ -37,7 +38,7 @@ pub fn name_is_banned( let full_name = format!("{module}.{}", &name.node.name); if let Some(ban) = banned_apis.get(&full_name) { return Some(Check::new( - CheckKind::BannedApi { + violations::BannedApi { name: full_name, message: ban.msg.to_string(), }, @@ -57,7 +58,7 @@ pub fn name_or_parent_is_banned( loop { if let Some(ban) = banned_apis.get(name) { return Some(Check::new( - CheckKind::BannedApi { + violations::BannedApi { name: name.to_string(), message: ban.msg.to_string(), }, @@ -84,7 +85,7 @@ pub fn banned_attribute_access( if let Some((module, member)) = banned_path.rsplit_once('.') { if match_call_path(call_path, module, member, &checker.from_imports) { checker.checks.push(Check::new( - CheckKind::BannedApi { + violations::BannedApi { name: banned_path.to_string(), message: ban.msg.to_string(), }, diff --git a/src/flake8_tidy_imports/mod.rs b/src/flake8_tidy_imports/mod.rs index 049f2f36e1..83c11b26f6 100644 --- a/src/flake8_tidy_imports/mod.rs +++ b/src/flake8_tidy_imports/mod.rs @@ -11,7 +11,7 @@ mod tests { use crate::flake8_tidy_imports::settings::{BannedApi, Strictness}; use crate::linter::test_path; use crate::registry::CheckCode; - use crate::{flake8_tidy_imports, Settings}; + use crate::{flake8_tidy_imports, violations, Settings}; #[test] fn ban_parent_imports() -> Result<()> { diff --git a/src/flake8_unused_arguments/mod.rs b/src/flake8_unused_arguments/mod.rs index eb9ef4d27c..8a4702ae6c 100644 --- a/src/flake8_unused_arguments/mod.rs +++ b/src/flake8_unused_arguments/mod.rs @@ -13,7 +13,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::{flake8_unused_arguments, settings}; + use crate::{flake8_unused_arguments, settings, violations}; #[test_case(CheckCode::ARG001, Path::new("ARG.py"); "ARG001")] #[test_case(CheckCode::ARG002, Path::new("ARG.py"); "ARG002")] diff --git a/src/flake8_unused_arguments/types.rs b/src/flake8_unused_arguments/types.rs index 34dcc7d012..5c901704c3 100644 --- a/src/flake8_unused_arguments/types.rs +++ b/src/flake8_unused_arguments/types.rs @@ -1,4 +1,5 @@ use crate::registry::{CheckCode, CheckKind}; +use crate::violations; /// An AST node that can contain arguments. pub enum Argumentable { @@ -12,11 +13,11 @@ pub enum Argumentable { impl Argumentable { pub fn check_for(&self, name: String) -> CheckKind { match self { - Argumentable::Function => CheckKind::UnusedFunctionArgument(name), - Argumentable::Method => CheckKind::UnusedMethodArgument(name), - Argumentable::ClassMethod => CheckKind::UnusedClassMethodArgument(name), - Argumentable::StaticMethod => CheckKind::UnusedStaticMethodArgument(name), - Argumentable::Lambda => CheckKind::UnusedLambdaArgument(name), + Argumentable::Function => violations::UnusedFunctionArgument(name), + Argumentable::Method => violations::UnusedMethodArgument(name), + Argumentable::ClassMethod => violations::UnusedClassMethodArgument(name), + Argumentable::StaticMethod => violations::UnusedStaticMethodArgument(name), + Argumentable::Lambda => violations::UnusedLambdaArgument(name), } } diff --git a/src/fs.rs b/src/fs.rs index 74c0fb3a86..79ab2ce8ac 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -9,6 +9,7 @@ use path_absolutize::{path_dedot, Absolutize}; use rustc_hash::FxHashSet; use crate::registry::CheckCode; +use crate::violations; /// Extract the absolute path and basename (as strings) from a Path. pub fn extract_path_names(path: &Path) -> Result<(&str, &str)> { diff --git a/src/isort/mod.rs b/src/isort/mod.rs index ebcff2c24c..10287d4500 100644 --- a/src/isort/mod.rs +++ b/src/isort/mod.rs @@ -634,7 +634,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::{isort, Settings}; + use crate::{isort, violations, Settings}; #[test_case(Path::new("add_newline_before_comments.py"))] #[test_case(Path::new("combine_as_imports.py"))] diff --git a/src/isort/plugins.rs b/src/isort/plugins.rs index fbf67a3d69..9466286e1c 100644 --- a/src/isort/plugins.rs +++ b/src/isort/plugins.rs @@ -14,7 +14,7 @@ use crate::isort::{comments, format_imports}; use crate::registry::CheckKind; use crate::settings::flags; use crate::source_code_style::SourceCodeStyleDetector; -use crate::{Check, Settings, SourceCodeLocator}; +use crate::{violations, Check, Settings, SourceCodeLocator}; fn extract_range(body: &[&Stmt]) -> Range { let location = body.first().unwrap().location; @@ -46,7 +46,7 @@ pub fn check_imports( if preceded_by_multi_statement_line(block.imports.first().unwrap(), locator) || followed_by_multi_statement_line(block.imports.last().unwrap(), locator) { - return Some(Check::new(CheckKind::UnsortedImports, range)); + return Some(Check::new(violations::UnsortedImports, range)); } // Extract comments. Take care to grab any inline comments from the last line. @@ -93,7 +93,7 @@ pub fn check_imports( if actual == dedent(&expected) { None } else { - let mut check = Check::new(CheckKind::UnsortedImports, range); + let mut check = Check::new(violations::UnsortedImports, range); if matches!(autofix, flags::Autofix::Enabled) && settings.fixable.contains(check.kind.code()) { diff --git a/src/lib_native.rs b/src/lib_native.rs index d7afd8f886..d35f45090c 100644 --- a/src/lib_native.rs +++ b/src/lib_native.rs @@ -12,7 +12,7 @@ use crate::settings::configuration::Configuration; use crate::settings::{flags, pyproject, Settings}; use crate::source_code_locator::SourceCodeLocator; use crate::source_code_style::SourceCodeStyleDetector; -use crate::{directives, packages, resolver}; +use crate::{directives, packages, resolver, violations}; /// Load the relevant `Settings` for a given `Path`. fn resolve(path: &Path) -> Result { diff --git a/src/linter.rs b/src/linter.rs index 8c349e0121..ae6bce6b3d 100644 --- a/src/linter.rs +++ b/src/linter.rs @@ -25,7 +25,7 @@ use crate::registry::{Check, CheckCode, CheckKind, LintSource}; use crate::settings::{flags, Settings}; use crate::source_code_locator::SourceCodeLocator; use crate::source_code_style::SourceCodeStyleDetector; -use crate::{cache, directives, fs, rustpython_helpers}; +use crate::{cache, directives, fs, rustpython_helpers, violations}; const CARGO_PKG_NAME: &str = env!("CARGO_PKG_NAME"); const CARGO_PKG_REPOSITORY: &str = env!("CARGO_PKG_REPOSITORY"); @@ -119,7 +119,7 @@ pub(crate) fn check_path( Err(parse_error) => { if settings.enabled.contains(&CheckCode::E999) { checks.push(Check::new( - CheckKind::SyntaxError(parse_error.error.to_string()), + violations::SyntaxError(parse_error.error.to_string()), Range::new(parse_error.location, parse_error.location), )); } diff --git a/src/mccabe/checks.rs b/src/mccabe/checks.rs index 9431fdca61..54584ac79d 100644 --- a/src/mccabe/checks.rs +++ b/src/mccabe/checks.rs @@ -3,6 +3,7 @@ use rustpython_ast::{ExcepthandlerKind, ExprKind, Stmt, StmtKind}; use crate::ast::helpers::identifier_range; use crate::registry::{Check, CheckKind}; use crate::source_code_locator::SourceCodeLocator; +use crate::violations; fn get_complexity_number(stmts: &[Stmt]) -> usize { let mut complexity = 0; @@ -65,7 +66,7 @@ pub fn function_is_too_complex( let complexity = get_complexity_number(body) + 1; if complexity > max_complexity { Some(Check::new( - CheckKind::FunctionIsTooComplex(name.to_string(), complexity), + violations::FunctionIsTooComplex(name.to_string(), complexity), identifier_range(stmt, locator), )) } else { diff --git a/src/mccabe/mod.rs b/src/mccabe/mod.rs index fa8a5e8feb..4c45fde090 100644 --- a/src/mccabe/mod.rs +++ b/src/mccabe/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::{mccabe, Settings}; + use crate::{mccabe, violations, Settings}; #[test_case(0)] #[test_case(3)] diff --git a/src/message.rs b/src/message.rs index 993618af62..144eb30f05 100644 --- a/src/message.rs +++ b/src/message.rs @@ -7,6 +7,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::registry::{Check, CheckKind}; use crate::source_code_locator::SourceCodeLocator; +use crate::violations; #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Message { diff --git a/src/noqa.rs b/src/noqa.rs index eddc95195c..7ed2582801 100644 --- a/src/noqa.rs +++ b/src/noqa.rs @@ -10,6 +10,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; use crate::registry::{Check, CheckCode, CODE_REDIRECTS}; use crate::source_code_style::LineEnding; +use crate::violations; static NOQA_LINE_REGEX: Lazy = Lazy::new(|| { Regex::new( @@ -215,6 +216,7 @@ mod tests { use crate::noqa::{add_noqa_inner, NOQA_LINE_REGEX}; use crate::registry::{Check, CheckKind}; use crate::source_code_style::LineEnding; + use crate::violations; #[test] fn regex() { @@ -247,7 +249,7 @@ mod tests { assert_eq!(output, format!("{contents}\n")); let checks = vec![Check::new( - CheckKind::UnusedVariable("x".to_string()), + violations::UnusedVariable("x".to_string()), Range::new(Location::new(1, 0), Location::new(1, 0)), )]; let contents = "x = 1"; @@ -265,11 +267,11 @@ mod tests { let checks = vec![ Check::new( - CheckKind::AmbiguousVariableName("x".to_string()), + violations::AmbiguousVariableName("x".to_string()), Range::new(Location::new(1, 0), Location::new(1, 0)), ), Check::new( - CheckKind::UnusedVariable("x".to_string()), + violations::UnusedVariable("x".to_string()), Range::new(Location::new(1, 0), Location::new(1, 0)), ), ]; @@ -288,11 +290,11 @@ mod tests { let checks = vec![ Check::new( - CheckKind::AmbiguousVariableName("x".to_string()), + violations::AmbiguousVariableName("x".to_string()), Range::new(Location::new(1, 0), Location::new(1, 0)), ), Check::new( - CheckKind::UnusedVariable("x".to_string()), + violations::UnusedVariable("x".to_string()), Range::new(Location::new(1, 0), Location::new(1, 0)), ), ]; diff --git a/src/pandas_vet/checks.rs b/src/pandas_vet/checks.rs index a9cc96118c..e42d4ac1d8 100644 --- a/src/pandas_vet/checks.rs +++ b/src/pandas_vet/checks.rs @@ -2,6 +2,7 @@ use rustpython_ast::{Constant, Expr, ExprKind, Keyword}; use crate::ast::types::Range; use crate::registry::{Check, CheckKind}; +use crate::violations; /// PD002 pub fn inplace_argument(keywords: &[Keyword]) -> Option { @@ -18,7 +19,7 @@ pub fn inplace_argument(keywords: &[Keyword]) -> Option { }; if is_true_literal { return Some(Check::new( - CheckKind::UseOfInplaceArgument, + violations::UseOfInplaceArgument, Range::from_located(keyword), )); } @@ -33,7 +34,7 @@ pub fn use_of_pd_merge(func: &Expr) -> Option { if let ExprKind::Name { id, .. } = &value.node { if id == "pd" && attr == "merge" { return Some(Check::new( - CheckKind::UseOfPdMerge, + violations::UseOfPdMerge, Range::from_located(func), )); } @@ -55,7 +56,7 @@ pub fn assignment_to_df(targets: &[Expr]) -> Option { return None; } Some(Check::new( - CheckKind::DfIsABadVariableName, + violations::DfIsABadVariableName, Range::from_located(target), )) } diff --git a/src/pandas_vet/mod.rs b/src/pandas_vet/mod.rs index 9673957721..7d79de79b9 100644 --- a/src/pandas_vet/mod.rs +++ b/src/pandas_vet/mod.rs @@ -15,7 +15,7 @@ mod tests { use crate::settings::flags; use crate::source_code_locator::SourceCodeLocator; use crate::source_code_style::SourceCodeStyleDetector; - use crate::{directives, rustpython_helpers, settings}; + use crate::{directives, rustpython_helpers, settings, violations}; fn check_code(contents: &str, expected: &[CheckCode]) -> Result<()> { let contents = dedent(contents); diff --git a/src/pep8_naming/checks.rs b/src/pep8_naming/checks.rs index 36c52b287a..ec23d030ea 100644 --- a/src/pep8_naming/checks.rs +++ b/src/pep8_naming/checks.rs @@ -9,6 +9,7 @@ use crate::pep8_naming::settings::Settings; use crate::python::string::{self}; use crate::registry::{Check, CheckKind}; use crate::source_code_locator::SourceCodeLocator; +use crate::violations; /// N801 pub fn invalid_class_name( @@ -19,7 +20,7 @@ pub fn invalid_class_name( let stripped = name.strip_prefix('_').unwrap_or(name); if !stripped.chars().next().map_or(false, char::is_uppercase) || stripped.contains('_') { return Some(Check::new( - CheckKind::InvalidClassName(name.to_string()), + violations::InvalidClassName(name.to_string()), identifier_range(class_def, locator), )); } @@ -35,7 +36,7 @@ pub fn invalid_function_name( ) -> Option { if name.to_lowercase() != name && !ignore_names.iter().any(|ignore_name| ignore_name == name) { return Some(Check::new( - CheckKind::InvalidFunctionName(name.to_string()), + violations::InvalidFunctionName(name.to_string()), identifier_range(func_def, locator), )); } @@ -46,7 +47,7 @@ pub fn invalid_function_name( pub fn invalid_argument_name(name: &str, arg: &Arg) -> Option { if name.to_lowercase() != name { return Some(Check::new( - CheckKind::InvalidArgumentName(name.to_string()), + violations::InvalidArgumentName(name.to_string()), Range::from_located(arg), )); } @@ -80,14 +81,14 @@ pub fn invalid_first_argument_name_for_class_method( if let Some(arg) = args.posonlyargs.first() { if arg.node.arg != "cls" { return Some(Check::new( - CheckKind::InvalidFirstArgumentNameForClassMethod, + violations::InvalidFirstArgumentNameForClassMethod, Range::from_located(arg), )); } } else if let Some(arg) = args.args.first() { if arg.node.arg != "cls" { return Some(Check::new( - CheckKind::InvalidFirstArgumentNameForClassMethod, + violations::InvalidFirstArgumentNameForClassMethod, Range::from_located(arg), )); } @@ -124,7 +125,7 @@ pub fn invalid_first_argument_name_for_method( return None; } Some(Check::new( - CheckKind::InvalidFirstArgumentNameForMethod, + violations::InvalidFirstArgumentNameForMethod, Range::from_located(arg), )) } @@ -148,7 +149,7 @@ pub fn dunder_function_name( } Some(Check::new( - CheckKind::DunderFunctionName, + violations::DunderFunctionName, identifier_range(stmt, locator), )) } @@ -162,7 +163,7 @@ pub fn constant_imported_as_non_constant( ) -> Option { if string::is_upper(name) && !string::is_upper(asname) { return Some(Check::new( - CheckKind::ConstantImportedAsNonConstant(name.to_string(), asname.to_string()), + violations::ConstantImportedAsNonConstant(name.to_string(), asname.to_string()), identifier_range(import_from, locator), )); } @@ -178,7 +179,7 @@ pub fn lowercase_imported_as_non_lowercase( ) -> Option { if !string::is_upper(name) && string::is_lower(name) && asname.to_lowercase() != asname { return Some(Check::new( - CheckKind::LowercaseImportedAsNonLowercase(name.to_string(), asname.to_string()), + violations::LowercaseImportedAsNonLowercase(name.to_string(), asname.to_string()), identifier_range(import_from, locator), )); } @@ -194,7 +195,7 @@ pub fn camelcase_imported_as_lowercase( ) -> Option { if helpers::is_camelcase(name) && string::is_lower(asname) { return Some(Check::new( - CheckKind::CamelcaseImportedAsLowercase(name.to_string(), asname.to_string()), + violations::CamelcaseImportedAsLowercase(name.to_string(), asname.to_string()), identifier_range(import_from, locator), )); } @@ -214,7 +215,7 @@ pub fn camelcase_imported_as_constant( && !helpers::is_acronym(name, asname) { return Some(Check::new( - CheckKind::CamelcaseImportedAsConstant(name.to_string(), asname.to_string()), + violations::CamelcaseImportedAsConstant(name.to_string(), asname.to_string()), identifier_range(import_from, locator), )); } @@ -234,7 +235,7 @@ pub fn camelcase_imported_as_acronym( && helpers::is_acronym(name, asname) { return Some(Check::new( - CheckKind::CamelcaseImportedAsAcronym(name.to_string(), asname.to_string()), + violations::CamelcaseImportedAsAcronym(name.to_string(), asname.to_string()), identifier_range(import_from, locator), )); } @@ -262,7 +263,7 @@ pub fn error_suffix_on_exception_name( return None; } Some(Check::new( - CheckKind::ErrorSuffixOnExceptionName(name.to_string()), + violations::ErrorSuffixOnExceptionName(name.to_string()), identifier_range(class_def, locator), )) } diff --git a/src/pep8_naming/mod.rs b/src/pep8_naming/mod.rs index 3fe6c8ac51..bfcf252eb6 100644 --- a/src/pep8_naming/mod.rs +++ b/src/pep8_naming/mod.rs @@ -13,7 +13,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::N801, Path::new("N801.py"); "N801")] #[test_case(CheckCode::N802, Path::new("N802.py"); "N802")] diff --git a/src/pep8_naming/plugins.rs b/src/pep8_naming/plugins.rs index 91f77cd790..9543619af1 100644 --- a/src/pep8_naming/plugins.rs +++ b/src/pep8_naming/plugins.rs @@ -4,7 +4,7 @@ use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::pep8_naming::helpers; use crate::registry::CheckKind; -use crate::Check; +use crate::{violations, Check}; /// N806 pub fn non_lowercase_variable_in_function( @@ -17,7 +17,7 @@ pub fn non_lowercase_variable_in_function( && !helpers::is_namedtuple_assignment(stmt, &checker.from_imports) { checker.checks.push(Check::new( - CheckKind::NonLowercaseVariableInFunction(name.to_string()), + violations::NonLowercaseVariableInFunction(name.to_string()), Range::from_located(expr), )); } @@ -34,7 +34,7 @@ pub fn mixed_case_variable_in_class_scope( && !helpers::is_namedtuple_assignment(stmt, &checker.from_imports) { checker.checks.push(Check::new( - CheckKind::MixedCaseVariableInClassScope(name.to_string()), + violations::MixedCaseVariableInClassScope(name.to_string()), Range::from_located(expr), )); } @@ -51,7 +51,7 @@ pub fn mixed_case_variable_in_global_scope( && !helpers::is_namedtuple_assignment(stmt, &checker.from_imports) { checker.checks.push(Check::new( - CheckKind::MixedCaseVariableInGlobalScope(name.to_string()), + violations::MixedCaseVariableInGlobalScope(name.to_string()), Range::from_located(expr), )); } diff --git a/src/printer.rs b/src/printer.rs index af7f1cc762..00099dc80a 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -17,7 +17,7 @@ use crate::logging::LogLevel; use crate::message::Message; use crate::registry::CheckCode; use crate::settings::types::SerializationFormat; -use crate::tell_user; +use crate::{tell_user, violations}; /// Enum to control whether lint violations are shown to the user. pub enum Violations { diff --git a/src/pycodestyle/checks.rs b/src/pycodestyle/checks.rs index d62dc13879..d9a27aff62 100644 --- a/src/pycodestyle/checks.rs +++ b/src/pycodestyle/checks.rs @@ -10,6 +10,7 @@ use crate::autofix::Fix; use crate::registry::{Check, CheckKind}; use crate::settings::Settings; use crate::source_code_locator::SourceCodeLocator; +use crate::violations; static URL_REGEX: Lazy = Lazy::new(|| Regex::new(r"^https?://\S+$").unwrap()); @@ -43,7 +44,7 @@ pub fn line_too_long(lineno: usize, line: &str, settings: &Settings) -> Option kind: None } ) { - checks.push(Check::new(CheckKind::TypeComparison, location)); + checks.push(Check::new(violations::TypeComparison, location)); } } } @@ -84,7 +85,7 @@ pub fn type_comparison(ops: &[Cmpop], comparators: &[Expr], location: Range) -> if let ExprKind::Name { id, .. } = &value.node { // Ex) types.IntType if id == "types" { - checks.push(Check::new(CheckKind::TypeComparison, location)); + checks.push(Check::new(violations::TypeComparison, location)); } } } @@ -108,7 +109,7 @@ pub fn do_not_use_bare_except( .any(|stmt| matches!(stmt.node, StmtKind::Raise { exc: None, .. })) { Some(Check::new( - CheckKind::DoNotUseBareExcept, + violations::DoNotUseBareExcept, except_range(handler, locator), )) } else { @@ -124,7 +125,7 @@ fn is_ambiguous_name(name: &str) -> bool { pub fn ambiguous_variable_name(name: &str, range: Range) -> Option { if is_ambiguous_name(name) { Some(Check::new( - CheckKind::AmbiguousVariableName(name.to_string()), + violations::AmbiguousVariableName(name.to_string()), range, )) } else { @@ -139,7 +140,7 @@ where { if is_ambiguous_name(name) { Some(Check::new( - CheckKind::AmbiguousClassName(name.to_string()), + violations::AmbiguousClassName(name.to_string()), locate(), )) } else { @@ -154,7 +155,7 @@ where { if is_ambiguous_name(name) { Some(Check::new( - CheckKind::AmbiguousFunctionName(name.to_string()), + violations::AmbiguousFunctionName(name.to_string()), locate(), )) } else { @@ -171,7 +172,7 @@ pub fn no_newline_at_end_of_file(contents: &str, autofix: bool) -> Option // Both locations are at the end of the file (and thus the same). let location = Location::new(contents.lines().count(), line.len()); let mut check = Check::new( - CheckKind::NoNewLineAtEndOfFile, + violations::NoNewLineAtEndOfFile, Range::new(location, location), ); if autofix { @@ -252,7 +253,7 @@ pub fn invalid_escape_sequence( let location = Location::new(start.row() + row_offset, col); let end_location = Location::new(location.row(), location.column() + 2); let mut check = Check::new( - CheckKind::InvalidEscapeSequence(next_char), + violations::InvalidEscapeSequence(next_char), Range::new(location, end_location), ); if autofix { diff --git a/src/pycodestyle/mod.rs b/src/pycodestyle/mod.rs index 49ee8db613..c10657a1b9 100644 --- a/src/pycodestyle/mod.rs +++ b/src/pycodestyle/mod.rs @@ -13,7 +13,7 @@ mod tests { use super::settings::Settings; use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::E401, Path::new("E40.py"))] #[test_case(CheckCode::E402, Path::new("E40.py"))] diff --git a/src/pycodestyle/plugins.rs b/src/pycodestyle/plugins.rs index 27dcaf60db..5f90fb4ac6 100644 --- a/src/pycodestyle/plugins.rs +++ b/src/pycodestyle/plugins.rs @@ -14,6 +14,7 @@ use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; use crate::source_code_generator::SourceCodeGenerator; use crate::source_code_style::SourceCodeStyleDetector; +use crate::violations; pub fn compare( left: &Expr, @@ -64,7 +65,7 @@ pub fn literal_comparisons( { if matches!(op, Cmpop::Eq) { let check = Check::new( - CheckKind::NoneComparison(op.into()), + violations::NoneComparison(op.into()), Range::from_located(comparator), ); if checker.patch(check.kind.code()) && !helpers::is_constant_non_singleton(next) { @@ -74,7 +75,7 @@ pub fn literal_comparisons( } if matches!(op, Cmpop::NotEq) { let check = Check::new( - CheckKind::NoneComparison(op.into()), + violations::NoneComparison(op.into()), Range::from_located(comparator), ); if checker.patch(check.kind.code()) && !helpers::is_constant_non_singleton(next) { @@ -92,7 +93,7 @@ pub fn literal_comparisons( { if matches!(op, Cmpop::Eq) { let check = Check::new( - CheckKind::TrueFalseComparison(value, op.into()), + violations::TrueFalseComparison(value, op.into()), Range::from_located(comparator), ); if checker.patch(check.kind.code()) && !helpers::is_constant_non_singleton(next) { @@ -102,7 +103,7 @@ pub fn literal_comparisons( } if matches!(op, Cmpop::NotEq) { let check = Check::new( - CheckKind::TrueFalseComparison(value, op.into()), + violations::TrueFalseComparison(value, op.into()), Range::from_located(comparator), ); if checker.patch(check.kind.code()) && !helpers::is_constant_non_singleton(next) { @@ -126,7 +127,7 @@ pub fn literal_comparisons( { if matches!(op, Cmpop::Eq) { let check = Check::new( - CheckKind::NoneComparison(op.into()), + violations::NoneComparison(op.into()), Range::from_located(next), ); if checker.patch(check.kind.code()) @@ -138,7 +139,7 @@ pub fn literal_comparisons( } if matches!(op, Cmpop::NotEq) { let check = Check::new( - CheckKind::NoneComparison(op.into()), + violations::NoneComparison(op.into()), Range::from_located(next), ); if checker.patch(check.kind.code()) @@ -158,7 +159,7 @@ pub fn literal_comparisons( { if matches!(op, Cmpop::Eq) { let check = Check::new( - CheckKind::TrueFalseComparison(value, op.into()), + violations::TrueFalseComparison(value, op.into()), Range::from_located(next), ); if checker.patch(check.kind.code()) @@ -170,7 +171,7 @@ pub fn literal_comparisons( } if matches!(op, Cmpop::NotEq) { let check = Check::new( - CheckKind::TrueFalseComparison(value, op.into()), + violations::TrueFalseComparison(value, op.into()), Range::from_located(next), ); if checker.patch(check.kind.code()) @@ -232,7 +233,7 @@ pub fn not_tests( Cmpop::In => { if check_not_in { let mut check = - Check::new(CheckKind::NotInTest, Range::from_located(operand)); + Check::new(violations::NotInTest, Range::from_located(operand)); if checker.patch(check.kind.code()) && should_fix { check.amend(Fix::replacement( compare(left, &[Cmpop::NotIn], comparators, checker.style), @@ -246,7 +247,7 @@ pub fn not_tests( Cmpop::Is => { if check_not_is { let mut check = - Check::new(CheckKind::NotIsTest, Range::from_located(operand)); + Check::new(violations::NotIsTest, Range::from_located(operand)); if checker.patch(check.kind.code()) && should_fix { check.amend(Fix::replacement( compare(left, &[Cmpop::IsNot], comparators, checker.style), @@ -299,7 +300,7 @@ pub fn do_not_assign_lambda(checker: &mut Checker, target: &Expr, value: &Expr, if let ExprKind::Name { id, .. } = &target.node { if let ExprKind::Lambda { args, body } = &value.node { let mut check = Check::new( - CheckKind::DoNotAssignLambda(id.to_string()), + violations::DoNotAssignLambda(id.to_string()), Range::from_located(stmt), ); if checker.patch(check.kind.code()) { diff --git a/src/pydocstyle/mod.rs b/src/pydocstyle/mod.rs index b8c0842d9f..eb4f5b0024 100644 --- a/src/pydocstyle/mod.rs +++ b/src/pydocstyle/mod.rs @@ -13,7 +13,7 @@ mod tests { use crate::linter::test_path; use crate::pydocstyle::settings::{Convention, Settings}; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::D100, Path::new("D.py"); "D100")] #[test_case(CheckCode::D101, Path::new("D.py"); "D101")] diff --git a/src/pydocstyle/plugins.rs b/src/pydocstyle/plugins.rs index 275b2d3192..cb5c8ac408 100644 --- a/src/pydocstyle/plugins.rs +++ b/src/pydocstyle/plugins.rs @@ -17,6 +17,7 @@ use crate::docstrings::styles::SectionStyle; use crate::pydocstyle::helpers::{leading_quote, logical_line}; use crate::pydocstyle::settings::Convention; use crate::registry::{Check, CheckCode, CheckKind}; +use crate::violations; use crate::visibility::{is_init, is_magic, is_overload, is_override, is_staticmethod, Visibility}; /// D100, D101, D102, D103, D104, D105, D106, D107 @@ -33,7 +34,7 @@ pub fn not_missing( DefinitionKind::Module => { if checker.settings.enabled.contains(&CheckCode::D100) { checker.checks.push(Check::new( - CheckKind::PublicModule, + violations::PublicModule, Range::new(Location::new(1, 0), Location::new(1, 0)), )); } @@ -42,7 +43,7 @@ pub fn not_missing( DefinitionKind::Package => { if checker.settings.enabled.contains(&CheckCode::D104) { checker.checks.push(Check::new( - CheckKind::PublicPackage, + violations::PublicPackage, Range::new(Location::new(1, 0), Location::new(1, 0)), )); } @@ -51,7 +52,7 @@ pub fn not_missing( DefinitionKind::Class(stmt) => { if checker.settings.enabled.contains(&CheckCode::D101) { checker.checks.push(Check::new( - CheckKind::PublicClass, + violations::PublicClass, identifier_range(stmt, checker.locator), )); } @@ -60,7 +61,7 @@ pub fn not_missing( DefinitionKind::NestedClass(stmt) => { if checker.settings.enabled.contains(&CheckCode::D106) { checker.checks.push(Check::new( - CheckKind::PublicNestedClass, + violations::PublicNestedClass, identifier_range(stmt, checker.locator), )); } @@ -72,7 +73,7 @@ pub fn not_missing( } else { if checker.settings.enabled.contains(&CheckCode::D103) { checker.checks.push(Check::new( - CheckKind::PublicFunction, + violations::PublicFunction, identifier_range(stmt, checker.locator), )); } @@ -87,7 +88,7 @@ pub fn not_missing( } else if is_magic(stmt) { if checker.settings.enabled.contains(&CheckCode::D105) { checker.checks.push(Check::new( - CheckKind::MagicMethod, + violations::MagicMethod, identifier_range(stmt, checker.locator), )); } @@ -95,7 +96,7 @@ pub fn not_missing( } else if is_init(stmt) { if checker.settings.enabled.contains(&CheckCode::D107) { checker.checks.push(Check::new( - CheckKind::PublicInit, + violations::PublicInit, identifier_range(stmt, checker.locator), )); } @@ -103,7 +104,7 @@ pub fn not_missing( } else { if checker.settings.enabled.contains(&CheckCode::D102) { checker.checks.push(Check::new( - CheckKind::PublicMethod, + violations::PublicMethod, identifier_range(stmt, checker.locator), )); } @@ -131,7 +132,7 @@ pub fn one_liner(checker: &mut Checker, docstring: &Docstring) { if non_empty_line_count == 1 && line_count > 1 { checker.checks.push(Check::new( - CheckKind::FitsOnOneLine, + violations::FitsOnOneLine, Range::from_located(docstring.expr), )); } @@ -166,7 +167,7 @@ pub fn blank_before_after_function(checker: &mut Checker, docstring: &Docstring) .count(); if blank_lines_before != 0 { let mut check = Check::new( - CheckKind::NoBlankLineBeforeFunction(blank_lines_before), + violations::NoBlankLineBeforeFunction(blank_lines_before), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -207,7 +208,7 @@ pub fn blank_before_after_function(checker: &mut Checker, docstring: &Docstring) if blank_lines_after != 0 { let mut check = Check::new( - CheckKind::NoBlankLineAfterFunction(blank_lines_after), + violations::NoBlankLineAfterFunction(blank_lines_after), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -248,7 +249,7 @@ pub fn blank_before_after_class(checker: &mut Checker, docstring: &Docstring) { if checker.settings.enabled.contains(&CheckCode::D211) { if blank_lines_before != 0 { let mut check = Check::new( - CheckKind::NoBlankLineBeforeClass(blank_lines_before), + violations::NoBlankLineBeforeClass(blank_lines_before), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -264,7 +265,7 @@ pub fn blank_before_after_class(checker: &mut Checker, docstring: &Docstring) { if checker.settings.enabled.contains(&CheckCode::D203) { if blank_lines_before != 1 { let mut check = Check::new( - CheckKind::OneBlankLineBeforeClass(blank_lines_before), + violations::OneBlankLineBeforeClass(blank_lines_before), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -301,7 +302,7 @@ pub fn blank_before_after_class(checker: &mut Checker, docstring: &Docstring) { .count(); if blank_lines_after != 1 { let mut check = Check::new( - CheckKind::OneBlankLineAfterClass(blank_lines_after), + violations::OneBlankLineAfterClass(blank_lines_after), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -336,7 +337,7 @@ pub fn blank_after_summary(checker: &mut Checker, docstring: &Docstring) { } if lines_count > 1 && blanks_count != 1 { let mut check = Check::new( - CheckKind::BlankLineAfterSummary(blanks_count), + violations::BlankLineAfterSummary(blanks_count), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -405,7 +406,7 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) { && line_indent.len() < docstring.indentation.len() { let mut check = Check::new( - CheckKind::NoUnderIndentation, + violations::NoUnderIndentation, Range::new( Location::new(docstring.expr.location.row() + i, 0), Location::new(docstring.expr.location.row() + i, 0), @@ -440,7 +441,7 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) { if checker.settings.enabled.contains(&CheckCode::D206) { if has_seen_tab { checker.checks.push(Check::new( - CheckKind::IndentWithSpaces, + violations::IndentWithSpaces, Range::from_located(docstring.expr), )); } @@ -455,7 +456,7 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) { // We report over-indentation on every line. This isn't great, but // enables autofix. let mut check = Check::new( - CheckKind::NoOverIndentation, + violations::NoOverIndentation, Range::new( Location::new(docstring.expr.location.row() + i, 0), Location::new(docstring.expr.location.row() + i, 0), @@ -479,7 +480,7 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) { let line_indent = whitespace::leading_space(lines[i]); if line_indent.len() > docstring.indentation.len() { let mut check = Check::new( - CheckKind::NoOverIndentation, + violations::NoOverIndentation, Range::new( Location::new(docstring.expr.location.row() + i, 0), Location::new(docstring.expr.location.row() + i, 0), @@ -512,7 +513,7 @@ pub fn newline_after_last_paragraph(checker: &mut Checker, docstring: &Docstring if let Some(last_line) = contents.lines().last().map(str::trim) { if last_line != "\"\"\"" && last_line != "'''" { let mut check = Check::new( - CheckKind::NewLineAfterLastParagraph, + violations::NewLineAfterLastParagraph, Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -551,7 +552,7 @@ pub fn no_surrounding_whitespace(checker: &mut Checker, docstring: &Docstring) { return; } let mut check = Check::new( - CheckKind::NoSurroundingWhitespace, + violations::NoSurroundingWhitespace, Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -596,14 +597,14 @@ pub fn multi_line_summary_start(checker: &mut Checker, docstring: &Docstring) { if constants::TRIPLE_QUOTE_PREFIXES.contains(&first_line) { if checker.settings.enabled.contains(&CheckCode::D212) { checker.checks.push(Check::new( - CheckKind::MultiLineSummaryFirstLine, + violations::MultiLineSummaryFirstLine, Range::from_located(docstring.expr), )); } } else { if checker.settings.enabled.contains(&CheckCode::D213) { checker.checks.push(Check::new( - CheckKind::MultiLineSummarySecondLine, + violations::MultiLineSummarySecondLine, Range::from_located(docstring.expr), )); } @@ -635,7 +636,7 @@ pub fn triple_quotes(checker: &mut Checker, docstring: &Docstring) { }; if !starts_with_triple { checker.checks.push(Check::new( - CheckKind::UsesTripleQuotes, + violations::UsesTripleQuotes, Range::from_located(docstring.expr), )); } @@ -654,7 +655,7 @@ pub fn backslashes(checker: &mut Checker, docstring: &Docstring) { if BACKSLASH_REGEX.is_match(contents) { checker.checks.push(Check::new( - CheckKind::UsesRPrefixForBackslashedContent, + violations::UsesRPrefixForBackslashedContent, Range::from_located(docstring.expr), )); } @@ -695,8 +696,10 @@ pub fn ends_with_period(checker: &mut Checker, docstring: &Docstring) { let trimmed = line.trim_end(); if !trimmed.ends_with('.') { - let mut check = - Check::new(CheckKind::EndsInPeriod, Range::from_located(docstring.expr)); + let mut check = Check::new( + violations::EndsInPeriod, + Range::from_located(docstring.expr), + ); // Best-effort autofix: avoid adding a period after other punctuation marks. if checker.patch(&CheckCode::D400) && !trimmed.ends_with(':') && !trimmed.ends_with(';') { @@ -745,7 +748,7 @@ pub fn no_signature(checker: &mut Checker, docstring: &Docstring) { return; }; checker.checks.push(Check::new( - CheckKind::NoSignature, + violations::NoSignature, Range::from_located(docstring.expr), )); } @@ -776,7 +779,7 @@ pub fn capitalized(checker: &mut Checker, docstring: &Docstring) { return; }; checker.checks.push(Check::new( - CheckKind::FirstLineCapitalized, + violations::FirstLineCapitalized, Range::from_located(docstring.expr), )); } @@ -801,7 +804,7 @@ pub fn starts_with_this(checker: &mut Checker, docstring: &Docstring) { return; } checker.checks.push(Check::new( - CheckKind::NoThisPrefix, + violations::NoThisPrefix, Range::from_located(docstring.expr), )); } @@ -841,7 +844,7 @@ pub fn ends_with_punctuation(checker: &mut Checker, docstring: &Docstring) { let trimmed = line.trim_end(); if !(trimmed.ends_with('.') || trimmed.ends_with('!') || trimmed.ends_with('?')) { let mut check = Check::new( - CheckKind::EndsInPunctuation, + violations::EndsInPunctuation, Range::from_located(docstring.expr), ); // Best-effort autofix: avoid adding a period after other punctuation marks. @@ -883,7 +886,7 @@ pub fn if_needed(checker: &mut Checker, docstring: &Docstring) { return; } checker.checks.push(Check::new( - CheckKind::SkipDocstring, + violations::SkipDocstring, identifier_range(stmt, checker.locator), )); } @@ -896,7 +899,7 @@ pub fn not_empty(checker: &mut Checker, docstring: &Docstring) -> bool { if checker.settings.enabled.contains(&CheckCode::D419) { checker.checks.push(Check::new( - CheckKind::NonEmpty, + violations::NonEmpty, Range::from_located(docstring.expr), )); } @@ -959,7 +962,7 @@ fn blanks_and_section_underline( if blank_lines_after_header == context.following_lines.len() { if checker.settings.enabled.contains(&CheckCode::D407) { let mut check = Check::new( - CheckKind::DashedUnderlineAfterSection(context.section_name.to_string()), + violations::DashedUnderlineAfterSection(context.section_name.to_string()), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -981,7 +984,7 @@ fn blanks_and_section_underline( } if checker.settings.enabled.contains(&CheckCode::D414) { checker.checks.push(Check::new( - CheckKind::NonEmptySection(context.section_name.to_string()), + violations::NonEmptySection(context.section_name.to_string()), Range::from_located(docstring.expr), )); } @@ -997,7 +1000,7 @@ fn blanks_and_section_underline( if blank_lines_after_header > 0 { if checker.settings.enabled.contains(&CheckCode::D408) { let mut check = Check::new( - CheckKind::SectionUnderlineAfterName(context.section_name.to_string()), + violations::SectionUnderlineAfterName(context.section_name.to_string()), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -1029,7 +1032,7 @@ fn blanks_and_section_underline( { if checker.settings.enabled.contains(&CheckCode::D409) { let mut check = Check::new( - CheckKind::SectionUnderlineMatchesSectionLength( + violations::SectionUnderlineMatchesSectionLength( context.section_name.to_string(), ), Range::from_located(docstring.expr), @@ -1068,7 +1071,7 @@ fn blanks_and_section_underline( let leading_space = whitespace::leading_space(non_empty_line); if leading_space.len() > docstring.indentation.len() { let mut check = Check::new( - CheckKind::SectionUnderlineNotOverIndented(context.section_name.to_string()), + violations::SectionUnderlineNotOverIndented(context.section_name.to_string()), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -1108,14 +1111,14 @@ fn blanks_and_section_underline( if blank_lines_after_dashes == rest_of_lines.len() { if checker.settings.enabled.contains(&CheckCode::D414) { checker.checks.push(Check::new( - CheckKind::NonEmptySection(context.section_name.to_string()), + violations::NonEmptySection(context.section_name.to_string()), Range::from_located(docstring.expr), )); } } else { if checker.settings.enabled.contains(&CheckCode::D412) { let mut check = Check::new( - CheckKind::NoBlankLinesBetweenHeaderAndContent( + violations::NoBlankLinesBetweenHeaderAndContent( context.section_name.to_string(), ), Range::from_located(docstring.expr), @@ -1147,7 +1150,7 @@ fn blanks_and_section_underline( } else { if checker.settings.enabled.contains(&CheckCode::D414) { checker.checks.push(Check::new( - CheckKind::NonEmptySection(context.section_name.to_string()), + violations::NonEmptySection(context.section_name.to_string()), Range::from_located(docstring.expr), )); } @@ -1155,7 +1158,7 @@ fn blanks_and_section_underline( } else { if checker.settings.enabled.contains(&CheckCode::D407) { let mut check = Check::new( - CheckKind::DashedUnderlineAfterSection(context.section_name.to_string()), + violations::DashedUnderlineAfterSection(context.section_name.to_string()), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -1178,7 +1181,7 @@ fn blanks_and_section_underline( if blank_lines_after_header > 0 { if checker.settings.enabled.contains(&CheckCode::D412) { let mut check = Check::new( - CheckKind::NoBlankLinesBetweenHeaderAndContent( + violations::NoBlankLinesBetweenHeaderAndContent( context.section_name.to_string(), ), Range::from_located(docstring.expr), @@ -1219,7 +1222,7 @@ fn common_section( .contains(capitalized_section_name.as_str()) { let mut check = Check::new( - CheckKind::CapitalizeSectionName(context.section_name.to_string()), + violations::CapitalizeSectionName(context.section_name.to_string()), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -1251,7 +1254,7 @@ fn common_section( let leading_space = whitespace::leading_space(context.line); if leading_space.len() > docstring.indentation.len() { let mut check = Check::new( - CheckKind::SectionNotOverIndented(context.section_name.to_string()), + violations::SectionNotOverIndented(context.section_name.to_string()), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -1277,7 +1280,7 @@ fn common_section( if context.is_last_section { if checker.settings.enabled.contains(&CheckCode::D413) { let mut check = Check::new( - CheckKind::BlankLineAfterLastSection(context.section_name.to_string()), + violations::BlankLineAfterLastSection(context.section_name.to_string()), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -1298,7 +1301,7 @@ fn common_section( } else { if checker.settings.enabled.contains(&CheckCode::D410) { let mut check = Check::new( - CheckKind::BlankLineAfterSection(context.section_name.to_string()), + violations::BlankLineAfterSection(context.section_name.to_string()), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -1322,7 +1325,7 @@ fn common_section( if checker.settings.enabled.contains(&CheckCode::D411) { if !context.previous_line.is_empty() { let mut check = Check::new( - CheckKind::BlankLineBeforeSection(context.section_name.to_string()), + violations::BlankLineBeforeSection(context.section_name.to_string()), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -1405,7 +1408,7 @@ fn missing_args(checker: &mut Checker, docstring: &Docstring, docstrings_args: & if !missing_arg_names.is_empty() { let names = missing_arg_names.into_iter().sorted().collect(); checker.checks.push(Check::new( - CheckKind::DocumentAllArguments(names), + violations::DocumentAllArguments(names), Range::from_located(parent), )); } @@ -1511,7 +1514,7 @@ fn numpy_section(checker: &mut Checker, docstring: &Docstring, context: &Section .unwrap(); if !suffix.is_empty() { let mut check = Check::new( - CheckKind::NewLineAfterSectionName(context.section_name.to_string()), + violations::NewLineAfterSectionName(context.section_name.to_string()), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { @@ -1557,7 +1560,7 @@ fn google_section(checker: &mut Checker, docstring: &Docstring, context: &Sectio .unwrap(); if suffix != ":" { let mut check = Check::new( - CheckKind::SectionNameEndsInColon(context.section_name.to_string()), + violations::SectionNameEndsInColon(context.section_name.to_string()), Range::from_located(docstring.expr), ); if checker.patch(check.kind.code()) { diff --git a/src/pydocstyle/settings.rs b/src/pydocstyle/settings.rs index e679c75203..d53601833d 100644 --- a/src/pydocstyle/settings.rs +++ b/src/pydocstyle/settings.rs @@ -5,6 +5,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use crate::registry::CheckCodePrefix; +use crate::violations; #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash, JsonSchema)] #[serde(deny_unknown_fields, rename_all = "kebab-case")] diff --git a/src/pyflakes/checks.rs b/src/pyflakes/checks.rs index 876aa7e680..e1458e7457 100644 --- a/src/pyflakes/checks.rs +++ b/src/pyflakes/checks.rs @@ -8,12 +8,13 @@ use crate::ast::helpers::except_range; use crate::ast::types::{Binding, Range, Scope, ScopeKind}; use crate::registry::{Check, CheckKind}; use crate::source_code_locator::SourceCodeLocator; +use crate::violations; /// F631 pub fn assert_tuple(test: &Expr, location: Range) -> Option { if let ExprKind::Tuple { elts, .. } = &test.node { if !elts.is_empty() { - return Some(Check::new(CheckKind::AssertTuple, location)); + return Some(Check::new(violations::AssertTuple, location)); } } None @@ -23,7 +24,7 @@ pub fn assert_tuple(test: &Expr, location: Range) -> Option { pub fn if_tuple(test: &Expr, location: Range) -> Option { if let ExprKind::Tuple { elts, .. } = &test.node { if !elts.is_empty() { - return Some(Check::new(CheckKind::IfTuple, location)); + return Some(Check::new(violations::IfTuple, location)); } } None @@ -39,7 +40,7 @@ pub fn undefined_local(name: &str, scopes: &[&Scope], bindings: &[Binding]) -> O if let Some((scope_id, location)) = binding.used { if scope_id == current.id { return Some(Check::new( - CheckKind::UndefinedLocal(name.to_string()), + violations::UndefinedLocal(name.to_string()), location, )); } @@ -60,7 +61,7 @@ pub fn default_except_not_last( let ExcepthandlerKind::ExceptHandler { type_, .. } = &handler.node; if type_.is_none() && idx < handlers.len() - 1 { return Some(Check::new( - CheckKind::DefaultExceptNotLast, + violations::DefaultExceptNotLast, except_range(handler, locator), )); } @@ -101,7 +102,7 @@ pub fn repeated_keys( (Some(DictionaryKey::Constant(v1)), Some(DictionaryKey::Constant(v2))) => { if check_repeated_literals && v1 == v2 { checks.push(Check::new( - CheckKind::MultiValueRepeatedKeyLiteral, + violations::MultiValueRepeatedKeyLiteral, Range::from_located(k2), )); } @@ -109,7 +110,7 @@ pub fn repeated_keys( (Some(DictionaryKey::Variable(v1)), Some(DictionaryKey::Variable(v2))) => { if check_repeated_variables && v1 == v2 { checks.push(Check::new( - CheckKind::MultiValueRepeatedKeyVariable((*v2).to_string()), + violations::MultiValueRepeatedKeyVariable((*v2).to_string()), Range::from_located(k2), )); } @@ -134,7 +135,7 @@ pub fn starred_expressions( for (index, elt) in elts.iter().enumerate() { if matches!(elt.node, ExprKind::Starred { .. }) { if has_starred && check_two_starred_expressions { - return Some(Check::new(CheckKind::TwoStarredExpressions, location)); + return Some(Check::new(violations::TwoStarredExpressions, location)); } has_starred = true; starred_index = Some(index); @@ -144,7 +145,10 @@ pub fn starred_expressions( if check_too_many_expressions { if let Some(starred_index) = starred_index { if starred_index >= 1 << 8 || elts.len() - starred_index > 1 << 24 { - return Some(Check::new(CheckKind::ExpressionsInStarAssignment, location)); + return Some(Check::new( + violations::ExpressionsInStarAssignment, + location, + )); } } } @@ -183,7 +187,7 @@ pub fn break_outside_loop<'a>( None } else { Some(Check::new( - CheckKind::BreakOutsideLoop, + violations::BreakOutsideLoop, Range::from_located(stmt), )) } @@ -220,7 +224,7 @@ pub fn continue_outside_loop<'a>( None } else { Some(Check::new( - CheckKind::ContinueOutsideLoop, + violations::ContinueOutsideLoop, Range::from_located(stmt), )) } diff --git a/src/pyflakes/mod.rs b/src/pyflakes/mod.rs index 799b2ec477..92140ae7b7 100644 --- a/src/pyflakes/mod.rs +++ b/src/pyflakes/mod.rs @@ -20,7 +20,7 @@ mod tests { use crate::settings::flags; use crate::source_code_locator::SourceCodeLocator; use crate::source_code_style::SourceCodeStyleDetector; - use crate::{directives, rustpython_helpers, settings}; + use crate::{directives, rustpython_helpers, settings, violations}; #[test_case(CheckCode::F401, Path::new("F401_0.py"); "F401_0")] #[test_case(CheckCode::F401, Path::new("F401_1.py"); "F401_1")] diff --git a/src/pyflakes/plugins/f_string_missing_placeholders.rs b/src/pyflakes/plugins/f_string_missing_placeholders.rs index 548c5f3c79..9ce73e7200 100644 --- a/src/pyflakes/plugins/f_string_missing_placeholders.rs +++ b/src/pyflakes/plugins/f_string_missing_placeholders.rs @@ -4,6 +4,7 @@ use crate::ast::helpers::find_useless_f_strings; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; +use crate::violations; /// F541 pub fn f_string_missing_placeholders(expr: &Expr, values: &[Expr], checker: &mut Checker) { @@ -12,7 +13,7 @@ pub fn f_string_missing_placeholders(expr: &Expr, values: &[Expr], checker: &mut .any(|value| matches!(value.node, ExprKind::FormattedValue { .. })) { for (prefix_range, tok_range) in find_useless_f_strings(expr, checker.locator) { - let mut check = Check::new(CheckKind::FStringMissingPlaceholders, tok_range); + let mut check = Check::new(violations::FStringMissingPlaceholders, tok_range); if checker.patch(&CheckCode::F541) { check.amend(Fix::deletion( prefix_range.location, diff --git a/src/pyflakes/plugins/invalid_literal_comparisons.rs b/src/pyflakes/plugins/invalid_literal_comparisons.rs index 43d8b40b8f..e0dcdc4615 100644 --- a/src/pyflakes/plugins/invalid_literal_comparisons.rs +++ b/src/pyflakes/plugins/invalid_literal_comparisons.rs @@ -8,6 +8,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// F632 pub fn invalid_literal_comparison( @@ -24,7 +25,7 @@ pub fn invalid_literal_comparison( && (helpers::is_constant_non_singleton(left) || helpers::is_constant_non_singleton(right)) { - let mut check = Check::new(CheckKind::IsLiteral(op.into()), location); + let mut check = Check::new(violations::IsLiteral(op.into()), location); if checker.patch(check.kind.code()) { if let Some(located_op) = &located.get(index) { assert_eq!(&located_op.node, op); diff --git a/src/pyflakes/plugins/invalid_print_syntax.rs b/src/pyflakes/plugins/invalid_print_syntax.rs index bbc9fdf66f..ec84fe6558 100644 --- a/src/pyflakes/plugins/invalid_print_syntax.rs +++ b/src/pyflakes/plugins/invalid_print_syntax.rs @@ -3,6 +3,7 @@ use rustpython_ast::{Expr, ExprKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// F633 pub fn invalid_print_syntax(checker: &mut Checker, left: &Expr) { @@ -16,7 +17,7 @@ pub fn invalid_print_syntax(checker: &mut Checker, left: &Expr) { return; }; checker.checks.push(Check::new( - CheckKind::InvalidPrintSyntax, + violations::InvalidPrintSyntax, Range::from_located(left), )); } diff --git a/src/pyflakes/plugins/raise_not_implemented.rs b/src/pyflakes/plugins/raise_not_implemented.rs index 41dde74a0c..4ad41e529a 100644 --- a/src/pyflakes/plugins/raise_not_implemented.rs +++ b/src/pyflakes/plugins/raise_not_implemented.rs @@ -4,6 +4,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; fn match_not_implemented(expr: &Expr) -> Option<&Expr> { match &expr.node { @@ -29,7 +30,7 @@ pub fn raise_not_implemented(checker: &mut Checker, expr: &Expr) { let Some(expr) = match_not_implemented(expr) else { return; }; - let mut check = Check::new(CheckKind::RaiseNotImplemented, Range::from_located(expr)); + let mut check = Check::new(violations::RaiseNotImplemented, Range::from_located(expr)); if checker.patch(check.kind.code()) { check.amend(Fix::replacement( "NotImplementedError".to_string(), diff --git a/src/pyflakes/plugins/strings.rs b/src/pyflakes/plugins/strings.rs index 28c5b6dc24..e2805cd071 100644 --- a/src/pyflakes/plugins/strings.rs +++ b/src/pyflakes/plugins/strings.rs @@ -13,6 +13,7 @@ use crate::pyflakes::fixes::{ }; use crate::pyflakes::format::FormatSummary; use crate::registry::{Check, CheckKind}; +use crate::violations; fn has_star_star_kwargs(keywords: &[Keyword]) -> bool { keywords.iter().any(|k| { @@ -42,7 +43,7 @@ pub(crate) fn percent_format_expected_mapping( | ExprKind::ListComp { .. } | ExprKind::SetComp { .. } | ExprKind::GeneratorExp { .. } => checker.checks.push(Check::new( - CheckKind::PercentFormatExpectedMapping, + violations::PercentFormatExpectedMapping, location, )), _ => {} @@ -64,7 +65,7 @@ pub(crate) fn percent_format_expected_sequence( ) { checker.checks.push(Check::new( - CheckKind::PercentFormatExpectedSequence, + violations::PercentFormatExpectedSequence, location, )); } @@ -110,7 +111,7 @@ pub(crate) fn percent_format_extra_named_arguments( } let mut check = Check::new( - CheckKind::PercentFormatExtraNamedArguments( + violations::PercentFormatExtraNamedArguments( missing.iter().map(|&arg| arg.to_string()).collect(), ), location, @@ -165,7 +166,7 @@ pub(crate) fn percent_format_missing_arguments( if !missing.is_empty() { checker.checks.push(Check::new( - CheckKind::PercentFormatMissingArgument( + violations::PercentFormatMissingArgument( missing.iter().map(|&s| s.clone()).collect(), ), location, @@ -182,7 +183,7 @@ pub(crate) fn percent_format_mixed_positional_and_named( ) { if !(summary.num_positional == 0 || summary.keywords.is_empty()) { checker.checks.push(Check::new( - CheckKind::PercentFormatMixedPositionalAndNamed, + violations::PercentFormatMixedPositionalAndNamed, location, )); } @@ -211,7 +212,7 @@ pub(crate) fn percent_format_positional_count_mismatch( if found != summary.num_positional { checker.checks.push(Check::new( - CheckKind::PercentFormatPositionalCountMismatch(summary.num_positional, found), + violations::PercentFormatPositionalCountMismatch(summary.num_positional, found), location, )); } @@ -230,7 +231,7 @@ pub(crate) fn percent_format_star_requires_sequence( if summary.starred { match &right.node { ExprKind::Dict { .. } | ExprKind::DictComp { .. } => checker.checks.push(Check::new( - CheckKind::PercentFormatStarRequiresSequence, + violations::PercentFormatStarRequiresSequence, location, )), _ => {} @@ -269,7 +270,7 @@ pub(crate) fn string_dot_format_extra_named_arguments( } let mut check = Check::new( - CheckKind::StringDotFormatExtraNamedArguments( + violations::StringDotFormatExtraNamedArguments( missing.iter().map(|&arg| arg.to_string()).collect(), ), location, @@ -306,7 +307,7 @@ pub(crate) fn string_dot_format_extra_positional_arguments( } checker.checks.push(Check::new( - CheckKind::StringDotFormatExtraPositionalArguments( + violations::StringDotFormatExtraPositionalArguments( missing .iter() .map(std::string::ToString::to_string) @@ -353,7 +354,7 @@ pub(crate) fn string_dot_format_missing_argument( if !missing.is_empty() { checker.checks.push(Check::new( - CheckKind::StringDotFormatMissingArguments(missing), + violations::StringDotFormatMissingArguments(missing), location, )); } @@ -367,7 +368,7 @@ pub(crate) fn string_dot_format_mixing_automatic( ) { if !(summary.autos.is_empty() || summary.indexes.is_empty()) { checker.checks.push(Check::new( - CheckKind::StringDotFormatMixingAutomatic, + violations::StringDotFormatMixingAutomatic, location, )); } diff --git a/src/pyflakes/plugins/unused_annotation.rs b/src/pyflakes/plugins/unused_annotation.rs index 9c5dc263f0..4944b5910c 100644 --- a/src/pyflakes/plugins/unused_annotation.rs +++ b/src/pyflakes/plugins/unused_annotation.rs @@ -1,6 +1,7 @@ use crate::ast::types::BindingKind; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// F842 pub fn unused_annotation(checker: &mut Checker, scope: usize) { @@ -15,7 +16,7 @@ pub fn unused_annotation(checker: &mut Checker, scope: usize) { && !checker.settings.dummy_variable_rgx.is_match(name) { checker.checks.push(Check::new( - CheckKind::UnusedAnnotation((*name).to_string()), + violations::UnusedAnnotation((*name).to_string()), binding.range, )); } diff --git a/src/pyflakes/plugins/unused_variable.rs b/src/pyflakes/plugins/unused_variable.rs index 8671b71d53..78f827c1e6 100644 --- a/src/pyflakes/plugins/unused_variable.rs +++ b/src/pyflakes/plugins/unused_variable.rs @@ -6,6 +6,7 @@ use crate::autofix::helpers::delete_stmt; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; +use crate::violations; fn is_literal_or_name(expr: &Expr, checker: &Checker) -> bool { // Accept any obvious literals or names. @@ -169,7 +170,7 @@ pub fn unused_variable(checker: &mut Checker, scope: usize) { && name != &"__traceback_supplement__" { let mut check = Check::new( - CheckKind::UnusedVariable((*name).to_string()), + violations::UnusedVariable((*name).to_string()), binding.range, ); if checker.patch(&CheckCode::F841) { diff --git a/src/pygrep_hooks/mod.rs b/src/pygrep_hooks/mod.rs index c20b69997b..6a901da183 100644 --- a/src/pygrep_hooks/mod.rs +++ b/src/pygrep_hooks/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::PGH001, Path::new("PGH001_0.py"); "PGH001_0")] #[test_case(CheckCode::PGH001, Path::new("PGH001_1.py"); "PGH001_1")] diff --git a/src/pygrep_hooks/plugins/blanket_noqa.rs b/src/pygrep_hooks/plugins/blanket_noqa.rs index d1f46fa2e8..6effb8a65b 100644 --- a/src/pygrep_hooks/plugins/blanket_noqa.rs +++ b/src/pygrep_hooks/plugins/blanket_noqa.rs @@ -4,6 +4,7 @@ use rustpython_ast::Location; use crate::ast::types::Range; use crate::registry::{Check, CheckKind}; +use crate::violations; static BLANKET_NOQA_REGEX: Lazy = Lazy::new(|| Regex::new(r"(?i)# noqa($|\s|:[^ ])").unwrap()); @@ -12,7 +13,7 @@ static BLANKET_NOQA_REGEX: Lazy = pub fn blanket_noqa(lineno: usize, line: &str) -> Option { BLANKET_NOQA_REGEX.find(line).map(|m| { Check::new( - CheckKind::BlanketNOQA, + violations::BlanketNOQA, Range::new( Location::new(lineno + 1, m.start()), Location::new(lineno + 1, m.end()), diff --git a/src/pygrep_hooks/plugins/blanket_type_ignore.rs b/src/pygrep_hooks/plugins/blanket_type_ignore.rs index da47ca1905..fa3fc8ac90 100644 --- a/src/pygrep_hooks/plugins/blanket_type_ignore.rs +++ b/src/pygrep_hooks/plugins/blanket_type_ignore.rs @@ -4,6 +4,7 @@ use rustpython_ast::Location; use crate::ast::types::Range; use crate::registry::{Check, CheckKind}; +use crate::violations; static BLANKET_TYPE_IGNORE_REGEX: Lazy = Lazy::new(|| Regex::new(r"# type:? *ignore($|\s)").unwrap()); @@ -12,7 +13,7 @@ static BLANKET_TYPE_IGNORE_REGEX: Lazy = pub fn blanket_type_ignore(lineno: usize, line: &str) -> Option { BLANKET_TYPE_IGNORE_REGEX.find(line).map(|m| { Check::new( - CheckKind::BlanketTypeIgnore, + violations::BlanketTypeIgnore, Range::new( Location::new(lineno + 1, m.start()), Location::new(lineno + 1, m.end()), diff --git a/src/pygrep_hooks/plugins/deprecated_log_warn.rs b/src/pygrep_hooks/plugins/deprecated_log_warn.rs index 97641dc975..1eade04fe1 100644 --- a/src/pygrep_hooks/plugins/deprecated_log_warn.rs +++ b/src/pygrep_hooks/plugins/deprecated_log_warn.rs @@ -4,6 +4,7 @@ use crate::ast::helpers::{collect_call_paths, dealias_call_path, match_call_path use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// PGH002 - deprecated use of logging.warn pub fn deprecated_log_warn(checker: &mut Checker, func: &Expr) { @@ -12,7 +13,7 @@ pub fn deprecated_log_warn(checker: &mut Checker, func: &Expr) { || match_call_path(&call_path, "logging", "warn", &checker.from_imports) { checker.checks.push(Check::new( - CheckKind::DeprecatedLogWarn, + violations::DeprecatedLogWarn, Range::from_located(func), )); } diff --git a/src/pygrep_hooks/plugins/no_eval.rs b/src/pygrep_hooks/plugins/no_eval.rs index d734d23047..90c691a68c 100644 --- a/src/pygrep_hooks/plugins/no_eval.rs +++ b/src/pygrep_hooks/plugins/no_eval.rs @@ -3,6 +3,7 @@ use rustpython_ast::{Expr, ExprKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// PGH001 - no eval pub fn no_eval(checker: &mut Checker, func: &Expr) { @@ -17,5 +18,5 @@ pub fn no_eval(checker: &mut Checker, func: &Expr) { } checker .checks - .push(Check::new(CheckKind::NoEval, Range::from_located(func))); + .push(Check::new(violations::NoEval, Range::from_located(func))); } diff --git a/src/pylint/mod.rs b/src/pylint/mod.rs index 13ab36b81b..01d3144dd9 100644 --- a/src/pylint/mod.rs +++ b/src/pylint/mod.rs @@ -9,7 +9,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::Settings; + use crate::{violations, Settings}; #[test_case(CheckCode::PLC0414, Path::new("import_aliasing.py"); "PLC0414")] #[test_case(CheckCode::PLC2201, Path::new("misplaced_comparison_constant.py"); "PLC2201")] diff --git a/src/pylint/plugins/await_outside_async.rs b/src/pylint/plugins/await_outside_async.rs index 580e8c8b6e..b362ee6567 100644 --- a/src/pylint/plugins/await_outside_async.rs +++ b/src/pylint/plugins/await_outside_async.rs @@ -3,7 +3,7 @@ use rustpython_ast::Expr; use crate::ast::types::{FunctionDef, Range, ScopeKind}; use crate::checkers::ast::Checker; use crate::registry::CheckKind; -use crate::Check; +use crate::{violations, Check}; /// PLE1142 pub fn await_outside_async(checker: &mut Checker, expr: &Expr) { @@ -19,7 +19,7 @@ pub fn await_outside_async(checker: &mut Checker, expr: &Expr) { .unwrap_or(true) { checker.checks.push(Check::new( - CheckKind::AwaitOutsideAsync, + violations::AwaitOutsideAsync, Range::from_located(expr), )); } diff --git a/src/pylint/plugins/merge_isinstance.rs b/src/pylint/plugins/merge_isinstance.rs index eda2887a28..b2f5b21c3a 100644 --- a/src/pylint/plugins/merge_isinstance.rs +++ b/src/pylint/plugins/merge_isinstance.rs @@ -5,7 +5,7 @@ use rustpython_ast::{Boolop, Expr, ExprKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::CheckKind; -use crate::Check; +use crate::{violations, Check}; /// PLR1701 pub fn merge_isinstance(checker: &mut Checker, expr: &Expr, op: &Boolop, values: &[Expr]) { @@ -42,7 +42,7 @@ pub fn merge_isinstance(checker: &mut Checker, expr: &Expr, op: &Boolop, values: for (obj, (num_calls, types)) in obj_to_types { if num_calls > 1 && types.len() > 1 { checker.checks.push(Check::new( - CheckKind::ConsiderMergingIsinstance(obj, types.into_iter().sorted().collect()), + violations::ConsiderMergingIsinstance(obj, types.into_iter().sorted().collect()), Range::from_located(expr), )); } diff --git a/src/pylint/plugins/misplaced_comparison_constant.rs b/src/pylint/plugins/misplaced_comparison_constant.rs index 56d3dafd30..711e0c4dbc 100644 --- a/src/pylint/plugins/misplaced_comparison_constant.rs +++ b/src/pylint/plugins/misplaced_comparison_constant.rs @@ -4,7 +4,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::CheckKind; -use crate::Check; +use crate::{violations, Check}; /// PLC2201 pub fn misplaced_comparison_constant( @@ -42,7 +42,7 @@ pub fn misplaced_comparison_constant( }; let suggestion = format!("{right} {reversed_op} {left}"); let mut check = Check::new( - CheckKind::MisplacedComparisonConstant(suggestion.clone()), + violations::MisplacedComparisonConstant(suggestion.clone()), Range::from_located(expr), ); if checker.patch(check.kind.code()) { diff --git a/src/pylint/plugins/property_with_parameters.rs b/src/pylint/plugins/property_with_parameters.rs index 9b121af878..a427c797e1 100644 --- a/src/pylint/plugins/property_with_parameters.rs +++ b/src/pylint/plugins/property_with_parameters.rs @@ -3,7 +3,7 @@ use rustpython_ast::{Arguments, Expr, ExprKind, Stmt}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::CheckKind; -use crate::Check; +use crate::{violations, Check}; /// PLR0206 pub fn property_with_parameters( @@ -28,7 +28,7 @@ pub fn property_with_parameters( > 1 { checker.checks.push(Check::new( - CheckKind::PropertyWithParameters, + violations::PropertyWithParameters, Range::from_located(stmt), )); } diff --git a/src/pylint/plugins/unnecessary_direct_lambda_call.rs b/src/pylint/plugins/unnecessary_direct_lambda_call.rs index 1d56dcabe6..174a70dbbf 100644 --- a/src/pylint/plugins/unnecessary_direct_lambda_call.rs +++ b/src/pylint/plugins/unnecessary_direct_lambda_call.rs @@ -3,13 +3,13 @@ use rustpython_ast::{Expr, ExprKind}; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::CheckKind; -use crate::Check; +use crate::{violations, Check}; /// PLC3002 pub fn unnecessary_direct_lambda_call(checker: &mut Checker, expr: &Expr, func: &Expr) { if let ExprKind::Lambda { .. } = &func.node { checker.checks.push(Check::new( - CheckKind::UnnecessaryDirectLambdaCall, + violations::UnnecessaryDirectLambdaCall, Range::from_located(expr), )); } diff --git a/src/pylint/plugins/use_from_import.rs b/src/pylint/plugins/use_from_import.rs index 31f96f010a..fd62fbaa3d 100644 --- a/src/pylint/plugins/use_from_import.rs +++ b/src/pylint/plugins/use_from_import.rs @@ -3,7 +3,7 @@ use rustpython_ast::Alias; use crate::ast::types::Range; use crate::checkers::ast::Checker; use crate::registry::CheckKind; -use crate::Check; +use crate::{violations, Check}; /// PLR0402 pub fn use_from_import(checker: &mut Checker, alias: &Alias) { @@ -17,7 +17,7 @@ pub fn use_from_import(checker: &mut Checker, alias: &Alias) { return; } checker.checks.push(Check::new( - CheckKind::ConsiderUsingFromImport(module.to_string(), name.to_string()), + violations::ConsiderUsingFromImport(module.to_string(), name.to_string()), Range::from_located(alias), )); } diff --git a/src/pylint/plugins/use_sys_exit.rs b/src/pylint/plugins/use_sys_exit.rs index 56d96b3ca1..a0d5686fd5 100644 --- a/src/pylint/plugins/use_sys_exit.rs +++ b/src/pylint/plugins/use_sys_exit.rs @@ -4,6 +4,7 @@ use crate::ast::types::{BindingKind, Range}; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// Return `true` if the `module` was imported using a star import (e.g., `from /// sys import *`). @@ -75,7 +76,7 @@ pub fn use_sys_exit(checker: &mut Checker, func: &Expr) { continue; } let mut check = Check::new( - CheckKind::UseSysExit(name.to_string()), + violations::UseSysExit(name.to_string()), Range::from_located(func), ); if checker.patch(check.kind.code()) { diff --git a/src/pylint/plugins/used_prior_global_declaration.rs b/src/pylint/plugins/used_prior_global_declaration.rs index 958f46f089..66691054f7 100644 --- a/src/pylint/plugins/used_prior_global_declaration.rs +++ b/src/pylint/plugins/used_prior_global_declaration.rs @@ -3,7 +3,7 @@ use rustpython_ast::Expr; use crate::ast::types::{Range, ScopeKind}; use crate::checkers::ast::Checker; use crate::registry::CheckKind; -use crate::Check; +use crate::{violations, Check}; /// PLE0118 pub fn used_prior_global_declaration(checker: &mut Checker, name: &str, expr: &Expr) { @@ -15,7 +15,7 @@ pub fn used_prior_global_declaration(checker: &mut Checker, name: &str, expr: &E if let Some(stmt) = globals.get(name) { if expr.location < stmt.location { checker.checks.push(Check::new( - CheckKind::UsedPriorGlobalDeclaration(name.to_string(), stmt.location.row()), + violations::UsedPriorGlobalDeclaration(name.to_string(), stmt.location.row()), Range::from_located(expr), )); } diff --git a/src/pylint/plugins/useless_else_on_loop.rs b/src/pylint/plugins/useless_else_on_loop.rs index bdf5094249..564ad472cc 100644 --- a/src/pylint/plugins/useless_else_on_loop.rs +++ b/src/pylint/plugins/useless_else_on_loop.rs @@ -3,7 +3,7 @@ use rustpython_ast::{ExcepthandlerKind, Stmt, StmtKind}; use crate::ast::helpers; use crate::checkers::ast::Checker; use crate::registry::CheckKind; -use crate::Check; +use crate::{violations, Check}; fn loop_exits_early(body: &[Stmt]) -> bool { body.iter().any(|stmt| match &stmt.node { @@ -34,7 +34,7 @@ fn loop_exits_early(body: &[Stmt]) -> bool { pub fn useless_else_on_loop(checker: &mut Checker, stmt: &Stmt, body: &[Stmt], orelse: &[Stmt]) { if !orelse.is_empty() && !loop_exits_early(body) { checker.checks.push(Check::new( - CheckKind::UselessElseOnLoop, + violations::UselessElseOnLoop, helpers::else_range(stmt, checker.locator).unwrap(), )); } diff --git a/src/pylint/plugins/useless_import_alias.rs b/src/pylint/plugins/useless_import_alias.rs index 0b4b7111e1..008bc61f23 100644 --- a/src/pylint/plugins/useless_import_alias.rs +++ b/src/pylint/plugins/useless_import_alias.rs @@ -4,7 +4,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::CheckKind; -use crate::Check; +use crate::{violations, Check}; /// PLC0414 pub fn useless_import_alias(checker: &mut Checker, alias: &Alias) { @@ -18,7 +18,7 @@ pub fn useless_import_alias(checker: &mut Checker, alias: &Alias) { return; } - let mut check = Check::new(CheckKind::UselessImportAlias, Range::from_located(alias)); + let mut check = Check::new(violations::UselessImportAlias, Range::from_located(alias)); if checker.patch(check.kind.code()) { check.amend(Fix::replacement( asname.to_string(), diff --git a/src/pyupgrade/checks.rs b/src/pyupgrade/checks.rs index 9f71d430a2..af825564d9 100644 --- a/src/pyupgrade/checks.rs +++ b/src/pyupgrade/checks.rs @@ -10,6 +10,7 @@ use crate::autofix::Fix; use crate::pyupgrade::types::Primitive; use crate::registry::{Check, CheckKind}; use crate::settings::types::PythonVersion; +use crate::violations; /// UP001 pub fn useless_metaclass_type(targets: &[Expr], value: &Expr, location: Range) -> Option { @@ -28,7 +29,7 @@ pub fn useless_metaclass_type(targets: &[Expr], value: &Expr, location: Range) - if id != "type" { return None; } - Some(Check::new(CheckKind::UselessMetaclassType, location)) + Some(Check::new(violations::UselessMetaclassType, location)) } /// UP003 @@ -50,7 +51,7 @@ pub fn type_of_primitive(func: &Expr, args: &[Expr], location: Range) -> Option< }; let primitive = Primitive::from_constant(value)?; - Some(Check::new(CheckKind::TypeOfPrimitive(primitive), location)) + Some(Check::new(violations::TypeOfPrimitive(primitive), location)) } /// UP004 @@ -80,7 +81,7 @@ pub fn useless_object_inheritance( continue; } return Some(Check::new( - CheckKind::UselessObjectInheritance(name.to_string()), + violations::UselessObjectInheritance(name.to_string()), Range::from_located(expr), )); } @@ -152,7 +153,7 @@ pub fn super_args( if first_arg_id == parent_name && second_arg_id == parent_arg { return Some(Check::new( - CheckKind::SuperCallWithParameters, + violations::SuperCallWithParameters, Range::from_located(expr), )); } @@ -169,7 +170,7 @@ pub fn unnecessary_coding_comment(lineno: usize, line: &str, autofix: bool) -> O // PEP3120 makes utf-8 the default encoding. if CODING_COMMENT_REGEX.is_match(line) { let mut check = Check::new( - CheckKind::PEP3120UnnecessaryCodingComment, + violations::PEP3120UnnecessaryCodingComment, Range::new(Location::new(lineno + 1, 0), Location::new(lineno + 2, 0)), ); if autofix { @@ -216,7 +217,7 @@ pub fn unnecessary_lru_cache_params( let range = Range::new(func.end_location.unwrap(), expr.end_location.unwrap()); // Ex) `functools.lru_cache()` if keywords.is_empty() { - return Some(Check::new(CheckKind::UnnecessaryLRUCacheParams, range)); + return Some(Check::new(violations::UnnecessaryLRUCacheParams, range)); } // Ex) `functools.lru_cache(maxsize=None)` if !(target_version >= PythonVersion::Py39 && keywords.len() == 1) { @@ -235,7 +236,7 @@ pub fn unnecessary_lru_cache_params( { continue; } - return Some(Check::new(CheckKind::UnnecessaryLRUCacheParams, range)); + return Some(Check::new(violations::UnnecessaryLRUCacheParams, range)); } None } diff --git a/src/pyupgrade/mod.rs b/src/pyupgrade/mod.rs index 17d6a422a0..a8aca2f3b5 100644 --- a/src/pyupgrade/mod.rs +++ b/src/pyupgrade/mod.rs @@ -14,8 +14,8 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; use crate::settings::types::PythonVersion; + use crate::{settings, violations}; #[test_case(CheckCode::UP001, Path::new("UP001.py"); "UP001")] #[test_case(CheckCode::UP003, Path::new("UP003.py"); "UP003")] diff --git a/src/pyupgrade/plugins/convert_named_tuple_functional_to_class.rs b/src/pyupgrade/plugins/convert_named_tuple_functional_to_class.rs index 9b37ff856a..b8d1f79952 100644 --- a/src/pyupgrade/plugins/convert_named_tuple_functional_to_class.rs +++ b/src/pyupgrade/plugins/convert_named_tuple_functional_to_class.rs @@ -11,6 +11,7 @@ use crate::python::keyword::KWLIST; use crate::registry::{Check, CheckKind}; use crate::source_code_generator::SourceCodeGenerator; use crate::source_code_style::SourceCodeStyleDetector; +use crate::violations; /// Return the typename, args, keywords and mother class fn match_named_tuple_assign<'a>( @@ -191,7 +192,7 @@ pub fn convert_named_tuple_functional_to_class( Ok(defaults) => match create_properties_from_args(args, defaults) { Ok(properties) => { let mut check = Check::new( - CheckKind::ConvertNamedTupleFunctionalToClass(typename.to_string()), + violations::ConvertNamedTupleFunctionalToClass(typename.to_string()), Range::from_located(stmt), ); if checker.patch(check.kind.code()) { diff --git a/src/pyupgrade/plugins/convert_typed_dict_functional_to_class.rs b/src/pyupgrade/plugins/convert_typed_dict_functional_to_class.rs index ffc37e4ccf..7af6c2c18d 100644 --- a/src/pyupgrade/plugins/convert_typed_dict_functional_to_class.rs +++ b/src/pyupgrade/plugins/convert_typed_dict_functional_to_class.rs @@ -13,6 +13,7 @@ use crate::python::keyword::KWLIST; use crate::registry::{Check, CheckKind}; use crate::source_code_generator::SourceCodeGenerator; use crate::source_code_style::SourceCodeStyleDetector; +use crate::violations; /// Return the class name, arguments, keywords and base class for a `TypedDict` /// assignment. @@ -233,7 +234,7 @@ pub fn convert_typed_dict_functional_to_class( Ok(args) => args, }; let mut check = Check::new( - CheckKind::ConvertTypedDictFunctionalToClass(class_name.to_string()), + violations::ConvertTypedDictFunctionalToClass(class_name.to_string()), Range::from_located(stmt), ); if checker.patch(check.kind.code()) { diff --git a/src/pyupgrade/plugins/datetime_utc_alias.rs b/src/pyupgrade/plugins/datetime_utc_alias.rs index 17fb87de27..1815c782d2 100644 --- a/src/pyupgrade/plugins/datetime_utc_alias.rs +++ b/src/pyupgrade/plugins/datetime_utc_alias.rs @@ -5,12 +5,13 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; +use crate::violations; /// UP017 pub fn datetime_utc_alias(checker: &mut Checker, expr: &Expr) { let dealiased_call_path = dealias_call_path(collect_call_paths(expr), &checker.import_aliases); if dealiased_call_path == ["datetime", "timezone", "utc"] { - let mut check = Check::new(CheckKind::DatetimeTimezoneUTC, Range::from_located(expr)); + let mut check = Check::new(violations::DatetimeTimezoneUTC, Range::from_located(expr)); if checker.patch(&CheckCode::UP017) { check.amend(Fix::replacement( compose_call_path(expr) diff --git a/src/pyupgrade/plugins/deprecated_unittest_alias.rs b/src/pyupgrade/plugins/deprecated_unittest_alias.rs index a1dbfff244..d1c31679f5 100644 --- a/src/pyupgrade/plugins/deprecated_unittest_alias.rs +++ b/src/pyupgrade/plugins/deprecated_unittest_alias.rs @@ -6,6 +6,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; static DEPRECATED_ALIASES: Lazy> = Lazy::new(|| { FxHashMap::from_iter([ @@ -42,7 +43,7 @@ pub fn deprecated_unittest_alias(checker: &mut Checker, expr: &Expr) { return; } let mut check = Check::new( - CheckKind::DeprecatedUnittestAlias(attr.to_string(), target.to_string()), + violations::DeprecatedUnittestAlias(attr.to_string(), target.to_string()), Range::from_located(expr), ); if checker.patch(check.kind.code()) { diff --git a/src/pyupgrade/plugins/native_literals.rs b/src/pyupgrade/plugins/native_literals.rs index bde80e8d86..525bce3c68 100644 --- a/src/pyupgrade/plugins/native_literals.rs +++ b/src/pyupgrade/plugins/native_literals.rs @@ -6,6 +6,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind, LiteralType}; +use crate::violations; /// UP018 pub fn native_literals( @@ -23,7 +24,7 @@ pub fn native_literals( if (id == "str" || id == "bytes") && checker.is_builtin(id) { let Some(arg) = args.get(0) else { - let mut check = Check::new(CheckKind::NativeLiterals(if id == "str" { + let mut check = Check::new(violations::NativeLiterals(if id == "str" { LiteralType::Str } else { LiteralType::Bytes @@ -92,7 +93,7 @@ pub fn native_literals( } let mut check = Check::new( - CheckKind::NativeLiterals(if id == "str" { + violations::NativeLiterals(if id == "str" { LiteralType::Str } else { LiteralType::Bytes diff --git a/src/pyupgrade/plugins/open_alias.rs b/src/pyupgrade/plugins/open_alias.rs index da33289717..d8d89d86e1 100644 --- a/src/pyupgrade/plugins/open_alias.rs +++ b/src/pyupgrade/plugins/open_alias.rs @@ -5,13 +5,14 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; +use crate::violations; /// UP020 pub fn open_alias(checker: &mut Checker, expr: &Expr, func: &Expr) { let call_path = dealias_call_path(collect_call_paths(expr), &checker.import_aliases); if match_call_path(&call_path, "io", "open", &checker.from_imports) { - let mut check = Check::new(CheckKind::OpenAlias, Range::from_located(expr)); + let mut check = Check::new(violations::OpenAlias, Range::from_located(expr)); if checker.patch(&CheckCode::UP020) { check.amend(Fix::replacement( "open".to_string(), diff --git a/src/pyupgrade/plugins/os_error_alias.rs b/src/pyupgrade/plugins/os_error_alias.rs index 2745931711..20a4bc684e 100644 --- a/src/pyupgrade/plugins/os_error_alias.rs +++ b/src/pyupgrade/plugins/os_error_alias.rs @@ -8,6 +8,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; const ERROR_NAMES: &[&str] = &["EnvironmentError", "IOError", "WindowsError"]; const ERROR_MODULES: &[&str] = &["mmap", "select", "socket"]; @@ -157,7 +158,7 @@ fn handle_making_changes( final_str.insert(0, '('); final_str.push(')'); } - let mut check = Check::new(CheckKind::OSErrorAlias(compose_call_path(target)), range); + let mut check = Check::new(violations::OSErrorAlias(compose_call_path(target)), range); if checker.patch(check.kind.code()) { check.amend(Fix::replacement( final_str, diff --git a/src/pyupgrade/plugins/redundant_open_modes.rs b/src/pyupgrade/plugins/redundant_open_modes.rs index 391b8beb51..fa398386ac 100644 --- a/src/pyupgrade/plugins/redundant_open_modes.rs +++ b/src/pyupgrade/plugins/redundant_open_modes.rs @@ -12,6 +12,7 @@ use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; use crate::source_code_locator::SourceCodeLocator; +use crate::violations; const OPEN_FUNC_NAME: &str = "open"; const MODE_KEYWORD_ARGUMENT: &str = "mode"; @@ -80,7 +81,7 @@ fn create_check( patch: bool, ) -> Check { let mut check = Check::new( - CheckKind::RedundantOpenModes(replacement_value.clone()), + violations::RedundantOpenModes(replacement_value.clone()), Range::from_located(expr), ); if patch { diff --git a/src/pyupgrade/plugins/remove_six_compat.rs b/src/pyupgrade/plugins/remove_six_compat.rs index 36fa572a09..84d41394f1 100644 --- a/src/pyupgrade/plugins/remove_six_compat.rs +++ b/src/pyupgrade/plugins/remove_six_compat.rs @@ -7,7 +7,7 @@ use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; use crate::source_code_generator::SourceCodeGenerator; use crate::source_code_style::SourceCodeStyleDetector; -use crate::SourceCodeLocator; +use crate::{violations, SourceCodeLocator}; /// Return `true` if the `Expr` is a reference to `${module}.${any}`. fn is_module_member(call_path: &[&str], module: &str) -> bool { @@ -35,7 +35,7 @@ fn map_name(name: &str, expr: &Expr, patch: bool) -> Option { _ => None, }; if let Some(replacement) = replacement { - let mut check = Check::new(CheckKind::RemoveSixCompat, Range::from_located(expr)); + let mut check = Check::new(violations::RemoveSixCompat, Range::from_located(expr)); if patch { check.amend(Fix::replacement( replacement.to_string(), @@ -58,7 +58,7 @@ fn replace_by_str_literal( ) -> Option { match &arg.node { ExprKind::Constant { .. } => { - let mut check = Check::new(CheckKind::RemoveSixCompat, Range::from_located(expr)); + let mut check = Check::new(violations::RemoveSixCompat, Range::from_located(expr)); if patch { let content = format!( "{}{}", @@ -132,7 +132,7 @@ fn replace_by_expr_kind( patch: bool, stylist: &SourceCodeStyleDetector, ) -> Check { - let mut check = Check::new(CheckKind::RemoveSixCompat, Range::from_located(expr)); + let mut check = Check::new(violations::RemoveSixCompat, Range::from_located(expr)); if patch { let mut generator: SourceCodeGenerator = stylist.into(); generator.unparse_expr(&create_expr(node), 0); @@ -151,7 +151,7 @@ fn replace_by_stmt_kind( patch: bool, stylist: &SourceCodeStyleDetector, ) -> Check { - let mut check = Check::new(CheckKind::RemoveSixCompat, Range::from_located(expr)); + let mut check = Check::new(violations::RemoveSixCompat, Range::from_located(expr)); if patch { let mut generator: SourceCodeGenerator = stylist.into(); generator.unparse_stmt(&create_stmt(node)); diff --git a/src/pyupgrade/plugins/replace_stdout_stderr.rs b/src/pyupgrade/plugins/replace_stdout_stderr.rs index 16a1eed12f..224ea115eb 100644 --- a/src/pyupgrade/plugins/replace_stdout_stderr.rs +++ b/src/pyupgrade/plugins/replace_stdout_stderr.rs @@ -6,6 +6,7 @@ use crate::ast::whitespace::indentation; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; #[derive(Debug)] struct MiddleContent<'a> { @@ -74,7 +75,7 @@ pub fn replace_stdout_stderr(checker: &mut Checker, expr: &Expr, kwargs: &[Keywo return; } - let mut check = Check::new(CheckKind::ReplaceStdoutStderr, Range::from_located(expr)); + let mut check = Check::new(violations::ReplaceStdoutStderr, Range::from_located(expr)); if checker.patch(check.kind.code()) { let first = if stdout.location < stderr.location { stdout diff --git a/src/pyupgrade/plugins/replace_universal_newlines.rs b/src/pyupgrade/plugins/replace_universal_newlines.rs index 697246b780..63ab1357a8 100644 --- a/src/pyupgrade/plugins/replace_universal_newlines.rs +++ b/src/pyupgrade/plugins/replace_universal_newlines.rs @@ -5,6 +5,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// UP021 pub fn replace_universal_newlines(checker: &mut Checker, expr: &Expr, kwargs: &[Keyword]) { @@ -23,7 +24,7 @@ pub fn replace_universal_newlines(checker: &mut Checker, expr: &Expr, kwargs: &[ kwarg.location.column() + "universal_newlines".len(), ), ); - let mut check = Check::new(CheckKind::ReplaceUniversalNewlines, range); + let mut check = Check::new(violations::ReplaceUniversalNewlines, range); if checker.patch(check.kind.code()) { check.amend(Fix::replacement( "text".to_string(), diff --git a/src/pyupgrade/plugins/rewrite_c_element_tree.rs b/src/pyupgrade/plugins/rewrite_c_element_tree.rs index ba38194ed3..c4c4750ed3 100644 --- a/src/pyupgrade/plugins/rewrite_c_element_tree.rs +++ b/src/pyupgrade/plugins/rewrite_c_element_tree.rs @@ -4,9 +4,10 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; fn add_check_for_node(checker: &mut Checker, node: &Located) { - let mut check = Check::new(CheckKind::RewriteCElementTree, Range::from_located(node)); + let mut check = Check::new(violations::RewriteCElementTree, Range::from_located(node)); if checker.patch(check.kind.code()) { let contents = checker .locator diff --git a/src/pyupgrade/plugins/rewrite_mock_import.rs b/src/pyupgrade/plugins/rewrite_mock_import.rs index 38f3fa8da9..20ea06849b 100644 --- a/src/pyupgrade/plugins/rewrite_mock_import.rs +++ b/src/pyupgrade/plugins/rewrite_mock_import.rs @@ -15,6 +15,7 @@ use crate::cst::matchers::{match_import, match_import_from, match_module}; use crate::registry::{Check, CheckCode, CheckKind, MockReference}; use crate::source_code_locator::SourceCodeLocator; use crate::source_code_style::SourceCodeStyleDetector; +use crate::violations; /// Return a vector of all non-`mock` imports. fn clean_import_aliases(aliases: Vec) -> (Vec, Vec>) { @@ -204,7 +205,7 @@ pub fn rewrite_mock_attribute(checker: &mut Checker, expr: &Expr) { if let ExprKind::Attribute { value, .. } = &expr.node { if collect_call_paths(value) == ["mock", "mock"] { let mut check = Check::new( - CheckKind::RewriteMockImport(MockReference::Attribute), + violations::RewriteMockImport(MockReference::Attribute), Range::from_located(value), ); if checker.patch(&CheckCode::UP026) { @@ -246,7 +247,7 @@ pub fn rewrite_mock_import(checker: &mut Checker, stmt: &Stmt) { for name in names { if name.node.name == "mock" || name.node.name == "mock.mock" { let mut check = Check::new( - CheckKind::RewriteMockImport(MockReference::Import), + violations::RewriteMockImport(MockReference::Import), Range::from_located(name), ); if let Some(content) = content.as_ref() { @@ -272,7 +273,7 @@ pub fn rewrite_mock_import(checker: &mut Checker, stmt: &Stmt) { if module == "mock" { let mut check = Check::new( - CheckKind::RewriteMockImport(MockReference::Import), + violations::RewriteMockImport(MockReference::Import), Range::from_located(stmt), ); if checker.patch(&CheckCode::UP026) { diff --git a/src/pyupgrade/plugins/rewrite_unicode_literal.rs b/src/pyupgrade/plugins/rewrite_unicode_literal.rs index 27e5873545..b5f56bf07c 100644 --- a/src/pyupgrade/plugins/rewrite_unicode_literal.rs +++ b/src/pyupgrade/plugins/rewrite_unicode_literal.rs @@ -4,12 +4,14 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// UP025 pub fn rewrite_unicode_literal(checker: &mut Checker, expr: &Expr, kind: Option<&str>) { if let Some(const_kind) = kind { if const_kind.to_lowercase() == "u" { - let mut check = Check::new(CheckKind::RewriteUnicodeLiteral, Range::from_located(expr)); + let mut check = + Check::new(violations::RewriteUnicodeLiteral, Range::from_located(expr)); if checker.patch(check.kind.code()) { check.amend(Fix::deletion( expr.location, diff --git a/src/pyupgrade/plugins/rewrite_yield_from.rs b/src/pyupgrade/plugins/rewrite_yield_from.rs index 5e161f1a64..d18b295398 100644 --- a/src/pyupgrade/plugins/rewrite_yield_from.rs +++ b/src/pyupgrade/plugins/rewrite_yield_from.rs @@ -7,6 +7,7 @@ use crate::ast::visitor::Visitor; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// Return `true` if the two expressions are equivalent, and consistent solely /// of tuples and names. @@ -156,7 +157,8 @@ pub fn rewrite_yield_from(checker: &mut Checker, stmt: &Stmt) { continue; } - let mut check = Check::new(CheckKind::RewriteYieldFrom, Range::from_located(item.stmt)); + let mut check = + Check::new(violations::RewriteYieldFrom, Range::from_located(item.stmt)); if checker.patch(check.kind.code()) { let contents = checker .locator diff --git a/src/pyupgrade/plugins/type_of_primitive.rs b/src/pyupgrade/plugins/type_of_primitive.rs index 63f24bb345..8faa953b5c 100644 --- a/src/pyupgrade/plugins/type_of_primitive.rs +++ b/src/pyupgrade/plugins/type_of_primitive.rs @@ -5,6 +5,7 @@ use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::pyupgrade::checks; use crate::registry::CheckKind; +use crate::violations; /// UP003 pub fn type_of_primitive(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) { @@ -12,7 +13,7 @@ pub fn type_of_primitive(checker: &mut Checker, expr: &Expr, func: &Expr, args: return; }; if checker.patch(check.kind.code()) { - if let CheckKind::TypeOfPrimitive(primitive) = &check.kind { + if let violations::TypeOfPrimitive(primitive) = &check.kind { check.amend(Fix::replacement( primitive.builtin(), expr.location, diff --git a/src/pyupgrade/plugins/typing_text_str_alias.rs b/src/pyupgrade/plugins/typing_text_str_alias.rs index 945d6fbca4..9375747834 100644 --- a/src/pyupgrade/plugins/typing_text_str_alias.rs +++ b/src/pyupgrade/plugins/typing_text_str_alias.rs @@ -5,6 +5,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// UP019 pub fn typing_text_str_alias(checker: &mut Checker, expr: &Expr) { @@ -15,7 +16,7 @@ pub fn typing_text_str_alias(checker: &mut Checker, expr: &Expr) { &checker.from_imports, &checker.import_aliases, ) { - let mut check = Check::new(CheckKind::TypingTextStrAlias, Range::from_located(expr)); + let mut check = Check::new(violations::TypingTextStrAlias, Range::from_located(expr)); if checker.patch(check.kind.code()) { check.amend(Fix::replacement( "str".to_string(), diff --git a/src/pyupgrade/plugins/unnecessary_builtin_import.rs b/src/pyupgrade/plugins/unnecessary_builtin_import.rs index 62bcad9ec0..acd9dfebb8 100644 --- a/src/pyupgrade/plugins/unnecessary_builtin_import.rs +++ b/src/pyupgrade/plugins/unnecessary_builtin_import.rs @@ -4,9 +4,9 @@ use rustpython_ast::{Alias, AliasData, Located}; use rustpython_parser::ast::Stmt; use crate::ast::types::Range; -use crate::autofix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::{autofix, violations}; const BUILTINS: &[&str] = &[ "*", @@ -69,7 +69,7 @@ pub fn unnecessary_builtin_import( return; } let mut check = Check::new( - CheckKind::UnnecessaryBuiltinImport( + violations::UnnecessaryBuiltinImport( unused_imports .iter() .map(|alias| alias.node.name.to_string()) diff --git a/src/pyupgrade/plugins/unnecessary_encode_utf8.rs b/src/pyupgrade/plugins/unnecessary_encode_utf8.rs index 008091ac02..15d6c47ed2 100644 --- a/src/pyupgrade/plugins/unnecessary_encode_utf8.rs +++ b/src/pyupgrade/plugins/unnecessary_encode_utf8.rs @@ -5,6 +5,7 @@ use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; use crate::source_code_locator::SourceCodeLocator; +use crate::violations; const UTF8_LITERALS: &[&str] = &["utf-8", "utf8", "utf_8", "u8", "utf", "cp65001"]; @@ -59,13 +60,13 @@ fn delete_default_encode_arg_or_kwarg( patch: bool, ) -> Option { if let Some(arg) = args.get(0) { - let mut check = Check::new(CheckKind::UnnecessaryEncodeUTF8, Range::from_located(expr)); + let mut check = Check::new(violations::UnnecessaryEncodeUTF8, Range::from_located(expr)); if patch { check.amend(Fix::deletion(arg.location, arg.end_location.unwrap())); } Some(check) } else if let Some(kwarg) = kwargs.get(0) { - let mut check = Check::new(CheckKind::UnnecessaryEncodeUTF8, Range::from_located(expr)); + let mut check = Check::new(violations::UnnecessaryEncodeUTF8, Range::from_located(expr)); if patch { check.amend(Fix::deletion(kwarg.location, kwarg.end_location.unwrap())); } @@ -82,7 +83,7 @@ fn replace_with_bytes_literal( locator: &SourceCodeLocator, patch: bool, ) -> Check { - let mut check = Check::new(CheckKind::UnnecessaryEncodeUTF8, Range::from_located(expr)); + let mut check = Check::new(violations::UnnecessaryEncodeUTF8, Range::from_located(expr)); if patch { let content = locator.slice_source_code_range(&Range::new( constant.location, diff --git a/src/pyupgrade/plugins/unnecessary_future_import.rs b/src/pyupgrade/plugins/unnecessary_future_import.rs index 472af437a0..bd73f0a677 100644 --- a/src/pyupgrade/plugins/unnecessary_future_import.rs +++ b/src/pyupgrade/plugins/unnecessary_future_import.rs @@ -4,10 +4,10 @@ use rustpython_ast::{Alias, AliasData, Located}; use rustpython_parser::ast::Stmt; use crate::ast::types::Range; -use crate::autofix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; use crate::settings::types::PythonVersion; +use crate::{autofix, violations}; const PY33_PLUS_REMOVE_FUTURES: &[&str] = &[ "nested_scopes", @@ -54,7 +54,7 @@ pub fn unnecessary_future_import(checker: &mut Checker, stmt: &Stmt, names: &[Lo return; } let mut check = Check::new( - CheckKind::UnnecessaryFutureImport( + violations::UnnecessaryFutureImport( unused_imports .iter() .map(|alias| alias.node.name.to_string()) diff --git a/src/pyupgrade/plugins/unpack_list_comprehension.rs b/src/pyupgrade/plugins/unpack_list_comprehension.rs index ce8a1c93bd..9190eb3754 100644 --- a/src/pyupgrade/plugins/unpack_list_comprehension.rs +++ b/src/pyupgrade/plugins/unpack_list_comprehension.rs @@ -4,6 +4,7 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckCode, CheckKind}; +use crate::violations; /// Returns `true` if `expr` contains an `ExprKind::Await`. fn contains_await(expr: &Expr) -> bool { @@ -75,7 +76,7 @@ pub fn unpack_list_comprehension(checker: &mut Checker, targets: &[Expr], value: } let mut check = Check::new( - CheckKind::RewriteListComprehension, + violations::RewriteListComprehension, Range::from_located(value), ); if checker.patch(&CheckCode::UP027) { diff --git a/src/pyupgrade/plugins/use_pep585_annotation.rs b/src/pyupgrade/plugins/use_pep585_annotation.rs index 74ec9b0058..05711cc1da 100644 --- a/src/pyupgrade/plugins/use_pep585_annotation.rs +++ b/src/pyupgrade/plugins/use_pep585_annotation.rs @@ -4,12 +4,13 @@ use crate::ast::types::Range; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; +use crate::violations; /// UP006 pub fn use_pep585_annotation(checker: &mut Checker, expr: &Expr, id: &str) { let replacement = *checker.import_aliases.get(id).unwrap_or(&id); let mut check = Check::new( - CheckKind::UsePEP585Annotation(replacement.to_string()), + violations::UsePEP585Annotation(replacement.to_string()), Range::from_located(expr), ); if checker.patch(check.kind.code()) { diff --git a/src/pyupgrade/plugins/use_pep604_annotation.rs b/src/pyupgrade/plugins/use_pep604_annotation.rs index acbe4c0160..0538a4445d 100644 --- a/src/pyupgrade/plugins/use_pep604_annotation.rs +++ b/src/pyupgrade/plugins/use_pep604_annotation.rs @@ -6,6 +6,7 @@ use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::{Check, CheckKind}; use crate::source_code_generator::SourceCodeGenerator; +use crate::violations; fn optional(expr: &Expr) -> Expr { Expr::new( @@ -63,7 +64,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s let call_path = dealias_call_path(collect_call_paths(value), &checker.import_aliases); if checker.match_typing_call_path(&call_path, "Optional") { - let mut check = Check::new(CheckKind::UsePEP604Annotation, Range::from_located(expr)); + let mut check = Check::new(violations::UsePEP604Annotation, Range::from_located(expr)); if checker.patch(check.kind.code()) { let mut generator: SourceCodeGenerator = checker.style.into(); generator.unparse_expr(&optional(slice), 0); @@ -75,7 +76,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s } checker.checks.push(check); } else if checker.match_typing_call_path(&call_path, "Union") { - let mut check = Check::new(CheckKind::UsePEP604Annotation, Range::from_located(expr)); + let mut check = Check::new(violations::UsePEP604Annotation, Range::from_located(expr)); if checker.patch(check.kind.code()) { match &slice.node { ExprKind::Slice { .. } => { diff --git a/src/ruff/checks.rs b/src/ruff/checks.rs index 4df462a26b..a94d6885d5 100644 --- a/src/ruff/checks.rs +++ b/src/ruff/checks.rs @@ -7,7 +7,7 @@ use crate::autofix::Fix; use crate::registry::CheckKind; use crate::settings::flags; use crate::source_code_locator::SourceCodeLocator; -use crate::{Check, Settings}; +use crate::{violations, Check, Settings}; /// See: static CONFUSABLES: Lazy> = Lazy::new(|| { @@ -1632,15 +1632,15 @@ pub fn ambiguous_unicode_character( let end_location = Location::new(location.row(), location.column() + 1); let mut check = Check::new( match context { - Context::String => CheckKind::AmbiguousUnicodeCharacterString( + Context::String => violations::AmbiguousUnicodeCharacterString( current_char, representant, ), - Context::Docstring => CheckKind::AmbiguousUnicodeCharacterDocstring( + Context::Docstring => violations::AmbiguousUnicodeCharacterDocstring( current_char, representant, ), - Context::Comment => CheckKind::AmbiguousUnicodeCharacterComment( + Context::Comment => violations::AmbiguousUnicodeCharacterComment( current_char, representant, ), @@ -1687,7 +1687,7 @@ pub fn keyword_argument_before_star_argument(args: &[Expr], keywords: &[Keyword] let KeywordData { arg, .. } = &keyword.node; if let Some(arg) = arg { checks.push(Check::new( - CheckKind::KeywordArgumentBeforeStarArgument(arg.to_string()), + violations::KeywordArgumentBeforeStarArgument(arg.to_string()), Range::from_located(keyword), )); } diff --git a/src/ruff/mod.rs b/src/ruff/mod.rs index 633ccc7196..23e89e6e17 100644 --- a/src/ruff/mod.rs +++ b/src/ruff/mod.rs @@ -12,7 +12,7 @@ mod tests { use crate::linter::test_path; use crate::registry::CheckCode; - use crate::settings; + use crate::{settings, violations}; #[test_case(CheckCode::RUF004, Path::new("RUF004.py"); "RUF004")] fn checks(check_code: CheckCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", check_code.as_ref(), path.to_string_lossy()); diff --git a/src/settings/configuration.rs b/src/settings/configuration.rs index dc262eed4e..f1fdc1fd3b 100644 --- a/src/settings/configuration.rs +++ b/src/settings/configuration.rs @@ -22,7 +22,7 @@ use crate::settings::types::{ use crate::{ flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, fs, isort, - mccabe, pep8_naming, pycodestyle, pydocstyle, pyupgrade, + mccabe, pep8_naming, pycodestyle, pydocstyle, pyupgrade, violations, }; #[derive(Debug, Default)] diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 48b97fefe5..c49c0fd9f8 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -25,7 +25,7 @@ use crate::settings::types::{ use crate::{ flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, isort, - mccabe, one_time_warning, pep8_naming, pycodestyle, pydocstyle, pyupgrade, + mccabe, one_time_warning, pep8_naming, pycodestyle, pydocstyle, pyupgrade, violations, }; pub mod configuration; @@ -442,6 +442,7 @@ mod tests { use crate::registry::{CheckCode, CheckCodePrefix}; use crate::settings::{resolve_codes, CheckCodeSpec}; + use crate::violations; #[test] fn check_codes() { diff --git a/src/settings/options.rs b/src/settings/options.rs index 620dd96368..4375a5751d 100644 --- a/src/settings/options.rs +++ b/src/settings/options.rs @@ -10,7 +10,7 @@ use crate::settings::types::{PythonVersion, SerializationFormat, Version}; use crate::{ flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, isort, - mccabe, pep8_naming, pycodestyle, pydocstyle, pyupgrade, + mccabe, pep8_naming, pycodestyle, pydocstyle, pyupgrade, violations, }; #[derive( diff --git a/src/settings/pyproject.rs b/src/settings/pyproject.rs index 5b888e3d5e..5ca65efa7c 100644 --- a/src/settings/pyproject.rs +++ b/src/settings/pyproject.rs @@ -138,7 +138,7 @@ mod tests { use crate::settings::types::PatternPrefixPair; use crate::{ flake8_bugbear, flake8_errmsg, flake8_import_conventions, flake8_pytest_style, - flake8_quotes, flake8_tidy_imports, mccabe, pep8_naming, + flake8_quotes, flake8_tidy_imports, mccabe, pep8_naming, violations, }; #[test] diff --git a/src/settings/types.rs b/src/settings/types.rs index 56383b87c7..a76f757ea0 100644 --- a/src/settings/types.rs +++ b/src/settings/types.rs @@ -10,8 +10,8 @@ use rustc_hash::FxHashSet; use schemars::JsonSchema; use serde::{de, Deserialize, Deserializer, Serialize}; -use crate::fs; use crate::registry::{CheckCode, CheckCodePrefix}; +use crate::{fs, violations}; #[derive( Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, Hash, JsonSchema,