|
1 | 1 | import js from '@eslint/js'
|
2 |
| -import prettierConfig from 'eslint-config-prettier' |
| 2 | +import vitestPlugin from '@vitest/eslint-plugin' |
| 3 | +import prettierConfig from 'eslint-config-prettier/flat' |
| 4 | +import type { ConfigArray } from 'typescript-eslint' |
3 | 5 | import { config, configs, parser } from 'typescript-eslint'
|
4 | 6 |
|
5 |
| -const ESLintConfig = config( |
6 |
| - { name: 'ignores', ignores: ['**/dist/', '**/__testfixtures__/'] }, |
7 |
| - { name: 'javascript', ...js.configs.recommended }, |
8 |
| - ...configs.recommended, |
9 |
| - ...configs.stylistic, |
10 |
| - { name: 'prettier-config', ...prettierConfig }, |
| 7 | +const eslintConfig: ConfigArray = config( |
| 8 | + { |
| 9 | + name: 'global-ignores', |
| 10 | + ignores: [ |
| 11 | + '**/dist/', |
| 12 | + '**/build/', |
| 13 | + '**/lib/', |
| 14 | + '**/coverage/', |
| 15 | + '**/__snapshots__/', |
| 16 | + '**/temp/', |
| 17 | + '**/.temp/', |
| 18 | + '**/.tmp/', |
| 19 | + '**/.yalc/', |
| 20 | + '**/.yarn/', |
| 21 | + '**/.docusaurus/', |
| 22 | + '**/.next/', |
| 23 | + '**/__testfixtures__/', |
| 24 | + ], |
| 25 | + }, |
| 26 | + { |
| 27 | + name: `${js.meta.name}/recommended`, |
| 28 | + ...js.configs.recommended, |
| 29 | + }, |
| 30 | + |
| 31 | + configs.recommended, |
| 32 | + configs.stylistic, |
| 33 | + |
| 34 | + vitestPlugin.configs.recommended, |
| 35 | + vitestPlugin.configs.env, |
| 36 | + |
11 | 37 | {
|
12 | 38 | name: 'main',
|
13 | 39 | languageOptions: {
|
14 | 40 | parser,
|
15 | 41 | parserOptions: {
|
16 |
| - projectService: { |
17 |
| - defaultProject: './tsconfig.json', |
18 |
| - }, |
19 | 42 | ecmaVersion: 'latest',
|
| 43 | + projectService: true, |
| 44 | + tsconfigRootDir: import.meta.dirname, |
20 | 45 | },
|
21 | 46 | },
|
22 | 47 | rules: {
|
23 |
| - 'no-undef': [0], |
24 | 48 | '@typescript-eslint/consistent-type-imports': [
|
25 | 49 | 2,
|
26 |
| - { fixStyle: 'separate-type-imports', disallowTypeAnnotations: false }, |
| 50 | + { |
| 51 | + disallowTypeAnnotations: true, |
| 52 | + fixStyle: 'separate-type-imports', |
| 53 | + prefer: 'type-imports', |
| 54 | + }, |
| 55 | + ], |
| 56 | + '@typescript-eslint/consistent-type-exports': [ |
| 57 | + 2, |
| 58 | + { fixMixedExportsWithInlineTypeSpecifier: false }, |
| 59 | + ], |
| 60 | + '@typescript-eslint/no-explicit-any': [ |
| 61 | + 2, |
| 62 | + { |
| 63 | + fixToUnknown: false, |
| 64 | + ignoreRestArgs: false, |
| 65 | + }, |
27 | 66 | ],
|
28 |
| - '@typescript-eslint/consistent-type-exports': [2], |
29 |
| - '@typescript-eslint/no-unused-vars': [0], |
30 |
| - '@typescript-eslint/no-explicit-any': [0], |
31 | 67 | '@typescript-eslint/no-empty-object-type': [
|
32 | 68 | 2,
|
33 |
| - { allowInterfaces: 'with-single-extends' }, |
| 69 | + { |
| 70 | + allowInterfaces: 'never', |
| 71 | + allowObjectTypes: 'never', |
| 72 | + }, |
| 73 | + ], |
| 74 | + '@typescript-eslint/no-restricted-types': [ |
| 75 | + 2, |
| 76 | + { |
| 77 | + types: { |
| 78 | + '{}': { |
| 79 | + message: ` |
| 80 | +- If you want to represent an empty object, use \`type EmptyObject = Record<string, never>\`. |
| 81 | +- If you want to represent an object literal, use either \`type AnyObject = Record<string, any>\` or \`object\`. |
| 82 | +- If you want to represent any non-nullish value, use \`type AnyNonNullishValue = NonNullable<unknown>\`.`, |
| 83 | + suggest: [ |
| 84 | + 'AnyNonNullishValue', |
| 85 | + 'EmptyObject', |
| 86 | + 'AnyObject', |
| 87 | + 'object', |
| 88 | + 'Record<string, never>', |
| 89 | + 'Record<string, any>', |
| 90 | + 'NonNullable<unknown>', |
| 91 | + ], |
| 92 | + }, |
| 93 | + }, |
| 94 | + }, |
34 | 95 | ],
|
35 | 96 | '@typescript-eslint/no-namespace': [
|
36 | 97 | 2,
|
37 |
| - { allowDeclarations: true, allowDefinitionFiles: true }, |
| 98 | + { |
| 99 | + allowDeclarations: false, |
| 100 | + allowDefinitionFiles: true, |
| 101 | + }, |
38 | 102 | ],
|
39 |
| - '@typescript-eslint/ban-ts-comment': [0], |
| 103 | + '@typescript-eslint/consistent-type-definitions': [2, 'type'], |
40 | 104 | 'sort-imports': [
|
41 | 105 | 2,
|
42 | 106 | {
|
| 107 | + allowSeparatedGroups: true, |
43 | 108 | ignoreCase: false,
|
44 | 109 | ignoreDeclarationSort: true,
|
45 | 110 | ignoreMemberSort: false,
|
46 | 111 | memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
|
47 |
| - allowSeparatedGroups: true, |
48 | 112 | },
|
49 | 113 | ],
|
| 114 | + '@typescript-eslint/unified-signatures': [ |
| 115 | + 2, |
| 116 | + { |
| 117 | + ignoreDifferentlyNamedParameters: false, |
| 118 | + ignoreOverloadsWithDifferentJSDoc: false, |
| 119 | + }, |
| 120 | + ], |
| 121 | + '@typescript-eslint/no-unnecessary-type-parameters': [2], |
| 122 | + '@typescript-eslint/no-invalid-void-type': [ |
| 123 | + 2, |
| 124 | + { |
| 125 | + allowAsThisParameter: false, |
| 126 | + allowInGenericTypeArguments: true, |
| 127 | + }, |
| 128 | + ], |
| 129 | + '@typescript-eslint/no-confusing-void-expression': [ |
| 130 | + 2, |
| 131 | + { |
| 132 | + ignoreArrowShorthand: false, |
| 133 | + ignoreVoidOperator: false, |
| 134 | + ignoreVoidReturningFunctions: false, |
| 135 | + }, |
| 136 | + ], |
| 137 | + '@typescript-eslint/no-duplicate-type-constituents': [ |
| 138 | + 2, |
| 139 | + { |
| 140 | + ignoreIntersections: false, |
| 141 | + ignoreUnions: false, |
| 142 | + }, |
| 143 | + ], |
| 144 | + '@typescript-eslint/require-await': [2], |
| 145 | + '@typescript-eslint/no-redundant-type-constituents': [2], |
| 146 | + '@typescript-eslint/no-unnecessary-type-arguments': [2], |
| 147 | + '@typescript-eslint/no-unnecessary-type-assertion': [ |
| 148 | + 2, |
| 149 | + { typesToIgnore: [] }, |
| 150 | + ], |
| 151 | + '@typescript-eslint/prefer-nullish-coalescing': [ |
| 152 | + 2, |
| 153 | + { |
| 154 | + allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false, |
| 155 | + ignoreBooleanCoercion: false, |
| 156 | + ignoreConditionalTests: true, |
| 157 | + ignoreIfStatements: false, |
| 158 | + ignoreMixedLogicalExpressions: false, |
| 159 | + ignorePrimitives: { |
| 160 | + bigint: false, |
| 161 | + boolean: false, |
| 162 | + number: false, |
| 163 | + string: false, |
| 164 | + }, |
| 165 | + ignoreTernaryTests: false, |
| 166 | + }, |
| 167 | + ], |
| 168 | + '@typescript-eslint/no-inferrable-types': [ |
| 169 | + 2, |
| 170 | + { |
| 171 | + ignoreParameters: false, |
| 172 | + ignoreProperties: false, |
| 173 | + }, |
| 174 | + ], |
| 175 | + '@typescript-eslint/no-require-imports': [ |
| 176 | + 2, |
| 177 | + { |
| 178 | + allow: [], |
| 179 | + allowAsImport: true, |
| 180 | + }, |
| 181 | + ], |
| 182 | + 'object-shorthand': [ |
| 183 | + 2, |
| 184 | + 'always', |
| 185 | + { |
| 186 | + avoidQuotes: true, |
| 187 | + ignoreConstructors: true, |
| 188 | + methodsIgnorePattern: '', |
| 189 | + avoidExplicitReturnArrows: true, |
| 190 | + }, |
| 191 | + ], |
| 192 | + |
| 193 | + 'no-undef': [0, { typeof: false }], |
| 194 | + '@typescript-eslint/no-unused-vars': [ |
| 195 | + 0, |
| 196 | + { |
| 197 | + args: 'all', |
| 198 | + argsIgnorePattern: '^_', |
| 199 | + caughtErrors: 'all', |
| 200 | + caughtErrorsIgnorePattern: '^_', |
| 201 | + destructuredArrayIgnorePattern: '^_', |
| 202 | + varsIgnorePattern: '^_', |
| 203 | + ignoreRestSiblings: true, |
| 204 | + }, |
| 205 | + ], |
| 206 | + '@typescript-eslint/ban-ts-comment': [ |
| 207 | + 0, |
| 208 | + { |
| 209 | + 'ts-expect-error': 'allow-with-description', |
| 210 | + 'ts-ignore': true, |
| 211 | + 'ts-nocheck': true, |
| 212 | + 'ts-check': false, |
| 213 | + minimumDescriptionLength: 3, |
| 214 | + }, |
| 215 | + ], |
| 216 | + |
| 217 | + 'vitest/valid-title': [0], |
| 218 | + |
| 219 | + 'vitest/no-alias-methods': [2], |
| 220 | + 'vitest/no-disabled-tests': [2], |
| 221 | + 'vitest/no-focused-tests': [2], |
| 222 | + 'vitest/no-test-prefixes': [2], |
| 223 | + 'vitest/no-test-return-statement': [2], |
| 224 | + 'vitest/prefer-each': [2], |
| 225 | + 'vitest/prefer-spy-on': [2], |
| 226 | + 'vitest/prefer-to-be': [2], |
| 227 | + 'vitest/prefer-to-contain': [2], |
| 228 | + 'vitest/prefer-to-have-length': [2], |
| 229 | + 'vitest/prefer-describe-function-title': [2], |
| 230 | + }, |
| 231 | + |
| 232 | + settings: { |
| 233 | + vitest: { |
| 234 | + typecheck: true, |
| 235 | + }, |
| 236 | + }, |
| 237 | + |
| 238 | + linterOptions: { |
| 239 | + reportUnusedDisableDirectives: 2, |
50 | 240 | },
|
51 |
| - linterOptions: { reportUnusedDisableDirectives: 2 }, |
52 | 241 | },
|
| 242 | + |
53 | 243 | {
|
54 |
| - name: 'commonjs', |
55 |
| - files: ['**/*.c[jt]s'], |
56 |
| - languageOptions: { sourceType: 'commonjs' }, |
| 244 | + name: 'commonjs-files', |
| 245 | + files: ['**/*.cjs'], |
| 246 | + languageOptions: { |
| 247 | + sourceType: 'commonjs', |
| 248 | + }, |
57 | 249 | rules: {
|
58 |
| - '@typescript-eslint/no-require-imports': [0], |
| 250 | + '@typescript-eslint/no-require-imports': [ |
| 251 | + 0, |
| 252 | + { |
| 253 | + allow: [], |
| 254 | + allowAsImport: false, |
| 255 | + }, |
| 256 | + ], |
59 | 257 | },
|
60 | 258 | },
|
| 259 | + |
| 260 | + prettierConfig, |
61 | 261 | )
|
62 | 262 |
|
63 |
| -export default ESLintConfig |
| 263 | +export default eslintConfig |
0 commit comments