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.
This commit is contained in:
Koen Vlaswinkel
2023-01-30 16:43:19 +01:00
parent 87465a65ae
commit 5f382a5677
9 changed files with 178 additions and 157 deletions

View File

@@ -1,6 +1,7 @@
.vscode-test/ .vscode-test/
node_modules/ node_modules/
out/ out/
build/
# Include the Storybook config # Include the Storybook config
!.storybook !.storybook

View File

@@ -1,15 +1,20 @@
module.exports = { const { resolve } = require("path");
const baseConfig = {
parser: "@typescript-eslint/parser", parser: "@typescript-eslint/parser",
parserOptions: { parserOptions: {
ecmaVersion: 2018, ecmaVersion: 2018,
sourceType: "module", 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: [ plugins: ["github", "@typescript-eslint", "etc"],
"github",
"@typescript-eslint",
"etc"
],
env: { env: {
node: true, node: true,
es6: true, es6: true,
@@ -21,7 +26,7 @@ module.exports = {
"plugin:github/typescript", "plugin:github/typescript",
"plugin:jest-dom/recommended", "plugin:jest-dom/recommended",
"plugin:prettier/recommended", "plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended" "plugin:@typescript-eslint/recommended",
], ],
rules: { rules: {
"@typescript-eslint/no-use-before-define": 0, "@typescript-eslint/no-use-before-define": 0,
@@ -37,14 +42,14 @@ module.exports = {
"@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "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-invalid-this": "off",
"@typescript-eslint/no-shadow": "off", "@typescript-eslint/no-shadow": "off",
"prefer-const": ["warn", { destructuring: "all" }], "prefer-const": ["warn", { destructuring: "all" }],
"@typescript-eslint/no-throw-literal": "error", "@typescript-eslint/no-throw-literal": "error",
"no-useless-escape": 0, "no-useless-escape": 0,
"camelcase": "off", camelcase: "off",
"eqeqeq": "off", eqeqeq: "off",
"escompat/no-regexp-lookbehind": "off", "escompat/no-regexp-lookbehind": "off",
"etc/no-implicit-any-catch": "error", "etc/no-implicit-any-catch": "error",
"filenames/match-regex": "off", "filenames/match-regex": "off",
@@ -72,3 +77,158 @@ module.exports = {
"github/no-then": "off", "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",
},
},
],
};

View File

@@ -1330,7 +1330,7 @@
"cli-integration": "jest --projects test/vscode-tests/cli-integration", "cli-integration": "jest --projects test/vscode-tests/cli-integration",
"update-vscode": "node ./node_modules/vscode/bin/install", "update-vscode": "node ./node_modules/vscode/bin/install",
"format": "prettier --write **/*.{ts,tsx} && eslint . --ext .ts,.tsx --fix", "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", "format-staged": "lint-staged",
"storybook": "start-storybook -p 6006", "storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook", "build-storybook": "build-storybook",

View File

@@ -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",
},
},
};

View File

@@ -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'
}
}
}

View File

@@ -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",
}
};

View File

@@ -1,6 +1,6 @@
{ {
"extends": "../tsconfig.json", "extends": "../tsconfig.json",
"include": ["**/*.ts", "../src/**/*.ts"], "include": ["**/*.ts", "../src/**/*.ts", "**/.eslintrc.js", "**/*.config.js"],
"exclude": [], "exclude": [],
"compilerOptions": { "compilerOptions": {
"noEmit": true, "noEmit": true,

View File

@@ -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"
}
}

View File

@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*.ts", "**/.eslintrc.js", "jest.config.js"]
}