【发布时间】:2016-11-22 07:42:30
【问题描述】:
我有一个包含大约 100 条规则的配置,使用所有这些规则在我的项目上运行 eslint 大约需要 10 秒。我想找出最慢的规则并消除其中的一些。我该怎么做呢?有没有 eslint 的 profiler 工具?
【问题讨论】:
标签: javascript profiling configuration-files eslint
我有一个包含大约 100 条规则的配置,使用所有这些规则在我的项目上运行 eslint 大约需要 10 秒。我想找出最慢的规则并消除其中的一些。我该怎么做呢?有没有 eslint 的 profiler 工具?
【问题讨论】:
标签: javascript profiling configuration-files eslint
如果设置了环境变量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 上的官方文档。
【讨论】:
@typescript-eslint/parser,它需要很长时间,想要一个基准。
@typescript-eslint/parser也有同样的问题,400行的文件大约需要6秒,实际规则比较快,600ms是最慢的,也是(99.6%亲戚)。所以至少有 5.4 秒消失到解析。 --cache 的不幸之处在于它不适用于 --stdin,这让我在尝试将其优化为编辑器集成时遇到了麻烦。
【讨论】:
let g:ale_javascript_eslint_executable = 'eslint_d --cache' 设置为同时使用 eslint_d 和 --cache 将其从大约 1 秒加速到几乎即时!
--cache 的任何信息?
let g:syntastic_javascript_eslint_args = "--cache"
eslint_d 与合成器一起正常工作。 let g:syntastic_javascript_checkers = ['eslint'] let g:syntastic_javascript_eslint_exe = 'eslint_d' let g:syntastic_javascript_eslint_args = "--cache" let g:syntastic_javascript_eslint_exec = '/bin/ls' 最后,当 vim 启动时,您需要确保 eslint_d 在 PATH 中。
create-react-app 一起使用?
就我而言,我使用的是@typescript-eslint/eslint-plugin(带有类型信息的linting),并且我错误地配置了tsconfig include 字段。基于this doc,您必须包含所有文件。所以我更新了我的 eslint 配置:
如果您使用@angular-eslint/eslint-plugin,也会发生这种情况。阅读the performance section of their docs
【讨论】:
@typescript-eslint 文档现在在这里:github.com/typescript-eslint/typescript-eslint/blob/main/docs/…
我也遇到了这个问题,这是因为我启用了createDefaultProgram: true,删除它显着提高了我的性能!!
【讨论】: