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

Enhancement: [no-floating-promises] Don't check coincidentally Promise-like (Thenable) type values by default #8433

Open
4 tasks done
JoshuaKGoldberg opened this issue Feb 11, 2024 · 0 comments
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@JoshuaKGoldberg
Copy link
Member

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

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

Description

Forwarding out from conversations with @mcollina, especially nodejs/node#51292 (comment): right now no-floating-promises will consider anything that looks like a Promise (i.e. is "Promise-like") to be a potential floating value:

But to my knowledge this hasn't been particularly helpful. If something coincidentally happens to match the Thenable interface that doesn't necessarily mean it shouldn't float!

The historical context here is that it used to be common in JavaScript code to use alternative implementations of Promises, such as Bluebird. Promises were only added to some browsers in ~2014 and Node & co in ~2015 or so. Many sites still had to support old versions of Internet Explorer. The no-floating-promises typescript-eslint rule was implemented in 2019 when it was still not-unheard-of to use alternative Promises or at least have Promise types provided by a polyfill: #495.

Now that the vast majority of projects are using built-in Promise values & types, I think the value of detecting those values automatically is no longer worth the pain of flagging general thenables. I propose we modify the rule to:

  • (non-breaking) Add in an option to specify types to be considered Promises - using the same standard format as Enhancement: [no-floating-promises] add an 'allowForKnownSafePromises' option #7008
  • (breaking, as a followup issue & PR for v8) Change the rule to no longer detect Thenables, and instead only look for the built-in Promise type
    • Nuance: should users be able to remove the built-in Promise type from the list of checked types? I don't think so, but that's not a decision we'd need to make now...

I.e. this is the opposite of #7008. That issue is about adding an allowlist for types to be allowed to float. This one is adding a blocklist of types to not be allowed to float - instead of always detecting Thenables.

Fail

declare function createPending(): PromiseLike<void>;

createPending();

Pass

declare function createPending(): Promise<void>;

createPending();

Additional Info

After the proposed followup, if folks still want to detect floating PromiseLikes, they'd be able to use this option.

As to whether we'd want to give users a way to opt back into the current "check anything that looks like a Thenable" behavior... I don't see why anybody would want that, but we could always make it an option if someone asks for it.

@JoshuaKGoldberg JoshuaKGoldberg added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look enhancement: plugin rule option New rule option for an existing eslint-plugin rule labels Feb 11, 2024
@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants