diff --git a/crates/ruff/src/checkers/ast/mod.rs b/crates/ruff/src/checkers/ast/mod.rs index 9645331823..1b855384cb 100644 --- a/crates/ruff/src/checkers/ast/mod.rs +++ b/crates/ruff/src/checkers/ast/mod.rs @@ -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); } diff --git a/crates/ruff/src/checkers/noqa.rs b/crates/ruff/src/checkers/noqa.rs index 7a452ae719..9c1b1d8155 100644 --- a/crates/ruff/src/checkers/noqa.rs +++ b/crates/ruff/src/checkers/noqa.rs @@ -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), diff --git a/crates/ruff/src/rules/eradicate/rules.rs b/crates/ruff/src/rules/eradicate/rules.rs index 4b5e7d1b17..7808cff4a9 100644 --- a/crates/ruff/src/rules/eradicate/rules.rs +++ b/crates/ruff/src/rules/eradicate/rules.rs @@ -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 { diff --git a/crates/ruff/src/rules/flake8_annotations/rules.rs b/crates/ruff/src/rules/flake8_annotations/rules.rs index b8cd375493..2a2e72a67d 100644 --- a/crates/ruff/src/rules/flake8_annotations/rules.rs +++ b/crates/ruff/src/rules/flake8_annotations/rules.rs @@ -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) }); } diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/assert_false.rs b/crates/ruff/src/rules/flake8_bugbear/rules/assert_false.rs index 188c0ecbb5..849dd0773c 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/assert_false.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/assert_false.rs @@ -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(), diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs b/crates/ruff/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs index 5349268691..630928f56d 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs @@ -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 { diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/getattr_with_constant.rs b/crates/ruff/src/rules/flake8_bugbear/rules/getattr_with_constant.rs index 0fe8ae6eef..73fcfa7120 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/getattr_with_constant.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/getattr_with_constant.rs @@ -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(), diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs b/crates/ruff/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs index 9809eee8d5..2ae2556e75 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs @@ -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(), diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/setattr_with_constant.rs b/crates/ruff/src/rules/flake8_bugbear/rules/setattr_with_constant.rs index 567a63cd91..289533713b 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/setattr_with_constant.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/setattr_with_constant.rs @@ -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(), diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs b/crates/ruff/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs index 6b06c569ab..7704a18312 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs @@ -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(), diff --git a/crates/ruff/src/rules/flake8_commas/rules.rs b/crates/ruff/src/rules/flake8_commas/rules.rs index f75641baf2..d541768a33 100644 --- a/crates/ruff/src/rules/flake8_commas/rules.rs +++ b/crates/ruff/src/rules/flake8_commas/rules.rs @@ -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, diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs index d1250bfc99..67aed7883a 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs @@ -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) }); } diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs index fbb5f1aa3e..ee97babdd3 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs @@ -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) }); } diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs index 2aed9c6461..96171fafea 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs @@ -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) }); } diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs index 545615cdfc..a0c3f20428 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs @@ -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, diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs index a1b52cc9d5..a3e5cf3810 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs @@ -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, diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs index 1e69c6eb34..63b1aa6b20 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs @@ -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) }); } diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs index 0a73d9f35a..0978042f4a 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs @@ -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) }); } diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs index 61b127064b..d0b2fac8f0 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs @@ -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); } diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs index ffe4afa701..2e334fcb09 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs @@ -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) }); } diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs index 7e06c13b70..9e362915de 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs @@ -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, diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs index efcc17fdf0..c3f3fb4497 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs @@ -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) }); } diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs index 591b9d9b49..a94483d26c 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs @@ -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) }); } diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs index 43ff7eba44..7ccc30fb75 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs @@ -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) }); } diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs index f0966b3db9..41aed3b54c 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs @@ -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) }); } diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_map.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_map.rs index 32e001e4ff..db5e56450e 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_map.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_map.rs @@ -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, diff --git a/crates/ruff/src/rules/flake8_executable/rules/shebang_whitespace.rs b/crates/ruff/src/rules/flake8_executable/rules/shebang_whitespace.rs index bfd2875c23..15f4d79d2b 100644 --- a/crates/ruff/src/rules/flake8_executable/rules/shebang_whitespace.rs +++ b/crates/ruff/src/rules/flake8_executable/rules/shebang_whitespace.rs @@ -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), )); diff --git a/crates/ruff/src/rules/flake8_logging_format/rules.rs b/crates/ruff/src/rules/flake8_logging_format/rules.rs index b4dedf580f..ba4ea7087c 100644 --- a/crates/ruff/src/rules/flake8_logging_format/rules.rs +++ b/crates/ruff/src/rules/flake8_logging_format/rules.rs @@ -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, diff --git a/crates/ruff/src/rules/flake8_pie/rules.rs b/crates/ruff/src/rules/flake8_pie/rules.rs index 16d73d3b0b..182be376dd 100644 --- a/crates/ruff/src/rules/flake8_pie/rules.rs +++ b/crates/ruff/src/rules/flake8_pie/rules.rs @@ -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(), diff --git a/crates/ruff/src/rules/flake8_pyi/rules/simple_defaults.rs b/crates/ruff/src/rules/flake8_pyi/rules/simple_defaults.rs index ec8251b967..f04aad113a 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/simple_defaults.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/simple_defaults.rs @@ -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(), diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs index f9b66c1967..b6d7b150ea 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs @@ -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); } diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs index 04f51165f7..2a6b8abe24 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs @@ -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); } diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs index a5d95a6468..9c07b8b807 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs @@ -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); } diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs index 62abdc1ea1..eff5528fc1 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs @@ -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(), diff --git a/crates/ruff/src/rules/flake8_quotes/rules.rs b/crates/ruff/src/rules/flake8_quotes/rules.rs index 6faab9bcab..051e4ddc40 100644 --- a/crates/ruff/src/rules/flake8_quotes/rules.rs +++ b/crates/ruff/src/rules/flake8_quotes/rules.rs @@ -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); } diff --git a/crates/ruff/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs b/crates/ruff/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs index ff4fd76273..836516d890 100644 --- a/crates/ruff/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs +++ b/crates/ruff/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs @@ -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, )); diff --git a/crates/ruff/src/rules/flake8_return/rules.rs b/crates/ruff/src/rules/flake8_return/rules.rs index dcd27ef7dd..334c783641 100644 --- a/crates/ruff/src/rules/flake8_return/rules.rs +++ b/crates/ruff/src/rules/flake8_return/rules.rs @@ -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), )); diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs index dae820cf45..6164fb3635 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs @@ -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(), diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_expr.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_expr.rs index d7e465b506..9ad9546aba 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_expr.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_expr.rs @@ -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(), diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs index 38612b3dc4..0e94565b62 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs @@ -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(), diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_ifexp.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_ifexp.rs index 447f5a9587..aedd8c9766 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_ifexp.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_ifexp.rs @@ -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())), diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_unary_op.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_unary_op.rs index d15350bc59..4c8036e6b5 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_unary_op.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_unary_op.rs @@ -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(), diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs index 49cf6a7355..7d2277e02f 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs @@ -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}"), diff --git a/crates/ruff/src/rules/flake8_simplify/rules/key_in_dict.rs b/crates/ruff/src/rules/flake8_simplify/rules/key_in_dict.rs index 8dec9eb07d..d8f9c3ec9a 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/key_in_dict.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/key_in_dict.rs @@ -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(), diff --git a/crates/ruff/src/rules/flake8_simplify/rules/reimplemented_builtin.rs b/crates/ruff/src/rules/flake8_simplify/rules/reimplemented_builtin.rs index 6df320a71d..4ceb5c49b5 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/reimplemented_builtin.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/reimplemented_builtin.rs @@ -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, diff --git a/crates/ruff/src/rules/flake8_simplify/rules/yoda_conditions.rs b/crates/ruff/src/rules/flake8_simplify/rules/yoda_conditions.rs index e74e079f6c..dabaf64cff 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/yoda_conditions.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/yoda_conditions.rs @@ -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(), diff --git a/crates/ruff/src/rules/flake8_tidy_imports/relative_imports.rs b/crates/ruff/src/rules/flake8_tidy_imports/relative_imports.rs index 0ac7c4b025..86b27f4013 100644 --- a/crates/ruff/src/rules/flake8_tidy_imports/relative_imports.rs +++ b/crates/ruff/src/rules/flake8_tidy_imports/relative_imports.rs @@ -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) diff --git a/crates/ruff/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs b/crates/ruff/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs index d28755f651..2a76676505 100644 --- a/crates/ruff/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs +++ b/crates/ruff/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs @@ -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}"), } diff --git a/crates/ruff/src/rules/isort/rules/add_required_imports.rs b/crates/ruff/src/rules/isort/rules/add_required_imports.rs index 81348e0954..ddf5f0158a 100644 --- a/crates/ruff/src/rules/isort/rules/add_required_imports.rs +++ b/crates/ruff/src/rules/isort/rules/add_required_imports.rs @@ -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) } diff --git a/crates/ruff/src/rules/isort/rules/organize_imports.rs b/crates/ruff/src/rules/isort/rules/organize_imports.rs index 90870ae31e..f71c50266b 100644 --- a/crates/ruff/src/rules/isort/rules/organize_imports.rs +++ b/crates/ruff/src/rules/isort/rules/organize_imports.rs @@ -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, diff --git a/crates/ruff/src/rules/numpy/rules/deprecated_type_alias.rs b/crates/ruff/src/rules/numpy/rules/deprecated_type_alias.rs index 864cb5b83b..f94e894e77 100644 --- a/crates/ruff/src/rules/numpy/rules/deprecated_type_alias.rs +++ b/crates/ruff/src/rules/numpy/rules/deprecated_type_alias.rs @@ -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", diff --git a/crates/ruff/src/rules/pandas_vet/rules/inplace_argument.rs b/crates/ruff/src/rules/pandas_vet/rules/inplace_argument.rs index e310d6ec69..316e5e3776 100644 --- a/crates/ruff/src/rules/pandas_vet/rules/inplace_argument.rs +++ b/crates/ruff/src/rules/pandas_vet/rules/inplace_argument.rs @@ -76,7 +76,7 @@ pub fn inplace_argument( args, keywords, ) { - diagnostic.amend(fix); + diagnostic.set_fix(fix); } } return Some(diagnostic); diff --git a/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs b/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs index 9a1365c1b1..5a09245566 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs @@ -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); } diff --git a/crates/ruff/src/rules/pycodestyle/rules/invalid_escape_sequence.rs b/crates/ruff/src/rules/pycodestyle/rules/invalid_escape_sequence.rs index ad063f0755..d46ae48c1f 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/invalid_escape_sequence.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/invalid_escape_sequence.rs @@ -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), )); diff --git a/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs b/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs index 00e5dbf5d5..50c1887272 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs @@ -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(), diff --git a/crates/ruff/src/rules/pycodestyle/rules/literal_comparisons.rs b/crates/ruff/src/rules/pycodestyle/rules/literal_comparisons.rs index 37d3d99023..6f4c3a3a20 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/literal_comparisons.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/literal_comparisons.rs @@ -273,7 +273,7 @@ pub fn literal_comparisons( .collect::>(); 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(), diff --git a/crates/ruff/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs b/crates/ruff/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs index 025284da9a..169e5f679b 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs @@ -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); } diff --git a/crates/ruff/src/rules/pycodestyle/rules/missing_whitespace.rs b/crates/ruff/src/rules/pycodestyle/rules/missing_whitespace.rs index f63e1220c6..d70caa98af 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/missing_whitespace.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/missing_whitespace.rs @@ -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), )); diff --git a/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs b/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs index 8458ba1f5a..da443a9597 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs @@ -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(), diff --git a/crates/ruff/src/rules/pycodestyle/rules/trailing_whitespace.rs b/crates/ruff/src/rules/pycodestyle/rules/trailing_whitespace.rs index ca9a371171..e23a7d14cf 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/trailing_whitespace.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/trailing_whitespace.rs @@ -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); } diff --git a/crates/ruff/src/rules/pycodestyle/rules/whitespace_before_parameters.rs b/crates/ruff/src/rules/pycodestyle/rules/whitespace_before_parameters.rs index 542da9343c..79899c9934 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/whitespace_before_parameters.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/whitespace_before_parameters.rs @@ -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); } diff --git a/crates/ruff/src/rules/pydocstyle/rules/blank_after_summary.rs b/crates/ruff/src/rules/pydocstyle/rules/blank_after_summary.rs index 40a3d9375d..913ca8d8cd 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/blank_after_summary.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/blank_after_summary.rs @@ -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( diff --git a/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_class.rs b/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_class.rs index 43ec54ff6a..52bd516d35 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_class.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_class.rs @@ -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( diff --git a/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_function.rs b/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_function.rs index 101aec58df..c7e34fb0b9 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_function.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/blank_before_after_function.rs @@ -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, diff --git a/crates/ruff/src/rules/pydocstyle/rules/capitalized.rs b/crates/ruff/src/rules/pydocstyle/rules/capitalized.rs index fbbed8bfe0..d46203c5a1 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/capitalized.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/capitalized.rs @@ -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 diff --git a/crates/ruff/src/rules/pydocstyle/rules/ends_with_period.rs b/crates/ruff/src/rules/pydocstyle/rules/ends_with_period.rs index 54e7a516d7..e36bad42b7 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/ends_with_period.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/ends_with_period.rs @@ -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); diff --git a/crates/ruff/src/rules/pydocstyle/rules/ends_with_punctuation.rs b/crates/ruff/src/rules/pydocstyle/rules/ends_with_punctuation.rs index ec439db7de..cff79b49e4 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/ends_with_punctuation.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/ends_with_punctuation.rs @@ -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); diff --git a/crates/ruff/src/rules/pydocstyle/rules/indent.rs b/crates/ruff/src/rules/pydocstyle/rules/indent.rs index 8287ceac3c..c11376e02a 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/indent.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/indent.rs @@ -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()), diff --git a/crates/ruff/src/rules/pydocstyle/rules/multi_line_summary_start.rs b/crates/ruff/src/rules/pydocstyle/rules/multi_line_summary_start.rs index 5aec7c1020..bc462c6067 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/multi_line_summary_start.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/multi_line_summary_start.rs @@ -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()), diff --git a/crates/ruff/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs b/crates/ruff/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs index e493673495..5f7e9ca5f4 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs @@ -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(), diff --git a/crates/ruff/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs b/crates/ruff/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs index 7599a9a7d4..ced81d26ca 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs @@ -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(), diff --git a/crates/ruff/src/rules/pydocstyle/rules/one_liner.rs b/crates/ruff/src/rules/pydocstyle/rules/one_liner.rs index 3df34ea357..d7cce0f985 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/one_liner.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/one_liner.rs @@ -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(), diff --git a/crates/ruff/src/rules/pydocstyle/rules/sections.rs b/crates/ruff/src/rules/pydocstyle/rules/sections.rs index 7a6e921b4c..49c8bbc11e 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/sections.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/sections.rs @@ -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, diff --git a/crates/ruff/src/rules/pyflakes/rules/f_string_missing_placeholders.rs b/crates/ruff/src/rules/pyflakes/rules/f_string_missing_placeholders.rs index 9f26ce3b9f..cd53757b61 100644 --- a/crates/ruff/src/rules/pyflakes/rules/f_string_missing_placeholders.rs +++ b/crates/ruff/src/rules/pyflakes/rules/f_string_missing_placeholders.rs @@ -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, diff --git a/crates/ruff/src/rules/pyflakes/rules/invalid_literal_comparisons.rs b/crates/ruff/src/rules/pyflakes/rules/invalid_literal_comparisons.rs index daba18cd48..228a21dbc2 100644 --- a/crates/ruff/src/rules/pyflakes/rules/invalid_literal_comparisons.rs +++ b/crates/ruff/src/rules/pyflakes/rules/invalid_literal_comparisons.rs @@ -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( diff --git a/crates/ruff/src/rules/pyflakes/rules/raise_not_implemented.rs b/crates/ruff/src/rules/pyflakes/rules/raise_not_implemented.rs index 2e5641258a..02cb7d1802 100644 --- a/crates/ruff/src/rules/pyflakes/rules/raise_not_implemented.rs +++ b/crates/ruff/src/rules/pyflakes/rules/raise_not_implemented.rs @@ -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(), diff --git a/crates/ruff/src/rules/pyflakes/rules/repeated_keys.rs b/crates/ruff/src/rules/pyflakes/rules/repeated_keys.rs index 8aa52f22e1..7dd7cd9475 100644 --- a/crates/ruff/src/rules/pyflakes/rules/repeated_keys.rs +++ b/crates/ruff/src/rules/pyflakes/rules/repeated_keys.rs @@ -110,7 +110,7 @@ pub fn repeated_keys(checker: &mut Checker, keys: &[Option], 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], 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(), )); diff --git a/crates/ruff/src/rules/pyflakes/rules/strings.rs b/crates/ruff/src/rules/pyflakes/rules/strings.rs index dce87c266d..52d26185ea 100644 --- a/crates/ruff/src/rules/pyflakes/rules/strings.rs +++ b/crates/ruff/src/rules/pyflakes/rules/strings.rs @@ -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, diff --git a/crates/ruff/src/rules/pyflakes/rules/unused_variable.rs b/crates/ruff/src/rules/pyflakes/rules/unused_variable.rs index 48441f9f61..cc261a5df0 100644 --- a/crates/ruff/src/rules/pyflakes/rules/unused_variable.rs +++ b/crates/ruff/src/rules/pyflakes/rules/unused_variable.rs @@ -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); } } } diff --git a/crates/ruff/src/rules/pylint/rules/invalid_string_characters.rs b/crates/ruff/src/rules/pylint/rules/invalid_string_characters.rs index 20136e8c2a..8eac9f2621 100644 --- a/crates/ruff/src/rules/pylint/rules/invalid_string_characters.rs +++ b/crates/ruff/src/rules/pylint/rules/invalid_string_characters.rs @@ -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, diff --git a/crates/ruff/src/rules/pylint/rules/manual_import_from.rs b/crates/ruff/src/rules/pylint/rules/manual_import_from.rs index eb25a412ba..a0c08f886b 100644 --- a/crates/ruff/src/rules/pylint/rules/manual_import_from.rs +++ b/crates/ruff/src/rules/pylint/rules/manual_import_from.rs @@ -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()), diff --git a/crates/ruff/src/rules/pylint/rules/sys_exit_alias.rs b/crates/ruff/src/rules/pylint/rules/sys_exit_alias.rs index 3a49724e8e..008af2143c 100644 --- a/crates/ruff/src/rules/pylint/rules/sys_exit_alias.rs +++ b/crates/ruff/src/rules/pylint/rules/sys_exit_alias.rs @@ -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(), diff --git a/crates/ruff/src/rules/pylint/rules/useless_import_alias.rs b/crates/ruff/src/rules/pylint/rules/useless_import_alias.rs index fac32df343..83b9505d92 100644 --- a/crates/ruff/src/rules/pylint/rules/useless_import_alias.rs +++ b/crates/ruff/src/rules/pylint/rules/useless_import_alias.rs @@ -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(), diff --git a/crates/ruff/src/rules/pylint/rules/useless_return.rs b/crates/ruff/src/rules/pylint/rules/useless_return.rs index 896c7998d8..c495bfab42 100644 --- a/crates/ruff/src/rules/pylint/rules/useless_return.rs +++ b/crates/ruff/src/rules/pylint/rules/useless_return.rs @@ -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); diff --git a/crates/ruff/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs b/crates/ruff/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs index 27da06ffb1..ae1a2ff0df 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs @@ -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, diff --git a/crates/ruff/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs b/crates/ruff/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs index 4848967226..d2a28e0fde 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs @@ -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, diff --git a/crates/ruff/src/rules/pyupgrade/rules/datetime_utc_alias.rs b/crates/ruff/src/rules/pyupgrade/rules/datetime_utc_alias.rs index 4482a810b9..9dd838f229 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/datetime_utc_alias.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/datetime_utc_alias.rs @@ -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(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs b/crates/ruff/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs index a98f3b5af8..5c078f3ab9 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs @@ -25,7 +25,7 @@ fn add_check_for_node(checker: &mut Checker, node: &Located) { 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(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs b/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs index 51942ef901..f28e38d31b 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs @@ -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(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/deprecated_mock_import.rs b/crates/ruff/src/rules/pyupgrade/rules/deprecated_mock_import.rs index 5dd6b82f67..6575bd2f7c 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_mock_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_mock_import.rs @@ -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( diff --git a/crates/ruff/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs b/crates/ruff/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs index d7d3d6839e..7c66768f8c 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs @@ -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(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/extraneous_parentheses.rs b/crates/ruff/src/rules/pyupgrade/rules/extraneous_parentheses.rs index cf8664d7ff..49085b0279 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/extraneous_parentheses.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/extraneous_parentheses.rs @@ -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, diff --git a/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs b/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs index d5ea95040b..252fa46ba1 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs @@ -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(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/format_literals.rs b/crates/ruff/src/rules/pyupgrade/rules/format_literals.rs index 3e531e4f51..9d40a1074f 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/format_literals.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/format_literals.rs @@ -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(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs b/crates/ruff/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs index 003f93627f..badf4cb8cf 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs @@ -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(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs b/crates/ruff/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs index 4c6899609d..f4f4fdb72d 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs @@ -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(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/native_literals.rs b/crates/ruff/src/rules/pyupgrade/rules/native_literals.rs index da06e8ae96..c28afc0d44 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/native_literals.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/native_literals.rs @@ -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(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/open_alias.rs b/crates/ruff/src/rules/pyupgrade/rules/open_alias.rs index 019b83667b..1c04120cda 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/open_alias.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/open_alias.rs @@ -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(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/os_error_alias.rs b/crates/ruff/src/rules/pyupgrade/rules/os_error_alias.rs index a60535007a..72e067e072 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/os_error_alias.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/os_error_alias.rs @@ -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( diff --git a/crates/ruff/src/rules/pyupgrade/rules/outdated_version_block.rs b/crates/ruff/src/rules/pyupgrade/rules/outdated_version_block.rs index 6cb1c253d8..54ca96787e 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/outdated_version_block.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/outdated_version_block.rs @@ -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); } } } diff --git a/crates/ruff/src/rules/pyupgrade/rules/printf_string_formatting.rs b/crates/ruff/src/rules/pyupgrade/rules/printf_string_formatting.rs index cba199a0cc..c7f8a12d6b 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/printf_string_formatting.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/printf_string_formatting.rs @@ -437,7 +437,7 @@ pub(crate) fn printf_string_formatting( let mut diagnostic = Diagnostic::new(PrintfStringFormatting, 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(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/quoted_annotation.rs b/crates/ruff/src/rules/pyupgrade/rules/quoted_annotation.rs index 1c9ee54d15..61167eb515 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/quoted_annotation.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/quoted_annotation.rs @@ -23,7 +23,7 @@ impl AlwaysAutofixableViolation for QuotedAnnotation { pub fn quoted_annotation(checker: &mut Checker, annotation: &str, range: Range) { let mut diagnostic = Diagnostic::new(QuotedAnnotation, range); if checker.patch(Rule::QuotedAnnotation) { - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( annotation.to_string(), range.location, range.end_location, diff --git a/crates/ruff/src/rules/pyupgrade/rules/redundant_open_modes.rs b/crates/ruff/src/rules/pyupgrade/rules/redundant_open_modes.rs index 5cd2b7f2b1..581187e819 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/redundant_open_modes.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/redundant_open_modes.rs @@ -115,13 +115,13 @@ fn create_check( ); if patch { if let Some(content) = replacement_value { - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( content, mode_param.location, mode_param.end_location.unwrap(), )); } else { - diagnostic.try_amend(|| create_remove_param_fix(locator, expr, mode_param)); + diagnostic.try_set_fix(|| create_remove_param_fix(locator, expr, mode_param)); } } diagnostic diff --git a/crates/ruff/src/rules/pyupgrade/rules/replace_stdout_stderr.rs b/crates/ruff/src/rules/pyupgrade/rules/replace_stdout_stderr.rs index 03e6d292b7..6cb31281ee 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/replace_stdout_stderr.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/replace_stdout_stderr.rs @@ -140,7 +140,7 @@ pub fn replace_stdout_stderr(checker: &mut Checker, expr: &Expr, func: &Expr, kw let mut diagnostic = Diagnostic::new(ReplaceStdoutStderr, Range::from(expr)); if checker.patch(diagnostic.kind.rule()) { if let Some(fix) = generate_fix(checker.stylist, checker.locator, stdout, stderr) { - diagnostic.amend(fix); + diagnostic.set_fix(fix); }; } checker.diagnostics.push(diagnostic); diff --git a/crates/ruff/src/rules/pyupgrade/rules/replace_universal_newlines.rs b/crates/ruff/src/rules/pyupgrade/rules/replace_universal_newlines.rs index aff6017e92..ea385ab6f8 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/replace_universal_newlines.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/replace_universal_newlines.rs @@ -41,7 +41,7 @@ pub fn replace_universal_newlines(checker: &mut Checker, func: &Expr, kwargs: &[ ); let mut diagnostic = Diagnostic::new(ReplaceUniversalNewlines, range); if checker.patch(diagnostic.kind.rule()) { - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( "text".to_string(), range.location, range.end_location, diff --git a/crates/ruff/src/rules/pyupgrade/rules/super_call_with_parameters.rs b/crates/ruff/src/rules/pyupgrade/rules/super_call_with_parameters.rs index 29c98812c8..36d26d4f56 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/super_call_with_parameters.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/super_call_with_parameters.rs @@ -99,7 +99,7 @@ pub fn super_call_with_parameters(checker: &mut Checker, expr: &Expr, func: &Exp let mut diagnostic = Diagnostic::new(SuperCallWithParameters, Range::from(expr)); if checker.patch(diagnostic.kind.rule()) { if let Some(fix) = fixes::remove_super_arguments(checker.locator, checker.stylist, expr) { - diagnostic.amend(fix); + diagnostic.set_fix(fix); } } checker.diagnostics.push(diagnostic); diff --git a/crates/ruff/src/rules/pyupgrade/rules/type_of_primitive.rs b/crates/ruff/src/rules/pyupgrade/rules/type_of_primitive.rs index 8a398a5b30..65f30b1b3d 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/type_of_primitive.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/type_of_primitive.rs @@ -47,7 +47,7 @@ pub fn type_of_primitive(checker: &mut Checker, expr: &Expr, func: &Expr, args: }; let mut diagnostic = Diagnostic::new(TypeOfPrimitive { primitive }, Range::from(expr)); if checker.patch(diagnostic.kind.rule()) { - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( primitive.builtin(), expr.location, expr.end_location.unwrap(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/typing_text_str_alias.rs b/crates/ruff/src/rules/pyupgrade/rules/typing_text_str_alias.rs index ae97b6de2a..04c3affb1e 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/typing_text_str_alias.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/typing_text_str_alias.rs @@ -32,7 +32,7 @@ pub fn typing_text_str_alias(checker: &mut Checker, expr: &Expr) { { let mut diagnostic = Diagnostic::new(TypingTextStrAlias, Range::from(expr)); if checker.patch(diagnostic.kind.rule()) { - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( "str".to_string(), expr.location, expr.end_location.unwrap(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/unicode_kind_prefix.rs b/crates/ruff/src/rules/pyupgrade/rules/unicode_kind_prefix.rs index 2f13e65992..66caff749f 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unicode_kind_prefix.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unicode_kind_prefix.rs @@ -27,7 +27,7 @@ pub fn unicode_kind_prefix(checker: &mut Checker, expr: &Expr, kind: Option<&str if const_kind.to_lowercase() == "u" { let mut diagnostic = Diagnostic::new(UnicodeKindPrefix, Range::from(expr)); if checker.patch(diagnostic.kind.rule()) { - diagnostic.amend(Edit::deletion( + diagnostic.set_fix(Edit::deletion( expr.location, Location::new(expr.location.row(), expr.location.column() + 1), )); diff --git a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs index 7a7601d951..b2f54b544b 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs @@ -125,7 +125,7 @@ pub fn unnecessary_builtin_import( if fix.content.is_empty() || fix.content == "pass" { checker.deletions.insert(defined_by.clone()); } - diagnostic.amend(fix); + diagnostic.set_fix(fix); } Err(e) => error!("Failed to remove builtin import: {e}"), } diff --git a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs index 265f1cd11e..4a6c189770 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs @@ -34,7 +34,7 @@ pub fn unnecessary_coding_comment(lineno: usize, line: &str, autofix: bool) -> O Range::new(Location::new(lineno + 1, 0), Location::new(lineno + 2, 0)), ); if autofix { - diagnostic.amend(Edit::deletion( + diagnostic.set_fix(Edit::deletion( Location::new(lineno + 1, 0), Location::new(lineno + 2, 0), )); diff --git a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs index 069465eff5..e714ad9929 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs @@ -78,13 +78,13 @@ fn delete_default_encode_arg_or_kwarg( if let Some(arg) = args.get(0) { let mut diagnostic = Diagnostic::new(UnnecessaryEncodeUTF8, Range::from(expr)); if patch { - diagnostic.amend(Edit::deletion(arg.location, arg.end_location.unwrap())); + diagnostic.set_fix(Edit::deletion(arg.location, arg.end_location.unwrap())); } Some(diagnostic) } else if let Some(kwarg) = kwargs.get(0) { let mut diagnostic = Diagnostic::new(UnnecessaryEncodeUTF8, Range::from(expr)); if patch { - diagnostic.amend(Edit::deletion(kwarg.location, kwarg.end_location.unwrap())); + diagnostic.set_fix(Edit::deletion(kwarg.location, kwarg.end_location.unwrap())); } Some(diagnostic) } else { @@ -127,7 +127,7 @@ fn replace_with_bytes_literal( } prev = Some(end); } - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( replacement, expr.location, expr.end_location.unwrap(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_future_import.rs b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_future_import.rs index 88763e7767..9a0e97ae6a 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_future_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_future_import.rs @@ -105,7 +105,7 @@ pub fn unnecessary_future_import(checker: &mut Checker, stmt: &Stmt, names: &[Lo if fix.content.is_empty() || fix.content == "pass" { checker.deletions.insert(defined_by.clone()); } - diagnostic.amend(fix); + diagnostic.set_fix(fix); } Err(e) => error!("Failed to remove `__future__` import: {e}"), } diff --git a/crates/ruff/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs b/crates/ruff/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs index a38277a815..fcd3ffa6a4 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs @@ -102,7 +102,7 @@ pub fn unpacked_list_comprehension(checker: &mut Checker, targets: &[Expr], valu content.push('('); content.push_str(&existing[1..existing.len() - 1]); content.push(')'); - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( content, value.location, value.end_location.unwrap(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/use_pep585_annotation.rs b/crates/ruff/src/rules/pyupgrade/rules/use_pep585_annotation.rs index 32d3e1d5dc..55a07268cf 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/use_pep585_annotation.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/use_pep585_annotation.rs @@ -56,7 +56,7 @@ pub fn use_pep585_annotation(checker: &mut Checker, expr: &Expr) { if fixable && checker.patch(diagnostic.kind.rule()) { let binding = binding.to_lowercase(); if checker.ctx.is_builtin(&binding) { - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( binding, expr.location, expr.end_location.unwrap(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/use_pep604_annotation.rs b/crates/ruff/src/rules/pyupgrade/rules/use_pep604_annotation.rs index 9805406796..87d509e736 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/use_pep604_annotation.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/use_pep604_annotation.rs @@ -111,7 +111,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s let mut diagnostic = Diagnostic::new(NonPEP604Annotation { fixable }, Range::from(expr)); if fixable && checker.patch(diagnostic.kind.rule()) { - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( unparse_expr(&optional(slice), checker.stylist), expr.location, expr.end_location.unwrap(), @@ -128,7 +128,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s // Invalid type annotation. } ExprKind::Tuple { elts, .. } => { - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( unparse_expr(&union(elts), checker.stylist), expr.location, expr.end_location.unwrap(), @@ -136,7 +136,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s } _ => { // Single argument. - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( unparse_expr(slice, checker.stylist), expr.location, expr.end_location.unwrap(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/use_pep604_isinstance.rs b/crates/ruff/src/rules/pyupgrade/rules/use_pep604_isinstance.rs index 77f9be8653..8aaac3b5d2 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/use_pep604_isinstance.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/use_pep604_isinstance.rs @@ -94,7 +94,7 @@ pub fn use_pep604_isinstance(checker: &mut Checker, expr: &Expr, func: &Expr, ar let mut diagnostic = Diagnostic::new(NonPEP604Isinstance { kind }, Range::from(expr)); if checker.patch(diagnostic.kind.rule()) { - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( unparse_expr(&union(elts), checker.stylist), types.location, types.end_location.unwrap(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/useless_metaclass_type.rs b/crates/ruff/src/rules/pyupgrade/rules/useless_metaclass_type.rs index da924ee9a8..5dabb77ed0 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/useless_metaclass_type.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/useless_metaclass_type.rs @@ -64,7 +64,7 @@ pub fn useless_metaclass_type(checker: &mut Checker, stmt: &Stmt, value: &Expr, if fix.content.is_empty() || fix.content == "pass" { checker.deletions.insert(defined_by.clone()); } - diagnostic.amend(fix); + diagnostic.set_fix(fix); } Err(e) => error!("Failed to fix remove metaclass type: {e}"), } diff --git a/crates/ruff/src/rules/pyupgrade/rules/useless_object_inheritance.rs b/crates/ruff/src/rules/pyupgrade/rules/useless_object_inheritance.rs index 0d8fd4638b..d46263de8d 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/useless_object_inheritance.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/useless_object_inheritance.rs @@ -66,7 +66,7 @@ pub fn useless_object_inheritance( if checker.patch(diagnostic.kind.rule()) { let location = diagnostic.location; let end_location = diagnostic.end_location; - diagnostic.try_amend(|| { + diagnostic.try_set_fix(|| { remove_argument( checker.locator, stmt.location, diff --git a/crates/ruff/src/rules/pyupgrade/rules/yield_in_for_loop.rs b/crates/ruff/src/rules/pyupgrade/rules/yield_in_for_loop.rs index a68e401673..91ead305dd 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/yield_in_for_loop.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/yield_in_for_loop.rs @@ -176,7 +176,7 @@ pub fn yield_in_for_loop(checker: &mut Checker, stmt: &Stmt) { if checker.patch(diagnostic.kind.rule()) { let contents = checker.locator.slice(item.iter); let contents = format!("yield from {contents}"); - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( contents, item.stmt.location, item.stmt.end_location.unwrap(), diff --git a/crates/ruff/src/rules/ruff/rules/ambiguous_unicode_character.rs b/crates/ruff/src/rules/ruff/rules/ambiguous_unicode_character.rs index f4b7edd3bb..22a7258c09 100644 --- a/crates/ruff/src/rules/ruff/rules/ambiguous_unicode_character.rs +++ b/crates/ruff/src/rules/ruff/rules/ambiguous_unicode_character.rs @@ -1730,7 +1730,7 @@ pub fn ambiguous_unicode_character( ); if settings.rules.enabled(diagnostic.kind.rule()) { if autofix.into() && settings.rules.should_fix(diagnostic.kind.rule()) { - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( (*representant as char).to_string(), location, end_location, diff --git a/crates/ruff/src/rules/ruff/rules/collection_literal_concatenation.rs b/crates/ruff/src/rules/ruff/rules/collection_literal_concatenation.rs index c6daaa93c2..697e956dcf 100644 --- a/crates/ruff/src/rules/ruff/rules/collection_literal_concatenation.rs +++ b/crates/ruff/src/rules/ruff/rules/collection_literal_concatenation.rs @@ -112,7 +112,7 @@ pub fn collection_literal_concatenation(checker: &mut Checker, expr: &Expr) { ); if checker.patch(diagnostic.kind.rule()) { if fixable { - diagnostic.amend(Edit::replacement( + diagnostic.set_fix(Edit::replacement( contents, expr.location, expr.end_location.unwrap(), diff --git a/crates/ruff_diagnostics/src/diagnostic.rs b/crates/ruff_diagnostics/src/diagnostic.rs index 100290ff80..3344b24662 100644 --- a/crates/ruff_diagnostics/src/diagnostic.rs +++ b/crates/ruff_diagnostics/src/diagnostic.rs @@ -42,21 +42,22 @@ impl Diagnostic { } } - pub fn amend(&mut self, fix: Edit) -> &mut Self { + /// Set the [`Edit`] used to fix the diagnostic. + pub fn set_fix(&mut self, fix: Edit) { self.fix = Some(fix); - self } - pub fn try_amend(&mut self, func: impl FnOnce() -> Result) -> &mut Self { + /// Set the [`Edit`] used to fix the diagnostic, if the provided function returns `Ok`. + /// Otherwise, log the error. + pub fn try_set_fix(&mut self, func: impl FnOnce() -> Result) { match func() { Ok(fix) => self.fix = Some(fix), Err(err) => error!("Failed to create fix: {}", err), } - self } - pub fn parent(&mut self, parent: Location) -> &mut Self { + /// Set the location of the diagnostic's parent node. + pub fn set_parent(&mut self, parent: Location) { self.parent = Some(parent); - self } }