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

[no-floating-promises] Should not report on async IIFEs #647

Closed
sindresorhus opened this issue Jun 26, 2019 · 4 comments · Fixed by #1799
Closed

[no-floating-promises] Should not report on async IIFEs #647

sindresorhus opened this issue Jun 26, 2019 · 4 comments · Fixed by #1799
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@sindresorhus
Copy link

Repro

{
  "rules": {
    "@typescript-eslint/no-floating-promises": "error"
  }
}
(async () => {
	await something();
})();

Expected Result

I expected it not to report as it's an intentional action. It doesn't catch a mistake.

If you're not willing to add this exception by default, at least add an option to ignore async IIFEs.

Actual Result

It reports as a floating promise, which is technically correct, but not wanted behavior, at least from my perspective.

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 1.11.0
@typescript-eslint/parser 1.11.0
TypeScript 3.5.1
ESLint 5.16.0
node 8.16.0
npm 6.9.0
@sindresorhus sindresorhus added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Jun 26, 2019
@Jessidhia
Copy link
Contributor

Jessidhia commented Jun 26, 2019

Using the void operator makes this explicit, and the promise does not count as floating: void (async () => { /* ... */ })()

@bradzacher
Copy link
Member

I would be okay with this living as an option.

It is potentially a reportable error because you might be using an IIFE to enclose some logic + variables with the intention of awaiting the response. I've seen this pattern before because it saves you passing arguments in, and it avoids the locally scoped variables from leaking into the wider function.

Whilst you have intentionally done this pattern, it doesn't mean everyone will intentionally float a promise there.

@bradzacher bradzacher added enhancement: plugin rule option New rule option for an existing eslint-plugin rule and removed triage Waiting for maintainers to take a look labels Jun 26, 2019
@sindresorhus
Copy link
Author

You're right. An option would be best.

@glen-84
Copy link
Contributor

glen-84 commented Jul 22, 2019

@Jessidhia,

Using the void operator makes this explicit, and the promise does not count as floating: void (async () => { /* ... */ })()

While this is true in TSLint (at least for now), it doesn't appear to work in ESLint. Would this be considered a bug, or an enhancement request?

Edit: I've just noticed the discussion in #495.

@bradzacher bradzacher added the good first issue Good for newcomers label Jul 27, 2019
anikethsaha added a commit to anikethsaha/typescript-eslint that referenced this issue Mar 25, 2020
anikethsaha added a commit to anikethsaha/typescript-eslint that referenced this issue Mar 26, 2020
anikethsaha added a commit to anikethsaha/typescript-eslint that referenced this issue Apr 4, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants