This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eslintrc.js
444 lines (441 loc) · 16.2 KB
/
.eslintrc.js
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
// https://github.com/andreashuber69/net-worth#--
module.exports = {
env: {
browser: true,
es2017: true,
},
extends: [
"eslint:all",
"plugin:@typescript-eslint/all",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
sourceType: "module",
},
plugins: [
"@typescript-eslint",
"import",
"jsdoc",
"no-null",
"prefer-arrow",
],
root: true,
rules: {
"array-element-newline": [
"error",
"consistent",
],
"@typescript-eslint/array-type": [
"error",
{
default: "array-simple",
},
],
"brace-style": "off",
"@typescript-eslint/brace-style": [
"error",
"1tbs",
{
allowSingleLine: true,
},
],
// Turned off in favor of @typescript-eslint/naming-convention
"camelcase": "off",
"capitalized-comments": [
"error",
"always",
{
ignoreConsecutiveComments: true,
ignoreInlineComments: true,
ignorePattern: "cSpell|codebeat",
},
],
// We want to use the most appropriate style for each property.
"@typescript-eslint/class-literal-property-style": "off",
"comma-dangle": "off",
"@typescript-eslint/comma-dangle": [
"error",
"always-multiline",
],
"@typescript-eslint/consistent-type-assertions": [
"error",
{
assertionStyle: "as",
objectLiteralTypeAssertions: "never",
},
],
"@typescript-eslint/consistent-type-definitions": "off", // We want to use both interfaces and types.
// cSpell: ignore eqeqeq
"eqeqeq": [
"error",
"always",
],
// Leads to a lot of duplication without clear advantages. If types are necessary for documentation purposes,
// @typescript-eslint/explicit-module-boundary-types would be preferable.
"@typescript-eslint/explicit-function-return-type": "off",
// Could make sense for larger projects with multiple developers, seems overkill for small projects.
"@typescript-eslint/explicit-module-boundary-types": "off",
"function-call-argument-newline": [
"error",
"consistent",
],
"function-paren-newline": [
"error",
"multiline-arguments",
],
"id-blacklist": "off", // Often, e.g. "error" is a perfectly acceptable identifier.
"id-length": "off", // Seems too restrictive, sometimes one character is enough (e.g. for inline arrows).
"import/default": "off", // Already covered by typescript.
// cSpell: ignore chunkname
"import/dynamic-import-chunkname": "error",
"import/export": "off", // Already covered by typescript.
"import/exports-last": "error",
"import/extensions": [
"error",
{
json: "always",
schema: "always",
},
],
"import/first": "error",
// There are advantages and disadvantages to turning this on or off. "off" seems the better choice.
"import/group-exports": "off",
"import/max-dependencies": [
"error",
{
max: 30,
},
],
"import/named": "off", // Already covered by typescript.
"import/namespace": "off", // Already covered by typescript.
"import/newline-after-import": "error",
"import/no-absolute-path": "error",
"import/no-amd": "error",
"import/no-anonymous-default-export": [
"error",
{
allowArray: false,
allowArrowFunction: false,
allowAnonymousClass: false,
allowAnonymousFunction: false,
allowCallExpression: false,
allowLiteral: false,
allowObject: false,
},
],
"import/no-commonjs": "error",
"import/no-cycle": "error",
"import/no-default-export": "error",
"import/no-deprecated": "error",
"import/no-duplicates": "error",
"import/no-dynamic-require": "error",
"import/no-extraneous-dependencies": "error",
"import/no-internal-modules": "off", // Seems too restrictive.
"import/no-mutable-exports": "error",
"import/no-named-as-default": "error",
"import/no-named-as-default-member": "error",
"import/no-named-default": "error",
"import/no-named-export": "off", // Does not make sense.
"import/no-namespace": "error",
"import/no-nodejs-modules": "error",
"import/no-relative-parent-imports": "off", // Seems too restrictive.
"import/no-restricted-paths": "off", // Seems too restrictive.
"import/no-self-import": "error",
"import/no-unassigned-import": "error",
"import/no-unresolved": "off", // Already covered by typescript.
"import/no-unused-modules": "error",
"import/no-useless-path-segments": "error",
"import/no-webpack-loader-syntax": "error",
"import/order": [
"error",
{
alphabetize: {
order: "asc",
caseInsensitive: true,
},
},
],
"import/prefer-default-export": "off", // Does not make much sense.
"import/unambiguous": "error",
"indent": "off",
// Was turned off in favor of @typescript-eslint/init-declarations (which is turned on with default settings).
"init-declarations": "off",
"@typescript-eslint/indent": [
"error",
4,
{
SwitchCase: 1,
},
],
"jsdoc/check-alignment": "warn",
"jsdoc/check-examples": "warn",
"jsdoc/check-indentation": [
"warn",
{
excludeTags: ["description"],
},
],
"jsdoc/check-param-names": "warn",
"jsdoc/check-syntax": "warn",
"jsdoc/check-tag-names": [
"warn",
{
definedTags: ["internal", "maximum", "minimum", "multipleOf"],
},
],
"jsdoc/check-types": "warn",
"jsdoc/match-description": "warn",
"jsdoc/newline-after-description": "warn",
"jsdoc/no-types": "warn",
"jsdoc/require-description-complete-sentence": "warn",
"jsdoc/require-param-description": "warn",
"jsdoc/require-param-name": "warn",
"jsdoc/require-returns-check": "warn",
"jsdoc/require-returns-description": "warn",
"jsdoc/valid-types": "warn",
"line-comment-position": "off", // We want to allow comments above and beside code.
// Does not work with interfaces, see https://github.com/typescript-eslint/typescript-eslint/issues/1150
"lines-around-comment": "off",
"lines-between-class-members": "off",
"@typescript-eslint/lines-between-class-members": [
"error",
"always",
{
exceptAfterSingleLine: true,
},
],
"max-len": [
"error",
{
code: 120,
},
],
"max-lines": [
"error",
1000,
],
"max-lines-per-function": "off", // Does not make much sense for describe-style tests.
"max-params": "off",
"max-statements": "off", // Does not make much sense for describe-style tests.
"@typescript-eslint/member-ordering": [
"error",
{
default: [
"signature",
"public-static-field",
"public-static-method",
"public-field",
"public-constructor",
"public-method",
"protected-static-field",
"protected-static-method",
"protected-field",
"protected-constructor",
"protected-method",
"private-static-field",
"private-static-method",
"private-field",
"private-constructor",
"private-method",
],
},
],
"multiline-comment-style": [
"error",
"separate-lines",
],
"multiline-ternary": [
"error",
"always-multiline",
],
"@typescript-eslint/naming-convention": [
"error",
{
selector: "default",
format: ["camelCase"], // TODO: Try to make this strict
leadingUnderscore: "forbid",
trailingUnderscore: "forbid",
},
{
selector: ["typeLike", "enumMember"],
format: ["PascalCase"], // TODO: Try to make this strict
leadingUnderscore: "forbid",
trailingUnderscore: "forbid",
},
{
selector: "interface",
format: ["PascalCase"], // TODO: Try to make this strict
custom: {
regex: "^I[A-Z]",
match: true,
},
leadingUnderscore: "forbid",
trailingUnderscore: "forbid",
},
],
// Typescript ensures that constructor functions are only called with new, so the convention is not necessary.
"new-cap": "off",
"newline-per-chained-call": "off", // This rule seems too restrictive.
// This isn't particularly helpful. For example, the runtime type implementing the Error interface will almost
// always have a meaningful implementation for toString(), yet calls to toString() on that interface are all
// flagged with this error.
"@typescript-eslint/no-base-to-string": "off",
// Typescript already catches many of the bugs that this rule would because bitwise operators are not allowed
// for booleans.
"no-bitwise": "off",
"@typescript-eslint/no-confusing-void-expression": [
"error",
{
ignoreVoidOperator: true,
},
],
"no-console": "off", // Does not make sense for my projects
"no-extra-parens": "off", // Was turned off in favor of no-mixed-operators.
"@typescript-eslint/no-extra-parens": "off", // Was turned off in favor of no-mixed-operators.
"@typescript-eslint/no-extraneous-class": [
"error",
{
allowStaticOnly: true,
},
],
"no-inline-comments": "off", // We want to allow inline comments.
// Does not work for all cases in typescript https://github.com/typescript-eslint/typescript-eslint/issues/491.
"no-invalid-this": "off",
"no-magic-numbers": "off", // Makes sense but appears to be too restrictive.
"@typescript-eslint/no-magic-numbers": "off", // Makes sense but appears to be too restrictive.
"no-null/no-null": "error",
"@typescript-eslint/no-parameter-properties": "off", // The value of this rule seems dubious at best.
// cSpell: ignore plusplus
// Most of the problems with the ++ and -- operators are avoided because we've turned on
// @typescript-eslint/semi.
"no-plusplus": "off",
// The following would make promise construction much more verbose for avoiding a bug that is easily detected.
"no-promise-executor-return": "off",
"no-restricted-syntax": [
"error",
"ForInStatement",
],
"no-return-await": "off", // Turned off in favor of @typescript-eslint/return-await
"no-shadow": "off",
"@typescript-eslint/no-shadow": [
"error",
{
hoist: "all",
},
],
"no-ternary": "off",
"@typescript-eslint/no-type-alias": "off", // Does not make much sense.
"no-undef": "off", // Does not make sense with typescript-only code.
// Does not make sense for js code >= ES5 with no-global-assign and no-shadow-restricted-names turned on.
"no-undefined": "off",
"@typescript-eslint/no-unnecessary-condition": "off", // Flags expressions like `... || "Error"`.
"@typescript-eslint/no-unused-vars-experimental": "off", // Turned off in favor of no-unused-vars.
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": [
"error",
{
functions: false,
// cSpell: ignore typedefs
typedefs: false,
enums: false,
},
],
// Was turned off in favor of @typescript-eslint/no-useless-constructor (which is turned on with default
// settings).
"no-useless-constructor": "off",
// We use void to avoid @typescript-eslint/no-confusing-void-expression
"no-void": "off",
// cSpell: ignore todos
"no-warning-comments": "off", // Turn this on after tackling TODOs ;-)?.
"object-curly-spacing": "off",
"@typescript-eslint/object-curly-spacing": [
"error",
"always",
],
"object-property-newline": [
"error",
{
allowAllPropertiesOnSameLine: true,
},
],
"one-var": "off", // Does not seem to work with const and let?
// cSpell: ignore linebreak
"operator-linebreak": [
"error",
"after",
],
"padded-blocks": [
"error",
"never",
],
"padding-line-between-statements": [
"error",
{
blankLine: "always",
prev: "*",
next: "return",
},
// TODO: Configure to match code style
],
"@typescript-eslint/prefer-enum-initializers": "off", // Implictly defined values should be common knowledge
"prefer-arrow/prefer-arrow-functions": [
"error",
{
disallowPrototype: true,
singleReturnOnly: false,
classPropertiesAllowed: false,
},
],
// TODO: This doesn't seem to work correctly yet
"@typescript-eslint/prefer-readonly-parameter-types": "off",
"quote-props": [
"error",
"consistent-as-needed",
],
"quotes": "off", // Turned off in favor of @typescript-eslint/quotes (which is turned on with default settings)
"@typescript-eslint/restrict-template-expressions": "off", // The advantages are unclear.
"@typescript-eslint/return-await": [
"error",
"always",
],
"semi": "off", // Turned off in favor of @typescript-eslint/semi (which is turned on with default settings)
"sort-imports": [
"error",
{
ignoreCase: true,
ignoreDeclarationSort: true,
},
],
"sort-keys": "off",
"space-before-function-paren": "off",
"@typescript-eslint/space-before-function-paren": [
"error",
{
anonymous: "never",
named: "never",
asyncArrow: "always",
},
],
"space-in-parens": [
"error",
"never",
],
"spaced-comment": [
"error",
"always",
{
exceptions: ["/"],
},
],
"@typescript-eslint/strict-boolean-expressions": "off", // Takes away too much expressive power.
// Value is questionable, see
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/typedef.md
"@typescript-eslint/typedef": "off",
},
settings: {
jsdoc: {
mode: "typescript",
},
},
};