Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(linter): use get_inner_expression in const-comparisons #7627

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading