From 81b8d5d69db7d7f97ff0f19dd4abb36efad48f2c Mon Sep 17 00:00:00 2001 From: Rob Morgan Date: Fri, 25 Nov 2022 09:36:56 +0000 Subject: [PATCH 1/5] Stop running typecheck on JS files --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 70436d4..885724b 100644 --- a/package.json +++ b/package.json @@ -55,9 +55,11 @@ }, "lint-staged": { "*.{js,ts}": [ - "npm run typecheck", "npm run format", "npm run lint:fix" + ], + "*.ts": [ + "npm run typecheck" ] } } From 078aadeb5591b853b00c55b6437450560821518c Mon Sep 17 00:00:00 2001 From: Rob Morgan Date: Fri, 25 Nov 2022 10:28:18 +0000 Subject: [PATCH 2/5] Convert eslintrc to JS file format --- .eslintrc.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ .eslintrc.json | 52 ------------------------------------------------- .prettierignore | 1 - 3 files changed, 52 insertions(+), 53 deletions(-) create mode 100644 .eslintrc.js delete mode 100644 .eslintrc.json diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..29df5a9 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,52 @@ +module.exports = { + env: { + node: true, + }, + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:import/recommended', + 'plugin:import/typescript', + 'prettier', + ], + ignorePatterns: ['**/node_modules'], + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + }, + plugins: ['@typescript-eslint', 'prettier', 'import', 'jest-formatting'], + root: true, + rules: { + eqeqeq: 'error', + 'import/no-default-export': 'error', + 'import/no-unresolved': 'error', + 'import/order': [ + 'error', + { + pathGroups: [ + { + group: 'external', + pattern: '~shared/**', + position: 'after', + }, + ], + pathGroupsExcludedImportTypes: ['builtin'], + }, + ], + 'prettier/prettier': [ + 'warn', + { + endOfLine: 'auto', + }, + ], + 'jest-formatting/padding-around-describe-blocks': 2, + 'jest-formatting/padding-around-test-blocks': 2, + '@typescript-eslint/explicit-module-boundary-types': 'error', + '@typescript-eslint/explicit-function-return-type': 'error', + '@typescript-eslint/no-unused-vars': [ + 'error', + { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }, + ], + }, +} diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 61caa16..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "env": { - "node": true - }, - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:import/recommended", - "plugin:import/typescript", - "prettier" - ], - "ignorePatterns": ["**/node_modules"], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module" - }, - "plugins": ["@typescript-eslint", "prettier", "import", "jest-formatting"], - "root": true, - "rules": { - "eqeqeq": "error", - "import/no-default-export": "error", - "import/no-unresolved": "error", - "import/order": [ - "error", - { - "pathGroups": [ - { - "group": "external", - "pattern": "~shared/**", - "position": "after" - } - ], - "pathGroupsExcludedImportTypes": ["builtin"] - } - ], - "prettier/prettier": [ - "warn", - { - "endOfLine": "auto" - } - ], - "jest-formatting/padding-around-describe-blocks": 2, - "jest-formatting/padding-around-test-blocks": 2, - "@typescript-eslint/explicit-module-boundary-types": "error", - "@typescript-eslint/explicit-function-return-type": "error", - "@typescript-eslint/no-unused-vars": [ - "error", - { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" } - ] - } -} diff --git a/.prettierignore b/.prettierignore index 425cceb..0709d75 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,6 +1,5 @@ package-lock.json package.json -.eslintrc.json .prettierrc.js tsconfig.json bin \ No newline at end of file From 2ee5d962aecb020138bec9e1f5ff9754fe32cfd1 Mon Sep 17 00:00:00 2001 From: Rob Morgan Date: Fri, 25 Nov 2022 10:55:09 +0000 Subject: [PATCH 3/5] Ensure eslint only applies TypeScript rules to .ts files --- .eslintrc.js | 124 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 79 insertions(+), 45 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 29df5a9..7f9b8fc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,52 +1,86 @@ +const jsExtends = [ + 'eslint:recommended', + 'plugin:import/recommended', + 'prettier', +] + +const tsExtends = [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:import/recommended', + 'plugin:import/typescript', + 'prettier', +] + +const jsPlugins = ['prettier', 'import', 'jest-formatting'] + +const tsPlugins = ['@typescript-eslint', ...jsPlugins] + +const jsParserOptions = { + ecmaVersion: 'latest', + sourceType: 'module', +} + +const tsParserOptions = { + ...jsParserOptions, + project: './tsconfig.json', +} + +const jsRules = { + eqeqeq: 'error', + 'import/no-default-export': 'error', + 'import/no-unresolved': 'error', + 'import/order': [ + 'error', + { + pathGroups: [ + { + group: 'external', + pattern: '~shared/**', + position: 'after', + }, + ], + pathGroupsExcludedImportTypes: ['builtin'], + }, + ], + 'prettier/prettier': [ + 'warn', + { + endOfLine: 'auto', + }, + ], + 'jest-formatting/padding-around-describe-blocks': 2, + 'jest-formatting/padding-around-test-blocks': 2, +} + +const tsRules = { + ...jsRules, + '@typescript-eslint/explicit-module-boundary-types': 'error', + '@typescript-eslint/explicit-function-return-type': 'error', + '@typescript-eslint/no-unused-vars': [ + 'error', + { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }, + ], +} + module.exports = { env: { node: true, }, - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:import/recommended', - 'plugin:import/typescript', - 'prettier', - ], + extends: jsExtends, ignorePatterns: ['**/node_modules'], - parser: '@typescript-eslint/parser', - parserOptions: { - ecmaVersion: 'latest', - sourceType: 'module', - }, - plugins: ['@typescript-eslint', 'prettier', 'import', 'jest-formatting'], + parserOptions: jsParserOptions, + plugins: jsPlugins, root: true, - rules: { - eqeqeq: 'error', - 'import/no-default-export': 'error', - 'import/no-unresolved': 'error', - 'import/order': [ - 'error', - { - pathGroups: [ - { - group: 'external', - pattern: '~shared/**', - position: 'after', - }, - ], - pathGroupsExcludedImportTypes: ['builtin'], - }, - ], - 'prettier/prettier': [ - 'warn', - { - endOfLine: 'auto', - }, - ], - 'jest-formatting/padding-around-describe-blocks': 2, - 'jest-formatting/padding-around-test-blocks': 2, - '@typescript-eslint/explicit-module-boundary-types': 'error', - '@typescript-eslint/explicit-function-return-type': 'error', - '@typescript-eslint/no-unused-vars': [ - 'error', - { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }, - ], - }, + rules: jsRules, + overrides: [ + { + files: ['**/*.ts', '**/*.tsx'], + extends: tsExtends, + parser: '@typescript-eslint/parser', + parserOptions: tsParserOptions, + plugins: tsPlugins, + rules: tsRules, + }, + ], } From 65e4e78b39992fbd4a1a53b68b0fc26c3afb77f3 Mon Sep 17 00:00:00 2001 From: Rob Morgan Date: Fri, 25 Nov 2022 10:57:38 +0000 Subject: [PATCH 4/5] typecheck ALL ts files when using lint-staged --- lint-staged.config.js | 4 ++++ package.json | 9 --------- 2 files changed, 4 insertions(+), 9 deletions(-) create mode 100644 lint-staged.config.js diff --git a/lint-staged.config.js b/lint-staged.config.js new file mode 100644 index 0000000..419c0d1 --- /dev/null +++ b/lint-staged.config.js @@ -0,0 +1,4 @@ +module.exports = { + '**/*.{js,ts}': ['npm run format', 'npm run lint:fix'], + '**/*.ts': () => 'npm run typecheck', +} diff --git a/package.json b/package.json index 885724b..002233b 100644 --- a/package.json +++ b/package.json @@ -52,14 +52,5 @@ }, "dependencies": { "prompts": "^2.4.2" - }, - "lint-staged": { - "*.{js,ts}": [ - "npm run format", - "npm run lint:fix" - ], - "*.ts": [ - "npm run typecheck" - ] } } From a837819b881b7d0131f81176058d5f2108416f37 Mon Sep 17 00:00:00 2001 From: Rob Morgan <46483646+robmorgan-tab@users.noreply.github.com> Date: Fri, 25 Nov 2022 11:04:07 +0000 Subject: [PATCH 5/5] Remove '**/*.tsx' reference from .eslintrc.js --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 7f9b8fc..188a0cb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -75,7 +75,7 @@ module.exports = { rules: jsRules, overrides: [ { - files: ['**/*.ts', '**/*.tsx'], + files: ['**/*.ts'], extends: tsExtends, parser: '@typescript-eslint/parser', parserOptions: tsParserOptions,