10000 [no-extra-parens] False positive when calling generic function with single argument and type parameter with parentheses · Issue #2314 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

[no-extra-parens] False positive when calling generic function with single argument and type parameter with parentheses #2314

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 8000 .

Already on GitHub? Sign in to your account

Closed
cherryblossom000 opened this issue Jul 21, 2020 · 1 comment · Fixed by #2319
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@cherryblossom000
Copy link
Contributor
cherryblossom000 commented Jul 21, 2020

Repro

{
  "rules": {
    "@typescript-eslint/no-extra-parens": 2
  }
}
declare module 'test' {
  class C {}
  export = C
}
declare const f: <T>(x: any) => any

f<import('test')>(1)

Expected Result

No errors because f<import('test')>1 isn't valid syntax.

Actual Result

8:18  error  Unnecessary parentheses around expression  @typescript-eslint/no-extra-parens

Additional Info

This seems to be because of getParentSyntaxParen used in isParentheszied in eslint-utils. Normally, the 1 in f(1) isn't considered to be parenthesised because the ( to the left of 1 is the same the first ( after f. With f<import('test')>(1), the first ( after f is the one used in import('test'), so 1 is reported for being an unnecessarily parenthesised literal.

This function is used in ESLint in isParenthesized -> hasExcessParensWithPrecedence -> checkCallNew.

This could be fixed by reducing the precedence of the argument node.

Versions

package version
@typescript-eslint/eslint-plugin 3.7.0
@typescript-eslint/parser 3.7.0
TypeScript 3.9.7
ESLint 7.5.0
node 12.18.2
npm 6.14.5
@cherryblossom000 cherryblossom000 added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jul 21, 2020
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for team members to take a look labels Jul 21, 2020
@cherryblossom000
Copy link
Contributor Author

This also happens for any type parameter containing parentheses:

f<(A | B) & C>(1)

@cherryblossom000 cherryblossom000 changed the title [no-extra-parens] False positive when calling generic function with single argument and import(...) type [no-extra-parens] False positive when calling generic function with single argument and type parameter with parentheses Jul 22, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 27, 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
2 participants
0