Eslint-plugin-react: eslint doesn't catch some unused imports

Created on 20 Jul 2016  路  6Comments  路  Source: yannickcr/eslint-plugin-react

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

bug

Most helpful comment

I believe I found the bug. PR coming soon.

All 6 comments

no-unused-vars is a core eslint rule. The use of jsx here shouldn't interfere with it, but if it does, I'd say it might need filing as an issue directly on eslint?

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();
}

@kumarharsh do you see the same behavior when you enable the react/jsx-uses-vars rule?

I believe I found the bug. PR coming soon.

@ljharb yes, jsx-uses-vars is already set in eslintconfig. @lencioni's PR seems good :)

Was this page helpful?
0 / 5 - 0 ratings