|
| 1 | +import { fixupPluginRules } from "@eslint/compat"; |
| 2 | +import { FlatCompat } from "@eslint/eslintrc"; |
| 3 | +import js from "@eslint/js"; |
| 4 | +import globals from "globals"; |
| 5 | +import reactPlugin from 'eslint-plugin-react'; |
| 6 | +import reactHooks from "eslint-plugin-react-hooks"; |
| 7 | +import reactRefresh from "eslint-plugin-react-refresh"; |
| 8 | +import tseslint from "typescript-eslint"; |
| 9 | +import prettier from "eslint-plugin-prettier/recommended"; |
| 10 | + |
| 11 | +const project = "./tsconfig.app.json"; |
| 12 | +// eslint flat structure backwards compatibility |
| 13 | +const compat = new FlatCompat({ |
| 14 | + recommendedConfig: js.configs.recommended, |
| 15 | +}); |
| 16 | + |
| 17 | +function legacyPlugin(name, alias = name) { |
| 18 | + const plugin = compat.plugins(name)[0]?.plugins?.[alias]; |
| 19 | + if (!plugin) { |
| 20 | + throw new Error(`Unable to resolve plugin ${name} and/or alias ${alias}`); |
| 21 | + } |
| 22 | + return fixupPluginRules(plugin); |
| 23 | +} |
| 24 | + |
| 25 | +export default tseslint.config( |
| 26 | + { ignores: ["node_modules", "dist", "build"] }, |
| 27 | + { |
| 28 | + extends: [ |
| 29 | + js.configs.recommended, |
| 30 | + ...tseslint.configs.recommended, |
| 31 | + prettier, |
| 32 | + ...compat.extends("plugin:import/typescript"), |
| 33 | + reactPlugin.configs.flat.recommended, |
| 34 | + ], |
| 35 | + files: ["**/*.{ts,tsx}"], |
| 36 | + languageOptions: { |
| 37 | + ecmaVersion: 2020, |
| 38 | + globals: globals.browser, |
| 39 | + }, |
| 40 | + plugins: { |
| 41 | + "react-hooks": reactHooks, |
| 42 | + "react-refresh": reactRefresh, |
| 43 | + import: legacyPlugin("eslint-plugin-import", "import"), |
| 44 | + }, |
| 45 | + settings: { |
| 46 | + "import/resolver": { |
| 47 | + typescript: { |
| 48 | + project, |
| 49 | + alwaysTryTypes: true, |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + rules: { |
| 54 | + ...reactHooks.configs.recommended.rules, |
| 55 | + "@typescript-eslint/no-empty-object-type": "off", |
| 56 | + "@typescript-eslint/no-unused-vars": ["error", { |
| 57 | + "argsIgnorePattern": "^_", |
| 58 | + "varsIgnorePattern": "^_", |
| 59 | + "caughtErrorsIgnorePattern": "^_" |
| 60 | + }], |
| 61 | + "import/order": ["error", { |
| 62 | + "groups": [ |
| 63 | + "builtin", |
| 64 | + "external", |
| 65 | + "internal", |
| 66 | + ["parent", "sibling"], |
| 67 | + "index", |
| 68 | + "object", |
| 69 | + "type", |
| 70 | + "unknown" |
| 71 | + ], |
| 72 | + "newlines-between": "always", |
| 73 | + "alphabetize": { |
| 74 | + "order": "asc", |
| 75 | + "caseInsensitive": true |
| 76 | + } |
| 77 | + }], |
| 78 | + "react/react-in-jsx-scope": "off", |
| 79 | + "react-refresh/only-export-components": [ |
| 80 | + "warn", |
| 81 | + { allowConstantExport: true }, |
| 82 | + ], |
| 83 | + "semi": ["error", "always"], |
| 84 | + }, |
| 85 | + } |
| 86 | +); |
0 commit comments