eslint doesn't catch some unused imports
See original GitHub issueWhen 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>
.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How can I remove unused imports/declarations from the entire ...
Old answer. eslint has a built-in fix option. If rules contains no-unused-vars , eslint will "fix" the unused import by removing them (along ......
Read more >eslint-plugin-unused-imports - npm
Find and remove unused es6 module imports. It works by splitting up the no-unused-vars rule depending on it being an import statement in...
Read more >eslint doesn't catch some unused imports · Issue #694 - GitHub
When I'm importing a component (say Input) which has other subcomponents as it's properties (like Input.Placeholder, Input.
Read more >Automatically Remove Unused Imports From Your JS Projects
Automatically remove unused imports. To automatically remove unused imports, we will need to add the eslint-plugin-unused-imports plugin.
Read more >no-unused-vars - ESLint - Pluggable JavaScript Linter
This rule is aimed at eliminating unused variables, functions, and function parameters. A variable foo is considered to be used if any of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I believe I found the bug. PR coming soon.
@ljharb yes,
jsx-uses-vars
is already set in eslintconfig. @lencioni’s PR seems good 😃