Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(es/lint): Remove usage of box_patterns #7966

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/swc_ecma_lints/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
68 changes: 35 additions & 33 deletions crates/swc_ecma_lints/src/rules/no_alert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,46 +129,48 @@ 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) => {
if self.is_satisfying_indent(ident) {
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);
Expand Down
9 changes: 4 additions & 5 deletions crates/swc_ecma_lints/src/rules/radix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down