From f8af40173ae9df40a4ed26afde9abd9a2513e734 Mon Sep 17 00:00:00 2001 From: Dmitry Dygalo Date: Tue, 13 Sep 2022 11:22:43 +0200 Subject: [PATCH] chore: Use patterns inside `matches!` instead of multiple `matches!` --- src/ast/checks.rs | 8 ++------ src/ast/operations.rs | 12 +++++------- src/check_ast.rs | 23 ++++++++++++----------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/ast/checks.rs b/src/ast/checks.rs index e393abf932..d0d7a25102 100644 --- a/src/ast/checks.rs +++ b/src/ast/checks.rs @@ -156,9 +156,7 @@ pub fn check_useless_object_inheritance( CheckKind::UselessObjectInheritance(name.to_string()), expr.location, ); - if matches!(autofix, fixer::Mode::Generate) - || matches!(autofix, fixer::Mode::Apply) - { + if matches!(autofix, fixer::Mode::Generate | fixer::Mode::Apply) { if let Some(fix) = fixes::remove_class_def_base( locator, &stmt.location, @@ -254,9 +252,7 @@ pub fn check_assert_equals(expr: &Expr, autofix: &fixer::Mode) -> Option if let ExprKind::Name { id, .. } = &value.node { if id == "self" { let mut check = Check::new(CheckKind::NoAssertEquals, expr.location); - if matches!(autofix, fixer::Mode::Generate) - || matches!(autofix, fixer::Mode::Apply) - { + if matches!(autofix, fixer::Mode::Generate | fixer::Mode::Apply) { check.amend(Fix { content: "assertEqual".to_string(), start: Location::new(expr.location.row(), expr.location.column() + 1), diff --git a/src/ast/operations.rs b/src/ast/operations.rs index b2b5e5d170..69d532faf2 100644 --- a/src/ast/operations.rs +++ b/src/ast/operations.rs @@ -70,9 +70,7 @@ pub fn extract_all_names(stmt: &Stmt, scope: &Scope) -> Vec { pub fn on_conditional_branch(parent_stack: &[usize], parents: &[&Stmt]) -> bool { for index in parent_stack.iter().rev() { let parent = parents[*index]; - if matches!(parent.node, StmtKind::If { .. }) - || matches!(parent.node, StmtKind::While { .. }) - { + if matches!(parent.node, StmtKind::If { .. } | StmtKind::While { .. }) { return true; } if let StmtKind::Expr { value } = &parent.node { @@ -89,10 +87,10 @@ pub fn on_conditional_branch(parent_stack: &[usize], parents: &[&Stmt]) -> bool pub fn in_nested_block(parent_stack: &[usize], parents: &[&Stmt]) -> bool { for index in parent_stack.iter().rev() { let parent = parents[*index]; - if matches!(parent.node, StmtKind::Try { .. }) - || matches!(parent.node, StmtKind::If { .. }) - || matches!(parent.node, StmtKind::With { .. }) - { + if matches!( + parent.node, + StmtKind::Try { .. } | StmtKind::If { .. } | StmtKind::With { .. } + ) { return true; } } diff --git a/src/check_ast.rs b/src/check_ast.rs index c775ad9b99..f689ac73b9 100644 --- a/src/check_ast.rs +++ b/src/check_ast.rs @@ -645,8 +645,7 @@ where .settings .select .contains(CheckKind::YieldOutsideFunction.code()) - && matches!(scope.kind, ScopeKind::Class) - || matches!(scope.kind, ScopeKind::Module) + && matches!(scope.kind, ScopeKind::Class | ScopeKind::Module) { self.checks .push(Check::new(CheckKind::YieldOutsideFunction, expr.location)); @@ -1077,9 +1076,7 @@ impl<'a> Checker<'a> { && !current.values.contains_key(id) { for scope in self.scopes.iter().rev().skip(1) { - if matches!(scope.kind, ScopeKind::Function) - || matches!(scope.kind, ScopeKind::Module) - { + if matches!(scope.kind, ScopeKind::Function | ScopeKind::Module) { let used = scope .values .get(id) @@ -1110,9 +1107,10 @@ impl<'a> Checker<'a> { } // TODO(charlie): Include comprehensions here. - if matches!(parent.node, StmtKind::For { .. }) - || matches!(parent.node, StmtKind::AsyncFor { .. }) - || operations::is_unpacking_assignment(parent) + if matches!( + parent.node, + StmtKind::For { .. } | StmtKind::AsyncFor { .. } + ) || operations::is_unpacking_assignment(parent) { self.add_binding( id.to_string(), @@ -1127,9 +1125,12 @@ impl<'a> Checker<'a> { if id == "__all__" && matches!(current.kind, ScopeKind::Module) - && (matches!(parent.node, StmtKind::Assign { .. }) - || matches!(parent.node, StmtKind::AugAssign { .. }) - || matches!(parent.node, StmtKind::AnnAssign { .. })) + && matches!( + parent.node, + StmtKind::Assign { .. } + | StmtKind::AugAssign { .. } + | StmtKind::AnnAssign { .. } + ) { self.add_binding( id.to_string(),