简体   繁体   English

规则“react/jsx-sort-props”的配置无效

[英]Invalid configuration for rule "react/jsx-sort-props"

I'm trying to sort props names alphabetically using the plugin eslint-plugin-react but I'm getting this error:我正在尝试使用插件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. 

This is my .eslintrc.json file:这是我的.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
      }
    ]
  }
}

What I'm missing?我缺少什么?

There are two issues:有两个问题:

  • The severity option, if you're using a number, should be a number, not a string that contains a number - 2 , not "2" . severity 选项,如果你使用的是数字,应该是一个数字,而不是包含数字的字符串 - 2 ,而不是"2" (Though, personally, I'd suggest using "error" instead - it makes it clearer from reading the config what the rule means for your project - "error" makes more intuitive sense than 2 ) (不过,就我个人而言,我建议改用"error" ——通过阅读配置可以更清楚地了解规则对你的项目意味着什么—— "error"2更直观)
  • There is a bug in the linter rule's jsx-sort-props.js - although the docs reference a multiline property, said property does not exist anywhere in the lint rule implementation, and so an error is thrown when you pass in an object containing that property. jsx-sort-props.js中存在一个错误 - 尽管文档引用了multiline属性,但该属性在 lint 规则实现中的任何地方都不存在,因此当您传入包含该内容的 object 时会抛出错误财产。 Remove it.去掉它。
"rules": {
    "react/jsx-sort-props": [
        2,
        {
            "callbacksLast": true,
            "shorthandFirst": false,
            "shorthandLast": true,
            "ignoreCase": true,
            "noSortAlphabetically": false
        }
    ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM