mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-09 21:28:21 +00:00
Add Applicability
to Fix
(#4303)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
d66ce76691
commit
cf7aa26aa4
116 changed files with 296 additions and 8 deletions
|
@ -108,6 +108,7 @@ mod tests {
|
|||
use crate::autofix::apply_fixes;
|
||||
use crate::rules::pycodestyle::rules::MissingNewlineAtEndOfFile;
|
||||
|
||||
#[allow(deprecated)]
|
||||
fn create_diagnostics(edit: impl IntoIterator<Item = Edit>) -> Vec<Diagnostic> {
|
||||
edit.into_iter()
|
||||
.map(|edit| Diagnostic {
|
||||
|
|
|
@ -5336,7 +5336,9 @@ impl<'a> Checker<'a> {
|
|||
if matches!(child.node, StmtKind::ImportFrom { .. }) {
|
||||
diagnostic.set_parent(child.start());
|
||||
}
|
||||
|
||||
if let Some(edit) = &fix {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(edit.clone()));
|
||||
}
|
||||
diagnostics.push(diagnostic);
|
||||
|
|
|
@ -180,6 +180,7 @@ pub fn check_noqa(
|
|||
locator,
|
||||
));
|
||||
} else {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
format!("# noqa: {}", valid_codes.join(", ")),
|
||||
*range,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::message::Message;
|
||||
use colored::{Color, ColoredString, Colorize, Styles};
|
||||
use ruff_diagnostics::Fix;
|
||||
use ruff_diagnostics::{Applicability, Fix};
|
||||
use ruff_python_ast::source_code::{OneIndexed, SourceFile};
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
use similar::{ChangeTag, TextDiff};
|
||||
|
@ -47,7 +47,13 @@ impl Display for Diff<'_> {
|
|||
|
||||
let diff = TextDiff::from_lines(self.source_code.source_text(), &output);
|
||||
|
||||
writeln!(f, "{}", "ℹ Suggested fix".blue())?;
|
||||
let message = match self.fix.applicability() {
|
||||
Applicability::Automatic => "Fix",
|
||||
Applicability::Suggested => "Suggested fix",
|
||||
Applicability::Manual => "Possible fix",
|
||||
Applicability::Unspecified => "Suggested fix", // For backwards compatibility, unspecified fixes are 'suggested'
|
||||
};
|
||||
writeln!(f, "ℹ {}", message.blue())?;
|
||||
|
||||
let (largest_old, largest_new) = diff
|
||||
.ops()
|
||||
|
|
|
@ -185,6 +185,7 @@ def fibonacci(n):
|
|||
|
||||
let fib_source = SourceFileBuilder::new("fib.py", fib).finish();
|
||||
|
||||
#[allow(deprecated)]
|
||||
let unused_variable = Diagnostic::new(
|
||||
UnusedVariable {
|
||||
name: "x".to_string(),
|
||||
|
|
|
@ -57,7 +57,9 @@ pub fn commented_out_code(
|
|||
// Verify that the comment is on its own line, and that it contains code.
|
||||
if is_standalone_comment(line) && comment_contains_code(line, &settings.task_tags[..]) {
|
||||
let mut diagnostic = Diagnostic::new(CommentedOutCode, range);
|
||||
|
||||
if autofix.into() && settings.rules.should_fix(Rule::CommentedOutCode) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(
|
||||
locator.full_lines_range(range),
|
||||
)));
|
||||
|
|
|
@ -63,6 +63,7 @@ pub fn assert_false(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg: Option
|
|||
|
||||
let mut diagnostic = Diagnostic::new(AssertFalse, test.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_stmt(&assertion_error(msg), checker.stylist),
|
||||
stmt.range(),
|
||||
|
|
|
@ -96,6 +96,7 @@ fn duplicate_handler_exceptions<'a>(
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
if unique_elts.len() == 1 {
|
||||
unparse_expr(unique_elts[0], checker.stylist)
|
||||
|
|
|
@ -64,6 +64,7 @@ pub fn getattr_with_constant(checker: &mut Checker, expr: &Expr, func: &Expr, ar
|
|||
let mut diagnostic = Diagnostic::new(GetAttrWithConstant, expr.range());
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(&attribute(obj, value), checker.stylist),
|
||||
expr.range(),
|
||||
|
|
|
@ -47,6 +47,7 @@ pub fn redundant_tuple_in_exception_handler(checker: &mut Checker, handlers: &[E
|
|||
type_.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(elt, checker.stylist),
|
||||
type_.range(),
|
||||
|
|
|
@ -79,6 +79,7 @@ pub fn setattr_with_constant(checker: &mut Checker, expr: &Expr, func: &Expr, ar
|
|||
let mut diagnostic = Diagnostic::new(SetAttrWithConstant, expr.range());
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
assignment(obj, name, value, checker.stylist),
|
||||
expr.range(),
|
||||
|
|
|
@ -169,6 +169,7 @@ pub fn unused_loop_control_variable(checker: &mut Checker, target: &Expr, body:
|
|||
if let Some(binding) = binding {
|
||||
if binding.kind.is_loop_var() {
|
||||
if !binding.used() {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
rename,
|
||||
expr.range(),
|
||||
|
|
|
@ -325,6 +325,7 @@ pub fn trailing_commas(
|
|||
let comma = prev.spanned.unwrap();
|
||||
let mut diagnostic = Diagnostic::new(ProhibitedTrailingComma, comma.1);
|
||||
if autofix.into() && settings.rules.should_fix(Rule::ProhibitedTrailingComma) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(diagnostic.range())));
|
||||
}
|
||||
diagnostics.push(diagnostic);
|
||||
|
@ -365,6 +366,7 @@ pub fn trailing_commas(
|
|||
// removing any brackets in the same linter pass - doing both at the same time could
|
||||
// lead to a syntax error.
|
||||
let contents = locator.slice(missing_comma.1);
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
format!("{contents},"),
|
||||
missing_comma.1,
|
||||
|
|
|
@ -203,6 +203,7 @@ fn generate_fix(stylist: &Stylist, stmt: &Stmt, exc_arg: &Expr, indentation: &st
|
|||
}),
|
||||
stylist,
|
||||
);
|
||||
#[allow(deprecated)]
|
||||
Fix::unspecified_edits(
|
||||
Edit::insertion(
|
||||
format!(
|
||||
|
|
|
@ -32,6 +32,7 @@ pub fn shebang_whitespace(
|
|||
TextRange::at(range.start(), *n_spaces),
|
||||
);
|
||||
if autofix {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(TextRange::at(
|
||||
range.start(),
|
||||
*n_spaces,
|
||||
|
|
|
@ -171,6 +171,7 @@ pub fn logging_call(checker: &mut Checker, func: &Expr, args: &[Expr], keywords:
|
|||
{
|
||||
let mut diagnostic = Diagnostic::new(LoggingWarn, level_call_range);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"warning".to_string(),
|
||||
level_call_range,
|
||||
|
|
|
@ -315,6 +315,7 @@ pub fn no_unnecessary_pass(checker: &mut Checker, body: &[Stmt]) {
|
|||
let mut diagnostic = Diagnostic::new(UnnecessaryPass, pass_stmt.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(index) = trailing_comment_start_offset(pass_stmt, checker.locator) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(
|
||||
pass_stmt.range().add_end(index),
|
||||
)));
|
||||
|
@ -596,7 +597,7 @@ pub fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) {
|
|||
})
|
||||
.collect(),
|
||||
});
|
||||
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(&bool_op, checker.stylist),
|
||||
expr.range(),
|
||||
|
@ -622,6 +623,7 @@ pub fn reimplemented_list_builtin(checker: &mut Checker, expr: &Expr) {
|
|||
if elts.is_empty() {
|
||||
let mut diagnostic = Diagnostic::new(ReimplementedListBuiltin, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"list".to_string(),
|
||||
expr.range(),
|
||||
|
|
|
@ -77,6 +77,7 @@ fn traverse_union<'a>(
|
|||
};
|
||||
|
||||
// Replace the parent with its non-duplicate child.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(
|
||||
if expr.node == left.node { right } else { left },
|
||||
|
|
|
@ -23,6 +23,7 @@ impl AlwaysAutofixableViolation for QuotedAnnotationInStub {
|
|||
pub fn quoted_annotation_in_stub(checker: &mut Checker, annotation: &str, range: TextRange) {
|
||||
let mut diagnostic = Diagnostic::new(QuotedAnnotationInStub, range);
|
||||
if checker.patch(Rule::QuotedAnnotationInStub) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
annotation.to_string(),
|
||||
range,
|
||||
|
|
|
@ -298,6 +298,7 @@ pub fn typed_argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
|
|||
Diagnostic::new(TypedArgumentDefaultInStub, default.range());
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"...".to_string(),
|
||||
default.range(),
|
||||
|
@ -324,6 +325,7 @@ pub fn typed_argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
|
|||
Diagnostic::new(TypedArgumentDefaultInStub, default.range());
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"...".to_string(),
|
||||
default.range(),
|
||||
|
@ -353,6 +355,7 @@ pub fn argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
|
|||
Diagnostic::new(ArgumentDefaultInStub, default.range());
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"...".to_string(),
|
||||
default.range(),
|
||||
|
@ -379,6 +382,7 @@ pub fn argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
|
|||
Diagnostic::new(ArgumentDefaultInStub, default.range());
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"...".to_string(),
|
||||
default.range(),
|
||||
|
@ -410,6 +414,7 @@ pub fn assignment_default_in_stub(checker: &mut Checker, targets: &[Expr], value
|
|||
|
||||
let mut diagnostic = Diagnostic::new(AssignmentDefaultInStub, value.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"...".to_string(),
|
||||
value.range(),
|
||||
|
@ -440,6 +445,7 @@ pub fn annotated_assignment_default_in_stub(
|
|||
|
||||
let mut diagnostic = Diagnostic::new(AssignmentDefaultInStub, value.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"...".to_string(),
|
||||
value.range(),
|
||||
|
|
|
@ -204,6 +204,7 @@ pub fn unittest_assertion(
|
|||
);
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
if let Ok(stmt) = unittest_assert.generate_assert(args, keywords) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_stmt(&stmt, checker.stylist),
|
||||
expr.range(),
|
||||
|
|
|
@ -292,6 +292,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E
|
|||
&& args.is_empty()
|
||||
&& keywords.is_empty()
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
let fix = Fix::unspecified(Edit::deletion(func.end(), decorator.end()));
|
||||
pytest_fixture_parentheses(
|
||||
checker,
|
||||
|
@ -354,6 +355,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E
|
|||
.enabled(Rule::PytestFixtureIncorrectParenthesesStyle)
|
||||
&& checker.settings.flake8_pytest_style.fixture_parentheses
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
let fix = Fix::unspecified(Edit::insertion(
|
||||
Parentheses::Empty.to_string(),
|
||||
decorator.end(),
|
||||
|
@ -423,6 +425,7 @@ fn check_fixture_returns(checker: &mut Checker, stmt: &Stmt, name: &str, body: &
|
|||
stmt.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"return".to_string(),
|
||||
TextRange::at(stmt.start(), "yield".text_len()),
|
||||
|
@ -495,6 +498,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Expr]) {
|
|||
Diagnostic::new(PytestUnnecessaryAsyncioMarkOnFixture, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let range = checker.locator.full_lines_range(expr.range());
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range)));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
@ -511,6 +515,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Expr]) {
|
|||
Diagnostic::new(PytestErroneousUseFixturesOnFixture, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let line_range = checker.locator.full_lines_range(expr.range());
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(line_range)));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -84,12 +84,14 @@ fn check_mark_parentheses(checker: &mut Checker, decorator: &Expr, call_path: &C
|
|||
&& args.is_empty()
|
||||
&& keywords.is_empty()
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
let fix = Fix::unspecified(Edit::deletion(func.end(), decorator.end()));
|
||||
pytest_mark_parentheses(checker, decorator, call_path, fix, "", "()");
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if checker.settings.flake8_pytest_style.mark_parentheses {
|
||||
#[allow(deprecated)]
|
||||
let fix = Fix::unspecified(Edit::insertion("()".to_string(), decorator.end()));
|
||||
pytest_mark_parentheses(checker, decorator, call_path, fix, "()", "");
|
||||
}
|
||||
|
@ -113,6 +115,7 @@ fn check_useless_usefixtures(checker: &mut Checker, decorator: &Expr, call_path:
|
|||
if !has_parameters {
|
||||
let mut diagnostic = Diagnostic::new(PytestUseFixturesWithoutParameters, decorator.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(
|
||||
decorator.range().sub_start(TextSize::from(1)),
|
||||
)));
|
||||
|
|
|
@ -148,6 +148,7 @@ fn check_names(checker: &mut Checker, decorator: &Expr, expr: &Expr) {
|
|||
name_range,
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
format!(
|
||||
"({})",
|
||||
|
@ -181,6 +182,7 @@ fn check_names(checker: &mut Checker, decorator: &Expr, expr: &Expr) {
|
|||
name_range,
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::List {
|
||||
|
@ -222,6 +224,7 @@ fn check_names(checker: &mut Checker, decorator: &Expr, expr: &Expr) {
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::List {
|
||||
|
@ -244,6 +247,7 @@ fn check_names(checker: &mut Checker, decorator: &Expr, expr: &Expr) {
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(content) = elts_to_csv(elts, checker) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
content,
|
||||
expr.range(),
|
||||
|
@ -271,6 +275,7 @@ fn check_names(checker: &mut Checker, decorator: &Expr, expr: &Expr) {
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
format!(
|
||||
"({})",
|
||||
|
@ -296,6 +301,7 @@ fn check_names(checker: &mut Checker, decorator: &Expr, expr: &Expr) {
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(content) = elts_to_csv(elts, checker) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
content,
|
||||
expr.range(),
|
||||
|
@ -372,6 +378,7 @@ fn handle_single_name(checker: &mut Checker, expr: &Expr, value: &Expr) {
|
|||
);
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(&create_expr(value.node.clone()), checker.stylist),
|
||||
expr.range(),
|
||||
|
|
|
@ -289,6 +289,7 @@ fn docstring(
|
|||
fixed_contents.push_str("e);
|
||||
fixed_contents.push_str(string_contents);
|
||||
fixed_contents.push_str("e);
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
fixed_contents,
|
||||
range,
|
||||
|
@ -367,6 +368,7 @@ fn strings(
|
|||
fixed_contents.push_str(quote);
|
||||
fixed_contents.push_str(string_contents);
|
||||
fixed_contents.push_str(quote);
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
fixed_contents,
|
||||
*range,
|
||||
|
@ -433,6 +435,7 @@ fn strings(
|
|||
|
||||
fixed_contents.push(quote);
|
||||
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
fixed_contents,
|
||||
*range,
|
||||
|
@ -459,6 +462,7 @@ fn strings(
|
|||
fixed_contents.push(quote);
|
||||
fixed_contents.push_str(string_contents);
|
||||
fixed_contents.push(quote);
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
fixed_contents,
|
||||
*range,
|
||||
|
|
|
@ -34,6 +34,7 @@ pub fn unnecessary_paren_on_raise_exception(checker: &mut Checker, expr: &Expr)
|
|||
.expect("Expected call to include parentheses");
|
||||
let mut diagnostic = Diagnostic::new(UnnecessaryParenOnRaiseException, range);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::deletion(func.end(), range.end())));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -341,6 +341,7 @@ fn unnecessary_return_none(checker: &mut Checker, stack: &Stack) {
|
|||
}
|
||||
let mut diagnostic = Diagnostic::new(UnnecessaryReturnNone, stmt.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"return".to_string(),
|
||||
stmt.range(),
|
||||
|
@ -358,6 +359,7 @@ fn implicit_return_value(checker: &mut Checker, stack: &Stack) {
|
|||
}
|
||||
let mut diagnostic = Diagnostic::new(ImplicitReturnValue, stmt.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"return None".to_string(),
|
||||
stmt.range(),
|
||||
|
@ -415,6 +417,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) {
|
|||
content.push_str(checker.stylist.line_ending().as_str());
|
||||
content.push_str(indent);
|
||||
content.push_str("return None");
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
|
||||
content,
|
||||
end_of_last_statement(stmt, checker.locator),
|
||||
|
@ -453,6 +456,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) {
|
|||
content.push_str(checker.stylist.line_ending().as_str());
|
||||
content.push_str(indent);
|
||||
content.push_str("return None");
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
|
||||
content,
|
||||
end_of_last_statement(stmt, checker.locator),
|
||||
|
@ -492,6 +496,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) {
|
|||
content.push_str(checker.stylist.line_ending().as_str());
|
||||
content.push_str(indent);
|
||||
content.push_str("return None");
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
|
||||
content,
|
||||
end_of_last_statement(stmt, checker.locator),
|
||||
|
|
|
@ -366,6 +366,7 @@ pub fn duplicate_isinstance_call(checker: &mut Checker, expr: &Expr) {
|
|||
|
||||
// Populate the `Fix`. Replace the _entire_ `BoolOp`. Note that if we have
|
||||
// multiple duplicates, the fixes will conflict.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(&bool_op, checker.stylist),
|
||||
expr.range(),
|
||||
|
@ -468,6 +469,7 @@ pub fn compare_with_tuple(checker: &mut Checker, expr: &Expr) {
|
|||
values: iter::once(in_expr).chain(unmatched).collect(),
|
||||
})
|
||||
};
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(&in_expr, checker.stylist),
|
||||
expr.range(),
|
||||
|
@ -519,6 +521,7 @@ pub fn expr_and_not_expr(checker: &mut Checker, expr: &Expr) {
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"False".to_string(),
|
||||
expr.range(),
|
||||
|
@ -572,6 +575,7 @@ pub fn expr_or_not_expr(checker: &mut Checker, expr: &Expr) {
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"True".to_string(),
|
||||
expr.range(),
|
||||
|
@ -695,6 +699,7 @@ pub fn expr_or_true(checker: &mut Checker, expr: &Expr) {
|
|||
edit.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(edit));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
@ -714,6 +719,7 @@ pub fn expr_and_false(checker: &mut Checker, expr: &Expr) {
|
|||
edit.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(edit));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -137,6 +137,7 @@ fn check_os_environ_subscript(checker: &mut Checker, expr: &Expr) {
|
|||
value: capital_env_var.into(),
|
||||
kind: kind.clone(),
|
||||
});
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(&new_env_var, checker.stylist),
|
||||
slice.range(),
|
||||
|
@ -197,6 +198,7 @@ pub fn dict_get_with_none_default(checker: &mut Checker, expr: &Expr) {
|
|||
);
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
expected,
|
||||
expr.range(),
|
||||
|
|
|
@ -304,6 +304,7 @@ pub fn nested_if_statements(
|
|||
.universal_newlines()
|
||||
.all(|line| line.width() <= checker.settings.line_length)
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(edit));
|
||||
}
|
||||
}
|
||||
|
@ -370,6 +371,7 @@ pub fn needless_bool(checker: &mut Checker, stmt: &Stmt) {
|
|||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
if matches!(test.node, ExprKind::Compare { .. }) {
|
||||
// If the condition is a comparison, we can replace it with the condition.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_stmt(
|
||||
&create_stmt(StmtKind::Return {
|
||||
|
@ -382,6 +384,7 @@ pub fn needless_bool(checker: &mut Checker, stmt: &Stmt) {
|
|||
} else {
|
||||
// Otherwise, we need to wrap the condition in a call to `bool`. (We've already
|
||||
// verified, above, that `bool` is a builtin.)
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_stmt(
|
||||
&create_stmt(StmtKind::Return {
|
||||
|
@ -528,6 +531,7 @@ pub fn use_ternary_operator(checker: &mut Checker, stmt: &Stmt, parent: Option<&
|
|||
stmt.range(),
|
||||
);
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
contents,
|
||||
stmt.range(),
|
||||
|
@ -878,6 +882,7 @@ pub fn use_dict_get_with_default(
|
|||
stmt.range(),
|
||||
);
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
contents,
|
||||
stmt.range(),
|
||||
|
|
|
@ -100,11 +100,13 @@ pub fn explicit_true_false_in_ifexpr(
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if matches!(test.node, ExprKind::Compare { .. }) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(&test.clone(), checker.stylist),
|
||||
expr.range(),
|
||||
)));
|
||||
} else if checker.ctx.is_builtin("bool") {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::Call {
|
||||
|
@ -152,6 +154,7 @@ pub fn explicit_false_true_in_ifexpr(
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::UnaryOp {
|
||||
|
@ -200,6 +203,7 @@ pub fn twisted_arms_in_ifexpr(
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::IfExp {
|
||||
|
|
|
@ -107,6 +107,7 @@ pub fn negation_with_equal_op(checker: &mut Checker, expr: &Expr, op: &Unaryop,
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::Compare {
|
||||
|
@ -157,6 +158,7 @@ pub fn negation_with_not_equal_op(
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::Compare {
|
||||
|
@ -192,11 +194,13 @@ pub fn double_negation(checker: &mut Checker, expr: &Expr, op: &Unaryop, operand
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if checker.ctx.in_boolean_test {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(operand, checker.stylist),
|
||||
expr.range(),
|
||||
)));
|
||||
} else if checker.ctx.is_builtin("bool") {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::Call {
|
||||
|
|
|
@ -118,6 +118,7 @@ pub fn multiple_with_statements(
|
|||
.universal_newlines()
|
||||
.all(|line| line.width() <= checker.settings.line_length)
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(edit));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,6 +91,7 @@ fn key_in_dict(checker: &mut Checker, left: &Expr, right: &Expr, range: TextRang
|
|||
range,
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
value_content,
|
||||
right.range(),
|
||||
|
|
|
@ -227,6 +227,7 @@ pub fn convert_for_loop_to_any_all(checker: &mut Checker, stmt: &Stmt, sibling:
|
|||
stmt.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) && checker.ctx.is_builtin("any") {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
|
||||
contents,
|
||||
stmt.start(),
|
||||
|
@ -308,6 +309,7 @@ pub fn convert_for_loop_to_any_all(checker: &mut Checker, stmt: &Stmt, sibling:
|
|||
stmt.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) && checker.ctx.is_builtin("all") {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
|
||||
contents,
|
||||
stmt.start(),
|
||||
|
|
|
@ -113,6 +113,7 @@ pub fn suppressible_exception(
|
|||
);
|
||||
let handler_line_begin = checker.locator.line_start(handler.start());
|
||||
let remove_handler = Edit::deletion(handler_line_begin, handler.end());
|
||||
#[allow(deprecated)]
|
||||
Ok(Fix::unspecified_edits(
|
||||
import_edit,
|
||||
[replace_try, remove_handler],
|
||||
|
|
|
@ -161,6 +161,7 @@ pub fn yoda_conditions(
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
suggestion,
|
||||
expr.range(),
|
||||
|
|
|
@ -112,7 +112,7 @@ fn fix_banned_relative_import(
|
|||
}),
|
||||
stylist,
|
||||
);
|
||||
|
||||
#[allow(deprecated)]
|
||||
Some(Fix::unspecified(Edit::range_replacement(
|
||||
content,
|
||||
stmt.range(),
|
||||
|
|
|
@ -74,6 +74,7 @@ pub fn empty_type_checking_block<'a, 'b>(
|
|||
if edit.is_deletion() || edit.content() == Some("pass") {
|
||||
checker.deletions.insert(RefEquality(stmt));
|
||||
}
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(edit));
|
||||
}
|
||||
Err(e) => error!("Failed to remove empty type-checking block: {e}"),
|
||||
|
|
|
@ -87,6 +87,7 @@ pub fn static_join_to_fstring(checker: &mut Checker, expr: &Expr, joiner: &str)
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
contents,
|
||||
expr.range(),
|
||||
|
|
|
@ -120,6 +120,7 @@ fn add_required_import(
|
|||
TextRange::default(),
|
||||
);
|
||||
if autofix.into() && settings.rules.should_fix(Rule::MissingRequiredImport) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(
|
||||
Importer::new(python_ast, locator, stylist)
|
||||
.add_import(required_import, TextSize::default()),
|
||||
|
|
|
@ -148,6 +148,7 @@ pub fn organize_imports(
|
|||
} else {
|
||||
let mut diagnostic = Diagnostic::new(UnsortedImports, range);
|
||||
if autofix.into() && settings.rules.should_fix(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
indent(&expected, indentation),
|
||||
range,
|
||||
|
|
|
@ -70,6 +70,7 @@ pub fn deprecated_type_alias(checker: &mut Checker, expr: &Expr) {
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
match type_name {
|
||||
"unicode" => "str",
|
||||
|
|
|
@ -40,6 +40,6 @@ pub(super) fn convert_inplace_argument_to_assignment(
|
|||
false,
|
||||
)
|
||||
.ok()?;
|
||||
|
||||
#[allow(deprecated)]
|
||||
Some(Fix::unspecified_edits(insert_assignment, [remove_argument]))
|
||||
}
|
||||
|
|
|
@ -164,6 +164,7 @@ pub fn compound_statements(
|
|||
let mut diagnostic =
|
||||
Diagnostic::new(UselessSemicolon, TextRange::new(start, end));
|
||||
if autofix.into() && settings.rules.should_fix(Rule::UselessSemicolon) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::deletion(start, end)));
|
||||
};
|
||||
diagnostics.push(diagnostic);
|
||||
|
|
|
@ -108,6 +108,7 @@ pub fn invalid_escape_sequence(
|
|||
let range = TextRange::at(location, next_char.text_len() + TextSize::from(1));
|
||||
let mut diagnostic = Diagnostic::new(InvalidEscapeSequence(*next_char), range);
|
||||
if autofix {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
|
||||
r"\".to_string(),
|
||||
range.start() + TextSize::from(1),
|
||||
|
|
|
@ -103,6 +103,7 @@ pub fn lambda_assignment(
|
|||
indented.push_str(&line);
|
||||
}
|
||||
}
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
indented,
|
||||
stmt.range(),
|
||||
|
|
|
@ -277,6 +277,7 @@ pub fn literal_comparisons(
|
|||
.collect::<Vec<_>>();
|
||||
let content = compare(left, &ops, comparators, checker.stylist);
|
||||
for diagnostic in &mut diagnostics {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
content.to_string(),
|
||||
expr.range(),
|
||||
|
|
|
@ -86,6 +86,7 @@ pub(crate) fn missing_whitespace(
|
|||
let mut diagnostic = Diagnostic::new(kind, TextRange::empty(token.start()));
|
||||
|
||||
if autofix {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
|
||||
" ".to_string(),
|
||||
token.end(),
|
||||
|
|
|
@ -63,6 +63,7 @@ pub(crate) fn whitespace_before_parameters(
|
|||
let mut diagnostic = Diagnostic::new(kind, TextRange::new(start, end));
|
||||
|
||||
if autofix {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::deletion(start, end)));
|
||||
}
|
||||
context.push_diagnostic(diagnostic);
|
||||
|
|
|
@ -55,6 +55,7 @@ pub fn no_newline_at_end_of_file(
|
|||
|
||||
let mut diagnostic = Diagnostic::new(MissingNewlineAtEndOfFile, range);
|
||||
if autofix {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
|
||||
stylist.line_ending().to_string(),
|
||||
range.start(),
|
||||
|
|
|
@ -99,6 +99,7 @@ pub fn not_tests(
|
|||
if check_not_in {
|
||||
let mut diagnostic = Diagnostic::new(NotInTest, operand.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
compare(left, &[Cmpop::NotIn], comparators, checker.stylist),
|
||||
expr.range(),
|
||||
|
@ -111,6 +112,7 @@ pub fn not_tests(
|
|||
if check_not_is {
|
||||
let mut diagnostic = Diagnostic::new(NotIsTest, operand.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
compare(left, &[Cmpop::IsNot], comparators, checker.stylist),
|
||||
expr.range(),
|
||||
|
|
|
@ -95,6 +95,7 @@ pub(crate) fn trailing_whitespace(
|
|||
if matches!(autofix, flags::Autofix::Enabled)
|
||||
&& settings.rules.should_fix(Rule::BlankLineWithWhitespace)
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range)));
|
||||
}
|
||||
return Some(diagnostic);
|
||||
|
@ -104,6 +105,7 @@ pub(crate) fn trailing_whitespace(
|
|||
if matches!(autofix, flags::Autofix::Enabled)
|
||||
&& settings.rules.should_fix(Rule::TrailingWhitespace)
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range)));
|
||||
}
|
||||
return Some(diagnostic);
|
||||
|
|
|
@ -82,6 +82,7 @@ pub fn blank_after_summary(checker: &mut Checker, docstring: &Docstring) {
|
|||
}
|
||||
|
||||
// Insert one blank line after the summary (replacing any existing lines).
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
|
||||
checker.stylist.line_ending().to_string(),
|
||||
summary_end,
|
||||
|
|
|
@ -94,6 +94,7 @@ pub fn blank_before_after_class(checker: &mut Checker, docstring: &Docstring) {
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Delete the blank line before the class.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::deletion(
|
||||
blank_lines_start,
|
||||
docstring.start() - docstring.indentation.text_len(),
|
||||
|
@ -116,6 +117,7 @@ pub fn blank_before_after_class(checker: &mut Checker, docstring: &Docstring) {
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Insert one blank line before the class.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
|
||||
checker.stylist.line_ending().to_string(),
|
||||
blank_lines_start,
|
||||
|
@ -163,6 +165,7 @@ pub fn blank_before_after_class(checker: &mut Checker, docstring: &Docstring) {
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Insert a blank line before the class (replacing any existing lines).
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
|
||||
checker.stylist.line_ending().to_string(),
|
||||
first_line_start,
|
||||
|
|
|
@ -88,6 +88,7 @@ pub fn blank_before_after_function(checker: &mut Checker, docstring: &Docstring)
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Delete the blank line before the docstring.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::deletion(
|
||||
blank_lines_start,
|
||||
docstring.start() - docstring.indentation.text_len(),
|
||||
|
@ -149,6 +150,7 @@ pub fn blank_before_after_function(checker: &mut Checker, docstring: &Docstring)
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Delete the blank line after the docstring.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::deletion(
|
||||
first_line_end,
|
||||
blank_lines_end,
|
||||
|
|
|
@ -71,6 +71,7 @@ pub fn capitalized(checker: &mut Checker, docstring: &Docstring) {
|
|||
);
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
capitalized_word,
|
||||
TextRange::at(body.start(), first_word.text_len()),
|
||||
|
|
|
@ -64,6 +64,7 @@ pub fn ends_with_period(checker: &mut Checker, docstring: &Docstring) {
|
|||
&& !trimmed.ends_with(':')
|
||||
&& !trimmed.ends_with(';')
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
|
||||
".".to_string(),
|
||||
line.start() + trimmed.text_len(),
|
||||
|
|
|
@ -61,6 +61,7 @@ pub fn ends_with_punctuation(checker: &mut Checker, docstring: &Docstring) {
|
|||
let mut diagnostic = Diagnostic::new(EndsInPunctuation, docstring.range());
|
||||
// Best-effort autofix: avoid adding a period after other punctuation marks.
|
||||
if checker.patch(diagnostic.kind.rule()) && !trimmed.ends_with([':', ';']) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
|
||||
".".to_string(),
|
||||
line.start() + trimmed.text_len(),
|
||||
|
|
|
@ -90,6 +90,7 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) {
|
|||
let mut diagnostic =
|
||||
Diagnostic::new(UnderIndentation, TextRange::empty(line.start()));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
whitespace::clean(docstring.indentation),
|
||||
TextRange::at(line.start(), line_indent.text_len()),
|
||||
|
@ -138,6 +139,7 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) {
|
|||
} else {
|
||||
Edit::range_replacement(new_indent, over_indented)
|
||||
};
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(edit));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
@ -151,6 +153,7 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) {
|
|||
let mut diagnostic =
|
||||
Diagnostic::new(OverIndentation, TextRange::empty(last.start()));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
whitespace::clean(docstring.indentation),
|
||||
TextRange::at(last.start(), line_indent.text_len()),
|
||||
|
|
|
@ -67,6 +67,7 @@ pub fn multi_line_summary_start(checker: &mut Checker, docstring: &Docstring) {
|
|||
// Delete until first non-whitespace char.
|
||||
for line in content_lines {
|
||||
if let Some(end_column) = line.find(|c: char| !c.is_whitespace()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::deletion(
|
||||
first_line.end(),
|
||||
line.start() + TextSize::try_from(end_column).unwrap(),
|
||||
|
@ -123,6 +124,7 @@ pub fn multi_line_summary_start(checker: &mut Checker, docstring: &Docstring) {
|
|||
first_line.strip_prefix(prefix).unwrap().trim_start()
|
||||
);
|
||||
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
|
||||
repl,
|
||||
body.start(),
|
||||
|
|
|
@ -56,6 +56,7 @@ pub fn newline_after_last_paragraph(checker: &mut Checker, docstring: &Docstring
|
|||
checker.stylist.line_ending().as_str(),
|
||||
whitespace::clean(docstring.indentation)
|
||||
);
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
|
||||
content,
|
||||
docstring.expr.end() - num_trailing_quotes - num_trailing_spaces,
|
||||
|
|
|
@ -44,6 +44,7 @@ pub fn no_surrounding_whitespace(checker: &mut Checker, docstring: &Docstring) {
|
|||
// characters, avoid applying the fix.
|
||||
if !trimmed.ends_with(quote) && !trimmed.starts_with(quote) && !ends_with_backslash(trimmed)
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
trimmed.to_string(),
|
||||
TextRange::at(body.start(), line.text_len()),
|
||||
|
|
|
@ -49,6 +49,7 @@ pub fn one_liner(checker: &mut Checker, docstring: &Docstring) {
|
|||
if !trimmed.ends_with(trailing.chars().last().unwrap())
|
||||
&& !trimmed.starts_with(leading.chars().last().unwrap())
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
format!("{leading}{trimmed}{trailing}"),
|
||||
docstring.range(),
|
||||
|
|
|
@ -373,6 +373,7 @@ fn blanks_and_section_underline(
|
|||
let range =
|
||||
TextRange::new(context.following_range().start(), blank_lines_end);
|
||||
// Delete any blank lines between the header and the underline.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range)));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
@ -405,6 +406,7 @@ fn blanks_and_section_underline(
|
|||
"-".repeat(context.section_name().len()),
|
||||
checker.stylist.line_ending().as_str()
|
||||
);
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
|
||||
content,
|
||||
blank_lines_end,
|
||||
|
@ -435,6 +437,7 @@ fn blanks_and_section_underline(
|
|||
);
|
||||
|
||||
// Replace the existing indentation with whitespace of the appropriate length.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
whitespace::clean(docstring.indentation),
|
||||
range,
|
||||
|
@ -478,6 +481,7 @@ fn blanks_and_section_underline(
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Delete any blank lines between the header and content.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::deletion(
|
||||
line_after_dashes.start(),
|
||||
blank_lines_after_dashes_end,
|
||||
|
@ -516,6 +520,7 @@ fn blanks_and_section_underline(
|
|||
whitespace::clean(docstring.indentation),
|
||||
"-".repeat(context.section_name().len()),
|
||||
);
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
|
||||
content,
|
||||
context.summary_range().end(),
|
||||
|
@ -539,6 +544,7 @@ fn blanks_and_section_underline(
|
|||
let range =
|
||||
TextRange::new(context.following_range().start(), blank_lines_end);
|
||||
// Delete any blank lines between the header and content.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range)));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
@ -568,6 +574,7 @@ fn blanks_and_section_underline(
|
|||
"-".repeat(context.section_name().len()),
|
||||
);
|
||||
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
|
||||
content,
|
||||
context.summary_range().end(),
|
||||
|
@ -605,6 +612,7 @@ fn common_section(
|
|||
// Replace the section title with the capitalized variant. This requires
|
||||
// locating the start and end of the section name.
|
||||
let section_range = context.section_name_range();
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
capitalized_section_name.to_string(),
|
||||
section_range,
|
||||
|
@ -628,6 +636,7 @@ fn common_section(
|
|||
let content = whitespace::clean(docstring.indentation);
|
||||
let fix_range = TextRange::at(context.range().start(), leading_space.text_len());
|
||||
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(if content.is_empty() {
|
||||
Edit::range_deletion(fix_range)
|
||||
} else {
|
||||
|
@ -655,6 +664,7 @@ fn common_section(
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Add a newline at the beginning of the next section.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
|
||||
line_end.to_string(),
|
||||
next.range().start(),
|
||||
|
@ -676,6 +686,7 @@ fn common_section(
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Add a newline after the section.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
|
||||
format!("{}{}", line_end, docstring.indentation),
|
||||
context.range().end(),
|
||||
|
@ -700,6 +711,7 @@ fn common_section(
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Add a blank line before the section.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
|
||||
line_end.to_string(),
|
||||
context.range().start(),
|
||||
|
@ -902,6 +914,7 @@ fn numpy_section(
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let section_range = context.section_name_range();
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(TextRange::at(
|
||||
section_range.end(),
|
||||
suffix.text_len(),
|
||||
|
@ -939,6 +952,7 @@ fn google_section(
|
|||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Replace the suffix.
|
||||
let section_name_range = context.section_name_range();
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
":".to_string(),
|
||||
TextRange::at(section_name_range.end(), suffix.text_len()),
|
||||
|
|
|
@ -89,6 +89,7 @@ fn fix_f_string_missing_placeholders(
|
|||
checker: &mut Checker,
|
||||
) -> Fix {
|
||||
let content = &checker.locator.contents()[TextRange::new(prefix_range.end(), tok_range.end())];
|
||||
#[allow(deprecated)]
|
||||
Fix::unspecified(Edit::replacement(
|
||||
unescape_f_string(content),
|
||||
prefix_range.start(),
|
||||
|
|
|
@ -78,6 +78,7 @@ pub fn invalid_literal_comparison(
|
|||
None
|
||||
}
|
||||
} {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
content,
|
||||
located_op.range() + location.start(),
|
||||
|
|
|
@ -46,6 +46,7 @@ pub fn raise_not_implemented(checker: &mut Checker, expr: &Expr) {
|
|||
};
|
||||
let mut diagnostic = Diagnostic::new(RaiseNotImplemented, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"NotImplementedError".to_string(),
|
||||
expr.range(),
|
||||
|
|
|
@ -109,6 +109,7 @@ pub fn repeated_keys(checker: &mut Checker, keys: &[Option<Expr>], values: &[Exp
|
|||
);
|
||||
if is_duplicate_value {
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::deletion(
|
||||
values[i - 1].end(),
|
||||
values[i].end(),
|
||||
|
@ -137,6 +138,7 @@ pub fn repeated_keys(checker: &mut Checker, keys: &[Option<Expr>], values: &[Exp
|
|||
);
|
||||
if is_duplicate_value {
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::deletion(
|
||||
values[i - 1].end(),
|
||||
values[i].end(),
|
||||
|
|
|
@ -204,6 +204,7 @@ fn remove_unused_variable(
|
|||
{
|
||||
// If the expression is complex (`x = foo()`), remove the assignment,
|
||||
// but preserve the right-hand side.
|
||||
#[allow(deprecated)]
|
||||
Some((
|
||||
DeletionKind::Partial,
|
||||
Fix::unspecified(Edit::deletion(
|
||||
|
@ -224,6 +225,7 @@ fn remove_unused_variable(
|
|||
checker.indexer,
|
||||
checker.stylist,
|
||||
) {
|
||||
#[allow(deprecated)]
|
||||
Ok(fix) => Some((DeletionKind::Whole, Fix::unspecified(fix))),
|
||||
Err(err) => {
|
||||
error!("Failed to delete unused variable: {}", err);
|
||||
|
@ -246,6 +248,7 @@ fn remove_unused_variable(
|
|||
return if contains_effect(value, |id| checker.ctx.is_builtin(id)) {
|
||||
// If the expression is complex (`x = foo()`), remove the assignment,
|
||||
// but preserve the right-hand side.
|
||||
#[allow(deprecated)]
|
||||
Some((
|
||||
DeletionKind::Partial,
|
||||
Fix::unspecified(Edit::deletion(
|
||||
|
@ -265,6 +268,7 @@ fn remove_unused_variable(
|
|||
checker.indexer,
|
||||
checker.stylist,
|
||||
) {
|
||||
#[allow(deprecated)]
|
||||
Ok(edit) => Some((DeletionKind::Whole, Fix::unspecified(edit))),
|
||||
Err(err) => {
|
||||
error!("Failed to delete unused variable: {}", err);
|
||||
|
@ -282,6 +286,7 @@ fn remove_unused_variable(
|
|||
for item in items {
|
||||
if let Some(optional_vars) = &item.optional_vars {
|
||||
if optional_vars.range() == range {
|
||||
#[allow(deprecated)]
|
||||
return Some((
|
||||
DeletionKind::Partial,
|
||||
Fix::unspecified(Edit::deletion(
|
||||
|
|
|
@ -197,6 +197,7 @@ pub fn invalid_string_characters(
|
|||
|
||||
let mut diagnostic = Diagnostic::new(rule, range);
|
||||
if autofix {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
replacement.to_string(),
|
||||
range,
|
||||
|
|
|
@ -53,6 +53,7 @@ pub fn manual_from_import(checker: &mut Checker, stmt: &Stmt, alias: &Alias, nam
|
|||
alias.range(),
|
||||
);
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_stmt(
|
||||
&create_stmt(StmtKind::ImportFrom {
|
||||
|
|
|
@ -121,6 +121,7 @@ pub fn nested_min_max(
|
|||
keywords: keywords.to_owned(),
|
||||
},
|
||||
);
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(&flattened_expr, checker.stylist),
|
||||
expr.range(),
|
||||
|
|
|
@ -55,6 +55,7 @@ pub fn sys_exit_alias(checker: &mut Checker, func: &Expr) {
|
|||
checker.locator,
|
||||
)?;
|
||||
let reference_edit = Edit::range_replacement(binding, func.range());
|
||||
#[allow(deprecated)]
|
||||
Ok(Fix::unspecified_edits(import_edit, [reference_edit]))
|
||||
});
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ pub fn useless_import_alias(checker: &mut Checker, alias: &Alias) {
|
|||
|
||||
let mut diagnostic = Diagnostic::new(UselessImportAlias, alias.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
asname.to_string(),
|
||||
alias.range(),
|
||||
|
|
|
@ -120,6 +120,7 @@ pub fn useless_return<'a>(
|
|||
if edit.is_deletion() || edit.content() == Some("pass") {
|
||||
checker.deletions.insert(RefEquality(last_stmt));
|
||||
}
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(edit));
|
||||
}
|
||||
Err(e) => {
|
||||
|
|
|
@ -163,6 +163,7 @@ fn convert_to_class(
|
|||
base_class: &Expr,
|
||||
stylist: &Stylist,
|
||||
) -> Fix {
|
||||
#[allow(deprecated)]
|
||||
Fix::unspecified(Edit::range_replacement(
|
||||
unparse_stmt(&create_class_def_stmt(typename, body, base_class), stylist),
|
||||
stmt.range(),
|
||||
|
|
|
@ -210,6 +210,7 @@ fn convert_to_class(
|
|||
base_class: &Expr,
|
||||
stylist: &Stylist,
|
||||
) -> Fix {
|
||||
#[allow(deprecated)]
|
||||
Fix::unspecified(Edit::range_replacement(
|
||||
unparse_stmt(
|
||||
&create_class_def_stmt(class_name, body, total_keyword, base_class),
|
||||
|
|
|
@ -44,6 +44,7 @@ pub fn datetime_utc_alias(checker: &mut Checker, expr: &Expr) {
|
|||
let mut diagnostic = Diagnostic::new(DatetimeTimezoneUTC { straight_import }, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if straight_import {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"datetime.UTC".to_string(),
|
||||
expr.range(),
|
||||
|
|
|
@ -24,6 +24,7 @@ fn add_check_for_node<T>(checker: &mut Checker, node: &Located<T>) {
|
|||
let mut diagnostic = Diagnostic::new(DeprecatedCElementTree, node.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let contents = checker.locator.slice(node.range());
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
contents.replacen("cElementTree", "ElementTree", 1),
|
||||
node.range(),
|
||||
|
|
|
@ -551,6 +551,7 @@ pub fn deprecated_import(
|
|||
);
|
||||
if checker.patch(Rule::DeprecatedImport) {
|
||||
if let Some(content) = fix {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
content,
|
||||
stmt.range(),
|
||||
|
|
|
@ -257,6 +257,7 @@ pub fn deprecated_mock_attribute(checker: &mut Checker, expr: &Expr) {
|
|||
value.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"mock".to_string(),
|
||||
value.range(),
|
||||
|
@ -303,6 +304,7 @@ pub fn deprecated_mock_import(checker: &mut Checker, stmt: &Stmt) {
|
|||
name.range(),
|
||||
);
|
||||
if let Some(content) = content.as_ref() {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
content.clone(),
|
||||
stmt.range(),
|
||||
|
|
|
@ -69,6 +69,7 @@ pub fn deprecated_unittest_alias(checker: &mut Checker, expr: &Expr) {
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
format!("self.{target}"),
|
||||
expr.range(),
|
||||
|
|
|
@ -142,6 +142,7 @@ pub fn extraneous_parentheses(
|
|||
if autofix.into() && settings.rules.should_fix(Rule::ExtraneousParentheses) {
|
||||
let contents =
|
||||
locator.slice(TextRange::new(start_range.start(), end_range.end()));
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
|
||||
contents[1..contents.len() - 1].to_string(),
|
||||
start_range.start(),
|
||||
|
|
|
@ -277,6 +277,7 @@ pub(crate) fn f_strings(checker: &mut Checker, summary: &FormatSummary, expr: &E
|
|||
|
||||
let mut diagnostic = Diagnostic::new(FString, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
contents,
|
||||
expr.range(),
|
||||
|
|
|
@ -145,6 +145,7 @@ pub(crate) fn format_literals(checker: &mut Checker, summary: &FormatSummary, ex
|
|||
if let Ok(contents) =
|
||||
generate_call(expr, &summary.indices, checker.locator, checker.stylist)
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
contents,
|
||||
expr.range(),
|
||||
|
|
|
@ -68,6 +68,7 @@ pub fn lru_cache_with_maxsize_none(checker: &mut Checker, decorator_list: &[Expr
|
|||
checker.locator,
|
||||
)?;
|
||||
let reference_edit = Edit::range_replacement(binding, expr.range());
|
||||
#[allow(deprecated)]
|
||||
Ok(Fix::unspecified_edits(import_edit, [reference_edit]))
|
||||
});
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ pub fn lru_cache_without_parameters(checker: &mut Checker, decorator_list: &[Exp
|
|||
TextRange::new(func.end(), expr.end()),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
unparse_expr(func, checker.stylist),
|
||||
expr.range(),
|
||||
|
|
|
@ -64,6 +64,7 @@ pub fn native_literals(
|
|||
LiteralType::Bytes
|
||||
}}, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
if id == "bytes" {
|
||||
let mut content = String::with_capacity(3);
|
||||
|
@ -127,6 +128,7 @@ pub fn native_literals(
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
arg_code.to_string(),
|
||||
expr.range(),
|
||||
|
|
|
@ -38,6 +38,7 @@ pub fn open_alias(checker: &mut Checker, expr: &Expr, func: &Expr) {
|
|||
.map_or(true, |binding| binding.kind.is_builtin());
|
||||
let mut diagnostic = Diagnostic::new(OpenAlias { fixable }, expr.range());
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"open".to_string(),
|
||||
func.range(),
|
||||
|
|
|
@ -63,6 +63,7 @@ fn atom_diagnostic(checker: &mut Checker, target: &Expr) {
|
|||
target.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"OSError".to_string(),
|
||||
target.range(),
|
||||
|
@ -103,11 +104,13 @@ fn tuple_diagnostic(checker: &mut Checker, target: &Expr, aliases: &[&Expr]) {
|
|||
}
|
||||
|
||||
if remaining.len() == 1 {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"OSError".to_string(),
|
||||
target.range(),
|
||||
)));
|
||||
} else {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
format!(
|
||||
"({})",
|
||||
|
|
|
@ -177,6 +177,7 @@ fn fix_py2_block(
|
|||
) {
|
||||
Ok(edit) => {
|
||||
checker.deletions.insert(RefEquality(defined_by));
|
||||
#[allow(deprecated)]
|
||||
Some(Fix::unspecified(edit))
|
||||
}
|
||||
Err(err) => {
|
||||
|
@ -193,6 +194,7 @@ fn fix_py2_block(
|
|||
|
||||
if indentation(checker.locator, start).is_none() {
|
||||
// Inline `else` block (e.g., `else: x = 1`).
|
||||
#[allow(deprecated)]
|
||||
Some(Fix::unspecified(Edit::range_replacement(
|
||||
checker
|
||||
.locator
|
||||
|
@ -212,6 +214,7 @@ fn fix_py2_block(
|
|||
.ok()
|
||||
})
|
||||
.map(|contents| {
|
||||
#[allow(deprecated)]
|
||||
Fix::unspecified(Edit::replacement(
|
||||
contents,
|
||||
checker.locator.line_start(stmt.start()),
|
||||
|
@ -233,6 +236,7 @@ fn fix_py2_block(
|
|||
end_location = body.last().unwrap().end();
|
||||
}
|
||||
}
|
||||
#[allow(deprecated)]
|
||||
Some(Fix::unspecified(Edit::deletion(stmt.start(), end_location)))
|
||||
}
|
||||
}
|
||||
|
@ -254,6 +258,7 @@ fn fix_py3_block(
|
|||
|
||||
if indentation(checker.locator, start).is_none() {
|
||||
// Inline `if` block (e.g., `if ...: x = 1`).
|
||||
#[allow(deprecated)]
|
||||
Some(Fix::unspecified(Edit::range_replacement(
|
||||
checker
|
||||
.locator
|
||||
|
@ -273,6 +278,7 @@ fn fix_py3_block(
|
|||
.ok()
|
||||
})
|
||||
.map(|contents| {
|
||||
#[allow(deprecated)]
|
||||
Fix::unspecified(Edit::replacement(
|
||||
contents,
|
||||
checker.locator.line_start(stmt.start()),
|
||||
|
@ -286,6 +292,7 @@ fn fix_py3_block(
|
|||
// the rest.
|
||||
let end = body.last().unwrap();
|
||||
let text = checker.locator.slice(TextRange::new(test.end(), end.end()));
|
||||
#[allow(deprecated)]
|
||||
Some(Fix::unspecified(Edit::range_replacement(
|
||||
format!("else{text}"),
|
||||
stmt.range(),
|
||||
|
|
|
@ -444,6 +444,7 @@ pub(crate) fn printf_string_formatting(
|
|||
|
||||
let mut diagnostic = Diagnostic::new(PrintfStringFormatting, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
contents,
|
||||
expr.range(),
|
||||
|
|
|
@ -23,6 +23,7 @@ impl AlwaysAutofixableViolation for QuotedAnnotation {
|
|||
pub fn quoted_annotation(checker: &mut Checker, annotation: &str, range: TextRange) {
|
||||
let mut diagnostic = Diagnostic::new(QuotedAnnotation, range);
|
||||
if checker.patch(Rule::QuotedAnnotation) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
annotation.to_string(),
|
||||
range,
|
||||
|
|
|
@ -116,6 +116,7 @@ fn create_check(
|
|||
);
|
||||
if patch {
|
||||
if let Some(content) = replacement_value {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
content.to_string(),
|
||||
mode_param.range(),
|
||||
|
|
|
@ -38,6 +38,7 @@ fn generate_fix(
|
|||
} else {
|
||||
(stderr, stdout)
|
||||
};
|
||||
#[allow(deprecated)]
|
||||
Ok(Fix::unspecified_edits(
|
||||
Edit::range_replacement("capture_output=True".to_string(), first.range()),
|
||||
[remove_argument(
|
||||
|
|
|
@ -35,6 +35,7 @@ pub fn replace_universal_newlines(checker: &mut Checker, func: &Expr, kwargs: &[
|
|||
let range = TextRange::at(kwarg.start(), "universal_newlines".text_len());
|
||||
let mut diagnostic = Diagnostic::new(ReplaceUniversalNewlines, range);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"text".to_string(),
|
||||
range,
|
||||
|
|
|
@ -97,6 +97,7 @@ pub fn super_call_with_parameters(checker: &mut Checker, expr: &Expr, func: &Exp
|
|||
let mut diagnostic = Diagnostic::new(SuperCallWithParameters, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(edit) = fixes::remove_super_arguments(checker.locator, checker.stylist, expr) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(edit));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ pub fn type_of_primitive(checker: &mut Checker, expr: &Expr, func: &Expr, args:
|
|||
};
|
||||
let mut diagnostic = Diagnostic::new(TypeOfPrimitive { primitive }, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
primitive.builtin(),
|
||||
expr.range(),
|
||||
|
|
|
@ -31,6 +31,7 @@ pub fn typing_text_str_alias(checker: &mut Checker, expr: &Expr) {
|
|||
{
|
||||
let mut diagnostic = Diagnostic::new(TypingTextStrAlias, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
"str".to_string(),
|
||||
expr.range(),
|
||||
|
|
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