close

no-compare-neg-zero

Configuration

PresetConfigured Value
✅ js.configs.recommended"error"
✅ ts.configs.recommended"error"
rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-compare-neg-zero': 'error',
    },
  },
]);

Rule Details

Disallows comparing against -0 using equality and relational operators (==, ===, !=, !==, >, >=, <, <=). Comparing directly to -0 does not work as intended because +0 === -0 is true. To check whether a value is -0, use Object.is(x, -0) instead.

Examples of incorrect code for this rule:

if (x === -0) {
}

if (x == -0) {
}

if (x > -0) {
}

if (x !== -0) {
}

Examples of correct code for this rule:

if (x === 0) {
}

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

if (x > 0) {
}

Original Documentation