-
Notifications
You must be signed in to change notification settings - Fork 65
/
index.js
423 lines (399 loc) · 17.5 KB
/
index.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
const fs = require('fs')
const path = require('path')
/**
* @see https://github.com/eslint/eslint/issues/3458
* @see https://www.npmjs.com/package/@rushstack/eslint-patch
*/
require('@rushstack/eslint-patch/modern-module-resolution')
const tsConfig = fs.existsSync('tsconfig.json')
? path.resolve('tsconfig.json')
: fs.existsSync('types/tsconfig.json')
? path.resolve('types/tsconfig.json')
: undefined
module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
extends: ['prettier', './import.js'],
rules: {
'accessor-pairs': 'error',
'array-callback-return': 'error',
'arrow-body-style': 'off',
'block-scoped-var': 'error',
camelcase: 'off', // annoying to disable...
'capitalized-comments': 'off', // wHO CaRes?
'class-methods-use-this': 'off', // three words: "componentDidMount" :)
complexity: ['error', 20],
'consistent-return': 'error',
'consistent-this': 'off', // Too many use-cases for reassigning "this" to different values
'constructor-super': 'error',
curly: ['error', 'multi-line'],
'default-case': 'error',
'default-case-last': 'error',
'default-param-last': 'off',
'dot-notation': 'error',
eqeqeq: 'off',
'for-direction': 'error',
'func-name-matching': 'error',
'func-names': 'error',
'func-style': 'off',
'getter-return': ['error', {allowImplicit: true}],
'grouped-accessor-pairs': 'off',
'guard-for-in': 'error',
'id-denylist': 'error',
'id-length': 'off', // when using short composable functions, using single-letter variables is fine
'id-match': [
'error',
// camelCase, PascalCase, __filename, CONST_VALUE, stream$, $el
'^\\$?(__)?(([A-Z]|[a-z]|[0-9]+)|([A-Z_]))*\\$?$',
],
'init-declarations': 'off',
'line-comment-position': 'off',
'logical-assignment-operators': 'warn',
'max-classes-per-file': 'off',
'max-depth': ['error', 4],
'max-lines': [
'error',
{max: 2500, skipBlankLines: false, skipComments: false},
],
'max-lines-per-function': 'off', // this becomes an obvious problem when it's actually a problem...
'max-nested-callbacks': ['error', 7],
'max-params': ['error', 7],
'max-statements': 'off', // this becomes an obvious problem when it's actually a problem...
'multiline-comment-style': 'off', // this would be cool to get the fixer, but too strict.
'new-cap': 'error',
'no-alert': 'error',
'no-array-constructor': 'error',
'no-async-promise-executor': 'off',
'no-await-in-loop': 'error',
'no-bitwise': 'error',
'no-caller': 'error',
'no-case-declarations': 'error',
'no-class-assign': 'error',
'no-compare-neg-zero': 'error',
'no-cond-assign': 'error',
'no-console': 'off',
'no-const-assign': 'error',
'no-constant-binary-expression': 'error',
'no-constant-condition': 'error',
'no-constructor-return': 'error',
'no-continue': 'off',
'no-control-regex': 'error',
'no-debugger': 'error',
'no-delete-var': 'error',
'no-div-regex': 'error',
'no-dupe-args': 'error',
'no-dupe-class-members': 'error',
'no-dupe-else-if': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-duplicate-imports': 'off', // turned off in favor of `import/no-duplicates`
'no-else-return': 'off',
'no-empty': 'error',
'no-empty-character-class': 'error',
'no-empty-function': 'off', // we're all grown ups here...
'no-empty-pattern': 'error',
'no-empty-static-block': 'error',
'no-eq-null': 'off',
'no-eval': 'error',
'no-ex-assign': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-extra-boolean-cast': 'off',
'no-extra-label': 'error',
'no-fallthrough': 'error',
'no-func-assign': 'error',
'no-global-assign': 'error',
'no-implicit-coercion': 'off',
'no-implicit-globals': 'error',
'no-implied-eval': 'error',
'no-import-assign': 'error',
'no-inline-comments': 'off',
'no-inner-declarations': 'error',
'no-invalid-regexp': 'error',
'no-invalid-this': 'error',
'no-irregular-whitespace': 'error',
'no-iterator': 'error',
'no-label-var': 'error',
'no-labels': 'error',
'no-lone-blocks': 'error',
'no-lonely-if': 'error',
'no-loop-func': 'error',
'no-loss-of-precision': 'error',
'no-magic-numbers': 'off', // sometimes this is ok (foo.length - 1 == index of last one)
'no-misleading-character-class': 'off',
'no-multi-assign': 'error', // it's handy, but harder to read
'no-multi-str': 'error',
'no-negated-condition': 'error',
'no-nested-ternary': 'off',
'no-new': 'error',
'no-new-func': 'error',
'no-new-native-nonconstructor': 'error',
'no-new-symbol': 'error',
'no-new-wrappers': 'error',
'no-nonoctal-decimal-escape': 'error',
'no-object-constructor': 'error',
'no-obj-calls': 'error',
'no-octal': 'error',
'no-octal-escape': 'error',
'no-param-reassign': 'off',
'no-plusplus': 'off',
'no-promise-executor-return': 'off', // prevents: new Promise(r => setTimeout(r))
'no-proto': 'error',
'no-prototype-builtins': 'off',
'no-redeclare': 'error',
'no-regex-spaces': 'error',
'no-restricted-exports': 'off', // not applicable for a config preset (should be configured only in projects)
'no-restricted-globals': ['error', 'event', 'fdescribe'],
'no-restricted-imports': 'off', // not applicable for a config preset (should be configured only in projects)
'no-restricted-properties': 'off', // no ideas of what to disallow right now...
'no-restricted-syntax': ['error', 'WithStatement'],
'no-return-assign': 'error',
'no-script-url': 'error',
'no-self-assign': 'error',
'no-self-compare': 'error',
'no-sequences': 'error',
'no-setter-return': 'error',
'no-shadow': 'error',
'no-shadow-restricted-names': 'error',
'no-sparse-arrays': 'error',
'no-template-curly-in-string': 'error',
'no-ternary': 'off',
'no-this-before-super': 'error',
'no-throw-literal': 'error',
'no-undef': 'error',
'no-undef-init': 'error',
'no-undefined': 'off',
'no-underscore-dangle': 'off',
'no-unmodified-loop-condition': 'error',
'no-unneeded-ternary': 'error',
'no-unreachable': 'error',
'no-unreachable-loop': 'error',
'no-unsafe-finally': 'error',
'no-unsafe-negation': 'error',
'no-unsafe-optional-chaining': 'error',
'no-unused-expressions': 'off',
'no-unused-labels': 'error',
'no-unused-private-class-members': 'error',
'no-unused-vars': [
'error',
{
args: 'after-used',
argsIgnorePattern: '^_',
ignoreRestSiblings: true,
varsIgnorePattern: '^ignored',
},
],
'no-use-before-define': ['error', 'nofunc'],
'no-useless-backreference': 'error',
'no-useless-call': 'error',
'no-useless-catch': 'error',
'no-useless-computed-key': 'error',
'no-useless-concat': 'error',
'no-useless-constructor': 'error',
'no-useless-escape': 'error',
'no-useless-rename': 'error',
'no-useless-return': 'error',
'no-var': 'error',
'no-void': 'off',
'no-warning-comments': ['error', {location: 'anywhere', terms: ['fixme']}],
'no-with': 'off',
'object-shorthand': ['error', 'properties'], // methods are optional so you can specify a name if you want
'one-var': ['error', {initialized: 'never', uninitialized: 'always'}],
'operator-assignment': 'off', // readability on a case-by-case basis
'prefer-arrow-callback': [
'error',
{allowNamedFunctions: true, allowUnboundThis: true},
],
'prefer-const': 'error',
'prefer-destructuring': 'off', // nah, I like it, but not that much...
'prefer-exponentiation-operator': 'warn',
'prefer-named-capture-group': 'off', // maybe one day... But I'm not used to it yet.
'prefer-numeric-literals': 'error',
'prefer-object-has-own': 'error',
'prefer-object-spread': 'warn',
'prefer-promise-reject-errors': 'off', // maybe one day... Not sure I'm in...
'prefer-regex-literals': 'off',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'prefer-template': 'error',
radix: 'error',
'require-atomic-updates': 'off',
'require-await': 'off',
'require-unicode-regexp': 'off',
'require-yield': 'error',
'sort-imports': 'off',
'sort-keys': 'off',
'sort-vars': 'off',
strict: 'error',
'symbol-description': 'error',
'use-isnan': 'error',
'unicode-bom': ['error', 'never'],
'valid-typeof': 'error',
'vars-on-top': 'error',
yoda: 'error',
},
overrides: [
{
files: ['**/*.ts?(x)'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
project: tsConfig,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
rules: {
'constructor-super': 'off', // ts(2335) & ts(2377)
'getter-return': 'off', // ts(2378)
'no-const-assign': 'off', // ts(2588)
'no-dupe-args': 'off', // ts(2300)
'no-dupe-keys': 'off', // ts(1117)
'no-func-assign': 'off', // ts(2539)
'no-import-assign': 'off', // ts(2539) & ts(2540)
'no-new-symbol': 'off', // ts(2588)
'no-obj-calls': 'off', // ts(2349)
'no-setter-return': 'off', // ts(2408)
'no-this-before-super': 'off', // ts(2376)
'no-undef': 'off', // ts(2304)
'no-unreachable': 'off', // ts(7027)
'no-unsafe-negation': 'off', // ts(2365) & ts(2360) & ts(2358)
'valid-typeof': 'off', // ts(2367)
'consistent-return': 'off', // in TS this is much less an issue
'no-var': 'error', // TS transpiles let/const to var, so no need for vars any more
'prefer-const': 'error', // TS provides better types with const
'prefer-rest-params': 'error', // TS provides better types with rest args over arguments
'prefer-spread': 'error', // TS transpiles spread to apply, so no need for manual apply
'default-param-last': 'off',
'@typescript-eslint/default-param-last': 'off',
'dot-notation': 'off',
'@typescript-eslint/dot-notation': 'error',
'init-declarations': 'off',
'@typescript-eslint/init-declarations': 'off',
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': 'error',
'no-dupe-class-members': 'off',
'@typescript-eslint/no-dupe-class-members': 'off', // ts(2393) & ts(2300)
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': 'off',
'no-implied-eval': 'error',
'@typescript-eslint/no-implied-eval': 'error',
'no-invalid-this': 'off',
'@typescript-eslint/no-invalid-this': 'error',
'no-loop-func': 'off',
'@typescript-eslint/no-loop-func': 'error',
'no-loss-of-precision': 'off',
'@typescript-eslint/no-loss-of-precision': 'error',
'no-magic-numbers': 'off',
'@typescript-eslint/no-magic-numbers': 'off',
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': 'off', // ts(2451)
'no-return-await': 'off',
'@typescript-eslint/return-await': 'error',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'no-throw-literal': 'off',
'@typescript-eslint/no-throw-literal': 'error',
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': ['error', 'nofunc'],
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'after-used',
argsIgnorePattern: '^_',
ignoreRestSiblings: true,
varsIgnorePattern: '^ignored',
},
],
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/ban-tslint-comment': 'error',
'@typescript-eslint/ban-types': 'off', // not useful in a reusable config
'@typescript-eslint/class-literal-property-style': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/consistent-type-imports': 'off', // I think I prefer typed imports, but you can't always use them
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/member-delimiter-style': 'off',
'@typescript-eslint/member-ordering': 'off',
'@typescript-eslint/method-signature-style': 'off',
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/no-base-to-string': 'warn',
'@typescript-eslint/no-confusing-non-null-assertion': 'off', // prettier reformats their "correct" example anyway 🤷♂️
'@typescript-eslint/no-confusing-void-expression': 'off', // honestly, it's probably a good rule, but I do this all the time so...
'@typescript-eslint/no-dynamic-delete': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-extra-non-null-assertion': 'error',
'@typescript-eslint/no-extraneous-class': 'error', // stay away from classes when you can
'@typescript-eslint/no-floating-promises': 'warn', // not a bad rule, but can be annoying
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-inferrable-types': 'off', // I personally prefer relying on inference where possible, but I don't want to lint for it.
'@typescript-eslint/no-invalid-void-type': 'warn',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-misused-promises': [
'warn',
{checksVoidReturn: false},
],
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-require-imports': 'off', // sometimes you can't do it any other way
'@typescript-eslint/no-this-alias': 'error',
'@typescript-eslint/no-type-alias': 'off',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'warn',
'@typescript-eslint/no-unnecessary-condition': 'error',
'@typescript-eslint/no-unnecessary-qualifier': 'warn', // I'm not sure I understand this one
'@typescript-eslint/no-unnecessary-type-arguments': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
'@typescript-eslint/no-unsafe-argument': 'error',
'@typescript-eslint/no-unsafe-assignment': 'warn', // seems like an ok idea, but I don't have enough experience with TS yet.
'@typescript-eslint/no-unsafe-call': 'warn', // seems like an ok idea, but I don't have enough experience with TS yet.
'@typescript-eslint/no-unsafe-member-access': 'warn', // seems like an ok idea, but I don't have enough experience with TS yet.
'@typescript-eslint/no-unsafe-return': 'off', // seems like an ok idea, but it failed on a regular React Component
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/non-nullable-type-assertion-style': 'off',
'@typescript-eslint/parameter-properties': 'error',
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/prefer-enum-initializers': 'error', // makes total sense
'@typescript-eslint/prefer-for-of': 'off', // I prefer for of, but I don't want to lint for it
'@typescript-eslint/prefer-function-type': 'off', // though I'm not sure I understand it
'@typescript-eslint/prefer-includes': 'error', // normally I wouldn't but includes is just so much better
'@typescript-eslint/prefer-literal-enum-member': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-readonly': 'off',
'@typescript-eslint/prefer-readonly-parameter-types': 'off',
'@typescript-eslint/prefer-reduce-type-parameter': 'warn',
'@typescript-eslint/prefer-regexp-exec': 'off',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/promise-function-async': 'off',
'@typescript-eslint/require-array-sort-compare': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/sort-type-union-intersection-members': 'off',
'@typescript-eslint/strict-boolean-expressions': 'off',
'@typescript-eslint/switch-exhaustiveness-check': 'error',
'@typescript-eslint/triple-slash-reference': 'error',
'@typescript-eslint/typedef': 'off',
'@typescript-eslint/unbound-method': 'error',
'@typescript-eslint/unified-signatures': 'warn',
},
},
],
}