From 5f382a5677b52c25abee348491a7bb9d92639966 Mon Sep 17 00:00:00 2001 From: Koen Vlaswinkel Date: Mon, 30 Jan 2023 16:43:19 +0100 Subject: [PATCH] Combine ESLint configurations Instead of having different ESLint configuration files in each directory which don't seem to inherit the configuration correctly, this will add `overrides` in the root file. --- extensions/ql-vscode/.eslintignore | 1 + extensions/ql-vscode/.eslintrc.js | 182 ++++++++++++++++-- extensions/ql-vscode/package.json | 2 +- extensions/ql-vscode/src/stories/.eslintrc.js | 26 --- extensions/ql-vscode/src/view/.eslintrc.js | 44 ----- extensions/ql-vscode/test/.eslintrc.js | 29 --- extensions/ql-vscode/test/tsconfig.json | 2 +- .../ql-vscode/test/vscode-tests/.eslintrc.js | 45 ----- extensions/ql-vscode/tsconfig.lint.json | 4 + 9 files changed, 178 insertions(+), 157 deletions(-) delete mode 100644 extensions/ql-vscode/src/stories/.eslintrc.js delete mode 100644 extensions/ql-vscode/src/view/.eslintrc.js delete mode 100644 extensions/ql-vscode/test/.eslintrc.js delete mode 100644 extensions/ql-vscode/test/vscode-tests/.eslintrc.js create mode 100644 extensions/ql-vscode/tsconfig.lint.json diff --git a/extensions/ql-vscode/.eslintignore b/extensions/ql-vscode/.eslintignore index a362ef891..73702ce54 100644 --- a/extensions/ql-vscode/.eslintignore +++ b/extensions/ql-vscode/.eslintignore @@ -1,6 +1,7 @@ .vscode-test/ node_modules/ out/ +build/ # Include the Storybook config !.storybook diff --git a/extensions/ql-vscode/.eslintrc.js b/extensions/ql-vscode/.eslintrc.js index 04da1978a..b3f3c4896 100644 --- a/extensions/ql-vscode/.eslintrc.js +++ b/extensions/ql-vscode/.eslintrc.js @@ -1,15 +1,20 @@ -module.exports = { +const { resolve } = require("path"); + +const baseConfig = { parser: "@typescript-eslint/parser", parserOptions: { ecmaVersion: 2018, sourceType: "module", - project: ["tsconfig.json", "./src/**/tsconfig.json", "./test/**/tsconfig.json", "./gulpfile.ts/tsconfig.json", "./scripts/tsconfig.json", "./.storybook/tsconfig.json"], + project: [ + resolve(__dirname, "tsconfig.lint.json"), + resolve(__dirname, "src/**/tsconfig.json"), + resolve(__dirname, "test/**/tsconfig.json"), + resolve(__dirname, "gulpfile.ts/tsconfig.json"), + resolve(__dirname, "scripts/tsconfig.json"), + resolve(__dirname, ".storybook/tsconfig.json"), + ], }, - plugins: [ - "github", - "@typescript-eslint", - "etc" - ], + plugins: ["github", "@typescript-eslint", "etc"], env: { node: true, es6: true, @@ -21,7 +26,7 @@ module.exports = { "plugin:github/typescript", "plugin:jest-dom/recommended", "plugin:prettier/recommended", - "plugin:@typescript-eslint/recommended" + "plugin:@typescript-eslint/recommended", ], rules: { "@typescript-eslint/no-use-before-define": 0, @@ -37,14 +42,14 @@ module.exports = { "@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-floating-promises": [ "error", { ignoreVoid: true } ], + "@typescript-eslint/no-floating-promises": ["error", { ignoreVoid: true }], "@typescript-eslint/no-invalid-this": "off", "@typescript-eslint/no-shadow": "off", "prefer-const": ["warn", { destructuring: "all" }], "@typescript-eslint/no-throw-literal": "error", "no-useless-escape": 0, - "camelcase": "off", - "eqeqeq": "off", + camelcase: "off", + eqeqeq: "off", "escompat/no-regexp-lookbehind": "off", "etc/no-implicit-any-catch": "error", "filenames/match-regex": "off", @@ -72,3 +77,158 @@ module.exports = { "github/no-then": "off", }, }; + +module.exports = { + root: true, + ...baseConfig, + overrides: [ + { + files: ["src/stories/**/*"], + parserOptions: { + project: resolve(__dirname, "src/stories/tsconfig.json"), + }, + extends: [ + ...baseConfig.extends, + "plugin:react/recommended", + "plugin:react-hooks/recommended", + "plugin:storybook/recommended", + ], + rules: { + ...baseConfig.rules, + "filenames/match-regex": "off", + "import/named": "off", + "import/no-namespace": "off", + "import/no-unresolved": "off", + "no-unused-vars": "off", + }, + settings: { + react: { + version: "detect", + }, + }, + }, + { + files: ["src/view/**/*"], + parserOptions: { + project: resolve(__dirname, "src/view/tsconfig.json"), + }, + extends: [ + ...baseConfig.extends, + "plugin:react/recommended", + "plugin:react-hooks/recommended", + ], + rules: { + ...baseConfig.rules, + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-invalid-this": "off", + "@typescript-eslint/no-shadow": "off", + camelcase: "off", + eqeqeq: "off", + "filenames/match-regex": "off", + "i18n-text/no-en": "off", + "import/named": "off", + "import/no-dynamic-require": "off", + "import/no-dynamic-required": "off", + "import/no-namespace": "off", + "import/no-unresolved": "off", + "jsx-a11y/anchor-is-valid": "off", + "jsx-a11y/no-noninteractive-element-interactions": "off", + "jsx-a11y/no-static-element-interactions": "off", + "jsx-a11y/click-events-have-key-events": "off", + "no-console": "off", + "no-invalid-this": "off", + "no-undef": "off", + "no-unused-vars": "off", + "no-shadow": "off", + "github/array-foreach": "off", + }, + settings: { + react: { + version: "detect", + }, + }, + }, + { + files: ["test/**/*"], + parserOptions: { + project: resolve(__dirname, "test/tsconfig.json"), + }, + env: { + jest: true, + }, + rules: { + ...baseConfig.rules, + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-shadow": "off", + camelcase: "off", + "filenames/match-regex": "off", + "i18n-text/no-en": "off", + "import/no-namespace": "off", + "import/no-unresolved": "off", + "no-console": "off", + "no-shadow": "off", + "no-undef": "off", + "github/array-foreach": "off", + }, + }, + { + files: ["test/vscode-tests/**/*"], + parserOptions: { + project: resolve(__dirname, "test/tsconfig.json"), + }, + env: { + jest: true, + }, + rules: { + ...baseConfig.rules, + "@typescript-eslint/ban-types": [ + "error", + { + // For a full list of the default banned types, see: + // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md + extendDefaults: true, + types: { + // Don't complain about the `Function` type in test files. (Default is `true`.) + Function: false, + }, + }, + ], + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-shadow": "off", + "@typescript-eslint/no-invalid-this": "off", + eqeqeq: "off", + "filenames/match-regex": "off", + "filenames/match-regexp": "off", + "i18n-text/no-en": "off", + "import/no-anonymous-default-export": "off", + "import/no-dynamic-require": "off", + "import/no-mutable-exports": "off", + "import/no-namespace": "off", + "import/no-unresolved": "off", + "no-console": "off", + "github/array-foreach": "off", + "github/no-then": "off", + }, + }, + { + files: [ + ".eslintrc.js", + "test/**/jest-runner-vscode.config.js", + "test/**/jest-runner-vscode.config.base.js", + ], + parser: undefined, + plugins: ["github"], + extends: [ + "eslint:recommended", + "plugin:github/recommended", + "plugin:prettier/recommended", + ], + rules: { + "import/no-commonjs": "off", + "prefer-template": "off", + "filenames/match-regex": "off", + "@typescript-eslint/no-var-requires": "off", + }, + }, + ], +}; diff --git a/extensions/ql-vscode/package.json b/extensions/ql-vscode/package.json index 4d70e9840..2151c175c 100644 --- a/extensions/ql-vscode/package.json +++ b/extensions/ql-vscode/package.json @@ -1330,7 +1330,7 @@ "cli-integration": "jest --projects test/vscode-tests/cli-integration", "update-vscode": "node ./node_modules/vscode/bin/install", "format": "prettier --write **/*.{ts,tsx} && eslint . --ext .ts,.tsx --fix", - "lint": "eslint . --ext .ts,.tsx --max-warnings=0", + "lint": "eslint . --ext .js,.ts,.tsx --max-warnings=0", "format-staged": "lint-staged", "storybook": "start-storybook -p 6006", "build-storybook": "build-storybook", diff --git a/extensions/ql-vscode/src/stories/.eslintrc.js b/extensions/ql-vscode/src/stories/.eslintrc.js deleted file mode 100644 index 0982f1e35..000000000 --- a/extensions/ql-vscode/src/stories/.eslintrc.js +++ /dev/null @@ -1,26 +0,0 @@ -module.exports = { - env: { - browser: true, - }, - plugins: ["github"], - extends: [ - "plugin:github/react", - "plugin:github/recommended", - "plugin:github/typescript", - "plugin:react/recommended", - "plugin:react-hooks/recommended", - "plugin:storybook/recommended", - ], - rules: { - "filenames/match-regex": "off", - "import/named": "off", - "import/no-namespace": "off", - "import/no-unresolved": "off", - "no-unused-vars": "off", - }, - settings: { - react: { - version: "detect", - }, - }, -}; diff --git a/extensions/ql-vscode/src/view/.eslintrc.js b/extensions/ql-vscode/src/view/.eslintrc.js deleted file mode 100644 index fd822dbd5..000000000 --- a/extensions/ql-vscode/src/view/.eslintrc.js +++ /dev/null @@ -1,44 +0,0 @@ -module.exports = { - env: { - browser: true - }, - plugins: [ - "github", - ], - extends: [ - "plugin:github/react", - "plugin:github/recommended", - "plugin:github/typescript", - "plugin:react/recommended", - "plugin:react-hooks/recommended", - ], - rules: { - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-invalid-this": "off", - "@typescript-eslint/no-shadow": "off", - "camelcase": "off", - "eqeqeq": "off", - "filenames/match-regex": "off", - "i18n-text/no-en": "off", - "import/named": "off", - "import/no-dynamic-require": "off", - "import/no-dynamic-required": "off", - "import/no-namespace": "off", - "import/no-unresolved": "off", - "jsx-a11y/anchor-is-valid": "off", - "jsx-a11y/no-noninteractive-element-interactions": "off", - "jsx-a11y/no-static-element-interactions": "off", - "jsx-a11y/click-events-have-key-events": "off", - "no-console": "off", - "no-invalid-this": "off", - "no-undef": "off", - "no-unused-vars": "off", - "no-shadow": "off", - "github/array-foreach": "off", - }, - settings: { - react: { - version: 'detect' - } - } -} diff --git a/extensions/ql-vscode/test/.eslintrc.js b/extensions/ql-vscode/test/.eslintrc.js deleted file mode 100644 index 796a7134f..000000000 --- a/extensions/ql-vscode/test/.eslintrc.js +++ /dev/null @@ -1,29 +0,0 @@ -module.exports = { - env: { - jest: true, - }, - parserOptions: { - project: "./test/tsconfig.json", - }, - plugins: [ - "github", - ], - extends: [ - "plugin:github/react", - "plugin:github/recommended", - "plugin:github/typescript", - ], - rules: { - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-shadow": "off", - "camelcase": "off", - "filenames/match-regex": "off", - "i18n-text/no-en": "off", - "import/no-namespace": "off", - "import/no-unresolved": "off", - "no-console": "off", - "no-shadow": "off", - "no-undef": "off", - "github/array-foreach": "off", - } -}; diff --git a/extensions/ql-vscode/test/tsconfig.json b/extensions/ql-vscode/test/tsconfig.json index bbc52dca9..c19043056 100644 --- a/extensions/ql-vscode/test/tsconfig.json +++ b/extensions/ql-vscode/test/tsconfig.json @@ -1,6 +1,6 @@ { "extends": "../tsconfig.json", - "include": ["**/*.ts", "../src/**/*.ts"], + "include": ["**/*.ts", "../src/**/*.ts", "**/.eslintrc.js", "**/*.config.js"], "exclude": [], "compilerOptions": { "noEmit": true, diff --git a/extensions/ql-vscode/test/vscode-tests/.eslintrc.js b/extensions/ql-vscode/test/vscode-tests/.eslintrc.js deleted file mode 100644 index b0b2f4fc3..000000000 --- a/extensions/ql-vscode/test/vscode-tests/.eslintrc.js +++ /dev/null @@ -1,45 +0,0 @@ -module.exports = { - parserOptions: { - project: ["../../tsconfig.json"], - }, - env: { - jest: true, - }, - plugins: [ - "github", - ], - extends: [ - "plugin:github/react", - "plugin:github/recommended", - "plugin:github/typescript", - ], - rules: { - "@typescript-eslint/ban-types": [ - "error", - { - // For a full list of the default banned types, see: - // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md - extendDefaults: true, - types: { - // Don't complain about the `Function` type in test files. (Default is `true`.) - Function: false, - }, - }, - ], - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-shadow": "off", - "@typescript-eslint/no-invalid-this": "off", - "eqeqeq": "off", - "filenames/match-regex": "off", - "filenames/match-regexp": "off", - "i18n-text/no-en": "off", - "import/no-anonymous-default-export": "off", - "import/no-dynamic-require": "off", - "import/no-mutable-exports": "off", - "import/no-namespace": "off", - "import/no-unresolved": "off", - "no-console": "off", - "github/array-foreach": "off", - "github/no-then": "off" - } -} diff --git a/extensions/ql-vscode/tsconfig.lint.json b/extensions/ql-vscode/tsconfig.lint.json new file mode 100644 index 000000000..c5067a163 --- /dev/null +++ b/extensions/ql-vscode/tsconfig.lint.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*.ts", "**/.eslintrc.js", "jest.config.js"] +}