{"record":{"id":"a52162992a701af0","repo":"oxc-project/oxc","slug":"unexpected-comparison-of-two-newly-constructed-obj","errorCode":null,"errorMessage":"Unexpected comparison of two newly constructed objects","messagePattern":"Unexpected comparison of two newly constructed objects","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/eslint/no_constant_binary_expression.rs","lineNumber":104,"sourceCode":"    .with_label(span)\n}\n\nfn constant_binary_operand(left_or_right: &str, operator: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected constant binary expression\")\n        .with_help(format!(\n            \"This compares constantly with the {left_or_right}-hand side of the {operator}\"\n        ))\n        .with_label(span)\n}\n\nfn constant_always_new(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected comparison to newly constructed object\")\n        .with_help(\"These two values can never be equal\")\n        .with_label(span)\n}\n\nfn constant_both_always_new(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected comparison of two newly constructed objects\")\n        .with_help(\"These two values can never be equal\")\n        .with_label(span)\n}\n\nfn constant_relational_comparison(operator: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected constant relational comparison\")\n        .with_help(format!(\"Both sides of the {operator} are literal values\"))\n        .with_label(span)\n}\n\nimpl Rule for NoConstantBinaryExpression {\n    fn from_configuration(value: serde_json::Value) -> Result<Self, serde_json::error::Error> {\n        DefaultRuleConfig::<Self>::from_value(value).map(DefaultRuleConfig::into_inner)\n    }\n\n    fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {\n        match node.kind() {\n            AstKind::LogicalExpression(expr) => match expr.operator {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_constant_binary_expression.rs#L86-L122","documentation":"Diagnostic from `no-constant-binary-expression`, emitted by `constant_both_always_new` (crates/oxc_linter/src/rules/eslint/no_constant_binary_expression.rs:103). It fires on loose equality/inequality (`==`/`!=`) where BOTH operands are always-new references — e.g. `[a] == [a]`, `({}) == []`. Because each side constructs a distinct object, even loose equality (which never crosses two object references) is guaranteed false; the help text reads 'These two values can never be equal'.","triggerScenarios":"BinaryExpression with Equality/Inequality where `is_always_new(left) && is_always_new(right)` — two object/array/function/class/regex literals or builtin-global `new` expressions compared with `==`/`!=`, e.g. `JSON.parse(s) == JSON.parse(s)` style copies compared after literal construction like `[a] == [a]`.","commonSituations":"Array-of-values comparison written as `[x] == [x]`; comparing two configuration object literals for overlap; refactored `deepEqual` sketches that regressed to `==`.","solutions":["Use a deep-equality helper: `assert.deepStrictEqual(a, b)` or `isEqual(a, b)`.","Compare stable primitive keys (ids, serialized forms) instead of constructed objects.","Hoist the shared object to a constant and compare references to that constant if identity is meant.","Delete the comparison when both sides are provably the same fresh construction — it always returns false."],"exampleFix":"// before\nif ([a, b] == [a, b]) { /* never true */ }\n\n// after\nif (a === a && b === b) { }\n// or, for real content checks:\nif (isEqual(left, right)) { }","handlingStrategy":"type-guard","validationCode":"// Gate: loose equality between two constructed literals\nconst bothFresh = /(\\[[^\\]]*\\]|\\{[^}]*\\})\\s*=={1,2}\\s*(\\[[^\\]]*\\]|\\{[^}]*\\})/.test(src);","typeGuard":"// Say what you mean: content equality\nimport { isEqual } from 'lodash-es';\nconst sameContent = (a, b) => isEqual(a, b);","tryCatchPattern":null,"preventionTips":["Treat `==` between two object-ish literals as always-false by definition.","Compare ids/keys or use a deep-equality utility.","Keep oxlint's correctness category on to catch this at author time."],"tags":["lint","reference-equality","loose-equality","dead-code","oxlint"],"backgroundTag":"reference-equality-new-object","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"}