Skip to content

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

@cherryblossom000

Description

@cherryblossom000

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy