简体   繁体   English

如何使用 eslint 只修复一个规则

[英]How to fix just one rule using eslint

I want to use eslint command flag --fix to just fix one rule.我想使用 eslint 命令标志--fix来修复一个规则。 And I tried the command: eslint --fix --config ./.eslintrcsomerules.js .我尝试了命令: eslint --fix --config ./.eslintrcsomerules.js . . . But it does not work.但它不起作用。 How to achieve the object?如何达到目的?

My .eslintrcsomerules.js file is below:我的.eslintrcsomerules.js文件如下:

module.exports = {
  'rules': {
    'indent': [2, 2],
  }
};

To fix the issues caused by just one rule, you need to combine --fix --rule with --no-eslintrc .要解决一条规则引起的问题,您需要将--fix --rule--no-eslintrc结合使用。 Otherwise your rule will just be merged with your existing configuration and all fixable issues will be corrected.否则,您的规则将与您现有的配置合并,所有可修复的问题都将得到纠正。 Eg例如

$ eslint --no-eslintrc --fix --rule 'indent: [2, 2]'

Depending on your setup you'll need to re-add mandatory settings from your ESLint configuration to the command line for the lint run to succeed.根据您的设置,您需要将 ESLint 配置中的强制性设置重新添加到命令行,以便 lint 运行成功。 In my case I had to use就我而言,我不得不使用

$ eslint --no-eslintrc --parser babel-eslint --fix --rule 'indent: [2, 2]'

You can pass a --rule flag with the rule you want to fix.您可以传递带有要修复的规则的--rule标志。 For example:例如:

eslint --fix --rule 'quotes: [2, double]' .

Check out the official documentation for more information.查看 官方文档以获取更多信息。

The list of available rules might also be helpful.可用规则列表也可能有帮助。

I struggled with this.我为此苦苦挣扎。 I was using create-react-app and it was very difficult to turn off all the rules but keep all the configs to parse ES6/TS/etc.我正在使用 create-react-app 并且很难关闭所有规则但保留所有配置来解析 ES6/TS/etc。

This library was exactly what I wanted!这个图书馆正是我想要的! I can see how many errors there are for each rule and selectively fix one rule at a time我可以看到每条规则有多少错误,并一次有选择地修复一个规则
https://github.com/IanVS/eslint-nibble https://github.com/IanVS/eslint-nibble

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

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