规则&Quot;Reaction/JSX-Sort-Props&Quot;的配置无效

人气:236 发布:2022-10-16 标签: javascript node.js reactjs eslint next.js

问题描述

我正在尝试使用插件eslint-plugin-react按字母顺序对道具名称进行排序,但遇到以下错误:

[Error ] .eslintrc.json: Configuration for rule "react/jsx-sort-props" is invalid: Value {"callbacksLast":true,"shorthandFirst":false,"shorthandLast":true,"multiline":"last","ignoreCase":true,"noSortAlphabetically":false} should NOT have additional properties. 

这是我的.eslintrc.json文件:

{
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "next/core-web-vitals"
  ],

  "rules": {
    "react/jsx-sort-props": [
      "2",
      {
        "callbacksLast": true,
        "shorthandFirst": false,
        "shorthandLast": true,
        "multiline": "last",
        "ignoreCase": true,
        "noSortAlphabetically": false
      }
    ]
  }
}

我错过了什么?

推荐答案

有两个问题:

如果您使用的是数字,则严重性选项应该是数字,而不是包含数字的字符串-2,而不是"2"。(不过,就我个人而言,我建议使用"error"-通过阅读配置可以更清楚地了解规则对您的项目意味着什么-"error"2更直观) Linter规则的jsx-sort-props.js中存在错误-尽管文档引用了multiline属性,但该属性在LINT规则实现中不存在,因此当您传入包含该属性的对象时会抛出错误。删除它。
"rules": {
    "react/jsx-sort-props": [
        2,
        {
            "callbacksLast": true,
            "shorthandFirst": false,
            "shorthandLast": true,
            "ignoreCase": true,
            "noSortAlphabetically": false
        }
    ]
}

582