Improve "no-constant-condition" rule for generators
See original GitHub issueThis topic has been discussed already in https://github.com/eslint/eslint/issues/1299 and https://github.com/eslint/eslint/issues/2375 but per https://github.com/eslint/eslint/issues/2375#issuecomment-299883115 I’m opening a new issue for this.
https://github.com/eslint/eslint/issues/2375#issuecomment-255137510 has introduced a proposal for handling this which seems pretty reasonable:
Bad:
while(true) {
//...
}
Bad:
function*() {
while(true) {
//...
}
yield 'foo';
}
Good:
function*() {
while(true) {
yield 'foo';
}
}
~It should be noted that the same should also apply to async functions which have roughly similar semantics. Since both generators and async/await are starting to be adopted a lot more this topic should be revisited.~
/cc @platinumazure
Issue Analytics
- State:
- Created 6 years ago
- Reactions:9
- Comments:13 (10 by maintainers)
Top Results From Across the Web
no-constant-condition - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Why does ESLint trigger lint errors on while(true) using fibers?
I have come JS code with some infinite loops (we're using node-fibers to allow things to happen). ESLint hates: while (true) { }....
Read more >ESLint v2.0.0-alpha-2 released - ESLint中文文档
We just pushed ESLint v2.0.0-alpha-2, which is a preview release upgrade of ESLint. ... The no-constant-condition will pick up the same errors as ......
Read more >0420 - Chapter 09 - Generator Exciter and Voltage Regulator.
Since the load was increased with relatively constant voltage, the output current (and hence, output power) of the generator must increase. This power...
Read more >tslint-eslint-rules - npm Package Health Analysis | Snyk
Improve your TSLint with the missing ESLint Rules For more information about ... no-constant-condition, disallow use of constant expressions in conditions ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If possible, can I take on this issue?
@Andarist My take on that is, just like for infinite loops,
no-constant-condition
can’t know when you mean to have an infinite task or not so your best bet is to use// eslint-disable-line
comments on those cases.Infinite generators, on the other hand, are a completely different animal altogether and I think we should consider enhancing
no-constant-condition
to allow an option to exclude infinite loops in generator functions (as long as they haveyield
statements in them).So with all that said, I think I lean towards an exception for generators only.