From 4926130e5f10d439fff39b0e2ef92fc032ddf6a4 Mon Sep 17 00:00:00 2001 From: Boshen Date: Wed, 21 Jun 2023 08:55:36 +0800 Subject: [PATCH] refactor(linter): remove `unwrap` from bad_comparison_sequence --- .../src/rules/deepscan/bad_comparison_sequence.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/oxc_linter/src/rules/deepscan/bad_comparison_sequence.rs b/crates/oxc_linter/src/rules/deepscan/bad_comparison_sequence.rs index 6f649c9cc..4b3051688 100644 --- a/crates/oxc_linter/src/rules/deepscan/bad_comparison_sequence.rs +++ b/crates/oxc_linter/src/rules/deepscan/bad_comparison_sequence.rs @@ -58,10 +58,8 @@ fn has_no_bad_comparison_in_parents<'a, 'b>( node: &'b AstNode<'a>, ctx: &'b LintContext<'a>, ) -> bool { - let mut current_node_id = node.id(); - loop { - current_node_id = ctx.nodes().parent_id(current_node_id).unwrap(); - let kind = ctx.nodes().kind(current_node_id); + for node_id in ctx.nodes().ancestors(node.id()).skip(1) { + let kind = ctx.nodes().kind(node_id); // `a === b === c === d === e` only produce one error, since `(a === b === c) === d === e` will produce two errors. // So we should treat Parenthesized Expression as a boundary. @@ -76,6 +74,7 @@ fn has_no_bad_comparison_in_parents<'a, 'b>( return false; } } + false } fn is_bad_comparison(expr: &BinaryExpression) -> bool {