是否包括相同ESLint规则的错误和警告? [英] Including both errors and warnings for same ESLint rule?

查看:34
本文介绍了是否包括相同ESLint规则的错误和警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队正在重构我们的代码库,并且我们正在使用ESLint来识别带有任何lint错误的文件.当前,我们有一个.eslintrc文件,该文件具有极高的阈值,并且随着对代码库中某些文件的改进,这些阈值正在降低.例如,我们的最大声明"阈值设置为99条语句,而我们的目标是将其降低到20条语句.因此,我们将阈值从99逐渐降低到98,再降低到97等,直到看到棉绒错误出现为止.然后,我们知道接下来要重构哪个文件.

My team is refactoring our codebase, and we're using ESLint to identify the files with any lint errors. We currently have one .eslintrc file with extremely high thresholds, and are ratcheting these thresholds down as we make improvements to certain files in the codebase. For example, our "max-statements" threshold is set to 99 statements, and our target is to get this down to 20 statements. So we incrementally lower our threshold from 99 to 98 to 97 etc., until we see a lint error appear. We then know which file to refactor next.

问题在于这种策略并不能阻止出血.继续上面的示例,假设引入了一个新的控制器,该控制器具有45个语句.此数字低于我们当前的阈值(因为我们的瓶颈文件有99条语句),但高于我们的目标阈值20条语句.

The problem is that this strategy doesn't stop the bleeding. To continue the above example, let's say a new controller is introduced which has 45 statements. This number is lower than our current threshold (because our bottleneck file has 99 statements), but higher than our target threshold of 20 statements.

理想情况下,我们希望看到任何违反我们当前阈值的皮棉错误的错误,以及警告那些违反目标阈值的皮棉错误的警告.这将为我们提供所有违规文件的列表,并首先对违反最严重的违规文件进行分类.例如:

Ideally, we'd like to see errors for any lint errors which violate our current thresholds, and warnings for lint errors which violate our target thresholds. This would give us a list of all offending files and triage the ones with the most egregious violations first. For example:

// inside .eslintrc
.... 
 "rules": {
   "max-statements": [2, 99],
   "max-statements": [1, 20]
 }
 ....

在这种情况下,对于任何包含20条以上语句的文件,我们都会看到警告,而对于包含99条以上语句的每个文件,则会出现错误.

In this case, we'd see warnings for any files with more than 20 statements, and errors for every file with more than 99 statements.

我尝试实现上述配置,但我担心,第一个最大声明"规则被第二个规则覆盖.

I tried implementing the above configuration, but as I feared, the 1st "max-statements" rule was overridden by the 2nd.

有什么办法可以实现我所描述的?

Is there any way to achieve what I described?

推荐答案

从命令行运行ESlint时,可以指定配置文件.只需使用不同的配置两次调用该命令即可.

When running ESlint from command line, you can specify the configuration file. Just call the command twice with different configurations.

实际上,您可以解析第一次运行的结果,并根据需要忽略第二次运行中有错误的文件.

You can actually parse the result from the first run and ignore files with errors in the second run, if needed.

这篇关于是否包括相同ESLint规则的错误和警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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