Skip to content

[return-await] --fix (amusingly) confused by ternaries #1838

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
FauxFaux opened this issue Apr 2, 2020 · 0 comments · Fixed by #2168
Closed

[return-await] --fix (amusingly) confused by ternaries #1838

FauxFaux opened this issue Apr 2, 2020 · 0 comments · Fixed by #2168
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@FauxFaux
Copy link

FauxFaux commented Apr 2, 2020

Repro

{
  "rules": {
    "@typescript-eslint/return-await": ["error", "always"],
  }
}
async function one() {}
async function one() {}
async function two() {}
async function three() {}

async function problem() {
  return (await one()) 
    ? two()
    : three();
}

Expected Result

async function problem() {
  return await ((await one()) 
    ? two()
    : three());
}

or:

async function problem() {
  return (await one()) 
    ? await two()
    : await three();
}

I think I prefer the second?

Actual Result

return await await await await await await await await await await (await one()) ? two() : three();

Yes, that's ten of them.

Additional Info

This new code is valid, possibly not even wrong? I don't know the binding order on await foo ? bar : baz;. It does, however, trigger "unnecessary await", pretty amusingly.

Full eslintrc / package.json (templates, without this specific lint enabled, at least, at time of writing):
https://github.com/snyk/unless-overloaded/blob/master/.eslintrc.json
https://github.com/snyk/unless-overloaded/blob/master/package.json

Versions

package version
@typescript-eslint/eslint-plugin 2.26.0
@typescript-eslint/parser 2.26.0
TypeScript 3.8.3
ESLint 6.8.0
node 12.16.1
npm 6.14.1
@FauxFaux FauxFaux added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Apr 2, 2020
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for team members to take a look labels Apr 2, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants