|
| 1 | +const { resolve } = require("path"); |
| 2 | + |
| 3 | +const baseConfig = { |
| 4 | + parser: "@typescript-eslint/parser", |
| 5 | + files: [".js", ".ts", ".tsx "], |
| 6 | + |
| 7 | + parserOptions: { |
| 8 | + ecmaVersion: 2018, |
| 9 | + sourceType: "module", |
| 10 | + project: [ |
| 11 | + resolve(__dirname, "tsconfig.lint.json"), |
| 12 | + resolve(__dirname, "src/**/tsconfig.json"), |
| 13 | + resolve(__dirname, "test/**/tsconfig.json"), |
| 14 | + resolve(__dirname, "gulpfile.ts/tsconfig.json"), |
| 15 | + resolve(__dirname, "scripts/tsconfig.json"), |
| 16 | + resolve(__dirname, ".storybook/tsconfig.json"), |
| 17 | + ], |
| 18 | + }, |
| 19 | + plugins: ["github", "@typescript-eslint", "etc"], |
| 20 | + env: { |
| 21 | + node: true, |
| 22 | + es6: true, |
| 23 | + }, |
| 24 | + extends: [ |
| 25 | + "eslint:recommended", |
| 26 | + "plugin:github/recommended", |
| 27 | + "plugin:github/typescript", |
| 28 | + "plugin:jest-dom/recommended", |
| 29 | + "plugin:prettier/recommended", |
| 30 | + "plugin:@typescript-eslint/recommended", |
| 31 | + "plugin:import/recommended", |
| 32 | + "plugin:import/typescript", |
| 33 | + "plugin:deprecation/recommended", |
| 34 | + ], |
| 35 | + rules: { |
| 36 | + "@typescript-eslint/await-thenable": "error", |
| 37 | + "@typescript-eslint/no-unused-vars": [ |
| 38 | + "warn", |
| 39 | + { |
| 40 | + vars: "all", |
| 41 | + args: "none", |
| 42 | + ignoreRestSiblings: false, |
| 43 | + }, |
| 44 | + ], |
| 45 | + "@typescript-eslint/no-explicit-any": "error", |
| 46 | + "@typescript-eslint/no-floating-promises": ["error", { ignoreVoid: true }], |
| 47 | + "@typescript-eslint/no-invalid-this": "off", |
| 48 | + "@typescript-eslint/no-shadow": "off", |
| 49 | + "prefer-const": ["warn", { destructuring: "all" }], |
| 50 | + "@typescript-eslint/only-throw-error": "error", |
| 51 | + "@typescript-eslint/consistent-type-imports": "error", |
| 52 | + "import/consistent-type-specifier-style": ["error", "prefer-top-level"], |
| 53 | + curly: ["error", "all"], |
| 54 | + "escompat/no-regexp-lookbehind": "off", |
| 55 | + "etc/no-implicit-any-catch": "error", |
| 56 | + "filenames/match-regex": "off", |
| 57 | + "i18n-text/no-en": "off", |
| 58 | + "no-invalid-this": "off", |
| 59 | + "no-console": "off", |
| 60 | + "no-shadow": "off", |
| 61 | + "github/array-foreach": "off", |
| 62 | + "github/no-then": "off", |
| 63 | + "react/jsx-key": ["error", { checkFragmentShorthand: true }], |
| 64 | + "import/no-cycle": "error", |
| 65 | + // Never allow extensions in import paths, except for JSON files where they are required. |
| 66 | + "import/extensions": ["error", "never", { json: "always" }], |
| 67 | + }, |
| 68 | + settings: { |
| 69 | + "import/resolver": { |
| 70 | + typescript: true, |
| 71 | + node: true, |
| 72 | + }, |
| 73 | + "import/extensions": [".js", ".jsx", ".ts", ".tsx", ".json"], |
| 74 | + // vscode and sarif don't exist on-disk, but only provide types. |
| 75 | + "import/core-modules": ["vscode", "sarif"], |
| 76 | + }, |
| 77 | +}; |
| 78 | + |
| 79 | +module.exports = [ |
| 80 | + baseConfig, |
| 81 | + { |
| 82 | + ignores: [ |
| 83 | + ".vscode-test/", |
| 84 | + "node_modules/", |
| 85 | + "out/", |
| 86 | + "build/", |
| 87 | + |
| 88 | + // Ignore js files |
| 89 | + "**/.*", |
| 90 | + "**/jest.config.js", |
| 91 | + "test/vscode-tests/activated-extension/jest-runner-vscode.config.js", |
| 92 | + "test/vscode-tests/cli-integration/jest-runner-vscode.config.js", |
| 93 | + "test/vscode-tests/jest-runner-vscode.config.base.js", |
| 94 | + "test/vscode-tests/minimal-workspace/jest-runner-vscode.config.js", |
| 95 | + "test/vscode-tests/no-workspace/jest-runner-vscode.config.js", |
| 96 | + |
| 97 | + // Include the Storybook config |
| 98 | + "!.storybook" |
| 99 | + ] |
| 100 | + }, |
| 101 | + { |
| 102 | + files: ["src/stories/**/*"], |
| 103 | + parserOptions: { |
| 104 | + project: resolve(__dirname, "src/stories/tsconfig.json"), |
| 105 | + }, |
| 106 | + extends: [ |
| 107 | + ...baseConfig.extends, |
| 108 | + "plugin:react/recommended", |
| 109 | + "plugin:react/jsx-runtime", |
| 110 | + "plugin:react-hooks/recommended", |
| 111 | + "plugin:storybook/recommended", |
| 112 | + "plugin:github/react", |
| 113 | + ], |
| 114 | + rules: { |
| 115 | + ...baseConfig.rules, |
| 116 | + }, |
| 117 | + settings: { |
| 118 | + react: { |
| 119 | + version: "detect", |
| 120 | + }, |
| 121 | + }, |
| 122 | + }, |
| 123 | + { |
| 124 | + files: ["src/view/**/*"], |
| 125 | + parserOptions: { |
| 126 | + project: resolve(__dirname, "src/view/tsconfig.json"), |
| 127 | + }, |
| 128 | + extends: [ |
| 129 | + ...baseConfig.extends, |
| 130 | + "plugin:react/recommended", |
| 131 | + "plugin:react/jsx-runtime", |
| 132 | + "plugin:react-hooks/recommended", |
| 133 | + "plugin:github/react", |
| 134 | + ], |
| 135 | + rules: { |
| 136 | + ...baseConfig.rules, |
| 137 | + }, |
| 138 | + settings: { |
| 139 | + react: { |
| 140 | + version: "detect", |
| 141 | + }, |
| 142 | + }, |
| 143 | + }, |
| 144 | + { |
| 145 | + files: ["test/vscode-tests/**/*"], |
| 146 | + parserOptions: { |
| 147 | + project: resolve(__dirname, "test/tsconfig.json"), |
| 148 | + }, |
| 149 | + env: { |
| 150 | + jest: true, |
| 151 | + }, |
| 152 | + rules: { |
| 153 | + ...baseConfig.rules, |
| 154 | + // We want to allow mocking of functions in modules, so we need to allow namespace imports. |
| 155 | + "import/no-namespace": "off", |
| 156 | + "@typescript-eslint/no-unsafe-function-type": "off", |
| 157 | + }, |
| 158 | + }, |
| 159 | + { |
| 160 | + files: ["test/**/*"], |
| 161 | + parserOptions: { |
| 162 | + project: resolve(__dirname, "test/tsconfig.json"), |
| 163 | + }, |
| 164 | + env: { |
| 165 | + jest: true, |
| 166 | + }, |
| 167 | + rules: { |
| 168 | + "@typescript-eslint/no-explicit-any": "off", |
| 169 | + }, |
| 170 | + }, |
| 171 | + { |
| 172 | + files: [ |
| 173 | + ".eslintrc.js", |
| 174 | + "test/**/jest-runner-vscode.config.js", |
| 175 | + "test/**/jest-runner-vscode.config.base.js", |
| 176 | + ], |
| 177 | + parser: undefined, |
| 178 | + plugins: ["github"], |
| 179 | + extends: [ |
| 180 | + "eslint:recommended", |
| 181 | + "plugin:github/recommended", |
| 182 | + "plugin:prettier/recommended", |
| 183 | + ], |
| 184 | + rules: { |
| 185 | + "import/no-commonjs": "off", |
| 186 | + "prefer-template": "off", |
| 187 | + "filenames/match-regex": "off", |
| 188 | + "@typescript-eslint/no-var-requires": "off", |
| 189 | + }, |
| 190 | + }, |
| 191 | + { |
| 192 | + files: [".storybook/**/*.tsx"], |
| 193 | + parserOptions: { |
| 194 | + project: resolve(__dirname, ".storybook/tsconfig.json"), |
| 195 | + }, |
| 196 | + rules: { |
| 197 | + ...baseConfig.rules, |
| 198 | + // Storybook doesn't use the automatic JSX runtime in the addon yet, so we need to allow |
| 199 | + // `React` to be imported. |
| 200 | + "import/no-namespace": ["error", { ignore: ["react"] }], |
| 201 | + }, |
| 202 | + }, |
| 203 | +]; |
0 commit comments