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(),
|
range: TextRange::default(),
|
||||||
});
|
});
|
||||||
let bool_op = node;
|
let bool_op = node;
|
||||||
#[allow(deprecated)]
|
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
|
||||||
checker.generator().expr(&bool_op),
|
checker.generator().expr(&bool_op),
|
||||||
expr.range(),
|
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());
|
let mut diagnostic = Diagnostic::new(UnnecessaryPass, pass_stmt.range());
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
if let Some(index) = trailing_comment_start_offset(pass_stmt, checker.locator) {
|
if let Some(index) = trailing_comment_start_offset(pass_stmt, checker.locator) {
|
||||||
#[allow(deprecated)]
|
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(
|
||||||
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(
|
|
||||||
pass_stmt.range().add_end(index),
|
pass_stmt.range().add_end(index),
|
||||||
)));
|
)));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use rustpython_parser::ast::{self, Expr, ExprLambda, Ranged};
|
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_diagnostics::{Diagnostic, Edit, Fix};
|
||||||
use ruff_macros::{derive_message_formats, violation};
|
use ruff_macros::{derive_message_formats, violation};
|
||||||
|
|
||||||
|
@ -38,14 +38,16 @@ use crate::registry::AsRule;
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct ReimplementedListBuiltin;
|
pub struct ReimplementedListBuiltin;
|
||||||
|
|
||||||
impl AlwaysAutofixableViolation for ReimplementedListBuiltin {
|
impl Violation for ReimplementedListBuiltin {
|
||||||
|
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||||
|
|
||||||
#[derive_message_formats]
|
#[derive_message_formats]
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
format!("Prefer `list` over useless lambda")
|
format!("Prefer `list` over useless lambda")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn autofix_title(&self) -> String {
|
fn autofix_title(&self) -> Option<String> {
|
||||||
"Replace with `list`".to_string()
|
Some("Replace with `list`".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,12 +69,13 @@ pub(crate) fn reimplemented_list_builtin(checker: &mut Checker, expr: &ExprLambd
|
||||||
if elts.is_empty() {
|
if elts.is_empty() {
|
||||||
let mut diagnostic = Diagnostic::new(ReimplementedListBuiltin, expr.range());
|
let mut diagnostic = Diagnostic::new(ReimplementedListBuiltin, expr.range());
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
#[allow(deprecated)]
|
if checker.semantic_model().is_builtin("list") {
|
||||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||||
"list".to_string(),
|
"list".to_string(),
|
||||||
expr.range(),
|
expr.range(),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,7 +307,7 @@ PIE790.py:101:5: PIE790 [*] Unnecessary `pass` statement
|
||||||
|
|
|
|
||||||
= help: Remove unnecessary `pass`
|
= help: Remove unnecessary `pass`
|
||||||
|
|
||||||
ℹ Suggested fix
|
ℹ Fix
|
||||||
98 98 |
|
98 98 |
|
||||||
99 99 | def foo() -> None:
|
99 99 | def foo() -> None:
|
||||||
100 100 | """buzz"""
|
100 100 | """buzz"""
|
||||||
|
|
|
@ -10,7 +10,7 @@ PIE807.py:3:44: PIE807 [*] Prefer `list` over useless lambda
|
||||||
|
|
|
|
||||||
= help: Replace with `list`
|
= help: Replace with `list`
|
||||||
|
|
||||||
ℹ Suggested fix
|
ℹ Fix
|
||||||
1 1 | @dataclass
|
1 1 | @dataclass
|
||||||
2 2 | class Foo:
|
2 2 | class Foo:
|
||||||
3 |- foo: List[str] = field(default_factory=lambda: []) # PIE807
|
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`
|
= help: Replace with `list`
|
||||||
|
|
||||||
ℹ Suggested fix
|
ℹ Fix
|
||||||
4 4 |
|
4 4 |
|
||||||
5 5 |
|
5 5 |
|
||||||
6 6 | class FooTable(BaseTable):
|
6 6 | class FooTable(BaseTable):
|
||||||
|
@ -45,7 +45,7 @@ PIE807.py:11:28: PIE807 [*] Prefer `list` over useless lambda
|
||||||
|
|
|
|
||||||
= help: Replace with `list`
|
= help: Replace with `list`
|
||||||
|
|
||||||
ℹ Suggested fix
|
ℹ Fix
|
||||||
8 8 |
|
8 8 |
|
||||||
9 9 |
|
9 9 |
|
||||||
10 10 | class FooTable(BaseTable):
|
10 10 | class FooTable(BaseTable):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue