|
| 1 | +// @ts-check |
| 2 | +import js from '@eslint/js'; |
| 3 | +import globals from 'globals'; |
| 4 | +import tseslint from 'typescript-eslint'; |
| 5 | +import reactPlugin from 'eslint-plugin-react'; |
| 6 | +import reactHooksPlugin from 'eslint-plugin-react-hooks'; |
| 7 | +import jsxA11yPlugin from 'eslint-plugin-jsx-a11y'; |
| 8 | +import importXPlugin from 'eslint-plugin-import-x'; |
| 9 | +import jestPlugin from 'eslint-plugin-jest'; |
| 10 | +import prettierPlugin from 'eslint-plugin-prettier'; |
| 11 | +import prettierConfig from 'eslint-config-prettier'; |
| 12 | + |
| 13 | +export default tseslint.config( |
| 14 | + // Global ignores (replaces .eslintignore) |
| 15 | + { |
| 16 | + ignores: [ |
| 17 | + 'node_modules/**', |
| 18 | + 'build/**', |
| 19 | + 'delete/**', |
| 20 | + 'tmp/**', |
| 21 | + 'src/graphql/generated/**', |
| 22 | + 'vite.config.js', |
| 23 | + ], |
| 24 | + }, |
| 25 | + |
| 26 | + // Base JS recommended rules |
| 27 | + js.configs.recommended, |
| 28 | + |
| 29 | + // Base config for all JS/JSX/TS/TSX files |
| 30 | + { |
| 31 | + files: ['src/**/*.{js,jsx,ts,tsx}'], |
| 32 | + plugins: { |
| 33 | + react: reactPlugin, |
| 34 | + 'react-hooks': reactHooksPlugin, |
| 35 | + 'jsx-a11y': jsxA11yPlugin, |
| 36 | + 'import-x': importXPlugin, |
| 37 | + jest: jestPlugin, |
| 38 | + prettier: prettierPlugin, |
| 39 | + }, |
| 40 | + languageOptions: { |
| 41 | + ecmaVersion: 'latest', |
| 42 | + sourceType: 'module', |
| 43 | + globals: { |
| 44 | + ...globals.browser, |
| 45 | + ...globals.es2021, |
| 46 | + ...globals.jest, |
| 47 | + }, |
| 48 | + parserOptions: { |
| 49 | + ecmaFeatures: { |
| 50 | + jsx: true, |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + settings: { |
| 55 | + react: { |
| 56 | + version: 'detect', |
| 57 | + }, |
| 58 | + 'import-x/resolver': { |
| 59 | + node: { |
| 60 | + extensions: ['.js', '.jsx', '.ts', '.tsx'], |
| 61 | + }, |
| 62 | + }, |
| 63 | + }, |
| 64 | + rules: { |
| 65 | + // React recommended rules (manually included since flat config) |
| 66 | + ...reactPlugin.configs.recommended.rules, |
| 67 | + ...jsxA11yPlugin.configs.recommended.rules, |
| 68 | + |
| 69 | + // Prettier |
| 70 | + 'prettier/prettier': [ |
| 71 | + 'error', |
| 72 | + { |
| 73 | + printWidth: 140, |
| 74 | + singleQuote: true, |
| 75 | + trailingComma: 'all', |
| 76 | + }, |
| 77 | + ], |
| 78 | + |
| 79 | + // General rules |
| 80 | + 'no-console': 'off', |
| 81 | + 'no-alert': 'off', |
| 82 | + 'max-len': [ |
| 83 | + 'error', |
| 84 | + { |
| 85 | + code: 140, |
| 86 | + ignoreUrls: true, |
| 87 | + ignoreTemplateLiterals: true, |
| 88 | + ignoreComments: true, |
| 89 | + ignoreStrings: true, |
| 90 | + ignoreRegExpLiterals: true, |
| 91 | + }, |
| 92 | + ], |
| 93 | + 'linebreak-style': ['error', 'unix'], |
| 94 | + 'object-curly-newline': ['error', { consistent: true }], |
| 95 | + |
| 96 | + // React rules |
| 97 | + 'react/jsx-filename-extension': ['warn', { extensions: ['.js', '.jsx', '.tsx'] }], |
| 98 | + 'react/jsx-wrap-multilines': ['off', { prop: 'parens-new-line' }], |
| 99 | + 'react/function-component-definition': ['error', { namedComponents: 'arrow-function' }], |
| 100 | + 'react/require-default-props': 'off', |
| 101 | + 'react/no-array-index-key': 'warn', |
| 102 | + 'react-hooks/exhaustive-deps': 'off', |
| 103 | + |
| 104 | + // Import rules |
| 105 | + 'import-x/no-unresolved': ['error', { ignore: ['\\.css$'] }], |
| 106 | + 'import-x/extensions': [ |
| 107 | + 'error', |
| 108 | + 'ignorePackages', |
| 109 | + { |
| 110 | + js: 'never', |
| 111 | + jsx: 'never', |
| 112 | + ts: 'never', |
| 113 | + tsx: 'never', |
| 114 | + }, |
| 115 | + ], |
| 116 | + 'import-x/prefer-default-export': 'off', |
| 117 | + |
| 118 | + // Misc |
| 119 | + 'no-shadow': 'warn', |
| 120 | + }, |
| 121 | + }, |
| 122 | + |
| 123 | + // TypeScript-specific overrides |
| 124 | + ...tseslint.configs.recommended.map((config) => ({ |
| 125 | + ...config, |
| 126 | + files: ['src/**/*.ts', 'src/**/*.tsx'], |
| 127 | + })), |
| 128 | + { |
| 129 | + files: ['src/**/*.ts', 'src/**/*.tsx'], |
| 130 | + rules: { |
| 131 | + 'no-unused-vars': 'off', |
| 132 | + '@typescript-eslint/no-unused-vars': [ |
| 133 | + 'warn', |
| 134 | + { |
| 135 | + argsIgnorePattern: '^_', |
| 136 | + varsIgnorePattern: '^_', |
| 137 | + destructuredArrayIgnorePattern: '^_', |
| 138 | + caughtErrors: 'none', |
| 139 | + }, |
| 140 | + ], |
| 141 | + 'no-shadow': 'off', |
| 142 | + '@typescript-eslint/no-shadow': 'warn', |
| 143 | + '@typescript-eslint/no-explicit-any': 'warn', |
| 144 | + 'react/react-in-jsx-scope': 'off', |
| 145 | + 'react/prop-types': 'off', |
| 146 | + }, |
| 147 | + }, |
| 148 | + |
| 149 | + // Prettier config last (disables conflicting rules) |
| 150 | + prettierConfig, |
| 151 | +); |
0 commit comments