Repository: eslint/eslint
File: tests/lib/rules/no-constant-binary-expression.js (JavaScript)

Code before:
         */
        { code: "[a] == [a]", errors: [{ messageId: "bothAlwaysNew" }] },
        { code: "[a] != [a]", errors: [{ messageId: "bothAlwaysNew" }] },
        { code: "({}) == []", errors: [{ messageId: "bothAlwaysNew" }] },

        // Comparing to always new objects
        { code: "x === {}", errors: [{ messageId: "alwaysNew" }] },
        { code: "x !== {}", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === []", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === (() => {})", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === (function() {})", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === (class {})", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === new Boolean()", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === new Promise()", env: { es6: true }, errors: [{ messageId: "alwaysNew" }] },
        { code: "x === new WeakSet()", env: { es6: true }, errors: [{ messageId: "alwaysNew" }] },
        { code: "x === (foo, {})", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === (y = {})", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === (y ? {} : [])", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === /[a-z]/", errors: [{ messageId: "alwaysNew" }] },

        // It's not obvious what this does, but it compares the old value of `x` to the new object.
        { code: "x === (x = {})", errors: [{ messageId: "alwaysNew" }] },

        { code: "window.abc && false && anything", errors: [{ messageId: "constantShortCircuit" }] },
        { code: "window.abc || true || anything", errors: [{ messageId: "constantShortCircuit" }] },
        { code: "window.abc ?? 'non-nullish' ?? 'non-nullish'", errors: [{ messageId: "constantShortCircuit" }] }
    ]
});


Review comment (suggestion):
```suggestion
        { code: "window.abc ?? 'non-nullish' ?? anything", errors: [{ messageId: "constantShortCircuit" }] }
```

To avoid confusion, as the right-most operand doesn't affect this check.

Code after:
         */
        { code: "[a] == [a]", errors: [{ messageId: "bothAlwaysNew" }] },
        { code: "[a] != [a]", errors: [{ messageId: "bothAlwaysNew" }] },
        { code: "({}) == []", errors: [{ messageId: "bothAlwaysNew" }] },

        // Comparing to always new objects
        { code: "x === {}", errors: [{ messageId: "alwaysNew" }] },
        { code: "x !== {}", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === []", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === (() => {})", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === (function() {})", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === (class {})", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === new Boolean()", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === new Promise()", env: { es6: true }, errors: [{ messageId: "alwaysNew" }] },
        { code: "x === new WeakSet()", env: { es6: true }, errors: [{ messageId: "alwaysNew" }] },
        { code: "x === (foo, {})", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === (y = {})", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === (y ? {} : [])", errors: [{ messageId: "alwaysNew" }] },
        { code: "x === /[a-z]/", errors: [{ messageId: "alwaysNew" }] },

        // It's not obvious what this does, but it compares the old value of `x` to the new object.
        { code: "x === (x = {})", errors: [{ messageId: "alwaysNew" }] },

        { code: "window.abc && false && anything", errors: [{ messageId: "constantShortCircuit" }] },
        { code: "window.abc || true || anything", errors: [{ messageId: "constantShortCircuit" }] },
        { code: "window.abc ?? 'non-nullish' ?? anything", errors: [{ messageId: "constantShortCircuit" }] }
    ]
});