no-constant-condition should allow for while(true) idiom
See original GitHub issueWhat version of ESLint are you using?
2.3.0
What configuration and parser (Espree, Babel-ESLint, etc.) are you using?
env: es6 + node parser: Espree config: “no-constant-condition”: “error”
What did you do? Please include the actual source code causing the issue.
while (true)
{
if (doSomething())
break;
}
What did you expect to happen?
I expected no error at the while
, because its dependent statement has a break
, and in this case it’s equivalent to for(;;)
. Maybe I’m the only one who uses this idiom.
What actually happened? Please include the actual, raw output from ESLint.
line 15, col 1, Error - Unexpected constant condition. (no-constant-condition)
line 15, col 1 is the “w” in while
.
What do you suggest?
There are three approaches to fixing this:
- Ignore it and hope I go away. 😉
- Always allow
while (true)
the wayfor (;;)
is allowed. - Add an “allow-while-true” option.
I’ll be happy to implement it, but let me know which approach you want to take.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:23 (21 by maintainers)
I feel an extra option for
no-constant-condition
to allow explicit boolean literals would be nice. I personally findwhile (true)
more readable and the intent more explicit thanfor (;;)
. Also, there’s thedo { ... } while (false)
idiom, for which there is no substitute other than labelled blocks, which IMHO are ugly.As for boolean literal conditions in
if (true)
, etc., that can still be caught byno-unreachable-code
.So 👍 from me.
@kaicataldo Go for it.