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();
43 var result = 0 ? a : b;
46 Examples of **correct** code for this rule:
49 /*eslint no-constant-condition: "error"*/
59 while (typeof x === "undefined") {
67 var result = x !== 0 ? a : b;
74 Set to `true` by default. Setting this option to `false` allows constant expressions in loops.
76 Examples of **correct** code for when `checkLoops` is `false`:
79 /*eslint no-constant-condition: ["error", { "checkLoops": false }]*/