{"record":{"id":"da8bd5e028aadc38","repo":"oxc-project/oxc","slug":"do-not-use-the-operator-operator-to-compare-agai","errorCode":null,"errorMessage":"Do not use the {operator} operator to compare against -0.","messagePattern":"Do not use the (.+?) operator to compare against -0\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_compare_neg_zero.rs","lineNumber":10,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_syntax::operator::{BinaryOperator, UnaryOperator};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_compare_neg_zero_diagnostic(operator: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Do not use the {operator} operator to compare against -0.\"))\n        .with_help(\"Use Object.is(x, -0) to test equality with -0 and use 0 for other cases\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoCompareNegZero;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow comparing against `-0`\n    ///\n    /// ### Why is this bad?\n    ///\n    /// The rule should warn against code that tries to compare against `-0`,\n    /// since that will not work as intended. That is, code like `x === -0` will\n    /// pass for both `+0` and `-0`. The author probably intended `Object.is(x, -0)`.\n    ///","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_compare_neg_zero.rs#L1-L28","documentation":"Diagnostic from the oxlint rule `no-compare-neg-zero` (crates/oxc_linter/src/rules/eslint/no_compare_neg_zero.rs). It fires when a relational or equality operator (`>`, `<`, `>=`, `<=`, `==`, `===`) has `-0` (a UnaryExpression negating the literal 0) as an operand. Signed zero compares equal to `+0` under these operators, so the comparison silently cannot distinguish -0; only `Object.is(x, -0)` can.","triggerScenarios":"BinaryExpression with a comparison operator where one side is `-0` — e.g. `if (x === -0)`, `x >= -0`. The message interpolates the concrete operator, e.g. 'Do not use the === operator to compare against -0.'","commonSituations":"Math-heavy code (Math.round, Math.sin results that can be -0); chart/graphics code checking for negative zero after divisions like `-1/Infinity`; developers porting `Object.is` semantics from tests into comparisons.","solutions":["Use `Object.is(x, -0)` when you specifically need to detect negative zero.","Use plain `0` when sign-of-zero does not matter (the comparison result is identical anyway).","If distinguishing sign matters more broadly, track the sign separately (e.g. `Math.sign`) instead of comparing against -0.","Suppress inline with `// oxlint-disable-next-line no-compare-neg-zero` for deliberate -0 tests (e.g. in spec-compliance test suites)."],"exampleFix":"// before\nif (x === -0) { /* ... */ }\n\n// after\nif (Object.is(x, -0)) { /* ... */ }","handlingStrategy":"type-guard","validationCode":"// Reject -0 comparisons at author time with a lint gate\nconst negZeroCompare = /[<>=!]==?\\s*-\\s*0\\b|(-\\s*0)\\s*[<>=]=?/.test(src);","typeGuard":"// The only correct discriminator for negative zero\nfunction isNegativeZero(v) {\n  return Object.is(v, -0);\n}","tryCatchPattern":null,"preventionTips":["Use Object.is when sign-of-zero matters; use 0 otherwise.","Remember 0 === -0 is true under every comparison operator.","Check Math.sign/1/x when debugging zero-sign surprises."],"tags":["lint","negative-zero","equality","floating-point","oxlint"],"backgroundTag":"negative-zero-comparison","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}