Skip to content

[no-floating-promises] assigning unresolved promises doesn't cause an error #3359

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
3 tasks done
ATheCoder opened this issue May 7, 2021 · 1 comment
Closed
3 tasks done
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin working as intended Issues that are closed as they are working as intended

Comments

@ATheCoder
Copy link

ATheCoder commented May 7, 2021

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

module.exports = {
  env: {
    browser: true,
    amd: true,
    node: true,
  },
  root: true,
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: ['tsconfig.json'],
  },
  plugins: ['@typescript-eslint'],
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
  ],
  rules: {
    '@typescript-eslint/no-floating-promises': [2],
    '@typescript-eslint/strict-boolean-expressions': [2],
    "require-await": "off",
    "@typescript-eslint/no-misused-promises": [2]
  }
};
const foo = async () => console.log('a')
foo()
const bar = foo()

Expected Result
Both the second and third lines should be linted.

Actual Result

only the second line gets linted

Additional Info

I think assigning unresolved promises doesn't trigger no-floating-promises

Versions

package version
@typescript-eslint/eslint-plugin 4.22.1
@typescript-eslint/parser 4.22.1
TypeScript 3.9.7
ESLint 7.25.0
node 14.16.1
@ATheCoder ATheCoder added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels May 7, 2021
@bradzacher
Copy link
Member

This is intentional.

A floating promise is a promise that is left dangling and is not awaitable. Eg the second line.

Assigning a promise to a variable is not a floating promise because you can later await that variable.

It's a common pattern to do something like

const prom = somethingAsync();
// Do some work
await prom();

@bradzacher bradzacher added 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 May 8, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 8, 2021
@JoshuaKGoldberg JoshuaKGoldberg marked this as a duplicate of #10822 Feb 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin working as intended Issues that are closed as they are working as intended
Projects
None yet
Development

No branches or pull requests

2 participants