question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve "no-constant-condition" rule for generators

See original GitHub issue

This 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:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
VictorHomcommented, Jun 12, 2017

If possible, can I take on this issue?

2reactions
platinumazurecommented, May 8, 2017

@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 have yield statements in them).

So with all that said, I think I lean towards an exception for generators only.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found