Skip to content

Commit

Permalink
refactor(linter): use get_inner_expression in const-comparisons (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
camc314 committed Dec 4, 2024
1 parent e824501 commit 7ae5e26
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/oxc_linter/src/rules/oxc/const_comparisons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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));
}
Expand All @@ -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))
}
_ => {
Expand Down

0 comments on commit 7ae5e26

Please sign in to comment.