|
| 1 | +import { resolve, dirname } from "path"; |
| 2 | +import { fileURLToPath } from "url"; |
| 3 | +import eslint from "@eslint/js"; |
| 4 | +import { globalIgnores } from "eslint/config"; |
| 5 | +import github from "eslint-plugin-github"; |
| 6 | +import tseslint from "typescript-eslint"; |
| 7 | +import eslintPrettierRecommended from 'eslint-plugin-prettier/recommended'; |
| 8 | +import * as jestDom from "eslint-plugin-jest-dom"; |
| 9 | +import * as typescriptESLintParser from "@typescript-eslint/parser"; |
| 10 | +import react from "eslint-plugin-react"; |
| 11 | +import reactHooks from "eslint-plugin-react-hooks"; |
| 12 | +import storybook from "eslint-plugin-storybook"; |
| 13 | + |
| 14 | +const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 15 | + |
| 16 | +export default tseslint.config( |
| 17 | + globalIgnores([ |
| 18 | + ".vscode-test/", |
| 19 | + "node_modules/", |
| 20 | + "out/", |
| 21 | + "build/", |
| 22 | + "scripts/", |
| 23 | + "jest.config.ts", |
| 24 | + "jest-runner-vscode.config.js", |
| 25 | + "eslint.config.mjs", |
| 26 | + "!.storybook", |
| 27 | + ]), |
| 28 | + github.getFlatConfigs().recommended, |
| 29 | + ...github.getFlatConfigs().typescript, |
| 30 | + tseslint.configs.recommendedTypeChecked, |
| 31 | + eslint.configs.recommended, |
| 32 | + tseslint.configs.recommended, |
| 33 | + jestDom.configs["flat/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 | + "filenames/match-regex": "off", |
| 56 | + "i18n-text/no-en": "off", |
| 57 | + "no-invalid-this": "off", |
| 58 | + "no-console": "off", |
| 59 | + "no-shadow": "off", |
| 60 | + "github/array-foreach": "off", |
| 61 | + "github/no-then": "off", |
| 62 | + // "react/jsx-key": ["error", { checkFragmentShorthand: true }], |
| 63 | + "import/no-cycle": "error", |
| 64 | + // Never allow extensions in import paths, except for JSON files where they are required. |
| 65 | + "import/extensions": ["error", "never", { json: "always" }], |
| 66 | + }, |
| 67 | + settings: { |
| 68 | + "import/parsers": { |
| 69 | + "@typescript-eslint/parser": [".ts", ".tsx"] |
| 70 | + }, |
| 71 | + "import/resolver": { |
| 72 | + typescript: true, |
| 73 | + node: true, |
| 74 | + }, |
| 75 | + "import/extensions": [".js", ".jsx", ".ts", ".tsx", ".json"], |
| 76 | + // vscode and sarif don't exist on-disk, but only provide types. |
| 77 | + "import/core-modules": ["vscode", "sarif"], |
| 78 | + }, |
| 79 | + languageOptions: { |
| 80 | + parser: typescriptESLintParser, |
| 81 | + parserOptions: { |
| 82 | + ecmaVersion: 2018, |
| 83 | + sourceType: "module", |
| 84 | + projectService: true, |
| 85 | + tsconfigRootDir: import.meta.dirname, |
| 86 | + project: resolve(__dirname, "tsconfig.lint.json"), |
| 87 | + }, |
| 88 | + }, |
| 89 | + }, |
| 90 | + { |
| 91 | + files: ["src/stories/**/*"], |
| 92 | + languageOptions: { |
| 93 | + parserOptions: { |
| 94 | + project: resolve(__dirname, "src/stories/tsconfig.json"), |
| 95 | + }, |
| 96 | + }, |
| 97 | + extends: [ |
| 98 | + react.configs.flat.recommended, |
| 99 | + react.configs.flat['jsx-runtime'], |
| 100 | + reactHooks.configs['recommended-latest'], |
| 101 | + storybook.configs['flat/recommended'], |
| 102 | + github.getFlatConfigs().react, |
| 103 | + ], |
| 104 | + settings: { |
| 105 | + react: { |
| 106 | + version: "detect", |
| 107 | + }, |
| 108 | + }, |
| 109 | + }, |
| 110 | + { |
| 111 | + files: ["src/view/**/*"], |
| 112 | + languageOptions: { |
| 113 | + parserOptions: { |
| 114 | + project: resolve(__dirname, "src/view/tsconfig.json"), |
| 115 | + }, |
| 116 | + }, |
| 117 | + extends: [ |
| 118 | + react.configs.flat.recommended, |
| 119 | + react.configs.flat['jsx-runtime'], |
| 120 | + reactHooks.configs['recommended-latest'], |
| 121 | + github.getFlatConfigs().react, |
| 122 | + ], |
| 123 | + settings: { |
| 124 | + react: { |
| 125 | + version: "detect", |
| 126 | + }, |
| 127 | + }, |
| 128 | + }, |
| 129 | + { |
| 130 | + files: ["test/vscode-tests/**/*"], |
| 131 | + languageOptions: { |
| 132 | + parserOptions: { |
| 133 | + project: resolve(__dirname, "test/tsconfig.json"), |
| 134 | + }, |
| 135 | + globals: { |
| 136 | + jest: true, |
| 137 | + }, |
| 138 | + }, |
| 139 | + rules: { |
| 140 | + // We want to allow mocking of functions in modules, so we need to allow namespace imports. |
| 141 | + "import/no-namespace": "off", |
| 142 | + "@typescript-eslint/no-unsafe-function-type": "off", |
| 143 | + }, |
| 144 | + }, |
| 145 | + { |
| 146 | + files: ["test/**/*"], |
| 147 | + languageOptions: { |
| 148 | + parserOptions: { |
| 149 | + project: resolve(__dirname, "test/tsconfig.json"), |
| 150 | + }, |
| 151 | + globals: { |
| 152 | + jest: true, |
| 153 | + }, |
| 154 | + }, |
| 155 | + rules: { |
| 156 | + "@typescript-eslint/no-explicit-any": "off", |
| 157 | + }, |
| 158 | + }, |
| 159 | + { |
| 160 | + files: [".storybook/**/*.tsx"], |
| 161 | + languageOptions: { |
| 162 | + parserOptions: { |
| 163 | + project: resolve(__dirname, ".storybook/tsconfig.json"), |
| 164 | + }, |
| 165 | + }, |
| 166 | + rules: { |
| 167 | + // Storybook doesn't use the automatic JSX runtime in the addon yet, so we need to allow |
| 168 | + // `React` to be imported. |
| 169 | + "import/no-namespace": ["error", { ignore: ["react"] }], |
| 170 | + }, |
| 171 | + }, |
| 172 | + eslintPrettierRecommended, |
| 173 | +); |
0 commit comments