简体   繁体   English

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

[英]Which eslint rules in my config are slow?

I have a config with around 100 rules, and running eslint on my project with all these rules takes around 10 seconds. 我有一个包含大约100条规则的配置,并且在我的项目上使用所有这些规则运行eslint大约需要10秒。 I'd like to identify the slowest rules and eliminate some of them. 我想确定最慢的规则并消除其中的一些规则。 How do I do this? 我该怎么做呢? Is there any profiler tool for eslint? 是否有任何用于eslint的分析器工具?

eslint shows the spent times of rules if the environment variable TIMING is set. 如果设置了环境变量TIMING则eslint显示规则的花费时间。 For example: 例如:

$ 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%

See also the official docs on Per-rule Performance . 另请参阅有关Per-rule性能的官方文档。

I found that removing slow rules didn't really help that much, as loading eslint and parsing files takes a while. 我发现删除慢速规则并没有太大帮助,因为加载eslint和解析文件需要一段时间。

It is possible to use the --cache option of eslint ( docs ) to speed things up substantially. 可以使用eslintdocs )的--cache选项来eslint加快速度。

When using eslint to "lint-as-you-type" in various editors, installing eslint_d allows running eslint as a daemon, and saves the node loading time. 在各种编辑器中使用eslint “lint-as-you-type”时,安装eslint_d允许将eslint作为守护进程运行,并保存node加载时间。

On the project I'm currently working on, combining both eslint_d and --cache brought the linting time from 4+ seconds to 0.17! 在我正在进行的项目中,结合eslint_d--cache使得--cache时间从4秒到0.17!

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

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