From c67b52d8038549e2f84cadb3f80fe12ec48e150d Mon Sep 17 00:00:00 2001 From: Yuanlin Lin Date: Thu, 24 Feb 2022 15:28:58 +0800 Subject: [PATCH] feat(disable-type-aware): Using process.env.DISABLE_TYPE_AWARE to let user disable type-aware linting (#123) --- src/eslint.ts | 4 +++- src/tsEslintConfig.ts | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/eslint.ts b/src/eslint.ts index b1d7e7f..6eecbf5 100644 --- a/src/eslint.ts +++ b/src/eslint.ts @@ -2,6 +2,8 @@ import * as path from 'path'; import * as fs from 'fs'; import tsEslintConfig from './tsEslintConfig'; +const isTypeAwareEnabled = process.env.DISABLE_TYPE_AWARE === undefined; + const parserOptions = { ecmaFeatures: { jsx: true, @@ -14,7 +16,7 @@ const parserOptions = { ], }, requireConfigFile: false, - project: './tsconfig.json', + project: isTypeAwareEnabled ? './tsconfig.json' : undefined, }; const isJsMoreTs = async (path = 'src') => { diff --git a/src/tsEslintConfig.ts b/src/tsEslintConfig.ts index 607d169..0fe3d53 100644 --- a/src/tsEslintConfig.ts +++ b/src/tsEslintConfig.ts @@ -1,3 +1,5 @@ +const isTypeAwareEnabled = process.env.DISABLE_TYPE_AWARE === undefined; + export default { 'no-undef': 0, '@typescript-eslint/adjacent-overload-signatures': 0, @@ -19,7 +21,7 @@ export default { 'default-param-last': 'off', '@typescript-eslint/default-param-last': 0, 'dot-notation': 'off', - '@typescript-eslint/dot-notation': 1, + '@typescript-eslint/dot-notation': isTypeAwareEnabled ? 1 : 0, '@typescript-eslint/explicit-function-return-type': 0, 'func-call-spacing': 'off', '@typescript-eslint/func-call-spacing': 0, @@ -79,7 +81,7 @@ export default { '@typescript-eslint/no-shadow': 'error', '@typescript-eslint/no-this-alias': 'error', 'no-throw-literal': 'off', - '@typescript-eslint/no-throw-literal': 'error', + '@typescript-eslint/no-throw-literal': isTypeAwareEnabled ? 2 : 0, '@typescript-eslint/no-type-alias': 0, '@typescript-eslint/no-unnecessary-boolean-literal-compare': 0, '@typescript-eslint/no-unnecessary-condition': 0, @@ -130,7 +132,7 @@ export default { 'space-infix-ops': 'off', '@typescript-eslint/space-infix-ops': 0, '@typescript-eslint/strict-boolean-expressions': 0, - '@typescript-eslint/switch-exhaustiveness-check': 'error', + '@typescript-eslint/switch-exhaustiveness-check': isTypeAwareEnabled ? 2 : 0, '@typescript-eslint/triple-slash-reference': 'error', '@typescript-eslint/type-annotation-spacing': 'error', '@typescript-eslint/typedef': 'error',