-
Notifications
You must be signed in to change notification settings - Fork 609
/
Copy pathindex.js
781 lines (662 loc) · 35.9 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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
const macros = require('./macros');
// Rule severity guidelines
// ------------------------
//
// Errors are generally printed in red, and may prevent other build tasks from running (e.g. unit tests).
// Developers should never ignore errors. Warnings are generally printed in yellow, and do not block local
// development, although they must be fixed/suppressed before merging. Developers will commonly ignore warnings
// until their feature is working.
//
// Rules that should be a WARNING:
// - An issue that is very common in partially implemented work (e.g. missing type declaration)
// - An issue that "keeps things nice" but otherwise doesn't affect the meaning of the code (e.g. naming convention)
// - Security rules -- developers may need to temporarily introduce "insecure" expressions while debugging;
// if our policy forces them to suppress the lint rule, they may forget to reenable it later.
//
// Rules that should be an ERROR:
// - An issue that is very likely to be a typo (e.g. "x = x;")
// - An issue that catches code that is likely to malfunction (e.g. unterminated promise chain)
// - An obsolete language feature that nobody should be using for any good reason
module.exports = {
// Disable the parser by default
parser: '',
plugins: [
'@rushstack/eslint-plugin',
'@typescript-eslint/eslint-plugin',
'eslint-plugin-promise',
'eslint-plugin-security',
'eslint-plugin-tsdoc'
],
overrides: [
{
// Declare an override that applies to TypeScript files only
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
parserOptions: {
// The "project" path is resolved relative to parserOptions.tsconfigRootDir.
// Your local .eslintrc.js must specify that parserOptions.tsconfigRootDir=__dirname.
project: './tsconfig.json',
// Allow parsing of newer ECMAScript constructs used in TypeScript source code. Although tsconfig.json
// may allow only a small subset of ES2018 features, this liberal setting ensures that ESLint will correctly
// parse whatever is encountered.
ecmaVersion: 2018,
sourceType: 'module'
},
rules: {
// The @rushstack rules are documented in the package README:
// https://www.npmjs.com/package/@rushstack/eslint-plugin
// RATIONALE: See the @rushstack/eslint-plugin documentation
'@rushstack/no-new-null': 'warn',
// RATIONALE: See the @rushstack/eslint-plugin documentation
// This is enabled and classified as an error because it is required when using Heft.
// It's not required when using ts-jest, but still a good practice.
'@rushstack/hoist-jest-mock': 'error',
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/adjacent-overload-signatures': 'warn',
// RATIONALE: We require "string[]" (instead of "Array<string>") because it is idiomatic TypeScript.
// We require "ReadonlyArray<string>" (instead of "readonly string[]") because, although
// the latter form is nicer, it is not supported by TypeScript version prior to 3.4.
// It can be expensive to upgrade a large code base to use the latest compiler, so our
// lint rules should not require usage of bleeding edge language features. In the future
// when TypeScript 3 is obsolete, we'll change this rule to require "readonly string[]".
'@typescript-eslint/array-type': [
'warn',
{
default: 'array',
readonly: 'generic'
}
],
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
//
// CONFIGURATION: By default, these are banned: String, Boolean, Number, Object, Symbol
'@typescript-eslint/ban-types': [
'warn',
{
extendDefaults: false, // (the complete list is in this file)
types: {
String: {
message: 'Use "string" instead',
fixWith: 'string'
},
Boolean: {
message: 'Use "boolean" instead',
fixWith: 'boolean'
},
Number: {
message: 'Use "number" instead',
fixWith: 'number'
},
Object: {
message: 'Use "object" instead, or else define a proper TypeScript type:'
},
Symbol: {
message: 'Use "symbol" instead',
fixWith: 'symbol'
},
Function: {
message: [
'The "Function" type accepts any function-like value.',
'It provides no type safety when calling the function, which can be a common source of bugs.',
'It also accepts things like class declarations, which will throw at runtime as they will not be called with "new".',
'If you are expecting the function to accept certain arguments, you should explicitly define the function shape.'
].join('\n')
}
// This is a good idea, but before enabling it we need to put some thought into the recommended
// coding practices; the default suggestions are too vague.
//
// '{}': {
// message: [
// '"{}" actually means "any non-nullish value".',
// '- If you want a type meaning "any object", you probably want "Record<string, unknown>" instead.',
// '- If you want a type meaning "any value", you probably want "unknown" instead.'
// ].join('\n')
// }
}
}
],
// RATIONALE: We require "x as number" instead of "<number>x" to avoid conflicts with JSX.
'@typescript-eslint/consistent-type-assertions': 'warn',
// RATIONALE: We prefer "interface IBlah { x: number }" over "type Blah = { x: number }"
// because code is more readable when it is built from stereotypical forms
// (interfaces, enums, functions, etc.) instead of freeform type algebra.
'@typescript-eslint/consistent-type-definitions': 'warn',
// RATIONALE: Code is more readable when the type of every variable is immediately obvious.
// Even if the compiler may be able to infer a type, this inference will be unavailable
// to a person who is reviewing a GitHub diff. This rule makes writing code harder,
// but writing code is a much less important activity than reading it.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/explicit-function-return-type': [
'warn',
{
allowExpressions: true,
allowTypedFunctionExpressions: true,
allowHigherOrderFunctions: false
}
],
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/explicit-member-accessibility': 'warn',
// RATIONALE: Object-oriented programming organizes code into "classes" that associate
// data structures (the class's fields) and the operations performed on those
// data structures (the class's members). Studying the fields often reveals the "idea"
// behind a class. The choice of which class a field belongs to may greatly impact
// the code readability and complexity. Thus, we group the fields prominently at the top
// of the class declaration. We do NOT enforce sorting based on public/protected/private
// or static/instance, because these designations tend to change as code evolves, and
// reordering methods produces spurious diffs that make PRs hard to read. For classes
// with lots of methods, alphabetization is probably a more useful secondary ordering.
'@typescript-eslint/member-ordering': [
'warn',
{
default: 'never',
classes: ['field', 'constructor', 'method']
}
],
// NOTE: This new rule replaces several deprecated rules from @typescript-eslint/eslint-plugin@2.3.3:
//
// - @typescript-eslint/camelcase
// - @typescript-eslint/class-name-casing
// - @typescript-eslint/interface-name-prefix
// - @typescript-eslint/member-naming
//
// Docs: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md
'@typescript-eslint/naming-convention': [
'warn',
...macros.expandNamingConventionSelectors([
{
// We should be stricter about 'enumMember', but it often functions legitimately as an ad hoc namespace.
selectors: ['variable', 'enumMember', 'function'],
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
leadingUnderscore: 'allow',
filter: {
regex: [
// This is a special exception for naming patterns that use an underscore to separate two camel-cased
// parts. Example: "checkBox1_onChanged" or "_checkBox1_onChanged"
'^_?[a-z][a-z0-9]*([A-Z][a-z]?[a-z0-9]*)*_[a-z][a-z0-9]*([A-Z][a-z]?[a-z0-9]*)*$'
]
.map((x) => `(${x})`)
.join('|'),
match: false
}
},
{
selectors: ['parameter'],
format: ['camelCase'],
filter: {
regex: [
// Silently accept names with a double-underscore prefix; we would like to be more strict about this,
// pending a fix for https://github.com/typescript-eslint/typescript-eslint/issues/2240
'^__'
]
.map((x) => `(${x})`)
.join('|'),
match: false
}
},
// Genuine properties
{
selectors: ['parameterProperty', 'accessor'],
enforceLeadingUnderscoreWhenPrivate: true,
format: ['camelCase', 'UPPER_CASE'],
filter: {
regex: [
// Silently accept names with a double-underscore prefix; we would like to be more strict about this,
// pending a fix for https://github.com/typescript-eslint/typescript-eslint/issues/2240
'^__',
// Ignore quoted identifiers such as { "X+Y": 123 }. Currently @typescript-eslint/naming-convention
// cannot detect whether an identifier is quoted or not, so we simply assume that it is quoted
// if-and-only-if it contains characters that require quoting.
'[^a-zA-Z0-9_]',
// This is a special exception for naming patterns that use an underscore to separate two camel-cased
// parts. Example: "checkBox1_onChanged" or "_checkBox1_onChanged"
'^_?[a-z][a-z0-9]*([A-Z][a-z]?[a-z0-9]*)*_[a-z][a-z0-9]*([A-Z][a-z]?[a-z0-9]*)*$'
]
.map((x) => `(${x})`)
.join('|'),
match: false
}
},
// Properties that incorrectly match other contexts
// See issue https://github.com/typescript-eslint/typescript-eslint/issues/2244
{
selectors: ['property'],
enforceLeadingUnderscoreWhenPrivate: true,
// The @typescript-eslint/naming-convention "property" selector matches cases like this:
//
// someLegacyApiWeCannotChange.invokeMethod({ SomeProperty: 123 });
//
// and this:
//
// const { CONSTANT1, CONSTANT2 } = someNamespace.constants;
//
// Thus for now "property" is more like a variable than a class member.
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
leadingUnderscore: 'allow',
filter: {
regex: [
// Silently accept names with a double-underscore prefix; we would like to be more strict about this,
// pending a fix for https://github.com/typescript-eslint/typescript-eslint/issues/2240
'^__',
// Ignore quoted identifiers such as { "X+Y": 123 }. Currently @typescript-eslint/naming-convention
// cannot detect whether an identifier is quoted or not, so we simply assume that it is quoted
// if-and-only-if it contains characters that require quoting.
'[^a-zA-Z0-9_]',
// This is a special exception for naming patterns that use an underscore to separate two camel-cased
// parts. Example: "checkBox1_onChanged" or "_checkBox1_onChanged"
'^_?[a-z][a-z0-9]*([A-Z][a-z]?[a-z0-9]*)*_[a-z][a-z0-9]*([A-Z][a-z]?[a-z0-9]*)*$'
]
.map((x) => `(${x})`)
.join('|'),
match: false
}
},
{
selectors: ['method'],
enforceLeadingUnderscoreWhenPrivate: true,
// A PascalCase method can arise somewhat legitimately in this way:
//
// class MyClass {
// public static MyReactButton(props: IButtonProps): JSX.Element {
// . . .
// }
// }
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'allow',
filter: {
regex: [
// Silently accept names with a double-underscore prefix; we would like to be more strict about this,
// pending a fix for https://github.com/typescript-eslint/typescript-eslint/issues/2240
'^__',
// This is a special exception for naming patterns that use an underscore to separate two camel-cased
// parts. Example: "checkBox1_onChanged" or "_checkBox1_onChanged"
'^_?[a-z][a-z0-9]*([A-Z][a-z]?[a-z0-9]*)*_[a-z][a-z0-9]*([A-Z][a-z]?[a-z0-9]*)*$'
]
.map((x) => `(${x})`)
.join('|'),
match: false
}
},
// Types should use PascalCase
{
// Group selector for: class, interface, typeAlias, enum, typeParameter
selectors: ['class', 'typeAlias', 'enum', 'typeParameter'],
format: ['PascalCase'],
leadingUnderscore: 'allow'
},
{
selectors: ['interface'],
// It is very common for a class to implement an interface of the same name.
// For example, the Widget class may implement the IWidget interface. The "I" prefix
// avoids the need to invent a separate name such as "AbstractWidget" or "WidgetInterface".
// In TypeScript it is also common to declare interfaces that are implemented by primitive
// objects, here the "I" prefix also helps by avoiding spurious conflicts with classes
// by the same name.
format: ['PascalCase'],
custom: {
regex: '^_?I[A-Z]',
match: true
}
}
])
],
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-array-constructor': 'warn',
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
//
// RATIONALE: The "any" keyword disables static type checking, the main benefit of using TypeScript.
// This rule should be suppressed only in very special cases such as JSON.stringify()
// where the type really can be anything. Even if the type is flexible, another type
// may be more appropriate such as "unknown", "{}", or "Record<k,V>".
'@typescript-eslint/no-explicit-any': 'warn',
// RATIONALE: The #1 rule of promises is that every promise chain must be terminated by a catch()
// handler. Thus wherever a Promise arises, the code must either append a catch handler,
// or else return the object to a caller (who assumes this responsibility). Unterminated
// promise chains are a serious issue. Besides causing errors to be silently ignored,
// they can also cause a NodeJS process to terminate unexpectedly.
'@typescript-eslint/no-floating-promises': 'error',
// RATIONALE: Catches a common coding mistake.
'@typescript-eslint/no-for-in-array': 'error',
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-misused-new': 'error',
// RATIONALE: The "namespace" keyword is not recommended for organizing code because JavaScript lacks
// a "using" statement to traverse namespaces. Nested namespaces prevent certain bundler
// optimizations. If you are declaring loose functions/variables, it's better to make them
// static members of a class, since classes support property getters and their private
// members are accessible by unit tests. Also, the exercise of choosing a meaningful
// class name tends to produce more discoverable APIs: for example, search+replacing
// the function "reverse()" is likely to return many false matches, whereas if we always
// write "Text.reverse()" is more unique. For large scale organization, it's recommended
// to decompose your code into separate NPM packages, which ensures that component
// dependencies are tracked more conscientiously.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-namespace': [
'warn',
{
// Discourage "namespace" in .ts and .tsx files
allowDeclarations: false,
// Allow it in .d.ts files that describe legacy libraries
allowDefinitionFiles: false
}
],
// RATIONALE: Parameter properties provide a shorthand such as "constructor(public title: string)"
// that avoids the effort of declaring "title" as a field. This TypeScript feature makes
// code easier to write, but arguably sacrifices readability: In the notes for
// "@typescript-eslint/member-ordering" we pointed out that fields are central to
// a class's design, so we wouldn't want to bury them in a constructor signature
// just to save some typing.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-parameter-properties': 'warn',
// RATIONALE: When left in shipping code, unused variables often indicate a mistake. Dead code
// may impact performance.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-unused-vars': [
'warn',
{
vars: 'all',
// Unused function arguments often indicate a mistake in JavaScript code. However in TypeScript code,
// the compiler catches most of those mistakes, and unused arguments are fairly common for type signatures
// that are overriding a base class method or implementing an interface.
args: 'none'
}
],
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/no-use-before-define': 'error',
// TODO: This is a good rule for web browser apps, but it is commonly needed API for Node.js tools.
// '@typescript-eslint/no-var-requires': 'error',
// RATIONALE: The "module" keyword is deprecated except when describing legacy libraries.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/prefer-namespace-keyword': 'warn',
// RATIONALE: We require explicit type annotations, even when the compiler could infer the type.
// This can be a controversial policy because it makes code more verbose. There are
// a couple downsides to type inference, however. First, it is not always available.
// For example, when reviewing a pull request or examining a Git history, we may see
// code like this:
//
// // What is the type of "y" here? The compiler knows, but the
// // person reading the code may have no clue.
// const x = f.();
// const y = x.z;
//
// Second, relying on implicit types also discourages design discussions and documentation.
// Consider this example:
//
// // Where's the documentation for "correlation" and "inventory"?
// // Where would you even write the TSDoc comments?
// function g() {
// return { correlation: 123, inventory: 'xyz' };
// }
//
// Implicit types make sense for small scale scenarios, where everyone is familiar with
// the project, and code should be "easy to write". Explicit types are preferable
// for large scale scenarios, where people regularly work with source files they've never
// seen before, and code should be "easy to read."
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/typedef': [
'warn',
{
arrayDestructuring: false,
arrowParameter: false,
memberVariableDeclaration: true,
objectDestructuring: false,
parameter: true,
propertyDeclaration: true,
variableDeclaration: true,
// Normally we require type declarations for class members. However, that rule is relaxed
// for situations where we need to bind the "this" pointer for a callback. For example, consider
// this event handler for a React component:
//
// class MyComponent {
// public render(): React.ReactNode {
// return (
// <a href="#" onClick={this._onClick}> click me </a>
// );
// }
//
// // The assignment here avoids the need for "this._onClick.bind(this)"
// private _onClick = (event: React.MouseEvent<HTMLAnchorElement>): void => {
// console.log("Clicked! " + this.props.title);
// };
// }
//
// This coding style has limitations and should be used sparingly. For example, "_onClick"
// will not participate correctly in "virtual"/"override" inheritance.
variableDeclarationIgnoreFunction: true
}
],
// RATIONALE: This rule warns if setters are defined without getters, which is probably a mistake.
'accessor-pairs': 'error',
// RATIONALE: In TypeScript, if you write x["y"] instead of x.y, it disables type checking.
'dot-notation': [
'warn',
{
allowPattern: '^_'
}
],
// RATIONALE: Catches code that is likely to be incorrect
eqeqeq: 'error',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'for-direction': 'warn',
// RATIONALE: Catches a common coding mistake.
'guard-for-in': 'error',
// RATIONALE: If you have more than 2,000 lines in a single source file, it's probably time
// to split up your code.
'max-lines': ['warn', { max: 2000 }],
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-async-promise-executor': 'error',
// RATIONALE: "|" and "&" are relatively rare, and are more likely to appear as a mistake when
// someone meant "||" or "&&". (But nobody types the other operators by mistake.)
'no-bitwise': [
'warn',
{
allow: [
'^',
// "|",
// "&",
'<<',
'>>',
'>>>',
'^=',
// "|=",
//"&=",
'<<=',
'>>=',
'>>>=',
'~'
]
}
],
// RATIONALE: Deprecated language feature.
'no-caller': 'error',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-compare-neg-zero': 'error',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-cond-assign': 'error',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-constant-condition': 'warn',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-control-regex': 'error',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-debugger': 'warn',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-delete-var': 'error',
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-duplicate-case': 'error',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-empty': 'warn',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-empty-character-class': 'error',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-empty-pattern': 'warn',
// RATIONALE: Eval is a security concern and a performance concern.
'no-eval': 'warn',
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-ex-assign': 'error',
// RATIONALE: System types are global and should not be tampered with in a scalable code base.
// If two different libraries (or two versions of the same library) both try to modify
// a type, only one of them can win. Polyfills are acceptable because they implement
// a standardized interoperable contract, but polyfills are generally coded in plain
// JavaScript.
'no-extend-native': 'error',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-extra-boolean-cast': 'warn',
'no-extra-label': 'warn',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-fallthrough': 'error',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-func-assign': 'warn',
// RATIONALE: Catches a common coding mistake.
'no-implied-eval': 'error',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-invalid-regexp': 'error',
// RATIONALE: Catches a common coding mistake.
'no-label-var': 'error',
// RATIONALE: Eliminates redundant code.
'no-lone-blocks': 'warn',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-misleading-character-class': 'error',
// RATIONALE: Catches a common coding mistake.
'no-multi-str': 'error',
// RATIONALE: It's generally a bad practice to call "new Thing()" without assigning the result to
// a variable. Either it's part of an awkward expression like "(new Thing()).doSomething()",
// or else implies that the constructor is doing nontrivial computations, which is often
// a poor class design.
'no-new': 'warn',
// RATIONALE: Obsolete language feature that is deprecated.
'no-new-func': 'error',
// RATIONALE: Obsolete language feature that is deprecated.
'no-new-object': 'error',
// RATIONALE: Obsolete notation.
'no-new-wrappers': 'warn',
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-octal': 'error',
// RATIONALE: Catches code that is likely to be incorrect
'no-octal-escape': 'error',
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-regex-spaces': 'error',
// RATIONALE: Catches a common coding mistake.
'no-return-assign': 'error',
// RATIONALE: Security risk.
'no-script-url': 'warn',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-self-assign': 'error',
// RATIONALE: Catches a common coding mistake.
'no-self-compare': 'error',
// RATIONALE: This avoids statements such as "while (a = next(), a && a.length);" that use
// commas to create compound expressions. In general code is more readable if each
// step is split onto a separate line. This also makes it easier to set breakpoints
// in the debugger.
'no-sequences': 'error',
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-shadow-restricted-names': 'error',
// RATIONALE: Obsolete language feature that is deprecated.
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-sparse-arrays': 'error',
// RATIONALE: Although in theory JavaScript allows any possible data type to be thrown as an exception,
// such flexibility adds pointless complexity, by requiring every catch block to test
// the type of the object that it receives. Whereas if catch blocks can always assume
// that their object implements the "Error" contract, then the code is simpler, and
// we generally get useful additional information like a call stack.
'no-throw-literal': 'error',
// RATIONALE: Catches a common coding mistake.
'no-unmodified-loop-condition': 'warn',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-unsafe-finally': 'error',
// RATIONALE: Catches a common coding mistake.
'no-unused-expressions': 'warn',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-unused-labels': 'warn',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-useless-catch': 'warn',
// RATIONALE: Avoids a potential performance problem.
'no-useless-concat': 'warn',
// RATIONALE: The "var" keyword is deprecated because of its confusing "hoisting" behavior.
// Always use "let" or "const" instead.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'no-var': 'error',
// RATIONALE: Generally not needed in modern code.
'no-void': 'error',
// RATIONALE: Obsolete language feature that is deprecated.
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'no-with': 'error',
// RATIONALE: Makes logic easier to understand, since constants always have a known value
// @typescript-eslint\eslint-plugin\dist\configs\eslint-recommended.js
'prefer-const': 'warn',
// RATIONALE: Catches a common coding mistake where "resolve" and "reject" are confused.
'promise/param-names': 'error',
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'require-atomic-updates': 'error',
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'require-yield': 'warn',
// "Use strict" is redundant when using the TypeScript compiler.
strict: ['error', 'never'],
// We're still experimenting with this plugin, so for now it is off by default.
'tsdoc/syntax': 'off',
// RATIONALE: Catches code that is likely to be incorrect
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
'use-isnan': 'error'
// The "no-restricted-syntax" rule is a general purpose pattern matcher that we can use to experiment with
// new rules. If a rule works well, we should convert it to a proper rule so it gets its own name
// for suppressions and documentation.
// How it works: https://eslint.org/docs/rules/no-restricted-syntax
// AST visualizer: https://astexplorer.net/
// Debugger: http://estools.github.io/esquery/
//
// "no-restricted-syntax": [
// ],
}
},
{
// For unit tests, we can be a little bit less strict. The settings below revise the
// defaults specified above.
files: [
// Test files
'*.test.ts',
'*.test.tsx',
// Facebook convention
'**/__mocks__/*.ts',
'**/__mocks__/*.tsx',
'**/__tests__/*.ts',
'**/__tests__/*.tsx',
// Microsoft convention
'**/test/*.ts',
'**/test/*.tsx'
],
rules: {
// Unit tests sometimes use a standalone statement like "new Thing(123);" to test a constructor.
'no-new': 'off',
// Jest's mocking API is designed in a way that produces compositional data types that often have
// no concise description. Since test code does not ship, and typically does not introduce new
// concepts or algorithms, the usual arguments for prioritizing readability over writability can be
// relaxed in this case. We follow C#'s model of allowing type inference for local variable declarations,
// but still requiring strict types for function signatures.
'@typescript-eslint/typedef': [
'warn',
{
arrayDestructuring: false,
arrowParameter: false,
memberVariableDeclaration: true,
objectDestructuring: false,
parameter: true,
propertyDeclaration: true,
variableDeclaration: false, // <--- special case for test files
variableDeclarationIgnoreFunction: true
}
]
}
}
]
};