From cf7aa26aa4d6f46a7f3945f26abfec8188378cfc Mon Sep 17 00:00:00 2001 From: Zanie Adkins Date: Wed, 10 May 2023 01:42:46 -0500 Subject: [PATCH] Add `Applicability` to `Fix` (#4303) Co-authored-by: Micha Reiser --- crates/ruff/src/autofix/mod.rs | 1 + crates/ruff/src/checkers/ast/mod.rs | 2 + crates/ruff/src/checkers/noqa.rs | 1 + crates/ruff/src/message/diff.rs | 10 ++- crates/ruff/src/message/mod.rs | 1 + crates/ruff/src/rules/eradicate/rules.rs | 2 + .../flake8_bugbear/rules/assert_false.rs | 1 + .../rules/duplicate_exceptions.rs | 1 + .../rules/getattr_with_constant.rs | 1 + .../redundant_tuple_in_exception_handler.rs | 1 + .../rules/setattr_with_constant.rs | 1 + .../rules/unused_loop_control_variable.rs | 1 + crates/ruff/src/rules/flake8_commas/rules.rs | 2 + crates/ruff/src/rules/flake8_errmsg/rules.rs | 1 + .../rules/shebang_whitespace.rs | 1 + .../src/rules/flake8_logging_format/rules.rs | 1 + crates/ruff/src/rules/flake8_pie/rules.rs | 4 +- .../rules/duplicate_union_member.rs | 1 + .../rules/quoted_annotation_in_stub.rs | 1 + .../rules/flake8_pyi/rules/simple_defaults.rs | 6 ++ .../flake8_pytest_style/rules/assertion.rs | 1 + .../flake8_pytest_style/rules/fixture.rs | 5 ++ .../rules/flake8_pytest_style/rules/marks.rs | 3 + .../flake8_pytest_style/rules/parametrize.rs | 7 ++ crates/ruff/src/rules/flake8_quotes/rules.rs | 4 + .../unnecessary_paren_on_raise_exception.rs | 1 + crates/ruff/src/rules/flake8_return/rules.rs | 5 ++ .../flake8_simplify/rules/ast_bool_op.rs | 6 ++ .../rules/flake8_simplify/rules/ast_expr.rs | 2 + .../src/rules/flake8_simplify/rules/ast_if.rs | 5 ++ .../rules/flake8_simplify/rules/ast_ifexp.rs | 4 + .../flake8_simplify/rules/ast_unary_op.rs | 4 + .../rules/flake8_simplify/rules/ast_with.rs | 1 + .../flake8_simplify/rules/key_in_dict.rs | 1 + .../rules/reimplemented_builtin.rs | 2 + .../rules/suppressible_exception.rs | 1 + .../flake8_simplify/rules/yoda_conditions.rs | 1 + .../flake8_tidy_imports/relative_imports.rs | 2 +- .../rules/empty_type_checking_block.rs | 1 + .../flynt/rules/static_join_to_fstring.rs | 1 + .../rules/isort/rules/add_required_imports.rs | 1 + .../src/rules/isort/rules/organize_imports.rs | 1 + .../numpy/rules/deprecated_type_alias.rs | 1 + crates/ruff/src/rules/pandas_vet/fixes.rs | 2 +- .../pycodestyle/rules/compound_statements.rs | 1 + .../rules/invalid_escape_sequence.rs | 1 + .../pycodestyle/rules/lambda_assignment.rs | 1 + .../pycodestyle/rules/literal_comparisons.rs | 1 + .../rules/logical_lines/missing_whitespace.rs | 1 + .../whitespace_before_parameters.rs | 1 + .../rules/missing_newline_at_end_of_file.rs | 1 + .../src/rules/pycodestyle/rules/not_tests.rs | 2 + .../pycodestyle/rules/trailing_whitespace.rs | 2 + .../pydocstyle/rules/blank_after_summary.rs | 1 + .../rules/blank_before_after_class.rs | 3 + .../rules/blank_before_after_function.rs | 2 + .../src/rules/pydocstyle/rules/capitalized.rs | 1 + .../pydocstyle/rules/ends_with_period.rs | 1 + .../pydocstyle/rules/ends_with_punctuation.rs | 1 + .../ruff/src/rules/pydocstyle/rules/indent.rs | 3 + .../rules/multi_line_summary_start.rs | 2 + .../rules/newline_after_last_paragraph.rs | 1 + .../rules/no_surrounding_whitespace.rs | 1 + .../src/rules/pydocstyle/rules/one_liner.rs | 1 + .../src/rules/pydocstyle/rules/sections.rs | 14 +++ .../rules/f_string_missing_placeholders.rs | 1 + .../rules/invalid_literal_comparisons.rs | 1 + .../pyflakes/rules/raise_not_implemented.rs | 1 + .../src/rules/pyflakes/rules/repeated_keys.rs | 2 + .../rules/pyflakes/rules/unused_variable.rs | 5 ++ .../pylint/rules/invalid_string_characters.rs | 1 + .../rules/pylint/rules/manual_import_from.rs | 1 + .../src/rules/pylint/rules/nested_min_max.rs | 1 + .../src/rules/pylint/rules/sys_exit_alias.rs | 1 + .../pylint/rules/useless_import_alias.rs | 1 + .../src/rules/pylint/rules/useless_return.rs | 1 + ...convert_named_tuple_functional_to_class.rs | 1 + .../convert_typed_dict_functional_to_class.rs | 1 + .../pyupgrade/rules/datetime_utc_alias.rs | 1 + .../rules/deprecated_c_element_tree.rs | 1 + .../pyupgrade/rules/deprecated_import.rs | 1 + .../pyupgrade/rules/deprecated_mock_import.rs | 2 + .../rules/deprecated_unittest_alias.rs | 1 + .../pyupgrade/rules/extraneous_parentheses.rs | 1 + .../src/rules/pyupgrade/rules/f_strings.rs | 1 + .../rules/pyupgrade/rules/format_literals.rs | 1 + .../rules/lru_cache_with_maxsize_none.rs | 1 + .../rules/lru_cache_without_parameters.rs | 1 + .../rules/pyupgrade/rules/native_literals.rs | 2 + .../src/rules/pyupgrade/rules/open_alias.rs | 1 + .../rules/pyupgrade/rules/os_error_alias.rs | 3 + .../pyupgrade/rules/outdated_version_block.rs | 7 ++ .../rules/printf_string_formatting.rs | 1 + .../pyupgrade/rules/quoted_annotation.rs | 1 + .../pyupgrade/rules/redundant_open_modes.rs | 1 + .../pyupgrade/rules/replace_stdout_stderr.rs | 1 + .../rules/replace_universal_newlines.rs | 1 + .../rules/super_call_with_parameters.rs | 1 + .../pyupgrade/rules/type_of_primitive.rs | 1 + .../pyupgrade/rules/typing_text_str_alias.rs | 1 + .../pyupgrade/rules/unicode_kind_prefix.rs | 1 + .../rules/unnecessary_builtin_import.rs | 1 + .../rules/unnecessary_coding_comment.rs | 1 + .../rules/unnecessary_encode_utf8.rs | 1 + .../rules/unnecessary_future_import.rs | 1 + .../rules/unpacked_list_comprehension.rs | 1 + .../pyupgrade/rules/use_pep585_annotation.rs | 1 + .../pyupgrade/rules/use_pep604_annotation.rs | 3 + .../pyupgrade/rules/use_pep604_isinstance.rs | 1 + .../pyupgrade/rules/useless_metaclass_type.rs | 1 + .../pyupgrade/rules/yield_in_for_loop.rs | 1 + .../ruff/rules/ambiguous_unicode_character.rs | 1 + .../rules/collection_literal_concatenation.rs | 1 + crates/ruff_diagnostics/src/diagnostic.rs | 3 + crates/ruff_diagnostics/src/fix.rs | 90 ++++++++++++++++++- crates/ruff_diagnostics/src/lib.rs | 2 +- 116 files changed, 296 insertions(+), 8 deletions(-) diff --git a/crates/ruff/src/autofix/mod.rs b/crates/ruff/src/autofix/mod.rs index 09802b4374e77..ac813ec0c7fbc 100644 --- a/crates/ruff/src/autofix/mod.rs +++ b/crates/ruff/src/autofix/mod.rs @@ -108,6 +108,7 @@ mod tests { use crate::autofix::apply_fixes; use crate::rules::pycodestyle::rules::MissingNewlineAtEndOfFile; + #[allow(deprecated)] fn create_diagnostics(edit: impl IntoIterator) -> Vec { edit.into_iter() .map(|edit| Diagnostic { diff --git a/crates/ruff/src/checkers/ast/mod.rs b/crates/ruff/src/checkers/ast/mod.rs index 827763d28ada1..a73d59fe73344 100644 --- a/crates/ruff/src/checkers/ast/mod.rs +++ b/crates/ruff/src/checkers/ast/mod.rs @@ -5336,7 +5336,9 @@ impl<'a> Checker<'a> { if matches!(child.node, StmtKind::ImportFrom { .. }) { diagnostic.set_parent(child.start()); } + if let Some(edit) = &fix { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(edit.clone())); } diagnostics.push(diagnostic); diff --git a/crates/ruff/src/checkers/noqa.rs b/crates/ruff/src/checkers/noqa.rs index f002d89f1473b..d694511db53a8 100644 --- a/crates/ruff/src/checkers/noqa.rs +++ b/crates/ruff/src/checkers/noqa.rs @@ -180,6 +180,7 @@ pub fn check_noqa( locator, )); } else { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( format!("# noqa: {}", valid_codes.join(", ")), *range, diff --git a/crates/ruff/src/message/diff.rs b/crates/ruff/src/message/diff.rs index 12026f4555ffb..bdc0eb9a18956 100644 --- a/crates/ruff/src/message/diff.rs +++ b/crates/ruff/src/message/diff.rs @@ -1,6 +1,6 @@ use crate::message::Message; use colored::{Color, ColoredString, Colorize, Styles}; -use ruff_diagnostics::Fix; +use ruff_diagnostics::{Applicability, Fix}; use ruff_python_ast::source_code::{OneIndexed, SourceFile}; use ruff_text_size::{TextRange, TextSize}; use similar::{ChangeTag, TextDiff}; @@ -47,7 +47,13 @@ impl Display for Diff<'_> { let diff = TextDiff::from_lines(self.source_code.source_text(), &output); - writeln!(f, "{}", "ℹ Suggested fix".blue())?; + let message = match self.fix.applicability() { + Applicability::Automatic => "Fix", + Applicability::Suggested => "Suggested fix", + Applicability::Manual => "Possible fix", + Applicability::Unspecified => "Suggested fix", // For backwards compatibility, unspecified fixes are 'suggested' + }; + writeln!(f, "ℹ {}", message.blue())?; let (largest_old, largest_new) = diff .ops() diff --git a/crates/ruff/src/message/mod.rs b/crates/ruff/src/message/mod.rs index 4f2cd6f685ec6..b462ea434cfb1 100644 --- a/crates/ruff/src/message/mod.rs +++ b/crates/ruff/src/message/mod.rs @@ -185,6 +185,7 @@ def fibonacci(n): let fib_source = SourceFileBuilder::new("fib.py", fib).finish(); + #[allow(deprecated)] let unused_variable = Diagnostic::new( UnusedVariable { name: "x".to_string(), diff --git a/crates/ruff/src/rules/eradicate/rules.rs b/crates/ruff/src/rules/eradicate/rules.rs index c2f730c4cb59a..45a9fd3246030 100644 --- a/crates/ruff/src/rules/eradicate/rules.rs +++ b/crates/ruff/src/rules/eradicate/rules.rs @@ -57,7 +57,9 @@ pub fn commented_out_code( // Verify that the comment is on its own line, and that it contains code. if is_standalone_comment(line) && comment_contains_code(line, &settings.task_tags[..]) { let mut diagnostic = Diagnostic::new(CommentedOutCode, range); + if autofix.into() && settings.rules.should_fix(Rule::CommentedOutCode) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_deletion( locator.full_lines_range(range), ))); 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 3f5b130e8da32..bdf4d9404d271 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/assert_false.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/assert_false.rs @@ -63,6 +63,7 @@ pub fn assert_false(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg: Option let mut diagnostic = Diagnostic::new(AssertFalse, test.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_stmt(&assertion_error(msg), checker.stylist), stmt.range(), 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 3063c044493ad..017ecd4f107ce 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs @@ -96,6 +96,7 @@ fn duplicate_handler_exceptions<'a>( expr.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( if unique_elts.len() == 1 { unparse_expr(unique_elts[0], checker.stylist) 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 67c9b54717f73..a2666a9328f1a 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 @@ -64,6 +64,7 @@ pub fn getattr_with_constant(checker: &mut Checker, expr: &Expr, func: &Expr, ar let mut diagnostic = Diagnostic::new(GetAttrWithConstant, expr.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(&attribute(obj, value), checker.stylist), expr.range(), 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 de129fa61e1f2..cefae124e7eda 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 @@ -47,6 +47,7 @@ pub fn redundant_tuple_in_exception_handler(checker: &mut Checker, handlers: &[E type_.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(elt, checker.stylist), type_.range(), 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 63c9cf5b47ee5..57efc0d8c0c11 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 @@ -79,6 +79,7 @@ pub fn setattr_with_constant(checker: &mut Checker, expr: &Expr, func: &Expr, ar let mut diagnostic = Diagnostic::new(SetAttrWithConstant, expr.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( assignment(obj, name, value, checker.stylist), expr.range(), 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 af8c9ed28aaf6..d46721614d667 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 @@ -169,6 +169,7 @@ pub fn unused_loop_control_variable(checker: &mut Checker, target: &Expr, body: if let Some(binding) = binding { if binding.kind.is_loop_var() { if !binding.used() { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( rename, expr.range(), diff --git a/crates/ruff/src/rules/flake8_commas/rules.rs b/crates/ruff/src/rules/flake8_commas/rules.rs index c79f77099845b..0592604e1b0ad 100644 --- a/crates/ruff/src/rules/flake8_commas/rules.rs +++ b/crates/ruff/src/rules/flake8_commas/rules.rs @@ -325,6 +325,7 @@ pub fn trailing_commas( let comma = prev.spanned.unwrap(); let mut diagnostic = Diagnostic::new(ProhibitedTrailingComma, comma.1); if autofix.into() && settings.rules.should_fix(Rule::ProhibitedTrailingComma) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(diagnostic.range()))); } diagnostics.push(diagnostic); @@ -365,6 +366,7 @@ pub fn trailing_commas( // removing any brackets in the same linter pass - doing both at the same time could // lead to a syntax error. let contents = locator.slice(missing_comma.1); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( format!("{contents},"), missing_comma.1, diff --git a/crates/ruff/src/rules/flake8_errmsg/rules.rs b/crates/ruff/src/rules/flake8_errmsg/rules.rs index 4ccaf40ec7ed7..46fe28a5c80ab 100644 --- a/crates/ruff/src/rules/flake8_errmsg/rules.rs +++ b/crates/ruff/src/rules/flake8_errmsg/rules.rs @@ -203,6 +203,7 @@ fn generate_fix(stylist: &Stylist, stmt: &Stmt, exc_arg: &Expr, indentation: &st }), stylist, ); + #[allow(deprecated)] Fix::unspecified_edits( Edit::insertion( format!( 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 3bf409e337f41..76480221c36e1 100644 --- a/crates/ruff/src/rules/flake8_executable/rules/shebang_whitespace.rs +++ b/crates/ruff/src/rules/flake8_executable/rules/shebang_whitespace.rs @@ -32,6 +32,7 @@ pub fn shebang_whitespace( TextRange::at(range.start(), *n_spaces), ); if autofix { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(TextRange::at( range.start(), *n_spaces, diff --git a/crates/ruff/src/rules/flake8_logging_format/rules.rs b/crates/ruff/src/rules/flake8_logging_format/rules.rs index 48917201bcfe6..ff43fd4ef60b2 100644 --- a/crates/ruff/src/rules/flake8_logging_format/rules.rs +++ b/crates/ruff/src/rules/flake8_logging_format/rules.rs @@ -171,6 +171,7 @@ pub fn logging_call(checker: &mut Checker, func: &Expr, args: &[Expr], keywords: { let mut diagnostic = Diagnostic::new(LoggingWarn, level_call_range); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "warning".to_string(), level_call_range, diff --git a/crates/ruff/src/rules/flake8_pie/rules.rs b/crates/ruff/src/rules/flake8_pie/rules.rs index 1e0ee808a6ae2..f3bd1b40360f0 100644 --- a/crates/ruff/src/rules/flake8_pie/rules.rs +++ b/crates/ruff/src/rules/flake8_pie/rules.rs @@ -315,6 +315,7 @@ pub fn no_unnecessary_pass(checker: &mut Checker, body: &[Stmt]) { let mut diagnostic = Diagnostic::new(UnnecessaryPass, pass_stmt.range()); if checker.patch(diagnostic.kind.rule()) { if let Some(index) = trailing_comment_start_offset(pass_stmt, checker.locator) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_deletion( pass_stmt.range().add_end(index), ))); @@ -596,7 +597,7 @@ pub fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) { }) .collect(), }); - + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(&bool_op, checker.stylist), expr.range(), @@ -622,6 +623,7 @@ pub fn reimplemented_list_builtin(checker: &mut Checker, expr: &Expr) { if elts.is_empty() { let mut diagnostic = Diagnostic::new(ReimplementedListBuiltin, expr.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "list".to_string(), expr.range(), diff --git a/crates/ruff/src/rules/flake8_pyi/rules/duplicate_union_member.rs b/crates/ruff/src/rules/flake8_pyi/rules/duplicate_union_member.rs index 93a170053ce32..6c081b5a3e6b1 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/duplicate_union_member.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/duplicate_union_member.rs @@ -77,6 +77,7 @@ fn traverse_union<'a>( }; // Replace the parent with its non-duplicate child. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr( if expr.node == left.node { right } else { left }, diff --git a/crates/ruff/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs b/crates/ruff/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs index 2a3e4271129b1..46f8aed2dfb75 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs @@ -23,6 +23,7 @@ impl AlwaysAutofixableViolation for QuotedAnnotationInStub { pub fn quoted_annotation_in_stub(checker: &mut Checker, annotation: &str, range: TextRange) { let mut diagnostic = Diagnostic::new(QuotedAnnotationInStub, range); if checker.patch(Rule::QuotedAnnotationInStub) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( annotation.to_string(), range, 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 468044057c861..dbfb00434d78c 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/simple_defaults.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/simple_defaults.rs @@ -298,6 +298,7 @@ pub fn typed_argument_simple_defaults(checker: &mut Checker, args: &Arguments) { Diagnostic::new(TypedArgumentDefaultInStub, default.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "...".to_string(), default.range(), @@ -324,6 +325,7 @@ pub fn typed_argument_simple_defaults(checker: &mut Checker, args: &Arguments) { Diagnostic::new(TypedArgumentDefaultInStub, default.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "...".to_string(), default.range(), @@ -353,6 +355,7 @@ pub fn argument_simple_defaults(checker: &mut Checker, args: &Arguments) { Diagnostic::new(ArgumentDefaultInStub, default.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "...".to_string(), default.range(), @@ -379,6 +382,7 @@ pub fn argument_simple_defaults(checker: &mut Checker, args: &Arguments) { Diagnostic::new(ArgumentDefaultInStub, default.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "...".to_string(), default.range(), @@ -410,6 +414,7 @@ pub fn assignment_default_in_stub(checker: &mut Checker, targets: &[Expr], value let mut diagnostic = Diagnostic::new(AssignmentDefaultInStub, value.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "...".to_string(), value.range(), @@ -440,6 +445,7 @@ pub fn annotated_assignment_default_in_stub( let mut diagnostic = Diagnostic::new(AssignmentDefaultInStub, value.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "...".to_string(), value.range(), 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 398e0932653e4..17391be70aedb 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs @@ -204,6 +204,7 @@ pub fn unittest_assertion( ); if fixable && checker.patch(diagnostic.kind.rule()) { if let Ok(stmt) = unittest_assert.generate_assert(args, keywords) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_stmt(&stmt, checker.stylist), expr.range(), 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 d7a351f6354b8..b2036afb57b71 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs @@ -292,6 +292,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E && args.is_empty() && keywords.is_empty() { + #[allow(deprecated)] let fix = Fix::unspecified(Edit::deletion(func.end(), decorator.end())); pytest_fixture_parentheses( checker, @@ -354,6 +355,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &E .enabled(Rule::PytestFixtureIncorrectParenthesesStyle) && checker.settings.flake8_pytest_style.fixture_parentheses { + #[allow(deprecated)] let fix = Fix::unspecified(Edit::insertion( Parentheses::Empty.to_string(), decorator.end(), @@ -423,6 +425,7 @@ fn check_fixture_returns(checker: &mut Checker, stmt: &Stmt, name: &str, body: & stmt.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "return".to_string(), TextRange::at(stmt.start(), "yield".text_len()), @@ -495,6 +498,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Expr]) { Diagnostic::new(PytestUnnecessaryAsyncioMarkOnFixture, expr.range()); if checker.patch(diagnostic.kind.rule()) { let range = checker.locator.full_lines_range(expr.range()); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range))); } checker.diagnostics.push(diagnostic); @@ -511,6 +515,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Expr]) { Diagnostic::new(PytestErroneousUseFixturesOnFixture, expr.range()); if checker.patch(diagnostic.kind.rule()) { let line_range = checker.locator.full_lines_range(expr.range()); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(line_range))); } checker.diagnostics.push(diagnostic); 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 de65afbf733db..92da8d41d847f 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs @@ -84,12 +84,14 @@ fn check_mark_parentheses(checker: &mut Checker, decorator: &Expr, call_path: &C && args.is_empty() && keywords.is_empty() { + #[allow(deprecated)] let fix = Fix::unspecified(Edit::deletion(func.end(), decorator.end())); pytest_mark_parentheses(checker, decorator, call_path, fix, "", "()"); } } _ => { if checker.settings.flake8_pytest_style.mark_parentheses { + #[allow(deprecated)] let fix = Fix::unspecified(Edit::insertion("()".to_string(), decorator.end())); pytest_mark_parentheses(checker, decorator, call_path, fix, "()", ""); } @@ -113,6 +115,7 @@ fn check_useless_usefixtures(checker: &mut Checker, decorator: &Expr, call_path: if !has_parameters { let mut diagnostic = Diagnostic::new(PytestUseFixturesWithoutParameters, decorator.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_deletion( decorator.range().sub_start(TextSize::from(1)), ))); 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 493a8eb1729f0..5bdd4c348f4ac 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs @@ -148,6 +148,7 @@ fn check_names(checker: &mut Checker, decorator: &Expr, expr: &Expr) { name_range, ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( format!( "({})", @@ -181,6 +182,7 @@ fn check_names(checker: &mut Checker, decorator: &Expr, expr: &Expr) { name_range, ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr( &create_expr(ExprKind::List { @@ -222,6 +224,7 @@ fn check_names(checker: &mut Checker, decorator: &Expr, expr: &Expr) { expr.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr( &create_expr(ExprKind::List { @@ -244,6 +247,7 @@ fn check_names(checker: &mut Checker, decorator: &Expr, expr: &Expr) { ); if checker.patch(diagnostic.kind.rule()) { if let Some(content) = elts_to_csv(elts, checker) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( content, expr.range(), @@ -271,6 +275,7 @@ fn check_names(checker: &mut Checker, decorator: &Expr, expr: &Expr) { expr.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( format!( "({})", @@ -296,6 +301,7 @@ fn check_names(checker: &mut Checker, decorator: &Expr, expr: &Expr) { ); if checker.patch(diagnostic.kind.rule()) { if let Some(content) = elts_to_csv(elts, checker) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( content, expr.range(), @@ -372,6 +378,7 @@ fn handle_single_name(checker: &mut Checker, expr: &Expr, value: &Expr) { ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(&create_expr(value.node.clone()), checker.stylist), expr.range(), diff --git a/crates/ruff/src/rules/flake8_quotes/rules.rs b/crates/ruff/src/rules/flake8_quotes/rules.rs index 04f7dae9f4788..40ad36859edff 100644 --- a/crates/ruff/src/rules/flake8_quotes/rules.rs +++ b/crates/ruff/src/rules/flake8_quotes/rules.rs @@ -289,6 +289,7 @@ fn docstring( fixed_contents.push_str("e); fixed_contents.push_str(string_contents); fixed_contents.push_str("e); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( fixed_contents, range, @@ -367,6 +368,7 @@ fn strings( fixed_contents.push_str(quote); fixed_contents.push_str(string_contents); fixed_contents.push_str(quote); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( fixed_contents, *range, @@ -433,6 +435,7 @@ fn strings( fixed_contents.push(quote); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( fixed_contents, *range, @@ -459,6 +462,7 @@ fn strings( fixed_contents.push(quote); fixed_contents.push_str(string_contents); fixed_contents.push(quote); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( fixed_contents, *range, 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 fc4351b7b898c..f7be163548c55 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,6 +34,7 @@ pub fn unnecessary_paren_on_raise_exception(checker: &mut Checker, expr: &Expr) .expect("Expected call to include parentheses"); let mut diagnostic = Diagnostic::new(UnnecessaryParenOnRaiseException, range); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::deletion(func.end(), range.end()))); } checker.diagnostics.push(diagnostic); diff --git a/crates/ruff/src/rules/flake8_return/rules.rs b/crates/ruff/src/rules/flake8_return/rules.rs index c37286b6d8cb7..f9bd06734e6f9 100644 --- a/crates/ruff/src/rules/flake8_return/rules.rs +++ b/crates/ruff/src/rules/flake8_return/rules.rs @@ -341,6 +341,7 @@ fn unnecessary_return_none(checker: &mut Checker, stack: &Stack) { } let mut diagnostic = Diagnostic::new(UnnecessaryReturnNone, stmt.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "return".to_string(), stmt.range(), @@ -358,6 +359,7 @@ fn implicit_return_value(checker: &mut Checker, stack: &Stack) { } let mut diagnostic = Diagnostic::new(ImplicitReturnValue, stmt.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "return None".to_string(), stmt.range(), @@ -415,6 +417,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) { content.push_str(checker.stylist.line_ending().as_str()); content.push_str(indent); content.push_str("return None"); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::insertion( content, end_of_last_statement(stmt, checker.locator), @@ -453,6 +456,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) { content.push_str(checker.stylist.line_ending().as_str()); content.push_str(indent); content.push_str("return None"); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::insertion( content, end_of_last_statement(stmt, checker.locator), @@ -492,6 +496,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) { content.push_str(checker.stylist.line_ending().as_str()); content.push_str(indent); content.push_str("return None"); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::insertion( content, end_of_last_statement(stmt, checker.locator), 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 289c520b80524..3f505c2a6d319 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 @@ -366,6 +366,7 @@ pub fn duplicate_isinstance_call(checker: &mut Checker, expr: &Expr) { // Populate the `Fix`. Replace the _entire_ `BoolOp`. Note that if we have // multiple duplicates, the fixes will conflict. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(&bool_op, checker.stylist), expr.range(), @@ -468,6 +469,7 @@ pub fn compare_with_tuple(checker: &mut Checker, expr: &Expr) { values: iter::once(in_expr).chain(unmatched).collect(), }) }; + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(&in_expr, checker.stylist), expr.range(), @@ -519,6 +521,7 @@ pub fn expr_and_not_expr(checker: &mut Checker, expr: &Expr) { expr.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "False".to_string(), expr.range(), @@ -572,6 +575,7 @@ pub fn expr_or_not_expr(checker: &mut Checker, expr: &Expr) { expr.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "True".to_string(), expr.range(), @@ -695,6 +699,7 @@ pub fn expr_or_true(checker: &mut Checker, expr: &Expr) { edit.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(edit)); } checker.diagnostics.push(diagnostic); @@ -714,6 +719,7 @@ pub fn expr_and_false(checker: &mut Checker, expr: &Expr) { edit.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(edit)); } checker.diagnostics.push(diagnostic); 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 47eaa9053ae35..2d16d23344753 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_expr.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_expr.rs @@ -137,6 +137,7 @@ fn check_os_environ_subscript(checker: &mut Checker, expr: &Expr) { value: capital_env_var.into(), kind: kind.clone(), }); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(&new_env_var, checker.stylist), slice.range(), @@ -197,6 +198,7 @@ pub fn dict_get_with_none_default(checker: &mut Checker, expr: &Expr) { ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( expected, expr.range(), 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 b24a6a5eb543b..e6e9b5fb27d0f 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs @@ -304,6 +304,7 @@ pub fn nested_if_statements( .universal_newlines() .all(|line| line.width() <= checker.settings.line_length) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(edit)); } } @@ -370,6 +371,7 @@ pub fn needless_bool(checker: &mut Checker, stmt: &Stmt) { if fixable && checker.patch(diagnostic.kind.rule()) { if matches!(test.node, ExprKind::Compare { .. }) { // If the condition is a comparison, we can replace it with the condition. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_stmt( &create_stmt(StmtKind::Return { @@ -382,6 +384,7 @@ pub fn needless_bool(checker: &mut Checker, stmt: &Stmt) { } else { // Otherwise, we need to wrap the condition in a call to `bool`. (We've already // verified, above, that `bool` is a builtin.) + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_stmt( &create_stmt(StmtKind::Return { @@ -528,6 +531,7 @@ pub fn use_ternary_operator(checker: &mut Checker, stmt: &Stmt, parent: Option<& stmt.range(), ); if fixable && checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( contents, stmt.range(), @@ -878,6 +882,7 @@ pub fn use_dict_get_with_default( stmt.range(), ); if fixable && checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( contents, stmt.range(), 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 65890018ca52a..2af780316b67c 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_ifexp.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_ifexp.rs @@ -100,11 +100,13 @@ pub fn explicit_true_false_in_ifexpr( ); if checker.patch(diagnostic.kind.rule()) { if matches!(test.node, ExprKind::Compare { .. }) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(&test.clone(), checker.stylist), expr.range(), ))); } else if checker.ctx.is_builtin("bool") { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr( &create_expr(ExprKind::Call { @@ -152,6 +154,7 @@ pub fn explicit_false_true_in_ifexpr( expr.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr( &create_expr(ExprKind::UnaryOp { @@ -200,6 +203,7 @@ pub fn twisted_arms_in_ifexpr( expr.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr( &create_expr(ExprKind::IfExp { 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 ac110b6a9c876..103e6d28ed0a8 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 @@ -107,6 +107,7 @@ pub fn negation_with_equal_op(checker: &mut Checker, expr: &Expr, op: &Unaryop, expr.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr( &create_expr(ExprKind::Compare { @@ -157,6 +158,7 @@ pub fn negation_with_not_equal_op( expr.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr( &create_expr(ExprKind::Compare { @@ -192,11 +194,13 @@ pub fn double_negation(checker: &mut Checker, expr: &Expr, op: &Unaryop, operand ); if checker.patch(diagnostic.kind.rule()) { if checker.ctx.in_boolean_test { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(operand, checker.stylist), expr.range(), ))); } else if checker.ctx.is_builtin("bool") { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr( &create_expr(ExprKind::Call { 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 d7ddf57f336a7..d7ab2d80892ca 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs @@ -118,6 +118,7 @@ pub fn multiple_with_statements( .universal_newlines() .all(|line| line.width() <= checker.settings.line_length) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(edit)); } } 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 8bed7b02d3252..f8a9fed6d14dc 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,6 +91,7 @@ fn key_in_dict(checker: &mut Checker, left: &Expr, right: &Expr, range: TextRang range, ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( value_content, right.range(), 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 1573f987c0238..08e3ff29a5820 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/reimplemented_builtin.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/reimplemented_builtin.rs @@ -227,6 +227,7 @@ pub fn convert_for_loop_to_any_all(checker: &mut Checker, stmt: &Stmt, sibling: stmt.range(), ); if checker.patch(diagnostic.kind.rule()) && checker.ctx.is_builtin("any") { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::replacement( contents, stmt.start(), @@ -308,6 +309,7 @@ pub fn convert_for_loop_to_any_all(checker: &mut Checker, stmt: &Stmt, sibling: stmt.range(), ); if checker.patch(diagnostic.kind.rule()) && checker.ctx.is_builtin("all") { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::replacement( contents, stmt.start(), diff --git a/crates/ruff/src/rules/flake8_simplify/rules/suppressible_exception.rs b/crates/ruff/src/rules/flake8_simplify/rules/suppressible_exception.rs index e80038fed7860..cae85a79ed52b 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/suppressible_exception.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/suppressible_exception.rs @@ -113,6 +113,7 @@ pub fn suppressible_exception( ); let handler_line_begin = checker.locator.line_start(handler.start()); let remove_handler = Edit::deletion(handler_line_begin, handler.end()); + #[allow(deprecated)] Ok(Fix::unspecified_edits( import_edit, [replace_try, remove_handler], 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 501bbd754b1b3..31dee60304b46 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/yoda_conditions.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/yoda_conditions.rs @@ -161,6 +161,7 @@ pub fn yoda_conditions( expr.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( suggestion, expr.range(), 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 cbbdbe908876f..f8c70eabe5dc1 100644 --- a/crates/ruff/src/rules/flake8_tidy_imports/relative_imports.rs +++ b/crates/ruff/src/rules/flake8_tidy_imports/relative_imports.rs @@ -112,7 +112,7 @@ fn fix_banned_relative_import( }), stylist, ); - + #[allow(deprecated)] Some(Fix::unspecified(Edit::range_replacement( content, stmt.range(), 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 b9348e6c6e16d..455c2d98a1338 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 @@ -74,6 +74,7 @@ pub fn empty_type_checking_block<'a, 'b>( if edit.is_deletion() || edit.content() == Some("pass") { checker.deletions.insert(RefEquality(stmt)); } + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(edit)); } Err(e) => error!("Failed to remove empty type-checking block: {e}"), diff --git a/crates/ruff/src/rules/flynt/rules/static_join_to_fstring.rs b/crates/ruff/src/rules/flynt/rules/static_join_to_fstring.rs index cf9194ba73d65..add76ad1dc89d 100644 --- a/crates/ruff/src/rules/flynt/rules/static_join_to_fstring.rs +++ b/crates/ruff/src/rules/flynt/rules/static_join_to_fstring.rs @@ -87,6 +87,7 @@ pub fn static_join_to_fstring(checker: &mut Checker, expr: &Expr, joiner: &str) expr.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( contents, expr.range(), 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 0baf34d8a4f1b..fc1894c987294 100644 --- a/crates/ruff/src/rules/isort/rules/add_required_imports.rs +++ b/crates/ruff/src/rules/isort/rules/add_required_imports.rs @@ -120,6 +120,7 @@ fn add_required_import( TextRange::default(), ); if autofix.into() && settings.rules.should_fix(Rule::MissingRequiredImport) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified( Importer::new(python_ast, locator, stylist) .add_import(required_import, TextSize::default()), diff --git a/crates/ruff/src/rules/isort/rules/organize_imports.rs b/crates/ruff/src/rules/isort/rules/organize_imports.rs index ff863723f0f20..157f6205b1836 100644 --- a/crates/ruff/src/rules/isort/rules/organize_imports.rs +++ b/crates/ruff/src/rules/isort/rules/organize_imports.rs @@ -148,6 +148,7 @@ pub fn organize_imports( } else { let mut diagnostic = Diagnostic::new(UnsortedImports, range); if autofix.into() && settings.rules.should_fix(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( indent(&expected, indentation), range, 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 73a0353eb8c56..364213f89c0df 100644 --- a/crates/ruff/src/rules/numpy/rules/deprecated_type_alias.rs +++ b/crates/ruff/src/rules/numpy/rules/deprecated_type_alias.rs @@ -70,6 +70,7 @@ pub fn deprecated_type_alias(checker: &mut Checker, expr: &Expr) { expr.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( match type_name { "unicode" => "str", diff --git a/crates/ruff/src/rules/pandas_vet/fixes.rs b/crates/ruff/src/rules/pandas_vet/fixes.rs index 5b10c61c9afe7..e6b5c6e40b55b 100644 --- a/crates/ruff/src/rules/pandas_vet/fixes.rs +++ b/crates/ruff/src/rules/pandas_vet/fixes.rs @@ -40,6 +40,6 @@ pub(super) fn convert_inplace_argument_to_assignment( false, ) .ok()?; - + #[allow(deprecated)] Some(Fix::unspecified_edits(insert_assignment, [remove_argument])) } diff --git a/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs b/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs index f524a7c97ae78..350c9e438112a 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs @@ -164,6 +164,7 @@ pub fn compound_statements( let mut diagnostic = Diagnostic::new(UselessSemicolon, TextRange::new(start, end)); if autofix.into() && settings.rules.should_fix(Rule::UselessSemicolon) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::deletion(start, end))); }; diagnostics.push(diagnostic); 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 ab70c0317723a..5335a8876429b 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/invalid_escape_sequence.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/invalid_escape_sequence.rs @@ -108,6 +108,7 @@ pub fn invalid_escape_sequence( let range = TextRange::at(location, next_char.text_len() + TextSize::from(1)); let mut diagnostic = Diagnostic::new(InvalidEscapeSequence(*next_char), range); if autofix { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::insertion( r"\".to_string(), range.start() + TextSize::from(1), diff --git a/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs b/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs index afd312d3e388d..6f82651ea9b3c 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs @@ -103,6 +103,7 @@ pub fn lambda_assignment( indented.push_str(&line); } } + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( indented, stmt.range(), diff --git a/crates/ruff/src/rules/pycodestyle/rules/literal_comparisons.rs b/crates/ruff/src/rules/pycodestyle/rules/literal_comparisons.rs index 81c09dbafd630..a527688eb487f 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/literal_comparisons.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/literal_comparisons.rs @@ -277,6 +277,7 @@ pub fn literal_comparisons( .collect::>(); let content = compare(left, &ops, comparators, checker.stylist); for diagnostic in &mut diagnostics { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( content.to_string(), expr.range(), diff --git a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs index fe0ff771d4d59..ca635b9a8e70c 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs @@ -86,6 +86,7 @@ pub(crate) fn missing_whitespace( let mut diagnostic = Diagnostic::new(kind, TextRange::empty(token.start())); if autofix { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::insertion( " ".to_string(), token.end(), diff --git a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs index 03f7b4b0d786d..0c5434509c260 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs @@ -63,6 +63,7 @@ pub(crate) fn whitespace_before_parameters( let mut diagnostic = Diagnostic::new(kind, TextRange::new(start, end)); if autofix { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::deletion(start, end))); } context.push_diagnostic(diagnostic); 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 42ab5b76288d8..ccfdba9c94cbc 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 @@ -55,6 +55,7 @@ pub fn no_newline_at_end_of_file( let mut diagnostic = Diagnostic::new(MissingNewlineAtEndOfFile, range); if autofix { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::insertion( stylist.line_ending().to_string(), range.start(), diff --git a/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs b/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs index e13dfbc112083..e1bff68f62b5e 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/not_tests.rs @@ -99,6 +99,7 @@ pub fn not_tests( if check_not_in { let mut diagnostic = Diagnostic::new(NotInTest, operand.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( compare(left, &[Cmpop::NotIn], comparators, checker.stylist), expr.range(), @@ -111,6 +112,7 @@ pub fn not_tests( if check_not_is { let mut diagnostic = Diagnostic::new(NotIsTest, operand.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( compare(left, &[Cmpop::IsNot], comparators, checker.stylist), expr.range(), diff --git a/crates/ruff/src/rules/pycodestyle/rules/trailing_whitespace.rs b/crates/ruff/src/rules/pycodestyle/rules/trailing_whitespace.rs index 5fb88c9e59f14..1125b6e0e9408 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/trailing_whitespace.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/trailing_whitespace.rs @@ -95,6 +95,7 @@ pub(crate) fn trailing_whitespace( if matches!(autofix, flags::Autofix::Enabled) && settings.rules.should_fix(Rule::BlankLineWithWhitespace) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range))); } return Some(diagnostic); @@ -104,6 +105,7 @@ pub(crate) fn trailing_whitespace( if matches!(autofix, flags::Autofix::Enabled) && settings.rules.should_fix(Rule::TrailingWhitespace) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range))); } return Some(diagnostic); 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 05da7ebbdc11d..5fbb28d0e260e 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/blank_after_summary.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/blank_after_summary.rs @@ -82,6 +82,7 @@ pub fn blank_after_summary(checker: &mut Checker, docstring: &Docstring) { } // Insert one blank line after the summary (replacing any existing lines). + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::replacement( checker.stylist.line_ending().to_string(), summary_end, 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 1647219bfaff8..036b1929d055b 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 @@ -94,6 +94,7 @@ pub fn blank_before_after_class(checker: &mut Checker, docstring: &Docstring) { ); if checker.patch(diagnostic.kind.rule()) { // Delete the blank line before the class. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::deletion( blank_lines_start, docstring.start() - docstring.indentation.text_len(), @@ -116,6 +117,7 @@ pub fn blank_before_after_class(checker: &mut Checker, docstring: &Docstring) { ); if checker.patch(diagnostic.kind.rule()) { // Insert one blank line before the class. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::replacement( checker.stylist.line_ending().to_string(), blank_lines_start, @@ -163,6 +165,7 @@ pub fn blank_before_after_class(checker: &mut Checker, docstring: &Docstring) { ); if checker.patch(diagnostic.kind.rule()) { // Insert a blank line before the class (replacing any existing lines). + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::replacement( checker.stylist.line_ending().to_string(), first_line_start, 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 d12ad57414645..46e4261943e4a 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 @@ -88,6 +88,7 @@ pub fn blank_before_after_function(checker: &mut Checker, docstring: &Docstring) ); if checker.patch(diagnostic.kind.rule()) { // Delete the blank line before the docstring. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::deletion( blank_lines_start, docstring.start() - docstring.indentation.text_len(), @@ -149,6 +150,7 @@ pub fn blank_before_after_function(checker: &mut Checker, docstring: &Docstring) ); if checker.patch(diagnostic.kind.rule()) { // Delete the blank line after the docstring. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::deletion( first_line_end, blank_lines_end, diff --git a/crates/ruff/src/rules/pydocstyle/rules/capitalized.rs b/crates/ruff/src/rules/pydocstyle/rules/capitalized.rs index e588d7df24b3e..32c92d9d03c88 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/capitalized.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/capitalized.rs @@ -71,6 +71,7 @@ pub fn capitalized(checker: &mut Checker, docstring: &Docstring) { ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( capitalized_word, TextRange::at(body.start(), first_word.text_len()), 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 bdbf461c3dfd2..cf9c76f0a90be 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/ends_with_period.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/ends_with_period.rs @@ -64,6 +64,7 @@ pub fn ends_with_period(checker: &mut Checker, docstring: &Docstring) { && !trimmed.ends_with(':') && !trimmed.ends_with(';') { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::insertion( ".".to_string(), line.start() + trimmed.text_len(), 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 d123cbe6fd9ab..0c2c06661e154 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/ends_with_punctuation.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/ends_with_punctuation.rs @@ -61,6 +61,7 @@ pub fn ends_with_punctuation(checker: &mut Checker, docstring: &Docstring) { let mut diagnostic = Diagnostic::new(EndsInPunctuation, docstring.range()); // Best-effort autofix: avoid adding a period after other punctuation marks. if checker.patch(diagnostic.kind.rule()) && !trimmed.ends_with([':', ';']) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::insertion( ".".to_string(), line.start() + trimmed.text_len(), diff --git a/crates/ruff/src/rules/pydocstyle/rules/indent.rs b/crates/ruff/src/rules/pydocstyle/rules/indent.rs index c932051aa6ec0..f1ca1f987f693 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/indent.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/indent.rs @@ -90,6 +90,7 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) { let mut diagnostic = Diagnostic::new(UnderIndentation, TextRange::empty(line.start())); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( whitespace::clean(docstring.indentation), TextRange::at(line.start(), line_indent.text_len()), @@ -138,6 +139,7 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) { } else { Edit::range_replacement(new_indent, over_indented) }; + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(edit)); } checker.diagnostics.push(diagnostic); @@ -151,6 +153,7 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) { let mut diagnostic = Diagnostic::new(OverIndentation, TextRange::empty(last.start())); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( whitespace::clean(docstring.indentation), TextRange::at(last.start(), line_indent.text_len()), 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 6275913a1f185..93c766e0a03a2 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 @@ -67,6 +67,7 @@ pub fn multi_line_summary_start(checker: &mut Checker, docstring: &Docstring) { // Delete until first non-whitespace char. for line in content_lines { if let Some(end_column) = line.find(|c: char| !c.is_whitespace()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::deletion( first_line.end(), line.start() + TextSize::try_from(end_column).unwrap(), @@ -123,6 +124,7 @@ pub fn multi_line_summary_start(checker: &mut Checker, docstring: &Docstring) { first_line.strip_prefix(prefix).unwrap().trim_start() ); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::replacement( repl, body.start(), 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 912c03b7e7f1d..aa435172cc81b 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 @@ -56,6 +56,7 @@ pub fn newline_after_last_paragraph(checker: &mut Checker, docstring: &Docstring checker.stylist.line_ending().as_str(), whitespace::clean(docstring.indentation) ); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::replacement( content, docstring.expr.end() - num_trailing_quotes - num_trailing_spaces, 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 f07e94799f51b..1e5a2d5cc3b41 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs @@ -44,6 +44,7 @@ pub fn no_surrounding_whitespace(checker: &mut Checker, docstring: &Docstring) { // characters, avoid applying the fix. if !trimmed.ends_with(quote) && !trimmed.starts_with(quote) && !ends_with_backslash(trimmed) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( trimmed.to_string(), TextRange::at(body.start(), line.text_len()), diff --git a/crates/ruff/src/rules/pydocstyle/rules/one_liner.rs b/crates/ruff/src/rules/pydocstyle/rules/one_liner.rs index bafd15898cca3..f578e481c4ed5 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/one_liner.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/one_liner.rs @@ -49,6 +49,7 @@ pub fn one_liner(checker: &mut Checker, docstring: &Docstring) { if !trimmed.ends_with(trailing.chars().last().unwrap()) && !trimmed.starts_with(leading.chars().last().unwrap()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( format!("{leading}{trimmed}{trailing}"), docstring.range(), diff --git a/crates/ruff/src/rules/pydocstyle/rules/sections.rs b/crates/ruff/src/rules/pydocstyle/rules/sections.rs index 1daabe9dc95df..fa726e99f2c2a 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/sections.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/sections.rs @@ -373,6 +373,7 @@ fn blanks_and_section_underline( let range = TextRange::new(context.following_range().start(), blank_lines_end); // Delete any blank lines between the header and the underline. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range))); } checker.diagnostics.push(diagnostic); @@ -405,6 +406,7 @@ fn blanks_and_section_underline( "-".repeat(context.section_name().len()), checker.stylist.line_ending().as_str() ); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::replacement( content, blank_lines_end, @@ -435,6 +437,7 @@ fn blanks_and_section_underline( ); // Replace the existing indentation with whitespace of the appropriate length. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( whitespace::clean(docstring.indentation), range, @@ -478,6 +481,7 @@ fn blanks_and_section_underline( ); if checker.patch(diagnostic.kind.rule()) { // Delete any blank lines between the header and content. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::deletion( line_after_dashes.start(), blank_lines_after_dashes_end, @@ -516,6 +520,7 @@ fn blanks_and_section_underline( whitespace::clean(docstring.indentation), "-".repeat(context.section_name().len()), ); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::insertion( content, context.summary_range().end(), @@ -539,6 +544,7 @@ fn blanks_and_section_underline( let range = TextRange::new(context.following_range().start(), blank_lines_end); // Delete any blank lines between the header and content. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range))); } checker.diagnostics.push(diagnostic); @@ -568,6 +574,7 @@ fn blanks_and_section_underline( "-".repeat(context.section_name().len()), ); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::insertion( content, context.summary_range().end(), @@ -605,6 +612,7 @@ fn common_section( // Replace the section title with the capitalized variant. This requires // locating the start and end of the section name. let section_range = context.section_name_range(); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( capitalized_section_name.to_string(), section_range, @@ -628,6 +636,7 @@ fn common_section( let content = whitespace::clean(docstring.indentation); let fix_range = TextRange::at(context.range().start(), leading_space.text_len()); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(if content.is_empty() { Edit::range_deletion(fix_range) } else { @@ -655,6 +664,7 @@ fn common_section( ); if checker.patch(diagnostic.kind.rule()) { // Add a newline at the beginning of the next section. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::insertion( line_end.to_string(), next.range().start(), @@ -676,6 +686,7 @@ fn common_section( ); if checker.patch(diagnostic.kind.rule()) { // Add a newline after the section. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::insertion( format!("{}{}", line_end, docstring.indentation), context.range().end(), @@ -700,6 +711,7 @@ fn common_section( ); if checker.patch(diagnostic.kind.rule()) { // Add a blank line before the section. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::insertion( line_end.to_string(), context.range().start(), @@ -902,6 +914,7 @@ fn numpy_section( ); if checker.patch(diagnostic.kind.rule()) { let section_range = context.section_name_range(); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(TextRange::at( section_range.end(), suffix.text_len(), @@ -939,6 +952,7 @@ fn google_section( if checker.patch(diagnostic.kind.rule()) { // Replace the suffix. let section_name_range = context.section_name_range(); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( ":".to_string(), TextRange::at(section_name_range.end(), suffix.text_len()), 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 c98baa5873bdf..4184666bc879f 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 @@ -89,6 +89,7 @@ fn fix_f_string_missing_placeholders( checker: &mut Checker, ) -> Fix { let content = &checker.locator.contents()[TextRange::new(prefix_range.end(), tok_range.end())]; + #[allow(deprecated)] Fix::unspecified(Edit::replacement( unescape_f_string(content), prefix_range.start(), 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 2bd52a0544eaa..630e34efea52c 100644 --- a/crates/ruff/src/rules/pyflakes/rules/invalid_literal_comparisons.rs +++ b/crates/ruff/src/rules/pyflakes/rules/invalid_literal_comparisons.rs @@ -78,6 +78,7 @@ pub fn invalid_literal_comparison( None } } { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( content, located_op.range() + location.start(), 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 504305f651229..541779f42bf57 100644 --- a/crates/ruff/src/rules/pyflakes/rules/raise_not_implemented.rs +++ b/crates/ruff/src/rules/pyflakes/rules/raise_not_implemented.rs @@ -46,6 +46,7 @@ pub fn raise_not_implemented(checker: &mut Checker, expr: &Expr) { }; let mut diagnostic = Diagnostic::new(RaiseNotImplemented, expr.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "NotImplementedError".to_string(), expr.range(), diff --git a/crates/ruff/src/rules/pyflakes/rules/repeated_keys.rs b/crates/ruff/src/rules/pyflakes/rules/repeated_keys.rs index 2231c95e54ed5..4d39e5c4011ea 100644 --- a/crates/ruff/src/rules/pyflakes/rules/repeated_keys.rs +++ b/crates/ruff/src/rules/pyflakes/rules/repeated_keys.rs @@ -109,6 +109,7 @@ pub fn repeated_keys(checker: &mut Checker, keys: &[Option], values: &[Exp ); if is_duplicate_value { if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::deletion( values[i - 1].end(), values[i].end(), @@ -137,6 +138,7 @@ pub fn repeated_keys(checker: &mut Checker, keys: &[Option], values: &[Exp ); if is_duplicate_value { if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::deletion( values[i - 1].end(), values[i].end(), diff --git a/crates/ruff/src/rules/pyflakes/rules/unused_variable.rs b/crates/ruff/src/rules/pyflakes/rules/unused_variable.rs index b27a3ceeac3be..ac0b94676228b 100644 --- a/crates/ruff/src/rules/pyflakes/rules/unused_variable.rs +++ b/crates/ruff/src/rules/pyflakes/rules/unused_variable.rs @@ -204,6 +204,7 @@ fn remove_unused_variable( { // If the expression is complex (`x = foo()`), remove the assignment, // but preserve the right-hand side. + #[allow(deprecated)] Some(( DeletionKind::Partial, Fix::unspecified(Edit::deletion( @@ -224,6 +225,7 @@ fn remove_unused_variable( checker.indexer, checker.stylist, ) { + #[allow(deprecated)] Ok(fix) => Some((DeletionKind::Whole, Fix::unspecified(fix))), Err(err) => { error!("Failed to delete unused variable: {}", err); @@ -246,6 +248,7 @@ fn remove_unused_variable( return if contains_effect(value, |id| checker.ctx.is_builtin(id)) { // If the expression is complex (`x = foo()`), remove the assignment, // but preserve the right-hand side. + #[allow(deprecated)] Some(( DeletionKind::Partial, Fix::unspecified(Edit::deletion( @@ -265,6 +268,7 @@ fn remove_unused_variable( checker.indexer, checker.stylist, ) { + #[allow(deprecated)] Ok(edit) => Some((DeletionKind::Whole, Fix::unspecified(edit))), Err(err) => { error!("Failed to delete unused variable: {}", err); @@ -282,6 +286,7 @@ fn remove_unused_variable( for item in items { if let Some(optional_vars) = &item.optional_vars { if optional_vars.range() == range { + #[allow(deprecated)] return Some(( DeletionKind::Partial, Fix::unspecified(Edit::deletion( 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 0771551a81b71..710763228cb5d 100644 --- a/crates/ruff/src/rules/pylint/rules/invalid_string_characters.rs +++ b/crates/ruff/src/rules/pylint/rules/invalid_string_characters.rs @@ -197,6 +197,7 @@ pub fn invalid_string_characters( let mut diagnostic = Diagnostic::new(rule, range); if autofix { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( replacement.to_string(), range, 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 b32e173b39f13..b5bbbeeb87a78 100644 --- a/crates/ruff/src/rules/pylint/rules/manual_import_from.rs +++ b/crates/ruff/src/rules/pylint/rules/manual_import_from.rs @@ -53,6 +53,7 @@ pub fn manual_from_import(checker: &mut Checker, stmt: &Stmt, alias: &Alias, nam alias.range(), ); if fixable && checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_stmt( &create_stmt(StmtKind::ImportFrom { diff --git a/crates/ruff/src/rules/pylint/rules/nested_min_max.rs b/crates/ruff/src/rules/pylint/rules/nested_min_max.rs index 720fe865cc6ce..147a583099daa 100644 --- a/crates/ruff/src/rules/pylint/rules/nested_min_max.rs +++ b/crates/ruff/src/rules/pylint/rules/nested_min_max.rs @@ -121,6 +121,7 @@ pub fn nested_min_max( keywords: keywords.to_owned(), }, ); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(&flattened_expr, checker.stylist), expr.range(), 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 6cf01f0a4ae22..6ee7507482e94 100644 --- a/crates/ruff/src/rules/pylint/rules/sys_exit_alias.rs +++ b/crates/ruff/src/rules/pylint/rules/sys_exit_alias.rs @@ -55,6 +55,7 @@ pub fn sys_exit_alias(checker: &mut Checker, func: &Expr) { checker.locator, )?; let reference_edit = Edit::range_replacement(binding, func.range()); + #[allow(deprecated)] Ok(Fix::unspecified_edits(import_edit, [reference_edit])) }); } 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 9fcaa5437d718..d2f4aeacc008e 100644 --- a/crates/ruff/src/rules/pylint/rules/useless_import_alias.rs +++ b/crates/ruff/src/rules/pylint/rules/useless_import_alias.rs @@ -49,6 +49,7 @@ pub fn useless_import_alias(checker: &mut Checker, alias: &Alias) { let mut diagnostic = Diagnostic::new(UselessImportAlias, alias.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( asname.to_string(), alias.range(), diff --git a/crates/ruff/src/rules/pylint/rules/useless_return.rs b/crates/ruff/src/rules/pylint/rules/useless_return.rs index d847a0d216c9b..e53289c5f85b0 100644 --- a/crates/ruff/src/rules/pylint/rules/useless_return.rs +++ b/crates/ruff/src/rules/pylint/rules/useless_return.rs @@ -120,6 +120,7 @@ pub fn useless_return<'a>( if edit.is_deletion() || edit.content() == Some("pass") { checker.deletions.insert(RefEquality(last_stmt)); } + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(edit)); } Err(e) => { 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 736aafd86b103..237c1be4feb60 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 @@ -163,6 +163,7 @@ fn convert_to_class( base_class: &Expr, stylist: &Stylist, ) -> Fix { + #[allow(deprecated)] Fix::unspecified(Edit::range_replacement( unparse_stmt(&create_class_def_stmt(typename, body, base_class), stylist), stmt.range(), 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 6c3fffd7ae490..dee89608fca61 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 @@ -210,6 +210,7 @@ fn convert_to_class( base_class: &Expr, stylist: &Stylist, ) -> Fix { + #[allow(deprecated)] Fix::unspecified(Edit::range_replacement( unparse_stmt( &create_class_def_stmt(class_name, body, total_keyword, base_class), 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 945a5d1c37582..6548bffb4ab42 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/datetime_utc_alias.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/datetime_utc_alias.rs @@ -44,6 +44,7 @@ pub fn datetime_utc_alias(checker: &mut Checker, expr: &Expr) { let mut diagnostic = Diagnostic::new(DatetimeTimezoneUTC { straight_import }, expr.range()); if checker.patch(diagnostic.kind.rule()) { if straight_import { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "datetime.UTC".to_string(), expr.range(), 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 b79f6167b43d6..6b573261bd518 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 @@ -24,6 +24,7 @@ fn add_check_for_node(checker: &mut Checker, node: &Located) { let mut diagnostic = Diagnostic::new(DeprecatedCElementTree, node.range()); if checker.patch(diagnostic.kind.rule()) { let contents = checker.locator.slice(node.range()); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( contents.replacen("cElementTree", "ElementTree", 1), node.range(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs b/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs index 743d503667ff4..40af7306db928 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs @@ -551,6 +551,7 @@ pub fn deprecated_import( ); if checker.patch(Rule::DeprecatedImport) { if let Some(content) = fix { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( content, stmt.range(), 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 54af47c0e938a..61daf5e2a7636 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_mock_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_mock_import.rs @@ -257,6 +257,7 @@ pub fn deprecated_mock_attribute(checker: &mut Checker, expr: &Expr) { value.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "mock".to_string(), value.range(), @@ -303,6 +304,7 @@ pub fn deprecated_mock_import(checker: &mut Checker, stmt: &Stmt) { name.range(), ); if let Some(content) = content.as_ref() { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( content.clone(), stmt.range(), 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 1d4869212cb05..b079bc86d22ae 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs @@ -69,6 +69,7 @@ pub fn deprecated_unittest_alias(checker: &mut Checker, expr: &Expr) { expr.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( format!("self.{target}"), expr.range(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/extraneous_parentheses.rs b/crates/ruff/src/rules/pyupgrade/rules/extraneous_parentheses.rs index 97b64e002a921..195cdea7dba04 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/extraneous_parentheses.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/extraneous_parentheses.rs @@ -142,6 +142,7 @@ pub fn extraneous_parentheses( if autofix.into() && settings.rules.should_fix(Rule::ExtraneousParentheses) { let contents = locator.slice(TextRange::new(start_range.start(), end_range.end())); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::replacement( contents[1..contents.len() - 1].to_string(), start_range.start(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs b/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs index ad8b6d0d38653..620ea7449a3cb 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs @@ -277,6 +277,7 @@ pub(crate) fn f_strings(checker: &mut Checker, summary: &FormatSummary, expr: &E let mut diagnostic = Diagnostic::new(FString, expr.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( contents, expr.range(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/format_literals.rs b/crates/ruff/src/rules/pyupgrade/rules/format_literals.rs index 4b36d730f931a..daadea88ce834 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/format_literals.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/format_literals.rs @@ -145,6 +145,7 @@ pub(crate) fn format_literals(checker: &mut Checker, summary: &FormatSummary, ex if let Ok(contents) = generate_call(expr, &summary.indices, checker.locator, checker.stylist) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( contents, expr.range(), 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 106ca42d2bb18..9be90ee11cdc2 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 @@ -68,6 +68,7 @@ pub fn lru_cache_with_maxsize_none(checker: &mut Checker, decorator_list: &[Expr checker.locator, )?; let reference_edit = Edit::range_replacement(binding, expr.range()); + #[allow(deprecated)] Ok(Fix::unspecified_edits(import_edit, [reference_edit])) }); } 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 3e29da6ecbe75..d341cd211fc11 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,6 +48,7 @@ pub fn lru_cache_without_parameters(checker: &mut Checker, decorator_list: &[Exp TextRange::new(func.end(), expr.end()), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(func, checker.stylist), expr.range(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/native_literals.rs b/crates/ruff/src/rules/pyupgrade/rules/native_literals.rs index 2dc00e05e1ff3..c607f3388193d 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/native_literals.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/native_literals.rs @@ -64,6 +64,7 @@ pub fn native_literals( LiteralType::Bytes }}, expr.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( if id == "bytes" { let mut content = String::with_capacity(3); @@ -127,6 +128,7 @@ pub fn native_literals( expr.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( arg_code.to_string(), expr.range(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/open_alias.rs b/crates/ruff/src/rules/pyupgrade/rules/open_alias.rs index 0cba70739d792..4f3578bf426d3 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/open_alias.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/open_alias.rs @@ -38,6 +38,7 @@ pub fn open_alias(checker: &mut Checker, expr: &Expr, func: &Expr) { .map_or(true, |binding| binding.kind.is_builtin()); let mut diagnostic = Diagnostic::new(OpenAlias { fixable }, expr.range()); if fixable && checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "open".to_string(), func.range(), 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 92341af96383a..24de8961fa161 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/os_error_alias.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/os_error_alias.rs @@ -63,6 +63,7 @@ fn atom_diagnostic(checker: &mut Checker, target: &Expr) { target.range(), ); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "OSError".to_string(), target.range(), @@ -103,11 +104,13 @@ fn tuple_diagnostic(checker: &mut Checker, target: &Expr, aliases: &[&Expr]) { } if remaining.len() == 1 { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "OSError".to_string(), target.range(), ))); } else { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( format!( "({})", 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 29e2d346a8f07..8299e999928ea 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/outdated_version_block.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/outdated_version_block.rs @@ -177,6 +177,7 @@ fn fix_py2_block( ) { Ok(edit) => { checker.deletions.insert(RefEquality(defined_by)); + #[allow(deprecated)] Some(Fix::unspecified(edit)) } Err(err) => { @@ -193,6 +194,7 @@ fn fix_py2_block( if indentation(checker.locator, start).is_none() { // Inline `else` block (e.g., `else: x = 1`). + #[allow(deprecated)] Some(Fix::unspecified(Edit::range_replacement( checker .locator @@ -212,6 +214,7 @@ fn fix_py2_block( .ok() }) .map(|contents| { + #[allow(deprecated)] Fix::unspecified(Edit::replacement( contents, checker.locator.line_start(stmt.start()), @@ -233,6 +236,7 @@ fn fix_py2_block( end_location = body.last().unwrap().end(); } } + #[allow(deprecated)] Some(Fix::unspecified(Edit::deletion(stmt.start(), end_location))) } } @@ -254,6 +258,7 @@ fn fix_py3_block( if indentation(checker.locator, start).is_none() { // Inline `if` block (e.g., `if ...: x = 1`). + #[allow(deprecated)] Some(Fix::unspecified(Edit::range_replacement( checker .locator @@ -273,6 +278,7 @@ fn fix_py3_block( .ok() }) .map(|contents| { + #[allow(deprecated)] Fix::unspecified(Edit::replacement( contents, checker.locator.line_start(stmt.start()), @@ -286,6 +292,7 @@ fn fix_py3_block( // the rest. let end = body.last().unwrap(); let text = checker.locator.slice(TextRange::new(test.end(), end.end())); + #[allow(deprecated)] Some(Fix::unspecified(Edit::range_replacement( format!("else{text}"), stmt.range(), 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 5ad27adf3d97b..a9923d86a1b58 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/printf_string_formatting.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/printf_string_formatting.rs @@ -444,6 +444,7 @@ pub(crate) fn printf_string_formatting( let mut diagnostic = Diagnostic::new(PrintfStringFormatting, expr.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( contents, expr.range(), diff --git a/crates/ruff/src/rules/pyupgrade/rules/quoted_annotation.rs b/crates/ruff/src/rules/pyupgrade/rules/quoted_annotation.rs index 5ab670a612565..5f5f29422b551 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/quoted_annotation.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/quoted_annotation.rs @@ -23,6 +23,7 @@ impl AlwaysAutofixableViolation for QuotedAnnotation { pub fn quoted_annotation(checker: &mut Checker, annotation: &str, range: TextRange) { let mut diagnostic = Diagnostic::new(QuotedAnnotation, range); if checker.patch(Rule::QuotedAnnotation) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( annotation.to_string(), range, 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 f63a5377d7999..aed1012f2de73 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/redundant_open_modes.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/redundant_open_modes.rs @@ -116,6 +116,7 @@ fn create_check( ); if patch { if let Some(content) = replacement_value { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( content.to_string(), mode_param.range(), 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 6f2a6e64e1663..88069dc908f66 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/replace_stdout_stderr.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/replace_stdout_stderr.rs @@ -38,6 +38,7 @@ fn generate_fix( } else { (stderr, stdout) }; + #[allow(deprecated)] Ok(Fix::unspecified_edits( Edit::range_replacement("capture_output=True".to_string(), first.range()), [remove_argument( 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 8278b99e12330..2a050167ce0ca 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/replace_universal_newlines.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/replace_universal_newlines.rs @@ -35,6 +35,7 @@ pub fn replace_universal_newlines(checker: &mut Checker, func: &Expr, kwargs: &[ let range = TextRange::at(kwarg.start(), "universal_newlines".text_len()); let mut diagnostic = Diagnostic::new(ReplaceUniversalNewlines, range); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "text".to_string(), range, 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 7be7cc65d03e3..d5ef517b85fd0 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 @@ -97,6 +97,7 @@ pub fn super_call_with_parameters(checker: &mut Checker, expr: &Expr, func: &Exp let mut diagnostic = Diagnostic::new(SuperCallWithParameters, expr.range()); if checker.patch(diagnostic.kind.rule()) { if let Some(edit) = fixes::remove_super_arguments(checker.locator, checker.stylist, expr) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(edit)); } } 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 46c5f60d207e8..29f66b5fb74a1 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/type_of_primitive.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/type_of_primitive.rs @@ -46,6 +46,7 @@ pub fn type_of_primitive(checker: &mut Checker, expr: &Expr, func: &Expr, args: }; let mut diagnostic = Diagnostic::new(TypeOfPrimitive { primitive }, expr.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( primitive.builtin(), expr.range(), 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 b4f1fb3f33cb4..bd8b49fdc9481 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 @@ -31,6 +31,7 @@ pub fn typing_text_str_alias(checker: &mut Checker, expr: &Expr) { { let mut diagnostic = Diagnostic::new(TypingTextStrAlias, expr.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( "str".to_string(), expr.range(), 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 b8b8ce1cd78e7..258072053b9b6 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unicode_kind_prefix.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unicode_kind_prefix.rs @@ -27,6 +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, expr.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(TextRange::at( expr.start(), TextSize::from(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 af1498b6abb47..a9c57f2fed2fc 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs @@ -125,6 +125,7 @@ pub fn unnecessary_builtin_import( if edit.is_deletion() || edit.content() == Some("pass") { checker.deletions.insert(RefEquality(defined_by)); } + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(edit)); } 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 cfde7270230f4..230b5bad0d705 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs @@ -30,6 +30,7 @@ pub(crate) fn unnecessary_coding_comment(line: &Line, autofix: bool) -> Option Fix { } prev = range.end(); } + #[allow(deprecated)] Fix::unspecified(Edit::range_replacement(replacement, expr.range())) } 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 67991d30fe343..4aea314746c18 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unnecessary_future_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unnecessary_future_import.rs @@ -105,6 +105,7 @@ pub fn unnecessary_future_import(checker: &mut Checker, stmt: &Stmt, names: &[Lo if fix.is_deletion() || fix.content() == Some("pass") { checker.deletions.insert(RefEquality(defined_by)); } + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(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 5ea5c09d39549..1c76299241165 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs @@ -101,6 +101,7 @@ pub fn unpacked_list_comprehension(checker: &mut Checker, targets: &[Expr], valu content.push('('); content.push_str(&existing[1..existing.len() - 1]); content.push(')'); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( content, value.range(), 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 e0dae81068ec9..6d44c807f9b8b 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/use_pep585_annotation.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/use_pep585_annotation.rs @@ -55,6 +55,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) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( binding, expr.range(), 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 26e1205dd9565..5820321193087 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/use_pep604_annotation.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/use_pep604_annotation.rs @@ -112,6 +112,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s TypingMember::Optional => { let mut diagnostic = Diagnostic::new(NonPEP604Annotation { fixable }, expr.range()); if fixable && checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(&optional(slice), checker.stylist), expr.range(), @@ -127,6 +128,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s // Invalid type annotation. } ExprKind::Tuple { elts, .. } => { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(&union(elts), checker.stylist), expr.range(), @@ -134,6 +136,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s } _ => { // Single argument. + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(slice, checker.stylist), expr.range(), 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 ebef3e11825f1..bd330a41e1a90 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/use_pep604_isinstance.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/use_pep604_isinstance.rs @@ -93,6 +93,7 @@ pub fn use_pep604_isinstance(checker: &mut Checker, expr: &Expr, func: &Expr, ar let mut diagnostic = Diagnostic::new(NonPEP604Isinstance { kind }, expr.range()); if checker.patch(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( unparse_expr(&union(elts), checker.stylist), types.range(), 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 be871babb6b38..af024faf21e34 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/useless_metaclass_type.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/useless_metaclass_type.rs @@ -65,6 +65,7 @@ pub fn useless_metaclass_type(checker: &mut Checker, stmt: &Stmt, value: &Expr, if edit.is_deletion() || edit.content() == Some("pass") { checker.deletions.insert(RefEquality(defined_by)); } + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(edit)); } Err(e) => error!("Failed to fix remove metaclass type: {e}"), 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 d60a434c9167a..ab847b146c69b 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,6 +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.range()); let contents = format!("yield from {contents}"); + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( contents, item.stmt.range(), 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 736eb974f1fae..56377a7d2d4ac 100644 --- a/crates/ruff/src/rules/ruff/rules/ambiguous_unicode_character.rs +++ b/crates/ruff/src/rules/ruff/rules/ambiguous_unicode_character.rs @@ -136,6 +136,7 @@ pub fn ambiguous_unicode_character( ); if settings.rules.enabled(diagnostic.kind.rule()) { if autofix.into() && settings.rules.should_fix(diagnostic.kind.rule()) { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( (representant as char).to_string(), char_range, 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 eaeee2324c1ba..4a383643b0c68 100644 --- a/crates/ruff/src/rules/ruff/rules/collection_literal_concatenation.rs +++ b/crates/ruff/src/rules/ruff/rules/collection_literal_concatenation.rs @@ -108,6 +108,7 @@ pub fn collection_literal_concatenation(checker: &mut Checker, expr: &Expr) { ); if checker.patch(diagnostic.kind.rule()) { if fixable { + #[allow(deprecated)] diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( contents, expr.range(), diff --git a/crates/ruff_diagnostics/src/diagnostic.rs b/crates/ruff_diagnostics/src/diagnostic.rs index 4c1569db2735c..5051fe8cb1273 100644 --- a/crates/ruff_diagnostics/src/diagnostic.rs +++ b/crates/ruff_diagnostics/src/diagnostic.rs @@ -47,6 +47,7 @@ impl Diagnostic { /// Set the [`Fix`] used to fix the diagnostic. #[inline] #[deprecated(note = "Use `Diagnostic::set_fix` instead.")] + #[allow(deprecated)] pub fn set_fix_from_edit(&mut self, edit: Edit) { self.fix = Some(Fix::unspecified(edit)); } @@ -62,6 +63,7 @@ impl Diagnostic { /// Set the [`Fix`] used to fix the diagnostic, if the provided function returns `Ok`. /// Otherwise, log the error. #[inline] + #[allow(deprecated)] pub fn try_set_fix(&mut self, func: impl FnOnce() -> Result) { match func() { Ok(fix) => self.fix = Some(fix), @@ -73,6 +75,7 @@ impl Diagnostic { /// Otherwise, log the error. #[inline] #[deprecated(note = "Use Diagnostic::try_set_fix instead")] + #[allow(deprecated)] pub fn try_set_fix_from_edit(&mut self, func: impl FnOnce() -> Result) { match func() { Ok(edit) => self.fix = Some(Fix::unspecified(edit)), diff --git a/crates/ruff_diagnostics/src/fix.rs b/crates/ruff_diagnostics/src/fix.rs index f454b1b96850a..2769fca88c643 100644 --- a/crates/ruff_diagnostics/src/fix.rs +++ b/crates/ruff_diagnostics/src/fix.rs @@ -4,23 +4,105 @@ use serde::{Deserialize, Serialize}; use crate::edit::Edit; +/// Indicates confidence in the correctness of a suggested fix. +#[derive(Default, Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum Applicability { + /// The fix is definitely what the user intended, or maintains the exact meaning of the code. + /// This fix should be automatically applied. + Automatic, + + /// The fix may be what the user intended, but it is uncertain. + /// The fix should result in valid code if it is applied. + /// The fix can be applied with user opt-in. + Suggested, + + /// The fix has a good chance of being incorrect or the code be incomplete. + /// The fix may result in invalid code if it is applied. + /// The fix should only be manually applied by the user. + Manual, + + /// The applicability of the fix is unknown. + #[default] + Unspecified, +} + /// A collection of [`Edit`] elements to be applied to a source file. #[derive(Debug, PartialEq, Eq, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Fix { edits: Vec, + applicability: Applicability, } impl Fix { /// Create a new [`Fix`] with an unspecified applicability from an [`Edit`] element. + #[deprecated( + note = "Use `Fix::automatic`, `Fix::suggested`, or `Fix::manual` instead to specify an applicability." + )] pub fn unspecified(edit: Edit) -> Self { - Self { edits: vec![edit] } + Self { + edits: vec![edit], + applicability: Applicability::Unspecified, + } } - /// Create a new [`Fix`] with unspecified applicability from multiple [`Edit`] elements. + /// Create a new [`Fix`] with an unspecified applicability from multiple [`Edit`] elements. + #[deprecated( + note = "Use `Fix::automatic_edits`, `Fix::suggested_edits`, or `Fix::manual_edits` instead to specify an applicability." + )] pub fn unspecified_edits(edit: Edit, rest: impl IntoIterator) -> Self { Self { edits: std::iter::once(edit).chain(rest.into_iter()).collect(), + applicability: Applicability::Unspecified, + } + } + + /// Create a new [`Fix`] with [automatic applicability](Applicability::Automatic) from an [`Edit`] element. + pub fn automatic(edit: Edit) -> Self { + Self { + edits: vec![edit], + applicability: Applicability::Automatic, + } + } + + /// Create a new [`Fix`] with [automatic applicability](Applicability::Automatic) from multiple [`Edit`] elements. + pub fn automatic_edits(edit: Edit, rest: impl IntoIterator) -> Self { + Self { + edits: std::iter::once(edit).chain(rest.into_iter()).collect(), + applicability: Applicability::Automatic, + } + } + + /// Create a new [`Fix`] with [suggested applicability](Applicability::Suggested) from an [`Edit`] element. + pub fn suggested(edit: Edit) -> Self { + Self { + edits: vec![edit], + applicability: Applicability::Suggested, + } + } + + /// Create a new [`Fix`] with [suggested applicability](Applicability::Suggested) from multiple [`Edit`] elements. + pub fn suggested_edits(edit: Edit, rest: impl IntoIterator) -> Self { + Self { + edits: std::iter::once(edit).chain(rest.into_iter()).collect(), + applicability: Applicability::Suggested, + } + } + + /// Create a new [`Fix`] with [manual applicability](Applicability::Manual) from an [`Edit`] element. + pub fn manual(edit: Edit) -> Self { + Self { + edits: vec![edit], + applicability: Applicability::Manual, + } + } + + /// Create a new [`Fix`] with [manual applicability](Applicability::Manual) from multiple [`Edit`] elements. + pub fn manual_edits(edit: Edit, rest: impl IntoIterator) -> Self { + Self { + edits: std::iter::once(edit).chain(rest.into_iter()).collect(), + applicability: Applicability::Manual, } } @@ -37,4 +119,8 @@ impl Fix { pub fn into_edits(self) -> Vec { self.edits } + + pub fn applicability(&self) -> Applicability { + self.applicability + } } diff --git a/crates/ruff_diagnostics/src/lib.rs b/crates/ruff_diagnostics/src/lib.rs index b3b1ee2567a51..f8935258f7e8d 100644 --- a/crates/ruff_diagnostics/src/lib.rs +++ b/crates/ruff_diagnostics/src/lib.rs @@ -1,6 +1,6 @@ pub use diagnostic::{Diagnostic, DiagnosticKind}; pub use edit::Edit; -pub use fix::Fix; +pub use fix::{Applicability, Fix}; pub use violation::{AlwaysAutofixableViolation, AutofixKind, Violation}; mod diagnostic;