Rule Change: Have `no-unreachable-loop` ignore async iterators
See original GitHub issueWhat rule do you want to change?
no-unreachable-loop
What change to do you want to make?
Generate fewer warnings
How do you think the change should be implemented?
A new default behavior
Example code
async function peek () {
for await (const data of createIterator()) {
return data
}
throw new Error('Not found')
}
What does the rule currently do for this code?
It complains that the loop can never reach the second iteration
What will the rule do after it’s changed?
It acknowledges that using a for await
like that is the easiest way of getting the first item from and async iterator and thus does not complain about the fact that the loop can never reach the second iteration
Participation
- I am willing to submit a pull request to implement this change.
Additional comments
Brought up by @mafintosh in https://github.com/standard/standard/issues/1723
Issue Analytics
- State:
- Created 2 years ago
- Comments:19 (10 by maintainers)
Top Results From Across the Web
no-unreachable-loop - ESLint - Pluggable JavaScript Linter
This rule aims to detect and disallow loops that can have at most one iteration, by performing static code path analysis on loop...
Read more >Why ESLint no-await-in-loop not working with for await of?
In my opinion, the rule is flawed as it is all or nothing. Enabling it means you want no loops with await in...
Read more >for await...of - JavaScript - MDN Web Docs
The for await...of statement creates a loop iterating over async iterable objects as well as sync iterables. This statement can only be used ......
Read more >List of available rules - ESLint - Pluggable JavaScript linter
These rules relate to possible syntax or logic errors in JavaScript code: ... no-unreachable ... disallow async functions which have no await expression....
Read more >JavaScript Advanced Notes - Iterator
If an iterator is not closable, you can continue iterating over it after an abrupt exit. ... eslint-disable-next-line no-unreachable-loop
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
Would it be possible to just add a config that allows us to target async iterators? This is mainly a usecase for us there, ie “get the first item of this async stream” etc, so we’d like to just disable the invalid-loop stuff in general on async iterators 😃
Closing due to age