|
| 1 | +// @ts-check |
| 2 | + |
| 3 | +import js from '@eslint/js'; |
| 4 | +import { defineConfig, globalIgnores } from 'eslint/config'; |
| 5 | +import prettierConfig from 'eslint-config-prettier/flat'; |
| 6 | +import { importX } from 'eslint-plugin-import-x'; |
| 7 | +import jest from 'eslint-plugin-jest'; |
| 8 | +import * as jestFormatting from 'eslint-plugin-jest-formatting'; |
| 9 | +import globals from 'globals'; |
| 10 | +import tseslint from 'typescript-eslint'; |
| 11 | + |
| 12 | +const config = defineConfig( |
| 13 | + js.configs.recommended, |
| 14 | + tseslint.configs.recommendedTypeChecked, |
| 15 | + importX.flatConfigs.recommended, |
| 16 | + importX.flatConfigs.typescript, |
| 17 | + { |
| 18 | + name: 'Language options', |
| 19 | + files: ['**/*.{js,mjs,cjs,ts,mts}'], |
| 20 | + languageOptions: { |
| 21 | + globals: { |
| 22 | + ...globals.node, |
| 23 | + }, |
| 24 | + ecmaVersion: 'latest', |
| 25 | + sourceType: 'module', |
| 26 | + parser: tseslint.parser, |
| 27 | + parserOptions: { |
| 28 | + projectService: true, |
| 29 | + tsconfigRootDir: import.meta.dirname, |
| 30 | + }, |
| 31 | + }, |
| 32 | + }, |
| 33 | + { |
| 34 | + name: 'Rules overrides for all files', |
| 35 | + rules: { |
| 36 | + // Base |
| 37 | + 'max-lines-per-function': 'off', |
| 38 | + 'no-console': 'warn', |
| 39 | + |
| 40 | + // TypeScript |
| 41 | + '@typescript-eslint/consistent-type-imports': 'error', |
| 42 | + '@typescript-eslint/explicit-function-return-type': 'off', |
| 43 | + '@typescript-eslint/no-unused-vars': [ |
| 44 | + 'warn', |
| 45 | + { |
| 46 | + argsIgnorePattern: '^_', |
| 47 | + }, |
| 48 | + ], |
| 49 | + '@typescript-eslint/no-use-before-define': 'off', |
| 50 | + |
| 51 | + // Import |
| 52 | + 'import-x/order': [ |
| 53 | + 'warn', |
| 54 | + { |
| 55 | + groups: [ |
| 56 | + 'builtin', |
| 57 | + 'external', |
| 58 | + 'internal', |
| 59 | + ['parent', 'sibling', 'index'], |
| 60 | + 'object', |
| 61 | + 'type', |
| 62 | + ], |
| 63 | + 'newlines-between': 'always', |
| 64 | + |
| 65 | + alphabetize: { |
| 66 | + order: 'asc', |
| 67 | + caseInsensitive: false, |
| 68 | + }, |
| 69 | + }, |
| 70 | + ], |
| 71 | + 'import-x/first': 'error', |
| 72 | + 'import-x/no-empty-named-blocks': 'error', |
| 73 | + 'import-x/no-extraneous-dependencies': 'error', |
| 74 | + 'import-x/no-mutable-exports': 'error', |
| 75 | + 'import-x/no-named-default': 'error', |
| 76 | + 'import-x/no-relative-packages': 'warn', |
| 77 | + }, |
| 78 | + }, |
| 79 | + { |
| 80 | + name: 'Rule overrides only for TypeScript files', |
| 81 | + files: ['**/*.{ts,mts}'], |
| 82 | + rules: { |
| 83 | + // Rules enabled by `import-x/recommended` but are better handled by |
| 84 | + // TypeScript and typescript-eslint. |
| 85 | + 'import-x/default': 'off', |
| 86 | + 'import-x/export': 'off', |
| 87 | + 'import-x/namespace': 'off', |
| 88 | + 'import-x/no-unresolved': 'off', |
| 89 | + }, |
| 90 | + }, |
| 91 | + { |
| 92 | + name: 'Jest config', |
| 93 | + files: ['**/*.test.ts', '**/*.test.js'], |
| 94 | + ...jest.configs['flat/recommended'], |
| 95 | + ...jestFormatting.configs['flat/recommended'], |
| 96 | + }, |
| 97 | + { |
| 98 | + name: 'Plain JS', |
| 99 | + files: ['**/*.{js,mjs,cjs}'], |
| 100 | + extends: [tseslint.configs.disableTypeChecked], |
| 101 | + }, |
| 102 | + { |
| 103 | + name: 'Config files', |
| 104 | + files: ['**/*rc*.{js,mjs,cjs}', '**/*.config.{js,cjs,mjs,ts}'], |
| 105 | + rules: { |
| 106 | + '@typescript-eslint/no-require-imports': 'off', |
| 107 | + 'import-x/no-named-as-default-member': 'off', |
| 108 | + }, |
| 109 | + }, |
| 110 | + globalIgnores(['**/coverage/', '**/dist/']), |
| 111 | + prettierConfig // must always be the last one |
| 112 | +); |
| 113 | + |
| 114 | +export default config; |
0 commit comments