|
| 1 | +import js from '@eslint/js'; |
| 2 | +import tseslint from '@typescript-eslint/eslint-plugin'; |
| 3 | +import tsparser from '@typescript-eslint/parser'; |
| 4 | +// @ts-ignore - Plugin doesn't have proper ESLint 9 types yet |
| 5 | +import importPlugin from 'eslint-plugin-import'; |
| 6 | +// @ts-ignore - Plugin doesn't have proper ESLint 9 types yet |
| 7 | +import react from 'eslint-plugin-react'; |
| 8 | +// @ts-ignore - Plugin doesn't have proper ESLint 9 types yet |
| 9 | +import reactHooks from 'eslint-plugin-react-hooks'; |
| 10 | +import prettierConfig from 'eslint-config-prettier'; |
| 11 | + |
| 12 | +export default [ |
| 13 | + // Base recommended configurations |
| 14 | + js.configs.recommended, |
| 15 | + |
| 16 | + // TypeScript configuration for all TypeScript files |
| 17 | + { |
| 18 | + files: ['src/**/*.{ts,tsx}'], |
| 19 | + languageOptions: { |
| 20 | + parser: tsparser, |
| 21 | + parserOptions: { |
| 22 | + ecmaVersion: 'latest', |
| 23 | + sourceType: 'module', |
| 24 | + project: './tsconfig.json', |
| 25 | + ecmaFeatures: { |
| 26 | + jsx: true, |
| 27 | + }, |
| 28 | + }, |
| 29 | + globals: { |
| 30 | + // Only keep React global for JSX without explicit React imports |
| 31 | + React: 'writable', |
| 32 | + }, |
| 33 | + }, |
| 34 | + plugins: { |
| 35 | + '@typescript-eslint': tseslint, |
| 36 | + }, |
| 37 | + rules: { |
| 38 | + // Disable core ESLint rules that are covered by TypeScript |
| 39 | + 'no-unused-vars': 'off', |
| 40 | + 'no-undef': 'off', // TypeScript handles this |
| 41 | + |
| 42 | + // Apply TypeScript ESLint recommended rules |
| 43 | + ...tseslint.configs.recommended.rules, |
| 44 | + // Override specific rules for our project needs |
| 45 | + '@typescript-eslint/ban-ts-comment': 'off', |
| 46 | + '@typescript-eslint/no-explicit-any': 'warn', |
| 47 | + }, |
| 48 | + }, |
| 49 | + |
| 50 | + // Node.js CLI configuration |
| 51 | + { |
| 52 | + files: ['src/cli/**/*.{ts,tsx}'], |
| 53 | + languageOptions: { |
| 54 | + parser: tsparser, |
| 55 | + parserOptions: { |
| 56 | + ecmaVersion: 'latest', |
| 57 | + sourceType: 'module', |
| 58 | + project: './tsconfig.json', |
| 59 | + }, |
| 60 | + globals: { |
| 61 | + // Only the Node.js globals actually used in CLI files |
| 62 | + process: 'readonly', |
| 63 | + console: 'readonly', |
| 64 | + }, |
| 65 | + }, |
| 66 | + plugins: { |
| 67 | + '@typescript-eslint': tseslint, |
| 68 | + }, |
| 69 | + rules: { |
| 70 | + 'no-unused-vars': 'off', |
| 71 | + 'no-undef': 'off', |
| 72 | + ...tseslint.configs.recommended.rules, |
| 73 | + '@typescript-eslint/ban-ts-comment': 'off', |
| 74 | + '@typescript-eslint/no-explicit-any': 'warn', |
| 75 | + }, |
| 76 | + }, |
| 77 | + |
| 78 | + // React configuration |
| 79 | + { |
| 80 | + files: ['src/**/*.{js,jsx,ts,tsx}'], |
| 81 | + languageOptions: { |
| 82 | + parser: tsparser, |
| 83 | + parserOptions: { |
| 84 | + ecmaVersion: 'latest', |
| 85 | + sourceType: 'module', |
| 86 | + project: './tsconfig.json', |
| 87 | + ecmaFeatures: { |
| 88 | + jsx: true, |
| 89 | + }, |
| 90 | + }, |
| 91 | + globals: { |
| 92 | + React: 'writable', |
| 93 | + }, |
| 94 | + }, |
| 95 | + plugins: { |
| 96 | + react, |
| 97 | + 'react-hooks': reactHooks, |
| 98 | + import: importPlugin, |
| 99 | + }, |
| 100 | + settings: { |
| 101 | + react: { |
| 102 | + version: 'detect', |
| 103 | + }, |
| 104 | + 'import/resolver': { |
| 105 | + typescript: { |
| 106 | + project: './tsconfig.json', |
| 107 | + }, |
| 108 | + node: { |
| 109 | + extensions: ['.js', '.jsx', '.ts', '.tsx'], |
| 110 | + }, |
| 111 | + }, |
| 112 | + }, |
| 113 | + rules: { |
| 114 | + // Apply React recommended rules |
| 115 | + ...react.configs.recommended.rules, |
| 116 | + ...react.configs['jsx-runtime'].rules, |
| 117 | + |
| 118 | + // Apply React Hooks recommended rules |
| 119 | + ...reactHooks.configs.recommended.rules, |
| 120 | + |
| 121 | + // Apply Import recommended rules with custom order |
| 122 | + 'import/no-unresolved': 'off', // TypeScript handles this |
| 123 | + 'import/order': [ |
| 124 | + 'error', |
| 125 | + { |
| 126 | + groups: ['builtin', 'external', 'internal'], |
| 127 | + pathGroups: [ |
| 128 | + { |
| 129 | + pattern: 'react', |
| 130 | + group: 'external', |
| 131 | + position: 'before', |
| 132 | + }, |
| 133 | + ], |
| 134 | + pathGroupsExcludedImportTypes: ['react'], |
| 135 | + 'newlines-between': 'always', |
| 136 | + alphabetize: { |
| 137 | + order: 'asc', |
| 138 | + caseInsensitive: true, |
| 139 | + }, |
| 140 | + }, |
| 141 | + ], |
| 142 | + }, |
| 143 | + }, |
| 144 | + |
| 145 | + // Prettier configuration (disables conflicting rules) |
| 146 | + prettierConfig, |
| 147 | +]; |
0 commit comments