Skip to content

eslint/no-compare-neg-zero Correctness

This rule is turned on by default.
🛠️💡 An auto-fix and a suggestion are available for this rule for some violations.

What it does

Disallow comparing against -0

Why is this bad?

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).

Example

javascript
if (x === -0) {
}

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny no-compare-neg-zero
json
{
  "rules": {
    "no-compare-neg-zero": "error"
  }
}

References

Released under the MIT License.