Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require-await should be disabled for async generators #12459

Closed
mikeal opened this issue Oct 18, 2019 · 10 comments · Fixed by #13048
Closed

require-await should be disabled for async generators #12459

mikeal opened this issue Oct 18, 2019 · 10 comments · Fixed by #13048
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly enhancement This change enhances an existing feature of ESLint help wanted The team would welcome a contribution from the community for this issue rule Relates to ESLint's core rules

Comments

@mikeal
Copy link

mikeal commented Oct 18, 2019

What rule do you want to change? require-await

Does this change cause the rule to produce more or fewer warnings? neither

How will the change be implemented? (New option, new default behavior, etc.)? new default behavior

Please provide some example code that this change will affect:

Currently, require-await is enabled for both async functions and async generators.

The problem with this when it comes to generators is that the return value of an async generator contains symbols that a regular generator does not, making it quite different from async functions which are just regular functions that return promises.

Since generators yield rather than return a value, an async generator might yield all the values of another async generator without ever actually needing to use await.

async function * () {
  yield * anotherAsyncGenerator()
}

If you remove the async syntax the generator will fail with the following error:

TypeError: yield* (intermediate value) is not iterable

You can’t actually yield * of an async generator from a regular generator because the generator has to have the right symbols in order to be consumed properly. The VM guards against this and gives us a rather obtuse error.

IMO, it’s probably best to just disable await checking for async generators.

What does the rule currently do for this code? It fails on the required form and will not pass unless disabled.

What will the rule do after it's changed? Not check async generators for await.

Are you willing to submit a pull request to implement this change? Nope.

@mikeal mikeal added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules triage An ESLint team member will look at this issue soon labels Oct 18, 2019
@dmitryrn
Copy link

I'll pick it up

@eslint-deprecated
Copy link

Unfortunately, it looks like there wasn't enough interest from the team
or community to implement this change. While we wish we'd be able to
accommodate everyone's requests, we do need to prioritize. We've found
that issues failing to reach accepted status after 21 days tend to
never be accepted, and as such, we close those issues.
This doesn't mean the idea isn't interesting or useful, just that it's
not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

@kaicataldo
Copy link
Member

Reopening this since it seems to have slipped between the cracks.

This makes sense to me, but I’d like to hear what the rest of the team has to say.

@kaicataldo kaicataldo reopened this Nov 24, 2019
@kaicataldo kaicataldo added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion bug ESLint is working incorrectly and removed auto closed The bot closed this issue triage An ESLint team member will look at this issue soon labels Nov 24, 2019
@mysticatea
Copy link
Member

Sorry for the lack of activity here.

This makes sense to me.

@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Nov 24, 2019
@ljharb
Copy link
Sponsor Contributor

ljharb commented Nov 24, 2019

This makes sense to me too, but a regular async function also might never need to use await for identical reasons, so if this change makes sense, I'd suggest this entire rule be removed in the next major :-)

@mikeal
Copy link
Author

mikeal commented Jan 11, 2020

@ljharb it’s a bit different.

If you want to require await in all async functions and someone needs to produce an async function that doesn’t have await in it, they can just create a function that returns a promise. This will satisfy whatever need they have in-code and satisfy the linter rule.

For an async generator this isn’t the case because a regular generator that wasn’t created using the syntax won’t have the correct symbols.

@ljharb
Copy link
Sponsor Contributor

ljharb commented Jan 11, 2020

You can manually make a function that returns an object with Symbol.asyncIterator too, but I recognize there's a pretty big difficulty delta between "manually make a promise" and "manually make an asynchronous state machine".

@mikeal
Copy link
Author

mikeal commented Jan 11, 2020

@ljharb oh totally, i wouldn’t even know how to do that if i hadn’t had to dig through Node.js Core’s async generator support for Streams. most JS developers don’t even know Symbol is a thing ;)

@kaicataldo kaicataldo added help wanted The team would welcome a contribution from the community for this issue good first issue Good for people who haven't worked on ESLint before labels Feb 7, 2020
@kaicataldo kaicataldo removed the good first issue Good for people who haven't worked on ESLint before label Feb 17, 2020
@eslint-deprecated eslint-deprecated bot added the auto closed The bot closed this issue label Mar 19, 2020
@eslint-deprecated
Copy link

Unfortunately, it looks like there wasn't enough interest from the team
or community to implement this change. While we wish we'd be able to
accommodate everyone's requests, we do need to prioritize. We've found
that accepted issues failing to be implemented after 90 days tend to
never be implemented, and as such, we close those issues.
This doesn't mean the idea isn't interesting or useful, just that it's
not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

@mdjermanovic
Copy link
Member

Reopening since there are open PRs for this issue.

@mdjermanovic mdjermanovic reopened this Mar 19, 2020
@mdjermanovic mdjermanovic removed the auto closed The bot closed this issue label Mar 19, 2020
kaicataldo added a commit that referenced this issue Mar 28, 2020
* Fix: require-await should ignore async generators (fixes #12459)

* Chore: docs update and test update

* Docs: fixed typo for generator to generators

Co-Authored-By: Kai Cataldo <kai@kaicataldo.com>

* Chore: added more tests for async generators

Co-authored-by: Kai Cataldo <kai@kaicataldo.com>
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Sep 25, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Sep 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly enhancement This change enhances an existing feature of ESLint help wanted The team would welcome a contribution from the community for this issue rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants