eslint: Rule Change: Have `no-unreachable-loop` ignore async iterators
What 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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19 (17 by maintainers)
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 😃