Closed
Description
Repro
{
"rules": {
"@typescript-eslint/no-unused-vars": [ "error" ]
}
}
import * as React from 'react';
// ERROR: 'Foo' is defined but never used. [Error/@typescript-eslint/no-unused-vars]
class Foo extends React.Component { }
export class Bar extends React.Component {
public render(): React.ReactNode {
return <Foo />
}
}
Expected Result
There should be no error for Foo, because it is used in the expression <Foo />
.
Actual Result
The error is reported.
Additional Info
In the AST, the reference appears inside a JSXIdentifier
node like this:
{
"type": "ReturnStatement",
"argument": {
"type": "JSXElement",
"openingElement": {
"type": "JSXOpeningElement",
"typeParameters": null,
"selfClosing": true,
"name": {
"type": "JSXIdentifier", // <====
"name": "Foo"
},
"attributes": []
},
"closingElement": null,
"children": []
}
}
Whereas the rule only considers regular Identifier
nodes:
typescript-eslint/packages/eslint-plugin/src/rules/no-unused-vars.ts
Lines 42 to 72 in 5eb40dc
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
2.0.0 |
@typescript-eslint/parser |
2.0.0 |
TypeScript |
3.5.2 |
ESLint |
6.1.0 |
node |
8.15.0 |
npm |
6.4.1 |