mirror of https://github.com/astral-sh/ruff
structs 6/9: Automatically change CheckKind::* to violations::*
The changes in this commit were generated by running: for f in $(find src -name '*.rs'); do sed -Ei 's/use crate::registry::.*;/\0use crate::violations;/g' $f; done for f in $(find src -name '*.rs'); do sed -Ei 's/CheckKind::([A-Z])/violations::\1/g' $f; done git checkout src/registry.rs src/lib.rs src/lib_wasm.rs src/violations.rs cargo +nightly fmt
This commit is contained in:
parent
3c8fdbf107
commit
43db446dfa
|
|
@ -9,6 +9,7 @@ use crate::ast::types::Range;
|
||||||
use crate::autofix::Fix;
|
use crate::autofix::Fix;
|
||||||
use crate::registry::Check;
|
use crate::registry::Check;
|
||||||
use crate::source_code_locator::SourceCodeLocator;
|
use crate::source_code_locator::SourceCodeLocator;
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Hash)]
|
#[derive(Debug, Copy, Clone, Hash)]
|
||||||
pub enum Mode {
|
pub enum Mode {
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,8 @@ use crate::{
|
||||||
flake8_debugger, flake8_errmsg, flake8_implicit_str_concat, flake8_import_conventions,
|
flake8_debugger, flake8_errmsg, flake8_implicit_str_concat, flake8_import_conventions,
|
||||||
flake8_pie, flake8_print, flake8_pytest_style, flake8_return, flake8_simplify,
|
flake8_pie, flake8_print, flake8_pytest_style, flake8_return, flake8_simplify,
|
||||||
flake8_tidy_imports, flake8_unused_arguments, mccabe, noqa, pandas_vet, pep8_naming,
|
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;
|
const GLOBAL_SCOPE_INDEX: usize = 0;
|
||||||
|
|
@ -312,7 +313,7 @@ where
|
||||||
if !exists {
|
if !exists {
|
||||||
if self.settings.enabled.contains(&CheckCode::PLE0117) {
|
if self.settings.enabled.contains(&CheckCode::PLE0117) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::NonlocalWithoutBinding(name.to_string()),
|
violations::NonlocalWithoutBinding(name.to_string()),
|
||||||
*range,
|
*range,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -573,7 +574,7 @@ where
|
||||||
ScopeKind::Class(_) | ScopeKind::Module
|
ScopeKind::Class(_) | ScopeKind::Module
|
||||||
) {
|
) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::ReturnOutsideFunction,
|
violations::ReturnOutsideFunction,
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -656,7 +657,7 @@ where
|
||||||
if self.settings.enabled.contains(&CheckCode::E401) {
|
if self.settings.enabled.contains(&CheckCode::E401) {
|
||||||
if names.len() > 1 {
|
if names.len() > 1 {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::MultipleImportsOnOneLine,
|
violations::MultipleImportsOnOneLine,
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -665,7 +666,7 @@ where
|
||||||
if self.settings.enabled.contains(&CheckCode::E402) {
|
if self.settings.enabled.contains(&CheckCode::E402) {
|
||||||
if self.seen_import_boundary && stmt.location.column() == 0 {
|
if self.seen_import_boundary && stmt.location.column() == 0 {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::ModuleImportNotAtTopOfFile,
|
violations::ModuleImportNotAtTopOfFile,
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -886,7 +887,7 @@ where
|
||||||
if self.settings.enabled.contains(&CheckCode::E402) {
|
if self.settings.enabled.contains(&CheckCode::E402) {
|
||||||
if self.seen_import_boundary && stmt.location.column() == 0 {
|
if self.seen_import_boundary && stmt.location.column() == 0 {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::ModuleImportNotAtTopOfFile,
|
violations::ModuleImportNotAtTopOfFile,
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -965,7 +966,9 @@ where
|
||||||
if self.settings.enabled.contains(&CheckCode::F407) {
|
if self.settings.enabled.contains(&CheckCode::F407) {
|
||||||
if !ALL_FEATURE_NAMES.contains(&&*alias.node.name) {
|
if !ALL_FEATURE_NAMES.contains(&&*alias.node.name) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::FutureFeatureNotDefined(alias.node.name.to_string()),
|
violations::FutureFeatureNotDefined(
|
||||||
|
alias.node.name.to_string(),
|
||||||
|
),
|
||||||
Range::from_located(alias),
|
Range::from_located(alias),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -974,7 +977,7 @@ where
|
||||||
if self.settings.enabled.contains(&CheckCode::F404) && !self.futures_allowed
|
if self.settings.enabled.contains(&CheckCode::F404) && !self.futures_allowed
|
||||||
{
|
{
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::LateFutureImport,
|
violations::LateFutureImport,
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -994,10 +997,12 @@ where
|
||||||
[*(self.scope_stack.last().expect("No current scope found"))];
|
[*(self.scope_stack.last().expect("No current scope found"))];
|
||||||
if !matches!(scope.kind, ScopeKind::Module) {
|
if !matches!(scope.kind, ScopeKind::Module) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::ImportStarNotPermitted(helpers::format_import_from(
|
violations::ImportStarNotPermitted(
|
||||||
|
helpers::format_import_from(
|
||||||
level.as_ref(),
|
level.as_ref(),
|
||||||
module.as_deref(),
|
module.as_deref(),
|
||||||
)),
|
),
|
||||||
|
),
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -1005,7 +1010,7 @@ where
|
||||||
|
|
||||||
if self.settings.enabled.contains(&CheckCode::F403) {
|
if self.settings.enabled.contains(&CheckCode::F403) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::ImportStarUsed(helpers::format_import_from(
|
violations::ImportStarUsed(helpers::format_import_from(
|
||||||
level.as_ref(),
|
level.as_ref(),
|
||||||
module.as_deref(),
|
module.as_deref(),
|
||||||
)),
|
)),
|
||||||
|
|
@ -1804,7 +1809,7 @@ where
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if self.settings.enabled.contains(&CheckCode::F521) {
|
if self.settings.enabled.contains(&CheckCode::F521) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::StringDotFormatInvalidFormat(
|
violations::StringDotFormatInvalidFormat(
|
||||||
pyflakes::format::error_to_string(&e),
|
pyflakes::format::error_to_string(&e),
|
||||||
),
|
),
|
||||||
location,
|
location,
|
||||||
|
|
@ -2396,7 +2401,7 @@ where
|
||||||
let scope = self.current_scope();
|
let scope = self.current_scope();
|
||||||
if matches!(scope.kind, ScopeKind::Class(_) | ScopeKind::Module) {
|
if matches!(scope.kind, ScopeKind::Class(_) | ScopeKind::Module) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::YieldOutsideFunction(DeferralKeyword::Yield),
|
violations::YieldOutsideFunction(DeferralKeyword::Yield),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -2407,7 +2412,7 @@ where
|
||||||
let scope = self.current_scope();
|
let scope = self.current_scope();
|
||||||
if matches!(scope.kind, ScopeKind::Class(_) | ScopeKind::Module) {
|
if matches!(scope.kind, ScopeKind::Class(_) | ScopeKind::Module) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::YieldOutsideFunction(DeferralKeyword::YieldFrom),
|
violations::YieldOutsideFunction(DeferralKeyword::YieldFrom),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -2418,7 +2423,7 @@ where
|
||||||
let scope = self.current_scope();
|
let scope = self.current_scope();
|
||||||
if matches!(scope.kind, ScopeKind::Class(_) | ScopeKind::Module) {
|
if matches!(scope.kind, ScopeKind::Class(_) | ScopeKind::Module) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::YieldOutsideFunction(DeferralKeyword::Await),
|
violations::YieldOutsideFunction(DeferralKeyword::Await),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -2469,7 +2474,7 @@ where
|
||||||
}) => {
|
}) => {
|
||||||
if self.settings.enabled.contains(&CheckCode::F509) {
|
if self.settings.enabled.contains(&CheckCode::F509) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::PercentFormatUnsupportedFormatCharacter(c),
|
violations::PercentFormatUnsupportedFormatCharacter(c),
|
||||||
location,
|
location,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -2477,7 +2482,7 @@ where
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if self.settings.enabled.contains(&CheckCode::F501) {
|
if self.settings.enabled.contains(&CheckCode::F501) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::PercentFormatInvalidFormat(e.to_string()),
|
violations::PercentFormatInvalidFormat(e.to_string()),
|
||||||
location,
|
location,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -3068,7 +3073,7 @@ where
|
||||||
if self.bindings[*index].used.is_none() {
|
if self.bindings[*index].used.is_none() {
|
||||||
if self.settings.enabled.contains(&CheckCode::F841) {
|
if self.settings.enabled.contains(&CheckCode::F841) {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UnusedVariable(name.to_string()),
|
violations::UnusedVariable(name.to_string()),
|
||||||
name_range,
|
name_range,
|
||||||
);
|
);
|
||||||
if self.patch(&CheckCode::F841) {
|
if self.patch(&CheckCode::F841) {
|
||||||
|
|
@ -3354,7 +3359,7 @@ impl<'a> Checker<'a> {
|
||||||
overridden = Some((*scope_index, *existing_binding_index));
|
overridden = Some((*scope_index, *existing_binding_index));
|
||||||
if self.settings.enabled.contains(&CheckCode::F402) {
|
if self.settings.enabled.contains(&CheckCode::F402) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::ImportShadowedByLoopVar(
|
violations::ImportShadowedByLoopVar(
|
||||||
name.to_string(),
|
name.to_string(),
|
||||||
existing.range.location.row(),
|
existing.range.location.row(),
|
||||||
),
|
),
|
||||||
|
|
@ -3374,7 +3379,7 @@ impl<'a> Checker<'a> {
|
||||||
overridden = Some((*scope_index, *existing_binding_index));
|
overridden = Some((*scope_index, *existing_binding_index));
|
||||||
if self.settings.enabled.contains(&CheckCode::F811) {
|
if self.settings.enabled.contains(&CheckCode::F811) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::RedefinedWhileUnused(
|
violations::RedefinedWhileUnused(
|
||||||
name.to_string(),
|
name.to_string(),
|
||||||
existing.range.location.row(),
|
existing.range.location.row(),
|
||||||
),
|
),
|
||||||
|
|
@ -3500,7 +3505,7 @@ impl<'a> Checker<'a> {
|
||||||
from_list.sort();
|
from_list.sort();
|
||||||
|
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::ImportStarUsage(id.to_string(), from_list),
|
violations::ImportStarUsage(id.to_string(), from_list),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -3531,7 +3536,7 @@ impl<'a> Checker<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::UndefinedName(id.clone()),
|
violations::UndefinedName(id.clone()),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -3702,7 +3707,7 @@ impl<'a> Checker<'a> {
|
||||||
&& self.settings.enabled.contains(&CheckCode::F821)
|
&& self.settings.enabled.contains(&CheckCode::F821)
|
||||||
{
|
{
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::UndefinedName(id.to_string()),
|
violations::UndefinedName(id.to_string()),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -3763,7 +3768,7 @@ impl<'a> Checker<'a> {
|
||||||
} else {
|
} else {
|
||||||
if self.settings.enabled.contains(&CheckCode::F722) {
|
if self.settings.enabled.contains(&CheckCode::F722) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::ForwardAnnotationSyntaxError(expression.to_string()),
|
violations::ForwardAnnotationSyntaxError(expression.to_string()),
|
||||||
range,
|
range,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -3869,7 +3874,7 @@ impl<'a> Checker<'a> {
|
||||||
let binding = &self.bindings[*index];
|
let binding = &self.bindings[*index];
|
||||||
if matches!(binding.kind, BindingKind::Global) {
|
if matches!(binding.kind, BindingKind::Global) {
|
||||||
checks.push(Check::new(
|
checks.push(Check::new(
|
||||||
CheckKind::GlobalVariableNotAssigned((*name).to_string()),
|
violations::GlobalVariableNotAssigned((*name).to_string()),
|
||||||
binding.range,
|
binding.range,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -3898,7 +3903,7 @@ impl<'a> Checker<'a> {
|
||||||
for &name in names {
|
for &name in names {
|
||||||
if !scope.values.contains_key(name) {
|
if !scope.values.contains_key(name) {
|
||||||
checks.push(Check::new(
|
checks.push(Check::new(
|
||||||
CheckKind::UndefinedExport(name.to_string()),
|
violations::UndefinedExport(name.to_string()),
|
||||||
all_binding.range,
|
all_binding.range,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -3936,7 +3941,7 @@ impl<'a> Checker<'a> {
|
||||||
if let Some(indices) = self.redefinitions.get(index) {
|
if let Some(indices) = self.redefinitions.get(index) {
|
||||||
for index in indices {
|
for index in indices {
|
||||||
checks.push(Check::new(
|
checks.push(Check::new(
|
||||||
CheckKind::RedefinedWhileUnused(
|
violations::RedefinedWhileUnused(
|
||||||
(*name).to_string(),
|
(*name).to_string(),
|
||||||
binding.range.location.row(),
|
binding.range.location.row(),
|
||||||
),
|
),
|
||||||
|
|
@ -3967,7 +3972,7 @@ impl<'a> Checker<'a> {
|
||||||
for &name in names {
|
for &name in names {
|
||||||
if !scope.values.contains_key(name) {
|
if !scope.values.contains_key(name) {
|
||||||
checks.push(Check::new(
|
checks.push(Check::new(
|
||||||
CheckKind::ImportStarUsage(
|
violations::ImportStarUsage(
|
||||||
name.to_string(),
|
name.to_string(),
|
||||||
from_list.clone(),
|
from_list.clone(),
|
||||||
),
|
),
|
||||||
|
|
@ -4082,7 +4087,7 @@ impl<'a> Checker<'a> {
|
||||||
let multiple = unused_imports.len() > 1;
|
let multiple = unused_imports.len() > 1;
|
||||||
for (full_name, range) in unused_imports {
|
for (full_name, range) in unused_imports {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UnusedImport(full_name.to_string(), ignore_init, multiple),
|
violations::UnusedImport(full_name.to_string(), ignore_init, multiple),
|
||||||
*range,
|
*range,
|
||||||
);
|
);
|
||||||
if matches!(child.node, StmtKind::ImportFrom { .. })
|
if matches!(child.node, StmtKind::ImportFrom { .. })
|
||||||
|
|
@ -4104,7 +4109,7 @@ impl<'a> Checker<'a> {
|
||||||
let multiple = unused_imports.len() > 1;
|
let multiple = unused_imports.len() > 1;
|
||||||
for (full_name, range) in unused_imports {
|
for (full_name, range) in unused_imports {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UnusedImport(full_name.to_string(), ignore_init, multiple),
|
violations::UnusedImport(full_name.to_string(), ignore_init, multiple),
|
||||||
*range,
|
*range,
|
||||||
);
|
);
|
||||||
if matches!(child.node, StmtKind::ImportFrom { .. })
|
if matches!(child.node, StmtKind::ImportFrom { .. })
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ use rustpython_parser::ast::Suite;
|
||||||
|
|
||||||
use crate::ast::visitor::Visitor;
|
use crate::ast::visitor::Visitor;
|
||||||
use crate::directives::IsortDirectives;
|
use crate::directives::IsortDirectives;
|
||||||
use crate::isort;
|
|
||||||
use crate::isort::track::ImportTracker;
|
use crate::isort::track::ImportTracker;
|
||||||
use crate::registry::Check;
|
use crate::registry::Check;
|
||||||
use crate::settings::{flags, Settings};
|
use crate::settings::{flags, Settings};
|
||||||
use crate::source_code_locator::SourceCodeLocator;
|
use crate::source_code_locator::SourceCodeLocator;
|
||||||
use crate::source_code_style::SourceCodeStyleDetector;
|
use crate::source_code_style::SourceCodeStyleDetector;
|
||||||
|
use crate::{isort, violations};
|
||||||
|
|
||||||
fn check_import_blocks(
|
fn check_import_blocks(
|
||||||
tracker: ImportTracker,
|
tracker: ImportTracker,
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::pygrep_hooks::plugins::{blanket_noqa, blanket_type_ignore};
|
||||||
use crate::pyupgrade::checks::unnecessary_coding_comment;
|
use crate::pyupgrade::checks::unnecessary_coding_comment;
|
||||||
use crate::registry::{Check, CheckCode};
|
use crate::registry::{Check, CheckCode};
|
||||||
use crate::settings::{flags, Settings};
|
use crate::settings::{flags, Settings};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
pub fn check_lines(
|
pub fn check_lines(
|
||||||
contents: &str,
|
contents: &str,
|
||||||
|
|
@ -82,6 +83,7 @@ mod tests {
|
||||||
use super::check_lines;
|
use super::check_lines;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::settings::{flags, Settings};
|
use crate::settings::{flags, Settings};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn e501_non_ascii_char() {
|
fn e501_non_ascii_char() {
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@ use rustpython_parser::ast::Location;
|
||||||
|
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::autofix::Fix;
|
use crate::autofix::Fix;
|
||||||
use crate::noqa;
|
|
||||||
use crate::noqa::{is_file_exempt, Directive};
|
use crate::noqa::{is_file_exempt, Directive};
|
||||||
use crate::registry::{Check, CheckCode, CheckKind, UnusedCodes, CODE_REDIRECTS};
|
use crate::registry::{Check, CheckCode, CheckKind, UnusedCodes, CODE_REDIRECTS};
|
||||||
use crate::settings::{flags, Settings};
|
use crate::settings::{flags, Settings};
|
||||||
|
use crate::{noqa, violations};
|
||||||
|
|
||||||
pub fn check_noqa(
|
pub fn check_noqa(
|
||||||
checks: &mut Vec<Check>,
|
checks: &mut Vec<Check>,
|
||||||
|
|
@ -42,7 +42,7 @@ pub fn check_noqa(
|
||||||
|
|
||||||
// Remove any ignored checks.
|
// Remove any ignored checks.
|
||||||
for (index, check) in checks.iter().enumerate() {
|
for (index, check) in checks.iter().enumerate() {
|
||||||
if check.kind == CheckKind::BlanketNOQA {
|
if check.kind == violations::BlanketNOQA {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,7 +101,7 @@ pub fn check_noqa(
|
||||||
Directive::All(spaces, start, end) => {
|
Directive::All(spaces, start, end) => {
|
||||||
if matches.is_empty() {
|
if matches.is_empty() {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UnusedNOQA(None),
|
violations::UnusedNOQA(None),
|
||||||
Range::new(Location::new(row + 1, start), Location::new(row + 1, end)),
|
Range::new(Location::new(row + 1, start), Location::new(row + 1, end)),
|
||||||
);
|
);
|
||||||
if matches!(autofix, flags::Autofix::Enabled)
|
if matches!(autofix, flags::Autofix::Enabled)
|
||||||
|
|
@ -152,7 +152,7 @@ pub fn check_noqa(
|
||||||
&& unmatched_codes.is_empty())
|
&& unmatched_codes.is_empty())
|
||||||
{
|
{
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UnusedNOQA(Some(UnusedCodes {
|
violations::UnusedNOQA(Some(UnusedCodes {
|
||||||
disabled: disabled_codes
|
disabled: disabled_codes
|
||||||
.iter()
|
.iter()
|
||||||
.map(|code| (*code).to_string())
|
.map(|code| (*code).to_string())
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ use crate::registry::{Check, CheckCode};
|
||||||
use crate::ruff::checks::Context;
|
use crate::ruff::checks::Context;
|
||||||
use crate::settings::flags;
|
use crate::settings::flags;
|
||||||
use crate::source_code_locator::SourceCodeLocator;
|
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(
|
pub fn check_tokens(
|
||||||
locator: &SourceCodeLocator,
|
locator: &SourceCodeLocator,
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@ use clap::{command, Parser};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use crate::fs;
|
|
||||||
use crate::logging::LogLevel;
|
use crate::logging::LogLevel;
|
||||||
use crate::registry::{CheckCode, CheckCodePrefix};
|
use crate::registry::{CheckCode, CheckCodePrefix};
|
||||||
use crate::settings::types::{
|
use crate::settings::types::{
|
||||||
FilePattern, PatternPrefixPair, PerFileIgnore, PythonVersion, SerializationFormat,
|
FilePattern, PatternPrefixPair, PerFileIgnore, PythonVersion, SerializationFormat,
|
||||||
};
|
};
|
||||||
|
use crate::{fs, violations};
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[command(author, about = "Ruff: An extremely fast Python linter.")]
|
#[command(author, about = "Ruff: An extremely fast Python linter.")]
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ use crate::registry::{CheckCode, CheckKind};
|
||||||
use crate::resolver::{FileDiscovery, PyprojectDiscovery};
|
use crate::resolver::{FileDiscovery, PyprojectDiscovery};
|
||||||
use crate::settings::flags;
|
use crate::settings::flags;
|
||||||
use crate::settings::types::SerializationFormat;
|
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.
|
/// Run the linter over a collection of files.
|
||||||
pub fn run(
|
pub fn run(
|
||||||
|
|
@ -119,7 +119,7 @@ pub fn run(
|
||||||
let settings = resolver.resolve(path, pyproject_strategy);
|
let settings = resolver.resolve(path, pyproject_strategy);
|
||||||
if settings.enabled.contains(&CheckCode::E902) {
|
if settings.enabled.contains(&CheckCode::E902) {
|
||||||
Diagnostics::new(vec![Message {
|
Diagnostics::new(vec![Message {
|
||||||
kind: CheckKind::IOError(message),
|
kind: violations::IOError(message),
|
||||||
location: Location::default(),
|
location: Location::default(),
|
||||||
end_location: Location::default(),
|
end_location: Location::default(),
|
||||||
fix: None,
|
fix: None,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use rustpython_ast::Location;
|
||||||
use rustpython_parser::lexer::{LexResult, Tok};
|
use rustpython_parser::lexer::{LexResult, Tok};
|
||||||
|
|
||||||
use crate::registry::LintSource;
|
use crate::registry::LintSource;
|
||||||
use crate::Settings;
|
use crate::{violations, Settings};
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
pub struct Flags: u32 {
|
pub struct Flags: u32 {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use crate::autofix::Fix;
|
||||||
use crate::eradicate::detection::comment_contains_code;
|
use crate::eradicate::detection::comment_contains_code;
|
||||||
use crate::registry::{CheckCode, CheckKind};
|
use crate::registry::{CheckCode, CheckKind};
|
||||||
use crate::settings::flags;
|
use crate::settings::flags;
|
||||||
use crate::{Check, Settings, SourceCodeLocator};
|
use crate::{violations, Check, Settings, SourceCodeLocator};
|
||||||
|
|
||||||
fn is_standalone_comment(line: &str) -> bool {
|
fn is_standalone_comment(line: &str) -> bool {
|
||||||
for char in line.chars() {
|
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.
|
// 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[..]) {
|
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)
|
if matches!(autofix, flags::Autofix::Enabled)
|
||||||
&& settings.fixable.contains(&CheckCode::ERA001)
|
&& settings.fixable.contains(&CheckCode::ERA001)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::settings;
|
use crate::{settings, violations};
|
||||||
|
|
||||||
#[test_case(CheckCode::ERA001, Path::new("ERA001.py"); "ERA001")]
|
#[test_case(CheckCode::ERA001, Path::new("ERA001.py"); "ERA001")]
|
||||||
fn checks(check_code: CheckCode, path: &Path) -> Result<()> {
|
fn checks(check_code: CheckCode, path: &Path) -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::settings;
|
use crate::{settings, violations};
|
||||||
|
|
||||||
#[test_case(CheckCode::YTT101, Path::new("YTT101.py"); "YTT101")]
|
#[test_case(CheckCode::YTT101, Path::new("YTT101.py"); "YTT101")]
|
||||||
#[test_case(CheckCode::YTT102, Path::new("YTT102.py"); "YTT102")]
|
#[test_case(CheckCode::YTT102, Path::new("YTT102.py"); "YTT102")]
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::ast::helpers::match_module_member;
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckCode, CheckKind};
|
use crate::registry::{Check, CheckCode, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn is_sys(checker: &Checker, expr: &Expr, target: &str) -> bool {
|
fn is_sys(checker: &Checker, expr: &Expr, target: &str) -> bool {
|
||||||
match_module_member(
|
match_module_member(
|
||||||
|
|
@ -35,14 +36,14 @@ pub fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) {
|
||||||
&& checker.settings.enabled.contains(&CheckCode::YTT303)
|
&& checker.settings.enabled.contains(&CheckCode::YTT303)
|
||||||
{
|
{
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::SysVersionSlice1Referenced,
|
violations::SysVersionSlice1Referenced,
|
||||||
Range::from_located(value),
|
Range::from_located(value),
|
||||||
));
|
));
|
||||||
} else if *i == BigInt::from(3)
|
} else if *i == BigInt::from(3)
|
||||||
&& checker.settings.enabled.contains(&CheckCode::YTT101)
|
&& checker.settings.enabled.contains(&CheckCode::YTT101)
|
||||||
{
|
{
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::SysVersionSlice3Referenced,
|
violations::SysVersionSlice3Referenced,
|
||||||
Range::from_located(value),
|
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) {
|
if *i == BigInt::from(2) && checker.settings.enabled.contains(&CheckCode::YTT102) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::SysVersion2Referenced,
|
violations::SysVersion2Referenced,
|
||||||
Range::from_located(value),
|
Range::from_located(value),
|
||||||
));
|
));
|
||||||
} else if *i == BigInt::from(0)
|
} else if *i == BigInt::from(0)
|
||||||
&& checker.settings.enabled.contains(&CheckCode::YTT301)
|
&& checker.settings.enabled.contains(&CheckCode::YTT301)
|
||||||
{
|
{
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::SysVersion0Referenced,
|
violations::SysVersion0Referenced,
|
||||||
Range::from_located(value),
|
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.settings.enabled.contains(&CheckCode::YTT201)
|
||||||
{
|
{
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::SysVersionInfo0Eq3Referenced,
|
violations::SysVersionInfo0Eq3Referenced,
|
||||||
Range::from_located(left),
|
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) {
|
if checker.settings.enabled.contains(&CheckCode::YTT203) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::SysVersionInfo1CmpInt,
|
violations::SysVersionInfo1CmpInt,
|
||||||
Range::from_located(left),
|
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) {
|
if checker.settings.enabled.contains(&CheckCode::YTT204) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::SysVersionInfoMinorCmpInt,
|
violations::SysVersionInfoMinorCmpInt,
|
||||||
Range::from_located(left),
|
Range::from_located(left),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -171,13 +172,13 @@ pub fn compare(checker: &mut Checker, left: &Expr, ops: &[Cmpop], comparators: &
|
||||||
if s.len() == 1 {
|
if s.len() == 1 {
|
||||||
if checker.settings.enabled.contains(&CheckCode::YTT302) {
|
if checker.settings.enabled.contains(&CheckCode::YTT302) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::SysVersionCmpStr10,
|
violations::SysVersionCmpStr10,
|
||||||
Range::from_located(left),
|
Range::from_located(left),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else if checker.settings.enabled.contains(&CheckCode::YTT103) {
|
} else if checker.settings.enabled.contains(&CheckCode::YTT103) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::SysVersionCmpStr3,
|
violations::SysVersionCmpStr3,
|
||||||
Range::from_located(left),
|
Range::from_located(left),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -195,7 +196,7 @@ pub fn name_or_attribute(checker: &mut Checker, expr: &Expr) {
|
||||||
&checker.import_aliases,
|
&checker.import_aliases,
|
||||||
) {
|
) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::SixPY3Referenced,
|
violations::SixPY3Referenced,
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::{flake8_annotations, Settings};
|
use crate::{flake8_annotations, violations, Settings};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn defaults() -> Result<()> {
|
fn defaults() -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use crate::flake8_annotations::fixes;
|
||||||
use crate::flake8_annotations::helpers::match_function_def;
|
use crate::flake8_annotations::helpers::match_function_def;
|
||||||
use crate::registry::{CheckCode, CheckKind};
|
use crate::registry::{CheckCode, CheckKind};
|
||||||
use crate::visibility::Visibility;
|
use crate::visibility::Visibility;
|
||||||
use crate::{visibility, Check};
|
use crate::{violations, visibility, Check};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct ReturnStatementVisitor<'a> {
|
struct ReturnStatementVisitor<'a> {
|
||||||
|
|
@ -58,7 +58,7 @@ where
|
||||||
{
|
{
|
||||||
if checker.match_typing_expr(annotation, "Any") {
|
if checker.match_typing_expr(annotation, "Any") {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::DynamicallyTypedExpression(func()),
|
violations::DynamicallyTypedExpression(func()),
|
||||||
Range::from_located(annotation),
|
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) {
|
if checker.settings.enabled.contains(&CheckCode::ANN001) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingTypeFunctionArgument(arg.node.arg.to_string()),
|
violations::MissingTypeFunctionArgument(arg.node.arg.to_string()),
|
||||||
Range::from_located(arg),
|
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) {
|
if checker.settings.enabled.contains(&CheckCode::ANN002) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingTypeArgs(arg.node.arg.to_string()),
|
violations::MissingTypeArgs(arg.node.arg.to_string()),
|
||||||
Range::from_located(arg),
|
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) {
|
if checker.settings.enabled.contains(&CheckCode::ANN003) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingTypeKwargs(arg.node.arg.to_string()),
|
violations::MissingTypeKwargs(arg.node.arg.to_string()),
|
||||||
Range::from_located(arg),
|
Range::from_located(arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -166,7 +166,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V
|
||||||
Visibility::Public => {
|
Visibility::Public => {
|
||||||
if checker.settings.enabled.contains(&CheckCode::ANN201) {
|
if checker.settings.enabled.contains(&CheckCode::ANN201) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingReturnTypePublicFunction(name.to_string()),
|
violations::MissingReturnTypePublicFunction(name.to_string()),
|
||||||
helpers::identifier_range(stmt, checker.locator),
|
helpers::identifier_range(stmt, checker.locator),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -174,7 +174,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V
|
||||||
Visibility::Private => {
|
Visibility::Private => {
|
||||||
if checker.settings.enabled.contains(&CheckCode::ANN202) {
|
if checker.settings.enabled.contains(&CheckCode::ANN202) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingReturnTypePrivateFunction(name.to_string()),
|
violations::MissingReturnTypePrivateFunction(name.to_string()),
|
||||||
helpers::identifier_range(stmt, checker.locator),
|
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) {
|
if checker.settings.enabled.contains(&CheckCode::ANN001) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingTypeFunctionArgument(arg.node.arg.to_string()),
|
violations::MissingTypeFunctionArgument(arg.node.arg.to_string()),
|
||||||
Range::from_located(arg),
|
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) {
|
if checker.settings.enabled.contains(&CheckCode::ANN002) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingTypeArgs(arg.node.arg.to_string()),
|
violations::MissingTypeArgs(arg.node.arg.to_string()),
|
||||||
Range::from_located(arg),
|
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) {
|
if checker.settings.enabled.contains(&CheckCode::ANN003) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingTypeKwargs(arg.node.arg.to_string()),
|
violations::MissingTypeKwargs(arg.node.arg.to_string()),
|
||||||
Range::from_located(arg),
|
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 visibility::is_classmethod(checker, cast::decorator_list(stmt)) {
|
||||||
if checker.settings.enabled.contains(&CheckCode::ANN102) {
|
if checker.settings.enabled.contains(&CheckCode::ANN102) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingTypeCls(arg.node.arg.to_string()),
|
violations::MissingTypeCls(arg.node.arg.to_string()),
|
||||||
Range::from_located(arg),
|
Range::from_located(arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if checker.settings.enabled.contains(&CheckCode::ANN101) {
|
if checker.settings.enabled.contains(&CheckCode::ANN101) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingTypeSelf(arg.node.arg.to_string()),
|
violations::MissingTypeSelf(arg.node.arg.to_string()),
|
||||||
Range::from_located(arg),
|
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 visibility::is_classmethod(checker, cast::decorator_list(stmt)) {
|
||||||
if checker.settings.enabled.contains(&CheckCode::ANN206) {
|
if checker.settings.enabled.contains(&CheckCode::ANN206) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingReturnTypeClassMethod(name.to_string()),
|
violations::MissingReturnTypeClassMethod(name.to_string()),
|
||||||
helpers::identifier_range(stmt, checker.locator),
|
helpers::identifier_range(stmt, checker.locator),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else if visibility::is_staticmethod(checker, cast::decorator_list(stmt)) {
|
} else if visibility::is_staticmethod(checker, cast::decorator_list(stmt)) {
|
||||||
if checker.settings.enabled.contains(&CheckCode::ANN205) {
|
if checker.settings.enabled.contains(&CheckCode::ANN205) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingReturnTypeStaticMethod(name.to_string()),
|
violations::MissingReturnTypeStaticMethod(name.to_string()),
|
||||||
helpers::identifier_range(stmt, checker.locator),
|
helpers::identifier_range(stmt, checker.locator),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -327,7 +327,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V
|
||||||
&& has_any_typed_arg)
|
&& has_any_typed_arg)
|
||||||
{
|
{
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::MissingReturnTypeSpecialMethod(name.to_string()),
|
violations::MissingReturnTypeSpecialMethod(name.to_string()),
|
||||||
helpers::identifier_range(stmt, checker.locator),
|
helpers::identifier_range(stmt, checker.locator),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
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) {
|
} else if visibility::is_magic(stmt) {
|
||||||
if checker.settings.enabled.contains(&CheckCode::ANN204) {
|
if checker.settings.enabled.contains(&CheckCode::ANN204) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingReturnTypeSpecialMethod(name.to_string()),
|
violations::MissingReturnTypeSpecialMethod(name.to_string()),
|
||||||
helpers::identifier_range(stmt, checker.locator),
|
helpers::identifier_range(stmt, checker.locator),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -353,7 +353,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V
|
||||||
Visibility::Public => {
|
Visibility::Public => {
|
||||||
if checker.settings.enabled.contains(&CheckCode::ANN201) {
|
if checker.settings.enabled.contains(&CheckCode::ANN201) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingReturnTypePublicFunction(name.to_string()),
|
violations::MissingReturnTypePublicFunction(name.to_string()),
|
||||||
helpers::identifier_range(stmt, checker.locator),
|
helpers::identifier_range(stmt, checker.locator),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -361,7 +361,7 @@ pub fn definition(checker: &mut Checker, definition: &Definition, visibility: &V
|
||||||
Visibility::Private => {
|
Visibility::Private => {
|
||||||
if checker.settings.enabled.contains(&CheckCode::ANN202) {
|
if checker.settings.enabled.contains(&CheckCode::ANN202) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingReturnTypePrivateFunction(name.to_string()),
|
violations::MissingReturnTypePrivateFunction(name.to_string()),
|
||||||
helpers::identifier_range(stmt, checker.locator),
|
helpers::identifier_range(stmt, checker.locator),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,9 @@ use rustpython_ast::{Located, StmtKind};
|
||||||
|
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// S101
|
/// S101
|
||||||
pub fn assert_used(stmt: &Located<StmtKind>) -> Check {
|
pub fn assert_used(stmt: &Located<StmtKind>) -> Check {
|
||||||
Check::new(CheckKind::AssertUsed, Range::from_located(stmt))
|
Check::new(violations::AssertUsed, Range::from_located(stmt))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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::helpers::{compose_call_path, match_module_member, SimpleCallArgs};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
const WRITE_WORLD: u16 = 0o2;
|
const WRITE_WORLD: u16 = 0o2;
|
||||||
const EXECUTE_GROUP: u16 = 0o10;
|
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 let Some(int_value) = get_int_value(mode_arg) {
|
||||||
if (int_value & WRITE_WORLD > 0) || (int_value & EXECUTE_GROUP > 0) {
|
if (int_value & WRITE_WORLD > 0) || (int_value & EXECUTE_GROUP > 0) {
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::BadFilePermissions(int_value),
|
violations::BadFilePermissions(int_value),
|
||||||
Range::from_located(mode_arg),
|
Range::from_located(mode_arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use rustpython_ast::{Expr, ExprKind};
|
||||||
|
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// S102
|
/// S102
|
||||||
pub fn exec_used(expr: &Expr, func: &Expr) -> Option<Check> {
|
pub fn exec_used(expr: &Expr, func: &Expr) -> Option<Check> {
|
||||||
|
|
@ -11,5 +12,5 @@ pub fn exec_used(expr: &Expr, func: &Expr) -> Option<Check> {
|
||||||
if id != "exec" {
|
if id != "exec" {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(Check::new(CheckKind::ExecUsed, Range::from_located(expr)))
|
Some(Check::new(violations::ExecUsed, Range::from_located(expr)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// S104
|
/// S104
|
||||||
pub fn hardcoded_bind_all_interfaces(value: &str, range: &Range) -> Option<Check> {
|
pub fn hardcoded_bind_all_interfaces(value: &str, range: &Range) -> Option<Check> {
|
||||||
if value == "0.0.0.0" {
|
if value == "0.0.0.0" {
|
||||||
Some(Check::new(CheckKind::HardcodedBindAllInterfaces, *range))
|
Some(Check::new(violations::HardcodedBindAllInterfaces, *range))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::{ArgData, Arguments, Expr, Located};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::flake8_bandit::helpers::{matches_password_name, string_literal};
|
use crate::flake8_bandit::helpers::{matches_password_name, string_literal};
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn check_password_kwarg(arg: &Located<ArgData>, default: &Expr) -> Option<Check> {
|
fn check_password_kwarg(arg: &Located<ArgData>, default: &Expr) -> Option<Check> {
|
||||||
let string = string_literal(default)?;
|
let string = string_literal(default)?;
|
||||||
|
|
@ -11,7 +12,7 @@ fn check_password_kwarg(arg: &Located<ArgData>, default: &Expr) -> Option<Check>
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(Check::new(
|
Some(Check::new(
|
||||||
CheckKind::HardcodedPasswordDefault(string.to_string()),
|
violations::HardcodedPasswordDefault(string.to_string()),
|
||||||
Range::from_located(default),
|
Range::from_located(default),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::Keyword;
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::flake8_bandit::helpers::{matches_password_name, string_literal};
|
use crate::flake8_bandit::helpers::{matches_password_name, string_literal};
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// S106
|
/// S106
|
||||||
pub fn hardcoded_password_func_arg(keywords: &[Keyword]) -> Vec<Check> {
|
pub fn hardcoded_password_func_arg(keywords: &[Keyword]) -> Vec<Check> {
|
||||||
|
|
@ -15,7 +16,7 @@ pub fn hardcoded_password_func_arg(keywords: &[Keyword]) -> Vec<Check> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(Check::new(
|
Some(Check::new(
|
||||||
CheckKind::HardcodedPasswordFuncArg(string.to_string()),
|
violations::HardcodedPasswordFuncArg(string.to_string()),
|
||||||
Range::from_located(keyword),
|
Range::from_located(keyword),
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::{Constant, Expr, ExprKind};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::flake8_bandit::helpers::{matches_password_name, string_literal};
|
use crate::flake8_bandit::helpers::{matches_password_name, string_literal};
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn is_password_target(target: &Expr) -> bool {
|
fn is_password_target(target: &Expr) -> bool {
|
||||||
let target_name = match &target.node {
|
let target_name = match &target.node {
|
||||||
|
|
@ -34,7 +35,7 @@ pub fn compare_to_hardcoded_password_string(left: &Expr, comparators: &[Expr]) -
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(Check::new(
|
Some(Check::new(
|
||||||
CheckKind::HardcodedPasswordString(string.to_string()),
|
violations::HardcodedPasswordString(string.to_string()),
|
||||||
Range::from_located(comp),
|
Range::from_located(comp),
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
@ -47,7 +48,7 @@ pub fn assign_hardcoded_password_string(value: &Expr, targets: &[Expr]) -> Optio
|
||||||
for target in targets {
|
for target in targets {
|
||||||
if is_password_target(target) {
|
if is_password_target(target) {
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::HardcodedPasswordString(string.to_string()),
|
violations::HardcodedPasswordString(string.to_string()),
|
||||||
Range::from_located(value),
|
Range::from_located(value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,13 @@ use rustpython_ast::Expr;
|
||||||
|
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// S108
|
/// S108
|
||||||
pub fn hardcoded_tmp_directory(expr: &Expr, value: &str, prefixes: &[String]) -> Option<Check> {
|
pub fn hardcoded_tmp_directory(expr: &Expr, value: &str, prefixes: &[String]) -> Option<Check> {
|
||||||
if prefixes.iter().any(|prefix| value.starts_with(prefix)) {
|
if prefixes.iter().any(|prefix| value.starts_with(prefix)) {
|
||||||
Some(Check::new(
|
Some(Check::new(
|
||||||
CheckKind::HardcodedTempFile(value.to_string()),
|
violations::HardcodedTempFile(value.to_string()),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::ast::helpers::{match_module_member, SimpleCallArgs};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::flake8_bandit::helpers::string_literal;
|
use crate::flake8_bandit::helpers::string_literal;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
const WEAK_HASHES: [&str; 4] = ["md4", "md5", "sha", "sha1"];
|
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()) {
|
if WEAK_HASHES.contains(&hash_func_name.to_lowercase().as_str()) {
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::HashlibInsecureHashFunction(hash_func_name.to_string()),
|
violations::HashlibInsecureHashFunction(hash_func_name.to_string()),
|
||||||
Range::from_located(name_arg),
|
Range::from_located(name_arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -56,7 +57,7 @@ pub fn hashlib_insecure_hash_functions(
|
||||||
}
|
}
|
||||||
|
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::HashlibInsecureHashFunction((*func_name).to_string()),
|
violations::HashlibInsecureHashFunction((*func_name).to_string()),
|
||||||
Range::from_located(func),
|
Range::from_located(func),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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::helpers::{collect_call_paths, dealias_call_path, match_call_path, SimpleCallArgs};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
const REQUESTS_HTTP_VERBS: [&str; 7] = ["get", "options", "head", "post", "put", "patch", "delete"];
|
const REQUESTS_HTTP_VERBS: [&str; 7] = ["get", "options", "head", "post", "put", "patch", "delete"];
|
||||||
const HTTPX_METHODS: [&str; 11] = [
|
const HTTPX_METHODS: [&str; 11] = [
|
||||||
|
|
@ -41,7 +42,7 @@ pub fn request_with_no_cert_validation(
|
||||||
} = &verify_arg.node
|
} = &verify_arg.node
|
||||||
{
|
{
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::RequestWithNoCertValidation("requests".to_string()),
|
violations::RequestWithNoCertValidation("requests".to_string()),
|
||||||
Range::from_located(verify_arg),
|
Range::from_located(verify_arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +59,7 @@ pub fn request_with_no_cert_validation(
|
||||||
} = &verify_arg.node
|
} = &verify_arg.node
|
||||||
{
|
{
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::RequestWithNoCertValidation("httpx".to_string()),
|
violations::RequestWithNoCertValidation("httpx".to_string()),
|
||||||
Range::from_located(verify_arg),
|
Range::from_located(verify_arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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::helpers::{collect_call_paths, dealias_call_path, match_call_path, SimpleCallArgs};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
const HTTP_VERBS: [&str; 7] = ["get", "options", "head", "post", "put", "patch", "delete"];
|
const HTTP_VERBS: [&str; 7] = ["get", "options", "head", "post", "put", "patch", "delete"];
|
||||||
|
|
||||||
|
|
@ -29,13 +30,13 @@ pub fn request_without_timeout(
|
||||||
_ => None,
|
_ => None,
|
||||||
} {
|
} {
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::RequestWithoutTimeout(Some(timeout)),
|
violations::RequestWithoutTimeout(Some(timeout)),
|
||||||
Range::from_located(timeout_arg),
|
Range::from_located(timeout_arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::RequestWithoutTimeout(None),
|
violations::RequestWithoutTimeout(None),
|
||||||
Range::from_located(func),
|
Range::from_located(func),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use rustpython_ast::{Expr, ExprKind, Keyword};
|
||||||
use crate::ast::helpers::{match_module_member, SimpleCallArgs};
|
use crate::ast::helpers::{match_module_member, SimpleCallArgs};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// S506
|
/// S506
|
||||||
pub fn unsafe_yaml_load(
|
pub fn unsafe_yaml_load(
|
||||||
|
|
@ -35,13 +36,13 @@ pub fn unsafe_yaml_load(
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::UnsafeYAMLLoad(loader),
|
violations::UnsafeYAMLLoad(loader),
|
||||||
Range::from_located(loader_arg),
|
Range::from_located(loader_arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::UnsafeYAMLLoad(None),
|
violations::UnsafeYAMLLoad(None),
|
||||||
Range::from_located(func),
|
Range::from_located(func),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
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::S101, Path::new("S101.py"); "S101")]
|
||||||
#[test_case(CheckCode::S102, Path::new("S102.py"); "S102")]
|
#[test_case(CheckCode::S102, Path::new("S102.py"); "S102")]
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::settings;
|
use crate::{settings, violations};
|
||||||
|
|
||||||
#[test_case(CheckCode::BLE001, Path::new("BLE.py"); "BLE001")]
|
#[test_case(CheckCode::BLE001, Path::new("BLE.py"); "BLE001")]
|
||||||
fn checks(check_code: CheckCode, path: &Path) -> Result<()> {
|
fn checks(check_code: CheckCode, path: &Path) -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::{Expr, ExprKind, Stmt, StmtKind};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// BLE001
|
/// BLE001
|
||||||
pub fn blind_except(
|
pub fn blind_except(
|
||||||
|
|
@ -36,7 +37,7 @@ pub fn blind_except(
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::BlindExcept(id.to_string()),
|
violations::BlindExcept(id.to_string()),
|
||||||
Range::from_located(type_),
|
Range::from_located(type_),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::settings;
|
use crate::{settings, violations};
|
||||||
|
|
||||||
#[test_case(CheckCode::FBT001, Path::new("FBT.py"); "FBT001")]
|
#[test_case(CheckCode::FBT001, Path::new("FBT.py"); "FBT001")]
|
||||||
#[test_case(CheckCode::FBT002, Path::new("FBT.py"); "FBT002")]
|
#[test_case(CheckCode::FBT002, Path::new("FBT.py"); "FBT002")]
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use rustpython_parser::ast::{Constant, Expr};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
const FUNC_NAME_ALLOWLIST: &[&str] = &[
|
const FUNC_NAME_ALLOWLIST: &[&str] = &[
|
||||||
"assertEqual",
|
"assertEqual",
|
||||||
|
|
@ -76,7 +77,7 @@ pub fn check_positional_boolean_in_def(checker: &mut Checker, arguments: &Argume
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::BooleanPositionalArgInFunctionDefinition,
|
violations::BooleanPositionalArgInFunctionDefinition,
|
||||||
Range::from_located(arg),
|
Range::from_located(arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +91,7 @@ pub fn check_boolean_default_value_in_function_definition(
|
||||||
add_if_boolean(
|
add_if_boolean(
|
||||||
checker,
|
checker,
|
||||||
arg,
|
arg,
|
||||||
CheckKind::BooleanDefaultValueInFunctionDefinition,
|
violations::BooleanDefaultValueInFunctionDefinition,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +108,7 @@ pub fn check_boolean_positional_value_in_function_call(
|
||||||
add_if_boolean(
|
add_if_boolean(
|
||||||
checker,
|
checker,
|
||||||
arg,
|
arg,
|
||||||
CheckKind::BooleanPositionalValueInFunctionCall,
|
violations::BooleanPositionalValueInFunctionCall,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
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::B002, Path::new("B002.py"); "B002")]
|
||||||
#[test_case(CheckCode::B003, Path::new("B003.py"); "B003")]
|
#[test_case(CheckCode::B003, Path::new("B003.py"); "B003")]
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::ast::helpers::match_module_member;
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckCode, CheckKind};
|
use crate::registry::{Check, CheckCode, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn is_abc_class(
|
fn is_abc_class(
|
||||||
bases: &[Expr],
|
bases: &[Expr],
|
||||||
|
|
@ -118,7 +119,7 @@ pub fn abstract_base_class(
|
||||||
.any(|d| is_overload(d, &checker.from_imports, &checker.import_aliases))
|
.any(|d| is_overload(d, &checker.from_imports, &checker.import_aliases))
|
||||||
{
|
{
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::EmptyMethodWithoutAbstractDecorator(name.to_string()),
|
violations::EmptyMethodWithoutAbstractDecorator(name.to_string()),
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -126,7 +127,7 @@ pub fn abstract_base_class(
|
||||||
if checker.settings.enabled.contains(&CheckCode::B024) {
|
if checker.settings.enabled.contains(&CheckCode::B024) {
|
||||||
if !has_abstract_method {
|
if !has_abstract_method {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::AbstractBaseClassWithoutAbstractMethod(name.to_string()),
|
violations::AbstractBaseClassWithoutAbstractMethod(name.to_string()),
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::autofix::Fix;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
use crate::source_code_generator::SourceCodeGenerator;
|
use crate::source_code_generator::SourceCodeGenerator;
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn assertion_error(msg: Option<&Expr>) -> Stmt {
|
fn assertion_error(msg: Option<&Expr>) -> Stmt {
|
||||||
Stmt::new(
|
Stmt::new(
|
||||||
|
|
@ -45,7 +46,7 @@ pub fn assert_false(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg: Option
|
||||||
return;
|
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()) {
|
if checker.patch(check.kind.code()) {
|
||||||
let mut generator: SourceCodeGenerator = checker.style.into();
|
let mut generator: SourceCodeGenerator = checker.style.into();
|
||||||
generator.unparse_stmt(&assertion_error(msg));
|
generator.unparse_stmt(&assertion_error(msg));
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use crate::ast::helpers::match_module_member;
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// B017
|
/// B017
|
||||||
pub fn assert_raises_exception(checker: &mut Checker, stmt: &Stmt, items: &[Withitem]) {
|
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(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::NoAssertRaisesException,
|
violations::NoAssertRaisesException,
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::{Expr, ExprKind};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// B003
|
/// B003
|
||||||
pub fn assignment_to_os_environ(checker: &mut Checker, targets: &[Expr]) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::AssignmentToOsEnviron,
|
violations::AssignmentToOsEnviron,
|
||||||
Range::from_located(target),
|
Range::from_located(target),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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::ast::types::{Range, ScopeKind};
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn is_cache_func(checker: &Checker, expr: &Expr) -> bool {
|
fn is_cache_func(checker: &Checker, expr: &Expr) -> bool {
|
||||||
let call_path = dealias_call_path(collect_call_paths(expr), &checker.import_aliases);
|
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(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::CachedInstanceMethod,
|
violations::CachedInstanceMethod,
|
||||||
Range::from_located(decorator),
|
Range::from_located(decorator),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::{Expr, ExprKind};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// B016
|
/// B016
|
||||||
pub fn cannot_raise_literal(checker: &mut Checker, expr: &Expr) {
|
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;
|
return;
|
||||||
};
|
};
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::CannotRaiseLiteral,
|
violations::CannotRaiseLiteral,
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use crate::autofix::Fix;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckCode, CheckKind};
|
use crate::registry::{Check, CheckCode, CheckKind};
|
||||||
use crate::source_code_generator::SourceCodeGenerator;
|
use crate::source_code_generator::SourceCodeGenerator;
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn type_pattern(elts: Vec<&Expr>) -> Expr {
|
fn type_pattern(elts: Vec<&Expr>) -> Expr {
|
||||||
Expr::new(
|
Expr::new(
|
||||||
|
|
@ -44,7 +45,7 @@ fn duplicate_handler_exceptions<'a>(
|
||||||
// TODO(charlie): Handle "BaseException" and redundant exception aliases.
|
// TODO(charlie): Handle "BaseException" and redundant exception aliases.
|
||||||
if !duplicates.is_empty() {
|
if !duplicates.is_empty() {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::DuplicateHandlerException(
|
violations::DuplicateHandlerException(
|
||||||
duplicates
|
duplicates
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|call_path| call_path.join("."))
|
.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 (name, exprs) in duplicates {
|
||||||
for expr in exprs {
|
for expr in exprs {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::DuplicateTryBlockException(name.join(".")),
|
violations::DuplicateTryBlockException(name.join(".")),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::{ExprKind, Stmt, StmtKind};
|
||||||
use crate::ast::helpers;
|
use crate::ast::helpers;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// B021
|
/// B021
|
||||||
pub fn f_string_docstring(checker: &mut Checker, body: &[Stmt]) {
|
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;
|
return;
|
||||||
};
|
};
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::FStringDocstring,
|
violations::FStringDocstring,
|
||||||
helpers::identifier_range(stmt, checker.locator),
|
helpers::identifier_range(stmt, checker.locator),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use crate::ast::visitor::Visitor;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::flake8_bugbear::plugins::mutable_argument_default::is_mutable_func;
|
use crate::flake8_bugbear::plugins::mutable_argument_default::is_mutable_func;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
const IMMUTABLE_FUNCS: [(&str, &str); 7] = [
|
const IMMUTABLE_FUNCS: [(&str, &str); 7] = [
|
||||||
("", "tuple"),
|
("", "tuple"),
|
||||||
|
|
@ -58,7 +59,7 @@ where
|
||||||
&& !is_nan_or_infinity(func, args)
|
&& !is_nan_or_infinity(func, args)
|
||||||
{
|
{
|
||||||
self.checks.push((
|
self.checks.push((
|
||||||
CheckKind::FunctionCallArgumentDefault(compose_call_path(expr)),
|
violations::FunctionCallArgumentDefault(compose_call_path(expr)),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use crate::ast::visitor;
|
||||||
use crate::ast::visitor::Visitor;
|
use crate::ast::visitor::Visitor;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct LoadedNamesVisitor<'a> {
|
struct LoadedNamesVisitor<'a> {
|
||||||
|
|
@ -212,7 +213,7 @@ where
|
||||||
if !checker.flake8_bugbear_seen.contains(&expr) {
|
if !checker.flake8_bugbear_seen.contains(&expr) {
|
||||||
checker.flake8_bugbear_seen.push(expr);
|
checker.flake8_bugbear_seen.push(expr);
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::FunctionUsesLoopVariable(name.to_string()),
|
violations::FunctionUsesLoopVariable(name.to_string()),
|
||||||
range,
|
range,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use crate::python::identifiers::IDENTIFIER_REGEX;
|
||||||
use crate::python::keyword::KWLIST;
|
use crate::python::keyword::KWLIST;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
use crate::source_code_generator::SourceCodeGenerator;
|
use crate::source_code_generator::SourceCodeGenerator;
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn attribute(value: &Expr, attr: &str) -> Expr {
|
fn attribute(value: &Expr, attr: &str) -> Expr {
|
||||||
Expr::new(
|
Expr::new(
|
||||||
|
|
@ -44,7 +45,7 @@ pub fn getattr_with_constant(checker: &mut Checker, expr: &Expr, func: &Expr, ar
|
||||||
return;
|
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()) {
|
if checker.patch(check.kind.code()) {
|
||||||
let mut generator: SourceCodeGenerator = checker.style.into();
|
let mut generator: SourceCodeGenerator = checker.style.into();
|
||||||
generator.unparse_expr(&attribute(obj, value), 0);
|
generator.unparse_expr(&attribute(obj, value), 0);
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,13 @@ use rustpython_ast::{Stmt, StmtKind};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn walk_stmt(checker: &mut Checker, body: &[Stmt], f: fn(&Stmt) -> bool) {
|
fn walk_stmt(checker: &mut Checker, body: &[Stmt], f: fn(&Stmt) -> bool) {
|
||||||
for stmt in body {
|
for stmt in body {
|
||||||
if f(stmt) {
|
if f(stmt) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::JumpStatementInFinally(match &stmt.node {
|
violations::JumpStatementInFinally(match &stmt.node {
|
||||||
StmtKind::Break { .. } => "break".to_string(),
|
StmtKind::Break { .. } => "break".to_string(),
|
||||||
StmtKind::Continue { .. } => "continue".to_string(),
|
StmtKind::Continue { .. } => "continue".to_string(),
|
||||||
StmtKind::Return { .. } => "return".to_string(),
|
StmtKind::Return { .. } => "return".to_string(),
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use crate::ast::visitor;
|
||||||
use crate::ast::visitor::Visitor;
|
use crate::ast::visitor::Visitor;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct NameFinder<'a> {
|
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 {
|
for (name, expr) in target_names {
|
||||||
if iter_names.contains_key(name) {
|
if iter_names.contains_key(name) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::LoopVariableOverridesIterator(name.to_string()),
|
violations::LoopVariableOverridesIterator(name.to_string()),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::ast::helpers::{collect_call_paths, dealias_call_path, match_call_path
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
const MUTABLE_FUNCS: &[(&str, &str)] = &[
|
const MUTABLE_FUNCS: &[(&str, &str)] = &[
|
||||||
("", "dict"),
|
("", "dict"),
|
||||||
|
|
@ -165,7 +166,7 @@ pub fn mutable_argument_default(checker: &mut Checker, arguments: &Arguments) {
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MutableArgumentDefault,
|
violations::MutableArgumentDefault,
|
||||||
Range::from_located(default),
|
Range::from_located(default),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::ast::visitor::Visitor;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::python::string::is_lower;
|
use crate::python::string::is_lower;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
struct RaiseVisitor {
|
struct RaiseVisitor {
|
||||||
checks: Vec<Check>,
|
checks: Vec<Check>,
|
||||||
|
|
@ -20,7 +21,7 @@ impl<'a> Visitor<'a> for RaiseVisitor {
|
||||||
ExprKind::Name { id, .. } if is_lower(id) => {}
|
ExprKind::Name { id, .. } if is_lower(id) => {}
|
||||||
_ => {
|
_ => {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::RaiseWithoutFromInsideExcept,
|
violations::RaiseWithoutFromInsideExcept,
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::autofix::Fix;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
use crate::source_code_generator::SourceCodeGenerator;
|
use crate::source_code_generator::SourceCodeGenerator;
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// B013
|
/// B013
|
||||||
pub fn redundant_tuple_in_exception_handler(checker: &mut Checker, handlers: &[Excepthandler]) {
|
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;
|
continue;
|
||||||
};
|
};
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::RedundantTupleInExceptionHandler(elt.to_string()),
|
violations::RedundantTupleInExceptionHandler(elt.to_string()),
|
||||||
Range::from_located(type_),
|
Range::from_located(type_),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use crate::python::keyword::KWLIST;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
use crate::source_code_generator::SourceCodeGenerator;
|
use crate::source_code_generator::SourceCodeGenerator;
|
||||||
use crate::source_code_style::SourceCodeStyleDetector;
|
use crate::source_code_style::SourceCodeStyleDetector;
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn assignment(obj: &Expr, name: &str, value: &Expr, stylist: &SourceCodeStyleDetector) -> String {
|
fn assignment(obj: &Expr, name: &str, value: &Expr, stylist: &SourceCodeStyleDetector) -> String {
|
||||||
let stmt = Stmt::new(
|
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`).
|
// (i.e., it's directly within an `StmtKind::Expr`).
|
||||||
if let StmtKind::Expr { value: child } = &checker.current_stmt().node {
|
if let StmtKind::Expr { value: child } = &checker.current_stmt().node {
|
||||||
if expr == child.as_ref() {
|
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()) {
|
if checker.patch(check.kind.code()) {
|
||||||
check.amend(Fix::replacement(
|
check.amend(Fix::replacement(
|
||||||
assignment(obj, name, value, checker.style),
|
assignment(obj, name, value, checker.style),
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::{Expr, ExprKind, Keyword};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// B026
|
/// B026
|
||||||
pub fn star_arg_unpacking_after_keyword_arg(
|
pub fn star_arg_unpacking_after_keyword_arg(
|
||||||
|
|
@ -21,7 +22,7 @@ pub fn star_arg_unpacking_after_keyword_arg(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::StarArgUnpackingAfterKeywordArg,
|
violations::StarArgUnpackingAfterKeywordArg,
|
||||||
Range::from_located(arg),
|
Range::from_located(arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use rustpython_ast::{Constant, Expr, ExprKind};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// B005
|
/// B005
|
||||||
pub fn strip_with_multi_characters(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) {
|
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() {
|
if value.len() > 1 && value.chars().unique().count() != value.len() {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::StripWithMultiCharacters,
|
violations::StripWithMultiCharacters,
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::{Expr, ExprKind, Unaryop};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// B002
|
/// B002
|
||||||
pub fn unary_prefix_increment(checker: &mut Checker, expr: &Expr, op: &Unaryop, operand: &Expr) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::UnaryPrefixIncrement,
|
violations::UnaryPrefixIncrement,
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::{Constant, Expr, ExprKind};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// B004
|
/// B004
|
||||||
pub fn unreliable_callable_check(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::UnreliableCallableCheck,
|
violations::UnreliableCallableCheck,
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use crate::ast::visitor::Visitor;
|
||||||
use crate::autofix::Fix;
|
use crate::autofix::Fix;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// Identify all `ExprKind::Name` nodes in an AST.
|
/// Identify all `ExprKind::Name` nodes in an AST.
|
||||||
struct NameFinder<'a> {
|
struct NameFinder<'a> {
|
||||||
|
|
@ -62,7 +63,7 @@ pub fn unused_loop_control_variable(checker: &mut Checker, target: &Expr, body:
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UnusedLoopControlVariable(name.to_string()),
|
violations::UnusedLoopControlVariable(name.to_string()),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,12 @@ use rustpython_ast::{Expr, ExprKind};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
pub fn useless_comparison(checker: &mut Checker, expr: &Expr) {
|
pub fn useless_comparison(checker: &mut Checker, expr: &Expr) {
|
||||||
if matches!(expr.node, ExprKind::Compare { .. }) {
|
if matches!(expr.node, ExprKind::Compare { .. }) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::UselessComparison,
|
violations::UselessComparison,
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use crate::ast::helpers::{collect_call_paths, match_call_path};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// B005
|
/// B005
|
||||||
pub fn useless_contextlib_suppress(checker: &mut Checker, expr: &Expr, args: &[Expr]) {
|
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()
|
) && args.is_empty()
|
||||||
{
|
{
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::UselessContextlibSuppress,
|
violations::UselessContextlibSuppress,
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::{Constant, ExprKind, Stmt, StmtKind};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
// B018
|
// B018
|
||||||
pub fn useless_expression(checker: &mut Checker, body: &[Stmt]) {
|
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 {
|
match &value.node {
|
||||||
ExprKind::List { .. } | ExprKind::Dict { .. } | ExprKind::Set { .. } => {
|
ExprKind::List { .. } | ExprKind::Dict { .. } | ExprKind::Set { .. } => {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::UselessExpression,
|
violations::UselessExpression,
|
||||||
Range::from_located(value),
|
Range::from_located(value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -19,7 +20,7 @@ pub fn useless_expression(checker: &mut Checker, body: &[Stmt]) {
|
||||||
Constant::Str { .. } | Constant::Ellipsis => {}
|
Constant::Str { .. } | Constant::Ellipsis => {}
|
||||||
_ => {
|
_ => {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::UselessExpression,
|
violations::UselessExpression,
|
||||||
Range::from_located(value),
|
Range::from_located(value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::{Expr, ExprKind, Keyword};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// B905
|
/// B905
|
||||||
pub fn zip_without_explicit_strict(
|
pub fn zip_without_explicit_strict(
|
||||||
|
|
@ -23,7 +24,7 @@ pub fn zip_without_explicit_strict(
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::ZipWithoutExplicitStrict,
|
violations::ZipWithoutExplicitStrict,
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use crate::ast::types::Range;
|
||||||
use crate::flake8_builtins::types::ShadowingType;
|
use crate::flake8_builtins::types::ShadowingType;
|
||||||
use crate::python::builtins::BUILTINS;
|
use crate::python::builtins::BUILTINS;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// Check builtin name shadowing.
|
/// Check builtin name shadowing.
|
||||||
pub fn builtin_shadowing<T>(
|
pub fn builtin_shadowing<T>(
|
||||||
|
|
@ -14,9 +15,9 @@ pub fn builtin_shadowing<T>(
|
||||||
if BUILTINS.contains(&name) {
|
if BUILTINS.contains(&name) {
|
||||||
Some(Check::new(
|
Some(Check::new(
|
||||||
match node_type {
|
match node_type {
|
||||||
ShadowingType::Variable => CheckKind::BuiltinVariableShadowing(name.to_string()),
|
ShadowingType::Variable => violations::BuiltinVariableShadowing(name.to_string()),
|
||||||
ShadowingType::Argument => CheckKind::BuiltinArgumentShadowing(name.to_string()),
|
ShadowingType::Argument => violations::BuiltinArgumentShadowing(name.to_string()),
|
||||||
ShadowingType::Attribute => CheckKind::BuiltinAttributeShadowing(name.to_string()),
|
ShadowingType::Attribute => violations::BuiltinAttributeShadowing(name.to_string()),
|
||||||
},
|
},
|
||||||
Range::from_located(located),
|
Range::from_located(located),
|
||||||
))
|
))
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::settings;
|
use crate::{settings, violations};
|
||||||
|
|
||||||
#[test_case(CheckCode::A001, Path::new("A001.py"); "A001")]
|
#[test_case(CheckCode::A001, Path::new("A001.py"); "A001")]
|
||||||
#[test_case(CheckCode::A002, Path::new("A002.py"); "A002")]
|
#[test_case(CheckCode::A002, Path::new("A002.py"); "A002")]
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use crate::ast::types::Range;
|
||||||
use crate::flake8_comprehensions::fixes;
|
use crate::flake8_comprehensions::fixes;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
use crate::source_code_locator::SourceCodeLocator;
|
use crate::source_code_locator::SourceCodeLocator;
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn function_name(func: &Expr) -> Option<&str> {
|
fn function_name(func: &Expr) -> Option<&str> {
|
||||||
if let ExprKind::Name { id, .. } = &func.node {
|
if let ExprKind::Name { id, .. } = &func.node {
|
||||||
|
|
@ -58,7 +59,7 @@ pub fn unnecessary_generator_list(
|
||||||
) -> Option<Check> {
|
) -> Option<Check> {
|
||||||
let argument = exactly_one_argument_with_matching_function("list", func, args, keywords)?;
|
let argument = exactly_one_argument_with_matching_function("list", func, args, keywords)?;
|
||||||
if let ExprKind::GeneratorExp { .. } = argument {
|
if let ExprKind::GeneratorExp { .. } = argument {
|
||||||
let mut check = Check::new(CheckKind::UnnecessaryGeneratorList, location);
|
let mut check = Check::new(violations::UnnecessaryGeneratorList, location);
|
||||||
if fix {
|
if fix {
|
||||||
match fixes::fix_unnecessary_generator_list(locator, expr) {
|
match fixes::fix_unnecessary_generator_list(locator, expr) {
|
||||||
Ok(fix) => {
|
Ok(fix) => {
|
||||||
|
|
@ -84,7 +85,7 @@ pub fn unnecessary_generator_set(
|
||||||
) -> Option<Check> {
|
) -> Option<Check> {
|
||||||
let argument = exactly_one_argument_with_matching_function("set", func, args, keywords)?;
|
let argument = exactly_one_argument_with_matching_function("set", func, args, keywords)?;
|
||||||
if let ExprKind::GeneratorExp { .. } = argument {
|
if let ExprKind::GeneratorExp { .. } = argument {
|
||||||
let mut check = Check::new(CheckKind::UnnecessaryGeneratorSet, location);
|
let mut check = Check::new(violations::UnnecessaryGeneratorSet, location);
|
||||||
if fix {
|
if fix {
|
||||||
match fixes::fix_unnecessary_generator_set(locator, expr) {
|
match fixes::fix_unnecessary_generator_set(locator, expr) {
|
||||||
Ok(fix) => {
|
Ok(fix) => {
|
||||||
|
|
@ -112,7 +113,7 @@ pub fn unnecessary_generator_dict(
|
||||||
if let ExprKind::GeneratorExp { elt, .. } = argument {
|
if let ExprKind::GeneratorExp { elt, .. } = argument {
|
||||||
match &elt.node {
|
match &elt.node {
|
||||||
ExprKind::Tuple { elts, .. } if elts.len() == 2 => {
|
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 {
|
if fix {
|
||||||
match fixes::fix_unnecessary_generator_dict(locator, expr) {
|
match fixes::fix_unnecessary_generator_dict(locator, expr) {
|
||||||
Ok(fix) => {
|
Ok(fix) => {
|
||||||
|
|
@ -141,7 +142,7 @@ pub fn unnecessary_list_comprehension_set(
|
||||||
) -> Option<Check> {
|
) -> Option<Check> {
|
||||||
let argument = exactly_one_argument_with_matching_function("set", func, args, keywords)?;
|
let argument = exactly_one_argument_with_matching_function("set", func, args, keywords)?;
|
||||||
if let ExprKind::ListComp { .. } = &argument {
|
if let ExprKind::ListComp { .. } = &argument {
|
||||||
let mut check = Check::new(CheckKind::UnnecessaryListComprehensionSet, location);
|
let mut check = Check::new(violations::UnnecessaryListComprehensionSet, location);
|
||||||
if fix {
|
if fix {
|
||||||
match fixes::fix_unnecessary_list_comprehension_set(locator, expr) {
|
match fixes::fix_unnecessary_list_comprehension_set(locator, expr) {
|
||||||
Ok(fix) => {
|
Ok(fix) => {
|
||||||
|
|
@ -175,7 +176,7 @@ pub fn unnecessary_list_comprehension_dict(
|
||||||
if elts.len() != 2 {
|
if elts.len() != 2 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let mut check = Check::new(CheckKind::UnnecessaryListComprehensionDict, location);
|
let mut check = Check::new(violations::UnnecessaryListComprehensionDict, location);
|
||||||
if fix {
|
if fix {
|
||||||
match fixes::fix_unnecessary_list_comprehension_dict(locator, expr) {
|
match fixes::fix_unnecessary_list_comprehension_dict(locator, expr) {
|
||||||
Ok(fix) => {
|
Ok(fix) => {
|
||||||
|
|
@ -203,7 +204,10 @@ pub fn unnecessary_literal_set(
|
||||||
ExprKind::Tuple { .. } => "tuple",
|
ExprKind::Tuple { .. } => "tuple",
|
||||||
_ => return None,
|
_ => 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 {
|
if fix {
|
||||||
match fixes::fix_unnecessary_literal_set(locator, expr) {
|
match fixes::fix_unnecessary_literal_set(locator, expr) {
|
||||||
Ok(fix) => {
|
Ok(fix) => {
|
||||||
|
|
@ -239,7 +243,7 @@ pub fn unnecessary_literal_dict(
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UnnecessaryLiteralDict(kind.to_string()),
|
violations::UnnecessaryLiteralDict(kind.to_string()),
|
||||||
location,
|
location,
|
||||||
);
|
);
|
||||||
if fix {
|
if fix {
|
||||||
|
|
@ -277,7 +281,7 @@ pub fn unnecessary_collection_call(
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UnnecessaryCollectionCall(id.to_string()),
|
violations::UnnecessaryCollectionCall(id.to_string()),
|
||||||
location,
|
location,
|
||||||
);
|
);
|
||||||
if fix {
|
if fix {
|
||||||
|
|
@ -307,7 +311,7 @@ pub fn unnecessary_literal_within_tuple_call(
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UnnecessaryLiteralWithinTupleCall(argument_kind.to_string()),
|
violations::UnnecessaryLiteralWithinTupleCall(argument_kind.to_string()),
|
||||||
location,
|
location,
|
||||||
);
|
);
|
||||||
if fix {
|
if fix {
|
||||||
|
|
@ -337,7 +341,7 @@ pub fn unnecessary_literal_within_list_call(
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UnnecessaryLiteralWithinListCall(argument_kind.to_string()),
|
violations::UnnecessaryLiteralWithinListCall(argument_kind.to_string()),
|
||||||
location,
|
location,
|
||||||
);
|
);
|
||||||
if fix {
|
if fix {
|
||||||
|
|
@ -364,7 +368,7 @@ pub fn unnecessary_list_call(
|
||||||
if !matches!(argument, ExprKind::ListComp { .. }) {
|
if !matches!(argument, ExprKind::ListComp { .. }) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let mut check = Check::new(CheckKind::UnnecessaryListCall, location);
|
let mut check = Check::new(violations::UnnecessaryListCall, location);
|
||||||
if fix {
|
if fix {
|
||||||
match fixes::fix_unnecessary_list_call(locator, expr) {
|
match fixes::fix_unnecessary_list_call(locator, expr) {
|
||||||
Ok(fix) => {
|
Ok(fix) => {
|
||||||
|
|
@ -397,7 +401,7 @@ pub fn unnecessary_call_around_sorted(
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UnnecessaryCallAroundSorted(outer.to_string()),
|
violations::UnnecessaryCallAroundSorted(outer.to_string()),
|
||||||
location,
|
location,
|
||||||
);
|
);
|
||||||
if fix {
|
if fix {
|
||||||
|
|
@ -419,7 +423,7 @@ pub fn unnecessary_double_cast_or_process(
|
||||||
) -> Option<Check> {
|
) -> Option<Check> {
|
||||||
fn new_check(inner: &str, outer: &str, location: Range) -> Check {
|
fn new_check(inner: &str, outer: &str, location: Range) -> Check {
|
||||||
Check::new(
|
Check::new(
|
||||||
CheckKind::UnnecessaryDoubleCastOrProcess(inner.to_string(), outer.to_string()),
|
violations::UnnecessaryDoubleCastOrProcess(inner.to_string(), outer.to_string()),
|
||||||
location,
|
location,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -490,7 +494,7 @@ pub fn unnecessary_subscript_reversal(
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
Some(Check::new(
|
Some(Check::new(
|
||||||
CheckKind::UnnecessarySubscriptReversal(id.to_string()),
|
violations::UnnecessarySubscriptReversal(id.to_string()),
|
||||||
location,
|
location,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
@ -522,7 +526,7 @@ pub fn unnecessary_comprehension(
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UnnecessaryComprehension(expr_kind.to_string()),
|
violations::UnnecessaryComprehension(expr_kind.to_string()),
|
||||||
location,
|
location,
|
||||||
);
|
);
|
||||||
if fix {
|
if fix {
|
||||||
|
|
@ -539,7 +543,7 @@ pub fn unnecessary_comprehension(
|
||||||
/// C417
|
/// C417
|
||||||
pub fn unnecessary_map(func: &Expr, args: &[Expr], location: Range) -> Option<Check> {
|
pub fn unnecessary_map(func: &Expr, args: &[Expr], location: Range) -> Option<Check> {
|
||||||
fn new_check(kind: &str, location: Range) -> Check {
|
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)?;
|
let id = function_name(func)?;
|
||||||
match id {
|
match id {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::settings;
|
use crate::{settings, violations};
|
||||||
|
|
||||||
#[test_case(CheckCode::C400, Path::new("C400.py"); "C400")]
|
#[test_case(CheckCode::C400, Path::new("C400.py"); "C400")]
|
||||||
#[test_case(CheckCode::C401, Path::new("C401.py"); "C401")]
|
#[test_case(CheckCode::C401, Path::new("C401.py"); "C401")]
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::settings;
|
use crate::{settings, violations};
|
||||||
|
|
||||||
#[test_case(CheckCode::DTZ001, Path::new("DTZ001.py"); "DTZ001")]
|
#[test_case(CheckCode::DTZ001, Path::new("DTZ001.py"); "DTZ001")]
|
||||||
#[test_case(CheckCode::DTZ002, Path::new("DTZ002.py"); "DTZ002")]
|
#[test_case(CheckCode::DTZ002, Path::new("DTZ002.py"); "DTZ002")]
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use crate::ast::helpers::{
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
pub fn call_datetime_without_tzinfo(
|
pub fn call_datetime_without_tzinfo(
|
||||||
checker: &mut Checker,
|
checker: &mut Checker,
|
||||||
|
|
@ -23,7 +24,7 @@ pub fn call_datetime_without_tzinfo(
|
||||||
if args.len() < 8 && !has_non_none_keyword(keywords, "tzinfo") {
|
if args.len() < 8 && !has_non_none_keyword(keywords, "tzinfo") {
|
||||||
checker
|
checker
|
||||||
.checks
|
.checks
|
||||||
.push(Check::new(CheckKind::CallDatetimeWithoutTzinfo, location));
|
.push(Check::new(violations::CallDatetimeWithoutTzinfo, location));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,7 +32,7 @@ pub fn call_datetime_without_tzinfo(
|
||||||
if args.len() >= 8 && is_const_none(&args[7]) {
|
if args.len() >= 8 && is_const_none(&args[7]) {
|
||||||
checker
|
checker
|
||||||
.checks
|
.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
|
checker
|
||||||
.checks
|
.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
|
checker
|
||||||
.checks
|
.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.from_imports,
|
||||||
) {
|
) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::CallDatetimeUtcfromtimestamp,
|
violations::CallDatetimeUtcfromtimestamp,
|
||||||
location,
|
location,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +103,7 @@ pub fn call_datetime_now_without_tzinfo(
|
||||||
// no args / no args unqualified
|
// no args / no args unqualified
|
||||||
if args.is_empty() && keywords.is_empty() {
|
if args.is_empty() && keywords.is_empty() {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::CallDatetimeNowWithoutTzinfo,
|
violations::CallDatetimeNowWithoutTzinfo,
|
||||||
location,
|
location,
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
|
|
@ -111,7 +112,7 @@ pub fn call_datetime_now_without_tzinfo(
|
||||||
// none args
|
// none args
|
||||||
if !args.is_empty() && is_const_none(&args[0]) {
|
if !args.is_empty() && is_const_none(&args[0]) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::CallDatetimeNowWithoutTzinfo,
|
violations::CallDatetimeNowWithoutTzinfo,
|
||||||
location,
|
location,
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
|
|
@ -120,7 +121,7 @@ pub fn call_datetime_now_without_tzinfo(
|
||||||
// wrong keywords / none keyword
|
// wrong keywords / none keyword
|
||||||
if !keywords.is_empty() && !has_non_none_keyword(keywords, "tz") {
|
if !keywords.is_empty() && !has_non_none_keyword(keywords, "tz") {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::CallDatetimeNowWithoutTzinfo,
|
violations::CallDatetimeNowWithoutTzinfo,
|
||||||
location,
|
location,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -148,7 +149,7 @@ pub fn call_datetime_fromtimestamp(
|
||||||
if args.len() < 2 && keywords.is_empty() {
|
if args.len() < 2 && keywords.is_empty() {
|
||||||
checker
|
checker
|
||||||
.checks
|
.checks
|
||||||
.push(Check::new(CheckKind::CallDatetimeFromtimestamp, location));
|
.push(Check::new(violations::CallDatetimeFromtimestamp, location));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,7 +157,7 @@ pub fn call_datetime_fromtimestamp(
|
||||||
if args.len() > 1 && is_const_none(&args[1]) {
|
if args.len() > 1 && is_const_none(&args[1]) {
|
||||||
checker
|
checker
|
||||||
.checks
|
.checks
|
||||||
.push(Check::new(CheckKind::CallDatetimeFromtimestamp, location));
|
.push(Check::new(violations::CallDatetimeFromtimestamp, location));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,7 +165,7 @@ pub fn call_datetime_fromtimestamp(
|
||||||
if !keywords.is_empty() && !has_non_none_keyword(keywords, "tz") {
|
if !keywords.is_empty() && !has_non_none_keyword(keywords, "tz") {
|
||||||
checker
|
checker
|
||||||
.checks
|
.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 {
|
let (Some(grandparent), Some(parent)) = (checker.current_expr_grandparent(), checker.current_expr_parent()) else {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::CallDatetimeStrptimeWithoutZone,
|
violations::CallDatetimeStrptimeWithoutZone,
|
||||||
location,
|
location,
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
|
|
@ -221,7 +222,7 @@ pub fn call_datetime_strptime_without_zone(
|
||||||
}
|
}
|
||||||
|
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::CallDatetimeStrptimeWithoutZone,
|
violations::CallDatetimeStrptimeWithoutZone,
|
||||||
location,
|
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) {
|
if match_call_path(&call_path, "datetime.date", "today", &checker.from_imports) {
|
||||||
checker
|
checker
|
||||||
.checks
|
.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
|
checker
|
||||||
.checks
|
.checks
|
||||||
.push(Check::new(CheckKind::CallDateFromtimestamp, location));
|
.push(Check::new(violations::CallDateFromtimestamp, location));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::ast::helpers::{collect_call_paths, dealias_call_path, match_call_path
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::flake8_debugger::types::DebuggerUsingType;
|
use crate::flake8_debugger::types::DebuggerUsingType;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
const DEBUGGERS: &[(&str, &str)] = &[
|
const DEBUGGERS: &[(&str, &str)] = &[
|
||||||
("pdb", "set_trace"),
|
("pdb", "set_trace"),
|
||||||
|
|
@ -31,7 +32,7 @@ pub fn debugger_call(
|
||||||
.any(|(module, member)| match_call_path(&call_path, module, member, from_imports))
|
.any(|(module, member)| match_call_path(&call_path, module, member, from_imports))
|
||||||
{
|
{
|
||||||
Some(Check::new(
|
Some(Check::new(
|
||||||
CheckKind::Debugger(DebuggerUsingType::Call(call_path.join("."))),
|
violations::Debugger(DebuggerUsingType::Call(call_path.join("."))),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
))
|
))
|
||||||
} else {
|
} 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)
|
.find(|(module_name, member)| module_name == &module && member == &name)
|
||||||
{
|
{
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::Debugger(DebuggerUsingType::Import(format!("{module_name}.{member}"))),
|
violations::Debugger(DebuggerUsingType::Import(format!("{module_name}.{member}"))),
|
||||||
Range::from_located(stmt),
|
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)
|
.any(|(module_name, ..)| module_name == &name)
|
||||||
{
|
{
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::Debugger(DebuggerUsingType::Import(name.to_string())),
|
violations::Debugger(DebuggerUsingType::Import(name.to_string())),
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::settings;
|
use crate::{settings, violations};
|
||||||
|
|
||||||
#[test_case(CheckCode::T100, Path::new("T100.py"); "T100")]
|
#[test_case(CheckCode::T100, Path::new("T100.py"); "T100")]
|
||||||
fn checks(check_code: CheckCode, path: &Path) -> Result<()> {
|
fn checks(check_code: CheckCode, path: &Path) -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::{flake8_errmsg, settings};
|
use crate::{flake8_errmsg, settings, violations};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn defaults() -> Result<()> {
|
fn defaults() -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::{Constant, Expr, ExprKind};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckCode, CheckKind};
|
use crate::registry::{Check, CheckCode, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// EM101, EM102, EM103
|
/// EM101, EM102, EM103
|
||||||
pub fn string_in_exception(checker: &mut Checker, exc: &Expr) {
|
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 checker.settings.enabled.contains(&CheckCode::EM101) {
|
||||||
if string.len() > checker.settings.flake8_errmsg.max_string_length {
|
if string.len() > checker.settings.flake8_errmsg.max_string_length {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::RawStringInException,
|
violations::RawStringInException,
|
||||||
Range::from_located(first),
|
Range::from_located(first),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +28,7 @@ pub fn string_in_exception(checker: &mut Checker, exc: &Expr) {
|
||||||
ExprKind::JoinedStr { .. } => {
|
ExprKind::JoinedStr { .. } => {
|
||||||
if checker.settings.enabled.contains(&CheckCode::EM102) {
|
if checker.settings.enabled.contains(&CheckCode::EM102) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::FStringInException,
|
violations::FStringInException,
|
||||||
Range::from_located(first),
|
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 let ExprKind::Attribute { value, attr, .. } = &func.node {
|
||||||
if attr == "format" && matches!(value.node, ExprKind::Constant { .. }) {
|
if attr == "format" && matches!(value.node, ExprKind::Constant { .. }) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::DotFormatInException,
|
violations::DotFormatInException,
|
||||||
Range::from_located(first),
|
Range::from_located(first),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use rustpython_parser::lexer::{LexResult, Tok};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
use crate::source_code_locator::SourceCodeLocator;
|
use crate::source_code_locator::SourceCodeLocator;
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// ISC001, ISC002
|
/// ISC001, ISC002
|
||||||
pub fn implicit(tokens: &[LexResult], locator: &SourceCodeLocator) -> Vec<Check> {
|
pub fn implicit(tokens: &[LexResult], locator: &SourceCodeLocator) -> Vec<Check> {
|
||||||
|
|
@ -15,7 +16,7 @@ pub fn implicit(tokens: &[LexResult], locator: &SourceCodeLocator) -> Vec<Check>
|
||||||
if matches!(a_tok, Tok::String { .. }) && matches!(b_tok, Tok::String { .. }) {
|
if matches!(a_tok, Tok::String { .. }) && matches!(b_tok, Tok::String { .. }) {
|
||||||
if a_end.row() == b_start.row() {
|
if a_end.row() == b_start.row() {
|
||||||
checks.push(Check::new(
|
checks.push(Check::new(
|
||||||
CheckKind::SingleLineImplicitStringConcatenation,
|
violations::SingleLineImplicitStringConcatenation,
|
||||||
Range {
|
Range {
|
||||||
location: *a_start,
|
location: *a_start,
|
||||||
end_location: *b_end,
|
end_location: *b_end,
|
||||||
|
|
@ -30,7 +31,7 @@ pub fn implicit(tokens: &[LexResult], locator: &SourceCodeLocator) -> Vec<Check>
|
||||||
});
|
});
|
||||||
if contents.trim_end().ends_with('\\') {
|
if contents.trim_end().ends_with('\\') {
|
||||||
checks.push(Check::new(
|
checks.push(Check::new(
|
||||||
CheckKind::MultiLineImplicitStringConcatenation,
|
violations::MultiLineImplicitStringConcatenation,
|
||||||
Range {
|
Range {
|
||||||
location: *a_start,
|
location: *a_start,
|
||||||
end_location: *b_end,
|
end_location: *b_end,
|
||||||
|
|
@ -63,7 +64,7 @@ pub fn explicit(expr: &Expr) -> Option<Check> {
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::ExplicitStringConcatenation,
|
violations::ExplicitStringConcatenation,
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::settings;
|
use crate::{settings, violations};
|
||||||
|
|
||||||
#[test_case(CheckCode::ISC001, Path::new("ISC.py"); "ISC001")]
|
#[test_case(CheckCode::ISC001, Path::new("ISC.py"); "ISC001")]
|
||||||
#[test_case(CheckCode::ISC002, Path::new("ISC.py"); "ISC002")]
|
#[test_case(CheckCode::ISC002, Path::new("ISC.py"); "ISC002")]
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::Stmt;
|
||||||
|
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// ICN001
|
/// ICN001
|
||||||
pub fn check_conventional_import(
|
pub fn check_conventional_import(
|
||||||
|
|
@ -24,7 +25,7 @@ pub fn check_conventional_import(
|
||||||
}
|
}
|
||||||
if !is_valid_import {
|
if !is_valid_import {
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::ImportAliasIsNotConventional(
|
violations::ImportAliasIsNotConventional(
|
||||||
name.to_string(),
|
name.to_string(),
|
||||||
expected_alias.to_string(),
|
expected_alias.to_string(),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::{flake8_import_conventions, Settings};
|
use crate::{flake8_import_conventions, violations, Settings};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn defaults() -> Result<()> {
|
fn defaults() -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::settings;
|
use crate::{settings, violations};
|
||||||
|
|
||||||
#[test_case(CheckCode::PIE790, Path::new("PIE790.py"); "PIE790")]
|
#[test_case(CheckCode::PIE790, Path::new("PIE790.py"); "PIE790")]
|
||||||
#[test_case(CheckCode::PIE794, Path::new("PIE794.py"); "PIE794")]
|
#[test_case(CheckCode::PIE794, Path::new("PIE794.py"); "PIE794")]
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use crate::autofix::helpers::delete_stmt;
|
||||||
use crate::autofix::Fix;
|
use crate::autofix::Fix;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckCode, CheckKind};
|
use crate::registry::{Check, CheckCode, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// PIE790
|
/// PIE790
|
||||||
pub fn no_unnecessary_pass(checker: &mut Checker, body: &[Stmt]) {
|
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) {
|
if matches!(pass_stmt.node, StmtKind::Pass) {
|
||||||
let mut check =
|
let mut check = Check::new(
|
||||||
Check::new(CheckKind::NoUnnecessaryPass, Range::from_located(pass_stmt));
|
violations::NoUnnecessaryPass,
|
||||||
|
Range::from_located(pass_stmt),
|
||||||
|
);
|
||||||
if checker.patch(&CheckCode::PIE790) {
|
if checker.patch(&CheckCode::PIE790) {
|
||||||
match delete_stmt(pass_stmt, None, &[], checker.locator) {
|
match delete_stmt(pass_stmt, None, &[], checker.locator) {
|
||||||
Ok(fix) => {
|
Ok(fix) => {
|
||||||
|
|
@ -76,7 +79,7 @@ pub fn dupe_class_field_definitions(checker: &mut Checker, bases: &[Expr], body:
|
||||||
|
|
||||||
if seen_targets.contains(target) {
|
if seen_targets.contains(target) {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::DupeClassFieldDefinitions(target.to_string()),
|
violations::DupeClassFieldDefinitions(target.to_string()),
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
);
|
);
|
||||||
if checker.patch(&CheckCode::PIE794) {
|
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 args.args.is_empty() {
|
||||||
if let ExprKind::List { elts, .. } = &body.node {
|
if let ExprKind::List { elts, .. } = &body.node {
|
||||||
if elts.is_empty() {
|
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) {
|
if checker.patch(&CheckCode::PIE807) {
|
||||||
check.amend(Fix::replacement(
|
check.amend(Fix::replacement(
|
||||||
"list".to_string(),
|
"list".to_string(),
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::settings;
|
use crate::{settings, violations};
|
||||||
|
|
||||||
#[test_case(CheckCode::T201, Path::new("T201.py"); "T201")]
|
#[test_case(CheckCode::T201, Path::new("T201.py"); "T201")]
|
||||||
#[test_case(CheckCode::T203, Path::new("T203.py"); "T203")]
|
#[test_case(CheckCode::T203, Path::new("T203.py"); "T203")]
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use crate::ast::types::Range;
|
||||||
use crate::autofix::helpers;
|
use crate::autofix::helpers;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// T201, T203
|
/// T201, T203
|
||||||
pub fn print_call(checker: &mut Checker, func: &Expr, keywords: &[Keyword]) {
|
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) {
|
} 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 {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ mod tests {
|
||||||
use crate::flake8_pytest_style::types;
|
use crate::flake8_pytest_style::types;
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
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(CheckCode::PT001, Path::new("PT001.py"), Settings::default(), "PT001_default"; "PT001_0")]
|
||||||
#[test_case(
|
#[test_case(
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ use crate::ast::visitor::Visitor;
|
||||||
use crate::autofix::Fix;
|
use crate::autofix::Fix;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// Visitor that tracks assert statements and checks if they reference
|
/// Visitor that tracks assert statements and checks if they reference
|
||||||
/// the exception name.
|
/// the exception name.
|
||||||
|
|
@ -51,7 +52,7 @@ where
|
||||||
if let Some(current_assert) = self.current_assert {
|
if let Some(current_assert) = self.current_assert {
|
||||||
if id.as_str() == self.exception_name {
|
if id.as_str() == self.exception_name {
|
||||||
self.errors.push(Check::new(
|
self.errors.push(Check::new(
|
||||||
CheckKind::AssertInExcept(id.to_string()),
|
violations::AssertInExcept(id.to_string()),
|
||||||
Range::from_located(current_assert),
|
Range::from_located(current_assert),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +100,7 @@ pub fn unittest_assertion(
|
||||||
ExprKind::Attribute { attr, .. } => {
|
ExprKind::Attribute { attr, .. } => {
|
||||||
if let Ok(unittest_assert) = UnittestAssert::try_from(attr.as_str()) {
|
if let Ok(unittest_assert) = UnittestAssert::try_from(attr.as_str()) {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UnittestAssertion(unittest_assert.to_string()),
|
violations::UnittestAssertion(unittest_assert.to_string()),
|
||||||
Range::from_located(func),
|
Range::from_located(func),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
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<Check> {
|
pub fn assert_falsy(assert_stmt: &Stmt, test_expr: &Expr) -> Option<Check> {
|
||||||
if is_falsy_constant(test_expr) {
|
if is_falsy_constant(test_expr) {
|
||||||
Some(Check::new(
|
Some(Check::new(
|
||||||
CheckKind::AssertAlwaysFalse,
|
violations::AssertAlwaysFalse,
|
||||||
Range::from_located(assert_stmt),
|
Range::from_located(assert_stmt),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -152,7 +153,7 @@ pub fn assert_in_exception_handler(handlers: &[Excepthandler]) -> Vec<Check> {
|
||||||
pub fn composite_condition(assert_stmt: &Stmt, test_expr: &Expr) -> Option<Check> {
|
pub fn composite_condition(assert_stmt: &Stmt, test_expr: &Expr) -> Option<Check> {
|
||||||
if is_composite_condition(test_expr) {
|
if is_composite_condition(test_expr) {
|
||||||
Some(Check::new(
|
Some(Check::new(
|
||||||
CheckKind::CompositeAssertion,
|
violations::CompositeAssertion,
|
||||||
Range::from_located(assert_stmt),
|
Range::from_located(assert_stmt),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::ast::helpers::SimpleCallArgs;
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
pub fn fail_call(checker: &mut Checker, call: &Expr, args: &[Expr], keywords: &[Keyword]) {
|
pub fn fail_call(checker: &mut Checker, call: &Expr, args: &[Expr], keywords: &[Keyword]) {
|
||||||
if is_pytest_fail(call, checker) {
|
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 let Some(msg) = msg {
|
||||||
if is_empty_or_null_string(msg) {
|
if is_empty_or_null_string(msg) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::FailWithoutMessage,
|
violations::FailWithoutMessage,
|
||||||
Range::from_located(call),
|
Range::from_located(call),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::FailWithoutMessage,
|
violations::FailWithoutMessage,
|
||||||
Range::from_located(call),
|
Range::from_located(call),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ use crate::ast::visitor::Visitor;
|
||||||
use crate::autofix::Fix;
|
use crate::autofix::Fix;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckCode, CheckKind};
|
use crate::registry::{Check, CheckCode, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
/// Visitor that skips functions
|
/// Visitor that skips functions
|
||||||
|
|
@ -79,7 +80,7 @@ fn pytest_fixture_parentheses(
|
||||||
actual: &str,
|
actual: &str,
|
||||||
) {
|
) {
|
||||||
let mut check = Check::new(
|
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),
|
Range::from_located(decorator),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
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() {
|
if checker.settings.enabled.contains(&CheckCode::PT002) && !args.is_empty() {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::FixturePositionalArgs(func_name.to_string()),
|
violations::FixturePositionalArgs(func_name.to_string()),
|
||||||
Range::from_located(decorator),
|
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 let Some(scope_keyword) = scope_keyword {
|
||||||
if keyword_is_literal(scope_keyword, "function") {
|
if keyword_is_literal(scope_keyword, "function") {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::ExtraneousScopeFunction,
|
violations::ExtraneousScopeFunction,
|
||||||
Range::from_located(scope_keyword),
|
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('_')
|
&& func_name.starts_with('_')
|
||||||
{
|
{
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::IncorrectFixtureNameUnderscore(func_name.to_string()),
|
violations::IncorrectFixtureNameUnderscore(func_name.to_string()),
|
||||||
Range::from_located(func),
|
Range::from_located(func),
|
||||||
));
|
));
|
||||||
} else if checker.settings.enabled.contains(&CheckCode::PT004)
|
} 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('_')
|
&& !func_name.starts_with('_')
|
||||||
{
|
{
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MissingFixtureNameUnderscore(func_name.to_string()),
|
violations::MissingFixtureNameUnderscore(func_name.to_string()),
|
||||||
Range::from_located(func),
|
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 let ExprKind::Yield { .. } = value.node {
|
||||||
if visitor.yield_statements.len() == 1 {
|
if visitor.yield_statements.len() == 1 {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UselessYieldFixture(func_name.to_string()),
|
violations::UselessYieldFixture(func_name.to_string()),
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
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();
|
let name = arg.node.arg.to_string();
|
||||||
if name.starts_with('_') {
|
if name.starts_with('_') {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::FixtureParamWithoutValue(name),
|
violations::FixtureParamWithoutValue(name),
|
||||||
Range::from_located(arg),
|
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) {
|
fn check_fixture_decorator_name(checker: &mut Checker, decorator: &Expr) {
|
||||||
if is_pytest_yield_fixture(decorator, checker) {
|
if is_pytest_yield_fixture(decorator, checker) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::DeprecatedYieldFixture,
|
violations::DeprecatedYieldFixture,
|
||||||
Range::from_located(decorator),
|
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 {
|
if let Some(addfinalizer) = visitor.addfinalizer_call {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::FixtureFinalizerCallback,
|
violations::FixtureFinalizerCallback,
|
||||||
Range::from_located(addfinalizer),
|
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 checker.settings.enabled.contains(&CheckCode::PT024) {
|
||||||
if name == "asyncio" {
|
if name == "asyncio" {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::UnnecessaryAsyncioMarkOnFixture,
|
violations::UnnecessaryAsyncioMarkOnFixture,
|
||||||
Range::from_located(mark),
|
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 checker.settings.enabled.contains(&CheckCode::PT025) {
|
||||||
if name == "usefixtures" {
|
if name == "usefixtures" {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::ErroneousUseFixturesOnFixture,
|
violations::ErroneousUseFixturesOnFixture,
|
||||||
Range::from_located(mark),
|
Range::from_located(mark),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use rustpython_ast::Stmt;
|
||||||
|
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn is_pytest_or_subpackage(imported_name: &str) -> bool {
|
fn is_pytest_or_subpackage(imported_name: &str) -> bool {
|
||||||
imported_name == "pytest" || imported_name.starts_with("pytest.")
|
imported_name == "pytest" || imported_name.starts_with("pytest.")
|
||||||
|
|
@ -13,7 +14,7 @@ pub fn import(import_from: &Stmt, name: &str, asname: Option<&str>) -> Option<Ch
|
||||||
if let Some(alias) = asname {
|
if let Some(alias) = asname {
|
||||||
if alias != name {
|
if alias != name {
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::IncorrectPytestImport,
|
violations::IncorrectPytestImport,
|
||||||
Range::from_located(import_from),
|
Range::from_located(import_from),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -38,7 +39,7 @@ pub fn import_from(
|
||||||
if let Some(module) = module {
|
if let Some(module) = module {
|
||||||
if is_pytest_or_subpackage(module) {
|
if is_pytest_or_subpackage(module) {
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::IncorrectPytestImport,
|
violations::IncorrectPytestImport,
|
||||||
Range::from_located(import_from),
|
Range::from_located(import_from),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::ast::types::Range;
|
||||||
use crate::autofix::Fix;
|
use crate::autofix::Fix;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckCode, CheckKind};
|
use crate::registry::{Check, CheckCode, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn pytest_mark_parentheses(
|
fn pytest_mark_parentheses(
|
||||||
checker: &mut Checker,
|
checker: &mut Checker,
|
||||||
|
|
@ -14,7 +15,7 @@ fn pytest_mark_parentheses(
|
||||||
actual: &str,
|
actual: &str,
|
||||||
) {
|
) {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::IncorrectMarkParenthesesStyle(
|
violations::IncorrectMarkParenthesesStyle(
|
||||||
get_mark_name(decorator).to_string(),
|
get_mark_name(decorator).to_string(),
|
||||||
preferred.to_string(),
|
preferred.to_string(),
|
||||||
actual.to_string(),
|
actual.to_string(),
|
||||||
|
|
@ -71,7 +72,7 @@ fn check_useless_usefixtures(checker: &mut Checker, decorator: &Expr) {
|
||||||
|
|
||||||
if !has_parameters {
|
if !has_parameters {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UseFixturesWithoutParameters,
|
violations::UseFixturesWithoutParameters,
|
||||||
Range::from_located(decorator),
|
Range::from_located(decorator),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use crate::checkers::ast::Checker;
|
||||||
use crate::flake8_pytest_style::types;
|
use crate::flake8_pytest_style::types;
|
||||||
use crate::registry::{Check, CheckCode, CheckKind};
|
use crate::registry::{Check, CheckCode, CheckKind};
|
||||||
use crate::source_code_generator::SourceCodeGenerator;
|
use crate::source_code_generator::SourceCodeGenerator;
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn get_parametrize_decorator<'a>(checker: &Checker, decorators: &'a [Expr]) -> Option<&'a Expr> {
|
fn get_parametrize_decorator<'a>(checker: &Checker, decorators: &'a [Expr]) -> Option<&'a Expr> {
|
||||||
decorators
|
decorators
|
||||||
|
|
@ -80,7 +81,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
||||||
match names_type {
|
match names_type {
|
||||||
types::ParametrizeNameType::Tuple => {
|
types::ParametrizeNameType::Tuple => {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::ParametrizeNamesWrongType(names_type),
|
violations::ParametrizeNamesWrongType(names_type),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
|
|
@ -110,7 +111,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
||||||
}
|
}
|
||||||
types::ParametrizeNameType::List => {
|
types::ParametrizeNameType::List => {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::ParametrizeNamesWrongType(names_type),
|
violations::ParametrizeNamesWrongType(names_type),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
|
|
@ -152,7 +153,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
||||||
types::ParametrizeNameType::Tuple => {}
|
types::ParametrizeNameType::Tuple => {}
|
||||||
types::ParametrizeNameType::List => {
|
types::ParametrizeNameType::List => {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::ParametrizeNamesWrongType(names_type),
|
violations::ParametrizeNamesWrongType(names_type),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
|
|
@ -174,7 +175,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
||||||
}
|
}
|
||||||
types::ParametrizeNameType::CSV => {
|
types::ParametrizeNameType::CSV => {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::ParametrizeNamesWrongType(names_type),
|
violations::ParametrizeNamesWrongType(names_type),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
|
|
@ -201,7 +202,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
||||||
types::ParametrizeNameType::List => {}
|
types::ParametrizeNameType::List => {}
|
||||||
types::ParametrizeNameType::Tuple => {
|
types::ParametrizeNameType::Tuple => {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::ParametrizeNamesWrongType(names_type),
|
violations::ParametrizeNamesWrongType(names_type),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
|
|
@ -223,7 +224,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
||||||
}
|
}
|
||||||
types::ParametrizeNameType::CSV => {
|
types::ParametrizeNameType::CSV => {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::ParametrizeNamesWrongType(names_type),
|
violations::ParametrizeNamesWrongType(names_type),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
|
|
@ -257,7 +258,7 @@ fn check_values(checker: &mut Checker, expr: &Expr) {
|
||||||
ExprKind::List { elts, .. } => {
|
ExprKind::List { elts, .. } => {
|
||||||
if values_type != types::ParametrizeValuesType::List {
|
if values_type != types::ParametrizeValuesType::List {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::ParametrizeValuesWrongType(values_type, values_row_type),
|
violations::ParametrizeValuesWrongType(values_type, values_row_type),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -266,7 +267,7 @@ fn check_values(checker: &mut Checker, expr: &Expr) {
|
||||||
ExprKind::Tuple { elts, .. } => {
|
ExprKind::Tuple { elts, .. } => {
|
||||||
if values_type != types::ParametrizeValuesType::Tuple {
|
if values_type != types::ParametrizeValuesType::Tuple {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::ParametrizeValuesWrongType(values_type, values_row_type),
|
violations::ParametrizeValuesWrongType(values_type, values_row_type),
|
||||||
Range::from_located(expr),
|
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) {
|
fn handle_single_name(checker: &mut Checker, expr: &Expr, value: &Expr) {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::ParametrizeNamesWrongType(types::ParametrizeNameType::CSV),
|
violations::ParametrizeNamesWrongType(types::ParametrizeNameType::CSV),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -305,7 +306,7 @@ fn handle_value_rows(
|
||||||
ExprKind::Tuple { .. } => {
|
ExprKind::Tuple { .. } => {
|
||||||
if values_row_type != types::ParametrizeValuesRowType::Tuple {
|
if values_row_type != types::ParametrizeValuesRowType::Tuple {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::ParametrizeValuesWrongType(values_type, values_row_type),
|
violations::ParametrizeValuesWrongType(values_type, values_row_type),
|
||||||
Range::from_located(elt),
|
Range::from_located(elt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -313,7 +314,7 @@ fn handle_value_rows(
|
||||||
ExprKind::List { .. } => {
|
ExprKind::List { .. } => {
|
||||||
if values_row_type != types::ParametrizeValuesRowType::List {
|
if values_row_type != types::ParametrizeValuesRowType::List {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::ParametrizeValuesWrongType(values_type, values_row_type),
|
violations::ParametrizeValuesWrongType(values_type, values_row_type),
|
||||||
Range::from_located(elt),
|
Range::from_located(elt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use crate::ast::types::Range;
|
||||||
use crate::ast::visitor;
|
use crate::ast::visitor;
|
||||||
use crate::ast::visitor::Visitor;
|
use crate::ast::visitor::Visitor;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
const PATCH_NAMES: &[&str] = &[
|
const PATCH_NAMES: &[&str] = &[
|
||||||
"mocker.patch",
|
"mocker.patch",
|
||||||
|
|
@ -72,7 +73,7 @@ fn check_patch_call(
|
||||||
|
|
||||||
if !visitor.uses_args {
|
if !visitor.uses_args {
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::PatchWithLambda,
|
violations::PatchWithLambda,
|
||||||
Range::from_located(call),
|
Range::from_located(call),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use crate::ast::helpers::{
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckCode, CheckKind};
|
use crate::registry::{Check, CheckCode, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn is_pytest_raises(
|
fn is_pytest_raises(
|
||||||
func: &Expr,
|
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 checker.settings.enabled.contains(&CheckCode::PT010) {
|
||||||
if args.is_empty() && keywords.is_empty() {
|
if args.is_empty() && keywords.is_empty() {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::RaisesWithoutException,
|
violations::RaisesWithoutException,
|
||||||
Range::from_located(func),
|
Range::from_located(func),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -91,7 +92,7 @@ pub fn complex_raises(checker: &mut Checker, stmt: &Stmt, items: &[Withitem], bo
|
||||||
|
|
||||||
if is_too_complex {
|
if is_too_complex {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::RaisesWithMultipleStatements,
|
violations::RaisesWithMultipleStatements,
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +119,7 @@ fn exception_needs_match(checker: &mut Checker, exception: &Expr) {
|
||||||
|
|
||||||
if is_broad_exception {
|
if is_broad_exception {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::RaisesTooBroad(call_path.join(".")),
|
violations::RaisesTooBroad(call_path.join(".")),
|
||||||
Range::from_located(exception),
|
Range::from_located(exception),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use crate::ast::types::Range;
|
||||||
use crate::flake8_quotes::settings::{Quote, Settings};
|
use crate::flake8_quotes::settings::{Quote, Settings};
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
use crate::source_code_locator::SourceCodeLocator;
|
use crate::source_code_locator::SourceCodeLocator;
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn good_single(quote: &Quote) -> char {
|
fn good_single(quote: &Quote) -> char {
|
||||||
match quote {
|
match quote {
|
||||||
|
|
@ -72,7 +73,7 @@ pub fn quotes(
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(Check::new(
|
Some(Check::new(
|
||||||
CheckKind::BadQuotesDocstring(settings.docstring_quotes.clone()),
|
violations::BadQuotesDocstring(settings.docstring_quotes.clone()),
|
||||||
Range::new(start, end),
|
Range::new(start, end),
|
||||||
))
|
))
|
||||||
} else if is_multiline {
|
} else if is_multiline {
|
||||||
|
|
@ -87,7 +88,7 @@ pub fn quotes(
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(Check::new(
|
Some(Check::new(
|
||||||
CheckKind::BadQuotesMultilineString(settings.multiline_quotes.clone()),
|
violations::BadQuotesMultilineString(settings.multiline_quotes.clone()),
|
||||||
Range::new(start, end),
|
Range::new(start, end),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -102,7 +103,7 @@ pub fn quotes(
|
||||||
&& !string_contents.contains(bad_single(&settings.inline_quotes))
|
&& !string_contents.contains(bad_single(&settings.inline_quotes))
|
||||||
{
|
{
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::AvoidQuoteEscape,
|
violations::AvoidQuoteEscape,
|
||||||
Range::new(start, end),
|
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 we're not using the preferred type, only allow use to avoid escapes.
|
||||||
if !string_contents.contains(good_single(&settings.inline_quotes)) {
|
if !string_contents.contains(good_single(&settings.inline_quotes)) {
|
||||||
return Some(Check::new(
|
return Some(Check::new(
|
||||||
CheckKind::BadQuotesInlineString(settings.inline_quotes.clone()),
|
violations::BadQuotesInlineString(settings.inline_quotes.clone()),
|
||||||
Range::new(start, end),
|
Range::new(start, end),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ mod tests {
|
||||||
use crate::flake8_quotes::settings::Quote;
|
use crate::flake8_quotes::settings::Quote;
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
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.py"))]
|
||||||
#[test_case(Path::new("doubles_escaped.py"))]
|
#[test_case(Path::new("doubles_escaped.py"))]
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::Settings;
|
use crate::{violations, Settings};
|
||||||
|
|
||||||
#[test_case(CheckCode::RET501, Path::new("RET501.py"); "RET501")]
|
#[test_case(CheckCode::RET501, Path::new("RET501.py"); "RET501")]
|
||||||
#[test_case(CheckCode::RET502, Path::new("RET502.py"); "RET502")]
|
#[test_case(CheckCode::RET502, Path::new("RET502.py"); "RET502")]
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use crate::checkers::ast::Checker;
|
||||||
use crate::flake8_return::helpers::result_exists;
|
use crate::flake8_return::helpers::result_exists;
|
||||||
use crate::flake8_return::visitor::{ReturnVisitor, Stack};
|
use crate::flake8_return::visitor::{ReturnVisitor, Stack};
|
||||||
use crate::registry::{Branch, CheckCode, CheckKind};
|
use crate::registry::{Branch, CheckCode, CheckKind};
|
||||||
use crate::Check;
|
use crate::{violations, Check};
|
||||||
|
|
||||||
/// RET501
|
/// RET501
|
||||||
fn unnecessary_return_none(checker: &mut Checker, stack: &Stack) {
|
fn unnecessary_return_none(checker: &mut Checker, stack: &Stack) {
|
||||||
|
|
@ -26,7 +26,7 @@ fn unnecessary_return_none(checker: &mut Checker, stack: &Stack) {
|
||||||
) {
|
) {
|
||||||
continue;
|
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) {
|
if checker.patch(&CheckCode::RET501) {
|
||||||
check.amend(Fix::replacement(
|
check.amend(Fix::replacement(
|
||||||
"return".to_string(),
|
"return".to_string(),
|
||||||
|
|
@ -44,7 +44,7 @@ fn implicit_return_value(checker: &mut Checker, stack: &Stack) {
|
||||||
if expr.is_some() {
|
if expr.is_some() {
|
||||||
continue;
|
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) {
|
if checker.patch(&CheckCode::RET502) {
|
||||||
check.amend(Fix::replacement(
|
check.amend(Fix::replacement(
|
||||||
"return None".to_string(),
|
"return None".to_string(),
|
||||||
|
|
@ -62,7 +62,7 @@ fn implicit_return(checker: &mut Checker, last_stmt: &Stmt) {
|
||||||
StmtKind::If { body, orelse, .. } => {
|
StmtKind::If { body, orelse, .. } => {
|
||||||
if body.is_empty() || orelse.is_empty() {
|
if body.is_empty() || orelse.is_empty() {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::ImplicitReturn,
|
violations::ImplicitReturn,
|
||||||
Range::from_located(last_stmt),
|
Range::from_located(last_stmt),
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
|
|
@ -100,7 +100,7 @@ fn implicit_return(checker: &mut Checker, last_stmt: &Stmt) {
|
||||||
| StmtKind::Raise { .. }
|
| StmtKind::Raise { .. }
|
||||||
| StmtKind::Try { .. } => {}
|
| 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) {
|
if checker.patch(&CheckCode::RET503) {
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
content.push_str(&indentation(checker, last_stmt));
|
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()) {
|
if !stack.refs.contains_key(id.as_str()) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::UnnecessaryAssign,
|
violations::UnnecessaryAssign,
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
|
|
@ -208,7 +208,7 @@ fn unnecessary_assign(checker: &mut Checker, stack: &Stack, expr: &Expr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::UnnecessaryAssign,
|
violations::UnnecessaryAssign,
|
||||||
Range::from_located(expr),
|
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 matches!(child.node, StmtKind::Return { .. }) {
|
||||||
if checker.settings.enabled.contains(&CheckCode::RET505) {
|
if checker.settings.enabled.contains(&CheckCode::RET505) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::SuperfluousElseReturn(branch),
|
violations::SuperfluousElseReturn(branch),
|
||||||
Range::from_located(stmt),
|
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 matches!(child.node, StmtKind::Break) {
|
||||||
if checker.settings.enabled.contains(&CheckCode::RET508) {
|
if checker.settings.enabled.contains(&CheckCode::RET508) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::SuperfluousElseBreak(branch),
|
violations::SuperfluousElseBreak(branch),
|
||||||
Range::from_located(stmt),
|
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 matches!(child.node, StmtKind::Raise { .. }) {
|
||||||
if checker.settings.enabled.contains(&CheckCode::RET506) {
|
if checker.settings.enabled.contains(&CheckCode::RET506) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::SuperfluousElseRaise(branch),
|
violations::SuperfluousElseRaise(branch),
|
||||||
Range::from_located(stmt),
|
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 matches!(child.node, StmtKind::Continue) {
|
||||||
if checker.settings.enabled.contains(&CheckCode::RET507) {
|
if checker.settings.enabled.contains(&CheckCode::RET507) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::SuperfluousElseContinue(branch),
|
violations::SuperfluousElseContinue(branch),
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::linter::test_path;
|
use crate::linter::test_path;
|
||||||
use crate::registry::CheckCode;
|
use crate::registry::CheckCode;
|
||||||
use crate::settings;
|
use crate::{settings, violations};
|
||||||
|
|
||||||
#[test_case(CheckCode::SIM101, Path::new("SIM101.py"); "SIM101")]
|
#[test_case(CheckCode::SIM101, Path::new("SIM101.py"); "SIM101")]
|
||||||
#[test_case(CheckCode::SIM102, Path::new("SIM102.py"); "SIM102")]
|
#[test_case(CheckCode::SIM102, Path::new("SIM102.py"); "SIM102")]
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use crate::ast::types::Range;
|
||||||
use crate::autofix::Fix;
|
use crate::autofix::Fix;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckCode, CheckKind};
|
use crate::registry::{Check, CheckCode, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// Return `true` if two `Expr` instances are equivalent names.
|
/// Return `true` if two `Expr` instances are equivalent names.
|
||||||
fn is_same_expr<'a>(a: &'a Expr, b: &'a Expr) -> Option<&'a str> {
|
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 {
|
for (arg_name, indices) in duplicates {
|
||||||
if indices.len() > 1 {
|
if indices.len() > 1 {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::DuplicateIsinstanceCall(arg_name.to_string()),
|
violations::DuplicateIsinstanceCall(arg_name.to_string()),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(&CheckCode::SIM101) {
|
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))
|
.map(|value| unparse_expr(value, checker.style))
|
||||||
.collect();
|
.collect();
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::CompareWithTuple(
|
violations::CompareWithTuple(
|
||||||
value.to_string(),
|
value.to_string(),
|
||||||
str_values,
|
str_values,
|
||||||
unparse_expr(expr, checker.style),
|
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 {
|
for non_negate_expr in &non_negated_expr {
|
||||||
if let Some(id) = is_same_expr(negate_expr, non_negate_expr) {
|
if let Some(id) = is_same_expr(negate_expr, non_negate_expr) {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::AAndNotA(id.to_string()),
|
violations::AAndNotA(id.to_string()),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(&CheckCode::SIM220) {
|
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 {
|
for non_negate_expr in &non_negated_expr {
|
||||||
if let Some(id) = is_same_expr(negate_expr, non_negate_expr) {
|
if let Some(id) = is_same_expr(negate_expr, non_negate_expr) {
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::AOrNotA(id.to_string()),
|
violations::AOrNotA(id.to_string()),
|
||||||
Range::from_located(expr),
|
Range::from_located(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(&CheckCode::SIM220) {
|
if checker.patch(&CheckCode::SIM220) {
|
||||||
|
|
@ -308,7 +309,7 @@ pub fn or_true(checker: &mut Checker, expr: &Expr) {
|
||||||
..
|
..
|
||||||
} = &value.node
|
} = &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) {
|
if checker.patch(&CheckCode::SIM223) {
|
||||||
check.amend(Fix::replacement(
|
check.amend(Fix::replacement(
|
||||||
"True".to_string(),
|
"True".to_string(),
|
||||||
|
|
@ -332,7 +333,7 @@ pub fn and_false(checker: &mut Checker, expr: &Expr) {
|
||||||
..
|
..
|
||||||
} = &value.node
|
} = &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) {
|
if checker.patch(&CheckCode::SIM223) {
|
||||||
check.amend(Fix::replacement(
|
check.amend(Fix::replacement(
|
||||||
"False".to_string(),
|
"False".to_string(),
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckCode, CheckKind};
|
use crate::registry::{Check, CheckCode, CheckKind};
|
||||||
use crate::source_code_generator::SourceCodeGenerator;
|
use crate::source_code_generator::SourceCodeGenerator;
|
||||||
use crate::source_code_style::SourceCodeStyleDetector;
|
use crate::source_code_style::SourceCodeStyleDetector;
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
struct Loop<'a> {
|
struct Loop<'a> {
|
||||||
return_value: bool,
|
return_value: bool,
|
||||||
|
|
@ -118,7 +119,7 @@ pub fn convert_loop_to_any_all(checker: &mut Checker, stmt: &Stmt, sibling: &Stm
|
||||||
checker.style,
|
checker.style,
|
||||||
);
|
);
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::ConvertLoopToAny(content.clone()),
|
violations::ConvertLoopToAny(content.clone()),
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
);
|
);
|
||||||
if checker.patch(&CheckCode::SIM110) {
|
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,
|
checker.style,
|
||||||
);
|
);
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::ConvertLoopToAll(content.clone()),
|
violations::ConvertLoopToAll(content.clone()),
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
);
|
);
|
||||||
if checker.patch(&CheckCode::SIM111) {
|
if checker.patch(&CheckCode::SIM111) {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::ast::types::Range;
|
||||||
use crate::autofix::Fix;
|
use crate::autofix::Fix;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckCode, CheckKind};
|
use crate::registry::{Check, CheckCode, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn is_main_check(expr: &Expr) -> bool {
|
fn is_main_check(expr: &Expr) -> bool {
|
||||||
if let ExprKind::Compare {
|
if let ExprKind::Compare {
|
||||||
|
|
@ -60,7 +61,7 @@ pub fn nested_if_statements(checker: &mut Checker, stmt: &Stmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::NestedIfStatements,
|
violations::NestedIfStatements,
|
||||||
Range::from_located(stmt),
|
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 condition = unparse_expr(test, checker.style);
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::ReturnBoolConditionDirectly(condition),
|
violations::ReturnBoolConditionDirectly(condition),
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
);
|
);
|
||||||
if checker.patch(&CheckCode::SIM103) {
|
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 ternary = ternary(target_var, body_value, test, orelse_value);
|
||||||
let content = unparse_stmt(&ternary, checker.style);
|
let content = unparse_stmt(&ternary, checker.style);
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::UseTernaryOperator(content.clone()),
|
violations::UseTernaryOperator(content.clone()),
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
);
|
);
|
||||||
if checker.patch(&CheckCode::SIM108) {
|
if checker.patch(&CheckCode::SIM108) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::{Stmt, StmtKind};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// SIM117
|
/// SIM117
|
||||||
pub fn multiple_with_statements(checker: &mut Checker, stmt: &Stmt) {
|
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 { .. }) {
|
if matches!(body[0].node, StmtKind::With { .. }) {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::MultipleWithStatements,
|
violations::MultipleWithStatements,
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use crate::ast::types::Range;
|
||||||
use crate::autofix::Fix;
|
use crate::autofix::Fix;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// SIM118
|
/// SIM118
|
||||||
fn key_in_dict(checker: &mut Checker, left: &Expr, right: &Expr, range: Range) {
|
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));
|
.slice_source_code_range(&Range::from_located(value));
|
||||||
|
|
||||||
let mut check = Check::new(
|
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,
|
range,
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use rustpython_ast::{Excepthandler, ExcepthandlerKind, Stmt, StmtKind};
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn find_return(stmts: &[Stmt]) -> Option<&Stmt> {
|
fn find_return(stmts: &[Stmt]) -> Option<&Stmt> {
|
||||||
stmts
|
stmts
|
||||||
|
|
@ -26,7 +27,7 @@ pub fn return_in_try_except_finally(
|
||||||
if let Some(finally_return) = find_return(finalbody) {
|
if let Some(finally_return) = find_return(finalbody) {
|
||||||
if try_has_return || except_has_return {
|
if try_has_return || except_has_return {
|
||||||
checker.checks.push(Check::new(
|
checker.checks.push(Check::new(
|
||||||
CheckKind::ReturnInTryExceptFinally,
|
violations::ReturnInTryExceptFinally,
|
||||||
Range::from_located(finally_return),
|
Range::from_located(finally_return),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::ast::types::Range;
|
||||||
use crate::autofix::Fix;
|
use crate::autofix::Fix;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
fn is_exception_check(stmt: &Stmt) -> bool {
|
fn is_exception_check(stmt: &Stmt) -> bool {
|
||||||
let StmtKind::If {test: _, body, orelse: _} = &stmt.node else {
|
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(
|
let mut check = Check::new(
|
||||||
CheckKind::NegateEqualOp(
|
violations::NegateEqualOp(
|
||||||
unparse_expr(left, checker.style),
|
unparse_expr(left, checker.style),
|
||||||
unparse_expr(&comparators[0], checker.style),
|
unparse_expr(&comparators[0], checker.style),
|
||||||
),
|
),
|
||||||
|
|
@ -79,7 +80,7 @@ pub fn negation_with_not_equal_op(
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut check = Check::new(
|
let mut check = Check::new(
|
||||||
CheckKind::NegateNotEqualOp(
|
violations::NegateNotEqualOp(
|
||||||
unparse_expr(left, checker.style),
|
unparse_expr(left, checker.style),
|
||||||
unparse_expr(&comparators[0], 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(
|
let mut check = Check::new(
|
||||||
CheckKind::DoubleNegation(operand.to_string()),
|
violations::DoubleNegation(operand.to_string()),
|
||||||
Range::from_located(operand),
|
Range::from_located(operand),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use crate::ast::helpers;
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// SIM105
|
/// SIM105
|
||||||
pub fn use_contextlib_suppress(
|
pub fn use_contextlib_suppress(
|
||||||
|
|
@ -30,7 +31,7 @@ pub fn use_contextlib_suppress(
|
||||||
handler_names.join(", ")
|
handler_names.join(", ")
|
||||||
};
|
};
|
||||||
let check = Check::new(
|
let check = Check::new(
|
||||||
CheckKind::UseContextlibSuppress(exception),
|
violations::UseContextlibSuppress(exception),
|
||||||
Range::from_located(stmt),
|
Range::from_located(stmt),
|
||||||
);
|
);
|
||||||
checker.checks.push(check);
|
checker.checks.push(check);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use crate::ast::types::Range;
|
||||||
use crate::autofix::Fix;
|
use crate::autofix::Fix;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::{Check, CheckKind};
|
use crate::registry::{Check, CheckKind};
|
||||||
|
use crate::violations;
|
||||||
|
|
||||||
/// SIM300
|
/// SIM300
|
||||||
pub fn yoda_conditions(
|
pub fn yoda_conditions(
|
||||||
|
|
@ -41,7 +42,7 @@ pub fn yoda_conditions(
|
||||||
.slice_source_code_range(&Range::from_located(right));
|
.slice_source_code_range(&Range::from_located(right));
|
||||||
|
|
||||||
let mut check = Check::new(
|
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),
|
Range::from_located(expr),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue