|
| 1 | +// eslint-disable-next-line import/no-extraneous-dependencies |
| 2 | +import importPlugin from 'eslint-plugin-import'; |
| 3 | +import tailwindcss from 'eslint-plugin-tailwindcss'; |
| 4 | +// eslint-disable-next-line import/no-extraneous-dependencies |
| 5 | +import unicorn from 'eslint-plugin-unicorn'; |
| 6 | +import { FlatCompat } from '@eslint/eslintrc'; |
| 7 | +import js from '@eslint/js'; |
| 8 | + |
| 9 | +const compat = new FlatCompat({ |
| 10 | + baseDirectory: import.meta.dirname, |
| 11 | + recommendedConfig: js.configs.recommended, |
| 12 | + allConfig: js.configs.all, |
| 13 | +}); |
| 14 | + |
| 15 | +// Use sub-modules of @theguild/eslint-config that don't trigger @rushstack/eslint-patch |
| 16 | +// (the main index.js requires @rushstack/eslint-patch/modern-module-resolution which doesn't support ESLint 10) |
| 17 | +// FlatCompat uses CJS require() which can't load ESM-only plugins (unicorn v57+). |
| 18 | +// We import them directly and patch the FlatCompat output. |
| 19 | +const theGuildIndex = compat.config({ |
| 20 | + reportUnusedDisableDirectives: true, |
| 21 | + overrides: [ |
| 22 | + { |
| 23 | + files: ['*.{,c,m}{j,t}s{,x}'], |
| 24 | + extends: ['./node_modules/@theguild/eslint-config/src/base.js'], |
| 25 | + }, |
| 26 | + { |
| 27 | + files: ['*.{,c,m}ts{,x}'], |
| 28 | + excludedFiles: ['**/*.md{,x}/*'], |
| 29 | + parserOptions: { |
| 30 | + projectService: true, |
| 31 | + }, |
| 32 | + rules: { |
| 33 | + '@typescript-eslint/prefer-optional-chain': 'error', |
| 34 | + }, |
| 35 | + }, |
| 36 | + { |
| 37 | + files: ['*.{,c,m}ts{,x}'], |
| 38 | + rules: { |
| 39 | + '@typescript-eslint/consistent-type-assertions': 'error', |
| 40 | + }, |
| 41 | + }, |
| 42 | + { |
| 43 | + files: ['*.c{j,t}s'], |
| 44 | + env: { node: true }, |
| 45 | + rules: { '@typescript-eslint/no-var-requires': 'off' }, |
| 46 | + }, |
| 47 | + { |
| 48 | + files: [ |
| 49 | + 'jest.config.js', |
| 50 | + 'webpack.config.js', |
| 51 | + 'bob.config.js', |
| 52 | + 'babel.config.js', |
| 53 | + 'postcss.config.{js,cjs}', |
| 54 | + 'rollup.config.js', |
| 55 | + 'next-sitemap.config.js', |
| 56 | + ], |
| 57 | + env: { node: true }, |
| 58 | + }, |
| 59 | + { |
| 60 | + files: ['*.{spec,test}.*'], |
| 61 | + env: { jest: true }, |
| 62 | + rules: { 'import/extensions': ['error', 'never'] }, |
| 63 | + }, |
| 64 | + { |
| 65 | + files: ['vite.config.ts', 'jest.config.js', '*.d.ts', 'tsup.config.ts', 'prettier.config.js'], |
| 66 | + rules: { 'import/no-default-export': 'off' }, |
| 67 | + }, |
| 68 | + { |
| 69 | + files: ['*.d.ts'], |
| 70 | + rules: { |
| 71 | + 'no-var': 'off', |
| 72 | + }, |
| 73 | + }, |
| 74 | + ], |
| 75 | +}); |
| 76 | + |
| 77 | +export default [ |
| 78 | + // Global ignores (replaces ignorePatterns + .gitignore patterns) |
| 79 | + { |
| 80 | + ignores: [ |
| 81 | + '.bob/**', |
| 82 | + '.next/**', |
| 83 | + '.cache/**', |
| 84 | + '**/temp/**', |
| 85 | + 'dev-test/**', |
| 86 | + 'website/**', |
| 87 | + 'examples/**', |
| 88 | + '**/tests/test-files/**', |
| 89 | + '**/tests/test-documents/**', |
| 90 | + '**/react-app-env.d.ts', |
| 91 | + 'packages/presets/swc-plugin/tests/fixtures/simple-uppercase-operation-name.js', |
| 92 | + 'packages/presets/swc-plugin/tests/fixtures/simple-uppercase-operation-name.other-dir.js', |
| 93 | + '**/build/**', |
| 94 | + '**/dist/**', |
| 95 | + '**/*.json', |
| 96 | + ], |
| 97 | + }, |
| 98 | + |
| 99 | + // @theguild base config (via FlatCompat) |
| 100 | + // Patch: replace broken CJS-resolved unicorn plugin with the properly imported ESM version |
| 101 | + ...theGuildIndex.map(config => |
| 102 | + config.plugins?.unicorn ? { ...config, plugins: { ...config.plugins, unicorn } } : config, |
| 103 | + ), |
| 104 | + |
| 105 | + // Tailwind CSS plugin (flat config) |
| 106 | + ...tailwindcss.configs['flat/recommended'], |
| 107 | + |
| 108 | + // Project-level rule overrides |
| 109 | + { |
| 110 | + plugins: { |
| 111 | + import: importPlugin, |
| 112 | + }, |
| 113 | + rules: { |
| 114 | + 'no-empty': 'off', |
| 115 | + '@typescript-eslint/explicit-module-boundary-types': 'off', |
| 116 | + '@typescript-eslint/no-use-before-define': 'off', |
| 117 | + '@typescript-eslint/no-namespace': 'off', |
| 118 | + '@typescript-eslint/no-empty-interface': 'off', |
| 119 | + '@typescript-eslint/no-empty-function': 'off', |
| 120 | + '@typescript-eslint/no-var-requires': 'off', |
| 121 | + '@typescript-eslint/no-explicit-any': 'off', |
| 122 | + '@typescript-eslint/no-non-null-assertion': 'off', |
| 123 | + '@typescript-eslint/explicit-function-return-type': 'off', |
| 124 | + '@typescript-eslint/ban-ts-ignore': 'off', |
| 125 | + '@typescript-eslint/ban-types': 'off', |
| 126 | + 'import/no-extraneous-dependencies': 'error', |
| 127 | + |
| 128 | + // todo: enable |
| 129 | + 'unicorn/filename-case': 'off', |
| 130 | + 'import/extensions': 'off', |
| 131 | + 'import/no-default-export': 'off', |
| 132 | + // todo: enable in v3 |
| 133 | + 'unicorn/prefer-node-protocol': 'off', |
| 134 | + 'prefer-object-has-own': 'off', |
| 135 | + |
| 136 | + // Rules introduced/tightened by updated plugins in ESLint 10 migration |
| 137 | + 'preserve-caught-error': 'off', |
| 138 | + '@typescript-eslint/prefer-optional-chain': 'off', |
| 139 | + 'no-useless-assignment': 'off', |
| 140 | + }, |
| 141 | + }, |
| 142 | + |
| 143 | + // Node environment for all files |
| 144 | + ...compat.env({ node: true }), |
| 145 | + |
| 146 | + // Website files: extend @theguild react config |
| 147 | + ...compat |
| 148 | + .config({ |
| 149 | + extends: ['./node_modules/@theguild/eslint-config/src/react.js'], |
| 150 | + }) |
| 151 | + .map(config => ({ ...config, files: ['website/**'] })), |
| 152 | + |
| 153 | + // Test files |
| 154 | + { |
| 155 | + files: [ |
| 156 | + '**/*.spec.ts', |
| 157 | + '**/tests/**/*.{js,ts,tsx,cjs}', |
| 158 | + '**/graphql-codegen-testing/**/*.ts', |
| 159 | + '**/vitest.config.ts', |
| 160 | + '**/vitest.setup.ts', |
| 161 | + '**/__mocks__/*', |
| 162 | + ], |
| 163 | + rules: { |
| 164 | + 'import/no-extraneous-dependencies': 'off', |
| 165 | + '@typescript-eslint/no-require-imports': 'off', |
| 166 | + }, |
| 167 | + }, |
| 168 | + |
| 169 | + // Test fixtures |
| 170 | + { |
| 171 | + files: ['**/tests/fixtures/*.{ts,js}'], |
| 172 | + rules: { |
| 173 | + '@typescript-eslint/no-unused-vars': 'off', |
| 174 | + }, |
| 175 | + }, |
| 176 | + |
| 177 | + // Scripts and config files |
| 178 | + { |
| 179 | + files: ['scripts/*.{ts,js}', 'prettier.config.cjs'], |
| 180 | + rules: { |
| 181 | + '@typescript-eslint/no-require-imports': 'off', |
| 182 | + }, |
| 183 | + }, |
| 184 | +]; |
0 commit comments