feat(disable-type-aware): Using env var to let user disable type-aware linting #123
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
背景
在 ESLint 搭配 Typescript 使用的场景中,若设置了
parserOptions.project
则称作 type-aware linting,即在 lint 时会同时考虑所有变量的类型定义,带来更强大的自定义规则。但 type-aware linting 有一个众所周知的历史问题,同时也是 Typescript ESLint 官方自己都承认的问题 - 效率太差了。在开启 type-aware linting 的情况下,相当于 eslint 必须先将整个 ts 项目的类型定义编译过一次,才能够支持那些依赖类型定义的规则。
https://typescript-eslint.io/docs/linting/type-linting/#how-is-performance
typescript-eslint/typescript-eslint#319
typescript-eslint/typescript-eslint#243
typescript-eslint/typescript-eslint#389
一般使用上可能问题不会很明显,但对于大型项目来说,从头启动 ESLint 可能要等数分钟甚至数小时才能完成检查。
解决方案
提供一个环境变量的配置方式,使用 umijs/fabric 规则的用户可以自行决定是否要开启 type-aware linting。