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.

Rule Change: Have `no-unreachable-loop` ignore async iterators

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:19 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
mafintoshcommented, Oct 27, 2021

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 😃

0reactions
nzakascommented, Dec 28, 2021

Closing due to age

Read more comments on GitHub >

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

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