Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(disable-type-aware): Using env var to let user disable type-aware linting #123

Merged
merged 1 commit into from
Feb 24, 2022

Conversation

yuaanlin
Copy link
Member

背景

在 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。

# type-aware
eslint src/**/*.tsx --fix 

# disabled type-aware
DISABLE_TYPE_AWARE=true src/**/*.tsx --fix 

@chenshuai2144
Copy link
Collaborator

我 ts 规则和js 规则是分开的,如果DISABLE_TYPE_AWARE=true 直接不要加载ts 的规则好了

@yuaanlin
Copy link
Member Author

@chenshuai2144 有些 ts 的规则不需要 type-aware linting,如果直接不要加载 ts 规则的话那些规则也用不了了

@chenshuai2144 chenshuai2144 merged commit c67b52d into master Feb 24, 2022
@delete-merged-branch delete-merged-branch bot deleted the feat/disable-type-aware branch February 24, 2022 07:29
fonghehe pushed a commit to fonghehe/fabric that referenced this pull request Apr 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants