Skip to content

Commit

Permalink
Migrate flake8_pie autofix rules from unspecified to suggested an…
Browse files Browse the repository at this point in the history
…d `automatic` (#4621)
  • Loading branch information
qdegraaf authored May 24, 2023
1 parent f0e173d commit dcd2bfa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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<String> {
Some("Replace with `list`".to_string())
}
}

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit dcd2bfa

Please sign in to comment.