我的配置中哪些eslint规则很慢?

问题描述 投票:15回答:2

我有一个包含大约100条规则的配置,并且在我的项目上使用所有这些规则运行eslint大约需要10秒。我想确定最慢的规则并消除其中的一些规则。我该怎么做呢?是否有任何用于eslint的分析器工具?

javascript profiling configuration-files eslint
2个回答
40
投票

如果设置了环境变量TIMING,则eslint显示规则的花费时间。例如:

$ TIMING=1 eslint lib
Rule                         | Time (ms) | Relative
:----------------------------|----------:|--------:
valid-jsdoc                  |   203.798 |     6.7%
camelcase                    |   142.146 |     4.6%
no-unmodified-loop-condition |   136.811 |     4.5%
indent                       |   127.138 |     4.2%
no-undefined                 |   124.525 |     4.1%
keyword-spacing              |    85.397 |     2.8%
space-in-parens              |    76.179 |     2.5%
no-this-before-super         |    72.317 |     2.4%
no-implied-eval              |    69.945 |     2.3%
space-infix-ops              |    57.128 |     1.9%

另见Per-rule Performance的官方文档。


4
投票

我发现删除慢速规则并没有多大帮助,因为加载eslint和解析文件需要一段时间。

可以使用--cacheeslint)的docs选项来大幅提升速度。

当在各种编辑器中使用eslint“lint-as-you-type”时,安装eslint_d允许运行eslint作为守护进程,并保存node加载时间。

在我正在进行的项目中,将eslint_d--cache结合起来,使得掉毛时间从4秒到0.17!

© www.soinside.com 2019 - 2024. All rights reserved.