question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

eslint doesn't catch some unused imports

See original GitHub issue

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>.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
lencionicommented, Jul 24, 2016

I believe I found the bug. PR coming soon.

1reaction
kumarharshcommented, Jul 25, 2016

@ljharb yes, jsx-uses-vars is already set in eslintconfig. @lencioni’s PR seems good 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found