|
| 1 | +import js from '@eslint/js' |
| 2 | +import tseslint from 'typescript-eslint' |
| 3 | +import reactHooksPlugin from 'eslint-plugin-react-hooks' |
| 4 | +import cypressPlugin from 'eslint-plugin-cypress' |
| 5 | +import prettierConfig from 'eslint-config-prettier' |
| 6 | + |
| 7 | +const eslintConfig = [ |
| 8 | + // 1. Base ESLint recommended rules |
| 9 | + js.configs.recommended, |
| 10 | + |
| 11 | + // 2. TypeScript ESLint recommended rules (without type-checking for performance) |
| 12 | + ...tseslint.configs.recommended, |
| 13 | + |
| 14 | + // 3. React Hooks configuration for all JS/TS files |
| 15 | + { |
| 16 | + files: ['**/*.{ts,tsx,js,jsx}'], |
| 17 | + plugins: { |
| 18 | + 'react-hooks': reactHooksPlugin, |
| 19 | + }, |
| 20 | + rules: { |
| 21 | + 'react-hooks/rules-of-hooks': 'error', |
| 22 | + 'react-hooks/exhaustive-deps': 'warn', |
| 23 | + }, |
| 24 | + }, |
| 25 | + |
| 26 | + // 4. TypeScript-specific overrides |
| 27 | + { |
| 28 | + files: ['**/*.{ts,tsx}'], |
| 29 | + rules: { |
| 30 | + // Allow unused vars with underscore prefix (common pattern) |
| 31 | + '@typescript-eslint/no-unused-vars': [ |
| 32 | + 'warn', |
| 33 | + { |
| 34 | + argsIgnorePattern: '^_', |
| 35 | + varsIgnorePattern: '^_', |
| 36 | + }, |
| 37 | + ], |
| 38 | + // Allow explicit any when necessary |
| 39 | + '@typescript-eslint/no-explicit-any': 'warn', |
| 40 | + // Allow require statements in config files |
| 41 | + '@typescript-eslint/no-require-imports': 'off', |
| 42 | + }, |
| 43 | + }, |
| 44 | + |
| 45 | + // 5. Cypress test files |
| 46 | + { |
| 47 | + files: ['cypress/**/*.{js,ts}'], |
| 48 | + plugins: { |
| 49 | + cypress: cypressPlugin, |
| 50 | + }, |
| 51 | + languageOptions: { |
| 52 | + globals: { |
| 53 | + ...cypressPlugin.environments.globals.globals, |
| 54 | + }, |
| 55 | + }, |
| 56 | + rules: { |
| 57 | + ...cypressPlugin.configs.recommended.rules, |
| 58 | + // Cypress commands create false positives |
| 59 | + 'no-undef': 'off', |
| 60 | + // Allow require() in Cypress files (CommonJS) |
| 61 | + '@typescript-eslint/no-require-imports': 'off', |
| 62 | + }, |
| 63 | + }, |
| 64 | + |
| 65 | + // 6. Node.js scripts (build scripts, config files) |
| 66 | + { |
| 67 | + files: ['scripts/**/*.{js,mjs}', '*.config.{js,ts,mjs}'], |
| 68 | + languageOptions: { |
| 69 | + globals: { |
| 70 | + process: 'readonly', |
| 71 | + __dirname: 'readonly', |
| 72 | + __filename: 'readonly', |
| 73 | + module: 'readonly', |
| 74 | + require: 'readonly', |
| 75 | + console: 'readonly', |
| 76 | + }, |
| 77 | + }, |
| 78 | + rules: { |
| 79 | + '@typescript-eslint/no-require-imports': 'off', |
| 80 | + 'no-console': 'off', |
| 81 | + }, |
| 82 | + }, |
| 83 | + |
| 84 | + // 7. Prettier integration (must be last to override formatting rules) |
| 85 | + prettierConfig, |
| 86 | + |
| 87 | + // 8. Ignore patterns |
| 88 | + { |
| 89 | + ignores: [ |
| 90 | + 'node_modules/**', |
| 91 | + '.next/**', |
| 92 | + 'out/**', |
| 93 | + 'public/**', |
| 94 | + 'coverage/**', |
| 95 | + '.cache/**', |
| 96 | + 'dist/**', |
| 97 | + 'build/**', |
| 98 | + '*.min.js', |
| 99 | + 'next-env.d.ts', |
| 100 | + ], |
| 101 | + }, |
| 102 | +] |
| 103 | + |
| 104 | +export default eslintConfig |
0 commit comments