1 # disallow constant expressions in conditions (no-constant-condition)
3 A constant expression (for example, a literal) as a test condition might be a typo or development trigger for a specific behavior. For example, the following code looks as if it is not ready for production.
7 doSomethingUnfinished();
13 This rule disallows constant expressions in the test condition of:
15 * `if`, `for`, `while`, or `do...while` statement
16 * `?:` ternary expression
18 Examples of **incorrect** code for this rule:
21 /*eslint no-constant-condition: "error"*/
24 doSomethingUnfinished();
28 doSomethingUnfinished();
59 var result = 0 ? a : b;
62 Examples of **correct** code for this rule:
65 /*eslint no-constant-condition: "error"*/
75 while (typeof x === "undefined") {
83 var result = x !== 0 ? a : b;
90 Set to `true` by default. Setting this option to `false` allows constant expressions in loops.
92 Examples of **correct** code for when `checkLoops` is `false`:
95 /*eslint no-constant-condition: ["error", { "checkLoops": false }]*/