我有一个由 590 个 TypeScript 文件组成的 Angular12 项目。当我执行 ng lint
时,它会运行 TSLint 并在大约 5 秒内完成。尽管如此,我还是尝试按照 Angular 的 official video 上的说明升级到 eslint,现在 ng lint
需要 10 多分钟(实际上我并没有让这个过程完成,我在 10 分钟时停止了它) .
我试图隔离问题以了解原因是 ng
还是 eslint
所以我使用 npm i -g eslint
全局安装了 eslint 并使用单个文件的时间信息运行它:
time TIMING=1 eslint /home/user/my-file.ts
即使对于这个单个文件,也需要超过 2 分钟。奇怪的是 eslint
报告每个规则只用了几毫秒,而 Linux 说它用了 148 秒(准确地说,它用了 2 多分钟):
Rule | Time (ms) | Relative
:-------------------------------------------|----------:|--------:
@angular-eslint/no-conflicting-lifecycle | 0.342 | 35.9%
@angular-eslint/no-input-rename | 0.163 | 17.1%
@angular-eslint/template/banana-in-box | 0.161 | 16.9%
@angular-eslint/no-output-rename | 0.103 | 10.9%
@angular-eslint/component-class-suffix | 0.100 | 10.5%
@angular-eslint/contextual-lifecycle | 0.083 | 8.7%
@angular-eslint/directive-class-suffix | 0.000 | 0.0%
@angular-eslint/no-empty-lifecycle-method | 0.000 | 0.0%
@angular-eslint/no-host-metadata-property | 0.000 | 0.0%
@angular-eslint/no-inputs-metadata-property | 0.000 | 0.0%
Rule | Time (ms) | Relative
:----|----------:|--------:
TIMING=1 eslint 148.14s user 4.47s system 190% cpu 1:19.96 total
我怎样才能让 eslint 跑得更快?
The underlying issue is still the overhead of the TypeScript compiler generating an AST, and the @typescript-eslint/typescript-estree work of converting this AST to an ESLint compatible AST.
However, there are some minor tweaks:
There is also a whole article on TypeScript performance which recommends: