|
1 | 1 | import { GLOB_JS, GLOB_TS, GLOB_TSX } from '../globs'
|
2 |
| -import { parserTypeScript, pluginAntfu, pluginTypeScript } from '../plugins' |
| 2 | +import { tseslint } from '../plugins' |
3 | 3 | import { restrictedSyntaxJs } from './javascript'
|
4 |
| -import type { FlatESLintConfigItem } from 'eslint-define-config' |
| 4 | +import type { FlatESLintConfigItem, Rules } from 'eslint-define-config' |
| 5 | + |
| 6 | +export const typescriptRules: Rules = { |
| 7 | + '@typescript-eslint/ban-ts-comment': 'off', |
| 8 | + '@typescript-eslint/ban-types': 'off', |
| 9 | + '@typescript-eslint/consistent-type-assertions': [ |
| 10 | + 'error', |
| 11 | + { |
| 12 | + assertionStyle: 'as', |
| 13 | + objectLiteralTypeAssertions: 'allow-as-parameter', |
| 14 | + }, |
| 15 | + ], |
| 16 | + '@typescript-eslint/consistent-type-imports': [ |
| 17 | + 'error', |
| 18 | + { disallowTypeAnnotations: false, fixStyle: 'inline-type-imports' }, |
| 19 | + ], |
| 20 | + '@typescript-eslint/no-explicit-any': 'off', |
| 21 | + '@typescript-eslint/no-import-type-side-effects': 'error', |
| 22 | + '@typescript-eslint/no-non-null-assertion': 'off', |
| 23 | + '@typescript-eslint/no-redeclare': 'error', |
| 24 | + |
| 25 | + // handled by unused-imports/no-unused-imports |
| 26 | + '@typescript-eslint/no-unused-vars': 'off', |
| 27 | + |
| 28 | + '@typescript-eslint/prefer-as-const': 'warn', |
| 29 | + '@typescript-eslint/prefer-literal-enum-member': [ |
| 30 | + 'error', |
| 31 | + { allowBitwiseExpressions: true }, |
| 32 | + ], |
| 33 | + |
| 34 | + 'no-restricted-syntax': [ |
| 35 | + 'error', |
| 36 | + ...restrictedSyntaxJs, |
| 37 | + 'TSEnumDeclaration[const=true]', |
| 38 | + ], |
| 39 | +} |
5 | 40 |
|
6 | 41 | export const typescript: FlatESLintConfigItem[] = [
|
7 |
| - { |
| 42 | + ...(tseslint.config({ |
| 43 | + extends: [...tseslint.configs.recommended], |
8 | 44 | files: [GLOB_TS, GLOB_TSX],
|
9 | 45 | languageOptions: {
|
10 |
| - parser: parserTypeScript, |
| 46 | + parser: tseslint.parser, |
11 | 47 | parserOptions: {
|
12 | 48 | sourceType: 'module',
|
13 | 49 | },
|
14 | 50 | },
|
15 |
| - plugins: { |
16 |
| - '@typescript-eslint': pluginTypeScript, |
17 |
| - antfu: pluginAntfu, |
18 |
| - }, |
19 |
| - rules: { |
20 |
| - ...pluginTypeScript.configs['eslint-recommended'].overrides![0].rules, |
21 |
| - ...pluginTypeScript.configs.strict.rules, |
22 |
| - |
23 |
| - '@typescript-eslint/ban-ts-comment': 'off', |
24 |
| - '@typescript-eslint/ban-types': 'off', |
25 |
| - '@typescript-eslint/consistent-type-assertions': [ |
26 |
| - 'error', |
27 |
| - { |
28 |
| - assertionStyle: 'as', |
29 |
| - objectLiteralTypeAssertions: 'allow-as-parameter', |
30 |
| - }, |
31 |
| - ], |
32 |
| - '@typescript-eslint/consistent-type-imports': [ |
33 |
| - 'error', |
34 |
| - { disallowTypeAnnotations: false, fixStyle: 'inline-type-imports' }, |
35 |
| - ], |
36 |
| - '@typescript-eslint/no-explicit-any': 'off', |
37 |
| - '@typescript-eslint/no-import-type-side-effects': 'error', |
38 |
| - '@typescript-eslint/no-non-null-assertion': 'off', |
39 |
| - '@typescript-eslint/no-redeclare': 'error', |
40 |
| - |
41 |
| - // handled by unused-imports/no-unused-imports |
42 |
| - '@typescript-eslint/no-unused-vars': 'off', |
| 51 | + rules: typescriptRules, |
| 52 | + }) as FlatESLintConfigItem[]), |
43 | 53 |
|
44 |
| - '@typescript-eslint/prefer-as-const': 'warn', |
45 |
| - '@typescript-eslint/prefer-literal-enum-member': [ |
46 |
| - 'error', |
47 |
| - { allowBitwiseExpressions: true }, |
48 |
| - ], |
49 |
| - |
50 |
| - 'no-restricted-syntax': [ |
51 |
| - 'error', |
52 |
| - ...restrictedSyntaxJs, |
53 |
| - 'TSEnumDeclaration[const=true]', |
54 |
| - ], |
55 |
| - }, |
56 |
| - }, |
57 | 54 | {
|
58 | 55 | files: ['**/*.d.ts'],
|
59 | 56 | rules: {
|
|
0 commit comments