mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
refactor(linter): use get_inner_expression in const-comparisons (#7627)
This commit is contained in:
parent
3b1e63ecab
commit
b445654fbd
1 changed files with 6 additions and 6 deletions
|
|
@ -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))
|
||||
}
|
||||
_ => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue