【发布时间】:2020-05-04 03:54:46
【问题描述】:
我已经设置了 eslint 和 eslint-plugin-react。
当我运行 ESLint 时,linter 返回 no-unused-vars 。
我假设它没有识别出我正在使用 JSX 或 React 语法。有什么想法吗?
第 5:11 行:“x”被赋值但从未使用过 no-unused-vars
例子:
请帮帮我
文件组件内部
import React,{ Component } from 'react';
class Item extends Component{
render () {
const x = 1;
return (
<div>test</div>
);
}
};
export default Item;
在文件 .eslintrc.json 中
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"react-app","prettier"
],
"settings": {
"react": {
"createClass": "createReactClass"
"pragma": "React",
"version": "detect",
"flowVersion": "0.53"
},
"propWrapperFunctions": [
"forbidExtraProps",
{"property": "freeze", "object": "Object"},
{"property": "myFavoriteWrapper"}
],
"linkComponents": [
"Hyperlink",
{"name": "Link", "linkAttribute": "to"}
]
},
"parserOptions": {
"ecmaVersion": 2018,
"ecmaFeatures": {
"jsx": true
}
},
"plugins": [
"react","prettier"
],
"rules": {
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"no-unused-vars": ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }],
}
}
【问题讨论】:
-
const x = 1;并且你从不使用x。您认为为什么会使用该作业? -
发生这种情况是因为您定义了 x 但没有使用它。所以,只需删除它
-
欢迎来到 SO!请注意,尽可能保持提供的代码尽可能明确,但尽可能简短。您可能想看看stackoverflow.com/help/minimal-reproducible-example 以获得一些灵感。
标签: javascript reactjs function eslint eslintrc