Skip to content

[no-unused-vars] False negative with new JSX transform #3303

Closed
@lexanth

Description

@lexanth
  • 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": {
    "react/jsx-uses-react": "off",
    "no-unused-vars": "off",
    "@typescript-eslint/no-unused-vars": "error"
  }
}
import React from 'react';

export const MyComponent = () => {
  return <div>Hello world</div>
}

In tsconfig, I have

  "compilerOptions": {
    "jsx": "react-jsx",

Expected Result
If using the new JSX transform, the React should be flagged as an unused variable.

NB: users may also be using the new JSX transform with jsx set to preserve in tsconfig (e.g. if using babel to actually transpile TS to JS), so should have a way to configure it otherwise.

Actual Result
React is identified as in use, so is not flagged as unused.

Additional Info
What I'm pretty sure is going on:

I'd suggest adding a condition if jsxPragma is null, just ignore it in referencing like it does with jsxFragmentName? Could also add some smarts to auto detect setting jsxPragma to null when the jsx option is react-jsx or react-jsxdev, but the null option would still be required to handle preserve as above (could be either).

Versions

package version
@typescript-eslint/eslint-plugin 4.19.0
@typescript-eslint/parser 4.19.0
TypeScript 4.2.3
ESLint 7.22.0
node 14.16.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpackage: scope-managerIssues related to @typescript-eslint/scope-manager

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions