admin管理员组文章数量:1387360
I am having an issue with ESLint not detecting imported React ponents with a 'no-unused-vars' rule. My ponents are imported:
import MediaQuery from 'react-responsive';
and the ponent 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:
module.exports = {
"env": {
"browser": true,
"monjs": true,
"es6": true,
"node": true
},
"extends": "eslint:remended",
"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). What am I missing to make the linter detect the use of the imported ponent?
I am having an issue with ESLint not detecting imported React ponents with a 'no-unused-vars' rule. My ponents are imported:
import MediaQuery from 'react-responsive';
and the ponent 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:
module.exports = {
"env": {
"browser": true,
"monjs": true,
"es6": true,
"node": true
},
"extends": "eslint:remended",
"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). What am I missing to make the linter detect the use of the imported ponent?
Share Improve this question edited Feb 25, 2017 at 17:16 Dan Lowe 56.9k20 gold badges131 silver badges114 bronze badges asked Feb 25, 2017 at 13:14 bgmasterbgmaster 2,3334 gold badges28 silver badges42 bronze badges 2- @MayankShukla The errors is 'no-unused-vars'. You can read more about it at the eslint docs: eslint/docs/rules/no-unused-vars – bgmaster Commented Feb 26, 2017 at 16:53
- No, it appears to have to do with my React configuration, but I'm not sure what. I'm not super familiar with ESLint and how it needs to be configured. – bgmaster Commented Feb 26, 2017 at 16:56
1 Answer
Reset to default 6ESLint by default does not detect variables used in JSX. To mark them as used, you should use the jsx-uses-vars rule of the eslint-plugin-react plugin.
本文标签: javascriptESLint not detecting imported React ComponentsStack Overflow
版权声明:本文标题:javascript - ESLint not detecting imported React Components - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744533467a2611173.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论