-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypescript.ts
95 lines (93 loc) · 3.17 KB
/
typescript.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import process from 'node:process';
import tseslint from 'typescript-eslint';
import { RULE_PREFIX, GLOB_TS_SRC } from '../consts';
import type { Linter } from 'eslint';
import type { ITypescriptConfigsOptions } from '../types';
export function typescript(options: ITypescriptConfigsOptions = {}): Linter.Config[] {
const { overrides = {}, typeSafe = false } = options;
return [
...tseslint.config(
tseslint.configs.base,
tseslint.configs.recommendedTypeChecked,
tseslint.configs.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
).map((item) => ({
...item,
name: `${RULE_PREFIX}/typescript/shared/${item.name?.replace('typescript-eslint/', '')}`,
files: GLOB_TS_SRC,
})),
{
name: `${RULE_PREFIX}/typescript/customize`,
files: GLOB_TS_SRC,
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: process.cwd(),
},
},
rules: {
'@typescript-eslint/consistent-type-imports': [
'error',
{
disallowTypeAnnotations: false,
},
],
'@typescript-eslint/no-import-type-side-effects': 'error',
'@typescript-eslint/method-signature-style': ['error', 'property'],
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': [
'error',
{
allowShortCircuit: true,
allowTernary: true,
},
],
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-empty-object-type': [
'error',
{
allowInterfaces: 'with-single-extends',
allowObjectTypes: 'never',
allowWithName: 'Props$',
},
],
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'warn',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/no-misused-promises': [
'error',
{
checksVoidReturn: {
arguments: false,
attributes: false,
},
},
],
'@typescript-eslint/restrict-template-expressions': ['error', {}],
'@typescript-eslint/no-deprecated': 'warn',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/array-type': [
'error',
{
default: 'array-simple',
},
],
'@typescript-eslint/prefer-nullish-coalescing': 'off',
...(typeSafe
? {}
: {
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
}),
...overrides,
},
},
] as Linter.Config[];
}