-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
.eslintrc
177 lines (172 loc) · 5.38 KB
/
.eslintrc
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
* "off" 或 0 - 关闭规则
* "warn" 或 1 - 开启规则,使用警告级别的错误:warn (不会导致程序退出),
* "error" 或 2 - 开启规则,使用错误级别的错误:error (当被触发的时候,程序会退出)
*/
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"requireConfigFile": false,
"ecmaVersion": 6,
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint", "eslint-plugin-prettier", "unused-imports"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
"env": {
"browser": false,
"node": false
},
"globals": {
"self": true
},
"rules": {
// 禁止全局变量
"no-restricted-globals": ["error", "Node"],
// 禁止导入
"@typescript-eslint/no-restricted-imports": ["error",
{
"patterns": [
// 禁止使用 @framework 内的模块
{
"group": ["@framework"],
"message": "请使用 mk.xxx,而不是直接导入 @framework"
}
],
// 禁止使用 NodeJs 模块
"paths": ["assert","buffer","child_process","cluster","crypto","dgram","dns","domain","events","freelist","fs","http","https","module","net","os","path","punycode","querystring","readline","repl","smalloc","stream","string_decoder","sys","timers","tls","tracing","tty","url","util","vm","zlib"]
}
],
// 禁止返回类型 void 混合其他
"@typescript-eslint/no-invalid-void-type": "error",
// 一致的泛型构造函数
"@typescript-eslint/consistent-generic-constructors": "error",
// 使用 Record 代替 { [k: type]: type }
"@typescript-eslint/consistent-indexed-object-style": ["error", "record"],
// 不允许使用大类型
"@typescript-eslint/ban-types": "off",
// 不能在 promise 回调使用 async 函数
"no-async-promise-executor": "off",
// 不允许未使用的变量
"@typescript-eslint/no-unused-vars": "off",
// 自动删除未使用的导入
"unused-imports/no-unused-imports": "error",
// 注释首尾必须有空格
"spaced-comment": [
"error",
"always",
{
"line": {
"markers": ["/"],
"exceptions": ["-", "+"]
},
"block": {
"markers": ["!"],
"exceptions": ["*"],
"balanced": true
}
}
],
// 不允许自定义 namespace
"@typescript-eslint/no-namespace": "off",
// 不允许使用 any
"@typescript-eslint/no-explicit-any": "off",
// 禁止@ts-<directive>评论或要求指令后的描述
"@typescript-eslint/ban-ts-comment": "off",
// 使用 ?? 替代 !
"@typescript-eslint/no-non-null-assertion": "off",
// 强制使用简洁的可选链表达式
"@typescript-eslint/prefer-optional-chain": "error",
// 禁止使用联合或可选/剩余参数可以统一为一个的两个重载
"@typescript-eslint/unified-signatures": "error",
// 一致的类型断言
"@typescript-eslint/consistent-type-assertions": ["error", { "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }],
// 必须存在返回类型
"@typescript-eslint/explicit-function-return-type": [
"error",
{
"allowExpressions": true,
"allowedNames": ["onLoad", "onEnable", "start", "update", "lateUpdate", "onDisable", "onDestroy"]
}
],
// 类成员换行
"@typescript-eslint/lines-between-class-members": ["error", { "exceptAfterSingleLine": true }],
// 换行规则
"@typescript-eslint/padding-line-between-statements": [
"error",
// 多行表达式/多行块状语句/const/let/var 语句后换行
{ "blankLine": "always", "prev": ["multiline-expression", "multiline-block-like", "const", "let", "var"], "next": "*" },
// return 语句前换行
{ "blankLine": "always", "prev": "*", "next": "return" },
// 忽略单行 const/let/var 换行
{
"blankLine": "never",
"prev": ["singleline-const", "singleline-let", "singleline-var"],
"next": ["singleline-const", "singleline-let", "singleline-var"]
}
],
// 命名规则
"@typescript-eslint/naming-convention": [
"error",
// 蛇形命名规则
{
"selector": "variableLike",
"format": ["snake_case"],
"trailingUnderscore": "allowSingleOrDouble"
},
// private 命名规则
{
"selector": "memberLike",
"modifiers": ["private"],
"format": ["snake_case"],
"leadingUnderscore": "require"
},
// protected 命名规则
{
"selector": "memberLike",
"modifiers": ["protected"],
"format": ["snake_case"],
"filter": {
"match": true,
"regex": "[^(onLoad)(onEnable)(onDisable)(onDestroy)(targetOff)(displayName)(update)]"
},
"leadingUnderscore": "require"
},
// public 命名规则
{
"selector": "memberLike",
"modifiers": ["public"],
"format": ["snake_case"],
"filter": {
"match": true,
"regex": "[^(onLoad)(onEnable)(onDisable)(onDestroy)(targetOff)(displayName)]"
},
"leadingUnderscore": "allowSingleOrDouble",
"trailingUnderscore": "allowSingleOrDouble"
}
],
// 成员排序
"@typescript-eslint/member-ordering": [
"error",
{
"default": [
// Index signature
"signature",
// Fields
"public-static-field",
"protected-static-field",
"private-static-field",
"static-field",
"public-abstract-field",
"public-instance-field",
"protected-abstract-field",
"protected-instance-field",
"private-instance-field",
"public-field",
"protected-field",
"private-field"
]
}
]
}
}