Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何使用React设置Eslint_Reactjs_Webpack_Eslint - Fatal编程技术网

Reactjs 如何使用React设置Eslint

Reactjs 如何使用React设置Eslint,reactjs,webpack,eslint,Reactjs,Webpack,Eslint,我将webpack与React和Eslint一起使用,我已经在Eslint上设置了扩展,但是它仍然说,“React”已定义,但从未使用过。eslintno未使用的变量 这是我的.eslintrc文件: { "parser": "babel-eslint", "extends": ["eslint:recommended", "plugin:react/recommended", &

我将webpack与React和Eslint一起使用,我已经在Eslint上设置了扩展,但是它仍然说,
“React”已定义,但从未使用过。eslintno未使用的变量

这是我的.eslintrc文件:

{
    "parser": "babel-eslint",
    "extends": ["eslint:recommended", "plugin:react/recommended", "airbnb", "prettier"],
    "parserOptions": {
        "sourceType": "module",
        "ecmaVersion": 2015
    },
    "env": {
        "browser": true,
        "node": true,
        "jest": true,
        "commonjs": true
    },
    "rules": {
        "react/jsx-uses-react": "error",
        "react/jsx-uses-vars": "error",
        "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
        "linebreak-style": "off",
        "no-undef": "off",
        "no-debugger": "off",
        "no-alert": "off",
        "indent": ["error", 4],
        "quotes": "off",
        "no-console": "off"
    }
}
React版本为
^17.0.1

babel eslint是
^10.1.0

eslint是
^7.14.0


eslint插件react是
^7.21.5

看起来它与文件中的实际JSX有关

您的配置在实际包含有效JSX的文件上运行良好:

// App.jsx
import React from 'react'; // 
const App = () => {
    return <div />; // JSX
}

export default App
// App.jsx
import React from 'react'; // 'React' is defined but never used 
const App = () => {
    return 1; // no JSX
}

export default App