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

mik*_*1aj 22 javascript profiling configuration-files eslint

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

mys*_*tea 50

如果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%
Run Code Online (Sandbox Code Playgroud)

另请参阅有关Per-rule性能的官方文档.

  • 太糟糕了,它没有显示解析器计时器。我正在使用`@ typescript-eslint / parser`,它花了很长时间,想要一个基准。 (3认同)

Lau*_*t S 7

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

可以使用(docs--cache选项显着加快处理速度。eslint

eslint在各种编辑器中使用“ 按需输入”时,安装eslint_d可以eslint作为守护程序运行,并节省了node加载时间。

在我目前正在进行的项目中,将两者结合在一起eslint_d--cache使起毛时间从4+秒缩短到0.17!

  • 我使用 vim 和 [ALE](https://github.com/dense-analysis/ale) 插件进行 linting。设置 `let g:ale_javascript_eslint_executable = 'eslint_d --cache'` 以同时使用 `eslint_d` 和 `--cache` 将速度从约 1 秒提高到几乎即时! (2认同)