Migrate flake8_pie autofix rules from unspecified to suggested and automatic (#4621)

This commit is contained in:
qdegraaf 2023-05-24 18:08:22 +02:00 committed by GitHub
parent f0e173d9fd
commit dcd2bfaab7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 17 deletions

View file

@ -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(),
)));

View file

@ -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 {

View file

@ -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<String> {
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);
}

View file

@ -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"""

View file

@ -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):