Search code examples
javascriptreactjsatom-editoreslintlinter

ESLint not detecting imported React Components


I am having an issue with ESLint not detecting imported React components with a 'no-unused-vars' rule. My components are imported:

import MediaQuery from 'react-responsive';

and the component is used further down in the file:

render() {
  return (
    <MediaQuery maxDeviceWidth={750}>
      <div style={styles.iconMobileContainerRight} >
        <i className="fa fa-chevron-right" style={styles.checkboxMobile} aria-hidden="true" ></i>
      </div>
    </MediaQuery>
  );
}

My .eslintrc.js file is as follows:

module.exports = {
    "env": {
        "browser": true,
        "commonjs": true,
        "es6": true,
        "node": true
    },
    "extends": "eslint:recommended",
    "parserOptions": {
        "ecmaFeatures": {
            "experimentalObjectRestSpread": true,
            "jsx": true
        },
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
        "indent": [
            "error",
            2
        ],
        "linebreak-style": [
            "error",
            "unix"
        ],
        "quotes": [
            "error",
            "single"
        ],
        "semi": [
            "error",
            "always"
        ]
    }
};

I am using the atom text editor with the linter and linter-eslint packages installed (both up to date with the latest releases). What am I missing to make the linter detect the use of the imported component?


Solution

  • ESLint by default does not detect variables used in JSX. To mark them as used, you should use the jsx-uses-vars rule of the eslint-plugin-react plugin.