简体   繁体   English

ESLint:“react/sort-prop-types”错误可以自动修复吗?

[英]ESLint: Can "react/sort-prop-types" errors be auto-fixed?

I am using Eslint: v7.26.0 and have the following rule added to it:我正在使用Eslint: v7.26.0并添加了以下规则:

'react/sort-prop-types': [
  2,
  {
    callbacksLast: true,
    ignoreCase: false,
    requiredFirst: true,
    sortShapeProp: true,
    noSortAlphabetically: false,
  },
],

However, when I run the command to fix the ESLint issues, the issues thrown by this rule are not auto-fixed.但是,当我运行命令修复 ESLint 问题时,此规则引发的问题不会自动修复。

eslint --fix --format table someFile.js

Is there a way to auto-fix the errors thrown by this rule?有没有办法自动修复此规则引发的错误?

Sadly, this rule is not auto-fixable.可悲的是,此规则不可自动修复。

You can check the list of all the supported rules here .您可以在此处查看所有受支持规则的列表。
It also tells you if the rule fixable with eslint --fix and if it is enabled by default.它还告诉您规则是否可以使用eslint --fix ,以及它是否默认启用。

If you are using VSCode and have installed the ESLint extension , then it will show you all the errors during active development which you can then fix.如果你正在使用VSCode并且已经安装了ESLint 扩展,那么它会显示你在主动开发过程中的所有错误,然后你可以修复这些错误。

The only con of this is that you will have to manually fix the errors if you are in the middle of development唯一的缺点是,如果您处于开发过程中,您将不得不手动修复错误

sort-prop-types autofixer does sort within the spread boundaries: I think this is expected. sort-prop-types autofixer 确实在扩展边界内排序:我认为这是意料之中的。

https://github.com/yannickcr/eslint-plugin-react/blob/4a72e6a0784f7cc7f16f4574ce7f14de55540a73/tests/lib/rules/sort-prop-types.js#L1007-L1037 https://github.com/yannickcr/eslint-plugin-react/blob/4a72e6a0784f7cc7f16f4574ce7f14de55540a73/tests/lib/rules/sort-prop-types.js#L1007-L1037

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

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