mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:09:22 +00:00
Migrate flake8_pie autofix rules from unspecified
to suggested
and automatic
(#4621)
This commit is contained in:
parent
f0e173d9fd
commit
dcd2bfaab7
5 changed files with 18 additions and 17 deletions
|
@ -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(),
|
||||
)));
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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"""
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue