[英]ESLint Extra Parentheses In JSX
I've noticed that extra parentheses are getting added to my multi-line conditional renders using logical AND (&&) in my jsx files. 我注意到在jsx文件中使用逻辑AND(&&)将多余的括号添加到多行条件渲染中。 For example, this code from the React docs...
例如,此代码来自React文档...
{unreadMessages.length > 0 &&
<h2>
You have {unreadMessages.length} unread messages.
</h2>
}
...would get modified as follows: ...将进行如下修改:
{unreadMessages.length > 0 && (
<h2>
You have {unreadMessages.length} unread messages.
</h2>
)}
Here is my ESLint config : 这是我的ESLint配置 :
"eslintConfig": {
"root": true,
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"impliedStrict": true
}
},
"env": {
"browser": true,
"node": true,
"es6": true,
"mocha": true
},
"plugins": [
"react"
],
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"rules": {
"computed-property-spacing": [
"error"
],
"indent": [
"error",
2
],
"jsx-quotes": [
"error"
],
"key-spacing": [
"error"
],
"no-case-declarations": [
"off"
],
"no-console": [
"off"
],
"no-var": [
"error"
],
"object-curly-spacing": [
"error",
"always"
],
"prefer-const": [
"error"
],
"quotes": [
"error",
"single",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
],
"react/no-children-prop": "off",
"react/prop-types": "off",
"semi": [
"error",
"never"
]
}
}
Have I inadvertently caused this, or is there a good reason for it? 是我无意间造成了这种情况,还是有充分的理由呢? If not, how can I prevent this?
如果没有,我该如何预防? It seems like overkill to disallow unnecessary parentheses .
禁止不必要的括号似乎过大了。
看起来这是由react / jsx-wrap-multilines引起的 ,可以通过将logical
语法类型设置为"ignore"
来防止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.