pve-eslint/eslint/docs/rules/no-compare-neg-zero.md
Thomas Lamprecht 34eeec05c4 import 8.4.0 source
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-12-06 14:02:55 +01:00

670 B

disallow comparing against -0 (no-compare-neg-zero)

Rule Details

The rule should warn against code that tries to compare against -0, since that will not work as intended. That is, code like x === -0 will pass for both +0 and -0. The author probably intended Object.is(x, -0).

Examples of incorrect code for this rule:

/* eslint no-compare-neg-zero: "error" */

if (x === -0) {
    // doSomething()...
}

Examples of correct code for this rule:

/* eslint no-compare-neg-zero: "error" */

if (x === 0) {
    // doSomething()...
}
/* eslint no-compare-neg-zero: "error" */

if (Object.is(x, -0)) {
    // doSomething()...
}