From f7b5e16aef968c9c9f38f40962edf334cc3983e6 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Mon, 18 Sep 2023 22:39:53 +0800 Subject: [PATCH] refactor(es/lint): Remove usage of `box_patterns` (#7966) **Related issue:** - Closes #7964 --- crates/swc_ecma_lints/src/lib.rs | 1 - crates/swc_ecma_lints/src/rules/no_alert.rs | 68 +++++++++++---------- crates/swc_ecma_lints/src/rules/radix.rs | 9 ++- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/crates/swc_ecma_lints/src/lib.rs b/crates/swc_ecma_lints/src/lib.rs index d06a038506b8..af91c07f279c 100644 --- a/crates/swc_ecma_lints/src/lib.rs +++ b/crates/swc_ecma_lints/src/lib.rs @@ -1,6 +1,5 @@ #![cfg_attr(feature = "non_critical_lints", deny(unused))] #![cfg_attr(feature = "non_critical_lints", deny(clippy::all))] -#![feature(box_patterns)] pub mod config; pub mod rule; diff --git a/crates/swc_ecma_lints/src/rules/no_alert.rs b/crates/swc_ecma_lints/src/rules/no_alert.rs index 4f859e72909a..7a1bf85d7adc 100644 --- a/crates/swc_ecma_lints/src/rules/no_alert.rs +++ b/crates/swc_ecma_lints/src/rules/no_alert.rs @@ -129,6 +129,37 @@ impl NoAlert { } } + fn handle_member_expr(&mut self, member_expr: &MemberExpr) { + let MemberExpr { obj, prop, .. } = member_expr; + + match obj.as_ref() { + Expr::Ident(obj) => { + if !self.is_satisfying_indent(obj) { + return; + } + + self.obj = Some(obj.sym.clone()); + + self.handle_member_prop(prop); + } + Expr::This(_) => { + let inside_arrow_fn = self.is_inside_arrow_fn(); + let inside_class = self.is_inside_class(); + + if inside_arrow_fn && inside_class { + return; + } + + if !inside_arrow_fn && (inside_class || self.is_inside_object()) { + return; + } + + self.handle_member_prop(prop); + } + _ => {} + } + } + fn handle_callee(&mut self, expr: &Expr) { match expr { Expr::Ident(ident) => { @@ -136,39 +167,10 @@ impl NoAlert { self.prop = Some(ident.sym.clone()); } } - Expr::Member(member_expr) - | Expr::OptChain(OptChainExpr { - base: box OptChainBase::Member(member_expr), - .. - }) => { - let MemberExpr { obj, prop, .. } = member_expr; - - match obj.as_ref() { - Expr::Ident(obj) => { - if !self.is_satisfying_indent(obj) { - return; - } - - self.obj = Some(obj.sym.clone()); - - self.handle_member_prop(prop); - } - Expr::This(_) => { - let inside_arrow_fn = self.is_inside_arrow_fn(); - let inside_class = self.is_inside_class(); - - if inside_arrow_fn && inside_class { - return; - } - - if !inside_arrow_fn && (inside_class || self.is_inside_object()) { - return; - } - - self.handle_member_prop(prop); - } - _ => {} - } + Expr::Member(member_expr) => self.handle_member_expr(member_expr), + Expr::OptChain(OptChainExpr { base, .. }) if base.is_member() => { + let member_expr = base.as_member().unwrap(); + self.handle_member_expr(member_expr); } Expr::OptChain(opt_chain) => { opt_chain.visit_children_with(self); diff --git a/crates/swc_ecma_lints/src/rules/radix.rs b/crates/swc_ecma_lints/src/rules/radix.rs index 2b4ae2619b07..b93808dc54ae 100644 --- a/crates/swc_ecma_lints/src/rules/radix.rs +++ b/crates/swc_ecma_lints/src/rules/radix.rs @@ -243,11 +243,10 @@ impl Radix { Expr::Member(member_expr) => { return self.extract_obj_and_prop_member_case(member_expr); } - Expr::OptChain(OptChainExpr { - base: box OptChainBase::Member(member_expr), - .. - }) => { - return self.extract_obj_and_prop_member_case(member_expr); + Expr::OptChain(OptChainExpr { base, .. }) => { + if let OptChainBase::Member(member_expr) = &**base { + return self.extract_obj_and_prop_member_case(member_expr); + } } Expr::Paren(ParenExpr { expr, .. }) => { return self.extract_obj_and_prop(expr.as_ref());