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

Docs: Overhaul no-floating-promise messages and docs #8088

Open
2 tasks done
JoshuaKGoldberg opened this issue Dec 18, 2023 · 5 comments
Open
2 tasks done

Docs: Overhaul no-floating-promise messages and docs #8088

JoshuaKGoldberg opened this issue Dec 18, 2023 · 5 comments
Assignees
Labels
documentation Documentation ("docs") that needs adding/updating team assigned A member of the typescript-eslint team should work on this.
Milestone

Comments

@JoshuaKGoldberg
Copy link
Member

Before You File a Documentation Request Please Confirm You Have Done The Following...

Suggested Changes

Right now, @typescript-eslint/no-floating-promises logs quite a mouthful for its messages:

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.

So much text! Longer messages are less likely to be read by users - especially "error" (or "warning") messages like this one.

In addition, it's also missing the point that storing the Promise in a variable is considered an acceptable workaround by the rule (assuming you have unused variable detection enabled). #8046 is an example of a discussion asking about that.

This is a nuanced area. See replies to: https://twitter.com/flybayer/status/1469098848958222337, https://twitter.com/threepointone/status/1471458830626299911, https://twitter.com/nandafyi/status/1736164705448956388, and other threads from searching on no-floating-promises). I think we should rework the rule a bit to coach/encourage developers into treating the nuance with care:

  • Make the error message much shorter (so folks will actually read the whole thing), and perhaps encourage them to read the docs for more info
  • Mention the unused variable allowance in the docs
  • Link to a blog post explaining how to enable our Promise/Thenable-area rules (perhaps a separate issue?)

Affected URL(s)

https://typescript-eslint.io/rules/no-floating-promises

@JoshuaKGoldberg JoshuaKGoldberg added triage Waiting for maintainers to take a look documentation Documentation ("docs") that needs adding/updating labels Dec 18, 2023
@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Jan 6, 2024
@JoshuaKGoldberg JoshuaKGoldberg modified the milestone: 8.0.0 Feb 7, 2024
@JoshuaKGoldberg
Copy link
Member Author

Since #7008 was added to the 8 milestone for tracking, adding this as well. I think we'll really need to have good docs to make sure folks don't misuse this.

@JoshuaKGoldberg
Copy link
Member Author

Btw, referencing #7008 & nodejs/node#51292 & reduxjs/redux-toolkit#4102: we should definitely mention strategies for frameworks/libraries to mark Promises as safe (or not expose them).

@JoshuaKGoldberg
Copy link
Member Author

Note: #8573 has a good suggestion:

I fixed a no-floating-promises error by changing:

- promise.catch(() => {}).then(() => {})
+ promise.catch(() => {}).finally(() => {})

I think this is a good change! Since my .catch() handler couldn't reject, it's probably not even a change.

The .catch().then() form is mentioned on MDN and triggers this rule (playground). So it would be helpful if the docs on this rule included an example of the suggested refactor.

@JoshuaKGoldberg
Copy link
Member Author

Marking as blocked on PRs implementing #7008 and #8404, as I'd neglected to note this publicly till now. 🙂

@JoshuaKGoldberg JoshuaKGoldberg added team assigned A member of the typescript-eslint team should work on this. and removed accepting prs Go ahead, send a pull request that resolves this issue blocked by another PR PRs which are ready to go but waiting on another PR labels Jun 2, 2024
@JoshuaKGoldberg
Copy link
Member Author

JoshuaKGoldberg commented Jun 3, 2024

Now that #9186 is merged, I believe this is almost unblocked. I'd like to tackle it alongside #8517.

#8404 would be great too. Marking as blocked on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation ("docs") that needs adding/updating team assigned A member of the typescript-eslint team should work on this.
Projects
None yet
Development

No branches or pull requests

1 participant