[英]Error when enabling react/jsx-sort-props [Rules of eslint-plugin-react]
I`m trying to sort props names alphabetically in my project using the plugin eslint-plugin-react .我正在尝试使用插件eslint-plugin-react在我的项目中按字母顺序对道具名称进行排序。
I've read the jsx-sort-props rules option example and I'm here asking myself: What's props should be used in the <enable>
field?我已经阅读了jsx-sort-props 规则选项示例,我在这里问自己:在
<enable>
字段中应该使用什么道具?
...
"react/jsx-sort-props": [<enabled>, {
"callbacksLast": <boolean>,
"shorthandFirst": <boolean>,
"shorthandLast": <boolean>,
"multiline": "ignore" | "first" | "last",
"ignoreCase": <boolean>,
"noSortAlphabetically": <boolean>,
"reservedFirst": <boolean>|<array<string>>,
}]
...
I've tried everything but always get an invalid configuration notification:我什么都试过了,但总是收到无效的配置通知:
*Error: ESLint configuration in .eslintrc.JSON is invalid: Unexpected top-level property "react/jsx-sort-props".*
I'm editing it at my .eslintrc.json
file:我正在我的
.eslintrc.json
文件中编辑它:
{
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"next/core-web-vitals"
],
"react/jsx-sort-props": [<enabled>, {
"callbacksLast": true,
"shorthandFirst": false,
"shorthandLast": true,
"multiline": "last",
"ignoreCase": true,
"noSortAlphabetically": false,
"reservedFirst": false
}]
}
You need to put your rules into the rules
property of the object, not into the top level of the object:您需要将规则放入 object 的
rules
属性中,而不是放入 object 的顶层:
{
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"next/core-web-vitals"
],
"rules": {
"react/jsx-sort-props": [<enabled>, {
This helps clearly delimit the difference between ESLint configuration settings and rules - otherwise, the overlap would be confusing, and if there were ever a rule whose name conflicted with a possible other top-level property, there'd be problems.这有助于清楚地界定 ESLint 配置设置和规则之间的区别——否则,重叠会造成混淆,如果有一个规则的名称与其他可能的顶级属性发生冲突,就会出现问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.