Skip to content

Commit

Permalink
refactor(linter): reduce nested if statements in eslint/no_this_befor…
Browse files Browse the repository at this point in the history
…e_super (#5485)
  • Loading branch information
IWANABETHATGUY committed Sep 5, 2024
1 parent bc7be70 commit 979c16c
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions crates/oxc_linter/src/rules/eslint/no_this_before_super.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Rule for NoThisBeforeSuper {
for node in semantic.nodes().iter() {
match node.kind() {
AstKind::Function(_) | AstKind::ArrowFunctionExpression(_) => {
if Self::is_wanted_node(node, ctx) {
if Self::is_wanted_node(node, ctx).unwrap_or_default() {
wanted_nodes.push(node);
}
}
Expand Down Expand Up @@ -133,26 +133,20 @@ impl Rule for NoThisBeforeSuper {
}

impl NoThisBeforeSuper {
fn is_wanted_node(node: &AstNode, ctx: &LintContext<'_>) -> bool {
if let Some(parent) = ctx.nodes().parent_node(node.id()) {
if let AstKind::MethodDefinition(mdef) = parent.kind() {
if matches!(mdef.kind, MethodDefinitionKind::Constructor) {
let parent_2 = ctx.nodes().parent_node(parent.id());
if let Some(parent_2) = parent_2 {
let parent_3 = ctx.nodes().parent_node(parent_2.id());
if let Some(parent_3) = parent_3 {
if let AstKind::Class(c) = parent_3.kind() {
if let Some(super_class) = &c.super_class {
return !matches!(super_class, Expression::NullLiteral(_));
}
}
}
}
fn is_wanted_node(node: &AstNode, ctx: &LintContext<'_>) -> Option<bool> {
let parent = ctx.nodes().parent_node(node.id())?;
if let AstKind::MethodDefinition(mdef) = parent.kind() {
if matches!(mdef.kind, MethodDefinitionKind::Constructor) {
let parent_2 = ctx.nodes().parent_node(parent.id())?;
let parent_3 = ctx.nodes().parent_node(parent_2.id())?;
if let AstKind::Class(c) = parent_3.kind() {
let super_class = c.super_class.as_ref()?;
return Some(!matches!(super_class, Expression::NullLiteral(_)));
}
}
}

false
Some(false)
}

fn analyze(
Expand Down

0 comments on commit 979c16c

Please sign in to comment.