mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(linter): fix false positive for erasing-op in 0/0 case (#2009)
This commit is contained in:
parent
712e99cf9b
commit
107a32ea48
1 changed files with 5 additions and 2 deletions
|
|
@ -58,6 +58,9 @@ impl Rule for ErasingOp {
|
|||
check_op(binary_expression, &binary_expression.right, ctx);
|
||||
}
|
||||
BinaryOperator::Division => {
|
||||
if is_number_value(&binary_expression.right, 0.0) {
|
||||
return;
|
||||
}
|
||||
check_op(binary_expression, &binary_expression.left, ctx);
|
||||
}
|
||||
_ => (),
|
||||
|
|
@ -66,7 +69,7 @@ impl Rule for ErasingOp {
|
|||
}
|
||||
|
||||
fn is_number_value(expr: &Expression, value: f64) -> bool {
|
||||
if let Expression::NumberLiteral(number_literal) = expr {
|
||||
if let Expression::NumberLiteral(number_literal) = expr.without_parenthesized() {
|
||||
(number_literal.value - value).abs() < f64::EPSILON
|
||||
} else {
|
||||
false
|
||||
|
|
@ -87,7 +90,7 @@ fn check_op<'a, 'b>(
|
|||
fn test() {
|
||||
use crate::tester::Tester;
|
||||
|
||||
let pass = vec!["x * 1;", "1 * x;", "5 & x;", "x / 1;", "1 / x;"];
|
||||
let pass = vec!["x * 1;", "1 * x;", "5 & x;", "x / 1;", "1 / x;", "0 / 0"];
|
||||
|
||||
let fail = vec!["x * 0;", "0 * x;", "0 & x;", "0 / x;"];
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue