Description
- 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:
Referencer
(https://github.com/typescript-eslint/typescript-eslint/blob/498f397ff3898dde631f37311615b555f38a414e/packages/scope-manager/src/referencer/Referencer.ts) is referencing the JSX pragma (React
by default) anywhere that it finds JSX in use- It is therefore not marked as unused
jsxFragmentName
allows being ignored by being set to null, butjsxPragma
does not
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 |