diff --git a/crates/ruff/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs b/crates/ruff/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs index 737c55e6a1ba0..f00986155f083 100644 --- a/crates/ruff/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs +++ b/crates/ruff/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs @@ -170,8 +170,7 @@ pub(crate) fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) { range: TextRange::default(), }); let bool_op = node; - #[allow(deprecated)] - diagnostic.set_fix(Fix::unspecified(Edit::range_replacement( + diagnostic.set_fix(Fix::suggested(Edit::range_replacement( checker.generator().expr(&bool_op), expr.range(), ))); diff --git a/crates/ruff/src/rules/flake8_pie/rules/no_unnecessary_pass.rs b/crates/ruff/src/rules/flake8_pie/rules/no_unnecessary_pass.rs index 70befdbe47e32..7b08ed371f1dc 100644 --- a/crates/ruff/src/rules/flake8_pie/rules/no_unnecessary_pass.rs +++ b/crates/ruff/src/rules/flake8_pie/rules/no_unnecessary_pass.rs @@ -69,8 +69,7 @@ pub(crate) 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( + diagnostic.set_fix(Fix::automatic(Edit::range_deletion( pass_stmt.range().add_end(index), ))); } else { diff --git a/crates/ruff/src/rules/flake8_pie/rules/reimplemented_list_builtin.rs b/crates/ruff/src/rules/flake8_pie/rules/reimplemented_list_builtin.rs index 8c7f180c3a1c3..c7e562a36a548 100644 --- a/crates/ruff/src/rules/flake8_pie/rules/reimplemented_list_builtin.rs +++ b/crates/ruff/src/rules/flake8_pie/rules/reimplemented_list_builtin.rs @@ -1,6 +1,6 @@ use rustpython_parser::ast::{self, Expr, ExprLambda, Ranged}; -use ruff_diagnostics::AlwaysAutofixableViolation; +use ruff_diagnostics::{AutofixKind, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; @@ -38,14 +38,16 @@ use crate::registry::AsRule; #[violation] pub struct ReimplementedListBuiltin; -impl AlwaysAutofixableViolation for ReimplementedListBuiltin { +impl Violation for ReimplementedListBuiltin { + const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + #[derive_message_formats] fn message(&self) -> String { format!("Prefer `list` over useless lambda") } - fn autofix_title(&self) -> String { - "Replace with `list`".to_string() + fn autofix_title(&self) -> Option { + Some("Replace with `list`".to_string()) } } @@ -67,11 +69,12 @@ pub(crate) fn reimplemented_list_builtin(checker: &mut Checker, expr: &ExprLambd 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(), - ))); + if checker.semantic_model().is_builtin("list") { + diagnostic.set_fix(Fix::automatic(Edit::range_replacement( + "list".to_string(), + expr.range(), + ))); + } } checker.diagnostics.push(diagnostic); } diff --git a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE790_PIE790.py.snap b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE790_PIE790.py.snap index 1d8eb9f4d8d82..556ed22ec7030 100644 --- a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE790_PIE790.py.snap +++ b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE790_PIE790.py.snap @@ -307,7 +307,7 @@ PIE790.py:101:5: PIE790 [*] Unnecessary `pass` statement | = help: Remove unnecessary `pass` -ℹ Suggested fix +ℹ Fix 98 98 | 99 99 | def foo() -> None: 100 100 | """buzz""" diff --git a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE807_PIE807.py.snap b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE807_PIE807.py.snap index 82bc88464a418..dcd6048509daf 100644 --- a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE807_PIE807.py.snap +++ b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE807_PIE807.py.snap @@ -10,7 +10,7 @@ PIE807.py:3:44: PIE807 [*] Prefer `list` over useless lambda | = help: Replace with `list` -ℹ Suggested fix +ℹ Fix 1 1 | @dataclass 2 2 | class Foo: 3 |- foo: List[str] = field(default_factory=lambda: []) # PIE807 @@ -27,7 +27,7 @@ PIE807.py:7:36: PIE807 [*] Prefer `list` over useless lambda | = help: Replace with `list` -ℹ Suggested fix +ℹ Fix 4 4 | 5 5 | 6 6 | class FooTable(BaseTable): @@ -45,7 +45,7 @@ PIE807.py:11:28: PIE807 [*] Prefer `list` over useless lambda | = help: Replace with `list` -ℹ Suggested fix +ℹ Fix 8 8 | 9 9 | 10 10 | class FooTable(BaseTable):