-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
eslint doesn't catch some unused imports #694
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
Comments
|
Actually, I was in two minds where to file it, and I tried to reproduce the same with normal javascript, but can't get eslint to show the same behaviour... For example, eslint does show proper errors in this case: import Button from './Button';
import Input from './Input';
export function f() {
return new Input.Button();
} |
This might be related to the jsx-uses-vars rule: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md |
@kumarharsh do you see the same behavior when you enable the |
I believe I found the bug. PR coming soon. |
When I'm importing a component (say Input) which has other subcomponents as it's properties (like Input.Placeholder, Input.Button, etc), and there is another different component imported by a same name (say Button), and then if I use <Input.Button> in my code then eslint doesn't tell that <Button> is unused. Reproducible code: ``` import React from 'react'; import Button from './Button'; import Input from './Input'; export default class X extends React.Component { render() { return <Input.Button />; } } ``` What should be expected? The import Button from './Button'; line should be highlighted with a no-unused-vars error. You can see this if you just use <Input> in the render function instead of <Input.Button>. This was happening because the rule was checking for all JSXIdentifiers, which included the object properties. I fixed this by having it check for JSXOpeningElements and then drilling down to get the variable name used from there. Fixes jsx-eslint#694
When I'm importing a component (say
Input
) which has other subcomponents as it's properties (likeInput.Placeholder
,Input.Button
, etc), and there is another different component imported by a same name (sayButton
), and then if I use<Input.Button>
in my code then eslint doesn't tell that<Button>
is unused.Reproducible code:
What should be expected?
The
import Button from './Button';
line should be highlighted with ano-unused-vars
error. You can see this if you just use<Input>
in the render function instead of<Input.Button>
.The text was updated successfully, but these errors were encountered: