Thanks to visit codestin.com
Credit goes to github.com

Skip to content

docs: improve return-await description about motivation #9201

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

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

Josh-Cena
Copy link
Member

PR Checklist

Overview

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @Josh-Cena!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

Copy link

netlify bot commented Jun 1, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit f67809b
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/665b5b92c8dd8600085d3976
😎 Deploy Preview https://deploy-preview-9201--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (🟢 up 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

nx-cloud bot commented Jun 1, 2024

@@ -28,7 +28,7 @@ export default createRule({
name: 'return-await',
meta: {
docs: {
description: 'Enforce consistent returning of awaited values',
description: 'Enforce consistent awaiting of returned promises',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(praise) much better than the old text!

@@ -9,12 +9,14 @@ import TabItem from '@theme/TabItem';
>
> See **https://typescript-eslint.io/rules/return-await** for documentation.

Returning an awaited promise can make sense for better stack trace information as well as for consistent error handling (returned promises will not be caught in an async function try/catch).

This rule builds on top of the [`eslint/no-return-await`](https://eslint.org/docs/rules/no-return-await) rule.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i kinda think we should drop this, as well as the comments around the naming. the base rule has been deprecated for some time, and this rule has an independent life of its own now.

I think, instead, it would be better to relegate the reference to the base rule to a little info box saying (approximaely) "this was originally conceived as an extension rule associated with the eslint rule no-return-await, but that's no longer the case. The base rule became deprecated because it was realized that it did more harm than good, due to limitations of not having access to type information. If you're interested in reading on the history of that decision, see <insert link>"

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the base rule was deprecated because it was based on the false premise that return promise; is faster than return await promise;, which may be true for some time but not anymore. return await promise; is desirable in all other regards. It's totally possible to build a type-unaware rule that changes return await something; to return something;, but not in the other direction.

I think we should keep it at least for another ESLint major version, as people are still familiar with this rule.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the base rule was deprecated because it was based on the false premise that return promise; is faster than return await promise;

Right, performance was the once-believed-but-now-debunked good.

return await promise; is desirable in all other regards. It's totally possible to build a type-unaware rule that changes return await something; to return something;, but not in the other direction.

harm, due to limitations of not having access to type information.


That's where I get my summary that it was doing more harm than good due to the limitations of not having access to type information 🙂 But no need to use this wording if you feel otherwise!

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite only being a ~dozen added lines, this somehow makes the rule's doc page much more clear & informative. Very nicely done @Josh-Cena! 👏 😍

Shawshank Redemption scene where Andy is smiling and raising his arms to the rain. Caption: "AND IT'S GLORIOUS"

@JoshuaKGoldberg JoshuaKGoldberg merged commit af34737 into typescript-eslint:main Jun 17, 2024
61 checks passed
@Josh-Cena Josh-Cena deleted the return-await-doc branch June 17, 2024 13:41
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve return-await rule description, and better explain stack trace benefits
4 participants