mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 04:55:09 +00:00
Implement From<Located>
for Range
(#3377)
This commit is contained in:
parent
ff2c0dd491
commit
130e733023
232 changed files with 612 additions and 719 deletions
|
@ -12,7 +12,7 @@ use crate::fix::Fix;
|
||||||
use ruff_python_ast::helpers;
|
use ruff_python_ast::helpers;
|
||||||
use ruff_python_ast::helpers::to_absolute;
|
use ruff_python_ast::helpers::to_absolute;
|
||||||
use ruff_python_ast::source_code::{Indexer, Locator, Stylist};
|
use ruff_python_ast::source_code::{Indexer, Locator, Stylist};
|
||||||
use ruff_python_ast::types::Range;
|
|
||||||
use ruff_python_ast::whitespace::LinesWithTrailingNewline;
|
use ruff_python_ast::whitespace::LinesWithTrailingNewline;
|
||||||
|
|
||||||
/// Determine if a body contains only a single statement, taking into account
|
/// Determine if a body contains only a single statement, taking into account
|
||||||
|
@ -227,7 +227,7 @@ pub fn remove_unused_imports<'a>(
|
||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
let module_text = locator.slice(Range::from_located(stmt));
|
let module_text = locator.slice(stmt);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
|
|
||||||
let Some(Statement::Simple(body)) = tree.body.first_mut() else {
|
let Some(Statement::Simple(body)) = tree.body.first_mut() else {
|
||||||
|
|
|
@ -198,7 +198,7 @@ where
|
||||||
// Add the binding to the current scope.
|
// Add the binding to the current scope.
|
||||||
let context = self.ctx.execution_context();
|
let context = self.ctx.execution_context();
|
||||||
let scope = &mut self.ctx.scopes[scope_index];
|
let scope = &mut self.ctx.scopes[scope_index];
|
||||||
let usage = Some((scope.id, Range::from_located(stmt)));
|
let usage = Some((scope.id, Range::from(stmt)));
|
||||||
for (name, range) in names.iter().zip(ranges.iter()) {
|
for (name, range) in names.iter().zip(ranges.iter()) {
|
||||||
let index = self.ctx.bindings.len();
|
let index = self.ctx.bindings.len();
|
||||||
self.ctx.bindings.push(Binding {
|
self.ctx.bindings.push(Binding {
|
||||||
|
@ -227,7 +227,7 @@ where
|
||||||
if scope_index != GLOBAL_SCOPE_INDEX {
|
if scope_index != GLOBAL_SCOPE_INDEX {
|
||||||
let context = self.ctx.execution_context();
|
let context = self.ctx.execution_context();
|
||||||
let scope = &mut self.ctx.scopes[scope_index];
|
let scope = &mut self.ctx.scopes[scope_index];
|
||||||
let usage = Some((scope.id, Range::from_located(stmt)));
|
let usage = Some((scope.id, Range::from(stmt)));
|
||||||
for (name, range) in names.iter().zip(ranges.iter()) {
|
for (name, range) in names.iter().zip(ranges.iter()) {
|
||||||
// Add a binding to the current scope.
|
// Add a binding to the current scope.
|
||||||
let index = self.ctx.bindings.len();
|
let index = self.ctx.bindings.len();
|
||||||
|
@ -668,7 +668,7 @@ where
|
||||||
runtime_usage: None,
|
runtime_usage: None,
|
||||||
synthetic_usage: None,
|
synthetic_usage: None,
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(stmt),
|
range: Range::from(stmt),
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context,
|
context,
|
||||||
},
|
},
|
||||||
|
@ -865,10 +865,10 @@ where
|
||||||
.last()
|
.last()
|
||||||
.expect("No current scope found"))]
|
.expect("No current scope found"))]
|
||||||
.id,
|
.id,
|
||||||
Range::from_located(alias),
|
Range::from(alias),
|
||||||
)),
|
)),
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(alias),
|
range: Range::from(alias),
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
},
|
},
|
||||||
|
@ -879,7 +879,7 @@ where
|
||||||
{
|
{
|
||||||
self.diagnostics.push(Diagnostic::new(
|
self.diagnostics.push(Diagnostic::new(
|
||||||
pyflakes::rules::LateFutureImport,
|
pyflakes::rules::LateFutureImport,
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else if alias.node.name.contains('.') && alias.node.asname.is_none() {
|
} else if alias.node.name.contains('.') && alias.node.asname.is_none() {
|
||||||
|
@ -900,13 +900,13 @@ where
|
||||||
.last()
|
.last()
|
||||||
.expect("No current scope found"))]
|
.expect("No current scope found"))]
|
||||||
.id,
|
.id,
|
||||||
Range::from_located(alias),
|
Range::from(alias),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(alias),
|
range: Range::from(alias),
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
},
|
},
|
||||||
|
@ -938,13 +938,13 @@ where
|
||||||
.last()
|
.last()
|
||||||
.expect("No current scope found"))]
|
.expect("No current scope found"))]
|
||||||
.id,
|
.id,
|
||||||
Range::from_located(alias),
|
Range::from(alias),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(alias),
|
range: Range::from(alias),
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
},
|
},
|
||||||
|
@ -1211,10 +1211,10 @@ where
|
||||||
.last()
|
.last()
|
||||||
.expect("No current scope found"))]
|
.expect("No current scope found"))]
|
||||||
.id,
|
.id,
|
||||||
Range::from_located(alias),
|
Range::from(alias),
|
||||||
)),
|
)),
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(alias),
|
range: Range::from(alias),
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
},
|
},
|
||||||
|
@ -1233,7 +1233,7 @@ where
|
||||||
{
|
{
|
||||||
self.diagnostics.push(Diagnostic::new(
|
self.diagnostics.push(Diagnostic::new(
|
||||||
pyflakes::rules::LateFutureImport,
|
pyflakes::rules::LateFutureImport,
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else if alias.node.name == "*" {
|
} else if alias.node.name == "*" {
|
||||||
|
@ -1250,13 +1250,13 @@ where
|
||||||
.last()
|
.last()
|
||||||
.expect("No current scope found"))]
|
.expect("No current scope found"))]
|
||||||
.id,
|
.id,
|
||||||
Range::from_located(alias),
|
Range::from(alias),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(stmt),
|
range: Range::from(stmt),
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
},
|
},
|
||||||
|
@ -1273,7 +1273,7 @@ where
|
||||||
module.as_deref(),
|
module.as_deref(),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1286,7 +1286,7 @@ where
|
||||||
module.as_deref(),
|
module.as_deref(),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1328,13 +1328,13 @@ where
|
||||||
.last()
|
.last()
|
||||||
.expect("No current scope found"))]
|
.expect("No current scope found"))]
|
||||||
.id,
|
.id,
|
||||||
Range::from_located(alias),
|
Range::from(alias),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(alias),
|
range: Range::from(alias),
|
||||||
|
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
|
@ -1956,7 +1956,7 @@ where
|
||||||
runtime_usage: None,
|
runtime_usage: None,
|
||||||
synthetic_usage: None,
|
synthetic_usage: None,
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(stmt),
|
range: Range::from(stmt),
|
||||||
source: Some(RefEquality(stmt)),
|
source: Some(RefEquality(stmt)),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
});
|
});
|
||||||
|
@ -2021,7 +2021,7 @@ where
|
||||||
runtime_usage: None,
|
runtime_usage: None,
|
||||||
synthetic_usage: None,
|
synthetic_usage: None,
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(stmt),
|
range: Range::from(*stmt),
|
||||||
source: Some(RefEquality(stmt)),
|
source: Some(RefEquality(stmt)),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
});
|
});
|
||||||
|
@ -2164,7 +2164,7 @@ where
|
||||||
runtime_usage: None,
|
runtime_usage: None,
|
||||||
synthetic_usage: None,
|
synthetic_usage: None,
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(stmt),
|
range: Range::from(stmt),
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
},
|
},
|
||||||
|
@ -2194,7 +2194,7 @@ where
|
||||||
} = &expr.node
|
} = &expr.node
|
||||||
{
|
{
|
||||||
self.deferred.string_type_definitions.push((
|
self.deferred.string_type_definitions.push((
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
value,
|
value,
|
||||||
(self.ctx.in_annotation, self.ctx.in_type_checking_block),
|
(self.ctx.in_annotation, self.ctx.in_type_checking_block),
|
||||||
(self.ctx.scope_stack.clone(), self.ctx.parents.clone()),
|
(self.ctx.scope_stack.clone(), self.ctx.parents.clone()),
|
||||||
|
@ -2260,7 +2260,7 @@ where
|
||||||
elts,
|
elts,
|
||||||
check_too_many_expressions,
|
check_too_many_expressions,
|
||||||
check_two_starred_expressions,
|
check_two_starred_expressions,
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
) {
|
) {
|
||||||
self.diagnostics.push(diagnostic);
|
self.diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
|
@ -2295,10 +2295,9 @@ where
|
||||||
}
|
}
|
||||||
ExprContext::Store => {
|
ExprContext::Store => {
|
||||||
if self.settings.rules.enabled(&Rule::AmbiguousVariableName) {
|
if self.settings.rules.enabled(&Rule::AmbiguousVariableName) {
|
||||||
if let Some(diagnostic) = pycodestyle::rules::ambiguous_variable_name(
|
if let Some(diagnostic) =
|
||||||
id,
|
pycodestyle::rules::ambiguous_variable_name(id, Range::from(expr))
|
||||||
Range::from_located(expr),
|
{
|
||||||
) {
|
|
||||||
self.diagnostics.push(diagnostic);
|
self.diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2383,7 +2382,7 @@ where
|
||||||
{
|
{
|
||||||
if attr == "format" {
|
if attr == "format" {
|
||||||
// "...".format(...) call
|
// "...".format(...) call
|
||||||
let location = Range::from_located(expr);
|
let location = Range::from(expr);
|
||||||
match pyflakes::format::FormatSummary::try_from(value.as_ref()) {
|
match pyflakes::format::FormatSummary::try_from(value.as_ref()) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if self
|
if self
|
||||||
|
@ -2779,22 +2778,14 @@ where
|
||||||
func,
|
func,
|
||||||
args,
|
args,
|
||||||
keywords,
|
keywords,
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self.settings.rules.enabled(&Rule::CallDatetimeToday) {
|
if self.settings.rules.enabled(&Rule::CallDatetimeToday) {
|
||||||
flake8_datetimez::rules::call_datetime_today(
|
flake8_datetimez::rules::call_datetime_today(self, func, Range::from(expr));
|
||||||
self,
|
|
||||||
func,
|
|
||||||
Range::from_located(expr),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if self.settings.rules.enabled(&Rule::CallDatetimeUtcnow) {
|
if self.settings.rules.enabled(&Rule::CallDatetimeUtcnow) {
|
||||||
flake8_datetimez::rules::call_datetime_utcnow(
|
flake8_datetimez::rules::call_datetime_utcnow(self, func, Range::from(expr));
|
||||||
self,
|
|
||||||
func,
|
|
||||||
Range::from_located(expr),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if self
|
if self
|
||||||
.settings
|
.settings
|
||||||
|
@ -2804,7 +2795,7 @@ where
|
||||||
flake8_datetimez::rules::call_datetime_utcfromtimestamp(
|
flake8_datetimez::rules::call_datetime_utcfromtimestamp(
|
||||||
self,
|
self,
|
||||||
func,
|
func,
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self
|
if self
|
||||||
|
@ -2817,7 +2808,7 @@ where
|
||||||
func,
|
func,
|
||||||
args,
|
args,
|
||||||
keywords,
|
keywords,
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self
|
if self
|
||||||
|
@ -2830,7 +2821,7 @@ where
|
||||||
func,
|
func,
|
||||||
args,
|
args,
|
||||||
keywords,
|
keywords,
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self
|
if self
|
||||||
|
@ -2842,18 +2833,14 @@ where
|
||||||
self,
|
self,
|
||||||
func,
|
func,
|
||||||
args,
|
args,
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self.settings.rules.enabled(&Rule::CallDateToday) {
|
if self.settings.rules.enabled(&Rule::CallDateToday) {
|
||||||
flake8_datetimez::rules::call_date_today(self, func, Range::from_located(expr));
|
flake8_datetimez::rules::call_date_today(self, func, Range::from(expr));
|
||||||
}
|
}
|
||||||
if self.settings.rules.enabled(&Rule::CallDateFromtimestamp) {
|
if self.settings.rules.enabled(&Rule::CallDateFromtimestamp) {
|
||||||
flake8_datetimez::rules::call_date_fromtimestamp(
|
flake8_datetimez::rules::call_date_fromtimestamp(self, func, Range::from(expr));
|
||||||
self,
|
|
||||||
func,
|
|
||||||
Range::from_located(expr),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// pygrep-hooks
|
// pygrep-hooks
|
||||||
|
@ -3082,7 +3069,7 @@ where
|
||||||
.rules
|
.rules
|
||||||
.enabled(&Rule::PercentFormatUnsupportedFormatCharacter)
|
.enabled(&Rule::PercentFormatUnsupportedFormatCharacter)
|
||||||
{
|
{
|
||||||
let location = Range::from_located(expr);
|
let location = Range::from(expr);
|
||||||
match pyflakes::cformat::CFormatSummary::try_from(value.as_str()) {
|
match pyflakes::cformat::CFormatSummary::try_from(value.as_str()) {
|
||||||
Err(CFormatError {
|
Err(CFormatError {
|
||||||
typ: CFormatErrorType::UnsupportedFormatChar(c),
|
typ: CFormatErrorType::UnsupportedFormatChar(c),
|
||||||
|
@ -3271,7 +3258,7 @@ where
|
||||||
left,
|
left,
|
||||||
ops,
|
ops,
|
||||||
comparators,
|
comparators,
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3279,7 +3266,7 @@ where
|
||||||
self.diagnostics.extend(pycodestyle::rules::type_comparison(
|
self.diagnostics.extend(pycodestyle::rules::type_comparison(
|
||||||
ops,
|
ops,
|
||||||
comparators,
|
comparators,
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3356,7 +3343,7 @@ where
|
||||||
} => {
|
} => {
|
||||||
if self.ctx.in_type_definition && !self.ctx.in_literal {
|
if self.ctx.in_type_definition && !self.ctx.in_literal {
|
||||||
self.deferred.string_type_definitions.push((
|
self.deferred.string_type_definitions.push((
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
value,
|
value,
|
||||||
(self.ctx.in_annotation, self.ctx.in_type_checking_block),
|
(self.ctx.in_annotation, self.ctx.in_type_checking_block),
|
||||||
(self.ctx.scope_stack.clone(), self.ctx.parents.clone()),
|
(self.ctx.scope_stack.clone(), self.ctx.parents.clone()),
|
||||||
|
@ -3369,7 +3356,7 @@ where
|
||||||
{
|
{
|
||||||
if let Some(diagnostic) = flake8_bandit::rules::hardcoded_bind_all_interfaces(
|
if let Some(diagnostic) = flake8_bandit::rules::hardcoded_bind_all_interfaces(
|
||||||
value,
|
value,
|
||||||
&Range::from_located(expr),
|
&Range::from(expr),
|
||||||
) {
|
) {
|
||||||
self.diagnostics.push(diagnostic);
|
self.diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
|
@ -3952,7 +3939,7 @@ where
|
||||||
runtime_usage: None,
|
runtime_usage: None,
|
||||||
synthetic_usage: None,
|
synthetic_usage: None,
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(arg),
|
range: Range::from(arg),
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
},
|
},
|
||||||
|
@ -3960,7 +3947,7 @@ where
|
||||||
|
|
||||||
if self.settings.rules.enabled(&Rule::AmbiguousVariableName) {
|
if self.settings.rules.enabled(&Rule::AmbiguousVariableName) {
|
||||||
if let Some(diagnostic) =
|
if let Some(diagnostic) =
|
||||||
pycodestyle::rules::ambiguous_variable_name(&arg.node.arg, Range::from_located(arg))
|
pycodestyle::rules::ambiguous_variable_name(&arg.node.arg, Range::from(arg))
|
||||||
{
|
{
|
||||||
self.diagnostics.push(diagnostic);
|
self.diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
|
@ -3995,7 +3982,7 @@ where
|
||||||
runtime_usage: None,
|
runtime_usage: None,
|
||||||
synthetic_usage: None,
|
synthetic_usage: None,
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(pattern),
|
range: Range::from(pattern),
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
},
|
},
|
||||||
|
@ -4206,7 +4193,7 @@ impl<'a> Checker<'a> {
|
||||||
if let Some(index) = scope.bindings.get(&id.as_str()) {
|
if let Some(index) = scope.bindings.get(&id.as_str()) {
|
||||||
// Mark the binding as used.
|
// Mark the binding as used.
|
||||||
let context = self.ctx.execution_context();
|
let context = self.ctx.execution_context();
|
||||||
self.ctx.bindings[*index].mark_used(scope_id, Range::from_located(expr), context);
|
self.ctx.bindings[*index].mark_used(scope_id, Range::from(expr), context);
|
||||||
|
|
||||||
if self.ctx.bindings[*index].kind.is_annotation()
|
if self.ctx.bindings[*index].kind.is_annotation()
|
||||||
&& !self.ctx.in_deferred_string_type_definition
|
&& !self.ctx.in_deferred_string_type_definition
|
||||||
|
@ -4236,7 +4223,7 @@ impl<'a> Checker<'a> {
|
||||||
if let Some(index) = scope.bindings.get(full_name) {
|
if let Some(index) = scope.bindings.get(full_name) {
|
||||||
self.ctx.bindings[*index].mark_used(
|
self.ctx.bindings[*index].mark_used(
|
||||||
scope_id,
|
scope_id,
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
context,
|
context,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4253,7 +4240,7 @@ impl<'a> Checker<'a> {
|
||||||
if let Some(index) = scope.bindings.get(full_name.as_str()) {
|
if let Some(index) = scope.bindings.get(full_name.as_str()) {
|
||||||
self.ctx.bindings[*index].mark_used(
|
self.ctx.bindings[*index].mark_used(
|
||||||
scope_id,
|
scope_id,
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
context,
|
context,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4295,7 +4282,7 @@ impl<'a> Checker<'a> {
|
||||||
name: id.to_string(),
|
name: id.to_string(),
|
||||||
sources: from_list,
|
sources: from_list,
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -4326,7 +4313,7 @@ impl<'a> Checker<'a> {
|
||||||
|
|
||||||
self.diagnostics.push(Diagnostic::new(
|
self.diagnostics.push(Diagnostic::new(
|
||||||
pyflakes::rules::UndefinedName { name: id.clone() },
|
pyflakes::rules::UndefinedName { name: id.clone() },
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4398,7 +4385,7 @@ impl<'a> Checker<'a> {
|
||||||
runtime_usage: None,
|
runtime_usage: None,
|
||||||
synthetic_usage: None,
|
synthetic_usage: None,
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(expr),
|
range: Range::from(expr),
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
},
|
},
|
||||||
|
@ -4418,7 +4405,7 @@ impl<'a> Checker<'a> {
|
||||||
runtime_usage: None,
|
runtime_usage: None,
|
||||||
synthetic_usage: None,
|
synthetic_usage: None,
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(expr),
|
range: Range::from(expr),
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
},
|
},
|
||||||
|
@ -4434,7 +4421,7 @@ impl<'a> Checker<'a> {
|
||||||
runtime_usage: None,
|
runtime_usage: None,
|
||||||
synthetic_usage: None,
|
synthetic_usage: None,
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(expr),
|
range: Range::from(expr),
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
},
|
},
|
||||||
|
@ -4499,7 +4486,7 @@ impl<'a> Checker<'a> {
|
||||||
runtime_usage: None,
|
runtime_usage: None,
|
||||||
synthetic_usage: None,
|
synthetic_usage: None,
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(expr),
|
range: Range::from(expr),
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
},
|
},
|
||||||
|
@ -4515,7 +4502,7 @@ impl<'a> Checker<'a> {
|
||||||
runtime_usage: None,
|
runtime_usage: None,
|
||||||
synthetic_usage: None,
|
synthetic_usage: None,
|
||||||
typing_usage: None,
|
typing_usage: None,
|
||||||
range: Range::from_located(expr),
|
range: Range::from(expr),
|
||||||
source: Some(self.ctx.current_stmt().clone()),
|
source: Some(self.ctx.current_stmt().clone()),
|
||||||
context: self.ctx.execution_context(),
|
context: self.ctx.execution_context(),
|
||||||
},
|
},
|
||||||
|
@ -4546,7 +4533,7 @@ impl<'a> Checker<'a> {
|
||||||
pyflakes::rules::UndefinedName {
|
pyflakes::rules::UndefinedName {
|
||||||
name: id.to_string(),
|
name: id.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5286,7 +5273,7 @@ impl<'a> Checker<'a> {
|
||||||
|
|
||||||
// Extract a `Docstring` from a `Definition`.
|
// Extract a `Docstring` from a `Definition`.
|
||||||
let expr = definition.docstring.unwrap();
|
let expr = definition.docstring.unwrap();
|
||||||
let contents = self.locator.slice(Range::from_located(expr));
|
let contents = self.locator.slice(expr);
|
||||||
let indentation = self.locator.slice(Range::new(
|
let indentation = self.locator.slice(Range::new(
|
||||||
Location::new(expr.location.row(), 0),
|
Location::new(expr.location.row(), 0),
|
||||||
Location::new(expr.location.row(), expr.location.column()),
|
Location::new(expr.location.row(), expr.location.column()),
|
||||||
|
|
|
@ -144,7 +144,7 @@ pub fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) {
|
||||||
{
|
{
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
SysVersionSlice1Referenced,
|
SysVersionSlice1Referenced,
|
||||||
Range::from_located(value),
|
Range::from(value),
|
||||||
));
|
));
|
||||||
} else if *i == BigInt::from(3)
|
} else if *i == BigInt::from(3)
|
||||||
&& checker
|
&& checker
|
||||||
|
@ -154,7 +154,7 @@ pub fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) {
|
||||||
{
|
{
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
SysVersionSlice3Referenced,
|
SysVersionSlice3Referenced,
|
||||||
Range::from_located(value),
|
Range::from(value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,17 +167,15 @@ pub fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) {
|
||||||
if *i == BigInt::from(2)
|
if *i == BigInt::from(2)
|
||||||
&& checker.settings.rules.enabled(&Rule::SysVersion2Referenced)
|
&& checker.settings.rules.enabled(&Rule::SysVersion2Referenced)
|
||||||
{
|
{
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
SysVersion2Referenced,
|
.diagnostics
|
||||||
Range::from_located(value),
|
.push(Diagnostic::new(SysVersion2Referenced, Range::from(value)));
|
||||||
));
|
|
||||||
} else if *i == BigInt::from(0)
|
} else if *i == BigInt::from(0)
|
||||||
&& checker.settings.rules.enabled(&Rule::SysVersion0Referenced)
|
&& checker.settings.rules.enabled(&Rule::SysVersion0Referenced)
|
||||||
{
|
{
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
SysVersion0Referenced,
|
.diagnostics
|
||||||
Range::from_located(value),
|
.push(Diagnostic::new(SysVersion0Referenced, Range::from(value)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +214,7 @@ pub fn compare(checker: &mut Checker, left: &Expr, ops: &[Cmpop], comparators: &
|
||||||
{
|
{
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
SysVersionInfo0Eq3Referenced,
|
SysVersionInfo0Eq3Referenced,
|
||||||
Range::from_located(left),
|
Range::from(left),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,10 +232,9 @@ pub fn compare(checker: &mut Checker, left: &Expr, ops: &[Cmpop], comparators: &
|
||||||
) = (ops, comparators)
|
) = (ops, comparators)
|
||||||
{
|
{
|
||||||
if checker.settings.rules.enabled(&Rule::SysVersionInfo1CmpInt) {
|
if checker.settings.rules.enabled(&Rule::SysVersionInfo1CmpInt) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
SysVersionInfo1CmpInt,
|
.diagnostics
|
||||||
Range::from_located(left),
|
.push(Diagnostic::new(SysVersionInfo1CmpInt, Range::from(left)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -266,7 +263,7 @@ pub fn compare(checker: &mut Checker, left: &Expr, ops: &[Cmpop], comparators: &
|
||||||
{
|
{
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
SysVersionInfoMinorCmpInt,
|
SysVersionInfoMinorCmpInt,
|
||||||
Range::from_located(left),
|
Range::from(left),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -290,16 +287,14 @@ pub fn compare(checker: &mut Checker, left: &Expr, ops: &[Cmpop], comparators: &
|
||||||
{
|
{
|
||||||
if s.len() == 1 {
|
if s.len() == 1 {
|
||||||
if checker.settings.rules.enabled(&Rule::SysVersionCmpStr10) {
|
if checker.settings.rules.enabled(&Rule::SysVersionCmpStr10) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
SysVersionCmpStr10,
|
.diagnostics
|
||||||
Range::from_located(left),
|
.push(Diagnostic::new(SysVersionCmpStr10, Range::from(left)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
} else if checker.settings.rules.enabled(&Rule::SysVersionCmpStr3) {
|
} else if checker.settings.rules.enabled(&Rule::SysVersionCmpStr3) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
SysVersionCmpStr3,
|
.diagnostics
|
||||||
Range::from_located(left),
|
.push(Diagnostic::new(SysVersionCmpStr3, Range::from(left)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,6 +309,6 @@ pub fn name_or_attribute(checker: &mut Checker, expr: &Expr) {
|
||||||
{
|
{
|
||||||
checker
|
checker
|
||||||
.diagnostics
|
.diagnostics
|
||||||
.push(Diagnostic::new(SixPY3Referenced, Range::from_located(expr)));
|
.push(Diagnostic::new(SixPY3Referenced, Range::from(expr)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::fix::Fix;
|
||||||
|
|
||||||
/// ANN204
|
/// ANN204
|
||||||
pub fn add_return_none_annotation(locator: &Locator, stmt: &Stmt) -> Result<Fix> {
|
pub fn add_return_none_annotation(locator: &Locator, stmt: &Stmt) -> Result<Fix> {
|
||||||
let range = Range::from_located(stmt);
|
let range = Range::from(stmt);
|
||||||
let contents = locator.slice(range);
|
let contents = locator.slice(range);
|
||||||
|
|
||||||
// Find the colon (following the `def` keyword).
|
// Find the colon (following the `def` keyword).
|
||||||
|
|
|
@ -446,7 +446,7 @@ fn check_dynamically_typed<F>(
|
||||||
if checker.ctx.match_typing_expr(annotation, "Any") {
|
if checker.ctx.match_typing_expr(annotation, "Any") {
|
||||||
diagnostics.push(Diagnostic::new(
|
diagnostics.push(Diagnostic::new(
|
||||||
AnyType { name: func() },
|
AnyType { name: func() },
|
||||||
Range::from_located(annotation),
|
Range::from(annotation),
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -513,7 +513,7 @@ pub fn definition(
|
||||||
MissingTypeFunctionArgument {
|
MissingTypeFunctionArgument {
|
||||||
name: arg.node.arg.to_string(),
|
name: arg.node.arg.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(arg),
|
Range::from(arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -544,7 +544,7 @@ pub fn definition(
|
||||||
MissingTypeArgs {
|
MissingTypeArgs {
|
||||||
name: arg.node.arg.to_string(),
|
name: arg.node.arg.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(arg),
|
Range::from(arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -575,7 +575,7 @@ pub fn definition(
|
||||||
MissingTypeKwargs {
|
MissingTypeKwargs {
|
||||||
name: arg.node.arg.to_string(),
|
name: arg.node.arg.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(arg),
|
Range::from(arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -592,7 +592,7 @@ pub fn definition(
|
||||||
MissingTypeCls {
|
MissingTypeCls {
|
||||||
name: arg.node.arg.to_string(),
|
name: arg.node.arg.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(arg),
|
Range::from(arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -601,7 +601,7 @@ pub fn definition(
|
||||||
MissingTypeSelf {
|
MissingTypeSelf {
|
||||||
name: arg.node.arg.to_string(),
|
name: arg.node.arg.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(arg),
|
Range::from(arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ pub fn bad_file_permissions(
|
||||||
if (int_value & WRITE_WORLD > 0) || (int_value & EXECUTE_GROUP > 0) {
|
if (int_value & WRITE_WORLD > 0) || (int_value & EXECUTE_GROUP > 0) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
BadFilePermissions { mask: int_value },
|
BadFilePermissions { mask: int_value },
|
||||||
Range::from_located(mode_arg),
|
Range::from(mode_arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,5 +24,5 @@ pub fn exec_used(expr: &Expr, func: &Expr) -> Option<Diagnostic> {
|
||||||
if id != "exec" {
|
if id != "exec" {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(Diagnostic::new(ExecBuiltin, Range::from_located(expr)))
|
Some(Diagnostic::new(ExecBuiltin, Range::from(expr)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ fn check_password_kwarg(arg: &Arg, default: &Expr) -> Option<Diagnostic> {
|
||||||
HardcodedPasswordDefault {
|
HardcodedPasswordDefault {
|
||||||
string: string.to_string(),
|
string: string.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(default),
|
Range::from(default),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub fn hardcoded_password_func_arg(keywords: &[Keyword]) -> Vec<Diagnostic> {
|
||||||
HardcodedPasswordFuncArg {
|
HardcodedPasswordFuncArg {
|
||||||
string: string.to_string(),
|
string: string.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(keyword),
|
Range::from(keyword),
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
|
|
@ -54,7 +54,7 @@ pub fn compare_to_hardcoded_password_string(left: &Expr, comparators: &[Expr]) -
|
||||||
HardcodedPasswordString {
|
HardcodedPasswordString {
|
||||||
string: string.to_string(),
|
string: string.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(comp),
|
Range::from(comp),
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -69,7 +69,7 @@ pub fn assign_hardcoded_password_string(value: &Expr, targets: &[Expr]) -> Optio
|
||||||
HardcodedPasswordString {
|
HardcodedPasswordString {
|
||||||
string: string.to_string(),
|
string: string.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(value),
|
Range::from(value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,10 +97,9 @@ fn unparse_string_format_expression(checker: &mut Checker, expr: &Expr) -> Optio
|
||||||
pub fn hardcoded_sql_expression(checker: &mut Checker, expr: &Expr) {
|
pub fn hardcoded_sql_expression(checker: &mut Checker, expr: &Expr) {
|
||||||
match unparse_string_format_expression(checker, expr) {
|
match unparse_string_format_expression(checker, expr) {
|
||||||
Some(string) if matches_sql_statement(&string) => {
|
Some(string) if matches_sql_statement(&string) => {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
HardcodedSQLExpression,
|
.diagnostics
|
||||||
Range::from_located(expr),
|
.push(Diagnostic::new(HardcodedSQLExpression, Range::from(expr)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ pub fn hardcoded_tmp_directory(
|
||||||
HardcodedTempFile {
|
HardcodedTempFile {
|
||||||
string: value.to_string(),
|
string: value.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -75,7 +75,7 @@ pub fn hashlib_insecure_hash_functions(
|
||||||
HashlibInsecureHashFunction {
|
HashlibInsecureHashFunction {
|
||||||
string: hash_func_name.to_string(),
|
string: hash_func_name.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(name_arg),
|
Range::from(name_arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ pub fn hashlib_insecure_hash_functions(
|
||||||
HashlibInsecureHashFunction {
|
HashlibInsecureHashFunction {
|
||||||
string: (*func_name).to_string(),
|
string: (*func_name).to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(func),
|
Range::from(func),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,20 +58,20 @@ pub fn jinja2_autoescape_false(
|
||||||
if id.as_str() != "select_autoescape" {
|
if id.as_str() != "select_autoescape" {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
Jinja2AutoescapeFalse { value: true },
|
Jinja2AutoescapeFalse { value: true },
|
||||||
Range::from_located(autoescape_arg),
|
Range::from(autoescape_arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => checker.diagnostics.push(Diagnostic::new(
|
_ => checker.diagnostics.push(Diagnostic::new(
|
||||||
Jinja2AutoescapeFalse { value: true },
|
Jinja2AutoescapeFalse { value: true },
|
||||||
Range::from_located(autoescape_arg),
|
Range::from(autoescape_arg),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
Jinja2AutoescapeFalse { value: false },
|
Jinja2AutoescapeFalse { value: false },
|
||||||
Range::from_located(func),
|
Range::from(func),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub fn logging_config_insecure_listen(
|
||||||
if call_args.get_argument("verify", None).is_none() {
|
if call_args.get_argument("verify", None).is_none() {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
LoggingConfigInsecureListen,
|
LoggingConfigInsecureListen,
|
||||||
Range::from_located(func),
|
Range::from(func),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ pub fn request_with_no_cert_validation(
|
||||||
RequestWithNoCertValidation {
|
RequestWithNoCertValidation {
|
||||||
string: target.to_string(),
|
string: target.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(verify_arg),
|
Range::from(verify_arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,13 +57,13 @@ pub fn request_without_timeout(
|
||||||
RequestWithoutTimeout {
|
RequestWithoutTimeout {
|
||||||
timeout: Some(timeout),
|
timeout: Some(timeout),
|
||||||
},
|
},
|
||||||
Range::from_located(timeout_arg),
|
Range::from(timeout_arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
RequestWithoutTimeout { timeout: None },
|
RequestWithoutTimeout { timeout: None },
|
||||||
Range::from_located(func),
|
Range::from(func),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub fn snmp_insecure_version(
|
||||||
if value.is_zero() || value.is_one() {
|
if value.is_zero() || value.is_one() {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
SnmpInsecureVersion,
|
SnmpInsecureVersion,
|
||||||
Range::from_located(mp_model_arg),
|
Range::from(mp_model_arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,10 +37,9 @@ pub fn snmp_weak_cryptography(
|
||||||
{
|
{
|
||||||
let call_args = SimpleCallArgs::new(args, keywords);
|
let call_args = SimpleCallArgs::new(args, keywords);
|
||||||
if call_args.len() < 3 {
|
if call_args.len() < 3 {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
SnmpWeakCryptography,
|
.diagnostics
|
||||||
Range::from_located(func),
|
.push(Diagnostic::new(SnmpWeakCryptography, Range::from(func)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ pub fn try_except_continue(
|
||||||
{
|
{
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
TryExceptContinue,
|
TryExceptContinue,
|
||||||
Range::from_located(excepthandler),
|
Range::from(excepthandler),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,9 +31,8 @@ pub fn try_except_pass(
|
||||||
&& body[0].node == StmtKind::Pass
|
&& body[0].node == StmtKind::Pass
|
||||||
&& (check_typed_exception || is_untyped_exception(type_, checker))
|
&& (check_typed_exception || is_untyped_exception(type_, checker))
|
||||||
{
|
{
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
TryExceptPass,
|
.diagnostics
|
||||||
Range::from_located(excepthandler),
|
.push(Diagnostic::new(TryExceptPass, Range::from(excepthandler)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,13 +56,13 @@ pub fn unsafe_yaml_load(checker: &mut Checker, func: &Expr, args: &[Expr], keywo
|
||||||
};
|
};
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
UnsafeYAMLLoad { loader },
|
UnsafeYAMLLoad { loader },
|
||||||
Range::from_located(loader_arg),
|
Range::from(loader_arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
UnsafeYAMLLoad { loader: None },
|
UnsafeYAMLLoad { loader: None },
|
||||||
Range::from_located(func),
|
Range::from(func),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ pub fn blind_except(
|
||||||
BlindExcept {
|
BlindExcept {
|
||||||
name: id.to_string(),
|
name: id.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(type_),
|
Range::from(type_),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ fn add_if_boolean(checker: &mut Checker, arg: &Expr, kind: DiagnosticKind) {
|
||||||
if is_boolean_arg(arg) {
|
if is_boolean_arg(arg) {
|
||||||
checker
|
checker
|
||||||
.diagnostics
|
.diagnostics
|
||||||
.push(Diagnostic::new(kind, Range::from_located(arg)));
|
.push(Diagnostic::new(kind, Range::from(arg)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ pub fn check_positional_boolean_in_def(
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
BooleanPositionalArgInFunctionDefinition,
|
BooleanPositionalArgInFunctionDefinition,
|
||||||
Range::from_located(arg),
|
Range::from(arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ pub fn abstract_base_class(
|
||||||
EmptyMethodWithoutAbstractDecorator {
|
EmptyMethodWithoutAbstractDecorator {
|
||||||
name: format!("{name}.{method_name}"),
|
name: format!("{name}.{method_name}"),
|
||||||
},
|
},
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ pub fn abstract_base_class(
|
||||||
AbstractBaseClassWithoutAbstractMethod {
|
AbstractBaseClassWithoutAbstractMethod {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ pub fn assert_false(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg: Option
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut diagnostic = Diagnostic::new(AssertFalse, Range::from_located(test));
|
let mut diagnostic = Diagnostic::new(AssertFalse, Range::from(test));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
unparse_stmt(&assertion_error(msg), checker.stylist),
|
unparse_stmt(&assertion_error(msg), checker.stylist),
|
||||||
|
|
|
@ -62,8 +62,7 @@ pub fn assert_raises_exception(checker: &mut Checker, stmt: &Stmt, items: &[With
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
AssertRaisesException,
|
.diagnostics
|
||||||
Range::from_located(stmt),
|
.push(Diagnostic::new(AssertRaisesException, Range::from(stmt)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,7 @@ pub fn assignment_to_os_environ(checker: &mut Checker, targets: &[Expr]) {
|
||||||
if id != "os" {
|
if id != "os" {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
AssignmentToOsEnviron,
|
.diagnostics
|
||||||
Range::from_located(target),
|
.push(Diagnostic::new(AssignmentToOsEnviron, Range::from(target)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ pub fn cached_instance_method(checker: &mut Checker, decorator_list: &[Expr]) {
|
||||||
) {
|
) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
CachedInstanceMethod,
|
CachedInstanceMethod,
|
||||||
Range::from_located(decorator),
|
Range::from(decorator),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,7 @@ pub fn cannot_raise_literal(checker: &mut Checker, expr: &Expr) {
|
||||||
let ExprKind::Constant { .. } = &expr.node else {
|
let ExprKind::Constant { .. } = &expr.node else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
CannotRaiseLiteral,
|
.diagnostics
|
||||||
Range::from_located(expr),
|
.push(Diagnostic::new(CannotRaiseLiteral, Range::from(expr)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ fn duplicate_handler_exceptions<'a>(
|
||||||
.sorted()
|
.sorted()
|
||||||
.collect::<Vec<String>>(),
|
.collect::<Vec<String>>(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
|
@ -157,7 +157,7 @@ pub fn duplicate_exceptions(checker: &mut Checker, handlers: &[Excepthandler]) {
|
||||||
DuplicateTryBlockException {
|
DuplicateTryBlockException {
|
||||||
name: name.join("."),
|
name: name.join("."),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ pub fn except_with_empty_tuple(checker: &mut Checker, excepthandler: &Excepthand
|
||||||
if elts.is_empty() {
|
if elts.is_empty() {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
ExceptWithEmptyTuple,
|
ExceptWithEmptyTuple,
|
||||||
Range::from_located(excepthandler),
|
Range::from(excepthandler),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ where
|
||||||
name: compose_call_path(func),
|
name: compose_call_path(func),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
visitor::walk_expr(self, expr);
|
visitor::walk_expr(self, expr);
|
||||||
|
|
|
@ -40,8 +40,8 @@ where
|
||||||
fn visit_expr(&mut self, expr: &'b Expr) {
|
fn visit_expr(&mut self, expr: &'b Expr) {
|
||||||
match &expr.node {
|
match &expr.node {
|
||||||
ExprKind::Name { id, ctx } => match ctx {
|
ExprKind::Name { id, ctx } => match ctx {
|
||||||
ExprContext::Load => self.loaded.push((id, expr, Range::from_located(expr))),
|
ExprContext::Load => self.loaded.push((id, expr, Range::from(expr))),
|
||||||
ExprContext::Store => self.stored.push((id, expr, Range::from_located(expr))),
|
ExprContext::Store => self.stored.push((id, expr, Range::from(expr))),
|
||||||
ExprContext::Del => {}
|
ExprContext::Del => {}
|
||||||
},
|
},
|
||||||
_ => visitor::walk_expr(self, expr),
|
_ => visitor::walk_expr(self, expr),
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub fn getattr_with_constant(checker: &mut Checker, expr: &Expr, func: &Expr, ar
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut diagnostic = Diagnostic::new(GetAttrWithConstant, Range::from_located(expr));
|
let mut diagnostic = Diagnostic::new(GetAttrWithConstant, Range::from(expr));
|
||||||
|
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
|
|
|
@ -34,7 +34,7 @@ fn walk_stmt(checker: &mut Checker, body: &[Stmt], f: fn(&Stmt) -> bool) {
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
match &stmt.node {
|
match &stmt.node {
|
||||||
|
|
|
@ -75,7 +75,7 @@ pub fn loop_variable_overrides_iterator(checker: &mut Checker, target: &Expr, it
|
||||||
LoopVariableOverridesIterator {
|
LoopVariableOverridesIterator {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,7 @@ pub fn mutable_argument_default(checker: &mut Checker, arguments: &Arguments) {
|
||||||
{
|
{
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
MutableArgumentDefault,
|
MutableArgumentDefault,
|
||||||
Range::from_located(default),
|
Range::from(default),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ pub fn redundant_tuple_in_exception_handler(checker: &mut Checker, handlers: &[E
|
||||||
RedundantTupleInExceptionHandler {
|
RedundantTupleInExceptionHandler {
|
||||||
name: unparse_expr(elt, checker.stylist),
|
name: unparse_expr(elt, checker.stylist),
|
||||||
},
|
},
|
||||||
Range::from_located(type_),
|
Range::from(type_),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
|
|
|
@ -78,7 +78,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.ctx.current_stmt().node {
|
if let StmtKind::Expr { value: child } = &checker.ctx.current_stmt().node {
|
||||||
if expr == child.as_ref() {
|
if expr == child.as_ref() {
|
||||||
let mut diagnostic = Diagnostic::new(SetAttrWithConstant, Range::from_located(expr));
|
let mut diagnostic = Diagnostic::new(SetAttrWithConstant, Range::from(expr));
|
||||||
|
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub fn star_arg_unpacking_after_keyword_arg(
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
StarArgUnpackingAfterKeywordArg,
|
StarArgUnpackingAfterKeywordArg,
|
||||||
Range::from_located(arg),
|
Range::from(arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,9 +39,8 @@ pub fn strip_with_multi_characters(checker: &mut Checker, expr: &Expr, func: &Ex
|
||||||
|
|
||||||
let num_chars = value.chars().count();
|
let num_chars = value.chars().count();
|
||||||
if num_chars > 1 && num_chars != value.chars().unique().count() {
|
if num_chars > 1 && num_chars != value.chars().unique().count() {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
StripWithMultiCharacters,
|
.diagnostics
|
||||||
Range::from_located(expr),
|
.push(Diagnostic::new(StripWithMultiCharacters, Range::from(expr)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,7 @@ pub fn unary_prefix_increment(checker: &mut Checker, expr: &Expr, op: &Unaryop,
|
||||||
if !matches!(op, Unaryop::UAdd) {
|
if !matches!(op, Unaryop::UAdd) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
UnaryPrefixIncrement,
|
.diagnostics
|
||||||
Range::from_located(expr),
|
.push(Diagnostic::new(UnaryPrefixIncrement, Range::from(expr)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub fn unintentional_type_annotation(
|
||||||
if matches!(&value.node, ExprKind::Name { .. }) {
|
if matches!(&value.node, ExprKind::Name { .. }) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
UnintentionalTypeAnnotation,
|
UnintentionalTypeAnnotation,
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ pub fn unintentional_type_annotation(
|
||||||
if id != "self" {
|
if id != "self" {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
UnintentionalTypeAnnotation,
|
UnintentionalTypeAnnotation,
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,7 @@ pub fn unreliable_callable_check(checker: &mut Checker, expr: &Expr, func: &Expr
|
||||||
if s != "__call__" {
|
if s != "__call__" {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
UnreliableCallableCheck,
|
.diagnostics
|
||||||
Range::from_located(expr),
|
.push(Diagnostic::new(UnreliableCallableCheck, Range::from(expr)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,7 +159,7 @@ pub fn unused_loop_control_variable(
|
||||||
rename: rename.clone(),
|
rename: rename.clone(),
|
||||||
certainty,
|
certainty,
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if let Some(rename) = rename {
|
if let Some(rename) = rename {
|
||||||
if certainty.into() && checker.patch(diagnostic.kind.rule()) {
|
if certainty.into() && checker.patch(diagnostic.kind.rule()) {
|
||||||
|
|
|
@ -22,9 +22,8 @@ impl Violation for UselessComparison {
|
||||||
|
|
||||||
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.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
UselessComparison,
|
.diagnostics
|
||||||
Range::from_located(expr),
|
.push(Diagnostic::new(UselessComparison, Range::from(expr)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub fn useless_contextlib_suppress(checker: &mut Checker, expr: &Expr, func: &Ex
|
||||||
{
|
{
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
UselessContextlibSuppress,
|
UselessContextlibSuppress,
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,18 +23,16 @@ pub fn useless_expression(checker: &mut Checker, body: &[Stmt]) {
|
||||||
if let StmtKind::Expr { value } = &stmt.node {
|
if let StmtKind::Expr { value } = &stmt.node {
|
||||||
match &value.node {
|
match &value.node {
|
||||||
ExprKind::List { .. } | ExprKind::Dict { .. } | ExprKind::Set { .. } => {
|
ExprKind::List { .. } | ExprKind::Dict { .. } | ExprKind::Set { .. } => {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
UselessExpression,
|
.diagnostics
|
||||||
Range::from_located(value),
|
.push(Diagnostic::new(UselessExpression, Range::from(value)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
ExprKind::Constant { value: val, .. } => match &val {
|
ExprKind::Constant { value: val, .. } => match &val {
|
||||||
Constant::Str { .. } | Constant::Ellipsis => {}
|
Constant::Str { .. } | Constant::Ellipsis => {}
|
||||||
_ => {
|
_ => {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
UselessExpression,
|
.diagnostics
|
||||||
Range::from_located(value),
|
.push(Diagnostic::new(UselessExpression, Range::from(value)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -35,10 +35,9 @@ pub fn zip_without_explicit_strict(
|
||||||
.map_or(false, |name| name == "strict")
|
.map_or(false, |name| name == "strict")
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
ZipWithoutExplicitStrict,
|
.diagnostics
|
||||||
Range::from_located(expr),
|
.push(Diagnostic::new(ZipWithoutExplicitStrict, Range::from(expr)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,7 +192,7 @@ pub fn builtin_shadowing<T>(
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
},
|
},
|
||||||
Range::from_located(located),
|
Range::from(located),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -8,7 +8,6 @@ use libcst_native::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use ruff_python_ast::source_code::{Locator, Stylist};
|
use ruff_python_ast::source_code::{Locator, Stylist};
|
||||||
use ruff_python_ast::types::Range;
|
|
||||||
|
|
||||||
use crate::cst::matchers::{match_expr, match_module};
|
use crate::cst::matchers::{match_expr, match_module};
|
||||||
use crate::fix::Fix;
|
use crate::fix::Fix;
|
||||||
|
@ -36,7 +35,7 @@ pub fn fix_unnecessary_generator_list(
|
||||||
expr: &rustpython_parser::ast::Expr,
|
expr: &rustpython_parser::ast::Expr,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
// Expr(Call(GeneratorExp)))) -> Expr(ListComp)))
|
// Expr(Call(GeneratorExp)))) -> Expr(ListComp)))
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let mut body = match_expr(&mut tree)?;
|
let mut body = match_expr(&mut tree)?;
|
||||||
let call = match_call(body)?;
|
let call = match_call(body)?;
|
||||||
|
@ -83,7 +82,7 @@ pub fn fix_unnecessary_generator_set(
|
||||||
parent: Option<&rustpython_parser::ast::Expr>,
|
parent: Option<&rustpython_parser::ast::Expr>,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
// Expr(Call(GeneratorExp)))) -> Expr(SetComp)))
|
// Expr(Call(GeneratorExp)))) -> Expr(SetComp)))
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let mut body = match_expr(&mut tree)?;
|
let mut body = match_expr(&mut tree)?;
|
||||||
let call = match_call(body)?;
|
let call = match_call(body)?;
|
||||||
|
@ -140,7 +139,7 @@ pub fn fix_unnecessary_generator_dict(
|
||||||
expr: &rustpython_parser::ast::Expr,
|
expr: &rustpython_parser::ast::Expr,
|
||||||
parent: Option<&rustpython_parser::ast::Expr>,
|
parent: Option<&rustpython_parser::ast::Expr>,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let mut body = match_expr(&mut tree)?;
|
let mut body = match_expr(&mut tree)?;
|
||||||
let call = match_call(body)?;
|
let call = match_call(body)?;
|
||||||
|
@ -214,7 +213,7 @@ pub fn fix_unnecessary_list_comprehension_set(
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
// Expr(Call(ListComp)))) ->
|
// Expr(Call(ListComp)))) ->
|
||||||
// Expr(SetComp)))
|
// Expr(SetComp)))
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let mut body = match_expr(&mut tree)?;
|
let mut body = match_expr(&mut tree)?;
|
||||||
let call = match_call(body)?;
|
let call = match_call(body)?;
|
||||||
|
@ -258,7 +257,7 @@ pub fn fix_unnecessary_list_comprehension_dict(
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &rustpython_parser::ast::Expr,
|
expr: &rustpython_parser::ast::Expr,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let mut body = match_expr(&mut tree)?;
|
let mut body = match_expr(&mut tree)?;
|
||||||
let call = match_call(body)?;
|
let call = match_call(body)?;
|
||||||
|
@ -357,7 +356,7 @@ pub fn fix_unnecessary_literal_set(
|
||||||
expr: &rustpython_parser::ast::Expr,
|
expr: &rustpython_parser::ast::Expr,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
// Expr(Call(List|Tuple)))) -> Expr(Set)))
|
// Expr(Call(List|Tuple)))) -> Expr(Set)))
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let mut body = match_expr(&mut tree)?;
|
let mut body = match_expr(&mut tree)?;
|
||||||
let mut call = match_call(body)?;
|
let mut call = match_call(body)?;
|
||||||
|
@ -408,7 +407,7 @@ pub fn fix_unnecessary_literal_dict(
|
||||||
expr: &rustpython_parser::ast::Expr,
|
expr: &rustpython_parser::ast::Expr,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
// Expr(Call(List|Tuple)))) -> Expr(Dict)))
|
// Expr(Call(List|Tuple)))) -> Expr(Dict)))
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let mut body = match_expr(&mut tree)?;
|
let mut body = match_expr(&mut tree)?;
|
||||||
let call = match_call(body)?;
|
let call = match_call(body)?;
|
||||||
|
@ -481,7 +480,7 @@ pub fn fix_unnecessary_collection_call(
|
||||||
expr: &rustpython_parser::ast::Expr,
|
expr: &rustpython_parser::ast::Expr,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
// Expr(Call("list" | "tuple" | "dict")))) -> Expr(List|Tuple|Dict)
|
// Expr(Call("list" | "tuple" | "dict")))) -> Expr(List|Tuple|Dict)
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let mut body = match_expr(&mut tree)?;
|
let mut body = match_expr(&mut tree)?;
|
||||||
let call = match_call(body)?;
|
let call = match_call(body)?;
|
||||||
|
@ -596,7 +595,7 @@ pub fn fix_unnecessary_literal_within_tuple_call(
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &rustpython_parser::ast::Expr,
|
expr: &rustpython_parser::ast::Expr,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let mut body = match_expr(&mut tree)?;
|
let mut body = match_expr(&mut tree)?;
|
||||||
let call = match_call(body)?;
|
let call = match_call(body)?;
|
||||||
|
@ -655,7 +654,7 @@ pub fn fix_unnecessary_literal_within_list_call(
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &rustpython_parser::ast::Expr,
|
expr: &rustpython_parser::ast::Expr,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let mut body = match_expr(&mut tree)?;
|
let mut body = match_expr(&mut tree)?;
|
||||||
let call = match_call(body)?;
|
let call = match_call(body)?;
|
||||||
|
@ -717,7 +716,7 @@ pub fn fix_unnecessary_list_call(
|
||||||
expr: &rustpython_parser::ast::Expr,
|
expr: &rustpython_parser::ast::Expr,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
// Expr(Call(List|Tuple)))) -> Expr(List|Tuple)))
|
// Expr(Call(List|Tuple)))) -> Expr(List|Tuple)))
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let mut body = match_expr(&mut tree)?;
|
let mut body = match_expr(&mut tree)?;
|
||||||
let call = match_call(body)?;
|
let call = match_call(body)?;
|
||||||
|
@ -747,7 +746,7 @@ pub fn fix_unnecessary_call_around_sorted(
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &rustpython_parser::ast::Expr,
|
expr: &rustpython_parser::ast::Expr,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let mut body = match_expr(&mut tree)?;
|
let mut body = match_expr(&mut tree)?;
|
||||||
let outer_call = match_call(body)?;
|
let outer_call = match_call(body)?;
|
||||||
|
@ -874,7 +873,7 @@ pub fn fix_unnecessary_double_cast_or_process(
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &rustpython_parser::ast::Expr,
|
expr: &rustpython_parser::ast::Expr,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let body = match_expr(&mut tree)?;
|
let body = match_expr(&mut tree)?;
|
||||||
let mut outer_call = match_call(body)?;
|
let mut outer_call = match_call(body)?;
|
||||||
|
@ -913,7 +912,7 @@ pub fn fix_unnecessary_comprehension(
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &rustpython_parser::ast::Expr,
|
expr: &rustpython_parser::ast::Expr,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let mut body = match_expr(&mut tree)?;
|
let mut body = match_expr(&mut tree)?;
|
||||||
|
|
||||||
|
@ -989,7 +988,7 @@ pub fn fix_unnecessary_map(
|
||||||
parent: Option<&rustpython_parser::ast::Expr>,
|
parent: Option<&rustpython_parser::ast::Expr>,
|
||||||
kind: &str,
|
kind: &str,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
let module_text = locator.slice(Range::from_located(expr));
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
let mut body = match_expr(&mut tree)?;
|
let mut body = match_expr(&mut tree)?;
|
||||||
let call = match_call(body)?;
|
let call = match_call(body)?;
|
||||||
|
|
|
@ -84,7 +84,7 @@ pub fn unnecessary_call_around_sorted(
|
||||||
UnnecessaryCallAroundSorted {
|
UnnecessaryCallAroundSorted {
|
||||||
func: outer.to_string(),
|
func: outer.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_call_around_sorted(checker.locator, checker.stylist, expr) {
|
match fixes::fix_unnecessary_call_around_sorted(checker.locator, checker.stylist, expr) {
|
||||||
|
|
|
@ -64,7 +64,7 @@ pub fn unnecessary_collection_call(
|
||||||
UnnecessaryCollectionCall {
|
UnnecessaryCollectionCall {
|
||||||
obj_type: id.to_string(),
|
obj_type: id.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_collection_call(checker.locator, checker.stylist, expr) {
|
match fixes::fix_unnecessary_collection_call(checker.locator, checker.stylist, expr) {
|
||||||
|
|
|
@ -65,7 +65,7 @@ pub fn unnecessary_comprehension(
|
||||||
UnnecessaryComprehension {
|
UnnecessaryComprehension {
|
||||||
obj_type: id.to_string(),
|
obj_type: id.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_comprehension(checker.locator, checker.stylist, expr) {
|
match fixes::fix_unnecessary_comprehension(checker.locator, checker.stylist, expr) {
|
||||||
|
|
|
@ -112,7 +112,7 @@ pub fn unnecessary_double_cast_or_process(
|
||||||
|| (outer == "set" && inner == "set")
|
|| (outer == "set" && inner == "set")
|
||||||
|| ((outer == "list" || outer == "tuple") && (inner == "list" || inner == "tuple"))
|
|| ((outer == "list" || outer == "tuple") && (inner == "list" || inner == "tuple"))
|
||||||
{
|
{
|
||||||
let mut diagnostic = create_diagnostic(inner, outer, Range::from_located(expr));
|
let mut diagnostic = create_diagnostic(inner, outer, Range::from(expr));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
if let Ok(fix) = fixes::fix_unnecessary_double_cast_or_process(
|
if let Ok(fix) = fixes::fix_unnecessary_double_cast_or_process(
|
||||||
checker.locator,
|
checker.locator,
|
||||||
|
|
|
@ -58,8 +58,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 diagnostic =
|
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorDict, Range::from(expr));
|
||||||
Diagnostic::new(UnnecessaryGeneratorDict, Range::from_located(expr));
|
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_generator_dict(
|
match fixes::fix_unnecessary_generator_dict(
|
||||||
checker.locator,
|
checker.locator,
|
||||||
|
|
|
@ -58,7 +58,7 @@ pub fn unnecessary_generator_list(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let ExprKind::GeneratorExp { .. } = argument {
|
if let ExprKind::GeneratorExp { .. } = argument {
|
||||||
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorList, Range::from_located(expr));
|
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorList, Range::from(expr));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_generator_list(checker.locator, checker.stylist, expr) {
|
match fixes::fix_unnecessary_generator_list(checker.locator, checker.stylist, expr) {
|
||||||
Ok(fix) => {
|
Ok(fix) => {
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub fn unnecessary_generator_set(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let ExprKind::GeneratorExp { .. } = argument {
|
if let ExprKind::GeneratorExp { .. } = argument {
|
||||||
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorSet, Range::from_located(expr));
|
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorSet, Range::from(expr));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_generator_set(
|
match fixes::fix_unnecessary_generator_set(
|
||||||
checker.locator,
|
checker.locator,
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub fn unnecessary_list_call(checker: &mut Checker, expr: &Expr, func: &Expr, ar
|
||||||
if !matches!(argument, ExprKind::ListComp { .. }) {
|
if !matches!(argument, ExprKind::ListComp { .. }) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut diagnostic = Diagnostic::new(UnnecessaryListCall, Range::from_located(expr));
|
let mut diagnostic = Diagnostic::new(UnnecessaryListCall, Range::from(expr));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_list_call(checker.locator, checker.stylist, expr) {
|
match fixes::fix_unnecessary_list_call(checker.locator, checker.stylist, expr) {
|
||||||
Ok(fix) => {
|
Ok(fix) => {
|
||||||
|
|
|
@ -48,8 +48,7 @@ pub fn unnecessary_list_comprehension_dict(
|
||||||
if elts.len() != 2 {
|
if elts.len() != 2 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut diagnostic =
|
let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionDict, Range::from(expr));
|
||||||
Diagnostic::new(UnnecessaryListComprehensionDict, Range::from_located(expr));
|
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_list_comprehension_dict(checker.locator, checker.stylist, expr)
|
match fixes::fix_unnecessary_list_comprehension_dict(checker.locator, checker.stylist, expr)
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,8 +40,7 @@ pub fn unnecessary_list_comprehension_set(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let ExprKind::ListComp { .. } = &argument {
|
if let ExprKind::ListComp { .. } = &argument {
|
||||||
let mut diagnostic =
|
let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionSet, Range::from(expr));
|
||||||
Diagnostic::new(UnnecessaryListComprehensionSet, Range::from_located(expr));
|
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_list_comprehension_set(
|
match fixes::fix_unnecessary_list_comprehension_set(
|
||||||
checker.locator,
|
checker.locator,
|
||||||
|
|
|
@ -58,7 +58,7 @@ pub fn unnecessary_literal_dict(
|
||||||
UnnecessaryLiteralDict {
|
UnnecessaryLiteralDict {
|
||||||
obj_type: kind.to_string(),
|
obj_type: kind.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_literal_dict(checker.locator, checker.stylist, expr) {
|
match fixes::fix_unnecessary_literal_dict(checker.locator, checker.stylist, expr) {
|
||||||
|
|
|
@ -51,7 +51,7 @@ pub fn unnecessary_literal_set(
|
||||||
UnnecessaryLiteralSet {
|
UnnecessaryLiteralSet {
|
||||||
obj_type: kind.to_string(),
|
obj_type: kind.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_literal_set(checker.locator, checker.stylist, expr) {
|
match fixes::fix_unnecessary_literal_set(checker.locator, checker.stylist, expr) {
|
||||||
|
|
|
@ -66,7 +66,7 @@ pub fn unnecessary_literal_within_list_call(
|
||||||
UnnecessaryLiteralWithinListCall {
|
UnnecessaryLiteralWithinListCall {
|
||||||
literal: argument_kind.to_string(),
|
literal: argument_kind.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_literal_within_list_call(
|
match fixes::fix_unnecessary_literal_within_list_call(
|
||||||
|
|
|
@ -67,7 +67,7 @@ pub fn unnecessary_literal_within_tuple_call(
|
||||||
UnnecessaryLiteralWithinTupleCall {
|
UnnecessaryLiteralWithinTupleCall {
|
||||||
literal: argument_kind.to_string(),
|
literal: argument_kind.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_literal_within_tuple_call(
|
match fixes::fix_unnecessary_literal_within_tuple_call(
|
||||||
|
|
|
@ -104,7 +104,7 @@ pub fn unnecessary_map(
|
||||||
};
|
};
|
||||||
|
|
||||||
if args.len() == 2 && matches!(&args[0].node, ExprKind::Lambda { .. }) {
|
if args.len() == 2 && matches!(&args[0].node, ExprKind::Lambda { .. }) {
|
||||||
let mut diagnostic = create_diagnostic("generator", Range::from_located(expr));
|
let mut diagnostic = create_diagnostic("generator", Range::from(expr));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_map(
|
match fixes::fix_unnecessary_map(
|
||||||
checker.locator,
|
checker.locator,
|
||||||
|
@ -136,7 +136,7 @@ pub fn unnecessary_map(
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if let ExprKind::Lambda { .. } = argument {
|
if let ExprKind::Lambda { .. } = argument {
|
||||||
let mut diagnostic = create_diagnostic(id, Range::from_located(expr));
|
let mut diagnostic = create_diagnostic(id, Range::from(expr));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_map(
|
match fixes::fix_unnecessary_map(
|
||||||
checker.locator,
|
checker.locator,
|
||||||
|
@ -169,7 +169,7 @@ pub fn unnecessary_map(
|
||||||
if let ExprKind::Lambda { body, .. } = &argument {
|
if let ExprKind::Lambda { body, .. } = &argument {
|
||||||
if matches!(&body.node, ExprKind::Tuple { elts, .. } | ExprKind::List { elts, .. } if elts.len() == 2)
|
if matches!(&body.node, ExprKind::Tuple { elts, .. } | ExprKind::List { elts, .. } if elts.len() == 2)
|
||||||
{
|
{
|
||||||
let mut diagnostic = create_diagnostic(id, Range::from_located(expr));
|
let mut diagnostic = create_diagnostic(id, Range::from(expr));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_map(
|
match fixes::fix_unnecessary_map(
|
||||||
checker.locator,
|
checker.locator,
|
||||||
|
|
|
@ -73,6 +73,6 @@ pub fn unnecessary_subscript_reversal(
|
||||||
UnnecessarySubscriptReversal {
|
UnnecessarySubscriptReversal {
|
||||||
func: id.to_string(),
|
func: id.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ pub fn debugger_call(checker: &mut Checker, expr: &Expr, func: &Expr) {
|
||||||
Debugger {
|
Debugger {
|
||||||
using_type: DebuggerUsingType::Call(format_call_path(target)),
|
using_type: DebuggerUsingType::Call(format_call_path(target)),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ pub fn debugger_import(stmt: &Stmt, module: Option<&str>, name: &str) -> Option<
|
||||||
Debugger {
|
Debugger {
|
||||||
using_type: DebuggerUsingType::Import(format_call_path(&call_path)),
|
using_type: DebuggerUsingType::Import(format_call_path(&call_path)),
|
||||||
},
|
},
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,7 +91,7 @@ pub fn debugger_import(stmt: &Stmt, module: Option<&str>, name: &str) -> Option<
|
||||||
Debugger {
|
Debugger {
|
||||||
using_type: DebuggerUsingType::Import(name.to_string()),
|
using_type: DebuggerUsingType::Import(name.to_string()),
|
||||||
},
|
},
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,18 +76,12 @@ pub fn all_with_model_form(checker: &Checker, bases: &[Expr], body: &[Stmt]) ->
|
||||||
match &value {
|
match &value {
|
||||||
Constant::Str(s) => {
|
Constant::Str(s) => {
|
||||||
if s == "__all__" {
|
if s == "__all__" {
|
||||||
return Some(Diagnostic::new(
|
return Some(Diagnostic::new(AllWithModelForm, Range::from(element)));
|
||||||
AllWithModelForm,
|
|
||||||
Range::from_located(element),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Constant::Bytes(b) => {
|
Constant::Bytes(b) => {
|
||||||
if b == "__all__".as_bytes() {
|
if b == "__all__".as_bytes() {
|
||||||
return Some(Diagnostic::new(
|
return Some(Diagnostic::new(AllWithModelForm, Range::from(element)));
|
||||||
AllWithModelForm,
|
|
||||||
Range::from_located(element),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
|
@ -68,10 +68,7 @@ pub fn exclude_with_model_form(
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if id == "exclude" {
|
if id == "exclude" {
|
||||||
return Some(Diagnostic::new(
|
return Some(Diagnostic::new(ExcludeWithModelForm, Range::from(target)));
|
||||||
ExcludeWithModelForm,
|
|
||||||
Range::from_located(target),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,10 +77,9 @@ pub fn locals_in_render_function(
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
LocalsInRenderFunction,
|
.diagnostics
|
||||||
Range::from_located(locals),
|
.push(Diagnostic::new(LocalsInRenderFunction, Range::from(locals)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_locals_call(checker: &Checker, expr: &Expr) -> bool {
|
fn is_locals_call(checker: &Checker, expr: &Expr) -> bool {
|
||||||
|
|
|
@ -64,7 +64,7 @@ pub fn model_without_dunder_str(
|
||||||
if !has_dunder_method(body) {
|
if !has_dunder_method(body) {
|
||||||
return Some(Diagnostic::new(
|
return Some(Diagnostic::new(
|
||||||
ModelWithoutDunderStr,
|
ModelWithoutDunderStr,
|
||||||
Range::from_located(class_location),
|
Range::from(class_location),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
|
|
@ -69,7 +69,7 @@ where
|
||||||
if i > 0 && is_receiver && !seen_receiver {
|
if i > 0 && is_receiver && !seen_receiver {
|
||||||
diagnostics.push(Diagnostic::new(
|
diagnostics.push(Diagnostic::new(
|
||||||
NonLeadingReceiverDecorator,
|
NonLeadingReceiverDecorator,
|
||||||
Range::from_located(decorator),
|
Range::from(decorator),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if !is_receiver && seen_receiver {
|
if !is_receiver && seen_receiver {
|
||||||
|
|
|
@ -74,7 +74,7 @@ pub fn nullable_model_string_field(checker: &Checker, body: &[Stmt]) -> Vec<Diag
|
||||||
NullableModelStringField {
|
NullableModelStringField {
|
||||||
field_name: field_name.to_string(),
|
field_name: field_name.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(value),
|
Range::from(value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,20 +164,18 @@ pub fn string_in_exception(checker: &mut Checker, exc: &Expr) {
|
||||||
} => {
|
} => {
|
||||||
if checker.settings.rules.enabled(&Rule::RawStringInException) {
|
if checker.settings.rules.enabled(&Rule::RawStringInException) {
|
||||||
if string.len() > checker.settings.flake8_errmsg.max_string_length {
|
if string.len() > checker.settings.flake8_errmsg.max_string_length {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
RawStringInException,
|
.diagnostics
|
||||||
Range::from_located(first),
|
.push(Diagnostic::new(RawStringInException, Range::from(first)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check for f-strings
|
// Check for f-strings
|
||||||
ExprKind::JoinedStr { .. } => {
|
ExprKind::JoinedStr { .. } => {
|
||||||
if checker.settings.rules.enabled(&Rule::FStringInException) {
|
if checker.settings.rules.enabled(&Rule::FStringInException) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
FStringInException,
|
.diagnostics
|
||||||
Range::from_located(first),
|
.push(Diagnostic::new(FStringInException, Range::from(first)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check for .format() calls
|
// Check for .format() calls
|
||||||
|
@ -187,7 +185,7 @@ pub fn string_in_exception(checker: &mut Checker, exc: &Expr) {
|
||||||
if attr == "format" && matches!(value.node, ExprKind::Constant { .. }) {
|
if attr == "format" && matches!(value.node, ExprKind::Constant { .. }) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
DotFormatInException,
|
DotFormatInException,
|
||||||
Range::from_located(first),
|
Range::from(first),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,7 @@ pub fn explicit(expr: &Expr) -> Option<Diagnostic> {
|
||||||
) {
|
) {
|
||||||
return Some(Diagnostic::new(
|
return Some(Diagnostic::new(
|
||||||
ExplicitStringConcatenation,
|
ExplicitStringConcatenation,
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ pub fn check_conventional_import(
|
||||||
if !is_valid_import {
|
if !is_valid_import {
|
||||||
return Some(Diagnostic::new(
|
return Some(Diagnostic::new(
|
||||||
UnconventionalImportAlias(name.to_string(), expected_alias.to_string()),
|
UnconventionalImportAlias(name.to_string(), expected_alias.to_string()),
|
||||||
Range::from_located(import_from),
|
Range::from(import_from),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,18 +44,16 @@ fn check_msg(checker: &mut Checker, msg: &Expr) {
|
||||||
ExprKind::BinOp { op, .. } => match op {
|
ExprKind::BinOp { op, .. } => match op {
|
||||||
Operator::Add => {
|
Operator::Add => {
|
||||||
if checker.settings.rules.enabled(&Rule::LoggingStringConcat) {
|
if checker.settings.rules.enabled(&Rule::LoggingStringConcat) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
LoggingStringConcat,
|
.diagnostics
|
||||||
Range::from_located(msg),
|
.push(Diagnostic::new(LoggingStringConcat, Range::from(msg)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Operator::Mod => {
|
Operator::Mod => {
|
||||||
if checker.settings.rules.enabled(&Rule::LoggingPercentFormat) {
|
if checker.settings.rules.enabled(&Rule::LoggingPercentFormat) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
LoggingPercentFormat,
|
.diagnostics
|
||||||
Range::from_located(msg),
|
.push(Diagnostic::new(LoggingPercentFormat, Range::from(msg)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -65,7 +63,7 @@ fn check_msg(checker: &mut Checker, msg: &Expr) {
|
||||||
if checker.settings.rules.enabled(&Rule::LoggingFString) {
|
if checker.settings.rules.enabled(&Rule::LoggingFString) {
|
||||||
checker
|
checker
|
||||||
.diagnostics
|
.diagnostics
|
||||||
.push(Diagnostic::new(LoggingFString, Range::from_located(msg)));
|
.push(Diagnostic::new(LoggingFString, Range::from(msg)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check for .format() calls.
|
// Check for .format() calls.
|
||||||
|
@ -73,10 +71,9 @@ fn check_msg(checker: &mut Checker, msg: &Expr) {
|
||||||
if checker.settings.rules.enabled(&Rule::LoggingStringFormat) {
|
if checker.settings.rules.enabled(&Rule::LoggingStringFormat) {
|
||||||
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.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
LoggingStringFormat,
|
.diagnostics
|
||||||
Range::from_located(msg),
|
.push(Diagnostic::new(LoggingStringFormat, Range::from(msg)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +96,7 @@ fn check_log_record_attr_clash(checker: &mut Checker, extra: &Keyword) {
|
||||||
if RESERVED_ATTRS.contains(&string.as_str()) {
|
if RESERVED_ATTRS.contains(&string.as_str()) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
LoggingExtraAttrClash(string.to_string()),
|
LoggingExtraAttrClash(string.to_string()),
|
||||||
Range::from_located(key),
|
Range::from(key),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +114,7 @@ fn check_log_record_attr_clash(checker: &mut Checker, extra: &Keyword) {
|
||||||
if RESERVED_ATTRS.contains(&key.as_str()) {
|
if RESERVED_ATTRS.contains(&key.as_str()) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
LoggingExtraAttrClash(key.to_string()),
|
LoggingExtraAttrClash(key.to_string()),
|
||||||
Range::from_located(keyword),
|
Range::from(keyword),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,7 +220,7 @@ pub fn logging_call(checker: &mut Checker, func: &Expr, args: &[Expr], keywords:
|
||||||
{
|
{
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
LoggingRedundantExcInfo,
|
LoggingRedundantExcInfo,
|
||||||
Range::from_located(exc_info),
|
Range::from(exc_info),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ use anyhow::{bail, Result};
|
||||||
use libcst_native::{Codegen, CodegenState, Expression, GeneratorExp};
|
use libcst_native::{Codegen, CodegenState, Expression, GeneratorExp};
|
||||||
|
|
||||||
use ruff_python_ast::source_code::{Locator, Stylist};
|
use ruff_python_ast::source_code::{Locator, Stylist};
|
||||||
use ruff_python_ast::types::Range;
|
|
||||||
|
|
||||||
use crate::cst::matchers::{match_call, match_expression};
|
use crate::cst::matchers::{match_call, match_expression};
|
||||||
use crate::fix::Fix;
|
use crate::fix::Fix;
|
||||||
|
@ -14,7 +13,7 @@ pub fn fix_unnecessary_comprehension_any_all(
|
||||||
expr: &rustpython_parser::ast::Expr,
|
expr: &rustpython_parser::ast::Expr,
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
// Expr(ListComp) -> Expr(GeneratorExp)
|
// Expr(ListComp) -> Expr(GeneratorExp)
|
||||||
let expression_text = locator.slice(Range::from_located(expr));
|
let expression_text = locator.slice(expr);
|
||||||
let mut tree = match_expression(expression_text)?;
|
let mut tree = match_expression(expression_text)?;
|
||||||
let call = match_call(&mut tree)?;
|
let call = match_call(&mut tree)?;
|
||||||
|
|
||||||
|
|
|
@ -170,8 +170,7 @@ 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 diagnostic =
|
let mut diagnostic = Diagnostic::new(UnnecessaryPass, Range::from(pass_stmt));
|
||||||
Diagnostic::new(UnnecessaryPass, Range::from_located(pass_stmt));
|
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
if let Some(index) = match_trailing_comment(pass_stmt, checker.locator) {
|
if let Some(index) = match_trailing_comment(pass_stmt, checker.locator) {
|
||||||
diagnostic.amend(Fix::deletion(
|
diagnostic.amend(Fix::deletion(
|
||||||
|
@ -240,7 +239,7 @@ pub fn dupe_class_field_definitions<'a, 'b>(
|
||||||
if !seen_targets.insert(target) {
|
if !seen_targets.insert(target) {
|
||||||
let mut diagnostic = Diagnostic::new(
|
let mut diagnostic = Diagnostic::new(
|
||||||
DupeClassFieldDefinitions(target.to_string()),
|
DupeClassFieldDefinitions(target.to_string()),
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
let deleted: Vec<&Stmt> = checker.deletions.iter().map(Into::into).collect();
|
let deleted: Vec<&Stmt> = checker.deletions.iter().map(Into::into).collect();
|
||||||
|
@ -306,7 +305,7 @@ where
|
||||||
PreferUniqueEnums {
|
PreferUniqueEnums {
|
||||||
value: unparse_expr(value, checker.stylist),
|
value: unparse_expr(value, checker.stylist),
|
||||||
},
|
},
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
);
|
);
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
|
@ -320,7 +319,7 @@ pub fn no_unnecessary_spread(checker: &mut Checker, keys: &[Option<Expr>], value
|
||||||
// We only care about when the key is None which indicates a spread `**`
|
// We only care about when the key is None which indicates a spread `**`
|
||||||
// inside a dict.
|
// inside a dict.
|
||||||
if let ExprKind::Dict { .. } = value.node {
|
if let ExprKind::Dict { .. } = value.node {
|
||||||
let diagnostic = Diagnostic::new(UnnecessarySpread, Range::from_located(value));
|
let diagnostic = Diagnostic::new(UnnecessarySpread, Range::from(value));
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -340,10 +339,8 @@ pub fn unnecessary_comprehension_any_all(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let ExprKind::ListComp { .. } = args[0].node {
|
if let ExprKind::ListComp { .. } = args[0].node {
|
||||||
let mut diagnostic = Diagnostic::new(
|
let mut diagnostic =
|
||||||
UnnecessaryComprehensionAnyAll,
|
Diagnostic::new(UnnecessaryComprehensionAnyAll, Range::from(&args[0]));
|
||||||
Range::from_located(&args[0]),
|
|
||||||
);
|
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fixes::fix_unnecessary_comprehension_any_all(
|
match fixes::fix_unnecessary_comprehension_any_all(
|
||||||
checker.locator,
|
checker.locator,
|
||||||
|
@ -386,8 +383,7 @@ pub fn no_unnecessary_dict_kwargs(checker: &mut Checker, expr: &Expr, kwargs: &[
|
||||||
// handle case of foo(**{**bar})
|
// handle case of foo(**{**bar})
|
||||||
(keys.len() == 1 && keys[0].is_none())
|
(keys.len() == 1 && keys[0].is_none())
|
||||||
{
|
{
|
||||||
let diagnostic =
|
let diagnostic = Diagnostic::new(UnnecessaryDictKwargs, Range::from(expr));
|
||||||
Diagnostic::new(UnnecessaryDictKwargs, Range::from_located(expr));
|
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,7 +420,7 @@ pub fn single_starts_ends_with(checker: &mut Checker, values: &[Expr], node: &Bo
|
||||||
SingleStartsEndsWith {
|
SingleStartsEndsWith {
|
||||||
attr: attr.to_string(),
|
attr: attr.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(value),
|
Range::from(value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -446,7 +442,7 @@ pub fn prefer_list_builtin(checker: &mut Checker, expr: &Expr) {
|
||||||
{
|
{
|
||||||
if let ExprKind::List { elts, .. } = &body.node {
|
if let ExprKind::List { elts, .. } = &body.node {
|
||||||
if elts.is_empty() {
|
if elts.is_empty() {
|
||||||
let mut diagnostic = Diagnostic::new(PreferListBuiltin, Range::from_located(expr));
|
let mut diagnostic = Diagnostic::new(PreferListBuiltin, Range::from(expr));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
"list".to_string(),
|
"list".to_string(),
|
||||||
|
|
|
@ -54,11 +54,11 @@ pub fn print_call(checker: &mut Checker, func: &Expr, keywords: &[Keyword]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Diagnostic::new(PrintFound, Range::from_located(func))
|
Diagnostic::new(PrintFound, Range::from(func))
|
||||||
} else if call_path.as_ref().map_or(false, |call_path| {
|
} else if call_path.as_ref().map_or(false, |call_path| {
|
||||||
*call_path.as_slice() == ["pprint", "pprint"]
|
*call_path.as_slice() == ["pprint", "pprint"]
|
||||||
}) {
|
}) {
|
||||||
Diagnostic::new(PPrintFound, Range::from_located(func))
|
Diagnostic::new(PPrintFound, Range::from(func))
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ pub fn bad_version_info_comparison(
|
||||||
}
|
}
|
||||||
|
|
||||||
if !matches!(op, Cmpop::Lt | Cmpop::GtE) {
|
if !matches!(op, Cmpop::Lt | Cmpop::GtE) {
|
||||||
let diagnostic = Diagnostic::new(BadVersionInfoComparison, Range::from_located(expr));
|
let diagnostic = Diagnostic::new(BadVersionInfoComparison, Range::from(expr));
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,8 @@ impl Violation for DocstringInStub {
|
||||||
/// PYI021
|
/// PYI021
|
||||||
pub fn docstring_in_stubs(checker: &mut Checker, docstring: Option<&Expr>) {
|
pub fn docstring_in_stubs(checker: &mut Checker, docstring: Option<&Expr>) {
|
||||||
if let Some(docstr) = &docstring {
|
if let Some(docstr) = &docstring {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
DocstringInStub,
|
.diagnostics
|
||||||
Range::from_located(docstr),
|
.push(Diagnostic::new(DocstringInStub, Range::from(*docstr)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,7 @@ pub fn non_empty_stub_body(checker: &mut Checker, body: &[Stmt]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
NonEmptyStubBody,
|
.diagnostics
|
||||||
Range::from_located(&body[0]),
|
.push(Diagnostic::new(NonEmptyStubBody, Range::from(&body[0])));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ pub fn pass_statement_stub_body(checker: &mut Checker, body: &[Stmt]) {
|
||||||
if matches!(body[0].node, StmtKind::Pass) {
|
if matches!(body[0].node, StmtKind::Pass) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
PassStatementStubBody,
|
PassStatementStubBody,
|
||||||
Range::from_located(&body[0]),
|
Range::from(&body[0]),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ pub fn prefix_type_params(checker: &mut Checker, value: &Expr, targets: &[Expr])
|
||||||
};
|
};
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
PrefixTypeParams { kind },
|
PrefixTypeParams { kind },
|
||||||
Range::from_located(value),
|
Range::from(value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,16 +57,16 @@ fn is_valid_default_value_with_annotation(default: &Expr, checker: &Checker) ->
|
||||||
ExprKind::Constant {
|
ExprKind::Constant {
|
||||||
value: Constant::Str(..),
|
value: Constant::Str(..),
|
||||||
..
|
..
|
||||||
} => return checker.locator.slice(Range::from_located(default)).len() <= 50,
|
} => return checker.locator.slice(default).len() <= 50,
|
||||||
ExprKind::Constant {
|
ExprKind::Constant {
|
||||||
value: Constant::Bytes(..),
|
value: Constant::Bytes(..),
|
||||||
..
|
..
|
||||||
} => return checker.locator.slice(Range::from_located(default)).len() <= 50,
|
} => return checker.locator.slice(default).len() <= 50,
|
||||||
ExprKind::Constant {
|
ExprKind::Constant {
|
||||||
value: Constant::Int(..),
|
value: Constant::Int(..),
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
return checker.locator.slice(Range::from_located(default)).len() <= 10;
|
return checker.locator.slice(default).len() <= 10;
|
||||||
}
|
}
|
||||||
ExprKind::UnaryOp {
|
ExprKind::UnaryOp {
|
||||||
op: Unaryop::USub,
|
op: Unaryop::USub,
|
||||||
|
@ -77,7 +77,7 @@ fn is_valid_default_value_with_annotation(default: &Expr, checker: &Checker) ->
|
||||||
..
|
..
|
||||||
} = &operand.node
|
} = &operand.node
|
||||||
{
|
{
|
||||||
return checker.locator.slice(Range::from_located(operand)).len() <= 10;
|
return checker.locator.slice(operand).len() <= 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExprKind::BinOp {
|
ExprKind::BinOp {
|
||||||
|
@ -101,7 +101,7 @@ fn is_valid_default_value_with_annotation(default: &Expr, checker: &Checker) ->
|
||||||
..
|
..
|
||||||
} = &left.node
|
} = &left.node
|
||||||
{
|
{
|
||||||
return checker.locator.slice(Range::from_located(left)).len() <= 10;
|
return checker.locator.slice(left).len() <= 10;
|
||||||
} else if let ExprKind::UnaryOp {
|
} else if let ExprKind::UnaryOp {
|
||||||
op: Unaryop::USub,
|
op: Unaryop::USub,
|
||||||
operand,
|
operand,
|
||||||
|
@ -114,7 +114,7 @@ fn is_valid_default_value_with_annotation(default: &Expr, checker: &Checker) ->
|
||||||
..
|
..
|
||||||
} = &operand.node
|
} = &operand.node
|
||||||
{
|
{
|
||||||
return checker.locator.slice(Range::from_located(operand)).len() <= 10;
|
return checker.locator.slice(operand).len() <= 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ pub fn typed_argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
|
||||||
if !is_valid_default_value_with_annotation(default, checker) {
|
if !is_valid_default_value_with_annotation(default, checker) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
TypedArgumentSimpleDefaults,
|
TypedArgumentSimpleDefaults,
|
||||||
Range::from_located(default),
|
Range::from(default),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ pub fn typed_argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
|
||||||
if !is_valid_default_value_with_annotation(default, checker) {
|
if !is_valid_default_value_with_annotation(default, checker) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
TypedArgumentSimpleDefaults,
|
TypedArgumentSimpleDefaults,
|
||||||
Range::from_located(default),
|
Range::from(default),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ pub fn argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
|
||||||
if !is_valid_default_value_with_annotation(default, checker) {
|
if !is_valid_default_value_with_annotation(default, checker) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
ArgumentSimpleDefaults,
|
ArgumentSimpleDefaults,
|
||||||
Range::from_located(default),
|
Range::from(default),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ pub fn argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
|
||||||
if !is_valid_default_value_with_annotation(default, checker) {
|
if !is_valid_default_value_with_annotation(default, checker) {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
ArgumentSimpleDefaults,
|
ArgumentSimpleDefaults,
|
||||||
Range::from_located(default),
|
Range::from(default),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,7 @@ pub fn unrecognized_platform(
|
||||||
};
|
};
|
||||||
|
|
||||||
let diagnostic_unrecognized_platform_check =
|
let diagnostic_unrecognized_platform_check =
|
||||||
Diagnostic::new(UnrecognizedPlatformCheck, Range::from_located(expr));
|
Diagnostic::new(UnrecognizedPlatformCheck, Range::from(expr));
|
||||||
if !checker
|
if !checker
|
||||||
.ctx
|
.ctx
|
||||||
.resolve_call_path(left)
|
.resolve_call_path(left)
|
||||||
|
@ -143,7 +143,7 @@ pub fn unrecognized_platform(
|
||||||
UnrecognizedPlatformName {
|
UnrecognizedPlatformName {
|
||||||
platform: value.clone(),
|
platform: value.clone(),
|
||||||
},
|
},
|
||||||
Range::from_located(right),
|
Range::from(right),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,7 @@ where
|
||||||
AssertInExcept {
|
AssertInExcept {
|
||||||
name: id.to_string(),
|
name: id.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(current_assert),
|
Range::from(current_assert),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,13 +197,13 @@ pub fn unittest_assertion(
|
||||||
// the assertion is part of a larger expression.
|
// the assertion is part of a larger expression.
|
||||||
let fixable = checker.ctx.current_expr_parent().is_none()
|
let fixable = checker.ctx.current_expr_parent().is_none()
|
||||||
&& matches!(checker.ctx.current_stmt().node, StmtKind::Expr { .. })
|
&& matches!(checker.ctx.current_stmt().node, StmtKind::Expr { .. })
|
||||||
&& !has_comments_in(Range::from_located(expr), checker.locator);
|
&& !has_comments_in(Range::from(expr), checker.locator);
|
||||||
let mut diagnostic = Diagnostic::new(
|
let mut diagnostic = Diagnostic::new(
|
||||||
UnittestAssertion {
|
UnittestAssertion {
|
||||||
assertion: unittest_assert.to_string(),
|
assertion: unittest_assert.to_string(),
|
||||||
fixable,
|
fixable,
|
||||||
},
|
},
|
||||||
Range::from_located(func),
|
Range::from(func),
|
||||||
);
|
);
|
||||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||||
if let Ok(stmt) = unittest_assert.generate_assert(args, keywords) {
|
if let Ok(stmt) = unittest_assert.generate_assert(args, keywords) {
|
||||||
|
@ -226,10 +226,7 @@ pub fn unittest_assertion(
|
||||||
/// PT015
|
/// PT015
|
||||||
pub fn assert_falsy(stmt: &Stmt, test: &Expr) -> Option<Diagnostic> {
|
pub fn assert_falsy(stmt: &Stmt, test: &Expr) -> Option<Diagnostic> {
|
||||||
if is_falsy_constant(test) {
|
if is_falsy_constant(test) {
|
||||||
Some(Diagnostic::new(
|
Some(Diagnostic::new(AssertAlwaysFalse, Range::from(stmt)))
|
||||||
AssertAlwaysFalse,
|
|
||||||
Range::from_located(stmt),
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -435,9 +432,8 @@ pub fn composite_condition(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg:
|
||||||
if matches!(composite, CompositionKind::Simple | CompositionKind::Mixed) {
|
if matches!(composite, CompositionKind::Simple | CompositionKind::Mixed) {
|
||||||
let fixable = matches!(composite, CompositionKind::Simple)
|
let fixable = matches!(composite, CompositionKind::Simple)
|
||||||
&& msg.is_none()
|
&& msg.is_none()
|
||||||
&& !has_comments_in(Range::from_located(stmt), checker.locator);
|
&& !has_comments_in(Range::from(stmt), checker.locator);
|
||||||
let mut diagnostic =
|
let mut diagnostic = Diagnostic::new(CompositeAssertion { fixable }, Range::from(stmt));
|
||||||
Diagnostic::new(CompositeAssertion { fixable }, Range::from_located(stmt));
|
|
||||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||||
if let Ok(fix) = fix_composite_condition(stmt, checker.locator, checker.stylist) {
|
if let Ok(fix) = fix_composite_condition(stmt, checker.locator, checker.stylist) {
|
||||||
diagnostic.amend(fix);
|
diagnostic.amend(fix);
|
||||||
|
|
|
@ -27,16 +27,14 @@ pub fn fail_call(checker: &mut Checker, func: &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.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
FailWithoutMessage,
|
.diagnostics
|
||||||
Range::from_located(func),
|
.push(Diagnostic::new(FailWithoutMessage, Range::from(func)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
FailWithoutMessage,
|
.diagnostics
|
||||||
Range::from_located(func),
|
.push(Diagnostic::new(FailWithoutMessage, Range::from(func)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,7 +246,7 @@ fn pytest_fixture_parentheses(
|
||||||
expected_parens: preferred.to_string(),
|
expected_parens: preferred.to_string(),
|
||||||
actual_parens: actual.to_string(),
|
actual_parens: actual.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(decorator),
|
Range::from(decorator),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(fix);
|
diagnostic.amend(fix);
|
||||||
|
@ -292,7 +292,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E
|
||||||
FixturePositionalArgs {
|
FixturePositionalArgs {
|
||||||
function: func_name.to_string(),
|
function: func_name.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(decorator),
|
Range::from(decorator),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,10 +307,8 @@ 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") {
|
||||||
let mut diagnostic = Diagnostic::new(
|
let mut diagnostic =
|
||||||
ExtraneousScopeFunction,
|
Diagnostic::new(ExtraneousScopeFunction, Range::from(scope_keyword));
|
||||||
Range::from_located(scope_keyword),
|
|
||||||
);
|
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
match fix_extraneous_scope_function(
|
match fix_extraneous_scope_function(
|
||||||
checker.locator,
|
checker.locator,
|
||||||
|
@ -364,7 +362,7 @@ fn check_fixture_returns(checker: &mut Checker, func: &Stmt, func_name: &str, bo
|
||||||
IncorrectFixtureNameUnderscore {
|
IncorrectFixtureNameUnderscore {
|
||||||
function: func_name.to_string(),
|
function: func_name.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(func),
|
Range::from(func),
|
||||||
));
|
));
|
||||||
} else if checker
|
} else if checker
|
||||||
.settings
|
.settings
|
||||||
|
@ -378,7 +376,7 @@ fn check_fixture_returns(checker: &mut Checker, func: &Stmt, func_name: &str, bo
|
||||||
MissingFixtureNameUnderscore {
|
MissingFixtureNameUnderscore {
|
||||||
function: func_name.to_string(),
|
function: func_name.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(func),
|
Range::from(func),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,7 +389,7 @@ fn check_fixture_returns(checker: &mut Checker, func: &Stmt, func_name: &str, bo
|
||||||
UselessYieldFixture {
|
UselessYieldFixture {
|
||||||
name: func_name.to_string(),
|
name: func_name.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
|
@ -420,7 +418,7 @@ fn check_test_function_args(checker: &mut Checker, args: &Arguments) {
|
||||||
FixtureParamWithoutValue {
|
FixtureParamWithoutValue {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(arg),
|
Range::from(arg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -431,7 +429,7 @@ 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.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
DeprecatedYieldFixture,
|
DeprecatedYieldFixture,
|
||||||
Range::from_located(decorator),
|
Range::from(decorator),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -451,7 +449,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.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
FixtureFinalizerCallback,
|
FixtureFinalizerCallback,
|
||||||
Range::from_located(addfinalizer),
|
Range::from(addfinalizer),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -468,7 +466,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Expr]) {
|
||||||
{
|
{
|
||||||
if name == "asyncio" {
|
if name == "asyncio" {
|
||||||
let mut diagnostic =
|
let mut diagnostic =
|
||||||
Diagnostic::new(UnnecessaryAsyncioMarkOnFixture, Range::from_located(mark));
|
Diagnostic::new(UnnecessaryAsyncioMarkOnFixture, Range::from(mark));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
let start = Location::new(mark.location.row(), 0);
|
let start = Location::new(mark.location.row(), 0);
|
||||||
let end = Location::new(mark.end_location.unwrap().row() + 1, 0);
|
let end = Location::new(mark.end_location.unwrap().row() + 1, 0);
|
||||||
|
@ -485,7 +483,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Expr]) {
|
||||||
{
|
{
|
||||||
if name == "usefixtures" {
|
if name == "usefixtures" {
|
||||||
let mut diagnostic =
|
let mut diagnostic =
|
||||||
Diagnostic::new(ErroneousUseFixturesOnFixture, Range::from_located(mark));
|
Diagnostic::new(ErroneousUseFixturesOnFixture, Range::from(mark));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
let start = Location::new(mark.location.row(), 0);
|
let start = Location::new(mark.location.row(), 0);
|
||||||
let end = Location::new(mark.end_location.unwrap().row() + 1, 0);
|
let end = Location::new(mark.end_location.unwrap().row() + 1, 0);
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub fn import(import_from: &Stmt, name: &str, asname: Option<&str>) -> Option<Di
|
||||||
if alias != name {
|
if alias != name {
|
||||||
return Some(Diagnostic::new(
|
return Some(Diagnostic::new(
|
||||||
IncorrectPytestImport,
|
IncorrectPytestImport,
|
||||||
Range::from_located(import_from),
|
Range::from(import_from),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ pub fn import_from(
|
||||||
if is_pytest_or_subpackage(module) {
|
if is_pytest_or_subpackage(module) {
|
||||||
return Some(Diagnostic::new(
|
return Some(Diagnostic::new(
|
||||||
IncorrectPytestImport,
|
IncorrectPytestImport,
|
||||||
Range::from_located(import_from),
|
Range::from(import_from),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -63,7 +63,7 @@ fn pytest_mark_parentheses(
|
||||||
expected_parens: preferred.to_string(),
|
expected_parens: preferred.to_string(),
|
||||||
actual_parens: actual.to_string(),
|
actual_parens: actual.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(decorator),
|
Range::from(decorator),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(fix);
|
diagnostic.amend(fix);
|
||||||
|
@ -111,8 +111,7 @@ fn check_useless_usefixtures(checker: &mut Checker, decorator: &Expr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !has_parameters {
|
if !has_parameters {
|
||||||
let mut diagnostic =
|
let mut diagnostic = Diagnostic::new(UseFixturesWithoutParameters, Range::from(decorator));
|
||||||
Diagnostic::new(UseFixturesWithoutParameters, Range::from_located(decorator));
|
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
let at_start = Location::new(decorator.location.row(), decorator.location.column() - 1);
|
let at_start = Location::new(decorator.location.row(), decorator.location.column() - 1);
|
||||||
diagnostic.amend(Fix::deletion(at_start, decorator.end_location.unwrap()));
|
diagnostic.amend(Fix::deletion(at_start, decorator.end_location.unwrap()));
|
||||||
|
|
|
@ -97,7 +97,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
||||||
ParametrizeNamesWrongType {
|
ParametrizeNamesWrongType {
|
||||||
expected: names_type,
|
expected: names_type,
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
|
@ -130,7 +130,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
||||||
ParametrizeNamesWrongType {
|
ParametrizeNamesWrongType {
|
||||||
expected: names_type,
|
expected: names_type,
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
|
@ -172,7 +172,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
||||||
ParametrizeNamesWrongType {
|
ParametrizeNamesWrongType {
|
||||||
expected: names_type,
|
expected: names_type,
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
|
@ -194,7 +194,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
||||||
ParametrizeNamesWrongType {
|
ParametrizeNamesWrongType {
|
||||||
expected: names_type,
|
expected: names_type,
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
if let Some(content) = elts_to_csv(elts, checker) {
|
if let Some(content) = elts_to_csv(elts, checker) {
|
||||||
|
@ -223,7 +223,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
||||||
ParametrizeNamesWrongType {
|
ParametrizeNamesWrongType {
|
||||||
expected: names_type,
|
expected: names_type,
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
|
@ -248,7 +248,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
||||||
ParametrizeNamesWrongType {
|
ParametrizeNamesWrongType {
|
||||||
expected: names_type,
|
expected: names_type,
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
if let Some(content) = elts_to_csv(elts, checker) {
|
if let Some(content) = elts_to_csv(elts, checker) {
|
||||||
|
@ -295,7 +295,7 @@ fn check_values(checker: &mut Checker, names: &Expr, values: &Expr) {
|
||||||
values: values_type,
|
values: values_type,
|
||||||
row: values_row_type,
|
row: values_row_type,
|
||||||
},
|
},
|
||||||
Range::from_located(values),
|
Range::from(values),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if is_multi_named {
|
if is_multi_named {
|
||||||
|
@ -309,7 +309,7 @@ fn check_values(checker: &mut Checker, names: &Expr, values: &Expr) {
|
||||||
values: values_type,
|
values: values_type,
|
||||||
row: values_row_type,
|
row: values_row_type,
|
||||||
},
|
},
|
||||||
Range::from_located(values),
|
Range::from(values),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if is_multi_named {
|
if is_multi_named {
|
||||||
|
@ -325,7 +325,7 @@ fn handle_single_name(checker: &mut Checker, expr: &Expr, value: &Expr) {
|
||||||
ParametrizeNamesWrongType {
|
ParametrizeNamesWrongType {
|
||||||
expected: types::ParametrizeNameType::Csv,
|
expected: types::ParametrizeNameType::Csv,
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
|
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
|
@ -353,7 +353,7 @@ fn handle_value_rows(
|
||||||
values: values_type,
|
values: values_type,
|
||||||
row: values_row_type,
|
row: values_row_type,
|
||||||
},
|
},
|
||||||
Range::from_located(elt),
|
Range::from(elt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -364,7 +364,7 @@ fn handle_value_rows(
|
||||||
values: values_type,
|
values: values_type,
|
||||||
row: values_row_type,
|
row: values_row_type,
|
||||||
},
|
},
|
||||||
Range::from_located(elt),
|
Range::from(elt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ fn check_patch_call(
|
||||||
visitor.visit_expr(body);
|
visitor.visit_expr(body);
|
||||||
|
|
||||||
if !visitor.uses_args {
|
if !visitor.uses_args {
|
||||||
return Some(Diagnostic::new(PatchWithLambda, Range::from_located(call)));
|
return Some(Diagnostic::new(PatchWithLambda, Range::from(call)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,10 +73,9 @@ pub fn raises_call(checker: &mut Checker, func: &Expr, args: &[Expr], keywords:
|
||||||
.enabled(&Rule::RaisesWithoutException)
|
.enabled(&Rule::RaisesWithoutException)
|
||||||
{
|
{
|
||||||
if args.is_empty() && keywords.is_empty() {
|
if args.is_empty() && keywords.is_empty() {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
RaisesWithoutException,
|
.diagnostics
|
||||||
Range::from_located(func),
|
.push(Diagnostic::new(RaisesWithoutException, Range::from(func)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +132,7 @@ pub fn complex_raises(checker: &mut Checker, stmt: &Stmt, items: &[Withitem], bo
|
||||||
if is_too_complex {
|
if is_too_complex {
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
RaisesWithMultipleStatements,
|
RaisesWithMultipleStatements,
|
||||||
Range::from_located(stmt),
|
Range::from(stmt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,7 +167,7 @@ fn exception_needs_match(checker: &mut Checker, exception: &Expr) {
|
||||||
RaisesTooBroad {
|
RaisesTooBroad {
|
||||||
exception: call_path,
|
exception: call_path,
|
||||||
},
|
},
|
||||||
Range::from_located(exception),
|
Range::from(exception),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ fn unnecessary_return_none(checker: &mut Checker, stack: &Stack) {
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let mut diagnostic = Diagnostic::new(UnnecessaryReturnNone, Range::from_located(stmt));
|
let mut diagnostic = Diagnostic::new(UnnecessaryReturnNone, Range::from(*stmt));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
"return".to_string(),
|
"return".to_string(),
|
||||||
|
@ -155,7 +155,7 @@ fn implicit_return_value(checker: &mut Checker, stack: &Stack) {
|
||||||
if expr.is_some() {
|
if expr.is_some() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let mut diagnostic = Diagnostic::new(ImplicitReturnValue, Range::from_located(stmt));
|
let mut diagnostic = Diagnostic::new(ImplicitReturnValue, Range::from(*stmt));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
"return None".to_string(),
|
"return None".to_string(),
|
||||||
|
@ -212,7 +212,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) {
|
||||||
if let Some(last_stmt) = orelse.last() {
|
if let Some(last_stmt) = orelse.last() {
|
||||||
implicit_return(checker, last_stmt);
|
implicit_return(checker, last_stmt);
|
||||||
} else {
|
} else {
|
||||||
let mut diagnostic = Diagnostic::new(ImplicitReturn, Range::from_located(stmt));
|
let mut diagnostic = Diagnostic::new(ImplicitReturn, Range::from(stmt));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
if let Some(indent) = indentation(checker.locator, stmt) {
|
if let Some(indent) = indentation(checker.locator, stmt) {
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
|
@ -252,7 +252,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) {
|
||||||
if let Some(last_stmt) = orelse.last() {
|
if let Some(last_stmt) = orelse.last() {
|
||||||
implicit_return(checker, last_stmt);
|
implicit_return(checker, last_stmt);
|
||||||
} else {
|
} else {
|
||||||
let mut diagnostic = Diagnostic::new(ImplicitReturn, Range::from_located(stmt));
|
let mut diagnostic = Diagnostic::new(ImplicitReturn, Range::from(stmt));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
if let Some(indent) = indentation(checker.locator, stmt) {
|
if let Some(indent) = indentation(checker.locator, stmt) {
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
|
@ -291,7 +291,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) {
|
||||||
if is_noreturn_func(checker, func)
|
if is_noreturn_func(checker, func)
|
||||||
) => {}
|
) => {}
|
||||||
_ => {
|
_ => {
|
||||||
let mut diagnostic = Diagnostic::new(ImplicitReturn, Range::from_located(stmt));
|
let mut diagnostic = Diagnostic::new(ImplicitReturn, Range::from(stmt));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
if let Some(indent) = indentation(checker.locator, stmt) {
|
if let Some(indent) = indentation(checker.locator, stmt) {
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
|
@ -383,10 +383,9 @@ 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.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
UnnecessaryAssign,
|
.diagnostics
|
||||||
Range::from_located(expr),
|
.push(Diagnostic::new(UnnecessaryAssign, Range::from(expr)));
|
||||||
));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,10 +399,9 @@ fn unnecessary_assign(checker: &mut Checker, stack: &Stack, expr: &Expr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker
|
||||||
UnnecessaryAssign,
|
.diagnostics
|
||||||
Range::from_located(expr),
|
.push(Diagnostic::new(UnnecessaryAssign, Range::from(expr)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,7 +414,7 @@ fn superfluous_else_node(checker: &mut Checker, stmt: &Stmt, branch: Branch) ->
|
||||||
if matches!(child.node, StmtKind::Return { .. }) {
|
if matches!(child.node, StmtKind::Return { .. }) {
|
||||||
let diagnostic = Diagnostic::new(
|
let diagnostic = Diagnostic::new(
|
||||||
SuperfluousElseReturn { branch },
|
SuperfluousElseReturn { branch },
|
||||||
elif_else_range(stmt, checker.locator).unwrap_or_else(|| Range::from_located(stmt)),
|
elif_else_range(stmt, checker.locator).unwrap_or_else(|| Range::from(stmt)),
|
||||||
);
|
);
|
||||||
if checker.settings.rules.enabled(diagnostic.kind.rule()) {
|
if checker.settings.rules.enabled(diagnostic.kind.rule()) {
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
|
@ -426,7 +424,7 @@ fn superfluous_else_node(checker: &mut Checker, stmt: &Stmt, branch: Branch) ->
|
||||||
if matches!(child.node, StmtKind::Break) {
|
if matches!(child.node, StmtKind::Break) {
|
||||||
let diagnostic = Diagnostic::new(
|
let diagnostic = Diagnostic::new(
|
||||||
SuperfluousElseBreak { branch },
|
SuperfluousElseBreak { branch },
|
||||||
elif_else_range(stmt, checker.locator).unwrap_or_else(|| Range::from_located(stmt)),
|
elif_else_range(stmt, checker.locator).unwrap_or_else(|| Range::from(stmt)),
|
||||||
);
|
);
|
||||||
if checker.settings.rules.enabled(diagnostic.kind.rule()) {
|
if checker.settings.rules.enabled(diagnostic.kind.rule()) {
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
|
@ -436,7 +434,7 @@ fn superfluous_else_node(checker: &mut Checker, stmt: &Stmt, branch: Branch) ->
|
||||||
if matches!(child.node, StmtKind::Raise { .. }) {
|
if matches!(child.node, StmtKind::Raise { .. }) {
|
||||||
let diagnostic = Diagnostic::new(
|
let diagnostic = Diagnostic::new(
|
||||||
SuperfluousElseRaise { branch },
|
SuperfluousElseRaise { branch },
|
||||||
elif_else_range(stmt, checker.locator).unwrap_or_else(|| Range::from_located(stmt)),
|
elif_else_range(stmt, checker.locator).unwrap_or_else(|| Range::from(stmt)),
|
||||||
);
|
);
|
||||||
if checker.settings.rules.enabled(diagnostic.kind.rule()) {
|
if checker.settings.rules.enabled(diagnostic.kind.rule()) {
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
|
@ -446,7 +444,7 @@ fn superfluous_else_node(checker: &mut Checker, stmt: &Stmt, branch: Branch) ->
|
||||||
if matches!(child.node, StmtKind::Continue) {
|
if matches!(child.node, StmtKind::Continue) {
|
||||||
let diagnostic = Diagnostic::new(
|
let diagnostic = Diagnostic::new(
|
||||||
SuperfluousElseContinue { branch },
|
SuperfluousElseContinue { branch },
|
||||||
elif_else_range(stmt, checker.locator).unwrap_or_else(|| Range::from_located(stmt)),
|
elif_else_range(stmt, checker.locator).unwrap_or_else(|| Range::from(stmt)),
|
||||||
);
|
);
|
||||||
if checker.settings.rules.enabled(diagnostic.kind.rule()) {
|
if checker.settings.rules.enabled(diagnostic.kind.rule()) {
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
|
|
|
@ -120,7 +120,7 @@ pub fn private_member_access(checker: &mut Checker, expr: &Expr) {
|
||||||
PrivateMemberAccess {
|
PrivateMemberAccess {
|
||||||
access: attr.to_string(),
|
access: attr.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,7 +194,7 @@ pub fn duplicate_isinstance_call(checker: &mut Checker, expr: &Expr) {
|
||||||
DuplicateIsinstanceCall {
|
DuplicateIsinstanceCall {
|
||||||
name: arg_name.to_string(),
|
name: arg_name.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
// Grab the types used in each duplicate `isinstance` call.
|
// Grab the types used in each duplicate `isinstance` call.
|
||||||
|
@ -340,7 +340,7 @@ pub fn compare_with_tuple(checker: &mut Checker, expr: &Expr) {
|
||||||
CompareWithTuple {
|
CompareWithTuple {
|
||||||
replacement: unparse_expr(&in_expr, checker.stylist),
|
replacement: unparse_expr(&in_expr, checker.stylist),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
let unmatched: Vec<Expr> = values
|
let unmatched: Vec<Expr> = values
|
||||||
|
@ -407,7 +407,7 @@ pub fn expr_and_not_expr(checker: &mut Checker, expr: &Expr) {
|
||||||
ExprAndNotExpr {
|
ExprAndNotExpr {
|
||||||
name: id.to_string(),
|
name: id.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
|
@ -461,7 +461,7 @@ pub fn expr_or_not_expr(checker: &mut Checker, expr: &Expr) {
|
||||||
ExprOrNotExpr {
|
ExprOrNotExpr {
|
||||||
name: id.to_string(),
|
name: id.to_string(),
|
||||||
},
|
},
|
||||||
Range::from_located(expr),
|
Range::from(expr),
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
|
@ -490,7 +490,7 @@ pub fn expr_or_true(checker: &mut Checker, expr: &Expr) {
|
||||||
..
|
..
|
||||||
} = &value.node
|
} = &value.node
|
||||||
{
|
{
|
||||||
let mut diagnostic = Diagnostic::new(ExprOrTrue, Range::from_located(value));
|
let mut diagnostic = Diagnostic::new(ExprOrTrue, Range::from(value));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
"True".to_string(),
|
"True".to_string(),
|
||||||
|
@ -517,7 +517,7 @@ pub fn expr_and_false(checker: &mut Checker, expr: &Expr) {
|
||||||
..
|
..
|
||||||
} = &value.node
|
} = &value.node
|
||||||
{
|
{
|
||||||
let mut diagnostic = Diagnostic::new(ExprAndFalse, Range::from_located(value));
|
let mut diagnostic = Diagnostic::new(ExprAndFalse, Range::from(value));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.amend(Fix::replacement(
|
diagnostic.amend(Fix::replacement(
|
||||||
"False".to_string(),
|
"False".to_string(),
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue