mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 14:51:25 +00:00
Remove some matches on Stmt
(#4796)
This commit is contained in:
parent
b030c70dda
commit
b92be59ffe
5 changed files with 8 additions and 10 deletions
|
@ -38,7 +38,7 @@ fn walk_stmt(checker: &mut Checker, body: &[Stmt], f: fn(&Stmt) -> bool) {
|
|||
Stmt::While(ast::StmtWhile { body, .. })
|
||||
| Stmt::For(ast::StmtFor { body, .. })
|
||||
| Stmt::AsyncFor(ast::StmtAsyncFor { body, .. }) => {
|
||||
walk_stmt(checker, body, |stmt| matches!(stmt, Stmt::Return(_)));
|
||||
walk_stmt(checker, body, Stmt::is_return_stmt);
|
||||
}
|
||||
Stmt::If(ast::StmtIf { body, .. })
|
||||
| Stmt::Try(ast::StmtTry { body, .. })
|
||||
|
|
|
@ -50,7 +50,7 @@ impl Violation for ReturnInTryExceptFinally {
|
|||
}
|
||||
|
||||
fn find_return(stmts: &[Stmt]) -> Option<&Stmt> {
|
||||
stmts.iter().find(|stmt| matches!(stmt, Stmt::Return(_)))
|
||||
stmts.iter().find(|stmt| stmt.is_return_stmt())
|
||||
}
|
||||
|
||||
/// SIM107
|
||||
|
|
|
@ -96,7 +96,7 @@ fn num_branches(stmts: &[Stmt]) -> usize {
|
|||
+ (if let Some(stmt) = orelse.first() {
|
||||
// `elif:` and `else: if:` have the same AST representation.
|
||||
// Avoid treating `elif:` as two statements.
|
||||
usize::from(!matches!(stmt, Stmt::If(_)))
|
||||
usize::from(!stmt.is_if_stmt())
|
||||
} else {
|
||||
0
|
||||
})
|
||||
|
|
|
@ -73,7 +73,7 @@ fn num_statements(stmts: &[Stmt]) -> usize {
|
|||
if let Some(stmt) = orelse.first() {
|
||||
// `elif:` and `else: if:` have the same AST representation.
|
||||
// Avoid treating `elif:` as two statements.
|
||||
if !matches!(stmt, Stmt::If(_)) {
|
||||
if !stmt.is_if_stmt() {
|
||||
count += 1;
|
||||
}
|
||||
count += num_statements(orelse);
|
||||
|
|
|
@ -61,8 +61,7 @@ pub(crate) fn super_call_with_parameters(
|
|||
// Find the enclosing function definition (if any).
|
||||
let Some(Stmt::FunctionDef(ast::StmtFunctionDef {
|
||||
args: parent_args, ..
|
||||
})) = parents
|
||||
.find(|stmt| stmt.is_function_def_stmt()) else {
|
||||
})) = parents.find(|stmt| stmt.is_function_def_stmt()) else {
|
||||
return;
|
||||
};
|
||||
|
||||
|
@ -76,8 +75,7 @@ pub(crate) fn super_call_with_parameters(
|
|||
// Find the enclosing class definition (if any).
|
||||
let Some(Stmt::ClassDef(ast::StmtClassDef {
|
||||
name: parent_name, ..
|
||||
})) = parents
|
||||
.find(|stmt| matches!(stmt, Stmt::ClassDef (_))) else {
|
||||
})) = parents.find(|stmt| stmt.is_class_def_stmt()) else {
|
||||
return;
|
||||
};
|
||||
|
||||
|
@ -97,11 +95,11 @@ pub(crate) fn super_call_with_parameters(
|
|||
}
|
||||
|
||||
drop(parents);
|
||||
|
||||
let mut diagnostic = Diagnostic::new(SuperCallWithParameters, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(edit) = fixes::remove_super_arguments(checker.locator, checker.stylist, expr) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(edit));
|
||||
diagnostic.set_fix(Fix::suggested(edit));
|
||||
}
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue