no-constant-binary-expression
eslint
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"no-constant-binary-expression": "error",
},
},
];Disallow expressions where the operation doesn't affect the value
const value1 = +x == null;
const value2 = condition ? x : {} || DEFAULT;
const value3 = !foo == null;
const value4 = new Boolean(foo) === true;
const objIsEmpty = someObj === {};
const arrIsEmpty = someArr === [];
const shortCircuit1 = condition1 && false && condition2;
const shortCircuit2 = condition1 || true || condition2;
const shortCircuit3 = condition1 ?? "non-nullish" ?? condition2;const value1 = x == null;
const value2 = (condition ? x : {}) || DEFAULT;
const value3 = !(foo == null);
const value4 = Boolean(foo) === true;
const objIsEmpty = Object.keys(someObj).length === 0;
const arrIsEmpty = someArr.length === 0;Examples from the ESLint documentation.
no-constant-binary-expression
eslint
export default [
{
rules: {
"no-constant-binary-expression": "error",
},
},
];no-constant-binary-expression
eslint plugin · correctness
{
"rules": {
"no-constant-binary-expression": "error"
}
}suspicious/noConstantBinaryExpressions
suspicious · since 2.0.0
{
"linter": {
"rules": {
"suspicious": {
"noConstantBinaryExpressions": "error"
}
}
}
}Disallow invalid regular expression strings in RegExp constructors
Disallow empty static blocks
Disallow let or var variables that are read but never assigned
Disallow new operators with global non-constructor functions
Disallow fallthrough of case statements