From b445654fbd06034d87e4f29414aadd1927ad1466 Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Wed, 4 Dec 2024 02:59:54 +0000 Subject: [PATCH] refactor(linter): use `get_inner_expression` in `const-comparisons` (#7627) --- crates/oxc_linter/src/rules/oxc/const_comparisons.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/oxc_linter/src/rules/oxc/const_comparisons.rs b/crates/oxc_linter/src/rules/oxc/const_comparisons.rs index 38ea39c1ff149..68ad7c55ffc5e 100644 --- a/crates/oxc_linter/src/rules/oxc/const_comparisons.rs +++ b/crates/oxc_linter/src/rules/oxc/const_comparisons.rs @@ -83,13 +83,13 @@ impl Rule for ConstComparisons { } let Some((right_cmp_op, right_expr, right_const_expr, _)) = - comparison_to_const(logical_expr.right.without_parentheses()) + comparison_to_const(logical_expr.right.get_inner_expression()) else { return; }; for (left_cmp_op, left_expr, left_const_expr, left_span) in - all_and_comparison_to_const(logical_expr.left.without_parentheses()) + all_and_comparison_to_const(logical_expr.left.get_inner_expression()) { let Some(ordering) = left_const_expr.value.partial_cmp(&right_const_expr.value) else { return; @@ -138,7 +138,7 @@ impl Rule for ConstComparisons { ctx.diagnostic(impossible( left_span, - logical_expr.right.without_parentheses().span(), + logical_expr.right.get_inner_expression().span(), &format!( "`{} {} {}` ", expr_str, @@ -165,7 +165,7 @@ fn comparison_to_const<'a, 'b>( ) -> Option<(CmpOp, &'b Expression<'a>, &'b NumericLiteral<'a>, Span)> { if let Expression::BinaryExpression(bin_expr) = expr { if let Ok(cmp_op) = CmpOp::try_from(bin_expr.operator) { - match (&bin_expr.left.without_parentheses(), &bin_expr.right.without_parentheses()) { + match (&bin_expr.left.get_inner_expression(), &bin_expr.right.get_inner_expression()) { (Expression::NumericLiteral(lit), _) => { return Some((cmp_op.reverse(), &bin_expr.right, lit, bin_expr.span)); } @@ -187,8 +187,8 @@ fn all_and_comparison_to_const<'a, 'b>( Expression::LogicalExpression(logical_expr) if logical_expr.operator == LogicalOperator::And => { - let left_iter = all_and_comparison_to_const(logical_expr.left.without_parentheses()); - let right_iter = all_and_comparison_to_const(logical_expr.right.without_parentheses()); + let left_iter = all_and_comparison_to_const(logical_expr.left.get_inner_expression()); + let right_iter = all_and_comparison_to_const(logical_expr.right.get_inner_expression()); Box::new(left_iter.chain(right_iter)) } _ => {