Skip to content

Bug: [no-extra-parens] incorrect precedence for await vs assertion #5124

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
bradzacher opened this issue May 31, 2022 · 1 comment · Fixed by #5428
Closed
4 tasks done

Bug: [no-extra-parens] incorrect precedence for await vs assertion #5124

bradzacher opened this issue May 31, 2022 · 1 comment · Fixed by #5428
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working formatting Related to whitespace/bracket formatting. We strongly recommend you use a formatter instead. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@bradzacher
Copy link
Member

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=4.7.2&sourceType=module&code=IYZwngdgxgBAZgV2gFwJYHsLwBTIBaoQDmAXDMBGAJQwDeAUDOQO7CrIy4HHkgwAKAJ3QBbVCACmAHgBu6VABMAfFQDc9AL70gA&eslintrc=N4KAkARApgHgLlAdgEwM4QFwAIDa5IAOANgK4DmAlohgAJwCeBUqAxgE4UFwC0zRVcAPR8B3NlBYB7ALbSkyKMggAafBGLkqtBk1YcuvVP0RCAhkSIQQWLAF1VNiGxJFmmLKBuO6jZu048IiaCiJLc0hSoJKiK3ARsMpFu2HheXtBsCWwq1mkeuXlYECwAFhIA1qgAapIUyABKUHAkbIjuAGbmMQVeAL499j0QPrr+BkFCobzwbKZxpuKI6Ck9jlCZktkD1v29QA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkAhqqrAO4BSZlemArugDTgaMABbpoAa3YUwAMwYl+g2iXHJEAGWQAjAMKiJ0rrwE0oRWAFF4yPIZ6LTkACYsiGAG7pUASTxY6BMR2xkpQJLDcmNDoALJ0iMEOQiRcyNC2nPYmQubeSKhpNgCCRACeidnKqekActyMemLiHGBGSbS5+YV4ACrCyC1yqAqVZrAAqkTcCk7qsNDyFaGQ5pPT6E4ACnSYdPDofpiD8u1jeYgF0DYASgeRpEuO5gBiDKh4wpgRAObCOnQKEjeIgAZWYNmgwkeOQmREhTQ2wKc6AAHhsitBoiRjsNTpB1pNxOZmERgf88JCAGo7ZB0LQYFptUaQVF0dK4QJEBibL6ILB4Uo9Up8nEjZboEgxWBOeroYGHWAJTIhRzI6CoHYBQhEaRDMWOZBIWCYPAACS8fKO0NoeB23wO0hZJAATAAGACMAHZIMz4NLZY6JURUbZmQArEgox2YdBs0PLLQA9DjTCoR0AOnTAHofcsIngACLITAZ7N+JC5xwxv2eHQIfZEPCM+yCAC+2RgCBQGGwoLonl1Jw7yDhqG4yOkAG1liQolmAFTzheVoR+FJZ7hEGxrvALpfzyCCAC6HdR6vH6Cny3MyIA+n6ZQzDxAjyBW0A

Repro Code

async function f(thing: any) {
  await (thing as Promise<void>);
}

ESLint Config

module.exports = {
	"extends": [
		"plugin:@typescript-eslint/eslint-recommended",
		"plugin:@typescript-eslint/all"
  ],
  "rules": {
    "@typescript-eslint/no-misused-promises": [
      "error",
      {
        "checksVoidReturn": false
      }
    ],
    "@typescript-eslint/no-extra-parens": [
      "error"
    ]
 }
}

tsconfig

No response

Expected Result

No error as these are necessary parentheses in order to ensure the assertion is applied to the await argument, not the await result.

Actual Result

Unnecessary parentheses around expression. 2:9 - 2:10

Additional Info

Found in #5121 cc @doberkofler

A big problem that I can see is that this rule uses our old-school hack-and-extend method for extending the lint rule.
Instead we should fork the lint rule and leverage our relatively new precedence utilities in order to correctly understand all cases.

Versions

package version
@typescript-eslint/eslint-plugin 5.27.0
@typescript-eslint/parser 5.27.0
TypeScript 4.7.2
ESLint 8.15.0
node web
@bradzacher bradzacher added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin accepting prs Go ahead, send a pull request that resolves this issue formatting Related to whitespace/bracket formatting. We strongly recommend you use a formatter instead. labels May 31, 2022
@armano2
Copy link
Collaborator

armano2 commented Jun 1, 2022

related #1587

JoshuaKGoldberg added a commit to yeonjuan/typescript-eslint that referenced this issue Aug 7, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 7, 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 formatting Related to whitespace/bracket formatting. We strongly recommend you use a formatter instead. 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