Skip to content

Bug: no-floating-promises should not fire on Promise.resolve() #9192

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

Closed
4 tasks done
benmccann opened this issue Jun 1, 2024 · 2 comments
Closed
4 tasks done

Bug: no-floating-promises should not fire on Promise.resolve() #9192

benmccann opened this issue Jun 1, 2024 · 2 comments
Labels
bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin wontfix This will not be worked on working as intended Issues that are closed as they are working as intended

Comments

@benmccann
Copy link
Contributor

benmccann commented Jun 1, 2024

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.4.5&fileType=.tsx&code=FABQTg9gtglgzgUwHRgXCAbAbggFASgG5gg&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1oDN4OBDfMwDmtYtA4BbSshTooiaBOiRwYAL4hNQA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

Promise.resolve();

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-floating-promises": "error",
  },
};

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

The rule should not trigger because it's impossible for Promise.resolve() to fail. Thus, there is no need for a catch. The rule should only trigger when a promise is passed to Promise.resolve

Actual Result

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. 2:1 - 2:19

Add void operator to ignore.

Additional Info

No response

@benmccann benmccann added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jun 1, 2024
@Josh-Cena
Copy link
Member

In what situation would you end up with code like this?

I think in general it's impossible for us to detect which promises can never fail, and we have several solutions:

I see that in sveltejs/svelte#11842, your code actually looks like:

Promise.resolve().then(() => {
  // ...
});

But then the then handler failing would still result in a rejected promise which you need to handle.

@benmccann
Copy link
Contributor Author

But then the then handler failing would still result in a rejected promise which you need to handle.

Good point

@Josh-Cena Josh-Cena closed this as not planned Won't fix, can't repro, duplicate, stale Jun 1, 2024
@Josh-Cena Josh-Cena added wontfix This will not be worked on working as intended Issues that are closed as they are working as intended and removed triage Waiting for team members to take a look labels Jun 1, 2024
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Jun 9, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin wontfix This will not be worked on working as intended Issues that are closed as they are working as intended
Projects
None yet
Development

No branches or pull requests

2 participants