Skip to content

Commit

Permalink
chore: remove unnecessary "is_in_constructor_root" fn.
Browse files Browse the repository at this point in the history
  • Loading branch information
woai3c committed May 30, 2024
1 parent 97dd462 commit dbb0686
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions crates/oxc_linter/src/rules/eslint/no_constructor_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ impl Rule for NoConstructorReturn {
return;
}

let Some(is_in_constructor_root) = is_in_constructor_root(ctx, node.id()) else { return };

if is_in_constructor_root || is_definitely_in_constructor(ctx, node.id()) {
if is_definitely_in_constructor(ctx, node.id()) {
ctx.diagnostic(no_constructor_return_diagnostic(ret.span));
}
}
Expand All @@ -69,17 +67,6 @@ fn is_constructor(node: &AstNode<'_>) -> bool {
)
}

/// Checks to see if the given node is in the root of a constructor.
/// Returns `None` if it isn't possible for this node to be in a constructor.
fn is_in_constructor_root(ctx: &LintContext, node_id: AstNodeId) -> Option<bool> {
ctx.nodes()
.ancestors(node_id)
.map(|id| ctx.nodes().get_node(id))
.filter(|it| !matches!(it.kind(), AstKind::BlockStatement(_)))
.nth(3)
.map(is_constructor)
}

fn is_definitely_in_constructor(ctx: &LintContext, node_id: AstNodeId) -> bool {
ctx.nodes()
.ancestors(node_id)
Expand Down

0 comments on commit dbb0686

Please sign in to comment.