-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.json
345 lines (345 loc) · 10.5 KB
/
.eslintrc.json
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
{
"root": true,
"env": {
"node": true,
"es2020": true,
"jest": true
},
"extends": [
// https://eslint.org/docs/latest/rules/
"eslint:recommended"
],
"plugins": [
"@typescript-eslint"
],
"parser": "@typescript-eslint/parser",
"overrides": [
{
// https://stackoverflow.com/questions/58510287/parseroptions-project-has-been-set-for-typescript-eslint-parser
"files": [
"./src/**/*.ts"
],
"extends": [
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/eslint-recommended.ts
"plugin:@typescript-eslint/eslint-recommended",
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended.ts
"plugin:@typescript-eslint/recommended"
],
"parserOptions": {
"project": [
"./tsconfig.json"
],
"ecmaVersion": 2020
},
/*
Typescript specific rules
*/
"rules": {
// Let Typescript handle this instead
"@typescript-eslint/no-unused-vars": "off",
// Prefer T[] over Array<T>
"@typescript-eslint/array-type": [
"error",
{
"default": "array"
}
],
// Prefer const thing = 5 as const; over const thing = <const>5;
// Prefer const obj: T = { ... }; over const obj = { ... } as T;
"@typescript-eslint/consistent-type-assertions": [
"error",
{
"assertionStyle": "as",
"objectLiteralTypeAssertions": "allow"
}
],
// Note: you must disable the base rule as it can report incorrect errors
"default-param-last": [
"off"
],
// Disallow default function params placed before non-default
"@typescript-eslint/default-param-last": [
"error"
],
// Enforce the semicolon (preferred in Typescript) delimeter for members in type/interface definitions.
// However, allow the last member in a single line definition to omit the delimeter
"@typescript-eslint/member-delimiter-style": [
"error",
{
"multiline": {
"delimiter": "semi",
"requireLast": true
},
"singleline": {
"delimiter": "semi",
"requireLast": false
},
"multilineDetection": "brackets"
}
],
// Disallow non-null assertion operator in places where it could be confused with !==. More reading: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator
"@typescript-eslint/no-confusing-non-null-assertion": [
"error"
],
// Disallow duplicate values in enums, for example: enum E = { A: 0, B: 0 }
"@typescript-eslint/no-duplicate-enum-values": [
"error"
],
// Disallow empty interfaces, except in the case where it extends 1 interface, for example:
// interface EncryptedStrings { a: string; b: string }
// interface DecryptedStrings extends EncryptedStrings {}
"@typescript-eslint/no-empty-interface": [
"error",
{
"allowSingleExtends": true
}
],
// Kinda have to use the any type in a library, unknown works too but it doesn't really matter
"@typescript-eslint/no-explicit-any": [
"off"
],
// Note: you must disable the base rule as it can report incorrect errors
"no-loop-func": [
"off"
],
// Disallow function declarations that contain unsafe references inside loop statements. This is only a problem when using var
"@typescript-eslint/no-loop-func": [
"warn"
],
// Warn about instances of the following:
/*
declare const someCondition: boolean;
if (someCondition === true) {}
*/
"@typescript-eslint/no-unnecessary-boolean-literal-compare": [
"warn"
],
// Note: you must disable the base rule as it can report incorrect errors
"no-unused-expressions": [
"off"
],
// An unused expression which has no effect on the state of the program indicates a logic error
"@typescript-eslint/no-unused-expressions": [
"error"
],
// Warn about empty exports that don't change anything in a module file
"@typescript-eslint/no-useless-empty-export": [
"warn"
],
// This rule detects when an as cast is doing the same job as a ! would, and suggests fixing the code to be an !
// IMO, this is a good thing to error because if there is a need to assert something as non-null (which is fine in a few select places), the non-null assertion operator is safer because it only removes null and undefined from the type, not any other union members
// When fixing this error, another warning will be created, but I'd rather leave the warning in rather than turn it off
"@typescript-eslint/non-nullable-type-assertion-style": [
"error"
],
// Require each enum member value to be explicitly initialized. Changing the order of implicit enum values may cause errors
"@typescript-eslint/prefer-enum-initializers": [
"error"
],
// Enforce .includes method over .indexOf method for strings and arrays
"@typescript-eslint/prefer-includes": [
"warn"
],
// Prefer the nullish coalescing operator over logical chaining
// well, turns out this is a real PITA, there are a TON of valid reasons to use logical chaining
"@typescript-eslint/prefer-nullish-coalescing": [
"off"
],
// Enforce using type parameter when calling Array#reduce instead of casting. This is a relatively unknown solution but a very elegant one
"@typescript-eslint/prefer-reduce-type-parameter": [
"error"
],
// Enforce using .startsWith and .endsWith over other equivalent methods of checking substrings
"@typescript-eslint/prefer-string-starts-ends-with": [
"warn"
],
// The @ts-expect-error directive operates in the same manner as @ts-ignore, but will error if the line it's meant to be suppressing doesn't actually contain an error, making it a lot safer
"@typescript-eslint/prefer-ts-expect-error": [
"warn"
],
"@typescript-eslint/no-namespace": [
"warn",
{
"allowDeclarations": true
}
],
// Require or disallow spacing between function identifiers and their invocations.
"@typescript-eslint/func-call-spacing": [
"warn"
],
// Allow the generic function type to be used in type-helpers.ts functions
"@typescript-eslint/ban-types": [
"error",
{
"types": {
"{}": false
},
"extendDefaults": true
}
],
"@typescript-eslint/no-unnecessary-type-assertion": [
"error"
],
"@typescript-eslint/await-thenable": [
"error"
],
"@typescript-eslint/no-floating-promises": [
"error"
],
"@typescript-eslint/no-misused-promises": [
"error"
],
"@typescript-eslint/no-for-in-array": [
"error"
],
"@typescript-eslint/unbound-method": [
"error"
]
}
}
],
"rules": {
// Enforce return statements in callbacks of array methods. forEach() should be used if void is returned
"array-callback-return": [
"error",
{
"checkForEach": false
}
],
// Using a single import statement per module will make the code clearer because you can see everything being imported from that module on one line
"no-duplicate-imports": [
"error"
],
// Doing this is a little silly: if (x === x) {}
"no-self-compare": [
"error"
],
// Error prone: if (foo) foo++; Explicit: if (foo) { foo++; }
"curly": [
"error"
],
// Fall-through from the default case in a switch statement is almost always an error
"default-case-last": [
"warn"
],
// Disallow default function params placed before non-default
"default-param-last": [
"error"
],
// Require the use of === and !==
"eqeqeq": [
"error"
],
// Disallow function declarations that contain unsafe references inside loop statements. This is only a problem when using var
"no-loop-func": [
"error"
],
// An unused expression which has no effect on the state of the program indicates a logic error
"no-unused-expressions": [
"error"
],
// Require using arrow functions for callbacks
"prefer-arrow-callback": [
"error"
],
// Enforce consistent spacing after the // or /* in a comment
"spaced-comment": [
"error",
"always"
],
// Prefer color === "red" instead of "red" === color, except in ranges, for example: 0 < x && x < 1
"yoda": [
"error",
"never",
{
"exceptRange": true
}
],
"no-empty": [
"error",
{
"allowEmptyCatch": true
}
],
/*
Formatting rules
*/
"arrow-spacing": [
"error"
],
"block-spacing": [
"error"
],
"brace-style": [
"error"
],
// some typescript syntax clashes with this, so there is a dedicated TS rule above
"func-call-spacing": [
"off"
],
"indent": [
"error",
2,
{
"SwitchCase": 1
}
],
"key-spacing": [
"error"
],
"keyword-spacing": [
"error"
],
"no-multi-spaces": [
"error"
],
"no-trailing-spaces": [
"error",
{
"ignoreComments": true
}
],
"object-property-newline": [
"error",
{
"allowAllPropertiesOnSameLine": true
}
],
"operator-linebreak": [
"error",
"before"
],
"rest-spread-spacing": [
"error"
],
"semi": [
"error",
"always"
],
"semi-spacing": [
"error",
{
"before": false,
"after": true
}
],
"space-before-blocks": [
"error"
],
"space-in-parens": [
"error",
"never"
],
"space-infix-ops": [
"error"
],
"template-curly-spacing": [
"error",
"never"
]
},
"ignorePatterns": [
"tests/*",
"dist/*"
]
}