Skip to content

Commit dcd2bfa

Browse files
authored
Migrate flake8_pie autofix rules from unspecified to suggested and automatic (#4621)
1 parent f0e173d commit dcd2bfa

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

crates/ruff/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ pub(crate) fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) {
170170
range: TextRange::default(),
171171
});
172172
let bool_op = node;
173-
#[allow(deprecated)]
174-
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
173+
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
175174
checker.generator().expr(&bool_op),
176175
expr.range(),
177176
)));

crates/ruff/src/rules/flake8_pie/rules/no_unnecessary_pass.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ pub(crate) fn no_unnecessary_pass(checker: &mut Checker, body: &[Stmt]) {
6969
let mut diagnostic = Diagnostic::new(UnnecessaryPass, pass_stmt.range());
7070
if checker.patch(diagnostic.kind.rule()) {
7171
if let Some(index) = trailing_comment_start_offset(pass_stmt, checker.locator) {
72-
#[allow(deprecated)]
73-
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(
72+
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(
7473
pass_stmt.range().add_end(index),
7574
)));
7675
} else {

crates/ruff/src/rules/flake8_pie/rules/reimplemented_list_builtin.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustpython_parser::ast::{self, Expr, ExprLambda, Ranged};
22

3-
use ruff_diagnostics::AlwaysAutofixableViolation;
3+
use ruff_diagnostics::{AutofixKind, Violation};
44
use ruff_diagnostics::{Diagnostic, Edit, Fix};
55
use ruff_macros::{derive_message_formats, violation};
66

@@ -38,14 +38,16 @@ use crate::registry::AsRule;
3838
#[violation]
3939
pub struct ReimplementedListBuiltin;
4040

41-
impl AlwaysAutofixableViolation for ReimplementedListBuiltin {
41+
impl Violation for ReimplementedListBuiltin {
42+
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
43+
4244
#[derive_message_formats]
4345
fn message(&self) -> String {
4446
format!("Prefer `list` over useless lambda")
4547
}
4648

47-
fn autofix_title(&self) -> String {
48-
"Replace with `list`".to_string()
49+
fn autofix_title(&self) -> Option<String> {
50+
Some("Replace with `list`".to_string())
4951
}
5052
}
5153

@@ -67,11 +69,12 @@ pub(crate) fn reimplemented_list_builtin(checker: &mut Checker, expr: &ExprLambd
6769
if elts.is_empty() {
6870
let mut diagnostic = Diagnostic::new(ReimplementedListBuiltin, expr.range());
6971
if checker.patch(diagnostic.kind.rule()) {
70-
#[allow(deprecated)]
71-
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
72-
"list".to_string(),
73-
expr.range(),
74-
)));
72+
if checker.semantic_model().is_builtin("list") {
73+
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
74+
"list".to_string(),
75+
expr.range(),
76+
)));
77+
}
7578
}
7679
checker.diagnostics.push(diagnostic);
7780
}

crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE790_PIE790.py.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ PIE790.py:101:5: PIE790 [*] Unnecessary `pass` statement
307307
|
308308
= help: Remove unnecessary `pass`
309309

310-
Suggested fix
310+
Fix
311311
98 98 |
312312
99 99 | def foo() -> None:
313313
100 100 | """buzz"""

crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE807_PIE807.py.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PIE807.py:3:44: PIE807 [*] Prefer `list` over useless lambda
1010
|
1111
= help: Replace with `list`
1212

13-
Suggested fix
13+
Fix
1414
1 1 | @dataclass
1515
2 2 | class Foo:
1616
3 |- foo: List[str] = field(default_factory=lambda: []) # PIE807
@@ -27,7 +27,7 @@ PIE807.py:7:36: PIE807 [*] Prefer `list` over useless lambda
2727
|
2828
= help: Replace with `list`
2929

30-
Suggested fix
30+
Fix
3131
4 4 |
3232
5 5 |
3333
6 6 | class FooTable(BaseTable):
@@ -45,7 +45,7 @@ PIE807.py:11:28: PIE807 [*] Prefer `list` over useless lambda
4545
|
4646
= help: Replace with `list`
4747

48-
Suggested fix
48+
Fix
4949
8 8 |
5050
9 9 |
5151
10 10 | class FooTable(BaseTable):

0 commit comments

Comments
 (0)