|
| 1 | +import js from '@eslint/js'; |
| 2 | +import tsParser from '@typescript-eslint/parser'; |
| 3 | +import tsPlugin from '@typescript-eslint/eslint-plugin'; |
| 4 | +import prettierPlugin from 'eslint-plugin-prettier'; |
| 5 | +import prettierConfig from 'eslint-config-prettier'; |
| 6 | +import jestPlugin from 'eslint-plugin-jest'; |
| 7 | +import jestFormattingPlugin from 'eslint-plugin-jest-formatting'; |
| 8 | +import globals from 'globals'; |
| 9 | +import { dirname } from 'node:path'; |
| 10 | +import { fileURLToPath } from 'node:url'; |
| 11 | + |
| 12 | + |
| 13 | +export default [ |
| 14 | + // Base JavaScript configuration |
| 15 | + js.configs.recommended, |
| 16 | + |
| 17 | + // TypeScript files only |
| 18 | + { |
| 19 | + files: ['**/*.ts'], |
| 20 | + languageOptions: { |
| 21 | + parser: tsParser, |
| 22 | + ecmaVersion: 2022, |
| 23 | + globals: { |
| 24 | + ...globals.node, |
| 25 | + ...Object.fromEntries(Object.entries(globals.browser).map(([key]) => [key, 'off'])) |
| 26 | + }, |
| 27 | + parserOptions: { |
| 28 | + tsconfigRootDir: dirname(fileURLToPath(import.meta.url)), |
| 29 | + project: ['tsconfig.json', 'packages/tsconfig.json', 'examples/tsconfig.json'], |
| 30 | + warnOnUnsupportedTypeScriptVersion: false, |
| 31 | + EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true |
| 32 | + } |
| 33 | + }, |
| 34 | + plugins: { |
| 35 | + '@typescript-eslint': tsPlugin, |
| 36 | + prettier: prettierPlugin |
| 37 | + }, |
| 38 | + rules: { |
| 39 | + ...tsPlugin.configs.recommended.rules, |
| 40 | + ...tsPlugin.configs['recommended-requiring-type-checking'].rules, |
| 41 | + ...prettierConfig.rules, |
| 42 | + |
| 43 | + // Prettier |
| 44 | + 'prettier/prettier': 'warn', |
| 45 | + |
| 46 | + // TypeScript specific rules |
| 47 | + '@typescript-eslint/no-unsafe-declaration-merging': 'off', |
| 48 | + '@typescript-eslint/no-redundant-type-constituents': 'off', |
| 49 | + '@typescript-eslint/adjacent-overload-signatures': 'error', |
| 50 | + '@typescript-eslint/await-thenable': 'error', |
| 51 | + '@typescript-eslint/prefer-promise-reject-errors': 'off', |
| 52 | + '@typescript-eslint/explicit-function-return-type': [ |
| 53 | + 'warn', |
| 54 | + { |
| 55 | + allowExpressions: true, |
| 56 | + allowTypedFunctionExpressions: true |
| 57 | + } |
| 58 | + ], |
| 59 | + '@typescript-eslint/explicit-member-accessibility': 'off', |
| 60 | + '@typescript-eslint/interface-name-prefix': 'off', |
| 61 | + '@typescript-eslint/no-explicit-any': 'off', |
| 62 | + '@typescript-eslint/no-parameter-properties': 'off', |
| 63 | + '@typescript-eslint/no-shadow': 'error', |
| 64 | + '@typescript-eslint/no-this-alias': 'error', |
| 65 | + '@typescript-eslint/no-unused-expressions': 'off', |
| 66 | + '@typescript-eslint/no-require-imports': 'off', |
| 67 | + '@typescript-eslint/no-unused-vars': ['error', { args: 'none' }], |
| 68 | + '@typescript-eslint/prefer-function-type': 'error', |
| 69 | + '@typescript-eslint/prefer-namespace-keyword': 'error', |
| 70 | + '@typescript-eslint/promise-function-async': 'off', |
| 71 | + '@typescript-eslint/member-ordering': 'warn', |
| 72 | + '@typescript-eslint/require-await': 'off', |
| 73 | + '@typescript-eslint/no-var-requires': 'off', |
| 74 | + '@typescript-eslint/naming-convention': [ |
| 75 | + 'error', |
| 76 | + { |
| 77 | + selector: 'typeParameter', |
| 78 | + format: ['PascalCase'] |
| 79 | + } |
| 80 | + ], |
| 81 | + |
| 82 | + // General rules |
| 83 | + 'no-redeclare': 'off', |
| 84 | + 'no-empty': 'off', |
| 85 | + 'no-irregular-whitespace': 'error', |
| 86 | + 'no-return-assign': 'error', |
| 87 | + 'no-return-await': 'error', |
| 88 | + 'no-throw-literal': 'error', |
| 89 | + 'no-undef': 'off', |
| 90 | + 'no-useless-call': 'error', |
| 91 | + 'no-useless-concat': 'error', |
| 92 | + 'no-var': 'error', |
| 93 | + 'prefer-const': 'error', |
| 94 | + 'prefer-object-spread': 'error', |
| 95 | + 'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }], |
| 96 | + 'prefer-template': 'error', |
| 97 | + 'prefer-arrow-callback': 'warn', |
| 98 | + 'linebreak-style': ['error', 'unix'], |
| 99 | + quotes: ['error', 'single'], |
| 100 | + 'no-console': 'error' |
| 101 | + } |
| 102 | + }, |
| 103 | + |
| 104 | + // JavaScript files |
| 105 | + { |
| 106 | + files: ['**/*.js'], |
| 107 | + languageOptions: { |
| 108 | + ecmaVersion: 2022, |
| 109 | + globals: { |
| 110 | + ...globals.node |
| 111 | + } |
| 112 | + }, |
| 113 | + plugins: { |
| 114 | + prettier: prettierPlugin |
| 115 | + }, |
| 116 | + rules: { |
| 117 | + ...prettierConfig.rules, |
| 118 | + 'prettier/prettier': 'warn', |
| 119 | + 'no-empty': 'off', |
| 120 | + 'no-irregular-whitespace': 'error', |
| 121 | + 'no-return-assign': 'error', |
| 122 | + 'no-return-await': 'error', |
| 123 | + 'no-throw-literal': 'error', |
| 124 | + 'no-useless-call': 'error', |
| 125 | + 'no-useless-concat': 'error', |
| 126 | + 'no-var': 'error', |
| 127 | + 'prefer-const': 'error', |
| 128 | + 'prefer-object-spread': 'error', |
| 129 | + 'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }], |
| 130 | + 'prefer-template': 'error', |
| 131 | + 'prefer-arrow-callback': 'warn', |
| 132 | + 'linebreak-style': ['error', 'unix'], |
| 133 | + quotes: ['error', 'single'], |
| 134 | + 'no-console': 'error' |
| 135 | + } |
| 136 | + }, |
| 137 | + |
| 138 | + // Test files configuration |
| 139 | + { |
| 140 | + files: ['test/**/*.{ts,js}'], |
| 141 | + languageOptions: { |
| 142 | + globals: { |
| 143 | + ...globals.jest |
| 144 | + } |
| 145 | + }, |
| 146 | + plugins: { |
| 147 | + jest: jestPlugin, |
| 148 | + 'jest-formatting': jestFormattingPlugin |
| 149 | + }, |
| 150 | + rules: { |
| 151 | + ...jestPlugin.configs.recommended.rules, |
| 152 | + ...jestPlugin.configs.style.rules, |
| 153 | + ...jestFormattingPlugin.configs.recommended.rules, |
| 154 | + |
| 155 | + '@typescript-eslint/unbound-method': 'off', |
| 156 | + 'jest/expect-expect': [ |
| 157 | + 'error', |
| 158 | + { |
| 159 | + assertFunctionNames: ['expect', 'request.**.expect'] |
| 160 | + } |
| 161 | + ] |
| 162 | + } |
| 163 | + }, |
| 164 | + |
| 165 | + // Examples configuration |
| 166 | + { |
| 167 | + files: ['examples/**/*.{ts,js}'], |
| 168 | + rules: { |
| 169 | + '@typescript-eslint/explicit-function-return-type': 'off', |
| 170 | + 'no-console': 'off' |
| 171 | + } |
| 172 | + }, |
| 173 | + |
| 174 | + // Global ignores |
| 175 | + { |
| 176 | + ignores: [ |
| 177 | + '**/dist/', |
| 178 | + '**/scripts/', |
| 179 | + '**/lib/', |
| 180 | + '**/upload/', |
| 181 | + '**/uploads/', |
| 182 | + '**/files/', |
| 183 | + '**/tmp/', |
| 184 | + '**/temp/', |
| 185 | + '**/node_modules/', |
| 186 | + '**/*.example', |
| 187 | + '**/*.json', |
| 188 | + '**/coverage/', |
| 189 | + '**/*.snap', |
| 190 | + '**/*.config.js', |
| 191 | + '**/*.config.cjs', |
| 192 | + '**/*.config.mjs' |
| 193 | + ] |
| 194 | + } |
| 195 | +]; |
0 commit comments