mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +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::to_absolute;
|
||||
use ruff_python_ast::source_code::{Indexer, Locator, Stylist};
|
||||
use ruff_python_ast::types::Range;
|
||||
|
||||
use ruff_python_ast::whitespace::LinesWithTrailingNewline;
|
||||
|
||||
/// Determine if a body contains only a single statement, taking into account
|
||||
|
@ -227,7 +227,7 @@ pub fn remove_unused_imports<'a>(
|
|||
indexer: &Indexer,
|
||||
stylist: &Stylist,
|
||||
) -> 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 Some(Statement::Simple(body)) = tree.body.first_mut() else {
|
||||
|
|
|
@ -198,7 +198,7 @@ where
|
|||
// Add the binding to the current scope.
|
||||
let context = self.ctx.execution_context();
|
||||
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()) {
|
||||
let index = self.ctx.bindings.len();
|
||||
self.ctx.bindings.push(Binding {
|
||||
|
@ -227,7 +227,7 @@ where
|
|||
if scope_index != GLOBAL_SCOPE_INDEX {
|
||||
let context = self.ctx.execution_context();
|
||||
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()) {
|
||||
// Add a binding to the current scope.
|
||||
let index = self.ctx.bindings.len();
|
||||
|
@ -668,7 +668,7 @@ where
|
|||
runtime_usage: None,
|
||||
synthetic_usage: None,
|
||||
typing_usage: None,
|
||||
range: Range::from_located(stmt),
|
||||
range: Range::from(stmt),
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context,
|
||||
},
|
||||
|
@ -865,10 +865,10 @@ where
|
|||
.last()
|
||||
.expect("No current scope found"))]
|
||||
.id,
|
||||
Range::from_located(alias),
|
||||
Range::from(alias),
|
||||
)),
|
||||
typing_usage: None,
|
||||
range: Range::from_located(alias),
|
||||
range: Range::from(alias),
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context: self.ctx.execution_context(),
|
||||
},
|
||||
|
@ -879,7 +879,7 @@ where
|
|||
{
|
||||
self.diagnostics.push(Diagnostic::new(
|
||||
pyflakes::rules::LateFutureImport,
|
||||
Range::from_located(stmt),
|
||||
Range::from(stmt),
|
||||
));
|
||||
}
|
||||
} else if alias.node.name.contains('.') && alias.node.asname.is_none() {
|
||||
|
@ -900,13 +900,13 @@ where
|
|||
.last()
|
||||
.expect("No current scope found"))]
|
||||
.id,
|
||||
Range::from_located(alias),
|
||||
Range::from(alias),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
typing_usage: None,
|
||||
range: Range::from_located(alias),
|
||||
range: Range::from(alias),
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context: self.ctx.execution_context(),
|
||||
},
|
||||
|
@ -938,13 +938,13 @@ where
|
|||
.last()
|
||||
.expect("No current scope found"))]
|
||||
.id,
|
||||
Range::from_located(alias),
|
||||
Range::from(alias),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
typing_usage: None,
|
||||
range: Range::from_located(alias),
|
||||
range: Range::from(alias),
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context: self.ctx.execution_context(),
|
||||
},
|
||||
|
@ -1211,10 +1211,10 @@ where
|
|||
.last()
|
||||
.expect("No current scope found"))]
|
||||
.id,
|
||||
Range::from_located(alias),
|
||||
Range::from(alias),
|
||||
)),
|
||||
typing_usage: None,
|
||||
range: Range::from_located(alias),
|
||||
range: Range::from(alias),
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context: self.ctx.execution_context(),
|
||||
},
|
||||
|
@ -1233,7 +1233,7 @@ where
|
|||
{
|
||||
self.diagnostics.push(Diagnostic::new(
|
||||
pyflakes::rules::LateFutureImport,
|
||||
Range::from_located(stmt),
|
||||
Range::from(stmt),
|
||||
));
|
||||
}
|
||||
} else if alias.node.name == "*" {
|
||||
|
@ -1250,13 +1250,13 @@ where
|
|||
.last()
|
||||
.expect("No current scope found"))]
|
||||
.id,
|
||||
Range::from_located(alias),
|
||||
Range::from(alias),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
typing_usage: None,
|
||||
range: Range::from_located(stmt),
|
||||
range: Range::from(stmt),
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context: self.ctx.execution_context(),
|
||||
},
|
||||
|
@ -1273,7 +1273,7 @@ where
|
|||
module.as_deref(),
|
||||
),
|
||||
},
|
||||
Range::from_located(stmt),
|
||||
Range::from(stmt),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -1286,7 +1286,7 @@ where
|
|||
module.as_deref(),
|
||||
),
|
||||
},
|
||||
Range::from_located(stmt),
|
||||
Range::from(stmt),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -1328,13 +1328,13 @@ where
|
|||
.last()
|
||||
.expect("No current scope found"))]
|
||||
.id,
|
||||
Range::from_located(alias),
|
||||
Range::from(alias),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
typing_usage: None,
|
||||
range: Range::from_located(alias),
|
||||
range: Range::from(alias),
|
||||
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context: self.ctx.execution_context(),
|
||||
|
@ -1956,7 +1956,7 @@ where
|
|||
runtime_usage: None,
|
||||
synthetic_usage: None,
|
||||
typing_usage: None,
|
||||
range: Range::from_located(stmt),
|
||||
range: Range::from(stmt),
|
||||
source: Some(RefEquality(stmt)),
|
||||
context: self.ctx.execution_context(),
|
||||
});
|
||||
|
@ -2021,7 +2021,7 @@ where
|
|||
runtime_usage: None,
|
||||
synthetic_usage: None,
|
||||
typing_usage: None,
|
||||
range: Range::from_located(stmt),
|
||||
range: Range::from(*stmt),
|
||||
source: Some(RefEquality(stmt)),
|
||||
context: self.ctx.execution_context(),
|
||||
});
|
||||
|
@ -2164,7 +2164,7 @@ where
|
|||
runtime_usage: None,
|
||||
synthetic_usage: None,
|
||||
typing_usage: None,
|
||||
range: Range::from_located(stmt),
|
||||
range: Range::from(stmt),
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context: self.ctx.execution_context(),
|
||||
},
|
||||
|
@ -2194,7 +2194,7 @@ where
|
|||
} = &expr.node
|
||||
{
|
||||
self.deferred.string_type_definitions.push((
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
value,
|
||||
(self.ctx.in_annotation, self.ctx.in_type_checking_block),
|
||||
(self.ctx.scope_stack.clone(), self.ctx.parents.clone()),
|
||||
|
@ -2260,7 +2260,7 @@ where
|
|||
elts,
|
||||
check_too_many_expressions,
|
||||
check_two_starred_expressions,
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
) {
|
||||
self.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -2295,10 +2295,9 @@ where
|
|||
}
|
||||
ExprContext::Store => {
|
||||
if self.settings.rules.enabled(&Rule::AmbiguousVariableName) {
|
||||
if let Some(diagnostic) = pycodestyle::rules::ambiguous_variable_name(
|
||||
id,
|
||||
Range::from_located(expr),
|
||||
) {
|
||||
if let Some(diagnostic) =
|
||||
pycodestyle::rules::ambiguous_variable_name(id, Range::from(expr))
|
||||
{
|
||||
self.diagnostics.push(diagnostic);
|
||||
}
|
||||
}
|
||||
|
@ -2383,7 +2382,7 @@ where
|
|||
{
|
||||
if attr == "format" {
|
||||
// "...".format(...) call
|
||||
let location = Range::from_located(expr);
|
||||
let location = Range::from(expr);
|
||||
match pyflakes::format::FormatSummary::try_from(value.as_ref()) {
|
||||
Err(e) => {
|
||||
if self
|
||||
|
@ -2779,22 +2778,14 @@ where
|
|||
func,
|
||||
args,
|
||||
keywords,
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
}
|
||||
if self.settings.rules.enabled(&Rule::CallDatetimeToday) {
|
||||
flake8_datetimez::rules::call_datetime_today(
|
||||
self,
|
||||
func,
|
||||
Range::from_located(expr),
|
||||
);
|
||||
flake8_datetimez::rules::call_datetime_today(self, func, Range::from(expr));
|
||||
}
|
||||
if self.settings.rules.enabled(&Rule::CallDatetimeUtcnow) {
|
||||
flake8_datetimez::rules::call_datetime_utcnow(
|
||||
self,
|
||||
func,
|
||||
Range::from_located(expr),
|
||||
);
|
||||
flake8_datetimez::rules::call_datetime_utcnow(self, func, Range::from(expr));
|
||||
}
|
||||
if self
|
||||
.settings
|
||||
|
@ -2804,7 +2795,7 @@ where
|
|||
flake8_datetimez::rules::call_datetime_utcfromtimestamp(
|
||||
self,
|
||||
func,
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
}
|
||||
if self
|
||||
|
@ -2817,7 +2808,7 @@ where
|
|||
func,
|
||||
args,
|
||||
keywords,
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
}
|
||||
if self
|
||||
|
@ -2830,7 +2821,7 @@ where
|
|||
func,
|
||||
args,
|
||||
keywords,
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
}
|
||||
if self
|
||||
|
@ -2842,18 +2833,14 @@ where
|
|||
self,
|
||||
func,
|
||||
args,
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
}
|
||||
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) {
|
||||
flake8_datetimez::rules::call_date_fromtimestamp(
|
||||
self,
|
||||
func,
|
||||
Range::from_located(expr),
|
||||
);
|
||||
flake8_datetimez::rules::call_date_fromtimestamp(self, func, Range::from(expr));
|
||||
}
|
||||
|
||||
// pygrep-hooks
|
||||
|
@ -3082,7 +3069,7 @@ where
|
|||
.rules
|
||||
.enabled(&Rule::PercentFormatUnsupportedFormatCharacter)
|
||||
{
|
||||
let location = Range::from_located(expr);
|
||||
let location = Range::from(expr);
|
||||
match pyflakes::cformat::CFormatSummary::try_from(value.as_str()) {
|
||||
Err(CFormatError {
|
||||
typ: CFormatErrorType::UnsupportedFormatChar(c),
|
||||
|
@ -3271,7 +3258,7 @@ where
|
|||
left,
|
||||
ops,
|
||||
comparators,
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -3279,7 +3266,7 @@ where
|
|||
self.diagnostics.extend(pycodestyle::rules::type_comparison(
|
||||
ops,
|
||||
comparators,
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -3356,7 +3343,7 @@ where
|
|||
} => {
|
||||
if self.ctx.in_type_definition && !self.ctx.in_literal {
|
||||
self.deferred.string_type_definitions.push((
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
value,
|
||||
(self.ctx.in_annotation, self.ctx.in_type_checking_block),
|
||||
(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(
|
||||
value,
|
||||
&Range::from_located(expr),
|
||||
&Range::from(expr),
|
||||
) {
|
||||
self.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -3952,7 +3939,7 @@ where
|
|||
runtime_usage: None,
|
||||
synthetic_usage: None,
|
||||
typing_usage: None,
|
||||
range: Range::from_located(arg),
|
||||
range: Range::from(arg),
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context: self.ctx.execution_context(),
|
||||
},
|
||||
|
@ -3960,7 +3947,7 @@ where
|
|||
|
||||
if self.settings.rules.enabled(&Rule::AmbiguousVariableName) {
|
||||
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);
|
||||
}
|
||||
|
@ -3995,7 +3982,7 @@ where
|
|||
runtime_usage: None,
|
||||
synthetic_usage: None,
|
||||
typing_usage: None,
|
||||
range: Range::from_located(pattern),
|
||||
range: Range::from(pattern),
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context: self.ctx.execution_context(),
|
||||
},
|
||||
|
@ -4206,7 +4193,7 @@ impl<'a> Checker<'a> {
|
|||
if let Some(index) = scope.bindings.get(&id.as_str()) {
|
||||
// Mark the binding as used.
|
||||
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()
|
||||
&& !self.ctx.in_deferred_string_type_definition
|
||||
|
@ -4236,7 +4223,7 @@ impl<'a> Checker<'a> {
|
|||
if let Some(index) = scope.bindings.get(full_name) {
|
||||
self.ctx.bindings[*index].mark_used(
|
||||
scope_id,
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
@ -4253,7 +4240,7 @@ impl<'a> Checker<'a> {
|
|||
if let Some(index) = scope.bindings.get(full_name.as_str()) {
|
||||
self.ctx.bindings[*index].mark_used(
|
||||
scope_id,
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
@ -4295,7 +4282,7 @@ impl<'a> Checker<'a> {
|
|||
name: id.to_string(),
|
||||
sources: from_list,
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
));
|
||||
}
|
||||
return;
|
||||
|
@ -4326,7 +4313,7 @@ impl<'a> Checker<'a> {
|
|||
|
||||
self.diagnostics.push(Diagnostic::new(
|
||||
pyflakes::rules::UndefinedName { name: id.clone() },
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -4398,7 +4385,7 @@ impl<'a> Checker<'a> {
|
|||
runtime_usage: None,
|
||||
synthetic_usage: None,
|
||||
typing_usage: None,
|
||||
range: Range::from_located(expr),
|
||||
range: Range::from(expr),
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context: self.ctx.execution_context(),
|
||||
},
|
||||
|
@ -4418,7 +4405,7 @@ impl<'a> Checker<'a> {
|
|||
runtime_usage: None,
|
||||
synthetic_usage: None,
|
||||
typing_usage: None,
|
||||
range: Range::from_located(expr),
|
||||
range: Range::from(expr),
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context: self.ctx.execution_context(),
|
||||
},
|
||||
|
@ -4434,7 +4421,7 @@ impl<'a> Checker<'a> {
|
|||
runtime_usage: None,
|
||||
synthetic_usage: None,
|
||||
typing_usage: None,
|
||||
range: Range::from_located(expr),
|
||||
range: Range::from(expr),
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context: self.ctx.execution_context(),
|
||||
},
|
||||
|
@ -4499,7 +4486,7 @@ impl<'a> Checker<'a> {
|
|||
runtime_usage: None,
|
||||
synthetic_usage: None,
|
||||
typing_usage: None,
|
||||
range: Range::from_located(expr),
|
||||
range: Range::from(expr),
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context: self.ctx.execution_context(),
|
||||
},
|
||||
|
@ -4515,7 +4502,7 @@ impl<'a> Checker<'a> {
|
|||
runtime_usage: None,
|
||||
synthetic_usage: None,
|
||||
typing_usage: None,
|
||||
range: Range::from_located(expr),
|
||||
range: Range::from(expr),
|
||||
source: Some(self.ctx.current_stmt().clone()),
|
||||
context: self.ctx.execution_context(),
|
||||
},
|
||||
|
@ -4546,7 +4533,7 @@ impl<'a> Checker<'a> {
|
|||
pyflakes::rules::UndefinedName {
|
||||
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`.
|
||||
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(
|
||||
Location::new(expr.location.row(), 0),
|
||||
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(
|
||||
SysVersionSlice1Referenced,
|
||||
Range::from_located(value),
|
||||
Range::from(value),
|
||||
));
|
||||
} else if *i == BigInt::from(3)
|
||||
&& checker
|
||||
|
@ -154,7 +154,7 @@ pub fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) {
|
|||
{
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
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)
|
||||
&& checker.settings.rules.enabled(&Rule::SysVersion2Referenced)
|
||||
{
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
SysVersion2Referenced,
|
||||
Range::from_located(value),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(SysVersion2Referenced, Range::from(value)));
|
||||
} else if *i == BigInt::from(0)
|
||||
&& checker.settings.rules.enabled(&Rule::SysVersion0Referenced)
|
||||
{
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
SysVersion0Referenced,
|
||||
Range::from_located(value),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.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(
|
||||
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)
|
||||
{
|
||||
if checker.settings.rules.enabled(&Rule::SysVersionInfo1CmpInt) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
SysVersionInfo1CmpInt,
|
||||
Range::from_located(left),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.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(
|
||||
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 checker.settings.rules.enabled(&Rule::SysVersionCmpStr10) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
SysVersionCmpStr10,
|
||||
Range::from_located(left),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(SysVersionCmpStr10, Range::from(left)));
|
||||
}
|
||||
} else if checker.settings.rules.enabled(&Rule::SysVersionCmpStr3) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
SysVersionCmpStr3,
|
||||
Range::from_located(left),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(SysVersionCmpStr3, Range::from(left)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -314,6 +309,6 @@ pub fn name_or_attribute(checker: &mut Checker, expr: &Expr) {
|
|||
{
|
||||
checker
|
||||
.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
|
||||
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);
|
||||
|
||||
// Find the colon (following the `def` keyword).
|
||||
|
|
|
@ -446,7 +446,7 @@ fn check_dynamically_typed<F>(
|
|||
if checker.ctx.match_typing_expr(annotation, "Any") {
|
||||
diagnostics.push(Diagnostic::new(
|
||||
AnyType { name: func() },
|
||||
Range::from_located(annotation),
|
||||
Range::from(annotation),
|
||||
));
|
||||
};
|
||||
}
|
||||
|
@ -513,7 +513,7 @@ pub fn definition(
|
|||
MissingTypeFunctionArgument {
|
||||
name: arg.node.arg.to_string(),
|
||||
},
|
||||
Range::from_located(arg),
|
||||
Range::from(arg),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -544,7 +544,7 @@ pub fn definition(
|
|||
MissingTypeArgs {
|
||||
name: arg.node.arg.to_string(),
|
||||
},
|
||||
Range::from_located(arg),
|
||||
Range::from(arg),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -575,7 +575,7 @@ pub fn definition(
|
|||
MissingTypeKwargs {
|
||||
name: arg.node.arg.to_string(),
|
||||
},
|
||||
Range::from_located(arg),
|
||||
Range::from(arg),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -592,7 +592,7 @@ pub fn definition(
|
|||
MissingTypeCls {
|
||||
name: arg.node.arg.to_string(),
|
||||
},
|
||||
Range::from_located(arg),
|
||||
Range::from(arg),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
|
@ -601,7 +601,7 @@ pub fn definition(
|
|||
MissingTypeSelf {
|
||||
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) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
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" {
|
||||
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 {
|
||||
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 {
|
||||
string: string.to_string(),
|
||||
},
|
||||
Range::from_located(keyword),
|
||||
Range::from(keyword),
|
||||
))
|
||||
})
|
||||
.collect()
|
||||
|
|
|
@ -54,7 +54,7 @@ pub fn compare_to_hardcoded_password_string(left: &Expr, comparators: &[Expr]) -
|
|||
HardcodedPasswordString {
|
||||
string: string.to_string(),
|
||||
},
|
||||
Range::from_located(comp),
|
||||
Range::from(comp),
|
||||
))
|
||||
})
|
||||
.collect()
|
||||
|
@ -69,7 +69,7 @@ pub fn assign_hardcoded_password_string(value: &Expr, targets: &[Expr]) -> Optio
|
|||
HardcodedPasswordString {
|
||||
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) {
|
||||
match unparse_string_format_expression(checker, expr) {
|
||||
Some(string) if matches_sql_statement(&string) => {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
HardcodedSQLExpression,
|
||||
Range::from_located(expr),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(HardcodedSQLExpression, Range::from(expr)));
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ pub fn hardcoded_tmp_directory(
|
|||
HardcodedTempFile {
|
||||
string: value.to_string(),
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -75,7 +75,7 @@ pub fn hashlib_insecure_hash_functions(
|
|||
HashlibInsecureHashFunction {
|
||||
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 {
|
||||
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" {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
Jinja2AutoescapeFalse { value: true },
|
||||
Range::from_located(autoescape_arg),
|
||||
Range::from(autoescape_arg),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => checker.diagnostics.push(Diagnostic::new(
|
||||
Jinja2AutoescapeFalse { value: true },
|
||||
Range::from_located(autoescape_arg),
|
||||
Range::from(autoescape_arg),
|
||||
)),
|
||||
}
|
||||
} else {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
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() {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
LoggingConfigInsecureListen,
|
||||
Range::from_located(func),
|
||||
Range::from(func),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ pub fn request_with_no_cert_validation(
|
|||
RequestWithNoCertValidation {
|
||||
string: target.to_string(),
|
||||
},
|
||||
Range::from_located(verify_arg),
|
||||
Range::from(verify_arg),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,13 +57,13 @@ pub fn request_without_timeout(
|
|||
RequestWithoutTimeout {
|
||||
timeout: Some(timeout),
|
||||
},
|
||||
Range::from_located(timeout_arg),
|
||||
Range::from(timeout_arg),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
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() {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
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);
|
||||
if call_args.len() < 3 {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
SnmpWeakCryptography,
|
||||
Range::from_located(func),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(SnmpWeakCryptography, Range::from(func)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ pub fn try_except_continue(
|
|||
{
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
TryExceptContinue,
|
||||
Range::from_located(excepthandler),
|
||||
Range::from(excepthandler),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,9 +31,8 @@ pub fn try_except_pass(
|
|||
&& body[0].node == StmtKind::Pass
|
||||
&& (check_typed_exception || is_untyped_exception(type_, checker))
|
||||
{
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
TryExceptPass,
|
||||
Range::from_located(excepthandler),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.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(
|
||||
UnsafeYAMLLoad { loader },
|
||||
Range::from_located(loader_arg),
|
||||
Range::from(loader_arg),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
UnsafeYAMLLoad { loader: None },
|
||||
Range::from_located(func),
|
||||
Range::from(func),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ pub fn blind_except(
|
|||
BlindExcept {
|
||||
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) {
|
||||
checker
|
||||
.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(
|
||||
BooleanPositionalArgInFunctionDefinition,
|
||||
Range::from_located(arg),
|
||||
Range::from(arg),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ pub fn abstract_base_class(
|
|||
EmptyMethodWithoutAbstractDecorator {
|
||||
name: format!("{name}.{method_name}"),
|
||||
},
|
||||
Range::from_located(stmt),
|
||||
Range::from(stmt),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ pub fn abstract_base_class(
|
|||
AbstractBaseClassWithoutAbstractMethod {
|
||||
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;
|
||||
};
|
||||
|
||||
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()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
unparse_stmt(&assertion_error(msg), checker.stylist),
|
||||
|
|
|
@ -62,8 +62,7 @@ pub fn assert_raises_exception(checker: &mut Checker, stmt: &Stmt, items: &[With
|
|||
return;
|
||||
}
|
||||
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
AssertRaisesException,
|
||||
Range::from_located(stmt),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.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" {
|
||||
return;
|
||||
}
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
AssignmentToOsEnviron,
|
||||
Range::from_located(target),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.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(
|
||||
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 {
|
||||
return;
|
||||
};
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
CannotRaiseLiteral,
|
||||
Range::from_located(expr),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(CannotRaiseLiteral, Range::from(expr)));
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ fn duplicate_handler_exceptions<'a>(
|
|||
.sorted()
|
||||
.collect::<Vec<String>>(),
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
|
@ -157,7 +157,7 @@ pub fn duplicate_exceptions(checker: &mut Checker, handlers: &[Excepthandler]) {
|
|||
DuplicateTryBlockException {
|
||||
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() {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
ExceptWithEmptyTuple,
|
||||
Range::from_located(excepthandler),
|
||||
Range::from(excepthandler),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ where
|
|||
name: compose_call_path(func),
|
||||
}
|
||||
.into(),
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
));
|
||||
}
|
||||
visitor::walk_expr(self, expr);
|
||||
|
|
|
@ -40,8 +40,8 @@ where
|
|||
fn visit_expr(&mut self, expr: &'b Expr) {
|
||||
match &expr.node {
|
||||
ExprKind::Name { id, ctx } => match ctx {
|
||||
ExprContext::Load => self.loaded.push((id, expr, Range::from_located(expr))),
|
||||
ExprContext::Store => self.stored.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(expr))),
|
||||
ExprContext::Del => {}
|
||||
},
|
||||
_ => visitor::walk_expr(self, expr),
|
||||
|
|
|
@ -63,7 +63,7 @@ pub fn getattr_with_constant(checker: &mut Checker, expr: &Expr, func: &Expr, ar
|
|||
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()) {
|
||||
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 {
|
||||
|
|
|
@ -75,7 +75,7 @@ pub fn loop_variable_overrides_iterator(checker: &mut Checker, target: &Expr, it
|
|||
LoopVariableOverridesIterator {
|
||||
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(
|
||||
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 {
|
||||
name: unparse_expr(elt, checker.stylist),
|
||||
},
|
||||
Range::from_located(type_),
|
||||
Range::from(type_),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
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`).
|
||||
if let StmtKind::Expr { value: child } = &checker.ctx.current_stmt().node {
|
||||
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()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
|
|
|
@ -44,7 +44,7 @@ pub fn star_arg_unpacking_after_keyword_arg(
|
|||
}
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
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();
|
||||
if num_chars > 1 && num_chars != value.chars().unique().count() {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
StripWithMultiCharacters,
|
||||
Range::from_located(expr),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.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) {
|
||||
return;
|
||||
}
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
UnaryPrefixIncrement,
|
||||
Range::from_located(expr),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(UnaryPrefixIncrement, Range::from(expr)));
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ pub fn unintentional_type_annotation(
|
|||
if matches!(&value.node, ExprKind::Name { .. }) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
UnintentionalTypeAnnotation,
|
||||
Range::from_located(stmt),
|
||||
Range::from(stmt),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ pub fn unintentional_type_annotation(
|
|||
if id != "self" {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
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__" {
|
||||
return;
|
||||
}
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
UnreliableCallableCheck,
|
||||
Range::from_located(expr),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(UnreliableCallableCheck, Range::from(expr)));
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ pub fn unused_loop_control_variable(
|
|||
rename: rename.clone(),
|
||||
certainty,
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if let Some(rename) = rename {
|
||||
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) {
|
||||
if matches!(expr.node, ExprKind::Compare { .. }) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
UselessComparison,
|
||||
Range::from_located(expr),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.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(
|
||||
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 {
|
||||
match &value.node {
|
||||
ExprKind::List { .. } | ExprKind::Dict { .. } | ExprKind::Set { .. } => {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
UselessExpression,
|
||||
Range::from_located(value),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(UselessExpression, Range::from(value)));
|
||||
}
|
||||
ExprKind::Constant { value: val, .. } => match &val {
|
||||
Constant::Str { .. } | Constant::Ellipsis => {}
|
||||
_ => {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
UselessExpression,
|
||||
Range::from_located(value),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(UselessExpression, Range::from(value)));
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
|
|
|
@ -35,10 +35,9 @@ pub fn zip_without_explicit_strict(
|
|||
.map_or(false, |name| name == "strict")
|
||||
})
|
||||
{
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
ZipWithoutExplicitStrict,
|
||||
Range::from_located(expr),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(ZipWithoutExplicitStrict, Range::from(expr)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ pub fn builtin_shadowing<T>(
|
|||
}
|
||||
.into(),
|
||||
},
|
||||
Range::from_located(located),
|
||||
Range::from(located),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -8,7 +8,6 @@ use libcst_native::{
|
|||
};
|
||||
|
||||
use ruff_python_ast::source_code::{Locator, Stylist};
|
||||
use ruff_python_ast::types::Range;
|
||||
|
||||
use crate::cst::matchers::{match_expr, match_module};
|
||||
use crate::fix::Fix;
|
||||
|
@ -36,7 +35,7 @@ pub fn fix_unnecessary_generator_list(
|
|||
expr: &rustpython_parser::ast::Expr,
|
||||
) -> Result<Fix> {
|
||||
// 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 body = match_expr(&mut tree)?;
|
||||
let call = match_call(body)?;
|
||||
|
@ -83,7 +82,7 @@ pub fn fix_unnecessary_generator_set(
|
|||
parent: Option<&rustpython_parser::ast::Expr>,
|
||||
) -> Result<Fix> {
|
||||
// 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 body = match_expr(&mut tree)?;
|
||||
let call = match_call(body)?;
|
||||
|
@ -140,7 +139,7 @@ pub fn fix_unnecessary_generator_dict(
|
|||
expr: &rustpython_parser::ast::Expr,
|
||||
parent: Option<&rustpython_parser::ast::Expr>,
|
||||
) -> 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 body = match_expr(&mut tree)?;
|
||||
let call = match_call(body)?;
|
||||
|
@ -214,7 +213,7 @@ pub fn fix_unnecessary_list_comprehension_set(
|
|||
) -> Result<Fix> {
|
||||
// Expr(Call(ListComp)))) ->
|
||||
// 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 body = match_expr(&mut tree)?;
|
||||
let call = match_call(body)?;
|
||||
|
@ -258,7 +257,7 @@ pub fn fix_unnecessary_list_comprehension_dict(
|
|||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
) -> 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 body = match_expr(&mut tree)?;
|
||||
let call = match_call(body)?;
|
||||
|
@ -357,7 +356,7 @@ pub fn fix_unnecessary_literal_set(
|
|||
expr: &rustpython_parser::ast::Expr,
|
||||
) -> Result<Fix> {
|
||||
// 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 body = match_expr(&mut tree)?;
|
||||
let mut call = match_call(body)?;
|
||||
|
@ -408,7 +407,7 @@ pub fn fix_unnecessary_literal_dict(
|
|||
expr: &rustpython_parser::ast::Expr,
|
||||
) -> Result<Fix> {
|
||||
// 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 body = match_expr(&mut tree)?;
|
||||
let call = match_call(body)?;
|
||||
|
@ -481,7 +480,7 @@ pub fn fix_unnecessary_collection_call(
|
|||
expr: &rustpython_parser::ast::Expr,
|
||||
) -> Result<Fix> {
|
||||
// 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 body = match_expr(&mut tree)?;
|
||||
let call = match_call(body)?;
|
||||
|
@ -596,7 +595,7 @@ pub fn fix_unnecessary_literal_within_tuple_call(
|
|||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
) -> 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 body = match_expr(&mut tree)?;
|
||||
let call = match_call(body)?;
|
||||
|
@ -655,7 +654,7 @@ pub fn fix_unnecessary_literal_within_list_call(
|
|||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
) -> 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 body = match_expr(&mut tree)?;
|
||||
let call = match_call(body)?;
|
||||
|
@ -717,7 +716,7 @@ pub fn fix_unnecessary_list_call(
|
|||
expr: &rustpython_parser::ast::Expr,
|
||||
) -> Result<Fix> {
|
||||
// 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 body = match_expr(&mut tree)?;
|
||||
let call = match_call(body)?;
|
||||
|
@ -747,7 +746,7 @@ pub fn fix_unnecessary_call_around_sorted(
|
|||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
) -> 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 body = match_expr(&mut tree)?;
|
||||
let outer_call = match_call(body)?;
|
||||
|
@ -874,7 +873,7 @@ pub fn fix_unnecessary_double_cast_or_process(
|
|||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
) -> 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 body = match_expr(&mut tree)?;
|
||||
let mut outer_call = match_call(body)?;
|
||||
|
@ -913,7 +912,7 @@ pub fn fix_unnecessary_comprehension(
|
|||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
) -> 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 body = match_expr(&mut tree)?;
|
||||
|
||||
|
@ -989,7 +988,7 @@ pub fn fix_unnecessary_map(
|
|||
parent: Option<&rustpython_parser::ast::Expr>,
|
||||
kind: &str,
|
||||
) -> 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 body = match_expr(&mut tree)?;
|
||||
let call = match_call(body)?;
|
||||
|
|
|
@ -84,7 +84,7 @@ pub fn unnecessary_call_around_sorted(
|
|||
UnnecessaryCallAroundSorted {
|
||||
func: outer.to_string(),
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
match fixes::fix_unnecessary_call_around_sorted(checker.locator, checker.stylist, expr) {
|
||||
|
|
|
@ -64,7 +64,7 @@ pub fn unnecessary_collection_call(
|
|||
UnnecessaryCollectionCall {
|
||||
obj_type: id.to_string(),
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
match fixes::fix_unnecessary_collection_call(checker.locator, checker.stylist, expr) {
|
||||
|
|
|
@ -65,7 +65,7 @@ pub fn unnecessary_comprehension(
|
|||
UnnecessaryComprehension {
|
||||
obj_type: id.to_string(),
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
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 == "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 let Ok(fix) = fixes::fix_unnecessary_double_cast_or_process(
|
||||
checker.locator,
|
||||
|
|
|
@ -58,8 +58,7 @@ pub fn unnecessary_generator_dict(
|
|||
if let ExprKind::GeneratorExp { elt, .. } = argument {
|
||||
match &elt.node {
|
||||
ExprKind::Tuple { elts, .. } if elts.len() == 2 => {
|
||||
let mut diagnostic =
|
||||
Diagnostic::new(UnnecessaryGeneratorDict, Range::from_located(expr));
|
||||
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorDict, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
match fixes::fix_unnecessary_generator_dict(
|
||||
checker.locator,
|
||||
|
|
|
@ -58,7 +58,7 @@ pub fn unnecessary_generator_list(
|
|||
return;
|
||||
}
|
||||
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()) {
|
||||
match fixes::fix_unnecessary_generator_list(checker.locator, checker.stylist, expr) {
|
||||
Ok(fix) => {
|
||||
|
|
|
@ -59,7 +59,7 @@ pub fn unnecessary_generator_set(
|
|||
return;
|
||||
}
|
||||
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()) {
|
||||
match fixes::fix_unnecessary_generator_set(
|
||||
checker.locator,
|
||||
|
|
|
@ -36,7 +36,7 @@ pub fn unnecessary_list_call(checker: &mut Checker, expr: &Expr, func: &Expr, ar
|
|||
if !matches!(argument, ExprKind::ListComp { .. }) {
|
||||
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()) {
|
||||
match fixes::fix_unnecessary_list_call(checker.locator, checker.stylist, expr) {
|
||||
Ok(fix) => {
|
||||
|
|
|
@ -48,8 +48,7 @@ pub fn unnecessary_list_comprehension_dict(
|
|||
if elts.len() != 2 {
|
||||
return;
|
||||
}
|
||||
let mut diagnostic =
|
||||
Diagnostic::new(UnnecessaryListComprehensionDict, Range::from_located(expr));
|
||||
let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionDict, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
match fixes::fix_unnecessary_list_comprehension_dict(checker.locator, checker.stylist, expr)
|
||||
{
|
||||
|
|
|
@ -40,8 +40,7 @@ pub fn unnecessary_list_comprehension_set(
|
|||
return;
|
||||
}
|
||||
if let ExprKind::ListComp { .. } = &argument {
|
||||
let mut diagnostic =
|
||||
Diagnostic::new(UnnecessaryListComprehensionSet, Range::from_located(expr));
|
||||
let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionSet, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
match fixes::fix_unnecessary_list_comprehension_set(
|
||||
checker.locator,
|
||||
|
|
|
@ -58,7 +58,7 @@ pub fn unnecessary_literal_dict(
|
|||
UnnecessaryLiteralDict {
|
||||
obj_type: kind.to_string(),
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
match fixes::fix_unnecessary_literal_dict(checker.locator, checker.stylist, expr) {
|
||||
|
|
|
@ -51,7 +51,7 @@ pub fn unnecessary_literal_set(
|
|||
UnnecessaryLiteralSet {
|
||||
obj_type: kind.to_string(),
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
match fixes::fix_unnecessary_literal_set(checker.locator, checker.stylist, expr) {
|
||||
|
|
|
@ -66,7 +66,7 @@ pub fn unnecessary_literal_within_list_call(
|
|||
UnnecessaryLiteralWithinListCall {
|
||||
literal: argument_kind.to_string(),
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
match fixes::fix_unnecessary_literal_within_list_call(
|
||||
|
|
|
@ -67,7 +67,7 @@ pub fn unnecessary_literal_within_tuple_call(
|
|||
UnnecessaryLiteralWithinTupleCall {
|
||||
literal: argument_kind.to_string(),
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
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 { .. }) {
|
||||
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()) {
|
||||
match fixes::fix_unnecessary_map(
|
||||
checker.locator,
|
||||
|
@ -136,7 +136,7 @@ pub fn unnecessary_map(
|
|||
return;
|
||||
};
|
||||
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()) {
|
||||
match fixes::fix_unnecessary_map(
|
||||
checker.locator,
|
||||
|
@ -169,7 +169,7 @@ pub fn unnecessary_map(
|
|||
if let ExprKind::Lambda { body, .. } = &argument {
|
||||
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()) {
|
||||
match fixes::fix_unnecessary_map(
|
||||
checker.locator,
|
||||
|
|
|
@ -73,6 +73,6 @@ pub fn unnecessary_subscript_reversal(
|
|||
UnnecessarySubscriptReversal {
|
||||
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 {
|
||||
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 {
|
||||
using_type: DebuggerUsingType::Import(format_call_path(&call_path)),
|
||||
},
|
||||
Range::from_located(stmt),
|
||||
Range::from(stmt),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
|
@ -91,7 +91,7 @@ pub fn debugger_import(stmt: &Stmt, module: Option<&str>, name: &str) -> Option<
|
|||
Debugger {
|
||||
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 {
|
||||
Constant::Str(s) => {
|
||||
if s == "__all__" {
|
||||
return Some(Diagnostic::new(
|
||||
AllWithModelForm,
|
||||
Range::from_located(element),
|
||||
));
|
||||
return Some(Diagnostic::new(AllWithModelForm, Range::from(element)));
|
||||
}
|
||||
}
|
||||
Constant::Bytes(b) => {
|
||||
if b == "__all__".as_bytes() {
|
||||
return Some(Diagnostic::new(
|
||||
AllWithModelForm,
|
||||
Range::from_located(element),
|
||||
));
|
||||
return Some(Diagnostic::new(AllWithModelForm, Range::from(element)));
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
|
|
|
@ -68,10 +68,7 @@ pub fn exclude_with_model_form(
|
|||
continue;
|
||||
};
|
||||
if id == "exclude" {
|
||||
return Some(Diagnostic::new(
|
||||
ExcludeWithModelForm,
|
||||
Range::from_located(target),
|
||||
));
|
||||
return Some(Diagnostic::new(ExcludeWithModelForm, Range::from(target)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,10 +77,9 @@ pub fn locals_in_render_function(
|
|||
return;
|
||||
};
|
||||
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
LocalsInRenderFunction,
|
||||
Range::from_located(locals),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(LocalsInRenderFunction, Range::from(locals)));
|
||||
}
|
||||
|
||||
fn is_locals_call(checker: &Checker, expr: &Expr) -> bool {
|
||||
|
|
|
@ -64,7 +64,7 @@ pub fn model_without_dunder_str(
|
|||
if !has_dunder_method(body) {
|
||||
return Some(Diagnostic::new(
|
||||
ModelWithoutDunderStr,
|
||||
Range::from_located(class_location),
|
||||
Range::from(class_location),
|
||||
));
|
||||
}
|
||||
None
|
||||
|
|
|
@ -69,7 +69,7 @@ where
|
|||
if i > 0 && is_receiver && !seen_receiver {
|
||||
diagnostics.push(Diagnostic::new(
|
||||
NonLeadingReceiverDecorator,
|
||||
Range::from_located(decorator),
|
||||
Range::from(decorator),
|
||||
));
|
||||
}
|
||||
if !is_receiver && seen_receiver {
|
||||
|
|
|
@ -74,7 +74,7 @@ pub fn nullable_model_string_field(checker: &Checker, body: &[Stmt]) -> Vec<Diag
|
|||
NullableModelStringField {
|
||||
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 string.len() > checker.settings.flake8_errmsg.max_string_length {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
RawStringInException,
|
||||
Range::from_located(first),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(RawStringInException, Range::from(first)));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check for f-strings
|
||||
ExprKind::JoinedStr { .. } => {
|
||||
if checker.settings.rules.enabled(&Rule::FStringInException) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
FStringInException,
|
||||
Range::from_located(first),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(FStringInException, Range::from(first)));
|
||||
}
|
||||
}
|
||||
// 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 { .. }) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
DotFormatInException,
|
||||
Range::from_located(first),
|
||||
Range::from(first),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ pub fn explicit(expr: &Expr) -> Option<Diagnostic> {
|
|||
) {
|
||||
return Some(Diagnostic::new(
|
||||
ExplicitStringConcatenation,
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ pub fn check_conventional_import(
|
|||
if !is_valid_import {
|
||||
return Some(Diagnostic::new(
|
||||
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 {
|
||||
Operator::Add => {
|
||||
if checker.settings.rules.enabled(&Rule::LoggingStringConcat) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
LoggingStringConcat,
|
||||
Range::from_located(msg),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(LoggingStringConcat, Range::from(msg)));
|
||||
}
|
||||
}
|
||||
Operator::Mod => {
|
||||
if checker.settings.rules.enabled(&Rule::LoggingPercentFormat) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
LoggingPercentFormat,
|
||||
Range::from_located(msg),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.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) {
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(LoggingFString, Range::from_located(msg)));
|
||||
.push(Diagnostic::new(LoggingFString, Range::from(msg)));
|
||||
}
|
||||
}
|
||||
// Check for .format() calls.
|
||||
|
@ -73,10 +71,9 @@ fn check_msg(checker: &mut Checker, msg: &Expr) {
|
|||
if checker.settings.rules.enabled(&Rule::LoggingStringFormat) {
|
||||
if let ExprKind::Attribute { value, attr, .. } = &func.node {
|
||||
if attr == "format" && matches!(value.node, ExprKind::Constant { .. }) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
LoggingStringFormat,
|
||||
Range::from_located(msg),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.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()) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
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()) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
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(
|
||||
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 ruff_python_ast::source_code::{Locator, Stylist};
|
||||
use ruff_python_ast::types::Range;
|
||||
|
||||
use crate::cst::matchers::{match_call, match_expression};
|
||||
use crate::fix::Fix;
|
||||
|
@ -14,7 +13,7 @@ pub fn fix_unnecessary_comprehension_any_all(
|
|||
expr: &rustpython_parser::ast::Expr,
|
||||
) -> Result<Fix> {
|
||||
// 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 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) {
|
||||
let mut diagnostic =
|
||||
Diagnostic::new(UnnecessaryPass, Range::from_located(pass_stmt));
|
||||
let mut diagnostic = Diagnostic::new(UnnecessaryPass, Range::from(pass_stmt));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(index) = match_trailing_comment(pass_stmt, checker.locator) {
|
||||
diagnostic.amend(Fix::deletion(
|
||||
|
@ -240,7 +239,7 @@ pub fn dupe_class_field_definitions<'a, 'b>(
|
|||
if !seen_targets.insert(target) {
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
DupeClassFieldDefinitions(target.to_string()),
|
||||
Range::from_located(stmt),
|
||||
Range::from(stmt),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let deleted: Vec<&Stmt> = checker.deletions.iter().map(Into::into).collect();
|
||||
|
@ -306,7 +305,7 @@ where
|
|||
PreferUniqueEnums {
|
||||
value: unparse_expr(value, checker.stylist),
|
||||
},
|
||||
Range::from_located(stmt),
|
||||
Range::from(stmt),
|
||||
);
|
||||
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 `**`
|
||||
// inside a dict.
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -340,10 +339,8 @@ pub fn unnecessary_comprehension_any_all(
|
|||
return;
|
||||
}
|
||||
if let ExprKind::ListComp { .. } = args[0].node {
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
UnnecessaryComprehensionAnyAll,
|
||||
Range::from_located(&args[0]),
|
||||
);
|
||||
let mut diagnostic =
|
||||
Diagnostic::new(UnnecessaryComprehensionAnyAll, Range::from(&args[0]));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
match fixes::fix_unnecessary_comprehension_any_all(
|
||||
checker.locator,
|
||||
|
@ -386,8 +383,7 @@ pub fn no_unnecessary_dict_kwargs(checker: &mut Checker, expr: &Expr, kwargs: &[
|
|||
// handle case of foo(**{**bar})
|
||||
(keys.len() == 1 && keys[0].is_none())
|
||||
{
|
||||
let diagnostic =
|
||||
Diagnostic::new(UnnecessaryDictKwargs, Range::from_located(expr));
|
||||
let diagnostic = Diagnostic::new(UnnecessaryDictKwargs, Range::from(expr));
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
}
|
||||
|
@ -424,7 +420,7 @@ pub fn single_starts_ends_with(checker: &mut Checker, values: &[Expr], node: &Bo
|
|||
SingleStartsEndsWith {
|
||||
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 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()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
"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| {
|
||||
*call_path.as_slice() == ["pprint", "pprint"]
|
||||
}) {
|
||||
Diagnostic::new(PPrintFound, Range::from_located(func))
|
||||
Diagnostic::new(PPrintFound, Range::from(func))
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ pub fn bad_version_info_comparison(
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,9 +20,8 @@ impl Violation for DocstringInStub {
|
|||
/// PYI021
|
||||
pub fn docstring_in_stubs(checker: &mut Checker, docstring: Option<&Expr>) {
|
||||
if let Some(docstr) = &docstring {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
DocstringInStub,
|
||||
Range::from_located(docstr),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.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(
|
||||
NonEmptyStubBody,
|
||||
Range::from_located(&body[0]),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.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) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
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(
|
||||
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 {
|
||||
value: Constant::Str(..),
|
||||
..
|
||||
} => return checker.locator.slice(Range::from_located(default)).len() <= 50,
|
||||
} => return checker.locator.slice(default).len() <= 50,
|
||||
ExprKind::Constant {
|
||||
value: Constant::Bytes(..),
|
||||
..
|
||||
} => return checker.locator.slice(Range::from_located(default)).len() <= 50,
|
||||
} => return checker.locator.slice(default).len() <= 50,
|
||||
ExprKind::Constant {
|
||||
value: Constant::Int(..),
|
||||
..
|
||||
} => {
|
||||
return checker.locator.slice(Range::from_located(default)).len() <= 10;
|
||||
return checker.locator.slice(default).len() <= 10;
|
||||
}
|
||||
ExprKind::UnaryOp {
|
||||
op: Unaryop::USub,
|
||||
|
@ -77,7 +77,7 @@ fn is_valid_default_value_with_annotation(default: &Expr, checker: &Checker) ->
|
|||
..
|
||||
} = &operand.node
|
||||
{
|
||||
return checker.locator.slice(Range::from_located(operand)).len() <= 10;
|
||||
return checker.locator.slice(operand).len() <= 10;
|
||||
}
|
||||
}
|
||||
ExprKind::BinOp {
|
||||
|
@ -101,7 +101,7 @@ fn is_valid_default_value_with_annotation(default: &Expr, checker: &Checker) ->
|
|||
..
|
||||
} = &left.node
|
||||
{
|
||||
return checker.locator.slice(Range::from_located(left)).len() <= 10;
|
||||
return checker.locator.slice(left).len() <= 10;
|
||||
} else if let ExprKind::UnaryOp {
|
||||
op: Unaryop::USub,
|
||||
operand,
|
||||
|
@ -114,7 +114,7 @@ fn is_valid_default_value_with_annotation(default: &Expr, checker: &Checker) ->
|
|||
..
|
||||
} = &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) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
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) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
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) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
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) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
ArgumentSimpleDefaults,
|
||||
Range::from_located(default),
|
||||
Range::from(default),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ pub fn unrecognized_platform(
|
|||
};
|
||||
|
||||
let diagnostic_unrecognized_platform_check =
|
||||
Diagnostic::new(UnrecognizedPlatformCheck, Range::from_located(expr));
|
||||
Diagnostic::new(UnrecognizedPlatformCheck, Range::from(expr));
|
||||
if !checker
|
||||
.ctx
|
||||
.resolve_call_path(left)
|
||||
|
@ -143,7 +143,7 @@ pub fn unrecognized_platform(
|
|||
UnrecognizedPlatformName {
|
||||
platform: value.clone(),
|
||||
},
|
||||
Range::from_located(right),
|
||||
Range::from(right),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ where
|
|||
AssertInExcept {
|
||||
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.
|
||||
let fixable = checker.ctx.current_expr_parent().is_none()
|
||||
&& 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(
|
||||
UnittestAssertion {
|
||||
assertion: unittest_assert.to_string(),
|
||||
fixable,
|
||||
},
|
||||
Range::from_located(func),
|
||||
Range::from(func),
|
||||
);
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
if let Ok(stmt) = unittest_assert.generate_assert(args, keywords) {
|
||||
|
@ -226,10 +226,7 @@ pub fn unittest_assertion(
|
|||
/// PT015
|
||||
pub fn assert_falsy(stmt: &Stmt, test: &Expr) -> Option<Diagnostic> {
|
||||
if is_falsy_constant(test) {
|
||||
Some(Diagnostic::new(
|
||||
AssertAlwaysFalse,
|
||||
Range::from_located(stmt),
|
||||
))
|
||||
Some(Diagnostic::new(AssertAlwaysFalse, Range::from(stmt)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -435,9 +432,8 @@ pub fn composite_condition(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg:
|
|||
if matches!(composite, CompositionKind::Simple | CompositionKind::Mixed) {
|
||||
let fixable = matches!(composite, CompositionKind::Simple)
|
||||
&& msg.is_none()
|
||||
&& !has_comments_in(Range::from_located(stmt), checker.locator);
|
||||
let mut diagnostic =
|
||||
Diagnostic::new(CompositeAssertion { fixable }, Range::from_located(stmt));
|
||||
&& !has_comments_in(Range::from(stmt), checker.locator);
|
||||
let mut diagnostic = Diagnostic::new(CompositeAssertion { fixable }, Range::from(stmt));
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
if let Ok(fix) = fix_composite_condition(stmt, checker.locator, checker.stylist) {
|
||||
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 is_empty_or_null_string(msg) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
FailWithoutMessage,
|
||||
Range::from_located(func),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(FailWithoutMessage, Range::from(func)));
|
||||
}
|
||||
} else {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
FailWithoutMessage,
|
||||
Range::from_located(func),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(FailWithoutMessage, Range::from(func)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -246,7 +246,7 @@ fn pytest_fixture_parentheses(
|
|||
expected_parens: preferred.to_string(),
|
||||
actual_parens: actual.to_string(),
|
||||
},
|
||||
Range::from_located(decorator),
|
||||
Range::from(decorator),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(fix);
|
||||
|
@ -292,7 +292,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E
|
|||
FixturePositionalArgs {
|
||||
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 keyword_is_literal(scope_keyword, "function") {
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
ExtraneousScopeFunction,
|
||||
Range::from_located(scope_keyword),
|
||||
);
|
||||
let mut diagnostic =
|
||||
Diagnostic::new(ExtraneousScopeFunction, Range::from(scope_keyword));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
match fix_extraneous_scope_function(
|
||||
checker.locator,
|
||||
|
@ -364,7 +362,7 @@ fn check_fixture_returns(checker: &mut Checker, func: &Stmt, func_name: &str, bo
|
|||
IncorrectFixtureNameUnderscore {
|
||||
function: func_name.to_string(),
|
||||
},
|
||||
Range::from_located(func),
|
||||
Range::from(func),
|
||||
));
|
||||
} else if checker
|
||||
.settings
|
||||
|
@ -378,7 +376,7 @@ fn check_fixture_returns(checker: &mut Checker, func: &Stmt, func_name: &str, bo
|
|||
MissingFixtureNameUnderscore {
|
||||
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 {
|
||||
name: func_name.to_string(),
|
||||
},
|
||||
Range::from_located(stmt),
|
||||
Range::from(stmt),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
|
@ -420,7 +418,7 @@ fn check_test_function_args(checker: &mut Checker, args: &Arguments) {
|
|||
FixtureParamWithoutValue {
|
||||
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) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
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 {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
FixtureFinalizerCallback,
|
||||
Range::from_located(addfinalizer),
|
||||
Range::from(addfinalizer),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -468,7 +466,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Expr]) {
|
|||
{
|
||||
if name == "asyncio" {
|
||||
let mut diagnostic =
|
||||
Diagnostic::new(UnnecessaryAsyncioMarkOnFixture, Range::from_located(mark));
|
||||
Diagnostic::new(UnnecessaryAsyncioMarkOnFixture, Range::from(mark));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let start = Location::new(mark.location.row(), 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" {
|
||||
let mut diagnostic =
|
||||
Diagnostic::new(ErroneousUseFixturesOnFixture, Range::from_located(mark));
|
||||
Diagnostic::new(ErroneousUseFixturesOnFixture, Range::from(mark));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let start = Location::new(mark.location.row(), 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 {
|
||||
return Some(Diagnostic::new(
|
||||
IncorrectPytestImport,
|
||||
Range::from_located(import_from),
|
||||
Range::from(import_from),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ pub fn import_from(
|
|||
if is_pytest_or_subpackage(module) {
|
||||
return Some(Diagnostic::new(
|
||||
IncorrectPytestImport,
|
||||
Range::from_located(import_from),
|
||||
Range::from(import_from),
|
||||
));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -63,7 +63,7 @@ fn pytest_mark_parentheses(
|
|||
expected_parens: preferred.to_string(),
|
||||
actual_parens: actual.to_string(),
|
||||
},
|
||||
Range::from_located(decorator),
|
||||
Range::from(decorator),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(fix);
|
||||
|
@ -111,8 +111,7 @@ fn check_useless_usefixtures(checker: &mut Checker, decorator: &Expr) {
|
|||
}
|
||||
|
||||
if !has_parameters {
|
||||
let mut diagnostic =
|
||||
Diagnostic::new(UseFixturesWithoutParameters, Range::from_located(decorator));
|
||||
let mut diagnostic = Diagnostic::new(UseFixturesWithoutParameters, Range::from(decorator));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let at_start = Location::new(decorator.location.row(), decorator.location.column() - 1);
|
||||
diagnostic.amend(Fix::deletion(at_start, decorator.end_location.unwrap()));
|
||||
|
|
|
@ -97,7 +97,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
|||
ParametrizeNamesWrongType {
|
||||
expected: names_type,
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
|
@ -130,7 +130,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
|||
ParametrizeNamesWrongType {
|
||||
expected: names_type,
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
|
@ -172,7 +172,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
|||
ParametrizeNamesWrongType {
|
||||
expected: names_type,
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
|
@ -194,7 +194,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
|||
ParametrizeNamesWrongType {
|
||||
expected: names_type,
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(content) = elts_to_csv(elts, checker) {
|
||||
|
@ -223,7 +223,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
|||
ParametrizeNamesWrongType {
|
||||
expected: names_type,
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
|
@ -248,7 +248,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
|||
ParametrizeNamesWrongType {
|
||||
expected: names_type,
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
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,
|
||||
row: values_row_type,
|
||||
},
|
||||
Range::from_located(values),
|
||||
Range::from(values),
|
||||
));
|
||||
}
|
||||
if is_multi_named {
|
||||
|
@ -309,7 +309,7 @@ fn check_values(checker: &mut Checker, names: &Expr, values: &Expr) {
|
|||
values: values_type,
|
||||
row: values_row_type,
|
||||
},
|
||||
Range::from_located(values),
|
||||
Range::from(values),
|
||||
));
|
||||
}
|
||||
if is_multi_named {
|
||||
|
@ -325,7 +325,7 @@ fn handle_single_name(checker: &mut Checker, expr: &Expr, value: &Expr) {
|
|||
ParametrizeNamesWrongType {
|
||||
expected: types::ParametrizeNameType::Csv,
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
|
@ -353,7 +353,7 @@ fn handle_value_rows(
|
|||
values: values_type,
|
||||
row: values_row_type,
|
||||
},
|
||||
Range::from_located(elt),
|
||||
Range::from(elt),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -364,7 +364,7 @@ fn handle_value_rows(
|
|||
values: values_type,
|
||||
row: values_row_type,
|
||||
},
|
||||
Range::from_located(elt),
|
||||
Range::from(elt),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ fn check_patch_call(
|
|||
visitor.visit_expr(body);
|
||||
|
||||
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)
|
||||
{
|
||||
if args.is_empty() && keywords.is_empty() {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
RaisesWithoutException,
|
||||
Range::from_located(func),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.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 {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
RaisesWithMultipleStatements,
|
||||
Range::from_located(stmt),
|
||||
Range::from(stmt),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -168,7 +167,7 @@ fn exception_needs_match(checker: &mut Checker, exception: &Expr) {
|
|||
RaisesTooBroad {
|
||||
exception: call_path,
|
||||
},
|
||||
Range::from_located(exception),
|
||||
Range::from(exception),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ fn unnecessary_return_none(checker: &mut Checker, stack: &Stack) {
|
|||
) {
|
||||
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()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
"return".to_string(),
|
||||
|
@ -155,7 +155,7 @@ fn implicit_return_value(checker: &mut Checker, stack: &Stack) {
|
|||
if expr.is_some() {
|
||||
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()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
"return None".to_string(),
|
||||
|
@ -212,7 +212,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) {
|
|||
if let Some(last_stmt) = orelse.last() {
|
||||
implicit_return(checker, last_stmt);
|
||||
} 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 let Some(indent) = indentation(checker.locator, stmt) {
|
||||
let mut content = String::new();
|
||||
|
@ -252,7 +252,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) {
|
|||
if let Some(last_stmt) = orelse.last() {
|
||||
implicit_return(checker, last_stmt);
|
||||
} 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 let Some(indent) = indentation(checker.locator, stmt) {
|
||||
let mut content = String::new();
|
||||
|
@ -291,7 +291,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) {
|
|||
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 let Some(indent) = indentation(checker.locator, stmt) {
|
||||
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()) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
UnnecessaryAssign,
|
||||
Range::from_located(expr),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(UnnecessaryAssign, Range::from(expr)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -400,10 +399,9 @@ fn unnecessary_assign(checker: &mut Checker, stack: &Stack, expr: &Expr) {
|
|||
return;
|
||||
}
|
||||
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
UnnecessaryAssign,
|
||||
Range::from_located(expr),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.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 { .. }) {
|
||||
let diagnostic = Diagnostic::new(
|
||||
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()) {
|
||||
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) {
|
||||
let diagnostic = Diagnostic::new(
|
||||
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()) {
|
||||
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 { .. }) {
|
||||
let diagnostic = Diagnostic::new(
|
||||
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()) {
|
||||
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) {
|
||||
let diagnostic = Diagnostic::new(
|
||||
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()) {
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -120,7 +120,7 @@ pub fn private_member_access(checker: &mut Checker, expr: &Expr) {
|
|||
PrivateMemberAccess {
|
||||
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 {
|
||||
name: arg_name.to_string(),
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Grab the types used in each duplicate `isinstance` call.
|
||||
|
@ -340,7 +340,7 @@ pub fn compare_with_tuple(checker: &mut Checker, expr: &Expr) {
|
|||
CompareWithTuple {
|
||||
replacement: unparse_expr(&in_expr, checker.stylist),
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let unmatched: Vec<Expr> = values
|
||||
|
@ -407,7 +407,7 @@ pub fn expr_and_not_expr(checker: &mut Checker, expr: &Expr) {
|
|||
ExprAndNotExpr {
|
||||
name: id.to_string(),
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
|
@ -461,7 +461,7 @@ pub fn expr_or_not_expr(checker: &mut Checker, expr: &Expr) {
|
|||
ExprOrNotExpr {
|
||||
name: id.to_string(),
|
||||
},
|
||||
Range::from_located(expr),
|
||||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
|
@ -490,7 +490,7 @@ pub fn expr_or_true(checker: &mut Checker, expr: &Expr) {
|
|||
..
|
||||
} = &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()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
"True".to_string(),
|
||||
|
@ -517,7 +517,7 @@ pub fn expr_and_false(checker: &mut Checker, expr: &Expr) {
|
|||
..
|
||||
} = &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()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
"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