Skip to content

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

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
3 tasks done
lexanth opened this issue Apr 20, 2021 · 1 comment · Fixed by #3577
Closed
3 tasks done

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

lexanth opened this issue Apr 20, 2021 · 1 comment · Fixed by #3577
Labels
enhancement New feature or request package: scope-manager Issues related to @typescript-eslint/scope-manager

Comments

@lexanth
Copy link
Contributor

lexanth commented Apr 20, 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": {
    "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
@lexanth lexanth added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Apr 20, 2021
@bradzacher bradzacher added enhancement New feature or request package: scope-manager Issues related to @typescript-eslint/scope-manager and removed package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Apr 20, 2021
@tanohzana
Copy link
Contributor

Working on it! 🤝

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request package: scope-manager Issues related to @typescript-eslint/scope-manager
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants