forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
500 lines (405 loc) · 23.2 KB
/
index.js
File metadata and controls
500 lines (405 loc) · 23.2 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
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
"@rushstack/no-null": "error",
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
"@typescript-eslint/adjacent-overload-signatures": "error",
// 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": [
"error",
{
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": "error",
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
"@typescript-eslint/camelcase": [
"error",
{
// This is a special exception for naming patterns that use an underscore to separate two camel-cased
// parts. Example: "checkBox1_onChanged" or "_checkBox1_onChanged"
allow: [ "^_?[a-z][a-z0-9]*([A-Z][a-z]?[a-z0-9]*)*_[a-z][a-z0-9]*([A-Z][a-z]?[a-z0-9]*)*$" ]
}
],
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
"@typescript-eslint/class-name-casing": [
"error",
{
"allowUnderscorePrefix": true
}
],
// RATIONALE: We require "x as number" instead of "<number>x" to avoid conflicts with JSX.
"@typescript-eslint/consistent-type-assertions": "error",
// 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": "error",
// 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": [
"error",
{
allowExpressions: true,
allowTypedFunctionExpressions: true,
allowHigherOrderFunctions: false,
},
],
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
"@typescript-eslint/explicit-member-accessibility": "error",
// RATIONALE: 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.
//
"@typescript-eslint/interface-name-prefix": [
"error",
{
"prefixWithI": "always",
"allowUnderscorePrefix": true
}
],
// RATIONALE: Requiring private members to be prefixed with an underscore prevents accidental access
// by scripts that are coded in plain JavaScript and cannot see the TypeScript visibility
// declarations. Also, using underscore prefixes allows the private field to be exposed
// by a public getter/setter with the same name (but omitting the underscore).
"@typescript-eslint/member-naming": ["error", { "private": "^_" }],
// 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": [
"error",
{
"default": "never",
"classes": [
"field",
"constructor",
"method"
]
}
],
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
"@typescript-eslint/no-array-constructor": "error",
// 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": "error",
// 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": [
"error",
{
// 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": "error",
// 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": [
"error",
{
"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",
// RATIONALE: The require() API is generally obsolete. Use "import" instead.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
"@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": "error",
// RATIONALE: We require explicit type annotations, even when the compiler could infer the type.
// This is a controversial rule because it makes code more verbose. The reason is that
// type inference is useless when reviewing the diff for a pull request or a Git history.
// Unless the person is already familiar with every file (unlikely in a large project),
// it can be very difficult to guess the types for a typical statement such as
// "let item = provider.fetch(options);". In this situation, explicit type annotations
// greatly increase readability and justify the extra effort required to write them.
// Requiring type annotations also discourages anonymous type algebra, and code is easier
// to reason about when its authors went through the exercise of choosing meaningful names.
//
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
"@typescript-eslint/typedef": [
"error",
{
"arrayDestructuring": false,
"arrowParameter": false,
"memberVariableDeclaration": true,
"parameter": true,
"objectDestructuring": false,
"propertyDeclaration": true,
"variableDeclaration": true
},
],
// RATIONALE: Catches a common coding mistake.
"accessor-pairs": "error",
// RATIONALE: In TypeScript, if you write x["y"] instead of x.y, it disables type checking.
"dot-notation": [
"error",
{
"allowPattern": "^_"
}
],
// RATIONALE: Catches a common coding mistake.
"eqeqeq": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"for-direction": "error",
// RATIONALE: Catches a common coding mistake.
"guard-for-in": "error",
// RATIONALE: If you have more than 1,000 lines in a single source file, it's probably time
// to split up your code.
"max-lines": ["error", { "max": 1000 }],
// 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": [
"error",
{
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": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-control-regex": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-debugger": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-delete-var": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-duplicate-case": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-empty": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-empty-character-class": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-empty-pattern": "error",
// RATIONALE: Eval is a security concern and a performance concern.
"no-eval": "error",
// 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": "error",
// RATIONALE: Catches a common coding mistake.
"no-extra-label": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-fallthrough": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-func-assign": "error",
// 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": "error",
// 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": "error",
// RATIONALE: Obsolete notation that is error-prone.
"no-new-func": "error",
// RATIONALE: Obsolete notation.
"no-new-object": "error",
// RATIONALE: Obsolete notation.
"no-new-wrappers": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-octal": "error",
// RATIONALE: Catches a common coding mistake.
"no-octal-escape": "error",
// 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": "error",
// 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",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-shadow-restricted-names": "error",
// 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": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-unsafe-finally": "error",
// RATIONALE: Catches a common coding mistake.
"no-unused-expressions": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-unused-labels": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-useless-catch": "error",
// RATIONALE: Avoids a potential performance problem.
"no-useless-concat": "error",
// 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",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"no-with": "error",
// @typescript-eslint\eslint-plugin\dist\configs\eslint-recommended.js
"prefer-const": "error",
// RATIONALE: Catches a common coding mistake where "resolve" and "reject" are confused.
"promise/param-names": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"require-atomic-updates": "error",
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
"require-yield": "error",
// "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",
// 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": [
// ],
}
}
]
};