react.js 'x' 被分配了一个值但从未使用过 no-unused-vars
react.js 'x' is assigned a value but never used no-unused-vars
我已经设置了 eslint 和 eslint-plugin-react。
当我 运行 ESLint 时,linter returns 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 }],
}
}
ESLint lint 行为是正确的。你已经声明了 x
但没有在你的 JSX 中使用。
如果使用它应该会消失:)
import React,{ Component } from 'react';
class Item extends Component{
render () {
const x = 1;
return (
<div>test {x}</div>
);
}
};
export default Item;
我已经设置了 eslint 和 eslint-plugin-react。
当我 运行 ESLint 时,linter returns 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 }],
}
}
ESLint lint 行为是正确的。你已经声明了 x
但没有在你的 JSX 中使用。
如果使用它应该会消失:)
import React,{ Component } from 'react';
class Item extends Component{
render () {
const x = 1;
return (
<div>test {x}</div>
);
}
};
export default Item;