mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 11:59:10 +00:00
Rename setter methods on Diagnostic
(#3738)
This commit is contained in:
parent
5c7898124f
commit
a66481ed28
123 changed files with 225 additions and 221 deletions
|
@ -3822,7 +3822,7 @@ where
|
|||
name_range,
|
||||
);
|
||||
if self.patch(Rule::UnusedVariable) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
pyflakes::fixes::remove_exception_handler_assignment(
|
||||
excepthandler,
|
||||
self.locator,
|
||||
|
@ -4055,7 +4055,7 @@ impl<'a> Checker<'a> {
|
|||
if matches!(parent.node, StmtKind::ImportFrom { .. })
|
||||
&& parent.location.row() != binding.range.location.row()
|
||||
{
|
||||
diagnostic.parent(parent.location);
|
||||
diagnostic.set_parent(parent.location);
|
||||
}
|
||||
}
|
||||
self.diagnostics.push(diagnostic);
|
||||
|
@ -4848,7 +4848,7 @@ impl<'a> Checker<'a> {
|
|||
if matches!(parent.node, StmtKind::ImportFrom { .. })
|
||||
&& parent.location.row() != rebound.range.location.row()
|
||||
{
|
||||
diagnostic.parent(parent.location);
|
||||
diagnostic.set_parent(parent.location);
|
||||
}
|
||||
};
|
||||
diagnostics.push(diagnostic);
|
||||
|
@ -5050,10 +5050,10 @@ impl<'a> Checker<'a> {
|
|||
if matches!(child.node, StmtKind::ImportFrom { .. })
|
||||
&& child.location.row() != range.location.row()
|
||||
{
|
||||
diagnostic.parent(child.location);
|
||||
diagnostic.set_parent(child.location);
|
||||
}
|
||||
if let Some(fix) = fix.as_ref() {
|
||||
diagnostic.amend(fix.clone());
|
||||
diagnostic.set_fix(fix.clone());
|
||||
}
|
||||
diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -5084,7 +5084,7 @@ impl<'a> Checker<'a> {
|
|||
if matches!(child.node, StmtKind::ImportFrom { .. })
|
||||
&& child.location.row() != range.location.row()
|
||||
{
|
||||
diagnostic.parent(child.location);
|
||||
diagnostic.set_parent(child.location);
|
||||
}
|
||||
diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ pub fn check_noqa(
|
|||
),
|
||||
);
|
||||
if autofix.into() && settings.rules.should_fix(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(delete_noqa(
|
||||
diagnostic.set_fix(delete_noqa(
|
||||
row,
|
||||
lines[row],
|
||||
leading_spaces,
|
||||
|
@ -214,7 +214,7 @@ pub fn check_noqa(
|
|||
);
|
||||
if autofix.into() && settings.rules.should_fix(diagnostic.kind.rule()) {
|
||||
if valid_codes.is_empty() {
|
||||
diagnostic.amend(delete_noqa(
|
||||
diagnostic.set_fix(delete_noqa(
|
||||
row,
|
||||
lines[row],
|
||||
leading_spaces,
|
||||
|
@ -223,7 +223,7 @@ pub fn check_noqa(
|
|||
trailing_spaces,
|
||||
));
|
||||
} else {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
format!("# noqa: {}", valid_codes.join(", ")),
|
||||
Location::new(row + 1, start_char),
|
||||
Location::new(row + 1, end_char),
|
||||
|
|
|
@ -62,7 +62,7 @@ pub fn commented_out_code(
|
|||
if is_standalone_comment(line) && comment_contains_code(line, &settings.task_tags[..]) {
|
||||
let mut diagnostic = Diagnostic::new(CommentedOutCode, Range::new(start, end));
|
||||
if autofix.into() && settings.rules.should_fix(Rule::CommentedOutCode) {
|
||||
diagnostic.amend(Edit::deletion(location, end_location));
|
||||
diagnostic.set_fix(Edit::deletion(location, end_location));
|
||||
}
|
||||
Some(diagnostic)
|
||||
} else {
|
||||
|
|
|
@ -667,7 +667,7 @@ pub fn definition(
|
|||
helpers::identifier_range(stmt, checker.locator),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::add_return_annotation(checker.locator, stmt, "None")
|
||||
});
|
||||
}
|
||||
|
@ -689,7 +689,7 @@ pub fn definition(
|
|||
let return_type = SIMPLE_MAGIC_RETURN_TYPES.get(name);
|
||||
if let Some(return_type) = return_type {
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::add_return_annotation(checker.locator, stmt, return_type)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ pub fn assert_false(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg: Option
|
|||
|
||||
let mut diagnostic = Diagnostic::new(AssertFalse, Range::from(test));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_stmt(&assertion_error(msg), checker.stylist),
|
||||
stmt.location,
|
||||
stmt.end_location.unwrap(),
|
||||
|
|
|
@ -98,7 +98,7 @@ fn duplicate_handler_exceptions<'a>(
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
if unique_elts.len() == 1 {
|
||||
unparse_expr(unique_elts[0], checker.stylist)
|
||||
} else {
|
||||
|
|
|
@ -65,7 +65,7 @@ pub fn getattr_with_constant(checker: &mut Checker, expr: &Expr, func: &Expr, ar
|
|||
let mut diagnostic = Diagnostic::new(GetAttrWithConstant, Range::from(expr));
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(&attribute(obj, value), checker.stylist),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -48,7 +48,7 @@ pub fn redundant_tuple_in_exception_handler(checker: &mut Checker, handlers: &[E
|
|||
Range::from(type_),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(elt, checker.stylist),
|
||||
type_.location,
|
||||
type_.end_location.unwrap(),
|
||||
|
|
|
@ -80,7 +80,7 @@ pub fn setattr_with_constant(checker: &mut Checker, expr: &Expr, func: &Expr, ar
|
|||
let mut diagnostic = Diagnostic::new(SetAttrWithConstant, Range::from(expr));
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
assignment(obj, name, value, checker.stylist),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -178,7 +178,7 @@ pub fn unused_loop_control_variable(
|
|||
if let Some(binding) = binding {
|
||||
if binding.kind.is_loop_var() {
|
||||
if !binding.used() {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
rename,
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -261,7 +261,7 @@ pub fn trailing_commas(
|
|||
},
|
||||
);
|
||||
if autofix.into() && settings.rules.should_fix(Rule::ProhibitedTrailingComma) {
|
||||
diagnostic.amend(Edit::deletion(comma.0, comma.2));
|
||||
diagnostic.set_fix(Edit::deletion(comma.0, comma.2));
|
||||
}
|
||||
diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -310,7 +310,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(Range::new(missing_comma.0, missing_comma.2));
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
format!("{contents},"),
|
||||
missing_comma.0,
|
||||
missing_comma.2,
|
||||
|
|
|
@ -86,7 +86,7 @@ pub fn unnecessary_call_around_sorted(
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_call_around_sorted(checker.locator, checker.stylist, expr)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ pub fn unnecessary_collection_call(
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_collection_call(checker.locator, checker.stylist, expr)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ fn add_diagnostic(checker: &mut Checker, expr: &Expr) {
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_comprehension(checker.locator, checker.stylist, expr)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ pub fn unnecessary_double_cast_or_process(
|
|||
{
|
||||
let mut diagnostic = create_diagnostic(inner, outer, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_double_cast_or_process(
|
||||
checker.locator,
|
||||
checker.stylist,
|
||||
|
|
|
@ -59,7 +59,7 @@ pub fn unnecessary_generator_dict(
|
|||
ExprKind::Tuple { elts, .. } if elts.len() == 2 => {
|
||||
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorDict, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_generator_dict(
|
||||
checker.locator,
|
||||
checker.stylist,
|
||||
|
|
|
@ -59,7 +59,7 @@ pub fn unnecessary_generator_list(
|
|||
if let ExprKind::GeneratorExp { .. } = argument {
|
||||
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorList, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_generator_list(checker.locator, checker.stylist, expr)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ pub fn unnecessary_generator_set(
|
|||
if let ExprKind::GeneratorExp { .. } = argument {
|
||||
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorSet, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_generator_set(checker.locator, checker.stylist, expr, parent)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -52,8 +52,9 @@ pub fn unnecessary_list_call(checker: &mut Checker, expr: &Expr, func: &Expr, ar
|
|||
}
|
||||
let mut diagnostic = Diagnostic::new(UnnecessaryListCall, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic
|
||||
.try_amend(|| fixes::fix_unnecessary_list_call(checker.locator, checker.stylist, expr));
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_list_call(checker.locator, checker.stylist, expr)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ pub fn unnecessary_list_comprehension_dict(
|
|||
}
|
||||
let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionDict, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_list_comprehension_dict(checker.locator, checker.stylist, expr)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ pub fn unnecessary_list_comprehension_set(
|
|||
if let ExprKind::ListComp { .. } = &argument {
|
||||
let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionSet, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_list_comprehension_set(
|
||||
checker.locator,
|
||||
checker.stylist,
|
||||
|
|
|
@ -80,7 +80,7 @@ pub fn unnecessary_literal_dict(
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_literal_dict(checker.locator, checker.stylist, expr)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ pub fn unnecessary_literal_set(
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_literal_set(checker.locator, checker.stylist, expr)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ pub fn unnecessary_literal_within_list_call(
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_literal_within_list_call(checker.locator, checker.stylist, expr)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ pub fn unnecessary_literal_within_tuple_call(
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_literal_within_tuple_call(checker.locator, checker.stylist, expr)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ pub fn unnecessary_map(
|
|||
if args.len() == 2 && matches!(&args[0].node, ExprKind::Lambda { .. }) {
|
||||
let mut diagnostic = create_diagnostic("generator", Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_map(
|
||||
checker.locator,
|
||||
checker.stylist,
|
||||
|
@ -136,7 +136,7 @@ pub fn unnecessary_map(
|
|||
if let ExprKind::Lambda { .. } = argument {
|
||||
let mut diagnostic = create_diagnostic(id, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_map(
|
||||
checker.locator,
|
||||
checker.stylist,
|
||||
|
@ -166,7 +166,7 @@ pub fn unnecessary_map(
|
|||
{
|
||||
let mut diagnostic = create_diagnostic(id, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_map(
|
||||
checker.locator,
|
||||
checker.stylist,
|
||||
|
|
|
@ -36,7 +36,7 @@ pub fn shebang_whitespace(
|
|||
),
|
||||
);
|
||||
if autofix {
|
||||
diagnostic.amend(Edit::deletion(
|
||||
diagnostic.set_fix(Edit::deletion(
|
||||
Location::new(lineno + 1, 0),
|
||||
Location::new(lineno + 1, *n_spaces),
|
||||
));
|
||||
|
|
|
@ -177,7 +177,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()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"warning".to_string(),
|
||||
level_call_range.location,
|
||||
level_call_range.end_location,
|
||||
|
|
|
@ -184,7 +184,7 @@ pub fn no_unnecessary_pass(checker: &mut Checker, body: &[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(Edit::deletion(
|
||||
diagnostic.set_fix(Edit::deletion(
|
||||
pass_stmt.location,
|
||||
Location::new(
|
||||
pass_stmt.end_location.unwrap().row(),
|
||||
|
@ -192,7 +192,7 @@ pub fn no_unnecessary_pass(checker: &mut Checker, body: &[Stmt]) {
|
|||
),
|
||||
));
|
||||
} else {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
delete_stmt(
|
||||
pass_stmt,
|
||||
None,
|
||||
|
@ -260,7 +260,7 @@ pub fn duplicate_class_field_definition<'a, 'b>(
|
|||
) {
|
||||
Ok(fix) => {
|
||||
checker.deletions.insert(RefEquality(stmt));
|
||||
diagnostic.amend(fix);
|
||||
diagnostic.set_fix(fix);
|
||||
}
|
||||
Err(err) => {
|
||||
error!("Failed to remove duplicate class definition: {}", err);
|
||||
|
@ -348,7 +348,7 @@ pub fn unnecessary_comprehension_any_all(
|
|||
let mut diagnostic =
|
||||
Diagnostic::new(UnnecessaryComprehensionAnyAll, Range::from(&args[0]));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_comprehension_any_all(
|
||||
checker.locator,
|
||||
checker.stylist,
|
||||
|
@ -498,7 +498,7 @@ pub fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) {
|
|||
.collect(),
|
||||
});
|
||||
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(&bool_op, checker.stylist),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
@ -524,7 +524,7 @@ pub fn reimplemented_list_builtin(checker: &mut Checker, expr: &Expr) {
|
|||
if elts.is_empty() {
|
||||
let mut diagnostic = Diagnostic::new(ReimplementedListBuiltin, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"list".to_string(),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -236,7 +236,7 @@ pub fn typed_argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
|
|||
Diagnostic::new(TypedArgumentDefaultInStub, Range::from(default));
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"...".to_string(),
|
||||
default.location,
|
||||
default.end_location.unwrap(),
|
||||
|
@ -263,7 +263,7 @@ pub fn typed_argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
|
|||
Diagnostic::new(TypedArgumentDefaultInStub, Range::from(default));
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"...".to_string(),
|
||||
default.location,
|
||||
default.end_location.unwrap(),
|
||||
|
@ -293,7 +293,7 @@ pub fn argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
|
|||
Diagnostic::new(ArgumentDefaultInStub, Range::from(default));
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"...".to_string(),
|
||||
default.location,
|
||||
default.end_location.unwrap(),
|
||||
|
@ -320,7 +320,7 @@ pub fn argument_simple_defaults(checker: &mut Checker, args: &Arguments) {
|
|||
Diagnostic::new(ArgumentDefaultInStub, Range::from(default));
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"...".to_string(),
|
||||
default.location,
|
||||
default.end_location.unwrap(),
|
||||
|
@ -346,7 +346,7 @@ pub fn assignment_default_in_stub(checker: &mut Checker, value: &Expr, annotatio
|
|||
let mut diagnostic = Diagnostic::new(AssignmentDefaultInStub, Range::from(value));
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"...".to_string(),
|
||||
value.location,
|
||||
value.end_location.unwrap(),
|
||||
|
|
|
@ -206,7 +206,7 @@ pub fn unittest_assertion(
|
|||
);
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
if let Ok(stmt) = unittest_assert.generate_assert(args, keywords) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_stmt(&stmt, checker.stylist),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
@ -436,7 +436,7 @@ pub fn composite_condition(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg:
|
|||
Diagnostic::new(PytestCompositeAssertion { fixable }, Range::from(stmt));
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic
|
||||
.try_amend(|| fix_composite_condition(stmt, checker.locator, checker.stylist));
|
||||
.try_set_fix(|| fix_composite_condition(stmt, checker.locator, checker.stylist));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -248,7 +248,7 @@ fn pytest_fixture_parentheses(
|
|||
Range::from(decorator),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(fix);
|
||||
diagnostic.set_fix(fix);
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E
|
|||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let location = diagnostic.location;
|
||||
let end_location = diagnostic.end_location;
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fix_extraneous_scope_function(
|
||||
checker.locator,
|
||||
decorator.location,
|
||||
|
@ -401,7 +401,7 @@ fn check_fixture_returns(checker: &mut Checker, func: &Stmt, func_name: &str, bo
|
|||
Range::from(stmt),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"return".to_string(),
|
||||
stmt.location,
|
||||
Location::new(
|
||||
|
@ -479,7 +479,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Expr]) {
|
|||
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);
|
||||
diagnostic.amend(Edit::deletion(start, end));
|
||||
diagnostic.set_fix(Edit::deletion(start, end));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -496,7 +496,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Expr]) {
|
|||
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);
|
||||
diagnostic.amend(Edit::deletion(start, end));
|
||||
diagnostic.set_fix(Edit::deletion(start, end));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ fn pytest_mark_parentheses(
|
|||
Range::from(decorator),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(fix);
|
||||
diagnostic.set_fix(fix);
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ fn check_useless_usefixtures(checker: &mut Checker, decorator: &Expr) {
|
|||
Diagnostic::new(PytestUseFixturesWithoutParameters, Range::from(decorator));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let at_start = Location::new(decorator.location.row(), decorator.location.column() - 1);
|
||||
diagnostic.amend(Edit::deletion(at_start, decorator.end_location.unwrap()));
|
||||
diagnostic.set_fix(Edit::deletion(at_start, decorator.end_location.unwrap()));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
format!(
|
||||
"({})",
|
||||
unparse_expr(
|
||||
|
@ -133,7 +133,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::List {
|
||||
elts: names
|
||||
|
@ -175,7 +175,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::List {
|
||||
elts: elts.clone(),
|
||||
|
@ -198,7 +198,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(content) = elts_to_csv(elts, checker) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
content,
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
@ -226,7 +226,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
format!(
|
||||
"({})",
|
||||
unparse_expr(
|
||||
|
@ -252,7 +252,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(content) = elts_to_csv(elts, checker) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
content,
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
@ -329,7 +329,7 @@ fn handle_single_name(checker: &mut Checker, expr: &Expr, value: &Expr) {
|
|||
);
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(&create_expr(value.node.clone()), checker.stylist),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -291,7 +291,7 @@ fn docstring(
|
|||
fixed_contents.push_str("e);
|
||||
fixed_contents.push_str(string_contents);
|
||||
fixed_contents.push_str("e);
|
||||
diagnostic.amend(Edit::replacement(fixed_contents, start, end));
|
||||
diagnostic.set_fix(Edit::replacement(fixed_contents, start, end));
|
||||
}
|
||||
Some(diagnostic)
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ fn strings(
|
|||
fixed_contents.push_str(quote);
|
||||
fixed_contents.push_str(string_contents);
|
||||
fixed_contents.push_str(quote);
|
||||
diagnostic.amend(Edit::replacement(fixed_contents, *start, *end));
|
||||
diagnostic.set_fix(Edit::replacement(fixed_contents, *start, *end));
|
||||
}
|
||||
diagnostics.push(diagnostic);
|
||||
} else {
|
||||
|
@ -430,7 +430,7 @@ fn strings(
|
|||
|
||||
fixed_contents.push(quote);
|
||||
|
||||
diagnostic.amend(Edit::replacement(fixed_contents, *start, *end));
|
||||
diagnostic.set_fix(Edit::replacement(fixed_contents, *start, *end));
|
||||
}
|
||||
diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -453,7 +453,7 @@ fn strings(
|
|||
fixed_contents.push(quote);
|
||||
fixed_contents.push_str(string_contents);
|
||||
fixed_contents.push(quote);
|
||||
diagnostic.amend(Edit::replacement(fixed_contents, *start, *end));
|
||||
diagnostic.set_fix(Edit::replacement(fixed_contents, *start, *end));
|
||||
}
|
||||
diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -34,7 +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()) {
|
||||
diagnostic.amend(Edit::deletion(
|
||||
diagnostic.set_fix(Edit::deletion(
|
||||
func.end_location.unwrap(),
|
||||
range.end_location,
|
||||
));
|
||||
|
|
|
@ -140,7 +140,7 @@ fn unnecessary_return_none(checker: &mut Checker, stack: &Stack) {
|
|||
}
|
||||
let mut diagnostic = Diagnostic::new(UnnecessaryReturnNone, Range::from(*stmt));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"return".to_string(),
|
||||
stmt.location,
|
||||
stmt.end_location.unwrap(),
|
||||
|
@ -158,7 +158,7 @@ fn implicit_return_value(checker: &mut Checker, stack: &Stack) {
|
|||
}
|
||||
let mut diagnostic = Diagnostic::new(ImplicitReturnValue, Range::from(*stmt));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"return None".to_string(),
|
||||
stmt.location,
|
||||
stmt.end_location.unwrap(),
|
||||
|
@ -220,7 +220,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");
|
||||
diagnostic.amend(Edit::insertion(
|
||||
diagnostic.set_fix(Edit::insertion(
|
||||
content,
|
||||
end_of_statement(stmt, checker.locator),
|
||||
));
|
||||
|
@ -258,7 +258,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");
|
||||
diagnostic.amend(Edit::insertion(
|
||||
diagnostic.set_fix(Edit::insertion(
|
||||
content,
|
||||
end_of_statement(stmt, checker.locator),
|
||||
));
|
||||
|
@ -297,7 +297,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");
|
||||
diagnostic.amend(Edit::insertion(
|
||||
diagnostic.set_fix(Edit::insertion(
|
||||
content,
|
||||
end_of_statement(stmt, checker.locator),
|
||||
));
|
||||
|
|
|
@ -254,7 +254,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.
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(&bool_op, checker.stylist),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
@ -357,7 +357,7 @@ pub fn compare_with_tuple(checker: &mut Checker, expr: &Expr) {
|
|||
values: iter::once(in_expr).chain(unmatched).collect(),
|
||||
})
|
||||
};
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(&in_expr, checker.stylist),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
@ -409,7 +409,7 @@ pub fn expr_and_not_expr(checker: &mut Checker, expr: &Expr) {
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"False".to_string(),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
@ -463,7 +463,7 @@ pub fn expr_or_not_expr(checker: &mut Checker, expr: &Expr) {
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"True".to_string(),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
@ -491,7 +491,7 @@ pub fn expr_or_true(checker: &mut Checker, expr: &Expr) {
|
|||
{
|
||||
let mut diagnostic = Diagnostic::new(ExprOrTrue, Range::from(value));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"True".to_string(),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
@ -518,7 +518,7 @@ pub fn expr_and_false(checker: &mut Checker, expr: &Expr) {
|
|||
{
|
||||
let mut diagnostic = Diagnostic::new(ExprAndFalse, Range::from(value));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"False".to_string(),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -73,7 +73,7 @@ pub fn use_capital_environment_variables(checker: &mut Checker, expr: &Expr) {
|
|||
value: capital_env_var.into(),
|
||||
kind: kind.clone(),
|
||||
});
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(&new_env_var, checker.stylist),
|
||||
arg.location,
|
||||
arg.end_location.unwrap(),
|
||||
|
@ -115,7 +115,7 @@ fn check_os_environ_subscript(checker: &mut Checker, expr: &Expr) {
|
|||
value: capital_env_var.into(),
|
||||
kind: kind.clone(),
|
||||
});
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(&new_env_var, checker.stylist),
|
||||
slice.location,
|
||||
slice.end_location.unwrap(),
|
||||
|
|
|
@ -290,7 +290,7 @@ pub fn nested_if_statements(
|
|||
.universal_newlines()
|
||||
.all(|line| line.width() <= checker.settings.line_length)
|
||||
{
|
||||
diagnostic.amend(fix);
|
||||
diagnostic.set_fix(fix);
|
||||
}
|
||||
}
|
||||
Err(err) => error!("Failed to fix nested if: {err}"),
|
||||
|
@ -356,7 +356,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.
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_stmt(
|
||||
&create_stmt(StmtKind::Return {
|
||||
value: Some(test.clone()),
|
||||
|
@ -369,7 +369,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.)
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_stmt(
|
||||
&create_stmt(StmtKind::Return {
|
||||
value: Some(Box::new(create_expr(ExprKind::Call {
|
||||
|
@ -504,7 +504,7 @@ pub fn use_ternary_operator(checker: &mut Checker, stmt: &Stmt, parent: Option<&
|
|||
Range::from(stmt),
|
||||
);
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
contents,
|
||||
stmt.location,
|
||||
stmt.end_location.unwrap(),
|
||||
|
@ -853,7 +853,7 @@ pub fn use_dict_get_with_default(
|
|||
Range::from(stmt),
|
||||
);
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
contents,
|
||||
stmt.location,
|
||||
stmt.end_location.unwrap(),
|
||||
|
|
|
@ -101,13 +101,13 @@ pub fn explicit_true_false_in_ifexpr(
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if matches!(test.node, ExprKind::Compare { .. }) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(&test.clone(), checker.stylist),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
));
|
||||
} else if checker.ctx.is_builtin("bool") {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::Call {
|
||||
func: Box::new(create_expr(ExprKind::Name {
|
||||
|
@ -155,7 +155,7 @@ pub fn explicit_false_true_in_ifexpr(
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::UnaryOp {
|
||||
op: Unaryop::Not,
|
||||
|
@ -204,7 +204,7 @@ pub fn twisted_arms_in_ifexpr(
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::IfExp {
|
||||
test: Box::new(create_expr(orelse.node.clone())),
|
||||
|
|
|
@ -108,7 +108,7 @@ pub fn negation_with_equal_op(checker: &mut Checker, expr: &Expr, op: &Unaryop,
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::Compare {
|
||||
left: left.clone(),
|
||||
|
@ -159,7 +159,7 @@ pub fn negation_with_not_equal_op(
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::Compare {
|
||||
left: left.clone(),
|
||||
|
@ -194,7 +194,7 @@ pub fn double_negation(checker: &mut Checker, expr: &Expr, op: &Unaryop, operand
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(operand, checker.stylist),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -120,7 +120,7 @@ pub fn multiple_with_statements(
|
|||
.universal_newlines()
|
||||
.all(|line| line.width() <= checker.settings.line_length)
|
||||
{
|
||||
diagnostic.amend(fix);
|
||||
diagnostic.set_fix(fix);
|
||||
}
|
||||
}
|
||||
Err(err) => error!("Failed to fix nested with: {err}"),
|
||||
|
|
|
@ -91,7 +91,7 @@ fn key_in_dict(checker: &mut Checker, left: &Expr, right: &Expr, range: Range) {
|
|||
range,
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
value_content,
|
||||
right.location,
|
||||
right.end_location.unwrap(),
|
||||
|
|
|
@ -223,7 +223,7 @@ pub fn convert_for_loop_to_any_all(checker: &mut Checker, stmt: &Stmt, sibling:
|
|||
Range::from(stmt),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) && checker.ctx.is_builtin("any") {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
contents,
|
||||
stmt.location,
|
||||
loop_info.terminal,
|
||||
|
@ -300,7 +300,7 @@ pub fn convert_for_loop_to_any_all(checker: &mut Checker, stmt: &Stmt, sibling:
|
|||
Range::from(stmt),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) && checker.ctx.is_builtin("all") {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
contents,
|
||||
stmt.location,
|
||||
loop_info.terminal,
|
||||
|
|
|
@ -162,7 +162,7 @@ pub fn yoda_conditions(
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
suggestion,
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -174,7 +174,7 @@ pub fn banned_relative_import(
|
|||
if let Some(fix) =
|
||||
fix_banned_relative_import(stmt, level, module, module_path, checker.stylist)
|
||||
{
|
||||
diagnostic.amend(fix);
|
||||
diagnostic.set_fix(fix);
|
||||
};
|
||||
}
|
||||
Some(diagnostic)
|
||||
|
|
|
@ -54,7 +54,7 @@ pub fn empty_type_checking_block<'a, 'b>(
|
|||
if fix.content.is_empty() || fix.content == "pass" {
|
||||
checker.deletions.insert(RefEquality(stmt));
|
||||
}
|
||||
diagnostic.amend(fix);
|
||||
diagnostic.set_fix(fix);
|
||||
}
|
||||
Err(e) => error!("Failed to remove empty type-checking block: {e}"),
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ fn add_required_import(
|
|||
}
|
||||
|
||||
// Construct the fix.
|
||||
diagnostic.amend(Edit::insertion(contents, splice));
|
||||
diagnostic.set_fix(Edit::insertion(contents, splice));
|
||||
}
|
||||
Some(diagnostic)
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ pub fn organize_imports(
|
|||
} else {
|
||||
let mut diagnostic = Diagnostic::new(UnsortedImports, range);
|
||||
if autofix.into() && settings.rules.should_fix(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
indent(&expected, indentation),
|
||||
range.location,
|
||||
range.end_location,
|
||||
|
|
|
@ -71,7 +71,7 @@ pub fn deprecated_type_alias(checker: &mut Checker, expr: &Expr) {
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
match type_name {
|
||||
"unicode" => "str",
|
||||
"long" => "int",
|
||||
|
|
|
@ -76,7 +76,7 @@ pub fn inplace_argument(
|
|||
args,
|
||||
keywords,
|
||||
) {
|
||||
diagnostic.amend(fix);
|
||||
diagnostic.set_fix(fix);
|
||||
}
|
||||
}
|
||||
return Some(diagnostic);
|
||||
|
|
|
@ -163,7 +163,7 @@ pub fn compound_statements(
|
|||
if let Some((start, end)) = semi {
|
||||
let mut diagnostic = Diagnostic::new(UselessSemicolon, Range::new(start, end));
|
||||
if autofix.into() && settings.rules.should_fix(Rule::UselessSemicolon) {
|
||||
diagnostic.amend(Edit::deletion(start, end));
|
||||
diagnostic.set_fix(Edit::deletion(start, end));
|
||||
};
|
||||
diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ pub fn invalid_escape_sequence(
|
|||
Range::new(location, end_location),
|
||||
);
|
||||
if autofix {
|
||||
diagnostic.amend(Edit::insertion(
|
||||
diagnostic.set_fix(Edit::insertion(
|
||||
r"\".to_string(),
|
||||
Location::new(location.row(), location.column() + 1),
|
||||
));
|
||||
|
|
|
@ -99,7 +99,7 @@ pub fn lambda_assignment(checker: &mut Checker, target: &Expr, value: &Expr, stm
|
|||
indented.push_str(line);
|
||||
}
|
||||
}
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
indented,
|
||||
stmt.location,
|
||||
stmt.end_location.unwrap(),
|
||||
|
|
|
@ -273,7 +273,7 @@ pub fn literal_comparisons(
|
|||
.collect::<Vec<_>>();
|
||||
let content = compare(left, &ops, comparators, checker.stylist);
|
||||
for diagnostic in &mut diagnostics {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
content.to_string(),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -51,7 +51,7 @@ pub fn no_newline_at_end_of_file(
|
|||
let mut diagnostic =
|
||||
Diagnostic::new(MissingNewlineAtEndOfFile, Range::new(location, location));
|
||||
if autofix {
|
||||
diagnostic.amend(Edit::insertion(stylist.line_ending().to_string(), location));
|
||||
diagnostic.set_fix(Edit::insertion(stylist.line_ending().to_string(), location));
|
||||
}
|
||||
return Some(diagnostic);
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ pub fn missing_whitespace(
|
|||
);
|
||||
|
||||
if autofix {
|
||||
diagnostic.amend(Edit::insertion(
|
||||
diagnostic.set_fix(Edit::insertion(
|
||||
" ".to_string(),
|
||||
Location::new(row, indent_level + idx + 1),
|
||||
));
|
||||
|
|
|
@ -98,7 +98,7 @@ pub fn not_tests(
|
|||
if check_not_in {
|
||||
let mut diagnostic = Diagnostic::new(NotInTest, Range::from(operand));
|
||||
if checker.patch(diagnostic.kind.rule()) && should_fix {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
compare(left, &[Cmpop::NotIn], comparators, checker.stylist),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
@ -111,7 +111,7 @@ pub fn not_tests(
|
|||
if check_not_is {
|
||||
let mut diagnostic = Diagnostic::new(NotIsTest, Range::from(operand));
|
||||
if checker.patch(diagnostic.kind.rule()) && should_fix {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
compare(left, &[Cmpop::IsNot], comparators, checker.stylist),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -94,7 +94,7 @@ pub fn trailing_whitespace(
|
|||
if matches!(autofix, flags::Autofix::Enabled)
|
||||
&& settings.rules.should_fix(Rule::BlankLineWithWhitespace)
|
||||
{
|
||||
diagnostic.amend(Edit::deletion(start, end));
|
||||
diagnostic.set_fix(Edit::deletion(start, end));
|
||||
}
|
||||
return Some(diagnostic);
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ pub fn trailing_whitespace(
|
|||
if matches!(autofix, flags::Autofix::Enabled)
|
||||
&& settings.rules.should_fix(Rule::TrailingWhitespace)
|
||||
{
|
||||
diagnostic.amend(Edit::deletion(start, end));
|
||||
diagnostic.set_fix(Edit::deletion(start, end));
|
||||
}
|
||||
return Some(diagnostic);
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ pub fn whitespace_before_parameters(
|
|||
let mut diagnostic = Diagnostic::new(kind, Range::new(start, end));
|
||||
|
||||
if autofix {
|
||||
diagnostic.amend(Edit::deletion(start, end));
|
||||
diagnostic.set_fix(Edit::deletion(start, end));
|
||||
}
|
||||
diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ pub fn blank_after_summary(checker: &mut Checker, docstring: &Docstring) {
|
|||
}
|
||||
|
||||
// Insert one blank line after the summary (replacing any existing lines).
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
checker.stylist.line_ending().to_string(),
|
||||
Location::new(docstring.expr.location.row() + summary_line + 1, 0),
|
||||
Location::new(
|
||||
|
|
|
@ -88,7 +88,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.
|
||||
diagnostic.amend(Edit::deletion(
|
||||
diagnostic.set_fix(Edit::deletion(
|
||||
Location::new(docstring.expr.location.row() - blank_lines_before, 0),
|
||||
Location::new(docstring.expr.location.row(), 0),
|
||||
));
|
||||
|
@ -110,7 +110,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.
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
checker.stylist.line_ending().to_string(),
|
||||
Location::new(docstring.expr.location.row() - blank_lines_before, 0),
|
||||
Location::new(docstring.expr.location.row(), 0),
|
||||
|
@ -149,7 +149,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).
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
checker.stylist.line_ending().to_string(),
|
||||
Location::new(docstring.expr.end_location.unwrap().row() + 1, 0),
|
||||
Location::new(
|
||||
|
|
|
@ -82,7 +82,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.
|
||||
diagnostic.amend(Edit::deletion(
|
||||
diagnostic.set_fix(Edit::deletion(
|
||||
Location::new(docstring.expr.location.row() - blank_lines_before, 0),
|
||||
Location::new(docstring.expr.location.row(), 0),
|
||||
));
|
||||
|
@ -137,7 +137,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.
|
||||
diagnostic.amend(Edit::deletion(
|
||||
diagnostic.set_fix(Edit::deletion(
|
||||
Location::new(docstring.expr.end_location.unwrap().row() + 1, 0),
|
||||
Location::new(
|
||||
docstring.expr.end_location.unwrap().row() + 1 + blank_lines_after,
|
||||
|
|
|
@ -73,7 +73,7 @@ pub fn capitalized(checker: &mut Checker, docstring: &Docstring) {
|
|||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(pattern) = leading_quote(docstring.contents) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
capitalized_word,
|
||||
docstring.expr.location.with_col_offset(pattern.width()),
|
||||
docstring
|
||||
|
|
|
@ -81,7 +81,8 @@ pub fn ends_with_period(checker: &mut Checker, docstring: &Docstring) {
|
|||
trimmed.chars().count(),
|
||||
))
|
||||
} {
|
||||
diagnostic.amend(Edit::insertion(".".to_string(), Location::new(row, column)));
|
||||
diagnostic
|
||||
.set_fix(Edit::insertion(".".to_string(), Location::new(row, column)));
|
||||
}
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -80,7 +80,8 @@ pub fn ends_with_punctuation(checker: &mut Checker, docstring: &Docstring) {
|
|||
trimmed.chars().count(),
|
||||
))
|
||||
} {
|
||||
diagnostic.amend(Edit::insertion(".".to_string(), Location::new(row, column)));
|
||||
diagnostic
|
||||
.set_fix(Edit::insertion(".".to_string(), Location::new(row, column)));
|
||||
}
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -94,7 +94,7 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) {
|
|||
),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
whitespace::clean(docstring.indentation),
|
||||
Location::new(docstring.expr.location.row() + i, 0),
|
||||
Location::new(docstring.expr.location.row() + i, line_indent.len()),
|
||||
|
@ -144,7 +144,7 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) {
|
|||
),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
whitespace::clean(docstring.indentation),
|
||||
Location::new(docstring.expr.location.row() + i, 0),
|
||||
Location::new(docstring.expr.location.row() + i, line_indent.len()),
|
||||
|
@ -168,7 +168,7 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) {
|
|||
),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
whitespace::clean(docstring.indentation),
|
||||
Location::new(docstring.expr.location.row() + i, 0),
|
||||
Location::new(docstring.expr.location.row() + i, line_indent.len()),
|
||||
|
|
|
@ -69,7 +69,7 @@ pub fn multi_line_summary_start(checker: &mut Checker, docstring: &Docstring) {
|
|||
let start =
|
||||
Location::new(location.row(), location.column() + first_line.len());
|
||||
let end = Location::new(end_row, end_column);
|
||||
diagnostic.amend(Edit::deletion(start, end));
|
||||
diagnostic.set_fix(Edit::deletion(start, end));
|
||||
break;
|
||||
}
|
||||
end_row += 1;
|
||||
|
@ -123,7 +123,7 @@ pub fn multi_line_summary_start(checker: &mut Checker, docstring: &Docstring) {
|
|||
indentation,
|
||||
first_line.strip_prefix(prefix).unwrap().trim_start()
|
||||
);
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
repl,
|
||||
Location::new(location.row(), location.column() + prefix.len()),
|
||||
Location::new(location.row(), location.column() + first_line.len()),
|
||||
|
|
|
@ -52,7 +52,7 @@ pub fn newline_after_last_paragraph(checker: &mut Checker, docstring: &Docstring
|
|||
checker.stylist.line_ending().as_str(),
|
||||
whitespace::clean(docstring.indentation)
|
||||
);
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
content,
|
||||
Location::new(
|
||||
docstring.expr.end_location.unwrap().row(),
|
||||
|
|
|
@ -49,7 +49,7 @@ pub fn no_surrounding_whitespace(checker: &mut Checker, docstring: &Docstring) {
|
|||
&& !trimmed.starts_with(pattern.chars().last().unwrap())
|
||||
&& !ends_with_backslash(trimmed)
|
||||
{
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
trimmed.to_string(),
|
||||
Location::new(
|
||||
docstring.expr.location.row(),
|
||||
|
|
|
@ -49,7 +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())
|
||||
{
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
format!("{leading}{trimmed}{trailing}"),
|
||||
docstring.expr.location,
|
||||
docstring.expr.end_location.unwrap(),
|
||||
|
|
|
@ -369,7 +369,7 @@ fn blanks_and_section_underline(
|
|||
whitespace::clean(docstring.indentation),
|
||||
"-".repeat(context.section_name.len()),
|
||||
);
|
||||
diagnostic.amend(Edit::insertion(
|
||||
diagnostic.set_fix(Edit::insertion(
|
||||
content,
|
||||
Location::new(
|
||||
docstring.expr.location.row() + context.original_index,
|
||||
|
@ -410,7 +410,7 @@ fn blanks_and_section_underline(
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Delete any blank lines between the header and the underline.
|
||||
diagnostic.amend(Edit::deletion(
|
||||
diagnostic.set_fix(Edit::deletion(
|
||||
Location::new(
|
||||
docstring.expr.location.row() + context.original_index + 1,
|
||||
0,
|
||||
|
@ -454,7 +454,7 @@ fn blanks_and_section_underline(
|
|||
"-".repeat(context.section_name.len()),
|
||||
checker.stylist.line_ending().as_str()
|
||||
);
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
content,
|
||||
Location::new(
|
||||
docstring.expr.location.row()
|
||||
|
@ -492,7 +492,7 @@ fn blanks_and_section_underline(
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Replace the existing indentation with whitespace of the appropriate length.
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
whitespace::clean(docstring.indentation),
|
||||
Location::new(
|
||||
docstring.expr.location.row()
|
||||
|
@ -547,7 +547,7 @@ fn blanks_and_section_underline(
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Delete any blank lines between the header and content.
|
||||
diagnostic.amend(Edit::deletion(
|
||||
diagnostic.set_fix(Edit::deletion(
|
||||
Location::new(
|
||||
docstring.expr.location.row()
|
||||
+ context.original_index
|
||||
|
@ -599,7 +599,7 @@ fn blanks_and_section_underline(
|
|||
whitespace::clean(docstring.indentation),
|
||||
"-".repeat(context.section_name.len()),
|
||||
);
|
||||
diagnostic.amend(Edit::insertion(
|
||||
diagnostic.set_fix(Edit::insertion(
|
||||
content,
|
||||
Location::new(
|
||||
docstring.expr.location.row() + context.original_index,
|
||||
|
@ -623,7 +623,7 @@ fn blanks_and_section_underline(
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Delete any blank lines between the header and content.
|
||||
diagnostic.amend(Edit::deletion(
|
||||
diagnostic.set_fix(Edit::deletion(
|
||||
Location::new(
|
||||
docstring.expr.location.row() + context.original_index + 1,
|
||||
0,
|
||||
|
@ -660,7 +660,7 @@ fn common_section(checker: &mut Checker, docstring: &Docstring, context: &Sectio
|
|||
// Map from bytes to characters.
|
||||
let section_name_start = &context.line[..index].chars().count();
|
||||
let section_name_length = &context.section_name.chars().count();
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
capitalized_section_name.to_string(),
|
||||
Location::new(
|
||||
docstring.expr.location.row() + context.original_index,
|
||||
|
@ -688,7 +688,7 @@ fn common_section(checker: &mut Checker, docstring: &Docstring, context: &Sectio
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Replace the existing indentation with whitespace of the appropriate length.
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
whitespace::clean(docstring.indentation),
|
||||
Location::new(docstring.expr.location.row() + context.original_index, 0),
|
||||
Location::new(
|
||||
|
@ -722,7 +722,7 @@ fn common_section(checker: &mut Checker, docstring: &Docstring, context: &Sectio
|
|||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Add a newline after the section.
|
||||
let line = context.following_lines.last().unwrap_or(&context.line);
|
||||
diagnostic.amend(Edit::insertion(
|
||||
diagnostic.set_fix(Edit::insertion(
|
||||
format!("{}{}", line_end, docstring.indentation),
|
||||
Location::new(
|
||||
docstring.expr.location.row()
|
||||
|
@ -749,7 +749,7 @@ fn common_section(checker: &mut Checker, docstring: &Docstring, context: &Sectio
|
|||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Add a newline after the section.
|
||||
let line = context.following_lines.last().unwrap_or(&context.line);
|
||||
diagnostic.amend(Edit::insertion(
|
||||
diagnostic.set_fix(Edit::insertion(
|
||||
line_end.to_string(),
|
||||
Location::new(
|
||||
docstring.expr.location.row()
|
||||
|
@ -778,7 +778,7 @@ fn common_section(checker: &mut Checker, docstring: &Docstring, context: &Sectio
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Add a blank line before the section.
|
||||
diagnostic.amend(Edit::insertion(
|
||||
diagnostic.set_fix(Edit::insertion(
|
||||
line_end.to_string(),
|
||||
Location::new(docstring.expr.location.row() + context.original_index, 0),
|
||||
));
|
||||
|
@ -981,7 +981,7 @@ fn numpy_section(checker: &mut Checker, docstring: &Docstring, context: &Section
|
|||
.chars()
|
||||
.count();
|
||||
let suffix_length = suffix.chars().count();
|
||||
diagnostic.amend(Edit::deletion(
|
||||
diagnostic.set_fix(Edit::deletion(
|
||||
Location::new(
|
||||
docstring.expr.location.row() + context.original_index,
|
||||
*suffix_start,
|
||||
|
@ -1028,7 +1028,7 @@ fn google_section(checker: &mut Checker, docstring: &Docstring, context: &Sectio
|
|||
.chars()
|
||||
.count();
|
||||
let suffix_length = suffix.chars().count();
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
":".to_string(),
|
||||
Location::new(
|
||||
docstring.expr.location.row() + context.original_index,
|
||||
|
|
|
@ -76,7 +76,7 @@ pub fn f_string_missing_placeholders(expr: &Expr, values: &[Expr], checker: &mut
|
|||
for (prefix_range, tok_range) in find_useless_f_strings(expr, checker.locator) {
|
||||
let mut diagnostic = Diagnostic::new(FStringMissingPlaceholders, tok_range);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(fix_f_string_missing_placeholders(
|
||||
diagnostic.set_fix(fix_f_string_missing_placeholders(
|
||||
&prefix_range,
|
||||
&tok_range,
|
||||
checker,
|
||||
|
|
|
@ -79,7 +79,7 @@ pub fn invalid_literal_comparison(
|
|||
None
|
||||
}
|
||||
} {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
content,
|
||||
helpers::to_absolute(located_op.location, location.location),
|
||||
helpers::to_absolute(
|
||||
|
|
|
@ -47,7 +47,7 @@ pub fn raise_not_implemented(checker: &mut Checker, expr: &Expr) {
|
|||
};
|
||||
let mut diagnostic = Diagnostic::new(RaiseNotImplemented, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"NotImplementedError".to_string(),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -110,7 +110,7 @@ pub fn repeated_keys(checker: &mut Checker, keys: &[Option<Expr>], values: &[Exp
|
|||
);
|
||||
if is_duplicate_value {
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::deletion(
|
||||
diagnostic.set_fix(Edit::deletion(
|
||||
values[i - 1].end_location.unwrap(),
|
||||
values[i].end_location.unwrap(),
|
||||
));
|
||||
|
@ -138,7 +138,7 @@ pub fn repeated_keys(checker: &mut Checker, keys: &[Option<Expr>], values: &[Exp
|
|||
);
|
||||
if is_duplicate_value {
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::deletion(
|
||||
diagnostic.set_fix(Edit::deletion(
|
||||
values[i - 1].end_location.unwrap(),
|
||||
values[i].end_location.unwrap(),
|
||||
));
|
||||
|
|
|
@ -311,7 +311,7 @@ pub(crate) fn percent_format_extra_named_arguments(
|
|||
location,
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
remove_unused_format_arguments_from_dict(
|
||||
&missing,
|
||||
right,
|
||||
|
@ -474,7 +474,7 @@ pub(crate) fn string_dot_format_extra_named_arguments(
|
|||
location,
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
remove_unused_keyword_arguments_from_format_call(
|
||||
&missing,
|
||||
location,
|
||||
|
@ -515,7 +515,7 @@ pub(crate) fn string_dot_format_extra_positional_arguments(
|
|||
location,
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
remove_unused_positional_arguments_from_format_call(
|
||||
&missing,
|
||||
location,
|
||||
|
|
|
@ -343,7 +343,7 @@ pub fn unused_variable(checker: &mut Checker, scope: ScopeId) {
|
|||
if matches!(kind, DeletionKind::Whole) {
|
||||
checker.deletions.insert(RefEquality(stmt));
|
||||
}
|
||||
diagnostic.amend(fix);
|
||||
diagnostic.set_fix(fix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ pub fn invalid_string_characters(
|
|||
let end_location = Location::new(location.row(), location.column() + 1);
|
||||
let mut diagnostic = Diagnostic::new(rule, Range::new(location, end_location));
|
||||
if autofix {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
replacement.to_string(),
|
||||
location,
|
||||
end_location,
|
||||
|
|
|
@ -54,7 +54,7 @@ pub fn manual_from_import(checker: &mut Checker, stmt: &Stmt, alias: &Alias, nam
|
|||
Range::from(alias),
|
||||
);
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_stmt(
|
||||
&create_stmt(StmtKind::ImportFrom {
|
||||
module: Some(module.to_string()),
|
||||
|
|
|
@ -122,7 +122,7 @@ pub fn sys_exit_alias(checker: &mut Checker, func: &Expr) {
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(content) = get_member_import_name_alias(checker, "sys", "exit") {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
content,
|
||||
func.location,
|
||||
func.end_location.unwrap(),
|
||||
|
|
|
@ -35,7 +35,7 @@ pub fn useless_import_alias(checker: &mut Checker, alias: &Alias) {
|
|||
|
||||
let mut diagnostic = Diagnostic::new(UselessImportAlias, Range::from(alias));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
asname.to_string(),
|
||||
alias.location,
|
||||
alias.end_location.unwrap(),
|
||||
|
|
|
@ -120,7 +120,7 @@ pub fn useless_return<'a>(
|
|||
if fix.content.is_empty() || fix.content == "pass" {
|
||||
checker.deletions.insert(RefEquality(last_stmt));
|
||||
}
|
||||
diagnostic.amend(fix);
|
||||
diagnostic.set_fix(fix);
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to delete `return` statement: {}", e);
|
||||
|
|
|
@ -204,7 +204,7 @@ pub fn convert_named_tuple_functional_to_class(
|
|||
Range::from(stmt),
|
||||
);
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(convert_to_class(
|
||||
diagnostic.set_fix(convert_to_class(
|
||||
stmt,
|
||||
typename,
|
||||
properties,
|
||||
|
|
|
@ -252,7 +252,7 @@ pub fn convert_typed_dict_functional_to_class(
|
|||
Range::from(stmt),
|
||||
);
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(convert_to_class(
|
||||
diagnostic.set_fix(convert_to_class(
|
||||
stmt,
|
||||
class_name,
|
||||
body,
|
||||
|
|
|
@ -44,7 +44,7 @@ pub fn datetime_utc_alias(checker: &mut Checker, expr: &Expr) {
|
|||
Diagnostic::new(DatetimeTimezoneUTC { straight_import }, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if straight_import {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"datetime.UTC".to_string(),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -25,7 +25,7 @@ fn add_check_for_node<T>(checker: &mut Checker, node: &Located<T>) {
|
|||
let mut diagnostic = Diagnostic::new(DeprecatedCElementTree, Range::from(node));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let contents = checker.locator.slice(node);
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
contents.replacen("cElementTree", "ElementTree", 1),
|
||||
node.location,
|
||||
node.end_location.unwrap(),
|
||||
|
|
|
@ -552,7 +552,7 @@ pub fn deprecated_import(
|
|||
);
|
||||
if checker.patch(Rule::DeprecatedImport) {
|
||||
if let Some(content) = fix {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
content,
|
||||
stmt.location,
|
||||
stmt.end_location.unwrap(),
|
||||
|
|
|
@ -256,7 +256,7 @@ pub fn deprecated_mock_attribute(checker: &mut Checker, expr: &Expr) {
|
|||
Range::from(value),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"mock".to_string(),
|
||||
value.location,
|
||||
value.end_location.unwrap(),
|
||||
|
@ -303,7 +303,7 @@ pub fn deprecated_mock_import(checker: &mut Checker, stmt: &Stmt) {
|
|||
Range::from(name),
|
||||
);
|
||||
if let Some(content) = content.as_ref() {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
content.clone(),
|
||||
stmt.location,
|
||||
stmt.end_location.unwrap(),
|
||||
|
@ -332,7 +332,7 @@ pub fn deprecated_mock_import(checker: &mut Checker, stmt: &Stmt) {
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(indent) = indentation(checker.locator, stmt) {
|
||||
diagnostic.try_amend(|| {
|
||||
diagnostic.try_set_fix(|| {
|
||||
format_import_from(stmt, indent, checker.locator, checker.stylist).map(
|
||||
|content| {
|
||||
Edit::replacement(
|
||||
|
|
|
@ -70,7 +70,7 @@ pub fn deprecated_unittest_alias(checker: &mut Checker, expr: &Expr) {
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
format!("self.{target}"),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -139,7 +139,7 @@ pub fn extraneous_parentheses(
|
|||
Diagnostic::new(ExtraneousParentheses, Range::new(*start, *end));
|
||||
if autofix.into() && settings.rules.should_fix(Rule::ExtraneousParentheses) {
|
||||
let contents = locator.slice(Range::new(*start, *end));
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
contents[1..contents.len() - 1].to_string(),
|
||||
*start,
|
||||
*end,
|
||||
|
|
|
@ -271,7 +271,7 @@ pub(crate) fn f_strings(checker: &mut Checker, summary: &FormatSummary, expr: &E
|
|||
|
||||
let mut diagnostic = Diagnostic::new(FString, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
contents,
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -146,7 +146,7 @@ pub(crate) fn format_literals(checker: &mut Checker, summary: &FormatSummary, ex
|
|||
if let Ok(contents) =
|
||||
generate_call(expr, &summary.indexes, checker.locator, checker.stylist)
|
||||
{
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
contents,
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -59,7 +59,7 @@ pub fn lru_cache_with_maxsize_none(checker: &mut Checker, decorator_list: &[Expr
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let ExprKind::Attribute { value, ctx, .. } = &func.node {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(
|
||||
&create_expr(ExprKind::Attribute {
|
||||
value: value.clone(),
|
||||
|
|
|
@ -48,7 +48,7 @@ pub fn lru_cache_without_parameters(checker: &mut Checker, decorator_list: &[Exp
|
|||
Range::new(func.end_location.unwrap(), expr.end_location.unwrap()),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
unparse_expr(func, checker.stylist),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -65,7 +65,7 @@ pub fn native_literals(
|
|||
LiteralType::Bytes
|
||||
}}, Range::from(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
if id == "bytes" {
|
||||
let mut content = String::with_capacity(3);
|
||||
content.push('b');
|
||||
|
@ -129,7 +129,7 @@ pub fn native_literals(
|
|||
Range::from(expr),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
arg_code.to_string(),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
|
|
|
@ -39,7 +39,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 }, Range::from(expr));
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"open".to_string(),
|
||||
func.location,
|
||||
func.end_location.unwrap(),
|
||||
|
|
|
@ -63,7 +63,7 @@ fn atom_diagnostic(checker: &mut Checker, target: &Expr) {
|
|||
Range::from(target),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"OSError".to_string(),
|
||||
target.location,
|
||||
target.end_location.unwrap(),
|
||||
|
@ -104,13 +104,13 @@ fn tuple_diagnostic(checker: &mut Checker, target: &Expr, aliases: &[&Expr]) {
|
|||
}
|
||||
|
||||
if remaining.len() == 1 {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
"OSError".to_string(),
|
||||
target.location,
|
||||
target.end_location.unwrap(),
|
||||
));
|
||||
} else {
|
||||
diagnostic.amend(Edit::replacement(
|
||||
diagnostic.set_fix(Edit::replacement(
|
||||
format!(
|
||||
"({})",
|
||||
unparse_expr(
|
||||
|
|
|
@ -353,7 +353,7 @@ pub fn outdated_version_block(
|
|||
if let Some(fix) =
|
||||
fix_py2_block(checker, stmt, body, orelse, &block)
|
||||
{
|
||||
diagnostic.amend(fix);
|
||||
diagnostic.set_fix(fix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ pub fn outdated_version_block(
|
|||
if let Some(block) = metadata(checker.locator, stmt) {
|
||||
if let Some(fix) = fix_py3_block(checker, stmt, test, body, &block)
|
||||
{
|
||||
diagnostic.amend(fix);
|
||||
diagnostic.set_fix(fix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ pub fn outdated_version_block(
|
|||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(block) = metadata(checker.locator, stmt) {
|
||||
if let Some(fix) = fix_py2_block(checker, stmt, body, orelse, &block) {
|
||||
diagnostic.amend(fix);
|
||||
diagnostic.set_fix(fix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ pub fn outdated_version_block(
|
|||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(block) = metadata(checker.locator, stmt) {
|
||||
if let Some(fix) = fix_py3_block(checker, stmt, test, body, &block) {
|
||||
diagnostic.amend(fix);
|
||||
diagnostic.set_fix(fix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
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