简体   繁体   English

ESLint未检测到导入的React组件

[英]ESLint not detecting imported React Components

I am having an issue with ESLint not detecting imported React components with a 'no-unused-vars' rule. 我遇到一个问题,ESLint无法使用“ no-unused-vars”规则检测导入的React组件。 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: 我的.eslintrc.js文件如下:

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). 我正在使用安装了linter和linter-eslint软件包的原子文本编辑器(均为最新版本)。 What am I missing to make the linter detect the use of the imported component? 使短绒检测到导入组件的使用,我缺少什么?

ESLint by default does not detect variables used in JSX. 默认情况下,ESLint不检测JSX中使用的变量。 To mark them as used, you should use the jsx-uses-vars rule of the eslint-plugin-react plugin. 要将其标记为已使用,应使用eslint-plugin-react插件的jsx-uses-vars规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM