|
| 1 | +// @ts-check |
| 2 | +import path from 'node:path'; |
| 3 | +import { fileURLToPath } from 'node:url'; |
| 4 | +import eslint from '@eslint/js'; |
| 5 | +import { defineConfig } from 'eslint/config'; |
| 6 | +import tseslint from 'typescript-eslint'; |
| 7 | +import globals from 'globals'; |
| 8 | + |
| 9 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 10 | +import prettier from 'eslint-plugin-prettier'; |
| 11 | +import importPlugin from 'eslint-plugin-import'; |
| 12 | +import jest from 'eslint-plugin-jest'; |
| 13 | +import tsdoc from 'eslint-plugin-tsdoc'; |
| 14 | +import eslintConfigPrettier from 'eslint-config-prettier'; |
| 15 | + |
| 16 | +export default defineConfig([ |
| 17 | + // Ignore patterns (flat config: no other properties in this object) |
| 18 | + { |
| 19 | + ignores: [ |
| 20 | + '**/build', |
| 21 | + '**/node_modules', |
| 22 | + 'documentation', |
| 23 | + '**/.eslintrc.js', |
| 24 | + '**/.eslintrc.cjs', |
| 25 | + '**/eslint.config.*', |
| 26 | + ], |
| 27 | + }, |
| 28 | + |
| 29 | + // Base ESLint recommended |
| 30 | + eslint.configs.recommended, |
| 31 | + |
| 32 | + // TypeScript ESLint: recommended only for .ts (so .js files don't get TS rules) |
| 33 | + ...tseslint.configs.recommended.map((config) => ({ |
| 34 | + ...config, |
| 35 | + files: ['**/*.ts'], |
| 36 | + })), |
| 37 | + |
| 38 | + // Prettier: disable rules that conflict (must be last of shared configs) |
| 39 | + eslintConfigPrettier, |
| 40 | + |
| 41 | + // TypeScript files: type-checked config + language options + plugins + rules |
| 42 | + ...tseslint.configs.recommendedTypeChecked.map((config) => ({ |
| 43 | + ...config, |
| 44 | + files: ['**/*.ts'], |
| 45 | + })), |
| 46 | + { |
| 47 | + files: ['**/*.ts'], |
| 48 | + languageOptions: { |
| 49 | + parserOptions: { |
| 50 | + projectService: true, |
| 51 | + tsconfigRootDir: __dirname, |
| 52 | + }, |
| 53 | + globals: { |
| 54 | + ...globals.node, |
| 55 | + ...globals.jest, |
| 56 | + }, |
| 57 | + }, |
| 58 | + plugins: { |
| 59 | + prettier, |
| 60 | + import: importPlugin, |
| 61 | + jest, |
| 62 | + tsdoc, |
| 63 | + }, |
| 64 | + rules: { |
| 65 | + '@typescript-eslint/no-unsafe-argument': 'off', |
| 66 | + '@typescript-eslint/no-unsafe-return': 'warn', |
| 67 | + '@typescript-eslint/no-unsafe-assignment': 'warn', |
| 68 | + 'prettier/prettier': 'error', |
| 69 | + 'arrow-body-style': ['warn', 'always'], |
| 70 | + 'tsdoc/syntax': 'warn', |
| 71 | + 'import/prefer-default-export': 'off', |
| 72 | + 'import/no-default-export': 'error', |
| 73 | + 'no-underscore-dangle': 'off', |
| 74 | + }, |
| 75 | + }, |
| 76 | + |
| 77 | + // Spec files: relax some rules |
| 78 | + { |
| 79 | + files: ['**/*.spec.ts'], |
| 80 | + rules: { |
| 81 | + '@typescript-eslint/explicit-function-return-type': 'off', |
| 82 | + '@typescript-eslint/ban-ts-comment': 'off', |
| 83 | + }, |
| 84 | + }, |
| 85 | + |
| 86 | + // JS files (examples only) – Node globals, relax some rules |
| 87 | + { |
| 88 | + files: ['examples/**/examples/**/*.js'], |
| 89 | + languageOptions: { |
| 90 | + globals: { |
| 91 | + ...globals.node, |
| 92 | + }, |
| 93 | + }, |
| 94 | + plugins: { |
| 95 | + prettier, |
| 96 | + import: importPlugin, |
| 97 | + jest, |
| 98 | + }, |
| 99 | + rules: { |
| 100 | + 'no-console': 'off', |
| 101 | + 'prettier/prettier': 'error', |
| 102 | + '@typescript-eslint/no-require-imports': 'off', |
| 103 | + }, |
| 104 | + }, |
| 105 | +]); |
0 commit comments