admin管理员组文章数量:1277298
I've setup eslint & eslint-plugin-react.
When I run ESLint, the linter returns no-unused-vars .
I'm assuming it's not recognizing that I'm using JSX or React syntax. Any ideas?
Line 5:11: 'x' is assigned a value but never used no-unused-vars
Example:
Please help me
Inside a file Component
import React,{ Component } from 'react';
class Item extends Component{
render () {
const x = 1;
return (
<div>test</div>
);
}
};
export default Item;
Inside a file .eslintrc.json
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:remended",
"plugin:react/remended",
"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 }],
}
}
I've setup eslint & eslint-plugin-react.
When I run ESLint, the linter returns no-unused-vars .
I'm assuming it's not recognizing that I'm using JSX or React syntax. Any ideas?
Line 5:11: 'x' is assigned a value but never used no-unused-vars
Example:
Please help me
Inside a file Component
import React,{ Component } from 'react';
class Item extends Component{
render () {
const x = 1;
return (
<div>test</div>
);
}
};
export default Item;
Inside a file .eslintrc.json
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:remended",
"plugin:react/remended",
"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 }],
}
}
Share Improve this question asked Jan 17, 2020 at 9:18 hichemhichem 1211 gold badge3 silver badges7 bronze badges 3-
1
const x = 1;
and you never usex
. Why do you think that the assignment would be used? – VLAZ Commented Jan 17, 2020 at 9:19 - 1 this happen because you are defining x but not use it.So, just remove it – Prakash Karena Commented Jan 17, 2020 at 9:21
- Wele to SO! Please note that it is appreciated to keep the provided code as explicit as neccessary, but as short as possible. You might want to have a look at stackoverflow./help/minimal-reproducible-example for some inspiration. – Twonky Commented Jan 17, 2020 at 10:00
3 Answers
Reset to default 2ESLint lint behavior is right. You've declared x
but don't use in your JSX.
It should disappear if use it:)
import React,{ Component } from 'react';
class Item extends Component{
render () {
const x = 1;
return (
<div>test {x}</div>
);
}
};
export default Item;
In production you may do differently, but you can always add a line before your variable declaration to ignore the warnings:
// eslint-disable-next-line
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:remended",
"plugin:react/remended",
"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 }]
}
}
本文标签: javascriptreactjs 39x39 is assigned a value but never used nounusedvarsStack Overflow
版权声明:本文标题:javascript - react.js 'x' is assigned a value but never used no-unused-vars - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741241573a2364081.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论