no-constant-condition
eslint
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"no-constant-condition": "error",
},
},
];if (false) {
doSomethingUnfinished();
}
if (void x) {
doSomethingUnfinished();
}
if (x &&= false) {
doSomethingNever();
}
if (class {}) {
doSomethingAlways();
}
if (new Boolean(x)) {
doSomethingAlways();
}
if (Boolean(1)) {
doSomethingAlways();
}
if (undefined) {
doSomethingUnfinished();
}
if (x ||= true) {
doSomethingAlways();
}
// …if (x === 0) {
doSomething();
}
for (;;) {
doSomethingForever();
}
while (typeof x === "undefined") {
doSomething();
}
do {
doSomething();
} while (x);
const result = x !== 0 ? a : b;
if(input === "hello" || input === "bye"){
output(input);
}Examples from the ESLint documentation.
no-constant-condition
eslint
export default [
{
rules: {
"no-constant-condition": "error",
},
},
];no-constant-condition
eslint plugin · correctness
{
"rules": {
"no-constant-condition": "error"
}
}correctness/noConstantCondition
correctness · since 1.0.0
{
"linter": {
"rules": {
"correctness": {
"noConstantCondition": "error"
}
}
}
}Disallow constant expressions in conditions in <template>
Disallow literal numbers that lose precision
Disallow useless backreferences in regular expressions
Disallow duplicate class members
Require generator functions to contain yield