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

[return-await] wrong autofix of return undefined ?? promise to return await undefined ?? promise #4090

Closed
3 tasks done
fregante opened this issue Nov 5, 2021 · 3 comments · Fixed by #4401
Closed
3 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@fregante
Copy link
Contributor

fregante commented Nov 5, 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

{
  "rules": {
    "@typescript-eslint/await-thenable": "error"
  }
}
async function bar() {}
async function foo() {
	try {
		return window.foo ?? bar();
	} catch {}
}

tsconfig: https://github.com/sindresorhus/tsconfig/blob/67d56ca87d2790081696fe3d745befa7e9ff38b8/tsconfig.json

Expected Result

async function bar() {}
async function foo() {
	try {
		return window.foo ?? await bar();
		                  // ^ correct position of `await`
	} catch {}
}

Actual Result

async function bar() {}
async function foo() {
	try {
		return await await await await await await await await await await window.foo ?? bar();
		    // ^ incorrect position of `await`, which is then "autofixed" repeatedly
	} catch {}
}

Versions

package version
@typescript-eslint/eslint-plugin 5.3.0
@typescript-eslint/parser 5.3.0
TypeScript 4.4.4
ESLint 8.1.0
node 16.4.2
@fregante fregante added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Nov 5, 2021
@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers and removed triage Waiting for maintainers to take a look labels Nov 5, 2021
@bradzacher
Copy link
Member

I believe what's happening here is that it's not respecting the operator precedence - it should be wrapped with parentheses when fixed!

hoonoh added a commit to hoonoh/aws-spot-price that referenced this issue Nov 24, 2021
@armano2
Copy link
Member

armano2 commented Nov 27, 2021

@fregante i'm a little confused here. this rule doesn't have auto-fixer, and it doesn't report on this? are you sure this is related to await-thenable ?

@JoshuaKGoldberg JoshuaKGoldberg added awaiting response Issues waiting for a reply from the OP or another party and removed accepting prs Go ahead, send a pull request that resolves this issue labels Nov 28, 2021
@bradzacher
Copy link
Member

perhaps it's instead return-await? That's the only await rule with a fixer?

@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed awaiting response Issues waiting for a reply from the OP or another party labels Dec 20, 2021
@bradzacher bradzacher changed the title [await-thenable] wrong autofix of return undefined ?? promise to return await undefined ?? promise [return-await] wrong autofix of return undefined ?? promise to return await undefined ?? promise Dec 20, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
4 participants