|
| 1 | +import * as path from 'path'; |
| 2 | +import { fileURLToPath } from 'url'; |
| 3 | + |
| 4 | +// Calculate current directory for proper file path resolution |
| 5 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 6 | + |
| 7 | +// Import the modules from our CommonJS compatibility wrapper |
| 8 | +const compat = await import(`${__dirname}/eslint-compat.cjs`); |
| 9 | +const js = compat.default.js; |
| 10 | +const ts = compat.default.ts; |
| 11 | +const tsParser = compat.default.tsParser; |
| 12 | +const prettier = compat.default.prettier; |
| 13 | +const importPlugin = compat.default.importPlugin; |
| 14 | +const pluginJest = compat.default.pluginJest; |
| 15 | +const prettierPlugin = compat.default.prettierPlugin; |
| 16 | +const simpleImportSort = compat.default.simpleImportSort; |
| 17 | + |
| 18 | +// Recreate eslint:recommended |
| 19 | +const eslintRecommended = js.configs.recommended; |
| 20 | + |
| 21 | +// Recreate plugin:@typescript-eslint/recommended |
| 22 | +const typescriptRecommended = { |
| 23 | + plugins: { |
| 24 | + '@typescript-eslint': ts, |
| 25 | + }, |
| 26 | + rules: { |
| 27 | + ...ts.configs.recommended.rules, |
| 28 | + }, |
| 29 | +}; |
| 30 | + |
| 31 | +// Recreate plugin:import/errors, plugin:import/warnings, plugin:import/typescript |
| 32 | +const importRules = { |
| 33 | + plugins: { |
| 34 | + import: importPlugin, |
| 35 | + }, |
| 36 | + rules: { |
| 37 | + ...importPlugin.configs.errors.rules, |
| 38 | + ...importPlugin.configs.warnings.rules, |
| 39 | + ...importPlugin.configs.typescript.rules, |
| 40 | + }, |
| 41 | +}; |
| 42 | + |
| 43 | +// Recreate plugin:prettier/recommended |
| 44 | +const prettierRecommended = { |
| 45 | + plugins: { |
| 46 | + prettier: prettierPlugin, |
| 47 | + }, |
| 48 | + rules: { |
| 49 | + 'prettier/prettier': 'error', |
| 50 | + ...prettier.rules, |
| 51 | + }, |
| 52 | +}; |
| 53 | + |
| 54 | +export default [ |
| 55 | + { |
| 56 | + ignores: ['**/node_modules/**', '**/dist/**', 'eslint.config.mjs', 'eslint-compat.cjs', 'commitlint.config.cjs'], |
| 57 | + }, |
| 58 | + { |
| 59 | + files: ['**/*.ts', '**/*.mjs', '**/*.cjs', '**/*.js'], |
| 60 | + settings: { |
| 61 | + 'import/resolver': { |
| 62 | + typescript: { |
| 63 | + alwaysTryTypes: true, |
| 64 | + }, |
| 65 | + }, |
| 66 | + }, |
| 67 | + languageOptions: { |
| 68 | + ecmaVersion: 2022, |
| 69 | + sourceType: 'module', |
| 70 | + parser: tsParser, |
| 71 | + globals: { |
| 72 | + // Browser environment |
| 73 | + window: 'readonly', |
| 74 | + document: 'readonly', |
| 75 | + navigator: 'readonly', |
| 76 | + console: 'readonly', |
| 77 | + module: 'readonly', |
| 78 | + __dirname: 'readonly', |
| 79 | + process: 'readonly', |
| 80 | + Buffer: 'readonly', |
| 81 | + setTimeout: 'readonly', |
| 82 | + setInterval: 'readonly', |
| 83 | + clearTimeout: 'readonly', |
| 84 | + clearInterval: 'readonly', |
| 85 | + TextEncoder: 'readonly', |
| 86 | + TextDecoder: 'readonly', |
| 87 | + ImportMetaEnv: 'readonly', |
| 88 | + fetch: 'readonly', |
| 89 | + }, |
| 90 | + }, |
| 91 | + }, |
| 92 | + { |
| 93 | + files: ['tests/**/*.ts'], |
| 94 | + plugins: { |
| 95 | + jest: pluginJest, |
| 96 | + }, |
| 97 | + languageOptions: { |
| 98 | + globals: pluginJest.environments.globals.globals, |
| 99 | + }, |
| 100 | + rules: { |
| 101 | + 'jest/no-disabled-tests': 'warn', |
| 102 | + 'jest/no-focused-tests': 'error', |
| 103 | + 'jest/no-identical-title': 'error', |
| 104 | + 'jest/prefer-to-have-length': 'warn', |
| 105 | + 'jest/valid-expect': 'error', |
| 106 | + }, |
| 107 | + }, |
| 108 | + // Include all the extended configs |
| 109 | + eslintRecommended, |
| 110 | + typescriptRecommended, |
| 111 | + importRules, |
| 112 | + prettierRecommended, |
| 113 | + prettier, // Additional prettier config |
| 114 | + { |
| 115 | + // Plugin and rule configurations |
| 116 | + plugins: { |
| 117 | + '@typescript-eslint': ts, |
| 118 | + 'simple-import-sort': simpleImportSort, |
| 119 | + }, |
| 120 | + rules: { |
| 121 | + '@typescript-eslint/no-explicit-any': 'off', |
| 122 | + '@typescript-eslint/explicit-function-return-type': 'error', |
| 123 | + '@typescript-eslint/no-non-null-assertion': 'off', |
| 124 | + '@typescript-eslint/no-unused-vars': [ |
| 125 | + 'warn', |
| 126 | + { argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' }, |
| 127 | + ], |
| 128 | + 'simple-import-sort/imports': [ |
| 129 | + 'error', |
| 130 | + { |
| 131 | + groups: [ |
| 132 | + ['^@?\\w'], // Packages |
| 133 | + ['^\\u0000'], // Side effect imports |
| 134 | + ['^\\.\\.(?!/?$)', '^\\.\\./?$'], // Parent imports |
| 135 | + ['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'], // Other relative imports |
| 136 | + ['^.+\\.?(css)$'], // Style imports |
| 137 | + ], |
| 138 | + }, |
| 139 | + ], |
| 140 | + }, |
| 141 | + }, |
| 142 | +]; |
0 commit comments