规则&Quot;Reaction/JSX-Sort-Props&Quot;的配置无效 [英] Invalid configuration for rule "react/jsx-sort-props"

查看:24
本文介绍了规则&Quot;Reaction/JSX-Sort-Props&Quot;的配置无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用插件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
        }
    ]
}

这篇关于规则&Quot;Reaction/JSX-Sort-Props&Quot;的配置无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆