@tsslint/config 3.0.0-alpha.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/tsslint-docgen.js +0 -6
- package/lib/eslint-types.d.ts +2 -4666
- package/lib/eslint.d.ts +1 -13
- package/lib/eslint.js +1 -13
- package/lib/tslint-types.d.ts +2 -3792
- package/lib/tslint.d.ts +1 -13
- package/lib/tslint.js +1 -13
- package/package.json +4 -7
package/lib/tslint-types.d.ts
CHANGED
|
@@ -1,3793 +1,3 @@
|
|
|
1
|
-
export interface TSLintRulesConfig {
|
|
2
|
-
|
|
3
|
-
* @rulesDirectory tools/tslint
|
|
4
|
-
* @error Directory import '/Users/johnsonchu/Desktop/GitHub/angular/node_modules/tslint/lib' is not supported resolving ES modules imported from /Users/johnsonchu/Desktop/GitHub/angular/tools/tslint/requireInternalWithUnderscoreRule.ts
|
|
5
|
-
Did you mean to import "tslint/lib/index.js"?
|
|
6
|
-
*/
|
|
7
|
-
'require-internal-with-underscore'?: any[],
|
|
8
|
-
/**
|
|
9
|
-
* @rulesDirectory tools/tslint
|
|
10
|
-
*/
|
|
11
|
-
'ts-node-loader'?: any[],
|
|
12
|
-
/**
|
|
13
|
-
* Enforces function overloads to be consecutive.
|
|
14
|
-
*
|
|
15
|
-
* @rationale
|
|
16
|
-
* Improves readability and organization by grouping naturally related items together.
|
|
17
|
-
*
|
|
18
|
-
* @options
|
|
19
|
-
* If `ignore-accessors` is specified, then getters and setters are not considered to be overloads
|
|
20
|
-
* of function with the same signature.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* "adjacent-overload-signatures": true
|
|
24
|
-
* "adjacent-overload-signatures": [true,{"OPTION_IGNORE_ACCESSORS":true}]
|
|
25
|
-
*
|
|
26
|
-
* @type typescript
|
|
27
|
-
*
|
|
28
|
-
* @typescriptOnly
|
|
29
|
-
*/
|
|
30
|
-
'adjacent-overload-signatures'?: {
|
|
31
|
-
'ignore-accessors'?: boolean,
|
|
32
|
-
},
|
|
33
|
-
/**
|
|
34
|
-
* Enforces vertical alignment.
|
|
35
|
-
*
|
|
36
|
-
* @rationale
|
|
37
|
-
* Helps maintain a readable, consistent style in your codebase.
|
|
38
|
-
*
|
|
39
|
-
* Consistent alignment for code statements helps keep code readable and clear.
|
|
40
|
-
* Statements misaligned from the standard can be harder to read and understand.
|
|
41
|
-
*
|
|
42
|
-
* @options
|
|
43
|
-
* Five arguments may be optionally provided:
|
|
44
|
-
*
|
|
45
|
-
* * `"parameters"` checks alignment of function parameters.
|
|
46
|
-
* * `"arguments"` checks alignment of function call arguments.
|
|
47
|
-
* * `"statements"` checks alignment of statements.
|
|
48
|
-
* * `"members"` checks alignment of members of classes, interfaces, type literal, object literals and
|
|
49
|
-
* object destructuring.
|
|
50
|
-
* * `"elements"` checks alignment of elements of array literals, array destructuring and tuple types.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* "align": [true,"parameters","statements"]
|
|
54
|
-
*
|
|
55
|
-
* @type formatting
|
|
56
|
-
*/
|
|
57
|
-
'align'?: ("arguments" | "elements" | "members" | "parameters" | "statements")[],
|
|
58
|
-
/**
|
|
59
|
-
* Requires using either 'T[]' or 'Array<T>' for arrays.
|
|
60
|
-
*
|
|
61
|
-
* @options
|
|
62
|
-
* One of the following arguments must be provided:
|
|
63
|
-
*
|
|
64
|
-
* * `"array"` enforces use of `T[]` for all types T.
|
|
65
|
-
* * `"generic"` enforces use of `Array<T>` for all types T.
|
|
66
|
-
* * `"array-simple"` enforces use of `T[]` if `T` is a simple type (primitive or type reference).
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* "array-type": [true,"array"]
|
|
70
|
-
* "array-type": [true,"generic"]
|
|
71
|
-
* "array-type": [true,"array-simple"]
|
|
72
|
-
*
|
|
73
|
-
* @type style
|
|
74
|
-
*
|
|
75
|
-
* @typescriptOnly
|
|
76
|
-
*/
|
|
77
|
-
'array-type'?: "array" | "generic" | "array-simple",
|
|
78
|
-
/**
|
|
79
|
-
* Requires parentheses around the parameters of arrow function definitions.
|
|
80
|
-
*
|
|
81
|
-
* @rationale
|
|
82
|
-
* Maintains stylistic consistency with other arrow function definitions.
|
|
83
|
-
*
|
|
84
|
-
* @options
|
|
85
|
-
* If `ban-single-arg-parens` is specified, then arrow functions with one parameter
|
|
86
|
-
* must not have parentheses if removing them is allowed by TypeScript.
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* "arrow-parens": true
|
|
90
|
-
* "arrow-parens": [true,"ban-single-arg-parens"]
|
|
91
|
-
*
|
|
92
|
-
* @type formatting
|
|
93
|
-
*/
|
|
94
|
-
'arrow-parens'?: "ban-single-arg-parens",
|
|
95
|
-
/**
|
|
96
|
-
* Suggests to convert `() => { return x; }` to `() => x`.
|
|
97
|
-
*
|
|
98
|
-
* @rationale
|
|
99
|
-
* It's unnecessary to include `return` and `{}` brackets in arrow lambdas.
|
|
100
|
-
* Leaving them out results in simpler and easier to read code.
|
|
101
|
-
*
|
|
102
|
-
* @options
|
|
103
|
-
* If `multiline` is specified, then this will warn even if the function spans multiple lines.
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* "arrow-return-shorthand": true
|
|
107
|
-
* "arrow-return-shorthand": [true,"multiline"]
|
|
108
|
-
*
|
|
109
|
-
* @type style
|
|
110
|
-
*/
|
|
111
|
-
'arrow-return-shorthand'?: "multiline",
|
|
112
|
-
/**
|
|
113
|
-
* Warns for an awaited value that is not a Promise.
|
|
114
|
-
*
|
|
115
|
-
* @rationale
|
|
116
|
-
* While it is valid JavaScript to await a non-Promise-like value (it will resolve immediately),
|
|
117
|
-
* this pattern is often a programmer error and the resulting semantics can be unintuitive.
|
|
118
|
-
*
|
|
119
|
-
* Awaiting non-Promise-like values often is an indication of programmer error, such as
|
|
120
|
-
* forgetting to add parenthesis to call a function that returns a Promise.
|
|
121
|
-
*
|
|
122
|
-
* @options
|
|
123
|
-
* A list of 'string' names of any additional classes that should also be treated as Promises.
|
|
124
|
-
* For example, if you are using a class called 'Future' that implements the Thenable interface,
|
|
125
|
-
* you might tell the rule to consider type references with the name 'Future' as valid Promise-like
|
|
126
|
-
* types. Note that this rule doesn't check for type assignability or compatibility; it just checks
|
|
127
|
-
* type reference names.
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* "await-promise": true
|
|
131
|
-
* "await-promise": [true,"Thenable"]
|
|
132
|
-
*
|
|
133
|
-
* @type functionality
|
|
134
|
-
*
|
|
135
|
-
* @typescriptOnly
|
|
136
|
-
*/
|
|
137
|
-
'await-promise'?: unknown,
|
|
138
|
-
/**
|
|
139
|
-
* Disallows the comma operator to be used.
|
|
140
|
-
*
|
|
141
|
-
* [Read more about the comma operator here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator).
|
|
142
|
-
*
|
|
143
|
-
* @rationale
|
|
144
|
-
* Using the comma operator can create a potential for many non-obvious bugs or lead to misunderstanding of code.
|
|
145
|
-
*
|
|
146
|
-
* ### Examples
|
|
147
|
-
* ```
|
|
148
|
-
* foo((bar, baz)); // evaluates to 'foo(baz)' because of the extra parens - confusing and not obvious
|
|
149
|
-
* ```
|
|
150
|
-
*
|
|
151
|
-
* ```
|
|
152
|
-
* switch (foo) {
|
|
153
|
-
* case 1, 2: // equals 'case 2' - probably intended 'case 1: case2:'
|
|
154
|
-
* return true;
|
|
155
|
-
* case 3:
|
|
156
|
-
* return false;
|
|
157
|
-
* }
|
|
158
|
-
* ```
|
|
159
|
-
*
|
|
160
|
-
* ```
|
|
161
|
-
* let x = (y = 1, z = 2); // x is equal to 2 - this may not be immediately obvious.
|
|
162
|
-
* ```
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* "ban-comma-operator": true
|
|
166
|
-
*
|
|
167
|
-
* @type functionality
|
|
168
|
-
*/
|
|
169
|
-
'ban-comma-operator'?: any[],
|
|
170
|
-
/**
|
|
171
|
-
* Bans the use of specific functions or global methods.
|
|
172
|
-
*
|
|
173
|
-
* @options
|
|
174
|
-
* A list of banned functions or methods in the following format:
|
|
175
|
-
*
|
|
176
|
-
* * banning functions:
|
|
177
|
-
* * just the name of the function: `"functionName"`
|
|
178
|
-
* * the name of the function in an array with one element: `["functionName"]`
|
|
179
|
-
* * an object in the following format: `{"name": "functionName", "message": "optional explanation message"}`
|
|
180
|
-
* * banning methods:
|
|
181
|
-
* * an array with the object name, method name and optional message: `["objectName", "methodName", "optional message"]`
|
|
182
|
-
* * an object in the following format: `{"name": ["objectName", "methodName"], "message": "optional message"}`
|
|
183
|
-
* * you can also ban deeply nested methods: `{"name": ["foo", "bar", "baz"]}` bans `foo.bar.baz()`
|
|
184
|
-
* * the first element can contain a wildcard (`*`) that matches everything. `{"name": ["*", "forEach"]}` bans `[].forEach(...)`, `$(...).forEach(...)`, `arr.forEach(...)`, etc.
|
|
185
|
-
*
|
|
186
|
-
* @example
|
|
187
|
-
* "ban": [true,"eval",{"name":"$","message":"please don't"},["describe","only"],{"name":["it","only"],"message":"don't focus tests"},{"name":["chai","assert","equal"],"message":"Use 'strictEqual' instead."},{"name":["*","forEach"],"message":"Use a regular for loop instead."},{"name":["*","_id","toString"],"message":"Use 'toHexString' instead."}]
|
|
188
|
-
*
|
|
189
|
-
* @type functionality
|
|
190
|
-
*/
|
|
191
|
-
'ban'?: unknown,
|
|
192
|
-
/**
|
|
193
|
-
* Bans "// @ts-ignore" comments from being used.
|
|
194
|
-
*
|
|
195
|
-
* @options
|
|
196
|
-
* Not configurable.
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* "ban-ts-ignore": true
|
|
200
|
-
*
|
|
201
|
-
* @type typescript
|
|
202
|
-
*
|
|
203
|
-
* @typescriptOnly
|
|
204
|
-
*/
|
|
205
|
-
'ban-ts-ignore'?: any[],
|
|
206
|
-
/**
|
|
207
|
-
* Bans specific types from being used. Does not ban the
|
|
208
|
-
* corresponding runtime objects from being used.
|
|
209
|
-
*
|
|
210
|
-
* @options
|
|
211
|
-
* A list of `["regex", "optional explanation here"]`, which bans
|
|
212
|
-
* types that match `regex`
|
|
213
|
-
*
|
|
214
|
-
* @example
|
|
215
|
-
* "ban-types": [true,["Object","Use {} instead."],["String"]]
|
|
216
|
-
*
|
|
217
|
-
* @type typescript
|
|
218
|
-
*
|
|
219
|
-
* @typescriptOnly
|
|
220
|
-
*/
|
|
221
|
-
'ban-types'?: unknown,
|
|
222
|
-
/**
|
|
223
|
-
* In a binary expression, a literal should always be on the right-hand side if possible.
|
|
224
|
-
* For example, prefer 'x + 1' over '1 + x'.
|
|
225
|
-
*
|
|
226
|
-
* @rationale
|
|
227
|
-
* Expressions like `1 + x` are sometimes referred to as "Yoda" expressions because they read
|
|
228
|
-
* opposite to how we would normally speak the expression.
|
|
229
|
-
*
|
|
230
|
-
* Sticking to a consistent grammar for conditions helps keep code readable and understandable.
|
|
231
|
-
*
|
|
232
|
-
* @options
|
|
233
|
-
* Not configurable.
|
|
234
|
-
*
|
|
235
|
-
* @example
|
|
236
|
-
* "binary-expression-operand-order": true
|
|
237
|
-
*
|
|
238
|
-
* @type style
|
|
239
|
-
*/
|
|
240
|
-
'binary-expression-operand-order'?: any[],
|
|
241
|
-
/**
|
|
242
|
-
* An interface or literal type with just a call signature can be written as a function type.
|
|
243
|
-
*
|
|
244
|
-
* @rationale
|
|
245
|
-
* style
|
|
246
|
-
*
|
|
247
|
-
* @options
|
|
248
|
-
* Not configurable.
|
|
249
|
-
*
|
|
250
|
-
* @type style
|
|
251
|
-
*
|
|
252
|
-
* @typescriptOnly
|
|
253
|
-
*/
|
|
254
|
-
'callable-types'?: any[],
|
|
255
|
-
/**
|
|
256
|
-
* Enforces PascalCased class and interface names.
|
|
257
|
-
*
|
|
258
|
-
* @rationale
|
|
259
|
-
* Makes it easy to differentiate classes from regular variables at a glance.
|
|
260
|
-
*
|
|
261
|
-
* JavaScript and general programming convention is to refer to classes in PascalCase.
|
|
262
|
-
* It's confusing to use camelCase or other conventions for class names.
|
|
263
|
-
*
|
|
264
|
-
* @options
|
|
265
|
-
* Not configurable.
|
|
266
|
-
*
|
|
267
|
-
* @example
|
|
268
|
-
* "class-name": true
|
|
269
|
-
*
|
|
270
|
-
* @type style
|
|
271
|
-
*/
|
|
272
|
-
'class-name'?: any[],
|
|
273
|
-
/**
|
|
274
|
-
* Enforces formatting rules for single-line comments.
|
|
275
|
-
*
|
|
276
|
-
* @rationale
|
|
277
|
-
* Helps maintain a consistent, readable style in your codebase.
|
|
278
|
-
*
|
|
279
|
-
* @options
|
|
280
|
-
* Four arguments may be optionally provided:
|
|
281
|
-
*
|
|
282
|
-
* * `"check-space"` requires that all single-line comments must begin with a space, as in `// comment`
|
|
283
|
-
* * note that for comments starting with multiple slashes, e.g. `///`, leading slashes are ignored
|
|
284
|
-
* * TypeScript reference comments are ignored completely
|
|
285
|
-
* * `"check-lowercase"` requires that the first non-whitespace character of a comment must be lowercase, if applicable.
|
|
286
|
-
* * `"check-uppercase"` requires that the first non-whitespace character of a comment must be uppercase, if applicable.
|
|
287
|
-
* * `"allow-trailing-lowercase"` allows that only the first comment of a series of comments needs to be uppercase.
|
|
288
|
-
* * requires `"check-uppercase"`
|
|
289
|
-
* * comments must start at the same position
|
|
290
|
-
*
|
|
291
|
-
* Exceptions to `"check-lowercase"` or `"check-uppercase"` can be managed with object that may be passed as last
|
|
292
|
-
* argument.
|
|
293
|
-
*
|
|
294
|
-
* One of two options can be provided in this object:
|
|
295
|
-
*
|
|
296
|
-
* * `"ignore-words"` - array of strings - words that will be ignored at the beginning of the comment.
|
|
297
|
-
* * `"ignore-pattern"` - string - RegExp pattern that will be ignored at the beginning of the comment.
|
|
298
|
-
*
|
|
299
|
-
* @example
|
|
300
|
-
* "comment-format": [true,"check-space","check-uppercase","allow-trailing-lowercase"]
|
|
301
|
-
* "comment-format": [true,"check-lowercase",{"ignore-words":["TODO","HACK"]}]
|
|
302
|
-
* "comment-format": [true,"check-lowercase",{"ignore-pattern":"STD\\w{2,3}\\b"}]
|
|
303
|
-
*
|
|
304
|
-
* @type style
|
|
305
|
-
*/
|
|
306
|
-
'comment-format'?: ("check-space" | "check-lowercase" | "check-uppercase" | "allow-trailing-lowercase" | {
|
|
307
|
-
'ignore-words'?: (string)[],
|
|
308
|
-
'ignore-pattern'?: string,
|
|
309
|
-
})[],
|
|
310
|
-
/**
|
|
311
|
-
* Allows a limited set of comment types
|
|
312
|
-
*
|
|
313
|
-
* @options
|
|
314
|
-
* One or more of the following mutually exclusive comment types may be provided:
|
|
315
|
-
*
|
|
316
|
-
* * `singleline`: Comments starting with `//`
|
|
317
|
-
* * `multiline`: Comments between `/*` and `* /` but are not doc comments
|
|
318
|
-
* * `doc`: Multiline comments that start with `/**`
|
|
319
|
-
* * 'directive': Triple-slash directives that are singleline comments starting with `///`
|
|
320
|
-
*
|
|
321
|
-
* @example
|
|
322
|
-
* "comment-type": [true,"doc","singleline"]
|
|
323
|
-
* "comment-type": [true,"singleline"]
|
|
324
|
-
* "comment-type": [true,"multiline"]
|
|
325
|
-
*
|
|
326
|
-
* @type style
|
|
327
|
-
*/
|
|
328
|
-
'comment-type'?: ("singleline" | "multiline" | "doc" | "directive")[],
|
|
329
|
-
/**
|
|
330
|
-
* Enforces JSDoc comments for important items be filled out.
|
|
331
|
-
*
|
|
332
|
-
* @rationale
|
|
333
|
-
* Helps ensure important components are documented.
|
|
334
|
-
*
|
|
335
|
-
* Note: use this rule sparingly. It's better to have self-documenting names on components with single, concise responsibilities.
|
|
336
|
-
* Comments that only restate the names of variables add nothing to code, and can easily become outdated.
|
|
337
|
-
*
|
|
338
|
-
* @options
|
|
339
|
-
* `true` to enable for `[classes, functions, methods, properties]`,
|
|
340
|
-
* or an array with each item in one of two formats:
|
|
341
|
-
*
|
|
342
|
-
* * `string` to enable for that type
|
|
343
|
-
* * `object` keying types to when their documentation is required:
|
|
344
|
-
* * `"methods"` and `"properties"` may specify:
|
|
345
|
-
* * `"privacies"`:
|
|
346
|
-
* * `"all"`
|
|
347
|
-
* * `"private"`
|
|
348
|
-
* * `"protected"`
|
|
349
|
-
* * `"public"`
|
|
350
|
-
* * `"locations"`:
|
|
351
|
-
* * `"all"`
|
|
352
|
-
* * `"instance"`
|
|
353
|
-
* * `"static"`
|
|
354
|
-
* * Other types may specify `"visibilities"`:
|
|
355
|
-
* * `"all"`
|
|
356
|
-
* * `"exported"`
|
|
357
|
-
* * `"internal"`
|
|
358
|
-
* * `"functions"` `"methods"` may also specify `"overloads"`
|
|
359
|
-
* to indicate that each overload should have its own documentation, which is `false` by default.
|
|
360
|
-
* * All types may also provide `"tags"`
|
|
361
|
-
* with members specifying tags that allow the docs to not have a body.
|
|
362
|
-
* * `"content"`: Object mapping tags to `RegExp` bodies content allowed to count as complete docs.
|
|
363
|
-
* * `"existence"`: Array of tags that must only exist to count as complete docs.
|
|
364
|
-
*
|
|
365
|
-
* Types that may be enabled are:
|
|
366
|
-
*
|
|
367
|
-
* * `"classes"`
|
|
368
|
-
* * `"constructors"`
|
|
369
|
-
* * `"enums"`
|
|
370
|
-
* * `"enum-members"`
|
|
371
|
-
* * `"functions"`
|
|
372
|
-
* * `"interfaces"`
|
|
373
|
-
* * `"methods"`
|
|
374
|
-
* * `"namespaces"`
|
|
375
|
-
* * `"properties"`
|
|
376
|
-
* * `"types"`
|
|
377
|
-
* * `"variables"`
|
|
378
|
-
*
|
|
379
|
-
* @example
|
|
380
|
-
* "completed-docs": true
|
|
381
|
-
* "completed-docs": [true,"enums","functions","methods"]
|
|
382
|
-
* "completed-docs": [true,{"enums":true,"functions":{"visibilities":["exported"]},"methods":{"locations":"instance","privacies":["public","protected"]},"properties":{"tags":{"content":{"see":["#.*"]},"existence":["inheritdoc"]}}}]
|
|
383
|
-
*
|
|
384
|
-
* @type style
|
|
385
|
-
*/
|
|
386
|
-
'completed-docs'?: (string | {
|
|
387
|
-
classes?: {
|
|
388
|
-
tags?: {
|
|
389
|
-
content?: { [key: string]: unknown },
|
|
390
|
-
existence?: (string)[],
|
|
391
|
-
},
|
|
392
|
-
visibilities?: "all" | "exported" | "internal",
|
|
393
|
-
},
|
|
394
|
-
constructors?: {
|
|
395
|
-
tags?: {
|
|
396
|
-
content?: { [key: string]: unknown },
|
|
397
|
-
existence?: (string)[],
|
|
398
|
-
},
|
|
399
|
-
privacies?: "all" | "private" | "protected" | "public",
|
|
400
|
-
overloads?: boolean,
|
|
401
|
-
},
|
|
402
|
-
enums?: {
|
|
403
|
-
tags?: {
|
|
404
|
-
content?: { [key: string]: unknown },
|
|
405
|
-
existence?: (string)[],
|
|
406
|
-
},
|
|
407
|
-
visibilities?: "all" | "exported" | "internal",
|
|
408
|
-
},
|
|
409
|
-
'enum-members'?: {
|
|
410
|
-
tags?: {
|
|
411
|
-
content?: { [key: string]: unknown },
|
|
412
|
-
existence?: (string)[],
|
|
413
|
-
},
|
|
414
|
-
visibilities?: "all" | "exported" | "internal",
|
|
415
|
-
},
|
|
416
|
-
functions?: {
|
|
417
|
-
tags?: {
|
|
418
|
-
content?: { [key: string]: unknown },
|
|
419
|
-
existence?: (string)[],
|
|
420
|
-
},
|
|
421
|
-
visibilities?: "all" | "exported" | "internal",
|
|
422
|
-
overloads?: boolean,
|
|
423
|
-
},
|
|
424
|
-
interfaces?: {
|
|
425
|
-
tags?: {
|
|
426
|
-
content?: { [key: string]: unknown },
|
|
427
|
-
existence?: (string)[],
|
|
428
|
-
},
|
|
429
|
-
visibilities?: "all" | "exported" | "internal",
|
|
430
|
-
},
|
|
431
|
-
methods?: {
|
|
432
|
-
tags?: {
|
|
433
|
-
content?: { [key: string]: unknown },
|
|
434
|
-
existence?: (string)[],
|
|
435
|
-
},
|
|
436
|
-
locations?: "all" | "instance" | "static",
|
|
437
|
-
privacies?: "all" | "private" | "protected" | "public",
|
|
438
|
-
overloads?: boolean,
|
|
439
|
-
},
|
|
440
|
-
namespaces?: {
|
|
441
|
-
tags?: {
|
|
442
|
-
content?: { [key: string]: unknown },
|
|
443
|
-
existence?: (string)[],
|
|
444
|
-
},
|
|
445
|
-
visibilities?: "all" | "exported" | "internal",
|
|
446
|
-
},
|
|
447
|
-
properties?: {
|
|
448
|
-
tags?: {
|
|
449
|
-
content?: { [key: string]: unknown },
|
|
450
|
-
existence?: (string)[],
|
|
451
|
-
},
|
|
452
|
-
locations?: "all" | "instance" | "static",
|
|
453
|
-
privacies?: "all" | "private" | "protected" | "public",
|
|
454
|
-
},
|
|
455
|
-
types?: {
|
|
456
|
-
tags?: {
|
|
457
|
-
content?: { [key: string]: unknown },
|
|
458
|
-
existence?: (string)[],
|
|
459
|
-
},
|
|
460
|
-
visibilities?: "all" | "exported" | "internal",
|
|
461
|
-
},
|
|
462
|
-
variables?: {
|
|
463
|
-
tags?: {
|
|
464
|
-
content?: { [key: string]: unknown },
|
|
465
|
-
existence?: (string)[],
|
|
466
|
-
},
|
|
467
|
-
visibilities?: "all" | "exported" | "internal",
|
|
468
|
-
},
|
|
469
|
-
})[],
|
|
470
|
-
/**
|
|
471
|
-
* Enforces braces for `if`/`for`/`do`/`while` statements.
|
|
472
|
-
*
|
|
473
|
-
* @rationale
|
|
474
|
-
* ```ts
|
|
475
|
-
* if (foo === bar)
|
|
476
|
-
* foo++;
|
|
477
|
-
* bar++;
|
|
478
|
-
* ```
|
|
479
|
-
*
|
|
480
|
-
* In the code above, the author almost certainly meant for both `foo++` and `bar++`
|
|
481
|
-
* to be executed only if `foo === bar`. However, they forgot braces and `bar++` will be executed
|
|
482
|
-
* no matter what. This rule could prevent such a mistake.
|
|
483
|
-
*
|
|
484
|
-
* @options
|
|
485
|
-
* One of the following options may be provided:
|
|
486
|
-
*
|
|
487
|
-
* * `"as-needed"` forbids any unnecessary curly braces.
|
|
488
|
-
* * `"ignore-same-line"` skips checking braces for control-flow statements
|
|
489
|
-
* that are on one line and start on the same line as their control-flow keyword
|
|
490
|
-
*
|
|
491
|
-
* @example
|
|
492
|
-
* "curly": true
|
|
493
|
-
* "curly": [true,"ignore-same-line"]
|
|
494
|
-
* "curly": [true,"as-needed"]
|
|
495
|
-
*
|
|
496
|
-
* @type functionality
|
|
497
|
-
*/
|
|
498
|
-
'curly'?: ("as-needed" | "ignore-same-line")[],
|
|
499
|
-
/**
|
|
500
|
-
* Enforces a threshold of cyclomatic complexity.
|
|
501
|
-
*
|
|
502
|
-
* Cyclomatic complexity is assessed for each function of any type. A starting value of 0
|
|
503
|
-
* is assigned and this value is then incremented for every statement which can branch the
|
|
504
|
-
* control flow within the function. The following statements and expressions contribute
|
|
505
|
-
* to cyclomatic complexity:
|
|
506
|
-
* * `catch`
|
|
507
|
-
* * `if` and `? :`
|
|
508
|
-
* * `||` and `&&` due to short-circuit evaluation
|
|
509
|
-
* * `for`, `for in` and `for of` loops
|
|
510
|
-
* * `while` and `do while` loops
|
|
511
|
-
* * `case` clauses that contain statements
|
|
512
|
-
*
|
|
513
|
-
* @rationale
|
|
514
|
-
* Cyclomatic complexity is a code metric which indicates the level of complexity in a
|
|
515
|
-
* function. High cyclomatic complexity indicates confusing code which may be prone to
|
|
516
|
-
* errors or difficult to modify.
|
|
517
|
-
*
|
|
518
|
-
* It's better to have smaller, single-purpose functions with self-documenting names.
|
|
519
|
-
*
|
|
520
|
-
* @options
|
|
521
|
-
* An optional upper limit for cyclomatic complexity can be specified. If no limit option
|
|
522
|
-
* is provided a default value of 20 will be used.
|
|
523
|
-
*
|
|
524
|
-
* @example
|
|
525
|
-
* "cyclomatic-complexity": true
|
|
526
|
-
* "cyclomatic-complexity": [true,20]
|
|
527
|
-
*
|
|
528
|
-
* @type maintainability
|
|
529
|
-
*/
|
|
530
|
-
'cyclomatic-complexity'?: number,
|
|
531
|
-
/**
|
|
532
|
-
* Warns when deprecated APIs are used.
|
|
533
|
-
*
|
|
534
|
-
* Any usage of an identifier
|
|
535
|
-
* with the @deprecated JSDoc annotation will trigger a warning.
|
|
536
|
-
* See http://usejsdoc.org/tags-deprecated.html
|
|
537
|
-
*
|
|
538
|
-
* @rationale
|
|
539
|
-
* Deprecated APIs should be avoided, and usage updated.
|
|
540
|
-
*
|
|
541
|
-
* @example
|
|
542
|
-
* "deprecation": true
|
|
543
|
-
*
|
|
544
|
-
* @type maintainability
|
|
545
|
-
*/
|
|
546
|
-
'deprecation'?: any[],
|
|
547
|
-
/**
|
|
548
|
-
* Enforces UTF-8 file encoding.
|
|
549
|
-
*
|
|
550
|
-
* @options
|
|
551
|
-
* Not configurable.
|
|
552
|
-
*
|
|
553
|
-
* @example
|
|
554
|
-
* true
|
|
555
|
-
*
|
|
556
|
-
* @type style
|
|
557
|
-
*/
|
|
558
|
-
'encoding'?: any[],
|
|
559
|
-
/**
|
|
560
|
-
* Ensures the file ends with a newline.
|
|
561
|
-
*
|
|
562
|
-
* Fix for single-line files is not supported.
|
|
563
|
-
*
|
|
564
|
-
* @rationale
|
|
565
|
-
* It is a [standard convention](https://stackoverflow.com/q/729692/3124288) to end files with a newline.
|
|
566
|
-
*
|
|
567
|
-
* @options
|
|
568
|
-
* Not configurable.
|
|
569
|
-
*
|
|
570
|
-
* @example
|
|
571
|
-
* "eofline": true
|
|
572
|
-
*
|
|
573
|
-
* @type formatting
|
|
574
|
-
*/
|
|
575
|
-
'eofline'?: any[],
|
|
576
|
-
/**
|
|
577
|
-
* Enforces a certain header comment for all files, matched by a regular expression.
|
|
578
|
-
*
|
|
579
|
-
* @options
|
|
580
|
-
* A single object may be passed in for configuration that must contain:
|
|
581
|
-
*
|
|
582
|
-
* * `match`: a regular expression that all headers should match
|
|
583
|
-
*
|
|
584
|
-
* Any of the following optional fields may also be provided:
|
|
585
|
-
*
|
|
586
|
-
* * `allow-single-line-comments`: a boolean for whether `//` should be considered file headers in addition to `/*` comments
|
|
587
|
-
* * `default`: text to add for file headers when running in `--fix` mode
|
|
588
|
-
* * `enforce-trailing-newline`: a boolean for whether a newline must follow the header
|
|
589
|
-
*
|
|
590
|
-
* The rule will also accept array of strings as a legacy form of options, though the object form is recommended.
|
|
591
|
-
* The first option, which is mandatory, is a regular expression that all headers should match.
|
|
592
|
-
* The second argument, which is optional, is a string that should be inserted as a header comment
|
|
593
|
-
* if fixing is enabled and no header that matches the first argument is found.
|
|
594
|
-
* The third argument, which is optional, is a string that denotes whether or not a newline should
|
|
595
|
-
* exist on the header.
|
|
596
|
-
*
|
|
597
|
-
* @example
|
|
598
|
-
* "file-header": [true,{"match":"Copyright \\d{4}","allow-single-line-comments":true,"default":"Copyright 2018","enforce-trailing-newline":true}]
|
|
599
|
-
* "file-header": [true,"Copyright \\d{4}","Copyright 2018","enforce-trailing-newline"]
|
|
600
|
-
*
|
|
601
|
-
* @type style
|
|
602
|
-
*/
|
|
603
|
-
'file-header'?: ({
|
|
604
|
-
match?: string,
|
|
605
|
-
'allow-single-line-comments'?: boolean,
|
|
606
|
-
default?: string,
|
|
607
|
-
'enforce-trailing-newline'?: boolean,
|
|
608
|
-
})[] | [string, string, string],
|
|
609
|
-
/**
|
|
610
|
-
* Enforces a consistent file naming convention
|
|
611
|
-
*
|
|
612
|
-
* @rationale
|
|
613
|
-
* Helps maintain a consistent style across a file hierarchy
|
|
614
|
-
*
|
|
615
|
-
* @options
|
|
616
|
-
* One of the following arguments must be provided:
|
|
617
|
-
*
|
|
618
|
-
* * `camel-case`: File names must be camel-cased: `fileName.ts`.
|
|
619
|
-
* * `pascal-case`: File names must be Pascal-cased: `FileName.ts`.
|
|
620
|
-
* * `kebab-case`: File names must be kebab-cased: `file-name.ts`.
|
|
621
|
-
* * `snake-case`: File names must be snake-cased: `file_name.ts`.
|
|
622
|
-
* * `ignore`: File names are ignored _(useful for the object configuration)_.
|
|
623
|
-
*
|
|
624
|
-
* Or an object, where the key represents a regular expression that
|
|
625
|
-
* matches the file name, and the value is the file name rule from
|
|
626
|
-
* the previous list.
|
|
627
|
-
*
|
|
628
|
-
* * { ".tsx": "pascal-case", ".ts": "camel-case" }
|
|
629
|
-
*
|
|
630
|
-
* @example
|
|
631
|
-
* "file-name-casing": [true,"camel-case"]
|
|
632
|
-
* "file-name-casing": [true,"pascal-case"]
|
|
633
|
-
* "file-name-casing": [true,"kebab-case"]
|
|
634
|
-
* "file-name-casing": [true,"snake-case"]
|
|
635
|
-
* "file-name-casing": [true,{".tsx":"pascal-case",".ts":"camel-case"}]
|
|
636
|
-
* "file-name-casing": [true,{".style.ts":"kebab-case",".tsx":"pascal-case",".*":"camel-case"}]
|
|
637
|
-
* "file-name-casing": [true,{".ts":"ignore",".tsx":"pascal-case"}]
|
|
638
|
-
*
|
|
639
|
-
* @type style
|
|
640
|
-
*/
|
|
641
|
-
'file-name-casing'?: (["camel-case" | "ignore" | "pascal-case" | "kebab-case" | "snake-case"] | { [key: string]: unknown })[],
|
|
642
|
-
/**
|
|
643
|
-
* Requires a `for ... in` statement to be filtered with an `if` statement.
|
|
644
|
-
*
|
|
645
|
-
* @rationale
|
|
646
|
-
* ```ts
|
|
647
|
-
* for (let key in someObject) {
|
|
648
|
-
* if (someObject.hasOwnProperty(key)) {
|
|
649
|
-
* // code here
|
|
650
|
-
* }
|
|
651
|
-
* }
|
|
652
|
-
* ```
|
|
653
|
-
* Prevents accidental iteration over properties inherited from an object's prototype.
|
|
654
|
-
* See [MDN's `for...in`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in)
|
|
655
|
-
* documentation for more information about `for...in` loops.
|
|
656
|
-
*
|
|
657
|
-
* Also consider using a [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
|
|
658
|
-
* or [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
|
|
659
|
-
* if you're storing collections of objects.
|
|
660
|
-
* Using `Object`s can cause occasional edge case bugs, such as if a key is named "hasOwnProperty".
|
|
661
|
-
*
|
|
662
|
-
* @options
|
|
663
|
-
* Not configurable.
|
|
664
|
-
*
|
|
665
|
-
* @example
|
|
666
|
-
* "forin": true
|
|
667
|
-
*
|
|
668
|
-
* @type functionality
|
|
669
|
-
*/
|
|
670
|
-
'forin'?: any[],
|
|
671
|
-
/**
|
|
672
|
-
* Prevents using the built-in Function constructor.
|
|
673
|
-
*
|
|
674
|
-
* @rationale
|
|
675
|
-
* Calling the constructor directly is similar to `eval`, which is a symptom of design issues.
|
|
676
|
-
* String inputs don't receive type checking and can cause performance issues, particularly when dynamically created.
|
|
677
|
-
*
|
|
678
|
-
* If you need to dynamically create functions, use "factory" functions that themselves return functions.
|
|
679
|
-
*
|
|
680
|
-
* @options
|
|
681
|
-
* Not configurable.
|
|
682
|
-
*
|
|
683
|
-
* @example
|
|
684
|
-
* "function-constructor": true
|
|
685
|
-
*
|
|
686
|
-
* @type functionality
|
|
687
|
-
*/
|
|
688
|
-
'function-constructor'?: any[],
|
|
689
|
-
/**
|
|
690
|
-
* Disallows importing the specified modules via `import` and `require`,
|
|
691
|
-
* or importing specific named exports of the specified modules,
|
|
692
|
-
* or using imports matching specified regular expression patterns.
|
|
693
|
-
*
|
|
694
|
-
* @rationale
|
|
695
|
-
* For some libraries, importing the library directly can cause unused
|
|
696
|
-
* submodules to be loaded, so you may want to block these imports and
|
|
697
|
-
* require that users directly import only the submodules they need.
|
|
698
|
-
* In other cases, you may simply want to ban an import because using
|
|
699
|
-
* it is undesirable or unsafe.
|
|
700
|
-
*
|
|
701
|
-
* @options
|
|
702
|
-
* A list of blacklisted modules, named imports, or regular expression patterns.
|
|
703
|
-
*
|
|
704
|
-
* @example
|
|
705
|
-
* "import-blacklist": true
|
|
706
|
-
* "import-blacklist": [true,"rxjs","lodash"]
|
|
707
|
-
* "import-blacklist": [true,[".*\\.temp$",".*\\.tmp$"]]
|
|
708
|
-
* "import-blacklist": [true,{"lodash":["pull","pullAll"]}]
|
|
709
|
-
* "import-blacklist": [true,"lodash",{"lodash":["pull","pullAll"]}]
|
|
710
|
-
* "import-blacklist": [true,"rxjs",{"lodash":["pull","pullAll"]},[".*\\.temp$",".*\\.tmp$"]]
|
|
711
|
-
*
|
|
712
|
-
* @type functionality
|
|
713
|
-
*/
|
|
714
|
-
'import-blacklist'?: (string | { [key: string]: unknown } | (string)[])[],
|
|
715
|
-
/**
|
|
716
|
-
* Ensures proper spacing between import statement keywords
|
|
717
|
-
*
|
|
718
|
-
* @options
|
|
719
|
-
* Not configurable.
|
|
720
|
-
*
|
|
721
|
-
* @example
|
|
722
|
-
* "import-spacing": true
|
|
723
|
-
*
|
|
724
|
-
* @type formatting
|
|
725
|
-
*/
|
|
726
|
-
'import-spacing'?: any[],
|
|
727
|
-
/**
|
|
728
|
-
* Enforces using explicit += 1 or -= 1 operators.
|
|
729
|
-
*
|
|
730
|
-
* @rationale
|
|
731
|
-
* It's easy to type +i or -i instead of --i or ++i, and won't always result in invalid code.
|
|
732
|
-
* Prefer standardizing small arithmetic operations with the explicit += and -= operators.
|
|
733
|
-
*
|
|
734
|
-
* @options
|
|
735
|
-
* If no arguments are provided, both pre- and post-unary operators are banned.
|
|
736
|
-
* If `"allow-post"` is provided, post-unary operators will be allowed.
|
|
737
|
-
*
|
|
738
|
-
* @example
|
|
739
|
-
* "increment-decrement": true
|
|
740
|
-
* "increment-decrement": [true,"allow-post"]
|
|
741
|
-
*
|
|
742
|
-
* @type style
|
|
743
|
-
*/
|
|
744
|
-
'increment-decrement'?: ("allow-post")[],
|
|
745
|
-
/**
|
|
746
|
-
* Enforces indentation with tabs or spaces.
|
|
747
|
-
*
|
|
748
|
-
* @rationale
|
|
749
|
-
* Using only one of tabs or spaces for indentation leads to more consistent editor behavior,
|
|
750
|
-
* cleaner diffs in version control, and easier programmatic manipulation.
|
|
751
|
-
*
|
|
752
|
-
* @options
|
|
753
|
-
* One of the following arguments must be provided:
|
|
754
|
-
*
|
|
755
|
-
* * `spaces` enforces consistent spaces.
|
|
756
|
-
* * `tabs` enforces consistent tabs.
|
|
757
|
-
*
|
|
758
|
-
* A second optional argument specifies indentation size:
|
|
759
|
-
*
|
|
760
|
-
* * `2` enforces 2 space indentation.
|
|
761
|
-
* * `4` enforces 4 space indentation.
|
|
762
|
-
*
|
|
763
|
-
* Indentation size is **required** for auto-fixing, but not for rule checking.
|
|
764
|
-
*
|
|
765
|
-
* **NOTE**: auto-fixing will only convert invalid indent whitespace to the desired type, it will not fix invalid whitespace sizes.
|
|
766
|
-
*
|
|
767
|
-
* @example
|
|
768
|
-
* "indent": [true,"spaces"]
|
|
769
|
-
* "indent": [true,"spaces",4]
|
|
770
|
-
* "indent": [true,"tabs",2]
|
|
771
|
-
*
|
|
772
|
-
* @type formatting
|
|
773
|
-
*/
|
|
774
|
-
'indent'?: ["tabs" | "spaces", 2 | 4],
|
|
775
|
-
/**
|
|
776
|
-
* Requires interface names to begin with a capital 'I'
|
|
777
|
-
*
|
|
778
|
-
* @rationale
|
|
779
|
-
* Makes it easy to differentiate interfaces from regular classes at a glance.
|
|
780
|
-
*
|
|
781
|
-
* @options
|
|
782
|
-
* One of the following two options must be provided:
|
|
783
|
-
*
|
|
784
|
-
* * `"always-prefix"` requires interface names to start with an "I"
|
|
785
|
-
* * `"never-prefix"` requires interface names to not have an "I" prefix
|
|
786
|
-
*
|
|
787
|
-
* @example
|
|
788
|
-
* "interface-name": [true,"always-prefix"]
|
|
789
|
-
* "interface-name": [true,"never-prefix"]
|
|
790
|
-
*
|
|
791
|
-
* @type style
|
|
792
|
-
*
|
|
793
|
-
* @typescriptOnly
|
|
794
|
-
*/
|
|
795
|
-
'interface-name'?: "always-prefix" | "never-prefix",
|
|
796
|
-
/**
|
|
797
|
-
* Prefer an interface declaration over a type literal (`type T = { ... }`)
|
|
798
|
-
*
|
|
799
|
-
* @rationale
|
|
800
|
-
* Interfaces are generally preferred over type literals because interfaces can be implemented, extended and merged.
|
|
801
|
-
*
|
|
802
|
-
* @options
|
|
803
|
-
* Not configurable.
|
|
804
|
-
*
|
|
805
|
-
* @example
|
|
806
|
-
* "interface-over-type-literal": true
|
|
807
|
-
*
|
|
808
|
-
* @type style
|
|
809
|
-
*
|
|
810
|
-
* @typescriptOnly
|
|
811
|
-
*/
|
|
812
|
-
'interface-over-type-literal'?: any[],
|
|
813
|
-
/**
|
|
814
|
-
* Disallows usage of `void` type outside of generic or return types.
|
|
815
|
-
* If `void` is used as return type, it shouldn't be a part of intersection/union type.
|
|
816
|
-
*
|
|
817
|
-
* @rationale
|
|
818
|
-
* The `void` type means "nothing" or that a function does not return any value,
|
|
819
|
-
* in contra with implicit `undefined` type which means that a function returns a value `undefined`.
|
|
820
|
-
* So "nothing" cannot be mixed with any other types.
|
|
821
|
-
* If you need this - use `undefined` type instead.
|
|
822
|
-
*
|
|
823
|
-
* @options
|
|
824
|
-
* If `allow-generics` is specified as `false`, then generic types will no longer be allowed to to be `void`.
|
|
825
|
-
* Alternately, provide an array of strings for `allow-generics` to exclusively allow generic types by those names.
|
|
826
|
-
*
|
|
827
|
-
* @example
|
|
828
|
-
* "invalid-void": true
|
|
829
|
-
* "invalid-void": [true,{"allow-generics":false}]
|
|
830
|
-
* "invalid-void": [true,{"allow-generics":["Promise","PromiseLike"]}]
|
|
831
|
-
*
|
|
832
|
-
* @type maintainability
|
|
833
|
-
*
|
|
834
|
-
* @typescriptOnly
|
|
835
|
-
*/
|
|
836
|
-
'invalid-void'?: {
|
|
837
|
-
'allow-generics'?: boolean | (string)[],
|
|
838
|
-
},
|
|
839
|
-
/**
|
|
840
|
-
* Enforces basic format rules for JSDoc comments.
|
|
841
|
-
*
|
|
842
|
-
* The following rules are enforced for JSDoc comments (comments starting with `/**`):
|
|
843
|
-
*
|
|
844
|
-
* * each line contains an asterisk and asterisks must be aligned
|
|
845
|
-
* * each asterisk must be followed by either a space or a newline (except for the first and the last)
|
|
846
|
-
* * the only characters before the asterisk on each line must be whitespace characters
|
|
847
|
-
* * one line comments must start with `/** ` and end with `* /`
|
|
848
|
-
* * multiline comments don't allow text after `/** ` in the first line (with option `"check-multiline-start"`)
|
|
849
|
-
*
|
|
850
|
-
* @rationale
|
|
851
|
-
* Helps maintain a consistent, readable style for JSDoc comments.
|
|
852
|
-
*
|
|
853
|
-
* @options
|
|
854
|
-
* You can optionally specify the option `"check-multiline-start"` to enforce the first line of a
|
|
855
|
-
* multiline JSDoc comment to be empty.
|
|
856
|
-
*
|
|
857
|
-
* @example
|
|
858
|
-
* "jsdoc-format": true
|
|
859
|
-
* "jsdoc-format": [true,"check-multiline-start"]
|
|
860
|
-
*
|
|
861
|
-
* @type formatting
|
|
862
|
-
*/
|
|
863
|
-
'jsdoc-format'?: ("check-multiline-start")[],
|
|
864
|
-
/**
|
|
865
|
-
* Only allows labels in sensible locations.
|
|
866
|
-
*
|
|
867
|
-
* This rule only allows labels to be on `do/for/while/switch` statements.
|
|
868
|
-
*
|
|
869
|
-
* @rationale
|
|
870
|
-
* Labels in JavaScript only can be used in conjunction with `break` or `continue`,
|
|
871
|
-
* constructs meant to be used for loop flow control. While you can theoretically use
|
|
872
|
-
* labels on any block statement in JS, it is considered poor code structure to do so.
|
|
873
|
-
*
|
|
874
|
-
* @options
|
|
875
|
-
* Not configurable.
|
|
876
|
-
*
|
|
877
|
-
* @example
|
|
878
|
-
* "label-position": true
|
|
879
|
-
*
|
|
880
|
-
* @type functionality
|
|
881
|
-
*/
|
|
882
|
-
'label-position'?: any[],
|
|
883
|
-
/**
|
|
884
|
-
* Enforces a consistent linebreak style.
|
|
885
|
-
*
|
|
886
|
-
* @options
|
|
887
|
-
* One of the following options must be provided:
|
|
888
|
-
*
|
|
889
|
-
* * `"LF"` requires LF (`\n`) linebreaks
|
|
890
|
-
* * `"CRLF"` requires CRLF (`\r\n`) linebreaks
|
|
891
|
-
*
|
|
892
|
-
* @example
|
|
893
|
-
* "linebreak-style": [true,"LF"]
|
|
894
|
-
* "linebreak-style": [true,"CRLF"]
|
|
895
|
-
*
|
|
896
|
-
* @type formatting
|
|
897
|
-
*/
|
|
898
|
-
'linebreak-style'?: "LF" | "CRLF",
|
|
899
|
-
/**
|
|
900
|
-
* Requires that a default import have the same name as the declaration it imports.
|
|
901
|
-
* Does nothing for anonymous default exports.
|
|
902
|
-
*
|
|
903
|
-
* @options
|
|
904
|
-
* Not configurable.
|
|
905
|
-
*
|
|
906
|
-
* @example
|
|
907
|
-
* "match-default-export-name": true
|
|
908
|
-
*
|
|
909
|
-
* @type style
|
|
910
|
-
*
|
|
911
|
-
* @typescriptOnly
|
|
912
|
-
*/
|
|
913
|
-
'match-default-export-name'?: any[],
|
|
914
|
-
/**
|
|
915
|
-
* A file may not contain more than the specified number of classes
|
|
916
|
-
*
|
|
917
|
-
* @rationale
|
|
918
|
-
* Ensures that files have a single responsibility so that that classes each exist in their own files
|
|
919
|
-
*
|
|
920
|
-
* @options
|
|
921
|
-
* The one required argument is an integer indicating the maximum number of classes that can appear in a
|
|
922
|
-
* file. An optional argument `"exclude-class-expressions"` can be provided to exclude class expressions
|
|
923
|
-
* from the overall class count.
|
|
924
|
-
*
|
|
925
|
-
* @example
|
|
926
|
-
* "max-classes-per-file": [true,1]
|
|
927
|
-
* "max-classes-per-file": [true,5,"exclude-class-expressions"]
|
|
928
|
-
*
|
|
929
|
-
* @type maintainability
|
|
930
|
-
*/
|
|
931
|
-
'max-classes-per-file'?: [number, "exclude-class-expressions"],
|
|
932
|
-
/**
|
|
933
|
-
* Requires files to remain under a certain number of lines
|
|
934
|
-
*
|
|
935
|
-
* @rationale
|
|
936
|
-
* Limiting the number of lines allowed in a file allows files to remain small,
|
|
937
|
-
* single purpose, and maintainable.
|
|
938
|
-
*
|
|
939
|
-
* @options
|
|
940
|
-
* An integer indicating the maximum number of lines.
|
|
941
|
-
*
|
|
942
|
-
* @example
|
|
943
|
-
* "max-file-line-count": [true,300]
|
|
944
|
-
*
|
|
945
|
-
* @type maintainability
|
|
946
|
-
*/
|
|
947
|
-
'max-file-line-count'?: number,
|
|
948
|
-
/**
|
|
949
|
-
* Requires lines to be under a certain max length.
|
|
950
|
-
*
|
|
951
|
-
* @rationale
|
|
952
|
-
* Limiting the length of a line of code improves code readability.
|
|
953
|
-
* It also makes comparing code side-by-side easier and improves compatibility with
|
|
954
|
-
* various editors, IDEs, and diff viewers.
|
|
955
|
-
*
|
|
956
|
-
* @options
|
|
957
|
-
* It can take one argument, which can be any of the following:
|
|
958
|
-
* * integer indicating maximum length of lines.
|
|
959
|
-
* * object with keys:
|
|
960
|
-
* * `limit` - number greater than 0 defining the max line length
|
|
961
|
-
* * `ignore-pattern` - string defining ignore pattern for this rule, being parsed by `new RegExp()`.
|
|
962
|
-
* For example:
|
|
963
|
-
* * `// ` pattern will ignore all in-line comments.
|
|
964
|
-
* * `^import ` pattern will ignore all import statements.
|
|
965
|
-
* * `^export {(.*?)}` pattern will ignore all multiple export statements.
|
|
966
|
-
* * `class [a-zA-Z]+ implements ` pattern will ignore all class declarations implementing interfaces.
|
|
967
|
-
* * `^import |^export {(.*?)}|class [a-zA-Z]+ implements |// ` pattern will ignore all the cases listed above.
|
|
968
|
-
* * `check-strings` - determines if strings should be checked, `false` by default.
|
|
969
|
-
* * `check-regex` - determines if regular expressions should be checked, `false` by default.
|
|
970
|
-
*
|
|
971
|
-
* @example
|
|
972
|
-
* "max-line-length": [true,120]
|
|
973
|
-
* "max-line-length": [true,{"limit":120,"ignore-pattern":"^import |^export {(.*?)}","check-strings":true,"check-regex":true}]
|
|
974
|
-
*
|
|
975
|
-
* @type formatting
|
|
976
|
-
*/
|
|
977
|
-
'max-line-length'?: (number | {
|
|
978
|
-
limit?: number,
|
|
979
|
-
'ignore-pattern'?: string,
|
|
980
|
-
'check-strings'?: boolean,
|
|
981
|
-
'check-regex'?: boolean,
|
|
982
|
-
})[],
|
|
983
|
-
/**
|
|
984
|
-
* Requires explicit visibility declarations for class members.
|
|
985
|
-
*
|
|
986
|
-
* @rationale
|
|
987
|
-
* Explicit visibility declarations can make code more readable and accessible for those new to TS.
|
|
988
|
-
*
|
|
989
|
-
* Other languages such as C# default to `private`, unlike TypeScript's default of `public`.
|
|
990
|
-
* Members lacking a visibility declaration may be an indication of an accidental leak of class internals.
|
|
991
|
-
*
|
|
992
|
-
* @options
|
|
993
|
-
* These arguments may be optionally provided:
|
|
994
|
-
*
|
|
995
|
-
* * `"no-public"` forbids public accessibility to be specified, because this is the default.
|
|
996
|
-
* * `"check-accessor"` enforces explicit visibility on get/set accessors
|
|
997
|
-
* * `"check-constructor"` enforces explicit visibility on constructors
|
|
998
|
-
* * `"check-parameter-property"` enforces explicit visibility on parameter properties
|
|
999
|
-
*
|
|
1000
|
-
* @example
|
|
1001
|
-
* "member-access": true
|
|
1002
|
-
* "member-access": [true,"no-public"]
|
|
1003
|
-
* "member-access": [true,"check-accessor"]
|
|
1004
|
-
*
|
|
1005
|
-
* @type typescript
|
|
1006
|
-
*
|
|
1007
|
-
* @typescriptOnly
|
|
1008
|
-
*/
|
|
1009
|
-
'member-access'?: ("no-public" | "check-accessor" | "check-constructor" | "check-parameter-property")[],
|
|
1010
|
-
/**
|
|
1011
|
-
* Enforces member ordering.
|
|
1012
|
-
*
|
|
1013
|
-
* @rationale
|
|
1014
|
-
* A consistent ordering for class members can make classes easier to read, navigate, and edit.
|
|
1015
|
-
*
|
|
1016
|
-
* A common opposite practice to `member-ordering` is to keep related groups of classes together.
|
|
1017
|
-
* Instead of creating classes with multiple separate groups, consider splitting class responsibilities
|
|
1018
|
-
* apart across multiple single-responsibility classes.
|
|
1019
|
-
*
|
|
1020
|
-
* @options
|
|
1021
|
-
* One argument, which is an object, must be provided. It should contain an `order` property.
|
|
1022
|
-
* The `order` property should have a value of one of the following strings:
|
|
1023
|
-
*
|
|
1024
|
-
* * `fields-first`
|
|
1025
|
-
* * `instance-sandwich`
|
|
1026
|
-
* * `statics-first`
|
|
1027
|
-
*
|
|
1028
|
-
* `fields-first` puts, in order of precedence:
|
|
1029
|
-
* * fields before constructors before methods
|
|
1030
|
-
* * static members before instance members
|
|
1031
|
-
* * public members before protected members before private members
|
|
1032
|
-
* `instance-sandwich` puts, in order of precedence:
|
|
1033
|
-
* * fields before constructors before methods
|
|
1034
|
-
* * static fields before instance fields, but static methods *after* instance methods
|
|
1035
|
-
* * public members before protected members before private members
|
|
1036
|
-
* `statics-first` puts, in order of precedence:
|
|
1037
|
-
* * static members before instance members
|
|
1038
|
-
* * public members before protected members before private members
|
|
1039
|
-
* * fields before methods
|
|
1040
|
-
* * instance fields before constructors before instance methods
|
|
1041
|
-
* * fields before constructors before methods
|
|
1042
|
-
* * public members before protected members before private members
|
|
1043
|
-
* Note that these presets, despite looking similar, can have subtly different behavior due to the order in which these
|
|
1044
|
-
* rules are specified. A fully expanded ordering can be found in the PRESETS constant in
|
|
1045
|
-
* https://github.com/palantir/tslint/blob/master/src/rules/memberOrderingRule.ts.
|
|
1046
|
-
* (You may need to check the version of the file corresponding to your version of tslint.)
|
|
1047
|
-
*
|
|
1048
|
-
* Alternatively, the value for `order` may be an array consisting of the following strings:
|
|
1049
|
-
*
|
|
1050
|
-
* * `public-static-field`
|
|
1051
|
-
* * `protected-static-field`
|
|
1052
|
-
* * `private-static-field`
|
|
1053
|
-
* * `public-static-method`
|
|
1054
|
-
* * `private-static-method`
|
|
1055
|
-
* * `protected-static-method`
|
|
1056
|
-
* * `public-instance-field`
|
|
1057
|
-
* * `protected-instance-field`
|
|
1058
|
-
* * `private-instance-field`
|
|
1059
|
-
* * `public-constructor`
|
|
1060
|
-
* * `protected-constructor`
|
|
1061
|
-
* * `private-constructor`
|
|
1062
|
-
* * `public-instance-method`
|
|
1063
|
-
* * `protected-instance-method`
|
|
1064
|
-
* * `private-instance-method`
|
|
1065
|
-
* * `public-static-accessor`
|
|
1066
|
-
* * `protected-static-accessor`
|
|
1067
|
-
* * `private-static-accessor`
|
|
1068
|
-
* * `public-instance-accessor`
|
|
1069
|
-
* * `protected-instance-accessor`
|
|
1070
|
-
* * `private-instance-accessor`
|
|
1071
|
-
*
|
|
1072
|
-
* You can also omit the access modifier to refer to "public-", "protected-", and "private-" all at once; for example, "static-field".
|
|
1073
|
-
*
|
|
1074
|
-
* You can also make your own categories by using an object instead of a string:
|
|
1075
|
-
*
|
|
1076
|
-
* {
|
|
1077
|
-
* "name": "static non-private",
|
|
1078
|
-
* "kinds": [
|
|
1079
|
-
* "public-static-field",
|
|
1080
|
-
* "protected-static-field",
|
|
1081
|
-
* "public-static-method",
|
|
1082
|
-
* "protected-static-method"
|
|
1083
|
-
* ]
|
|
1084
|
-
* }
|
|
1085
|
-
*
|
|
1086
|
-
* The 'alphabetize' option will enforce that members within the same category should be alphabetically sorted by name.
|
|
1087
|
-
* Computed property names are sorted before others but not sorted amongst each other.
|
|
1088
|
-
* Additionally getters will be sorted before setters (after alphabetization).
|
|
1089
|
-
*
|
|
1090
|
-
* @example
|
|
1091
|
-
* "member-ordering": [true,{"order":"fields-first"}]
|
|
1092
|
-
* "member-ordering": [true,{"alphabetize":true,"order":["public-static-field","public-instance-field","public-constructor","private-static-field","private-instance-field","private-constructor","public-instance-method","protected-instance-method","private-instance-method"]}]
|
|
1093
|
-
* "member-ordering": [true,{"order":[{"name":"static non-private","kinds":["public-static-field","protected-static-field","public-static-method","protected-static-method"]},"constructor"]}]
|
|
1094
|
-
*
|
|
1095
|
-
* @type typescript
|
|
1096
|
-
*/
|
|
1097
|
-
'member-ordering'?: {
|
|
1098
|
-
alphabetize?: boolean,
|
|
1099
|
-
order?: "fields-first" | "instance-sandwich" | "statics-first" | ("public-static-field" | "protected-static-field" | "private-static-field" | "public-static-method" | "private-static-method" | "protected-static-method" | "public-instance-field" | "protected-instance-field" | "private-instance-field" | "public-constructor" | "protected-constructor" | "private-constructor" | "public-instance-method" | "protected-instance-method" | "private-instance-method" | "public-static-accessor" | "protected-static-accessor" | "private-static-accessor" | "public-instance-accessor" | "protected-instance-accessor" | "private-instance-accessor")[],
|
|
1100
|
-
},
|
|
1101
|
-
/**
|
|
1102
|
-
* Requires parentheses when invoking a constructor via the `new` keyword.
|
|
1103
|
-
*
|
|
1104
|
-
* @rationale
|
|
1105
|
-
* Maintains stylistic consistency with other function calls.
|
|
1106
|
-
*
|
|
1107
|
-
* @options
|
|
1108
|
-
* Not configurable.
|
|
1109
|
-
*
|
|
1110
|
-
* @example
|
|
1111
|
-
* "new-parens": true
|
|
1112
|
-
*
|
|
1113
|
-
* @type formatting
|
|
1114
|
-
*/
|
|
1115
|
-
'new-parens'?: any[],
|
|
1116
|
-
/**
|
|
1117
|
-
* Enforces blank line before return when not the only line in the block.
|
|
1118
|
-
*
|
|
1119
|
-
* @rationale
|
|
1120
|
-
* Helps maintain a readable style in your codebase.
|
|
1121
|
-
*
|
|
1122
|
-
* @options
|
|
1123
|
-
* Not configurable.
|
|
1124
|
-
*
|
|
1125
|
-
* @example
|
|
1126
|
-
* "newline-before-return": true
|
|
1127
|
-
*
|
|
1128
|
-
* @type formatting
|
|
1129
|
-
*/
|
|
1130
|
-
'newline-before-return'?: unknown,
|
|
1131
|
-
/**
|
|
1132
|
-
* Requires that chained method calls be broken apart onto separate lines.
|
|
1133
|
-
*
|
|
1134
|
-
* @rationale
|
|
1135
|
-
* This style helps to keep code 'vertical', avoiding the need for side-scrolling in IDEs or text editors.
|
|
1136
|
-
*
|
|
1137
|
-
* @options
|
|
1138
|
-
* Not configurable
|
|
1139
|
-
*
|
|
1140
|
-
* @type style
|
|
1141
|
-
*/
|
|
1142
|
-
'newline-per-chained-call'?: any[],
|
|
1143
|
-
/**
|
|
1144
|
-
* Requires the use of `as Type` for type assertions instead of `<Type>`.
|
|
1145
|
-
*
|
|
1146
|
-
* @rationale
|
|
1147
|
-
* Both formats of type assertions have the same effect, but only `as` type assertions
|
|
1148
|
-
* work in `.tsx` files. This rule ensures that you have a consistent type assertion style
|
|
1149
|
-
* across your codebase.
|
|
1150
|
-
*
|
|
1151
|
-
* @options
|
|
1152
|
-
* Not configurable.
|
|
1153
|
-
*
|
|
1154
|
-
* @example
|
|
1155
|
-
* "no-angle-bracket-type-assertion": true
|
|
1156
|
-
*
|
|
1157
|
-
* @type style
|
|
1158
|
-
*
|
|
1159
|
-
* @typescriptOnly
|
|
1160
|
-
*/
|
|
1161
|
-
'no-angle-bracket-type-assertion'?: any[],
|
|
1162
|
-
/**
|
|
1163
|
-
* Disallows usages of `any` as a type declaration.
|
|
1164
|
-
*
|
|
1165
|
-
* @rationale
|
|
1166
|
-
* Using `any` as a type declaration nullifies the compile-time benefits of the type system.
|
|
1167
|
-
*
|
|
1168
|
-
* If you're dealing with data of unknown or "any" types, you shouldn't be accessing members of it.
|
|
1169
|
-
* Either add type annotations for properties that may exist or change the data type to the empty object type `{}`.
|
|
1170
|
-
*
|
|
1171
|
-
* Alternately, if you're creating storage or handling for consistent but unknown types, such as in data structures
|
|
1172
|
-
* or serialization, use `<T>` template types for generic type handling.
|
|
1173
|
-
*
|
|
1174
|
-
* Also see the `no-unsafe-any` rule.
|
|
1175
|
-
*
|
|
1176
|
-
* @options
|
|
1177
|
-
* If `"ignore-rest-args": true` is provided rest arguments will be ignored.
|
|
1178
|
-
*
|
|
1179
|
-
* @example
|
|
1180
|
-
* "no-any": true
|
|
1181
|
-
* "no-any": [true,{"ignore-rest-args":true}]
|
|
1182
|
-
*
|
|
1183
|
-
* @type typescript
|
|
1184
|
-
*
|
|
1185
|
-
* @typescriptOnly
|
|
1186
|
-
*/
|
|
1187
|
-
'no-any'?: {
|
|
1188
|
-
'ignore-rest-args'?: boolean,
|
|
1189
|
-
},
|
|
1190
|
-
/**
|
|
1191
|
-
* Disallows use of `arguments.callee`.
|
|
1192
|
-
*
|
|
1193
|
-
* @rationale
|
|
1194
|
-
* Using `arguments.callee` makes various performance optimizations impossible.
|
|
1195
|
-
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee)
|
|
1196
|
-
* for more details on why to avoid `arguments.callee`.
|
|
1197
|
-
*
|
|
1198
|
-
* @options
|
|
1199
|
-
* Not configurable.
|
|
1200
|
-
*
|
|
1201
|
-
* @example
|
|
1202
|
-
* "no-arg": true
|
|
1203
|
-
*
|
|
1204
|
-
* @type functionality
|
|
1205
|
-
*/
|
|
1206
|
-
'no-arg'?: any[],
|
|
1207
|
-
/**
|
|
1208
|
-
* Functions marked async must contain an await or return statement.
|
|
1209
|
-
*
|
|
1210
|
-
* @rationale
|
|
1211
|
-
* Marking a function as `async` without using `await` or returning a value inside it can lead to an unintended promise return and a larger transpiled output.
|
|
1212
|
-
* Often the function can be synchronous and the `async` keyword is there by mistake.
|
|
1213
|
-
* Return statements are allowed as sometimes it is desirable to wrap the returned value in a Promise.
|
|
1214
|
-
*
|
|
1215
|
-
* @options
|
|
1216
|
-
* Not configurable.
|
|
1217
|
-
*
|
|
1218
|
-
* @example
|
|
1219
|
-
* "no-async-without-await": true
|
|
1220
|
-
*
|
|
1221
|
-
* @type functionality
|
|
1222
|
-
*/
|
|
1223
|
-
'no-async-without-await'?: any[],
|
|
1224
|
-
/**
|
|
1225
|
-
* Disallows bitwise operators.
|
|
1226
|
-
*
|
|
1227
|
-
* Specifically, the following bitwise operators are banned:
|
|
1228
|
-
* `&`, `&=`, `|`, `|=`,
|
|
1229
|
-
* `^`, `^=`, `<<`, `<<=`,
|
|
1230
|
-
* `>>`, `>>=`, `>>>`, `>>>=`, and `~`.
|
|
1231
|
-
* This rule does not ban the use of `&` and `|` for intersection and union types.
|
|
1232
|
-
*
|
|
1233
|
-
* @rationale
|
|
1234
|
-
* Bitwise operators are often typos - for example `bool1 & bool2` instead of `bool1 && bool2`.
|
|
1235
|
-
* They also can be an indicator of overly clever code which decreases maintainability.
|
|
1236
|
-
*
|
|
1237
|
-
* @options
|
|
1238
|
-
* Not configurable.
|
|
1239
|
-
*
|
|
1240
|
-
* @example
|
|
1241
|
-
* "no-bitwise": true
|
|
1242
|
-
*
|
|
1243
|
-
* @type functionality
|
|
1244
|
-
*/
|
|
1245
|
-
'no-bitwise'?: any[],
|
|
1246
|
-
/**
|
|
1247
|
-
* Warns on comparison to a boolean literal, as in `x === true`.
|
|
1248
|
-
*
|
|
1249
|
-
* @rationale
|
|
1250
|
-
* Comparing boolean values to boolean literals is unnecessary, as those expressions will result in booleans too.
|
|
1251
|
-
* Just use the boolean values directly or negate them.
|
|
1252
|
-
*
|
|
1253
|
-
* @options
|
|
1254
|
-
* Not configurable.
|
|
1255
|
-
*
|
|
1256
|
-
* @example
|
|
1257
|
-
* "no-boolean-literal-compare": true
|
|
1258
|
-
*
|
|
1259
|
-
* @type style
|
|
1260
|
-
*
|
|
1261
|
-
* @typescriptOnly
|
|
1262
|
-
*/
|
|
1263
|
-
'no-boolean-literal-compare'?: any[],
|
|
1264
|
-
/**
|
|
1265
|
-
* Disallows any type of assignment in conditionals.
|
|
1266
|
-
*
|
|
1267
|
-
* This applies to `do-while`, `for`, `if`, and `while` statements and conditional (ternary) expressions.
|
|
1268
|
-
*
|
|
1269
|
-
* @rationale
|
|
1270
|
-
* Assignments in conditionals are often typos:
|
|
1271
|
-
* for example `if (var1 = var2)` instead of `if (var1 == var2)`.
|
|
1272
|
-
* They also can be an indicator of overly clever code which decreases maintainability.
|
|
1273
|
-
*
|
|
1274
|
-
* @options
|
|
1275
|
-
* Not configurable.
|
|
1276
|
-
*
|
|
1277
|
-
* @example
|
|
1278
|
-
* "no-conditional-assignment": true
|
|
1279
|
-
*
|
|
1280
|
-
* @type functionality
|
|
1281
|
-
*/
|
|
1282
|
-
'no-conditional-assignment'?: any[],
|
|
1283
|
-
/**
|
|
1284
|
-
* Disallows one or more blank lines in a row.
|
|
1285
|
-
*
|
|
1286
|
-
* @rationale
|
|
1287
|
-
* Helps maintain a readable style in your codebase.
|
|
1288
|
-
*
|
|
1289
|
-
* Extra blank lines take up extra space and add little to a semantic understanding of the code.
|
|
1290
|
-
* It can be harder to read through files when fewer components can fit into the screen.
|
|
1291
|
-
* If you find a file is so large you feel a need to split them up with extra blank lines or comments,
|
|
1292
|
-
* consider splitting your file into smaller files.
|
|
1293
|
-
*
|
|
1294
|
-
* @options
|
|
1295
|
-
* An optional number of maximum allowed sequential blanks can be specified. If no value
|
|
1296
|
-
* is provided, a default of 1 will be used.
|
|
1297
|
-
*
|
|
1298
|
-
* @example
|
|
1299
|
-
* "no-consecutive-blank-lines": true
|
|
1300
|
-
* "no-consecutive-blank-lines": [true,2]
|
|
1301
|
-
*
|
|
1302
|
-
* @type formatting
|
|
1303
|
-
*/
|
|
1304
|
-
'no-consecutive-blank-lines'?: number,
|
|
1305
|
-
/**
|
|
1306
|
-
* Bans the use of specified `console` methods.
|
|
1307
|
-
*
|
|
1308
|
-
* @rationale
|
|
1309
|
-
* In general, `console` methods aren't appropriate for production code.
|
|
1310
|
-
*
|
|
1311
|
-
* @options
|
|
1312
|
-
* A list of method names to ban. If no method names are provided, all console methods are banned.
|
|
1313
|
-
*
|
|
1314
|
-
* @example
|
|
1315
|
-
* "no-console": [true,"log","error"]
|
|
1316
|
-
*
|
|
1317
|
-
* @type functionality
|
|
1318
|
-
*/
|
|
1319
|
-
'no-console'?: (string)[],
|
|
1320
|
-
/**
|
|
1321
|
-
* Disallows access to the constructors of `String`, `Number`, and `Boolean`.
|
|
1322
|
-
*
|
|
1323
|
-
* Disallows constructor use such as `new Number(foo)` but does not disallow `Number(foo)`.
|
|
1324
|
-
*
|
|
1325
|
-
* @rationale
|
|
1326
|
-
* There is little reason to use `String`, `Number`, or `Boolean` as constructors.
|
|
1327
|
-
* In almost all cases, the regular function-call version is more appropriate.
|
|
1328
|
-
* [More details](http://stackoverflow.com/q/4719320/3124288) are available on StackOverflow.
|
|
1329
|
-
*
|
|
1330
|
-
* @options
|
|
1331
|
-
* Not configurable.
|
|
1332
|
-
*
|
|
1333
|
-
* @example
|
|
1334
|
-
* "no-construct": true
|
|
1335
|
-
*
|
|
1336
|
-
* @type functionality
|
|
1337
|
-
*/
|
|
1338
|
-
'no-construct'?: any[],
|
|
1339
|
-
/**
|
|
1340
|
-
* Disallows `debugger` statements.
|
|
1341
|
-
*
|
|
1342
|
-
* @rationale
|
|
1343
|
-
* In general, `debugger` statements aren't appropriate for production code.
|
|
1344
|
-
*
|
|
1345
|
-
* @options
|
|
1346
|
-
* Not configurable.
|
|
1347
|
-
*
|
|
1348
|
-
* @example
|
|
1349
|
-
* "no-debugger": true
|
|
1350
|
-
*
|
|
1351
|
-
* @type functionality
|
|
1352
|
-
*/
|
|
1353
|
-
'no-debugger'?: any[],
|
|
1354
|
-
/**
|
|
1355
|
-
* Disallows default exports in ES6-style modules.
|
|
1356
|
-
*
|
|
1357
|
-
* Use named exports instead.
|
|
1358
|
-
*
|
|
1359
|
-
* @rationale
|
|
1360
|
-
* Named imports/exports [promote clarity](https://github.com/palantir/tslint/issues/1182#issue-151780453).
|
|
1361
|
-
* In addition, current tooling differs on the correct way to handle default imports/exports.
|
|
1362
|
-
* Avoiding them all together can help avoid tooling bugs and conflicts.
|
|
1363
|
-
*
|
|
1364
|
-
* @options
|
|
1365
|
-
* Not configurable.
|
|
1366
|
-
*
|
|
1367
|
-
* @example
|
|
1368
|
-
* "no-default-export": true
|
|
1369
|
-
*
|
|
1370
|
-
* @type maintainability
|
|
1371
|
-
*/
|
|
1372
|
-
'no-default-export'?: any[],
|
|
1373
|
-
/**
|
|
1374
|
-
* Disallows importing default members from certain ES6-style modules.
|
|
1375
|
-
*
|
|
1376
|
-
* Import named members instead.
|
|
1377
|
-
*
|
|
1378
|
-
* @rationale
|
|
1379
|
-
* Named imports/exports [promote clarity](https://github.com/palantir/tslint/issues/1182#issue-151780453).
|
|
1380
|
-
* In addition, current tooling differs on the correct way to handle default imports/exports.
|
|
1381
|
-
* Avoiding them all together can help avoid tooling bugs and conflicts.
|
|
1382
|
-
*
|
|
1383
|
-
* The rule supposed to narrow the scope of your changes in the case of monorepo.
|
|
1384
|
-
* Say, you have packages `A`, `B`, `C` and `utils`, where `A`, `B`, `C` dependends on `utils`,
|
|
1385
|
-
* which is full of default exports.
|
|
1386
|
-
* `"no-default-export"` requires you to remove default _export_ from `utils`, which leads to changes
|
|
1387
|
-
* in packages `A`, `B`, `C`. It's harder to get merged bigger changeset by various reasons (harder to get your code approved
|
|
1388
|
-
* due to a number of required reviewers; longer build time due to a number of affected packages)
|
|
1389
|
-
* and could result in ignored `"no-default-export"` rule in `utils'`.
|
|
1390
|
-
*
|
|
1391
|
-
* Unlike `"no-default-export"`, the rule requires you to replace default _import_ with named only in `A` you work on,
|
|
1392
|
-
* and `utils` you import from.
|
|
1393
|
-
*
|
|
1394
|
-
* @options
|
|
1395
|
-
* optionsDescription
|
|
1396
|
-
*
|
|
1397
|
-
* @example
|
|
1398
|
-
* "no-default-import": [true,{"fromModules":"^palantir-|^_internal-*|^\\./|^\\.\\./"}]
|
|
1399
|
-
*
|
|
1400
|
-
* @type maintainability
|
|
1401
|
-
*/
|
|
1402
|
-
'no-default-import'?: ({
|
|
1403
|
-
fromModules: string,
|
|
1404
|
-
})[],
|
|
1405
|
-
/**
|
|
1406
|
-
* Disallows multiple import statements from the same module.
|
|
1407
|
-
*
|
|
1408
|
-
* @rationale
|
|
1409
|
-
* Using a single import statement per module will make the code clearer because you can see everything being imported
|
|
1410
|
-
* from that module on one line.
|
|
1411
|
-
*
|
|
1412
|
-
* @options
|
|
1413
|
-
* "allow-namespace-imports" allows you to import namespaces on separate lines.
|
|
1414
|
-
*
|
|
1415
|
-
* @example
|
|
1416
|
-
* "no-duplicate-imports": [true,{"allow-namespace-imports":true}]
|
|
1417
|
-
*
|
|
1418
|
-
* @type maintainability
|
|
1419
|
-
*/
|
|
1420
|
-
'no-duplicate-imports'?: {
|
|
1421
|
-
'allow-namespace-imports'?: boolean,
|
|
1422
|
-
},
|
|
1423
|
-
/**
|
|
1424
|
-
* Warns if 'super()' appears twice in a constructor.
|
|
1425
|
-
*
|
|
1426
|
-
* @rationale
|
|
1427
|
-
* The second call to 'super()' will fail at runtime.
|
|
1428
|
-
*
|
|
1429
|
-
* @options
|
|
1430
|
-
* Not configurable.
|
|
1431
|
-
*
|
|
1432
|
-
* @example
|
|
1433
|
-
* "no-duplicate-super": true
|
|
1434
|
-
*
|
|
1435
|
-
* @type functionality
|
|
1436
|
-
*/
|
|
1437
|
-
'no-duplicate-super'?: any[],
|
|
1438
|
-
/**
|
|
1439
|
-
* Prevents duplicate cases in switch statements.
|
|
1440
|
-
*
|
|
1441
|
-
* @example
|
|
1442
|
-
* "no-duplicate-switch-case": true
|
|
1443
|
-
*
|
|
1444
|
-
* @type functionality
|
|
1445
|
-
*/
|
|
1446
|
-
'no-duplicate-switch-case'?: any[],
|
|
1447
|
-
/**
|
|
1448
|
-
* Disallows duplicate variable declarations in the same block scope.
|
|
1449
|
-
*
|
|
1450
|
-
* This rule is only useful when using the `var` keyword -
|
|
1451
|
-
* the compiler will detect redeclarations of `let` and `const` variables.
|
|
1452
|
-
*
|
|
1453
|
-
* @rationale
|
|
1454
|
-
* A variable can be reassigned if necessary -
|
|
1455
|
-
* there's no good reason to have a duplicate variable declaration.
|
|
1456
|
-
*
|
|
1457
|
-
* @options
|
|
1458
|
-
* You can specify `"check-parameters"` to check for variables with the same name as a parameter.
|
|
1459
|
-
*
|
|
1460
|
-
* @example
|
|
1461
|
-
* "no-duplicate-variable": true
|
|
1462
|
-
* "no-duplicate-variable": [true,"check-parameters"]
|
|
1463
|
-
*
|
|
1464
|
-
* @type functionality
|
|
1465
|
-
*/
|
|
1466
|
-
'no-duplicate-variable'?: "check-parameters",
|
|
1467
|
-
/**
|
|
1468
|
-
* Bans usage of the delete operator with computed key expressions.
|
|
1469
|
-
*
|
|
1470
|
-
* @rationale
|
|
1471
|
-
* Deleting dynamically computed keys is dangerous and not well optimized.
|
|
1472
|
-
*
|
|
1473
|
-
* Also consider using a [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
|
|
1474
|
-
* or [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
|
|
1475
|
-
* if you're storing collections of objects.
|
|
1476
|
-
* Using `Object`s can cause occasional edge case bugs, such as if a key is named "hasOwnProperty".
|
|
1477
|
-
*
|
|
1478
|
-
* @options
|
|
1479
|
-
* Not configurable.
|
|
1480
|
-
*
|
|
1481
|
-
* @example
|
|
1482
|
-
* "no-dynamic-delete": true
|
|
1483
|
-
*
|
|
1484
|
-
* @type functionality
|
|
1485
|
-
*/
|
|
1486
|
-
'no-dynamic-delete'?: any[],
|
|
1487
|
-
/**
|
|
1488
|
-
* Forbids empty interfaces.
|
|
1489
|
-
*
|
|
1490
|
-
* @rationale
|
|
1491
|
-
* An empty interface is equivalent to its supertype (or `{}`).
|
|
1492
|
-
*
|
|
1493
|
-
* @options
|
|
1494
|
-
* Not configurable.
|
|
1495
|
-
*
|
|
1496
|
-
* @type typescript
|
|
1497
|
-
*
|
|
1498
|
-
* @typescriptOnly
|
|
1499
|
-
*/
|
|
1500
|
-
'no-empty-interface'?: any[],
|
|
1501
|
-
/**
|
|
1502
|
-
* Disallows empty blocks.
|
|
1503
|
-
*
|
|
1504
|
-
* Blocks with a comment inside are not considered empty.
|
|
1505
|
-
*
|
|
1506
|
-
* @rationale
|
|
1507
|
-
* Empty blocks are often indicators of missing code.
|
|
1508
|
-
*
|
|
1509
|
-
* @options
|
|
1510
|
-
* If `allow-empty-catch` is specified, then catch blocks are allowed to be empty.
|
|
1511
|
-
* If `allow-empty-functions` is specified, then function definitions are allowed to be empty.
|
|
1512
|
-
*
|
|
1513
|
-
* @example
|
|
1514
|
-
* "no-empty": true
|
|
1515
|
-
* "no-empty": [true,"allow-empty-catch"]
|
|
1516
|
-
* "no-empty": [true,"allow-empty-functions"]
|
|
1517
|
-
* "no-empty": [true,"allow-empty-catch","allow-empty-functions"]
|
|
1518
|
-
*
|
|
1519
|
-
* @type functionality
|
|
1520
|
-
*/
|
|
1521
|
-
'no-empty'?: ("allow-empty-catch" | "allow-empty-functions")[],
|
|
1522
|
-
/**
|
|
1523
|
-
* Disallows `eval` function invocations.
|
|
1524
|
-
*
|
|
1525
|
-
* @rationale
|
|
1526
|
-
* `eval()` is dangerous as it allows arbitrary code execution with full privileges. There are
|
|
1527
|
-
* [alternatives](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)
|
|
1528
|
-
* for most of the use cases for `eval()`.
|
|
1529
|
-
*
|
|
1530
|
-
* @options
|
|
1531
|
-
* Not configurable.
|
|
1532
|
-
*
|
|
1533
|
-
* @example
|
|
1534
|
-
* "no-eval": true
|
|
1535
|
-
*
|
|
1536
|
-
* @type functionality
|
|
1537
|
-
*/
|
|
1538
|
-
'no-eval'?: any[],
|
|
1539
|
-
/**
|
|
1540
|
-
* Promises returned by functions must be handled appropriately.
|
|
1541
|
-
*
|
|
1542
|
-
* Unhandled Promises can cause unexpected behavior, such as resolving at unexpected times.
|
|
1543
|
-
*
|
|
1544
|
-
* @rationale
|
|
1545
|
-
* Creating a Promise and not storing or returning it may let other code run independently of its result.
|
|
1546
|
-
* This can cause unexpected and/or non-deterministic behavior depending on external timing factors.
|
|
1547
|
-
*
|
|
1548
|
-
* It's typically better to return Promises from functions that start them, then handle them in calling code.
|
|
1549
|
-
*
|
|
1550
|
-
* Use `no-unused-expression` in addition to this rule to reveal even more floating promises.
|
|
1551
|
-
*
|
|
1552
|
-
* @options
|
|
1553
|
-
* A list of 'string' names of any additional classes that should also be handled as Promises.
|
|
1554
|
-
*
|
|
1555
|
-
* @example
|
|
1556
|
-
* "no-floating-promises": true
|
|
1557
|
-
* "no-floating-promises": [true,"JQueryPromise"]
|
|
1558
|
-
*
|
|
1559
|
-
* @type functionality
|
|
1560
|
-
*
|
|
1561
|
-
* @typescriptOnly
|
|
1562
|
-
*/
|
|
1563
|
-
'no-floating-promises'?: unknown,
|
|
1564
|
-
/**
|
|
1565
|
-
* Disallows iterating over an array with a for-in loop.
|
|
1566
|
-
*
|
|
1567
|
-
* A for-in loop (`for (var k in o)`) iterates over the properties of an Object.
|
|
1568
|
-
*
|
|
1569
|
-
* While it is legal to use for-in loops with array types, it is not common.
|
|
1570
|
-
* for-in will iterate over the indices of the array as strings, omitting any "holes" in
|
|
1571
|
-
* the array.
|
|
1572
|
-
*
|
|
1573
|
-
* More common is to use for-of, which iterates over the values of an array.
|
|
1574
|
-
* If you want to iterate over the indices, alternatives include:
|
|
1575
|
-
*
|
|
1576
|
-
* array.forEach((value, index) => { ... });
|
|
1577
|
-
* for (const [index, value] of array.entries()) { ... }
|
|
1578
|
-
* for (let i = 0; i < array.length; i++) { ... }
|
|
1579
|
-
*
|
|
1580
|
-
* @options
|
|
1581
|
-
* Not configurable.
|
|
1582
|
-
*
|
|
1583
|
-
* @example
|
|
1584
|
-
* "no-for-in-array": true
|
|
1585
|
-
*
|
|
1586
|
-
* @type functionality
|
|
1587
|
-
*/
|
|
1588
|
-
'no-for-in-array'?: any[],
|
|
1589
|
-
/**
|
|
1590
|
-
* Ban the usage of for...in statements.
|
|
1591
|
-
*
|
|
1592
|
-
* @rationale
|
|
1593
|
-
* for...in statements are legacy JavaScript syntax which usually require a verbose `hasOwnProperty` check inside their loop body. These statements can be fully replaced with for...of statements in modern JS & TS.
|
|
1594
|
-
*
|
|
1595
|
-
* @options
|
|
1596
|
-
* Not configurable.
|
|
1597
|
-
*
|
|
1598
|
-
* @example
|
|
1599
|
-
* "no-for-in": true
|
|
1600
|
-
*
|
|
1601
|
-
* @type typescript
|
|
1602
|
-
*/
|
|
1603
|
-
'no-for-in'?: any[],
|
|
1604
|
-
/**
|
|
1605
|
-
* Disallows importing modules that are not listed as dependency in the project's package.json
|
|
1606
|
-
*
|
|
1607
|
-
* Disallows importing transient dependencies and modules installed above your package's root directory.
|
|
1608
|
-
*
|
|
1609
|
-
* @options
|
|
1610
|
-
* By default the rule looks at `"dependencies"` and `"peerDependencies"`.
|
|
1611
|
-
* By adding the `"dev"` option the rule also looks at `"devDependencies"`.
|
|
1612
|
-
* By adding the `"optional"` option the rule also looks at `"optionalDependencies"`.
|
|
1613
|
-
* An array of whitelisted modules can be added to skip checking their existence in package.json.
|
|
1614
|
-
*
|
|
1615
|
-
* @example
|
|
1616
|
-
* "no-implicit-dependencies": true
|
|
1617
|
-
* "no-implicit-dependencies": [true,"dev"]
|
|
1618
|
-
* "no-implicit-dependencies": [true,"optional"]
|
|
1619
|
-
* "no-implicit-dependencies": [true,["src","app"]]
|
|
1620
|
-
*
|
|
1621
|
-
* @type functionality
|
|
1622
|
-
*/
|
|
1623
|
-
'no-implicit-dependencies'?: ["dev" | "optional", any[]],
|
|
1624
|
-
/**
|
|
1625
|
-
* Avoid import statements with side-effect.
|
|
1626
|
-
*
|
|
1627
|
-
* @rationale
|
|
1628
|
-
* Imports with side effects may have behavior which is hard for static verification.
|
|
1629
|
-
*
|
|
1630
|
-
* @options
|
|
1631
|
-
* One argument may be optionally provided:
|
|
1632
|
-
*
|
|
1633
|
-
* * `ignore-module` allows to specify a regex and ignore modules which it matches.
|
|
1634
|
-
*
|
|
1635
|
-
* @example
|
|
1636
|
-
* "no-import-side-effect": true
|
|
1637
|
-
* "no-import-side-effect": [true,{"ignore-module":"(\\.html|\\.css)$"}]
|
|
1638
|
-
*
|
|
1639
|
-
* @type typescript
|
|
1640
|
-
*/
|
|
1641
|
-
'no-import-side-effect'?: ({
|
|
1642
|
-
'ignore-module'?: string,
|
|
1643
|
-
})[],
|
|
1644
|
-
/**
|
|
1645
|
-
* Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean.
|
|
1646
|
-
*
|
|
1647
|
-
* @rationale
|
|
1648
|
-
* Explicit types where they can be easily inferred by the compiler make code more verbose.
|
|
1649
|
-
*
|
|
1650
|
-
* @options
|
|
1651
|
-
* Two arguments may be optionally provided:
|
|
1652
|
-
*
|
|
1653
|
-
* * `ignore-params` allows specifying an inferrable type annotation for function params.
|
|
1654
|
-
* This can be useful when combining with the `typedef` rule.
|
|
1655
|
-
* * `ignore-properties` allows specifying an inferrable type annotation for class properties.
|
|
1656
|
-
*
|
|
1657
|
-
* @example
|
|
1658
|
-
* "no-inferrable-types": true
|
|
1659
|
-
* "no-inferrable-types": [true,"ignore-params"]
|
|
1660
|
-
* "no-inferrable-types": [true,"ignore-params","ignore-properties"]
|
|
1661
|
-
*
|
|
1662
|
-
* @type typescript
|
|
1663
|
-
*
|
|
1664
|
-
* @typescriptOnly
|
|
1665
|
-
*/
|
|
1666
|
-
'no-inferrable-types'?: ("ignore-params" | "ignore-properties")[],
|
|
1667
|
-
/**
|
|
1668
|
-
* Disallow type inference of {} (empty object type) at function and constructor call sites
|
|
1669
|
-
*
|
|
1670
|
-
* @rationale
|
|
1671
|
-
* Prior to TypeScript 3.4, generic type parameters for functions and constructors are inferred as
|
|
1672
|
-
* `{}` (the empty object type) by default when no type parameter is explicitly supplied or when
|
|
1673
|
-
* the compiler cannot infer a more specific type.
|
|
1674
|
-
* This is often undesirable as the call is meant to be of a more specific type.
|
|
1675
|
-
*
|
|
1676
|
-
* @options
|
|
1677
|
-
* Not configurable.
|
|
1678
|
-
*
|
|
1679
|
-
* @example
|
|
1680
|
-
* "no-inferred-empty-object-type": true
|
|
1681
|
-
*
|
|
1682
|
-
* @type functionality
|
|
1683
|
-
*
|
|
1684
|
-
* @typescriptOnly
|
|
1685
|
-
*/
|
|
1686
|
-
'no-inferred-empty-object-type'?: any[],
|
|
1687
|
-
/**
|
|
1688
|
-
* Disallows internal `module`
|
|
1689
|
-
*
|
|
1690
|
-
* @rationale
|
|
1691
|
-
* Using `module` leads to a confusion of concepts with external modules. Use the newer `namespace` keyword instead.
|
|
1692
|
-
*
|
|
1693
|
-
* @options
|
|
1694
|
-
* Not configurable.
|
|
1695
|
-
*
|
|
1696
|
-
* @example
|
|
1697
|
-
* "no-internal-module": true
|
|
1698
|
-
*
|
|
1699
|
-
* @type typescript
|
|
1700
|
-
*
|
|
1701
|
-
* @typescriptOnly
|
|
1702
|
-
*/
|
|
1703
|
-
'no-internal-module'?: any[],
|
|
1704
|
-
/**
|
|
1705
|
-
* Warns on use of `${` in non-template strings.
|
|
1706
|
-
*
|
|
1707
|
-
* @rationale
|
|
1708
|
-
* Interpolation will only work for template strings.
|
|
1709
|
-
*
|
|
1710
|
-
* @options
|
|
1711
|
-
* Not configurable.
|
|
1712
|
-
*
|
|
1713
|
-
* @example
|
|
1714
|
-
* "no-invalid-template-strings": true
|
|
1715
|
-
*
|
|
1716
|
-
* @type functionality
|
|
1717
|
-
*/
|
|
1718
|
-
'no-invalid-template-strings'?: any[],
|
|
1719
|
-
/**
|
|
1720
|
-
* Disallows using the `this` keyword outside of classes.
|
|
1721
|
-
*
|
|
1722
|
-
* @rationale
|
|
1723
|
-
* See [the rule's author's rationale here.](https://github.com/palantir/tslint/pull/1105#issue-147549402)
|
|
1724
|
-
*
|
|
1725
|
-
* @options
|
|
1726
|
-
* One argument may be optionally provided:
|
|
1727
|
-
*
|
|
1728
|
-
* * `check-function-in-method` disallows using the `this` keyword in functions within class methods.
|
|
1729
|
-
*
|
|
1730
|
-
* @example
|
|
1731
|
-
* "no-invalid-this": true
|
|
1732
|
-
* "no-invalid-this": [true,"check-function-in-method"]
|
|
1733
|
-
*
|
|
1734
|
-
* @type functionality
|
|
1735
|
-
*/
|
|
1736
|
-
'no-invalid-this'?: ("check-function-in-method")[],
|
|
1737
|
-
/**
|
|
1738
|
-
* Disallow irregular whitespace within a file, including strings and comments.
|
|
1739
|
-
*
|
|
1740
|
-
* @options
|
|
1741
|
-
* Not configurable.
|
|
1742
|
-
*
|
|
1743
|
-
* @example
|
|
1744
|
-
* "no-irregular-whitespace": true
|
|
1745
|
-
*
|
|
1746
|
-
* @type formatting
|
|
1747
|
-
*/
|
|
1748
|
-
'no-irregular-whitespace'?: any[],
|
|
1749
|
-
/**
|
|
1750
|
-
* Disallows the use constant number values outside of variable assignments.
|
|
1751
|
-
* When no list of allowed values is specified, -1, 0 and 1 are allowed by default.
|
|
1752
|
-
*
|
|
1753
|
-
* @rationale
|
|
1754
|
-
* Magic numbers should be avoided as they often lack documentation.
|
|
1755
|
-
* Forcing them to be stored in variables gives them implicit documentation.
|
|
1756
|
-
*
|
|
1757
|
-
* @options
|
|
1758
|
-
* Options may either be a list of numbers to ignore (not consider 'magic'), or an object containing up to two properties:
|
|
1759
|
-
* * `allowed-numbers` as the list of numbers to ignore.
|
|
1760
|
-
* * `ignore-jsx` to specify that 'magic' numbers should be allowed as JSX attributes.
|
|
1761
|
-
*
|
|
1762
|
-
* @example
|
|
1763
|
-
* "no-magic-numbers": [true,1,2,3]
|
|
1764
|
-
* "no-magic-numbers": [true,{"allowed-numbers":[1,2,3],"ignore-jsx":true}]
|
|
1765
|
-
*
|
|
1766
|
-
* @type typescript
|
|
1767
|
-
*/
|
|
1768
|
-
'no-magic-numbers'?: {
|
|
1769
|
-
type?: { [key: string]: unknown },
|
|
1770
|
-
'allowed-numbers'?: any[],
|
|
1771
|
-
'ignore-jsx'?: boolean,
|
|
1772
|
-
},
|
|
1773
|
-
/**
|
|
1774
|
-
* Disallows mergeable namespaces in the same file.
|
|
1775
|
-
*
|
|
1776
|
-
* @options
|
|
1777
|
-
* Not configurable.
|
|
1778
|
-
*
|
|
1779
|
-
* @example
|
|
1780
|
-
* "no-mergeable-namespace": true
|
|
1781
|
-
*
|
|
1782
|
-
* @type maintainability
|
|
1783
|
-
*
|
|
1784
|
-
* @typescriptOnly
|
|
1785
|
-
*/
|
|
1786
|
-
'no-mergeable-namespace'?: any[],
|
|
1787
|
-
/**
|
|
1788
|
-
* Warns on apparent attempts to define constructors for interfaces or `new` for classes.
|
|
1789
|
-
*
|
|
1790
|
-
* @rationale
|
|
1791
|
-
* Interfaces in TypeScript aren't meant to describe constructors on their implementations.
|
|
1792
|
-
* The `new` descriptor is primarily for describing JavaScript libraries.
|
|
1793
|
-
* If you're trying to describe a function known to be a class, it's typically better to `declare class`.
|
|
1794
|
-
*
|
|
1795
|
-
* @options
|
|
1796
|
-
* Not configurable.
|
|
1797
|
-
*
|
|
1798
|
-
* @example
|
|
1799
|
-
* "no-misused-new": true
|
|
1800
|
-
*
|
|
1801
|
-
* @type functionality
|
|
1802
|
-
*
|
|
1803
|
-
* @typescriptOnly
|
|
1804
|
-
*/
|
|
1805
|
-
'no-misused-new'?: any[],
|
|
1806
|
-
/**
|
|
1807
|
-
* Disallows use of internal `module`s and `namespace`s.
|
|
1808
|
-
*
|
|
1809
|
-
* This rule still allows the use of `declare module ... {}`
|
|
1810
|
-
*
|
|
1811
|
-
* @rationale
|
|
1812
|
-
* ES6-style external modules are the standard way to modularize code.
|
|
1813
|
-
* Using `module {}` and `namespace {}` are outdated ways to organize TypeScript code.
|
|
1814
|
-
*
|
|
1815
|
-
* @options
|
|
1816
|
-
* One argument may be optionally provided:
|
|
1817
|
-
*
|
|
1818
|
-
* * `allow-declarations` allows `declare namespace ... {}` to describe external APIs.
|
|
1819
|
-
*
|
|
1820
|
-
* @example
|
|
1821
|
-
* "no-namespace": true
|
|
1822
|
-
* "no-namespace": [true,"allow-declarations"]
|
|
1823
|
-
*
|
|
1824
|
-
* @type typescript
|
|
1825
|
-
*
|
|
1826
|
-
* @typescriptOnly
|
|
1827
|
-
*/
|
|
1828
|
-
'no-namespace'?: ("allow-declarations")[],
|
|
1829
|
-
/**
|
|
1830
|
-
* Disallows non-null assertions using the `!` postfix operator.
|
|
1831
|
-
*
|
|
1832
|
-
* @rationale
|
|
1833
|
-
* Using non-null assertion cancels the benefits of the strict null checking mode.
|
|
1834
|
-
*
|
|
1835
|
-
* Instead of assuming objects exist:
|
|
1836
|
-
*
|
|
1837
|
-
* ```
|
|
1838
|
-
* function foo(instance: MyClass | undefined) {
|
|
1839
|
-
* instance!.doWork();
|
|
1840
|
-
* }
|
|
1841
|
-
* ```
|
|
1842
|
-
*
|
|
1843
|
-
* Either inform the strict type system that the object must exist:
|
|
1844
|
-
*
|
|
1845
|
-
* ```
|
|
1846
|
-
* function foo(instance: MyClass) {
|
|
1847
|
-
* instance.doWork();
|
|
1848
|
-
* }
|
|
1849
|
-
* ```
|
|
1850
|
-
*
|
|
1851
|
-
* Or verify that the instance exists, which will inform the type checker:
|
|
1852
|
-
*
|
|
1853
|
-
* ```
|
|
1854
|
-
* function foo(instance: MyClass | undefined) {
|
|
1855
|
-
* if (instance !== undefined) {
|
|
1856
|
-
* instance.doWork();
|
|
1857
|
-
* }
|
|
1858
|
-
* }
|
|
1859
|
-
* ```
|
|
1860
|
-
*
|
|
1861
|
-
* @options
|
|
1862
|
-
* Not configurable.
|
|
1863
|
-
*
|
|
1864
|
-
* @example
|
|
1865
|
-
* "no-non-null-assertion": true
|
|
1866
|
-
*
|
|
1867
|
-
* @type typescript
|
|
1868
|
-
*
|
|
1869
|
-
* @typescriptOnly
|
|
1870
|
-
*/
|
|
1871
|
-
'no-non-null-assertion'?: any[],
|
|
1872
|
-
/**
|
|
1873
|
-
* Disallows use of the `null` keyword literal.
|
|
1874
|
-
*
|
|
1875
|
-
* @rationale
|
|
1876
|
-
* Instead of having the dual concepts of `null` and`undefined` in a codebase,
|
|
1877
|
-
* this rule ensures that only `undefined` is used.
|
|
1878
|
-
*
|
|
1879
|
-
* JavaScript originally intended `undefined` to refer to a value that doesn't yet exist,
|
|
1880
|
-
* while `null` was meant to refer to a value that does exist but points to nothing.
|
|
1881
|
-
* That's confusing.
|
|
1882
|
-
* `undefined` is the default value when object members don't exist, and is the return value
|
|
1883
|
-
* for newer native collection APIs such as `Map.get` when collection values don't exist.
|
|
1884
|
-
*
|
|
1885
|
-
* ```
|
|
1886
|
-
* const myObject = {};
|
|
1887
|
-
* myObject.doesNotExist; // undefined
|
|
1888
|
-
* ```
|
|
1889
|
-
*
|
|
1890
|
-
* ```
|
|
1891
|
-
* const myMap = new Map<string, number>();
|
|
1892
|
-
* myMap.get("doesNotExist"); // undefined
|
|
1893
|
-
* ```
|
|
1894
|
-
*
|
|
1895
|
-
* To remove confusion over the two similar values, it's better to stick with just `undefined`.
|
|
1896
|
-
*
|
|
1897
|
-
* @options
|
|
1898
|
-
* Not configurable.
|
|
1899
|
-
*
|
|
1900
|
-
* @example
|
|
1901
|
-
* "no-null-keyword": true
|
|
1902
|
-
*
|
|
1903
|
-
* @type functionality
|
|
1904
|
-
*/
|
|
1905
|
-
'no-null-keyword'?: any[],
|
|
1906
|
-
/**
|
|
1907
|
-
* Disallows explicitly declared or implicitly returned union types with both `null` and
|
|
1908
|
-
* `undefined` as members.
|
|
1909
|
-
*
|
|
1910
|
-
* @rationale
|
|
1911
|
-
* A union type that includes both `null` and `undefined` is either redundant or fragile.
|
|
1912
|
-
* Enforcing the choice between the two allows the `triple-equals` rule to exist without
|
|
1913
|
-
* exceptions, and is essentially a more flexible version of the `no-null-keyword` rule.
|
|
1914
|
-
* Optional parameters are not considered to have the type `undefined`.
|
|
1915
|
-
*
|
|
1916
|
-
* @options
|
|
1917
|
-
* Not configurable.
|
|
1918
|
-
*
|
|
1919
|
-
* @example
|
|
1920
|
-
* "no-null-undefined-union": true
|
|
1921
|
-
*
|
|
1922
|
-
* @type functionality
|
|
1923
|
-
*
|
|
1924
|
-
* @typescriptOnly
|
|
1925
|
-
*/
|
|
1926
|
-
'no-null-undefined-union'?: any[],
|
|
1927
|
-
/**
|
|
1928
|
-
* Forbids an object literal to appear in a type assertion expression.
|
|
1929
|
-
* Casting to `any` or to `unknown` is still allowed.
|
|
1930
|
-
*
|
|
1931
|
-
* @rationale
|
|
1932
|
-
* Always prefer `const x: T = { ... };` to `const x = { ... } as T;`.
|
|
1933
|
-
* The type assertion in the latter case is either unnecessary or hides an error.
|
|
1934
|
-
* The compiler will warn for excess properties with this syntax, but not missing required fields.
|
|
1935
|
-
* For example: `const x: { foo: number } = {}` will fail to compile, but
|
|
1936
|
-
* `const x = {} as { foo: number }` will succeed.
|
|
1937
|
-
* Additionally, the const assertion `const x = { foo: 1 } as const`,
|
|
1938
|
-
* introduced in TypeScript 3.4, is considered beneficial and is ignored by this rule.
|
|
1939
|
-
*
|
|
1940
|
-
* @options
|
|
1941
|
-
* One option may be configured:
|
|
1942
|
-
*
|
|
1943
|
-
* * `allow-arguments` allows type assertions to be used on object literals inside call expressions.
|
|
1944
|
-
*
|
|
1945
|
-
* @example
|
|
1946
|
-
* "no-object-literal-type-assertion": true
|
|
1947
|
-
* "no-object-literal-type-assertion": [true,{"allow-arguments":true}]
|
|
1948
|
-
*
|
|
1949
|
-
* @type functionality
|
|
1950
|
-
*
|
|
1951
|
-
* @typescriptOnly
|
|
1952
|
-
*/
|
|
1953
|
-
'no-object-literal-type-assertion'?: {
|
|
1954
|
-
'allow-arguments'?: boolean,
|
|
1955
|
-
},
|
|
1956
|
-
/**
|
|
1957
|
-
* Disallows parameter properties in class constructors.
|
|
1958
|
-
*
|
|
1959
|
-
* @rationale
|
|
1960
|
-
* Parameter properties can be confusing to those new to TS as they are less explicit
|
|
1961
|
-
* than other ways of declaring and initializing class members.
|
|
1962
|
-
*
|
|
1963
|
-
* It can be cleaner to keep member variable declarations in one list directly above the class constructor
|
|
1964
|
-
* (instead of mixed between direct class members and constructor parameter properties).
|
|
1965
|
-
*
|
|
1966
|
-
* @options
|
|
1967
|
-
* Not configurable.
|
|
1968
|
-
*
|
|
1969
|
-
* @example
|
|
1970
|
-
* "no-parameter-properties": true
|
|
1971
|
-
*
|
|
1972
|
-
* @type style
|
|
1973
|
-
*
|
|
1974
|
-
* @typescriptOnly
|
|
1975
|
-
*/
|
|
1976
|
-
'no-parameter-properties'?: any[],
|
|
1977
|
-
/**
|
|
1978
|
-
* Disallows reassigning parameters.
|
|
1979
|
-
*
|
|
1980
|
-
* @options
|
|
1981
|
-
* Not configurable.
|
|
1982
|
-
*
|
|
1983
|
-
* @example
|
|
1984
|
-
* "no-parameter-reassignment": true
|
|
1985
|
-
*
|
|
1986
|
-
* @type typescript
|
|
1987
|
-
*/
|
|
1988
|
-
'no-parameter-reassignment'?: any[],
|
|
1989
|
-
/**
|
|
1990
|
-
* Warns for Promises that are used for boolean conditions.
|
|
1991
|
-
*
|
|
1992
|
-
* For the most accurate findings, set `"strict": true` in your `tsconfig.json`.
|
|
1993
|
-
*
|
|
1994
|
-
* It's recommended to enable the following rules as well:
|
|
1995
|
-
* * [`strict-boolean-expressions`](https://palantir.github.io/tslint/rules/strict-boolean-expressions/)
|
|
1996
|
-
* * [`strict-type-predicates`](https://palantir.github.io/tslint/rules/strict-type-predicates/)
|
|
1997
|
-
* * [`no-floating-promises`](https://palantir.github.io/tslint/rules/no-floating-promises/)
|
|
1998
|
-
*
|
|
1999
|
-
* @rationale
|
|
2000
|
-
* There are no situations where one would like to check whether a variable's value is truthy if its type
|
|
2001
|
-
* only is Promise.
|
|
2002
|
-
* This may only occur when the typings are incorrect or the variable has a union type
|
|
2003
|
-
* (like Promise | undefined), of which the latter is allowed.
|
|
2004
|
-
*
|
|
2005
|
-
* This rule prevents common bugs from forgetting to 'await' a Promise.
|
|
2006
|
-
*
|
|
2007
|
-
* @options
|
|
2008
|
-
* A list of 'string' names of any additional classes that should also be treated as Promises.
|
|
2009
|
-
* For example, if you are using a class called 'Future' that implements the Thenable interface,
|
|
2010
|
-
* you might tell the rule to consider type references with the name 'Future' as valid Promise-like
|
|
2011
|
-
* types. Note that this rule doesn't check for type assignability or compatibility; it just checks
|
|
2012
|
-
* type reference names.
|
|
2013
|
-
*
|
|
2014
|
-
* @example
|
|
2015
|
-
* "no-promise-as-boolean": true
|
|
2016
|
-
* "no-promise-as-boolean": [true,{"OPTION_PROMISE_CLASSES":["Thenable"]}]
|
|
2017
|
-
*
|
|
2018
|
-
* @type functionality
|
|
2019
|
-
*
|
|
2020
|
-
* @typescriptOnly
|
|
2021
|
-
*/
|
|
2022
|
-
'no-promise-as-boolean'?: {
|
|
2023
|
-
'promise-classes'?: (string)[],
|
|
2024
|
-
},
|
|
2025
|
-
/**
|
|
2026
|
-
* Forbids JSDoc which duplicates TypeScript functionality.
|
|
2027
|
-
*
|
|
2028
|
-
* @options
|
|
2029
|
-
* Not configurable.
|
|
2030
|
-
*
|
|
2031
|
-
* @example
|
|
2032
|
-
* "no-redundant-jsdoc": true
|
|
2033
|
-
*
|
|
2034
|
-
* @type style
|
|
2035
|
-
*
|
|
2036
|
-
* @typescriptOnly
|
|
2037
|
-
*/
|
|
2038
|
-
'no-redundant-jsdoc'?: any[],
|
|
2039
|
-
/**
|
|
2040
|
-
* Don't `<reference types="foo" />` if you import `foo` anyway.
|
|
2041
|
-
*
|
|
2042
|
-
* @options
|
|
2043
|
-
* Not configurable.
|
|
2044
|
-
*
|
|
2045
|
-
* @type style
|
|
2046
|
-
*
|
|
2047
|
-
* @typescriptOnly
|
|
2048
|
-
*/
|
|
2049
|
-
'no-reference-import'?: any[],
|
|
2050
|
-
/**
|
|
2051
|
-
* Disallows `/// <reference path=>` imports (use ES6-style imports instead).
|
|
2052
|
-
*
|
|
2053
|
-
* @rationale
|
|
2054
|
-
* Using `/// <reference path=>` comments to load other files is outdated.
|
|
2055
|
-
* Use ES6-style imports to reference other files.
|
|
2056
|
-
*
|
|
2057
|
-
* @options
|
|
2058
|
-
* Not configurable.
|
|
2059
|
-
*
|
|
2060
|
-
* @example
|
|
2061
|
-
* "no-reference": true
|
|
2062
|
-
*
|
|
2063
|
-
* @type typescript
|
|
2064
|
-
*/
|
|
2065
|
-
'no-reference'?: any[],
|
|
2066
|
-
/**
|
|
2067
|
-
* Disallows invocation of `require()`.
|
|
2068
|
-
*
|
|
2069
|
-
* @rationale
|
|
2070
|
-
* Prefer the newer ES6-style imports over `require()`.
|
|
2071
|
-
*
|
|
2072
|
-
* @options
|
|
2073
|
-
* Not configurable.
|
|
2074
|
-
*
|
|
2075
|
-
* @example
|
|
2076
|
-
* "no-require-imports": true
|
|
2077
|
-
*
|
|
2078
|
-
* @type maintainability
|
|
2079
|
-
*/
|
|
2080
|
-
'no-require-imports'?: any[],
|
|
2081
|
-
/**
|
|
2082
|
-
* Disallow specific global variables.
|
|
2083
|
-
*
|
|
2084
|
-
* Disallowing usage of specific global variables can be useful if you want to allow
|
|
2085
|
-
* a set of global variables by enabling an environment, but still want to disallow
|
|
2086
|
-
* some of those.
|
|
2087
|
-
*
|
|
2088
|
-
* @rationale
|
|
2089
|
-
* ```ts
|
|
2090
|
-
* function broken(evt: Event) {
|
|
2091
|
-
* // Meant to do something with `evt` but typed it incorrectly.
|
|
2092
|
-
* Event.target; // compiler error
|
|
2093
|
-
* event.target; // should be a lint failure
|
|
2094
|
-
* }
|
|
2095
|
-
*
|
|
2096
|
-
* Early Internet Explorer versions exposed the current DOM event as a global variable 'event',
|
|
2097
|
-
* but using this variable has been considered a bad practice for a long time.
|
|
2098
|
-
* Restricting this will make sure this variable isn’t used in browser code.
|
|
2099
|
-
* ```
|
|
2100
|
-
*
|
|
2101
|
-
* @options
|
|
2102
|
-
* This rule takes a list of strings, where each string is a global to be restricted.
|
|
2103
|
-
* `event`, `name` and `length` are restricted by default.
|
|
2104
|
-
*
|
|
2105
|
-
* @example
|
|
2106
|
-
* "no-restricted-globals": [true,"name","length","event"]
|
|
2107
|
-
*
|
|
2108
|
-
* @type functionality
|
|
2109
|
-
*/
|
|
2110
|
-
'no-restricted-globals'?: unknown,
|
|
2111
|
-
/**
|
|
2112
|
-
* Disallows unnecessary `return await`.
|
|
2113
|
-
*
|
|
2114
|
-
* @rationale
|
|
2115
|
-
* An async function always wraps the return value in a Promise.
|
|
2116
|
-
* Using `return await` just adds extra time before the overreaching promise is resolved without changing the semantics.
|
|
2117
|
-
*
|
|
2118
|
-
* @options
|
|
2119
|
-
* Not configurable.
|
|
2120
|
-
*
|
|
2121
|
-
* @example
|
|
2122
|
-
* "no-return-await": true
|
|
2123
|
-
*
|
|
2124
|
-
* @type functionality
|
|
2125
|
-
*/
|
|
2126
|
-
'no-return-await'?: any[],
|
|
2127
|
-
/**
|
|
2128
|
-
* Disallows shadowing variable declarations.
|
|
2129
|
-
*
|
|
2130
|
-
* @rationale
|
|
2131
|
-
* When a variable in a local scope and a variable in the containing scope have the same name, shadowing occurs.
|
|
2132
|
-
* Shadowing makes it impossible to access the variable in the containing scope and
|
|
2133
|
-
* obscures to what value an identifier actually refers. Compare the following snippets:
|
|
2134
|
-
*
|
|
2135
|
-
* ```
|
|
2136
|
-
* const a = 'no shadow';
|
|
2137
|
-
* function print() {
|
|
2138
|
-
* console.log(a);
|
|
2139
|
-
* }
|
|
2140
|
-
* print(); // logs 'no shadow'.
|
|
2141
|
-
* ```
|
|
2142
|
-
*
|
|
2143
|
-
* ```
|
|
2144
|
-
* const a = 'no shadow';
|
|
2145
|
-
* function print() {
|
|
2146
|
-
* const a = 'shadow'; // TSLint will complain here.
|
|
2147
|
-
* console.log(a);
|
|
2148
|
-
* }
|
|
2149
|
-
* print(); // logs 'shadow'.
|
|
2150
|
-
* ```
|
|
2151
|
-
*
|
|
2152
|
-
* ESLint has [an equivalent rule](https://eslint.org/docs/rules/no-shadow).
|
|
2153
|
-
* For more background information, refer to
|
|
2154
|
-
* [this MDN closure doc](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures#Lexical_scoping).
|
|
2155
|
-
*
|
|
2156
|
-
* @options
|
|
2157
|
-
* You can optionally pass an object to disable checking for certain kinds of declarations.
|
|
2158
|
-
* Possible keys are `"class"`, `"enum"`, `"function"`, `"import"`, `"interface"`, `"namespace"`, `"typeAlias"`
|
|
2159
|
-
* and `"typeParameter"`. You can also pass `"underscore`" to ignore variable names that begin with `_`.
|
|
2160
|
-
* Just set the value to `false` for the check you want to disable.
|
|
2161
|
-
* All checks default to `true`, i.e. are enabled by default.
|
|
2162
|
-
* Note that you cannot disable variables and parameters.
|
|
2163
|
-
*
|
|
2164
|
-
* The option `"temporalDeadZone"` defaults to `true` which shows errors when shadowing block scoped declarations in their
|
|
2165
|
-
* temporal dead zone. When set to `false` parameters, classes, enums and variables declared
|
|
2166
|
-
* with `let` or `const` are not considered shadowed if the shadowing occurs within their
|
|
2167
|
-
* [temporal dead zone](http://jsrocks.org/2015/01/temporal-dead-zone-tdz-demystified).
|
|
2168
|
-
*
|
|
2169
|
-
* The following example shows how the `"temporalDeadZone"` option changes the linting result:
|
|
2170
|
-
*
|
|
2171
|
-
* ```ts
|
|
2172
|
-
* function fn(value) {
|
|
2173
|
-
* if (value) {
|
|
2174
|
-
* const tmp = value; // no error on this line if "temporalDeadZone" is false
|
|
2175
|
-
* return tmp;
|
|
2176
|
-
* }
|
|
2177
|
-
* let tmp = undefined;
|
|
2178
|
-
* if (!value) {
|
|
2179
|
-
* const tmp = value; // this line always contains an error
|
|
2180
|
-
* return tmp;
|
|
2181
|
-
* }
|
|
2182
|
-
* }
|
|
2183
|
-
* ```
|
|
2184
|
-
*
|
|
2185
|
-
* @example
|
|
2186
|
-
* "no-shadowed-variable": true
|
|
2187
|
-
* "no-shadowed-variable": [true,{"class":true,"enum":true,"function":true,"interface":false,"namespace":true,"typeAlias":false,"typeParameter":false,"underscore":false}]
|
|
2188
|
-
*
|
|
2189
|
-
* @type functionality
|
|
2190
|
-
*/
|
|
2191
|
-
'no-shadowed-variable'?: {
|
|
2192
|
-
class?: boolean,
|
|
2193
|
-
enum?: boolean,
|
|
2194
|
-
function?: boolean,
|
|
2195
|
-
import?: boolean,
|
|
2196
|
-
interface?: boolean,
|
|
2197
|
-
namespace?: boolean,
|
|
2198
|
-
typeAlias?: boolean,
|
|
2199
|
-
typeParameter?: boolean,
|
|
2200
|
-
temporalDeadZone?: boolean,
|
|
2201
|
-
underscore?: boolean,
|
|
2202
|
-
},
|
|
2203
|
-
/**
|
|
2204
|
-
* Forbids array literals to contain missing elements.
|
|
2205
|
-
*
|
|
2206
|
-
* @rationale
|
|
2207
|
-
* Missing elements are probably an accidentally duplicated comma.
|
|
2208
|
-
*
|
|
2209
|
-
* @options
|
|
2210
|
-
* Not configurable.
|
|
2211
|
-
*
|
|
2212
|
-
* @example
|
|
2213
|
-
* "no-sparse-arrays": true
|
|
2214
|
-
*
|
|
2215
|
-
* @type functionality
|
|
2216
|
-
*/
|
|
2217
|
-
'no-sparse-arrays'?: any[],
|
|
2218
|
-
/**
|
|
2219
|
-
* Forbids unnecessary string literal property access.
|
|
2220
|
-
* Allows `obj["prop-erty"]` (can't be a regular property access).
|
|
2221
|
-
* Disallows `obj["property"]` (should be `obj.property`).
|
|
2222
|
-
*
|
|
2223
|
-
* @rationale
|
|
2224
|
-
* If `--noImplicitAny` is turned off,
|
|
2225
|
-
* property access via a string literal will be 'any' if the property does not exist.
|
|
2226
|
-
*
|
|
2227
|
-
* @options
|
|
2228
|
-
* Not configurable.
|
|
2229
|
-
*
|
|
2230
|
-
* @example
|
|
2231
|
-
* "no-string-literal": true
|
|
2232
|
-
*
|
|
2233
|
-
* @type functionality
|
|
2234
|
-
*/
|
|
2235
|
-
'no-string-literal'?: any[],
|
|
2236
|
-
/**
|
|
2237
|
-
* Flags throwing plain strings or concatenations of strings.
|
|
2238
|
-
*
|
|
2239
|
-
* @rationale
|
|
2240
|
-
* Example – Doing it right
|
|
2241
|
-
*
|
|
2242
|
-
* ```ts
|
|
2243
|
-
* // throwing an Error from typical function, whether sync or async
|
|
2244
|
-
* if (!productToAdd) {
|
|
2245
|
-
* throw new Error("How can I add new product when no value provided?");
|
|
2246
|
-
* }
|
|
2247
|
-
* ```
|
|
2248
|
-
*
|
|
2249
|
-
* Example – Anti Pattern
|
|
2250
|
-
*
|
|
2251
|
-
* ```ts
|
|
2252
|
-
* // throwing a string lacks any stack trace information and other important data properties
|
|
2253
|
-
* if (!productToAdd) {
|
|
2254
|
-
* throw ("How can I add new product when no value provided?");
|
|
2255
|
-
* }
|
|
2256
|
-
* ```
|
|
2257
|
-
*
|
|
2258
|
-
* Only Error objects contain a `.stack` member equivalent to the current stack trace.
|
|
2259
|
-
* Primitives such as strings do not.
|
|
2260
|
-
*
|
|
2261
|
-
* @options
|
|
2262
|
-
* Not configurable.
|
|
2263
|
-
*
|
|
2264
|
-
* @example
|
|
2265
|
-
* "no-string-throw": true
|
|
2266
|
-
*
|
|
2267
|
-
* @type functionality
|
|
2268
|
-
*/
|
|
2269
|
-
'no-string-throw'?: any[],
|
|
2270
|
-
/**
|
|
2271
|
-
* Disallows importing any submodule.
|
|
2272
|
-
*
|
|
2273
|
-
* @rationale
|
|
2274
|
-
* Submodules of some packages are treated as private APIs and the import
|
|
2275
|
-
* paths may change without deprecation periods. It's best to stick with
|
|
2276
|
-
* top-level package exports.
|
|
2277
|
-
*
|
|
2278
|
-
* @options
|
|
2279
|
-
* A list of whitelisted package or submodule names.
|
|
2280
|
-
*
|
|
2281
|
-
* @example
|
|
2282
|
-
* "no-submodule-imports": true
|
|
2283
|
-
* "no-submodule-imports": [true,"rxjs","@angular/platform-browser","@angular/core/testing"]
|
|
2284
|
-
*
|
|
2285
|
-
* @type functionality
|
|
2286
|
-
*/
|
|
2287
|
-
'no-submodule-imports'?: (string)[],
|
|
2288
|
-
/**
|
|
2289
|
-
* Disallows falling through case statements.
|
|
2290
|
-
*
|
|
2291
|
-
* For example, the following is not allowed:
|
|
2292
|
-
*
|
|
2293
|
-
* ```ts
|
|
2294
|
-
* switch(foo) {
|
|
2295
|
-
* case 1:
|
|
2296
|
-
* someFunc(foo);
|
|
2297
|
-
* case 2:
|
|
2298
|
-
* someOtherFunc(foo);
|
|
2299
|
-
* }
|
|
2300
|
-
* ```
|
|
2301
|
-
*
|
|
2302
|
-
* However, fall through is allowed when case statements are consecutive or
|
|
2303
|
-
* a magic `/* falls through * /` comment is present. The following is valid:
|
|
2304
|
-
*
|
|
2305
|
-
* ```ts
|
|
2306
|
-
* switch(foo) {
|
|
2307
|
-
* case 1:
|
|
2308
|
-
* someFunc(foo);
|
|
2309
|
-
* /* falls through * /
|
|
2310
|
-
* case 2:
|
|
2311
|
-
* case 3:
|
|
2312
|
-
* someOtherFunc(foo);
|
|
2313
|
-
* }
|
|
2314
|
-
* ```
|
|
2315
|
-
*
|
|
2316
|
-
* @rationale
|
|
2317
|
-
* Fall though in switch statements is often unintentional and a bug.
|
|
2318
|
-
*
|
|
2319
|
-
* @options
|
|
2320
|
-
* Not configurable.
|
|
2321
|
-
*
|
|
2322
|
-
* @example
|
|
2323
|
-
* "no-switch-case-fall-through": true
|
|
2324
|
-
*
|
|
2325
|
-
* @type functionality
|
|
2326
|
-
*/
|
|
2327
|
-
'no-switch-case-fall-through'?: any[],
|
|
2328
|
-
/**
|
|
2329
|
-
* Enforces that relational/equality binary operators does not take two equal variables/literals as operands.
|
|
2330
|
-
* Expression like 3 === 3, someVar === someVar, "1" > "1" are either a tautology or contradiction, and will produce an error.
|
|
2331
|
-
*
|
|
2332
|
-
* @rationale
|
|
2333
|
-
* Clean redundant code and unnecessary comparison of objects and literals.
|
|
2334
|
-
*
|
|
2335
|
-
* @options
|
|
2336
|
-
* Not configurable.
|
|
2337
|
-
*
|
|
2338
|
-
* @example
|
|
2339
|
-
* "no-tautology-expression": true
|
|
2340
|
-
*
|
|
2341
|
-
* @type functionality
|
|
2342
|
-
*/
|
|
2343
|
-
'no-tautology-expression'?: any[],
|
|
2344
|
-
/**
|
|
2345
|
-
* Disallows unnecessary references to `this`.
|
|
2346
|
-
*
|
|
2347
|
-
* @rationale
|
|
2348
|
-
* Assigning a variable to `this` instead of properly using arrow lambdas may be a symptom of pre-ES6 practices
|
|
2349
|
-
* or not managing scope well.
|
|
2350
|
-
*
|
|
2351
|
-
* Instead of storing a reference to `this` and using it inside a `function () {`:
|
|
2352
|
-
*
|
|
2353
|
-
* ```
|
|
2354
|
-
* const self = this;
|
|
2355
|
-
*
|
|
2356
|
-
* setTimeout(function () {
|
|
2357
|
-
* self.doWork();
|
|
2358
|
-
* });
|
|
2359
|
-
* ```
|
|
2360
|
-
*
|
|
2361
|
-
* Use `() =>` arrow lambdas, as they preserve `this` scope for you:
|
|
2362
|
-
*
|
|
2363
|
-
* ```
|
|
2364
|
-
* setTimeout(() => {
|
|
2365
|
-
* this.doWork();
|
|
2366
|
-
* });
|
|
2367
|
-
* ```
|
|
2368
|
-
*
|
|
2369
|
-
* @options
|
|
2370
|
-
* Two options may be provided on an object:
|
|
2371
|
-
*
|
|
2372
|
-
* * `allow-destructuring` allows using destructuring to access members of `this` (e.g. `{ foo, bar } = this;`).
|
|
2373
|
-
* * `allowed-names` may be specified as a list of regular expressions to match allowed variable names.
|
|
2374
|
-
*
|
|
2375
|
-
* @example
|
|
2376
|
-
* "no-this-assignment": true
|
|
2377
|
-
* "no-this-assignment": [true,{"allowed-names":["^self$"],"allow-destructuring":true}]
|
|
2378
|
-
*
|
|
2379
|
-
* @type functionality
|
|
2380
|
-
*/
|
|
2381
|
-
'no-this-assignment'?: {
|
|
2382
|
-
'allow-destructuring'?: boolean,
|
|
2383
|
-
'allowed-names'?: unknown,
|
|
2384
|
-
},
|
|
2385
|
-
/**
|
|
2386
|
-
* Disallows trailing whitespace at the end of a line.
|
|
2387
|
-
*
|
|
2388
|
-
* @rationale
|
|
2389
|
-
* Keeps version control diffs clean as it prevents accidental whitespace from being committed.
|
|
2390
|
-
*
|
|
2391
|
-
* @options
|
|
2392
|
-
* Possible settings are:
|
|
2393
|
-
*
|
|
2394
|
-
* * `"ignore-template-strings"`: Allows trailing whitespace in template strings.
|
|
2395
|
-
* * `"ignore-comments"`: Allows trailing whitespace in comments.
|
|
2396
|
-
* * `"ignore-jsdoc"`: Allows trailing whitespace only in JSDoc comments.
|
|
2397
|
-
* * `"ignore-blank-lines"`: Allows trailing whitespace on empty lines.
|
|
2398
|
-
*
|
|
2399
|
-
* @example
|
|
2400
|
-
* "no-trailing-whitespace": true
|
|
2401
|
-
* "no-trailing-whitespace": [true,"ignore-comments"]
|
|
2402
|
-
* "no-trailing-whitespace": [true,"ignore-jsdoc"]
|
|
2403
|
-
*
|
|
2404
|
-
* @type formatting
|
|
2405
|
-
*/
|
|
2406
|
-
'no-trailing-whitespace'?: ("ignore-comments" | "ignore-jsdoc" | "ignore-template-strings" | "ignore-blank-lines")[],
|
|
2407
|
-
/**
|
|
2408
|
-
* Warns when a method is used outside of a method call.
|
|
2409
|
-
*
|
|
2410
|
-
* @rationale
|
|
2411
|
-
* Class functions don't preserve the class scope when passed as standalone variables.
|
|
2412
|
-
* For example, this code will log the global scope (`window`/`global`), not the class instance:
|
|
2413
|
-
*
|
|
2414
|
-
* ```
|
|
2415
|
-
* class MyClass {
|
|
2416
|
-
* public log(): void {
|
|
2417
|
-
* console.log(this);
|
|
2418
|
-
* }
|
|
2419
|
-
* }
|
|
2420
|
-
*
|
|
2421
|
-
* const instance = new MyClass();
|
|
2422
|
-
* const log = instance.log;
|
|
2423
|
-
*
|
|
2424
|
-
* log();
|
|
2425
|
-
* ```
|
|
2426
|
-
*
|
|
2427
|
-
* You need to either use an arrow lambda (`() => {...}`) or call the function with the correct scope.
|
|
2428
|
-
*
|
|
2429
|
-
* ```
|
|
2430
|
-
* class MyClass {
|
|
2431
|
-
* public logArrowBound = (): void => {
|
|
2432
|
-
* console.log(bound);
|
|
2433
|
-
* };
|
|
2434
|
-
*
|
|
2435
|
-
* public logManualBind(): void {
|
|
2436
|
-
* console.log(this);
|
|
2437
|
-
* }
|
|
2438
|
-
* }
|
|
2439
|
-
*
|
|
2440
|
-
* const instance = new MyClass();
|
|
2441
|
-
* const logArrowBound = instance.logArrowBound;
|
|
2442
|
-
* const logManualBind = instance.logManualBind.bind(instance);
|
|
2443
|
-
*
|
|
2444
|
-
* logArrowBound();
|
|
2445
|
-
* logManualBind();
|
|
2446
|
-
* ```
|
|
2447
|
-
*
|
|
2448
|
-
* @options
|
|
2449
|
-
* You may additionally pass "ignore-static" to ignore static methods, or an options object.
|
|
2450
|
-
*
|
|
2451
|
-
* The object may have the following properties:
|
|
2452
|
-
*
|
|
2453
|
-
* * "ignore-static" - to ignore static methods.
|
|
2454
|
-
* * "allow-delete" - ignore methods referenced in a delete expression.
|
|
2455
|
-
* * "allow-typeof" - ignore methods referenced in a typeof expression.
|
|
2456
|
-
* * "whitelist" - ignore method references in parameters of specifed function calls.
|
|
2457
|
-
*
|
|
2458
|
-
* @example
|
|
2459
|
-
* "no-unbound-method": true
|
|
2460
|
-
* "no-unbound-method": [true,"ignore-static"]
|
|
2461
|
-
* "no-unbound-method": [true,{"ignore-static":true,"whitelist":["expect"],"allow-typeof":true}]
|
|
2462
|
-
*
|
|
2463
|
-
* @type functionality
|
|
2464
|
-
*
|
|
2465
|
-
* @typescriptOnly
|
|
2466
|
-
*/
|
|
2467
|
-
'no-unbound-method'?: "ignore-static" | {
|
|
2468
|
-
'allow-delete'?: boolean,
|
|
2469
|
-
'allow-typeof'?: boolean,
|
|
2470
|
-
'ignore-static'?: boolean,
|
|
2471
|
-
whitelist?: (string)[],
|
|
2472
|
-
},
|
|
2473
|
-
/**
|
|
2474
|
-
* Replaces `x => f(x)` with just `f`.
|
|
2475
|
-
* To catch more cases, enable `only-arrow-functions` and `arrow-return-shorthand` too.
|
|
2476
|
-
*
|
|
2477
|
-
* @rationale
|
|
2478
|
-
* There's generally no reason to wrap a function with a callback wrapper if it's directly called anyway.
|
|
2479
|
-
* Doing so creates extra inline lambdas that slow the runtime down.
|
|
2480
|
-
*
|
|
2481
|
-
* @options
|
|
2482
|
-
* Not configurable.
|
|
2483
|
-
*
|
|
2484
|
-
* @example
|
|
2485
|
-
* "no-unnecessary-callback-wrapper": true
|
|
2486
|
-
*
|
|
2487
|
-
* @type style
|
|
2488
|
-
*/
|
|
2489
|
-
'no-unnecessary-callback-wrapper'?: any[],
|
|
2490
|
-
/**
|
|
2491
|
-
* Disallows classes that are not strictly necessary.
|
|
2492
|
-
*
|
|
2493
|
-
* @rationale
|
|
2494
|
-
* Users who come from a Java-style OO language may wrap
|
|
2495
|
-
* their utility functions in an extra class, instead of
|
|
2496
|
-
* putting them at the top level.
|
|
2497
|
-
*
|
|
2498
|
-
* @options
|
|
2499
|
-
* Three arguments may be optionally provided:
|
|
2500
|
-
*
|
|
2501
|
-
* * `"allow-constructor-only"` ignores classes whose members are constructors.
|
|
2502
|
-
* * `"allow-empty-class"` ignores `class DemoClass {}`.
|
|
2503
|
-
* * `"allow-static-only"` ignores classes whose members are static.
|
|
2504
|
-
*
|
|
2505
|
-
* @example
|
|
2506
|
-
* "no-unnecessary-class": true
|
|
2507
|
-
* "no-unnecessary-class": ["allow-empty-class","allow-constructor-only"]
|
|
2508
|
-
*
|
|
2509
|
-
* @type functionality
|
|
2510
|
-
*/
|
|
2511
|
-
'no-unnecessary-class'?: (string)[],
|
|
2512
|
-
/**
|
|
2513
|
-
* Forbids a 'var'/'let' statement or destructuring initializer to be initialized to 'undefined'.
|
|
2514
|
-
*
|
|
2515
|
-
* @rationale
|
|
2516
|
-
* Values in JavaScript default to `undefined`.
|
|
2517
|
-
* There's no need to do so manually.
|
|
2518
|
-
*
|
|
2519
|
-
* @options
|
|
2520
|
-
* Not configurable.
|
|
2521
|
-
*
|
|
2522
|
-
* @example
|
|
2523
|
-
* "no-unnecessary-initializer": true
|
|
2524
|
-
*
|
|
2525
|
-
* @type style
|
|
2526
|
-
*/
|
|
2527
|
-
'no-unnecessary-initializer'?: any[],
|
|
2528
|
-
/**
|
|
2529
|
-
* Warns when a namespace qualifier (`A.x`) is unnecessary.
|
|
2530
|
-
*
|
|
2531
|
-
* @options
|
|
2532
|
-
* Not configurable.
|
|
2533
|
-
*
|
|
2534
|
-
* @example
|
|
2535
|
-
* "no-unnecessary-qualifier": true
|
|
2536
|
-
*
|
|
2537
|
-
* @type style
|
|
2538
|
-
*
|
|
2539
|
-
* @typescriptOnly
|
|
2540
|
-
*/
|
|
2541
|
-
'no-unnecessary-qualifier'?: any[],
|
|
2542
|
-
/**
|
|
2543
|
-
* Warns if a type assertion does not change the type of an expression.
|
|
2544
|
-
*
|
|
2545
|
-
* @options
|
|
2546
|
-
* A list of whitelisted assertion types to ignore
|
|
2547
|
-
*
|
|
2548
|
-
* @type typescript
|
|
2549
|
-
*
|
|
2550
|
-
* @typescriptOnly
|
|
2551
|
-
*/
|
|
2552
|
-
'no-unnecessary-type-assertion'?: unknown,
|
|
2553
|
-
/**
|
|
2554
|
-
* Warns when using an expression of type 'any' in a dynamic way.
|
|
2555
|
-
* Uses are only allowed if they would work for `{} | null | undefined`.
|
|
2556
|
-
* Downcasting to unknown is always safe.
|
|
2557
|
-
* Type casts and tests are allowed.
|
|
2558
|
-
* Expressions that work on all values (such as `"" + x`) are allowed.
|
|
2559
|
-
*
|
|
2560
|
-
* @rationale
|
|
2561
|
-
* If you're dealing with data of unknown or "any" types, you shouldn't be accessing members of it.
|
|
2562
|
-
* Either add type annotations for properties that may exist or change the data type to the empty object type `{}`.
|
|
2563
|
-
*
|
|
2564
|
-
* Alternately, if you're creating storage or handling for consistent but unknown types, such as in data structures
|
|
2565
|
-
* or serialization, use `<T>` template types for generic type handling.
|
|
2566
|
-
*
|
|
2567
|
-
* Also see the `no-any` rule.
|
|
2568
|
-
*
|
|
2569
|
-
* @options
|
|
2570
|
-
* Not configurable.
|
|
2571
|
-
*
|
|
2572
|
-
* @example
|
|
2573
|
-
* "no-unsafe-any": true
|
|
2574
|
-
*
|
|
2575
|
-
* @type functionality
|
|
2576
|
-
*
|
|
2577
|
-
* @typescriptOnly
|
|
2578
|
-
*/
|
|
2579
|
-
'no-unsafe-any'?: any[],
|
|
2580
|
-
/**
|
|
2581
|
-
* Disallows control flow statements, such as `return`, `continue`,
|
|
2582
|
-
* `break` and `throws` in finally blocks.
|
|
2583
|
-
*
|
|
2584
|
-
* @rationale
|
|
2585
|
-
* When used inside `finally` blocks, control flow statements,
|
|
2586
|
-
* such as `return`, `continue`, `break` and `throws`
|
|
2587
|
-
* override any other control flow statements in the same try/catch scope.
|
|
2588
|
-
* This is confusing and unexpected behavior.
|
|
2589
|
-
*
|
|
2590
|
-
* @options
|
|
2591
|
-
* Not configurable.
|
|
2592
|
-
*
|
|
2593
|
-
* @example
|
|
2594
|
-
* "no-unsafe-finally": true
|
|
2595
|
-
*
|
|
2596
|
-
* @type functionality
|
|
2597
|
-
*/
|
|
2598
|
-
'no-unsafe-finally'?: any[],
|
|
2599
|
-
/**
|
|
2600
|
-
* Disallows unused expression statements.
|
|
2601
|
-
*
|
|
2602
|
-
* Unused expressions are expression statements which are not assignments or function calls
|
|
2603
|
-
* (and thus usually no-ops).
|
|
2604
|
-
*
|
|
2605
|
-
* @rationale
|
|
2606
|
-
* Detects potential errors where an assignment or function call was intended.
|
|
2607
|
-
*
|
|
2608
|
-
* @options
|
|
2609
|
-
* Three arguments may be optionally provided:
|
|
2610
|
-
*
|
|
2611
|
-
* * `allow-fast-null-checks` allows to use logical operators to perform fast null checks and perform
|
|
2612
|
-
* method or function calls for side effects (e.g. `e && e.preventDefault()`).
|
|
2613
|
-
* * `allow-new` allows 'new' expressions for side effects (e.g. `new ModifyGlobalState();`.
|
|
2614
|
-
* * `allow-tagged-template` allows tagged templates for side effects (e.g. `this.add\`foo\`;`.
|
|
2615
|
-
*
|
|
2616
|
-
* @example
|
|
2617
|
-
* "no-unused-expression": true
|
|
2618
|
-
* "no-unused-expression": [true,"allow-fast-null-checks"]
|
|
2619
|
-
*
|
|
2620
|
-
* @type functionality
|
|
2621
|
-
*/
|
|
2622
|
-
'no-unused-expression'?: ("allow-fast-null-checks" | "allow-new" | "allow-tagged-template")[],
|
|
2623
|
-
/**
|
|
2624
|
-
* Disallows unused imports, variables, functions and
|
|
2625
|
-
* private class members. Similar to tsc's --noUnusedParameters and --noUnusedLocals
|
|
2626
|
-
* options, but does not interrupt code compilation.
|
|
2627
|
-
*
|
|
2628
|
-
* In addition to avoiding compilation errors, this rule may still be useful if you
|
|
2629
|
-
* wish to have `tslint` automatically remove unused imports, variables, functions,
|
|
2630
|
-
* and private class members, when using TSLint's `--fix` option.
|
|
2631
|
-
*
|
|
2632
|
-
* @rationale
|
|
2633
|
-
* Variables that are declared and not used anywhere in code are likely an error due to incomplete refactoring.
|
|
2634
|
-
* Such variables take up space in the code, are mild performance pains, and can lead to confusion by readers.
|
|
2635
|
-
*
|
|
2636
|
-
* @options
|
|
2637
|
-
* Two optional arguments may be optionally provided:
|
|
2638
|
-
*
|
|
2639
|
-
* * `"check-parameters"` disallows unused function and constructor parameters.
|
|
2640
|
-
* * NOTE: this option is experimental and does not work with classes
|
|
2641
|
-
* that use abstract method declarations, among other things.
|
|
2642
|
-
* * `{"ignore-pattern": "pattern"}` where pattern is a case-sensitive regexp.
|
|
2643
|
-
* Variable names and imports that match the pattern will be ignored.
|
|
2644
|
-
*
|
|
2645
|
-
* @example
|
|
2646
|
-
* "no-unused-variable": true
|
|
2647
|
-
* "no-unused-variable": [true,{"ignore-pattern":"^_"}]
|
|
2648
|
-
*
|
|
2649
|
-
* @type functionality
|
|
2650
|
-
*
|
|
2651
|
-
* @typescriptOnly
|
|
2652
|
-
*/
|
|
2653
|
-
'no-unused-variable'?: ("check-parameters" | {
|
|
2654
|
-
'ignore-pattern'?: string,
|
|
2655
|
-
})[],
|
|
2656
|
-
/**
|
|
2657
|
-
* Disallows usage of variables before their declaration.
|
|
2658
|
-
*
|
|
2659
|
-
* This rule is primarily useful when using the `var` keyword since the compiler will
|
|
2660
|
-
* automatically detect if a block-scoped `let` and `const` variable is used before
|
|
2661
|
-
* declaration. Since most modern TypeScript doesn't use `var`, this rule is generally
|
|
2662
|
-
* discouraged and is kept around for legacy purposes. It is slow to compute, is not
|
|
2663
|
-
* enabled in the built-in configuration presets, and should not be used to inform TSLint
|
|
2664
|
-
* design decisions.
|
|
2665
|
-
*
|
|
2666
|
-
* @options
|
|
2667
|
-
* Not configurable.
|
|
2668
|
-
*
|
|
2669
|
-
* @example
|
|
2670
|
-
* "no-use-before-declare": true
|
|
2671
|
-
*
|
|
2672
|
-
* @type functionality
|
|
2673
|
-
*/
|
|
2674
|
-
'no-use-before-declare'?: any[],
|
|
2675
|
-
/**
|
|
2676
|
-
* Disallows usage of the `var` keyword.
|
|
2677
|
-
*
|
|
2678
|
-
* Use `let` or `const` instead.
|
|
2679
|
-
*
|
|
2680
|
-
* @rationale
|
|
2681
|
-
* Declaring variables using `var` has several edge case behaviors that make `var` unsuitable for modern code.
|
|
2682
|
-
* Variables declared by `var` have their parent function block as their scope, ignoring other control flow statements.
|
|
2683
|
-
* `var`s have declaration "hoisting" (similar to `function`s) and can appear to be used before declaration.
|
|
2684
|
-
*
|
|
2685
|
-
* Variables declared by `const` and `let` instead have as their scope the block in which they are defined,
|
|
2686
|
-
* and are not allowed to used before declaration or be re-declared with another `const` or `let`.
|
|
2687
|
-
*
|
|
2688
|
-
* @options
|
|
2689
|
-
* Not configurable.
|
|
2690
|
-
*
|
|
2691
|
-
* @example
|
|
2692
|
-
* "no-var-keyword": true
|
|
2693
|
-
*
|
|
2694
|
-
* @type functionality
|
|
2695
|
-
*/
|
|
2696
|
-
'no-var-keyword'?: any[],
|
|
2697
|
-
/**
|
|
2698
|
-
* Disallows the use of require statements except in import statements.
|
|
2699
|
-
*
|
|
2700
|
-
* In other words, the use of forms such as `var module = require("module")` are banned.
|
|
2701
|
-
* Instead use ES2015-style imports or `import foo = require('foo')` imports.
|
|
2702
|
-
*
|
|
2703
|
-
* @rationale
|
|
2704
|
-
* AMD-style `require([])` and CommonJS-style `require("")` statements are environment-specific
|
|
2705
|
-
* and more difficult to statically analyze.
|
|
2706
|
-
*
|
|
2707
|
-
* ES2015-style `import`s are part of the JavaScript language specfication and recommended as the path going forward.
|
|
2708
|
-
* TypeScript will compile them to environment-specific forms as needed.
|
|
2709
|
-
*
|
|
2710
|
-
* @options
|
|
2711
|
-
* Not configurable.
|
|
2712
|
-
*
|
|
2713
|
-
* @example
|
|
2714
|
-
* "no-var-requires": true
|
|
2715
|
-
*
|
|
2716
|
-
* @type typescript
|
|
2717
|
-
*
|
|
2718
|
-
* @typescriptOnly
|
|
2719
|
-
*/
|
|
2720
|
-
'no-var-requires'?: any[],
|
|
2721
|
-
/**
|
|
2722
|
-
* Requires expressions of type `void` to appear in statement position.
|
|
2723
|
-
*
|
|
2724
|
-
* @rationale
|
|
2725
|
-
* It's misleading returning the results of an expression whose type is `void`.
|
|
2726
|
-
* Attempting to do so is likely a symptom of expecting a different return type from a function.
|
|
2727
|
-
* For example, the following code will log `undefined` but looks like it logs a value:
|
|
2728
|
-
*
|
|
2729
|
-
* ```
|
|
2730
|
-
* const performWork = (): void => {
|
|
2731
|
-
* workFirst();
|
|
2732
|
-
* workSecond();
|
|
2733
|
-
* };
|
|
2734
|
-
*
|
|
2735
|
-
* console.log(performWork());
|
|
2736
|
-
* ```
|
|
2737
|
-
*
|
|
2738
|
-
* @options
|
|
2739
|
-
* If `ignore-arrow-function-shorthand` is provided, `() => returnsVoid()` will be allowed.
|
|
2740
|
-
* Otherwise, it must be written as `() => { returnsVoid(); }`.
|
|
2741
|
-
*
|
|
2742
|
-
* @type functionality
|
|
2743
|
-
*/
|
|
2744
|
-
'no-void-expression'?: ("ignore-arrow-function-shorthand")[],
|
|
2745
|
-
/**
|
|
2746
|
-
* Checks that decimal literals should begin with '0.' instead of just '.', and should not end with a trailing '0'.
|
|
2747
|
-
*
|
|
2748
|
-
* @rationale
|
|
2749
|
-
* Helps keep a consistent style with numeric literals.
|
|
2750
|
-
* Non-standard literals are more difficult to scan through and can be a symptom of typos.
|
|
2751
|
-
*
|
|
2752
|
-
* @options
|
|
2753
|
-
* Not configurable.
|
|
2754
|
-
*
|
|
2755
|
-
* @example
|
|
2756
|
-
* "number-literal-format": true
|
|
2757
|
-
*
|
|
2758
|
-
* @type formatting
|
|
2759
|
-
*/
|
|
2760
|
-
'number-literal-format'?: any[],
|
|
2761
|
-
/**
|
|
2762
|
-
* Enforces consistent object literal property quote style.
|
|
2763
|
-
*
|
|
2764
|
-
* Object literal property names can be defined in two ways: using literals or using strings.
|
|
2765
|
-
* For example, these two objects are equivalent:
|
|
2766
|
-
*
|
|
2767
|
-
* var object1 = {
|
|
2768
|
-
* property: true
|
|
2769
|
-
* };
|
|
2770
|
-
*
|
|
2771
|
-
* var object2 = {
|
|
2772
|
-
* "property": true
|
|
2773
|
-
* };
|
|
2774
|
-
*
|
|
2775
|
-
* In many cases, it doesn’t matter if you choose to use an identifier instead of a string
|
|
2776
|
-
* or vice-versa. Even so, you might decide to enforce a consistent style in your code.
|
|
2777
|
-
*
|
|
2778
|
-
* This rules lets you enforce consistent quoting of property names. Either they should always
|
|
2779
|
-
* be quoted (default behavior) or quoted only as needed ("as-needed").
|
|
2780
|
-
*
|
|
2781
|
-
* @options
|
|
2782
|
-
* Possible settings are:
|
|
2783
|
-
*
|
|
2784
|
-
* * `"always"`: Property names should always be quoted. (This is the default.)
|
|
2785
|
-
* * `"as-needed"`: Only property names which require quotes may be quoted (e.g. those with spaces in them).
|
|
2786
|
-
* * `"consistent"`: Property names should either all be quoted or unquoted.
|
|
2787
|
-
* * `"consistent-as-needed"`: If any property name requires quotes, then all properties must be quoted. Otherwise, no
|
|
2788
|
-
* property names may be quoted.
|
|
2789
|
-
*
|
|
2790
|
-
* For ES6, computed property names (`{[name]: value}`) and methods (`{foo() {}}`) never need
|
|
2791
|
-
* to be quoted.
|
|
2792
|
-
*
|
|
2793
|
-
* @example
|
|
2794
|
-
* "object-literal-key-quotes": [true,"as-needed"]
|
|
2795
|
-
* "object-literal-key-quotes": [true,"always"]
|
|
2796
|
-
*
|
|
2797
|
-
* @type style
|
|
2798
|
-
*/
|
|
2799
|
-
'object-literal-key-quotes'?: "always" | "as-needed" | "consistent" | "consistent-as-needed",
|
|
2800
|
-
/**
|
|
2801
|
-
* Enforces/disallows use of ES6 object literal shorthand.
|
|
2802
|
-
*
|
|
2803
|
-
* @options
|
|
2804
|
-
* `"always"` assumed to be default option, thus with no options provided
|
|
2805
|
-
* the rule enforces object literal methods and properties shorthands.
|
|
2806
|
-
* With `"never"` option provided, any shorthand object literal syntax causes an error.
|
|
2807
|
-
*
|
|
2808
|
-
* The rule can be configured in a more granular way.
|
|
2809
|
-
* With `{"property": "never"}` provided (which is equivalent to `{"property": "never", "method": "always"}`),
|
|
2810
|
-
* the rule only flags property shorthand assignments,
|
|
2811
|
-
* and respectively with `{"method": "never"}` (equivalent to `{"property": "always", "method": "never"}`),
|
|
2812
|
-
* the rule fails only on method shorthands.
|
|
2813
|
-
*
|
|
2814
|
-
* @example
|
|
2815
|
-
* "object-literal-shorthand": true
|
|
2816
|
-
* "object-literal-shorthand": [true,"never"]
|
|
2817
|
-
* "object-literal-shorthand": [true,{"property":"never"}]
|
|
2818
|
-
*
|
|
2819
|
-
* @type style
|
|
2820
|
-
*/
|
|
2821
|
-
'object-literal-shorthand'?: "never" | {
|
|
2822
|
-
property?: "never",
|
|
2823
|
-
method?: "never",
|
|
2824
|
-
},
|
|
2825
|
-
/**
|
|
2826
|
-
* Checks ordering of keys in object literals.
|
|
2827
|
-
*
|
|
2828
|
-
* When using the default alphabetical ordering, additional blank lines may be used to group
|
|
2829
|
-
* object properties together while keeping the elements within each group in alphabetical order.
|
|
2830
|
-
* To opt out of this use ignore-blank-lines option.
|
|
2831
|
-
*
|
|
2832
|
-
* @rationale
|
|
2833
|
-
* Useful in preventing merge conflicts
|
|
2834
|
-
*
|
|
2835
|
-
* @options
|
|
2836
|
-
* By default, this rule checks that keys are in alphabetical order.
|
|
2837
|
-
* The following may optionally be passed:
|
|
2838
|
-
*
|
|
2839
|
-
* * `ignore-blank-lines` will enforce alphabetical ordering regardless of blank lines between each key-value pair.
|
|
2840
|
-
* * `ignore-case` will compare keys in a case insensitive way.
|
|
2841
|
-
* * `locale-compare` will compare keys using the expected sort order of special characters, such as accents.
|
|
2842
|
-
* * `match-declaration-order` will prefer to use the key ordering of the contextual type of the object literal, as in:
|
|
2843
|
-
*
|
|
2844
|
-
* ```
|
|
2845
|
-
* interface I { foo: number; bar: number; }
|
|
2846
|
-
* const obj: I = { foo: 1, bar: 2 };
|
|
2847
|
-
* ```
|
|
2848
|
-
*
|
|
2849
|
-
* If a contextual type is not found, alphabetical ordering will be used instead.
|
|
2850
|
-
* * "match-declaration-order-only" exactly like "match-declaration-order",
|
|
2851
|
-
* but don't fall back to alphabetical if a contextual type is not found.
|
|
2852
|
-
*
|
|
2853
|
-
* Note: If both match-declaration-order-only and match-declaration-order options are present,
|
|
2854
|
-
* match-declaration-order-only will take precedence and alphabetical fallback will not occur.
|
|
2855
|
-
*
|
|
2856
|
-
* * `shorthand-first` will enforce shorthand properties to appear first, as in:
|
|
2857
|
-
*
|
|
2858
|
-
* ```
|
|
2859
|
-
* const obj = { a, c, b: true };
|
|
2860
|
-
* ```
|
|
2861
|
-
*
|
|
2862
|
-
* @example
|
|
2863
|
-
* "object-literal-sort-keys": true
|
|
2864
|
-
* "object-literal-sort-keys": [true,"ignore-blank-lines","ignore-case","locale-compare","match-declaration-order","shorthand-first"]
|
|
2865
|
-
*
|
|
2866
|
-
* @type maintainability
|
|
2867
|
-
*/
|
|
2868
|
-
'object-literal-sort-keys'?: "ignore-blank-lines" | "ignore-case" | "locale-compare" | "match-declaration-order" | "match-declaration-order-only" | "shorthand-first",
|
|
2869
|
-
/**
|
|
2870
|
-
* Requires the specified tokens to be on the same line as the expression preceding them.
|
|
2871
|
-
*
|
|
2872
|
-
* @options
|
|
2873
|
-
* Five arguments may be optionally provided:
|
|
2874
|
-
*
|
|
2875
|
-
* * `"check-catch"` checks that `catch` is on the same line as the closing brace for `try`.
|
|
2876
|
-
* * `"check-finally"` checks that `finally` is on the same line as the closing brace for `catch`.
|
|
2877
|
-
* * `"check-else"` checks that `else` is on the same line as the closing brace for `if`.
|
|
2878
|
-
* * `"check-open-brace"` checks that an open brace falls on the same line as its preceding expression.
|
|
2879
|
-
* * `"check-whitespace"` checks preceding whitespace for the specified tokens.
|
|
2880
|
-
*
|
|
2881
|
-
* @example
|
|
2882
|
-
* "one-line": [true,"check-catch","check-finally","check-else"]
|
|
2883
|
-
*
|
|
2884
|
-
* @type style
|
|
2885
|
-
*/
|
|
2886
|
-
'one-line'?: ("check-catch" | "check-finally" | "check-else" | "check-open-brace" | "check-whitespace")[],
|
|
2887
|
-
/**
|
|
2888
|
-
* Disallows multiple variable definitions in the same declaration statement.
|
|
2889
|
-
*
|
|
2890
|
-
* @options
|
|
2891
|
-
* One argument may be optionally provided:
|
|
2892
|
-
*
|
|
2893
|
-
* * `ignore-for-loop` allows multiple variable definitions in a for loop declaration.
|
|
2894
|
-
*
|
|
2895
|
-
* @example
|
|
2896
|
-
* "one-variable-per-declaration": true
|
|
2897
|
-
* "one-variable-per-declaration": [true,"ignore-for-loop"]
|
|
2898
|
-
*
|
|
2899
|
-
* @type style
|
|
2900
|
-
*/
|
|
2901
|
-
'one-variable-per-declaration'?: ("ignore-for-loop")[],
|
|
2902
|
-
/**
|
|
2903
|
-
* Disallows traditional (non-arrow) function expressions.
|
|
2904
|
-
*
|
|
2905
|
-
* Note that non-arrow functions are allowed if 'this' appears somewhere in its body
|
|
2906
|
-
* (as such functions cannot be converted to arrow functions).
|
|
2907
|
-
*
|
|
2908
|
-
* @rationale
|
|
2909
|
-
* Traditional functions don't bind lexical scope, which can lead to unexpected behavior when accessing 'this'.
|
|
2910
|
-
*
|
|
2911
|
-
* @options
|
|
2912
|
-
* Two arguments may be optionally provided:
|
|
2913
|
-
*
|
|
2914
|
-
* * `"allow-declarations"` allows standalone function declarations.
|
|
2915
|
-
* * `"allow-named-functions"` allows the expression `function foo() {}` but not `function() {}`.
|
|
2916
|
-
*
|
|
2917
|
-
* @example
|
|
2918
|
-
* "only-arrow-functions": true
|
|
2919
|
-
* "only-arrow-functions": [true,"allow-declarations","allow-named-functions"]
|
|
2920
|
-
*
|
|
2921
|
-
* @type typescript
|
|
2922
|
-
*/
|
|
2923
|
-
'only-arrow-functions'?: ("allow-declarations" | "allow-named-functions")[],
|
|
2924
|
-
/**
|
|
2925
|
-
* Requires that import statements be alphabetized and grouped.
|
|
2926
|
-
*
|
|
2927
|
-
* Enforce a consistent ordering for ES6 imports:
|
|
2928
|
-
* - Named imports must be alphabetized (i.e. "import {A, B, C} from "foo";")
|
|
2929
|
-
* - The exact ordering can be controlled by the named-imports-order option.
|
|
2930
|
-
* - "longName as name" imports are ordered by "longName".
|
|
2931
|
-
* - Import sources must be alphabetized within groups, i.e.:
|
|
2932
|
-
* import * as foo from "a";
|
|
2933
|
-
* import * as bar from "b";
|
|
2934
|
-
* - Groups of imports are delineated by blank lines. You can use this rule to group
|
|
2935
|
-
* imports however you like, e.g. by first- vs. third-party or thematically or
|
|
2936
|
-
* you can define groups based upon patterns in import path names.
|
|
2937
|
-
*
|
|
2938
|
-
* @options
|
|
2939
|
-
* You may set the `"import-sources-order"` option to control the ordering of source
|
|
2940
|
-
* imports (the `"foo"` in `import {A, B, C} from "foo"`).
|
|
2941
|
-
*
|
|
2942
|
-
* Possible values for `"import-sources-order"` are:
|
|
2943
|
-
*
|
|
2944
|
-
* * `"case-insensitive'`: Correct order is `"Bar"`, `"baz"`, `"Foo"`. (This is the default.)
|
|
2945
|
-
* * `"case-insensitive-legacy'`: Correct order is `"Bar"`, `"baz"`, `"Foo"`.
|
|
2946
|
-
* * `"lowercase-first"`: Correct order is `"baz"`, `"Bar"`, `"Foo"`.
|
|
2947
|
-
* * `"lowercase-last"`: Correct order is `"Bar"`, `"Foo"`, `"baz"`.
|
|
2948
|
-
* * `"any"`: Allow any order.
|
|
2949
|
-
*
|
|
2950
|
-
* You may set the `"grouped-imports"` option to control the grouping of source
|
|
2951
|
-
* imports (the `"foo"` in `import {A, B, C} from "foo"`). The grouping used
|
|
2952
|
-
* is controlled by the `"groups"` option.
|
|
2953
|
-
*
|
|
2954
|
-
* Possible values for `"grouped-imports"` are:
|
|
2955
|
-
*
|
|
2956
|
-
* * `false`: Do not enforce grouping. (This is the default.)
|
|
2957
|
-
* * `true`: Group source imports using default grouping or groups setting.
|
|
2958
|
-
*
|
|
2959
|
-
* The value of `"groups"` is a list of group rules of the form:
|
|
2960
|
-
*
|
|
2961
|
-
* [{
|
|
2962
|
-
* "name": "optional rule name",
|
|
2963
|
-
* "match": "regex string",
|
|
2964
|
-
* "order": 10
|
|
2965
|
-
* }, {
|
|
2966
|
-
* "name": "pkga imports",
|
|
2967
|
-
* "match": "^@pkga",
|
|
2968
|
-
* "order": 20
|
|
2969
|
-
* }]
|
|
2970
|
-
*
|
|
2971
|
-
* there is also a simplified form where you only pass a list of patterns and
|
|
2972
|
-
* the order is given by the position in the list
|
|
2973
|
-
*
|
|
2974
|
-
* ["^@pkga", "^\.\."]
|
|
2975
|
-
*
|
|
2976
|
-
* The first rule in the list to match a given import is the group that is used.
|
|
2977
|
-
* If no rule in matched then the import will be put in an `unmatched` group
|
|
2978
|
-
* at the end of all groups. The groups must be ordered based upon the sequential
|
|
2979
|
-
* value of the `order` value. (ie. order 0 is first)
|
|
2980
|
-
*
|
|
2981
|
-
* If no `"groups"` options is set, a default grouping is used of third-party,
|
|
2982
|
-
* parent directories and the current directory. (`"bar"`, `"../baz"`, `"./foo"`.)
|
|
2983
|
-
*
|
|
2984
|
-
* You may set the `"named-imports-order"` option to control the ordering of named
|
|
2985
|
-
* imports (the `{A, B, C}` in `import {A, B, C} from "foo"`).
|
|
2986
|
-
*
|
|
2987
|
-
* Possible values for `"named-imports-order"` are:
|
|
2988
|
-
*
|
|
2989
|
-
* * `"case-insensitive'`: Correct order is `{A, b, C}`. (This is the default.)
|
|
2990
|
-
* * `"case-insensitive-legacy'`: Correct order is `"Bar"`, `"baz"`, `"Foo"`.
|
|
2991
|
-
* * `"lowercase-first"`: Correct order is `{b, A, C}`.
|
|
2992
|
-
* * `"lowercase-last"`: Correct order is `{A, C, b}`.
|
|
2993
|
-
* * `"any"`: Allow any order.
|
|
2994
|
-
*
|
|
2995
|
-
* You may set the `"module-source-path"` option to control the ordering of imports based full path
|
|
2996
|
-
* or just the module name
|
|
2997
|
-
*
|
|
2998
|
-
* Possible values for `"module-source-path"` are:
|
|
2999
|
-
*
|
|
3000
|
-
* * `"full'`: Correct order is `"./a/Foo"`, `"./b/baz"`, `"./c/Bar"`. (This is the default.)
|
|
3001
|
-
* * `"basename"`: Correct order is `"./c/Bar"`, `"./b/baz"`, `"./a/Foo"`.
|
|
3002
|
-
*
|
|
3003
|
-
* @example
|
|
3004
|
-
* "ordered-imports": true
|
|
3005
|
-
* "ordered-imports": [true,{"import-sources-order":"lowercase-last","named-imports-order":"lowercase-first"}]
|
|
3006
|
-
*
|
|
3007
|
-
* @type style
|
|
3008
|
-
*/
|
|
3009
|
-
'ordered-imports'?: {
|
|
3010
|
-
'grouped-imports'?: boolean,
|
|
3011
|
-
groups?: unknown,
|
|
3012
|
-
'import-sources-order'?: "case-insensitive" | "case-insensitive-legacy" | "lowercase-first" | "lowercase-last" | "any",
|
|
3013
|
-
'named-imports-order'?: "case-insensitive" | "case-insensitive-legacy" | "lowercase-first" | "lowercase-last" | "any",
|
|
3014
|
-
'module-source-path'?: "full" | "basename",
|
|
3015
|
-
},
|
|
3016
|
-
/**
|
|
3017
|
-
* Recommends to use a conditional expression instead of assigning to the same thing in each branch of an if statement.
|
|
3018
|
-
*
|
|
3019
|
-
* @rationale
|
|
3020
|
-
* This reduces duplication and can eliminate an unnecessary variable declaration.
|
|
3021
|
-
*
|
|
3022
|
-
* @options
|
|
3023
|
-
* If `check-else-if` is specified, the rule also checks nested if-else-if statements.
|
|
3024
|
-
*
|
|
3025
|
-
* @example
|
|
3026
|
-
* "prefer-conditional-expression": true
|
|
3027
|
-
* "prefer-conditional-expression": [true,"check-else-if"]
|
|
3028
|
-
*
|
|
3029
|
-
* @type functionality
|
|
3030
|
-
*/
|
|
3031
|
-
'prefer-conditional-expression'?: "check-else-if",
|
|
3032
|
-
/**
|
|
3033
|
-
* Requires that variable declarations use `const` instead of `let` and `var` if possible.
|
|
3034
|
-
*
|
|
3035
|
-
* If a variable is only assigned to once when it is declared, it should be declared using 'const'
|
|
3036
|
-
*
|
|
3037
|
-
* @options
|
|
3038
|
-
* An optional object containing the property "destructuring" with two possible values:
|
|
3039
|
-
*
|
|
3040
|
-
* * "any" (default) - If any variable in destructuring can be const, this rule warns for those variables.
|
|
3041
|
-
* * "all" - Only warns if all variables in destructuring can be const.
|
|
3042
|
-
*
|
|
3043
|
-
* @example
|
|
3044
|
-
* "prefer-const": true
|
|
3045
|
-
* "prefer-const": [true,{"destructuring":"all"}]
|
|
3046
|
-
*
|
|
3047
|
-
* @type maintainability
|
|
3048
|
-
*/
|
|
3049
|
-
'prefer-const'?: {
|
|
3050
|
-
destructuring?: "all" | "any",
|
|
3051
|
-
},
|
|
3052
|
-
/**
|
|
3053
|
-
* Recommends a 'for-of' loop over a standard 'for' loop if the index is only used to access the array being iterated.
|
|
3054
|
-
*
|
|
3055
|
-
* @rationale
|
|
3056
|
-
* A for(... of ...) loop is easier to implement and read when the index is not needed.
|
|
3057
|
-
*
|
|
3058
|
-
* @options
|
|
3059
|
-
* Not configurable.
|
|
3060
|
-
*
|
|
3061
|
-
* @example
|
|
3062
|
-
* "prefer-for-of": true
|
|
3063
|
-
*
|
|
3064
|
-
* @type typescript
|
|
3065
|
-
*/
|
|
3066
|
-
'prefer-for-of'?: any[],
|
|
3067
|
-
/**
|
|
3068
|
-
* Warns for class methods that do not use 'this'.
|
|
3069
|
-
*
|
|
3070
|
-
* @options
|
|
3071
|
-
* "allow-public" excludes checking of public methods.
|
|
3072
|
-
* "allow-protected" excludes checking of protected methods.
|
|
3073
|
-
*
|
|
3074
|
-
* @example
|
|
3075
|
-
* "prefer-function-over-method": true
|
|
3076
|
-
* "prefer-function-over-method": [true,"allow-public","allow-protected"]
|
|
3077
|
-
*
|
|
3078
|
-
* @type style
|
|
3079
|
-
*/
|
|
3080
|
-
'prefer-function-over-method'?: "allow-public" | "allow-protected",
|
|
3081
|
-
/**
|
|
3082
|
-
* Prefer `foo(): void` over `foo: () => void` in interfaces and types.
|
|
3083
|
-
*
|
|
3084
|
-
* @options
|
|
3085
|
-
* Not configurable.
|
|
3086
|
-
*
|
|
3087
|
-
* @example
|
|
3088
|
-
* "prefer-method-signature": true
|
|
3089
|
-
*
|
|
3090
|
-
* @type style
|
|
3091
|
-
*/
|
|
3092
|
-
'prefer-method-signature'?: any[],
|
|
3093
|
-
/**
|
|
3094
|
-
* Enforces the use of the ES2018 object spread operator over `Object.assign()` where appropriate.
|
|
3095
|
-
*
|
|
3096
|
-
* @rationale
|
|
3097
|
-
* Object spread allows for better type checking and inference.
|
|
3098
|
-
*
|
|
3099
|
-
* @options
|
|
3100
|
-
* Not configurable.
|
|
3101
|
-
*
|
|
3102
|
-
* @example
|
|
3103
|
-
* "prefer-object-spread": true
|
|
3104
|
-
*
|
|
3105
|
-
* @type functionality
|
|
3106
|
-
*/
|
|
3107
|
-
'prefer-object-spread'?: any[],
|
|
3108
|
-
/**
|
|
3109
|
-
* Requires that private variables are marked as `readonly` if they're never modified outside of the constructor.
|
|
3110
|
-
*
|
|
3111
|
-
* If a private variable is only assigned to in the constructor, it should be declared as `readonly`.
|
|
3112
|
-
*
|
|
3113
|
-
* @rationale
|
|
3114
|
-
* Marking never-modified variables as readonly helps enforce the code's intent of keeping them as never-modified.
|
|
3115
|
-
* It can also help prevent accidental changes of members not meant to be changed.
|
|
3116
|
-
*
|
|
3117
|
-
* @options
|
|
3118
|
-
* If `only-inline-lambdas` is specified, only immediately-declared arrow functions are checked.
|
|
3119
|
-
*
|
|
3120
|
-
* @example
|
|
3121
|
-
* "prefer-readonly": true
|
|
3122
|
-
* "prefer-readonly": [true,"only-inline-lambdas"]
|
|
3123
|
-
*
|
|
3124
|
-
* @type maintainability
|
|
3125
|
-
*
|
|
3126
|
-
* @typescriptOnly
|
|
3127
|
-
*/
|
|
3128
|
-
'prefer-readonly'?: "only-inline-lambdas",
|
|
3129
|
-
/**
|
|
3130
|
-
* Prefer a `switch` statement to an `if` statement with simple `===` comparisons.
|
|
3131
|
-
*
|
|
3132
|
-
* @options
|
|
3133
|
-
* An optional object with the property 'min-cases'.
|
|
3134
|
-
* This is the number cases needed before a switch statement is recommended.
|
|
3135
|
-
* Defaults to 3.
|
|
3136
|
-
*
|
|
3137
|
-
* @example
|
|
3138
|
-
* "prefer-switch": true
|
|
3139
|
-
* "prefer-switch": [true,{"min-cases":2}]
|
|
3140
|
-
*
|
|
3141
|
-
* @type style
|
|
3142
|
-
*/
|
|
3143
|
-
'prefer-switch'?: {
|
|
3144
|
-
'min-cases'?: number,
|
|
3145
|
-
},
|
|
3146
|
-
/**
|
|
3147
|
-
* Prefer a template expression over string literal concatenation.
|
|
3148
|
-
*
|
|
3149
|
-
* @options
|
|
3150
|
-
* If `allow-single-concat` is specified, then a single concatenation (`x + y`) is allowed, but not more (`x + y + z`).
|
|
3151
|
-
*
|
|
3152
|
-
* @example
|
|
3153
|
-
* "prefer-template": true
|
|
3154
|
-
* "prefer-template": [true,"allow-single-concat"]
|
|
3155
|
-
*
|
|
3156
|
-
* @type style
|
|
3157
|
-
*/
|
|
3158
|
-
'prefer-template'?: "allow-single-concat",
|
|
3159
|
-
/**
|
|
3160
|
-
* Prefer `while` loops instead of `for` loops without an initializer and incrementor.
|
|
3161
|
-
*
|
|
3162
|
-
* @rationale
|
|
3163
|
-
* Simplifies the readability of the loop statement, while maintaining the same functionality.
|
|
3164
|
-
*
|
|
3165
|
-
* @options
|
|
3166
|
-
* Not configurable.
|
|
3167
|
-
*
|
|
3168
|
-
* @example
|
|
3169
|
-
* "prefer-while": true
|
|
3170
|
-
*
|
|
3171
|
-
* @type style
|
|
3172
|
-
*/
|
|
3173
|
-
'prefer-while'?: any[],
|
|
3174
|
-
/**
|
|
3175
|
-
* Requires any function or method that returns a promise to be marked async.
|
|
3176
|
-
*
|
|
3177
|
-
* @rationale
|
|
3178
|
-
* Ensures that each function is only capable of 1) returning a rejected promise, or 2)
|
|
3179
|
-
* throwing an Error object. In contrast, non-`async` `Promise`-returning functions
|
|
3180
|
-
* are technically capable of either. This practice removes a requirement for consuming
|
|
3181
|
-
* code to handle both cases.
|
|
3182
|
-
*
|
|
3183
|
-
* If no optional arguments are provided then all function types are checked,
|
|
3184
|
-
* otherwise the specific function types are checked:
|
|
3185
|
-
*
|
|
3186
|
-
* * `"check-function-declaration"` check function declarations.
|
|
3187
|
-
* * `"check-function-expression"` check function expressions.
|
|
3188
|
-
* * `"check-arrow-function"` check arrow functions.
|
|
3189
|
-
* * `"check-method-declaration"` check method declarations.
|
|
3190
|
-
*
|
|
3191
|
-
* @options
|
|
3192
|
-
* Not configurable.
|
|
3193
|
-
*
|
|
3194
|
-
* @example
|
|
3195
|
-
* "promise-function-async": true
|
|
3196
|
-
* "promise-function-async": [true,"check-function-declaration","check-method-declaration"]
|
|
3197
|
-
*
|
|
3198
|
-
* @type typescript
|
|
3199
|
-
*/
|
|
3200
|
-
'promise-function-async'?: ("check-function-declaration" | "check-function-expression" | "check-arrow-function" | "check-method-declaration")[],
|
|
3201
|
-
/**
|
|
3202
|
-
* Enforces quote character for string literals.
|
|
3203
|
-
*
|
|
3204
|
-
* @options
|
|
3205
|
-
* Five arguments may be optionally provided:
|
|
3206
|
-
*
|
|
3207
|
-
* * `"single"` enforces single quotes.
|
|
3208
|
-
* * `"double"` enforces double quotes.
|
|
3209
|
-
* * `"backtick"` enforces backticks.
|
|
3210
|
-
* * `"jsx-single"` enforces single quotes for JSX attributes.
|
|
3211
|
-
* * `"jsx-double"` enforces double quotes for JSX attributes.
|
|
3212
|
-
* * `"avoid-template"` forbids single-line untagged template strings that do not contain string interpolations.
|
|
3213
|
-
* Note that backticks may still be used if `"avoid-escape"` is enabled and both single and double quotes are
|
|
3214
|
-
* present in the string (the latter option takes precedence).
|
|
3215
|
-
* * `"avoid-escape"` allows you to use the "other" quotemark in cases where escaping would normally be required.
|
|
3216
|
-
* For example, `[true, "double", "avoid-escape"]` would not report a failure on the string literal
|
|
3217
|
-
* `'Hello "World"'`.
|
|
3218
|
-
*
|
|
3219
|
-
* @example
|
|
3220
|
-
* "quotemark": [true,"single","avoid-escape","avoid-template"]
|
|
3221
|
-
* "quotemark": [true,"single","jsx-double"]
|
|
3222
|
-
*
|
|
3223
|
-
* @type formatting
|
|
3224
|
-
*/
|
|
3225
|
-
'quotemark'?: ("single" | "double" | "backtick" | "jsx-single" | "jsx-double" | "avoid-escape" | "avoid-template")[],
|
|
3226
|
-
/**
|
|
3227
|
-
* Requires the radix parameter to be specified when calling `parseInt`.
|
|
3228
|
-
*
|
|
3229
|
-
* @rationale
|
|
3230
|
-
* From [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt):
|
|
3231
|
-
* > Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior.
|
|
3232
|
-
* > Different implementations produce different results when a radix is not specified, usually defaulting the value to 10.
|
|
3233
|
-
*
|
|
3234
|
-
* @options
|
|
3235
|
-
* Not configurable.
|
|
3236
|
-
*
|
|
3237
|
-
* @example
|
|
3238
|
-
* "radix": true
|
|
3239
|
-
*
|
|
3240
|
-
* @type functionality
|
|
3241
|
-
*/
|
|
3242
|
-
'radix'?: any[],
|
|
3243
|
-
/**
|
|
3244
|
-
* When adding two variables, operands must both be of type number or of type string.
|
|
3245
|
-
*
|
|
3246
|
-
* @options
|
|
3247
|
-
* Not configurable.
|
|
3248
|
-
*
|
|
3249
|
-
* @example
|
|
3250
|
-
* "restrict-plus-operands": true
|
|
3251
|
-
*
|
|
3252
|
-
* @type functionality
|
|
3253
|
-
*/
|
|
3254
|
-
'restrict-plus-operands'?: any[],
|
|
3255
|
-
/**
|
|
3256
|
-
* Prefer `return;` in void functions and `return undefined;` in value-returning functions.
|
|
3257
|
-
*
|
|
3258
|
-
* @options
|
|
3259
|
-
* Not configurable.
|
|
3260
|
-
*
|
|
3261
|
-
* @example
|
|
3262
|
-
* "return-undefined": true
|
|
3263
|
-
*
|
|
3264
|
-
* @type style
|
|
3265
|
-
*/
|
|
3266
|
-
'return-undefined'?: any[],
|
|
3267
|
-
/**
|
|
3268
|
-
* Enforces consistent semicolon usage at the end of every statement.
|
|
3269
|
-
*
|
|
3270
|
-
* @options
|
|
3271
|
-
* One of the following arguments must be provided:
|
|
3272
|
-
*
|
|
3273
|
-
* * `"always"` enforces semicolons at the end of every statement.
|
|
3274
|
-
* * `"never"` disallows semicolons at the end of every statement except for when they are necessary.
|
|
3275
|
-
*
|
|
3276
|
-
* The following arguments may be optionally provided:
|
|
3277
|
-
*
|
|
3278
|
-
* * `"ignore-interfaces"` skips checking semicolons at the end of interface members.
|
|
3279
|
-
* * `"ignore-bound-class-methods"` skips checking semicolons at the end of bound class methods.
|
|
3280
|
-
* * `"strict-bound-class-methods"` disables any special handling of bound class methods and treats them as any
|
|
3281
|
-
* other assignment. This option overrides `"ignore-bound-class-methods"`.
|
|
3282
|
-
*
|
|
3283
|
-
* @example
|
|
3284
|
-
* "semicolon": [true,"always"]
|
|
3285
|
-
* "semicolon": [true,"never"]
|
|
3286
|
-
* "semicolon": [true,"always","ignore-interfaces"]
|
|
3287
|
-
* "semicolon": [true,"always","ignore-bound-class-methods"]
|
|
3288
|
-
*
|
|
3289
|
-
* @type formatting
|
|
3290
|
-
*/
|
|
3291
|
-
'semicolon'?: ["always" | "never", "ignore-interfaces"],
|
|
3292
|
-
/**
|
|
3293
|
-
* Require or disallow a space before function parenthesis
|
|
3294
|
-
*
|
|
3295
|
-
* @options
|
|
3296
|
-
* One argument which is an object which may contain the keys `anonymous`, `named`, and `asyncArrow`
|
|
3297
|
-
* These should be set to either `"always"` or `"never"`.
|
|
3298
|
-
*
|
|
3299
|
-
* * `"anonymous"` checks before the opening paren in anonymous functions
|
|
3300
|
-
* * `"named"` checks before the opening paren in named functions
|
|
3301
|
-
* * `"asyncArrow"` checks before the opening paren in async arrow functions
|
|
3302
|
-
* * `"method"` checks before the opening paren in class methods
|
|
3303
|
-
* * `"constructor"` checks before the opening paren in class constructors
|
|
3304
|
-
*
|
|
3305
|
-
* @example
|
|
3306
|
-
* "space-before-function-paren": true
|
|
3307
|
-
* "space-before-function-paren": [true,"always"]
|
|
3308
|
-
* "space-before-function-paren": [true,"never"]
|
|
3309
|
-
* "space-before-function-paren": [true,{"anonymous":"always","named":"never","asyncArrow":"always"}]
|
|
3310
|
-
*
|
|
3311
|
-
* @type style
|
|
3312
|
-
*/
|
|
3313
|
-
'space-before-function-paren'?: {
|
|
3314
|
-
anonymous?: "always" | "never",
|
|
3315
|
-
asyncArrow?: "always" | "never",
|
|
3316
|
-
constructor?: "always" | "never",
|
|
3317
|
-
method?: "always" | "never",
|
|
3318
|
-
named?: "always" | "never",
|
|
3319
|
-
},
|
|
3320
|
-
/**
|
|
3321
|
-
* Enforces spaces within parentheses or disallow them. Empty parentheses () are always allowed.
|
|
3322
|
-
*
|
|
3323
|
-
* @options
|
|
3324
|
-
* You may enforce the amount of whitespace within parentheses.
|
|
3325
|
-
*
|
|
3326
|
-
* @type style
|
|
3327
|
-
*/
|
|
3328
|
-
'space-within-parens'?: number,
|
|
3329
|
-
/**
|
|
3330
|
-
* Ban the use of `this` in static methods.
|
|
3331
|
-
*
|
|
3332
|
-
* @rationale
|
|
3333
|
-
* Static `this` usage can be confusing for newcomers.
|
|
3334
|
-
* It can also become imprecise when used with extended classes when a static `this` of a parent class no longer specifically refers to the parent class.
|
|
3335
|
-
*
|
|
3336
|
-
* @example
|
|
3337
|
-
* "static-this": true
|
|
3338
|
-
*
|
|
3339
|
-
* @type functionality
|
|
3340
|
-
*/
|
|
3341
|
-
'static-this'?: any[],
|
|
3342
|
-
/**
|
|
3343
|
-
* Restricts the types allowed in boolean expressions. By default only booleans are allowed.
|
|
3344
|
-
*
|
|
3345
|
-
* The following nodes are checked:
|
|
3346
|
-
*
|
|
3347
|
-
* * Arguments to the `!`, `&&`, and `||` operators
|
|
3348
|
-
* * The condition in a conditional expression (`cond ? x : y`)
|
|
3349
|
-
* * Conditions for `if`, `for`, `while`, and `do-while` statements.
|
|
3350
|
-
*
|
|
3351
|
-
* @options
|
|
3352
|
-
* These options may be provided:
|
|
3353
|
-
*
|
|
3354
|
-
* * `allow-null-union` allows union types containing `null`.
|
|
3355
|
-
* - It does *not* allow `null` itself.
|
|
3356
|
-
* - Without the '--strictNullChecks' compiler option, this will allow anything other than a string, number, or enum.
|
|
3357
|
-
* * `allow-undefined-union` allows union types containing `undefined`.
|
|
3358
|
-
* - It does *not* allow `undefined` itself.
|
|
3359
|
-
* - Without the '--strictNullChecks' compiler option, this will allow anything other than a string, number, or enum.
|
|
3360
|
-
* * `allow-string` allows strings.
|
|
3361
|
-
* - It does *not* allow unions containing `string`.
|
|
3362
|
-
* - It does *not* allow string literal types.
|
|
3363
|
-
* * `allow-enum` allows enums.
|
|
3364
|
-
* - It does *not* allow unions containing `enum`.
|
|
3365
|
-
* * `allow-number` allows numbers.
|
|
3366
|
-
* - It does *not* allow unions containing `number`.
|
|
3367
|
-
* - It does *not* allow enums or number literal types.
|
|
3368
|
-
* * `allow-mix` allows multiple of the above to appear together.
|
|
3369
|
-
* - For example, `string | number` or `RegExp | null | undefined` would normally not be allowed.
|
|
3370
|
-
* - A type like `"foo" | "bar" | undefined` is always allowed, because it has only one way to be false.
|
|
3371
|
-
* * `allow-boolean-or-undefined` allows `boolean | undefined`.
|
|
3372
|
-
* - Also allows `true | false | undefined`.
|
|
3373
|
-
* - Does not allow `false | undefined`.
|
|
3374
|
-
* - This option is a subset of `allow-undefined-union`, so you don't need to enable both options at the same time.
|
|
3375
|
-
* * `ignore-rhs` ignores the right-hand operand of `&&` and `||`.
|
|
3376
|
-
*
|
|
3377
|
-
* @example
|
|
3378
|
-
* "strict-boolean-expressions": true
|
|
3379
|
-
* "strict-boolean-expressions": [true,"allow-null-union","allow-undefined-union","allow-string","allow-enum","allow-number"]
|
|
3380
|
-
* "strict-boolean-expressions": [true,"allow-boolean-or-undefined"]
|
|
3381
|
-
*
|
|
3382
|
-
* @type functionality
|
|
3383
|
-
*
|
|
3384
|
-
* @typescriptOnly
|
|
3385
|
-
*/
|
|
3386
|
-
'strict-boolean-expressions'?: ("allow-null-union" | "allow-undefined-union" | "allow-string" | "allow-enum" | "allow-number" | "allow-boolean-or-undefined" | "ignore-rhs")[],
|
|
3387
|
-
/**
|
|
3388
|
-
* Only allow comparisons between primitives.
|
|
3389
|
-
*
|
|
3390
|
-
* @rationale
|
|
3391
|
-
* When using comparison operators to compare objects, they compare references and not values.
|
|
3392
|
-
* This is often done accidentally.
|
|
3393
|
-
* With this rule, `>`, `>=`, `<`, `<=` operators are only allowed when comparing `numbers`.
|
|
3394
|
-
* `===`, `!==` are allowed for `number` `string` and `boolean` types and if one of the
|
|
3395
|
-
* operands is `null` or `undefined`.
|
|
3396
|
-
*
|
|
3397
|
-
* @options
|
|
3398
|
-
* One of the following arguments may be optionally provided:
|
|
3399
|
-
* * `allow-object-equal-comparison` allows `!=` `==` `!==` `===` comparison between any types.
|
|
3400
|
-
* * `allow-string-order-comparison` allows `>` `<` `>=` `<=` comparison between strings.
|
|
3401
|
-
*
|
|
3402
|
-
* @example
|
|
3403
|
-
* "strict-comparisons": true
|
|
3404
|
-
* "strict-comparisons": [true,{"allow-object-equal-comparison":false,"allow-string-order-comparison":false}]
|
|
3405
|
-
*
|
|
3406
|
-
* @type functionality
|
|
3407
|
-
*/
|
|
3408
|
-
'strict-comparisons'?: {
|
|
3409
|
-
'allow-object-equal-comparison'?: boolean,
|
|
3410
|
-
'allow-string-order-comparison'?: boolean,
|
|
3411
|
-
},
|
|
3412
|
-
/**
|
|
3413
|
-
* Disable implicit toString() calls
|
|
3414
|
-
*
|
|
3415
|
-
* Require explicit toString() call for variables used in strings. By default only strings are allowed.
|
|
3416
|
-
*
|
|
3417
|
-
* The following nodes are checked:
|
|
3418
|
-
*
|
|
3419
|
-
* * String literals ("foo" + bar)
|
|
3420
|
-
* * ES6 templates (`foo ${bar}`)
|
|
3421
|
-
*
|
|
3422
|
-
* @options
|
|
3423
|
-
* Following arguments may be optionally provided:
|
|
3424
|
-
* * `allow-empty-types` allows `null`, `undefined` and `never` to be passed into strings without explicit conversion
|
|
3425
|
-
*
|
|
3426
|
-
* @example
|
|
3427
|
-
* "strict-string-expressions": true
|
|
3428
|
-
* "strict-string-expressions": [true,{"allow-empty-types":true}]
|
|
3429
|
-
*
|
|
3430
|
-
* @type functionality
|
|
3431
|
-
*
|
|
3432
|
-
* @typescriptOnly
|
|
3433
|
-
*/
|
|
3434
|
-
'strict-string-expressions'?: {
|
|
3435
|
-
'allow-empty-types'?: boolean,
|
|
3436
|
-
},
|
|
3437
|
-
/**
|
|
3438
|
-
* Warns for type predicates that are always true or always false.
|
|
3439
|
-
* Works for 'typeof' comparisons to constants (e.g. 'typeof foo === "string"'), and equality comparison to 'null'/'undefined'.
|
|
3440
|
-
* (TypeScript won't let you compare '1 === 2', but it has an exception for '1 === undefined'.)
|
|
3441
|
-
* Does not yet work for 'instanceof'.
|
|
3442
|
-
* Does *not* warn for 'if (x.y)' where 'x.y' is always truthy. For that, see strict-boolean-expressions.
|
|
3443
|
-
*
|
|
3444
|
-
* This rule requires `strictNullChecks` to work properly.
|
|
3445
|
-
*
|
|
3446
|
-
* @options
|
|
3447
|
-
* Not configurable.
|
|
3448
|
-
*
|
|
3449
|
-
* @example
|
|
3450
|
-
* "strict-type-predicates": true
|
|
3451
|
-
*
|
|
3452
|
-
* @type functionality
|
|
3453
|
-
*
|
|
3454
|
-
* @typescriptOnly
|
|
3455
|
-
*/
|
|
3456
|
-
'strict-type-predicates'?: any[],
|
|
3457
|
-
/**
|
|
3458
|
-
* Require a `default` case in all `switch` statements.
|
|
3459
|
-
*
|
|
3460
|
-
* @options
|
|
3461
|
-
* Not configurable.
|
|
3462
|
-
*
|
|
3463
|
-
* @example
|
|
3464
|
-
* "switch-default": true
|
|
3465
|
-
*
|
|
3466
|
-
* @type functionality
|
|
3467
|
-
*/
|
|
3468
|
-
'switch-default'?: any[],
|
|
3469
|
-
/**
|
|
3470
|
-
* Checks whether the final clause of a switch statement ends in `break;`.
|
|
3471
|
-
*
|
|
3472
|
-
* @options
|
|
3473
|
-
* If no options are passed, a final 'break;' is forbidden.
|
|
3474
|
-
* If the "always" option is passed this will require a 'break;' to always be present
|
|
3475
|
-
* unless control flow is escaped in some other way.
|
|
3476
|
-
*
|
|
3477
|
-
* @example
|
|
3478
|
-
* "switch-final-break": true
|
|
3479
|
-
* "switch-final-break": [true,"always"]
|
|
3480
|
-
*
|
|
3481
|
-
* @type style
|
|
3482
|
-
*/
|
|
3483
|
-
'switch-final-break'?: "always",
|
|
3484
|
-
/**
|
|
3485
|
-
* Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings,
|
|
3486
|
-
* named imports and exports and function parameters.
|
|
3487
|
-
*
|
|
3488
|
-
* @options
|
|
3489
|
-
* One argument which is an object with the keys `multiline` and `singleline`.
|
|
3490
|
-
* Both can be set to a string (`"always"` or `"never"`) or an object.
|
|
3491
|
-
*
|
|
3492
|
-
* The object can contain any of the following keys: `"arrays"`, `"objects"`, `"functions"`,
|
|
3493
|
-
* `"imports"`, `"exports"`, and `"typeLiterals"`; each key can have one of the following
|
|
3494
|
-
* values: `"always"`, `"never"`, and `"ignore"`. Any missing keys will default to `"ignore"`.
|
|
3495
|
-
*
|
|
3496
|
-
* * `"multiline"` checks multi-line object literals.
|
|
3497
|
-
* * `"singleline"` checks single-line object literals.
|
|
3498
|
-
*
|
|
3499
|
-
* An array is considered "multiline" if its closing bracket is on a line
|
|
3500
|
-
* after the last array element. The same general logic is followed for
|
|
3501
|
-
* object literals, function typings, named import statements
|
|
3502
|
-
* and function parameters.
|
|
3503
|
-
*
|
|
3504
|
-
* To align this rule with the ECMAScript specification that is implemented in modern JavaScript VMs,
|
|
3505
|
-
* there is a third option `esSpecCompliant`. Set this option to `true` to disallow trailing comma on
|
|
3506
|
-
* object and array rest and rest parameters.
|
|
3507
|
-
*
|
|
3508
|
-
* @example
|
|
3509
|
-
* "trailing-comma": [true,{"multiline":"always","singleline":"never"}]
|
|
3510
|
-
* "trailing-comma": [true,{"multiline":{"objects":"always","arrays":"always","functions":"never","typeLiterals":"ignore"},"esSpecCompliant":true}]
|
|
3511
|
-
*
|
|
3512
|
-
* @type formatting
|
|
3513
|
-
*/
|
|
3514
|
-
'trailing-comma'?: {
|
|
3515
|
-
multiline?: "always" | "never" | {
|
|
3516
|
-
arrays?: "always" | "never" | "ignore",
|
|
3517
|
-
exports?: "always" | "never" | "ignore",
|
|
3518
|
-
functions?: "always" | "never" | "ignore",
|
|
3519
|
-
imports?: "always" | "never" | "ignore",
|
|
3520
|
-
objects?: "always" | "never" | "ignore",
|
|
3521
|
-
typeLiterals?: "always" | "never" | "ignore",
|
|
3522
|
-
},
|
|
3523
|
-
singleline?: "always" | "never" | {
|
|
3524
|
-
arrays?: "always" | "never" | "ignore",
|
|
3525
|
-
exports?: "always" | "never" | "ignore",
|
|
3526
|
-
functions?: "always" | "never" | "ignore",
|
|
3527
|
-
imports?: "always" | "never" | "ignore",
|
|
3528
|
-
objects?: "always" | "never" | "ignore",
|
|
3529
|
-
typeLiterals?: "always" | "never" | "ignore",
|
|
3530
|
-
},
|
|
3531
|
-
esSpecCompliant?: boolean,
|
|
3532
|
-
},
|
|
3533
|
-
/**
|
|
3534
|
-
* Requires `===` and `!==` in place of `==` and `!=`.
|
|
3535
|
-
*
|
|
3536
|
-
* @options
|
|
3537
|
-
* Two arguments may be optionally provided:
|
|
3538
|
-
*
|
|
3539
|
-
* * `"allow-null-check"` allows `==` and `!=` when comparing to `null`.
|
|
3540
|
-
* * `"allow-undefined-check"` allows `==` and `!=` when comparing to `undefined`.
|
|
3541
|
-
*
|
|
3542
|
-
* @example
|
|
3543
|
-
* "triple-equals": true
|
|
3544
|
-
* "triple-equals": [true,"allow-null-check"]
|
|
3545
|
-
* "triple-equals": [true,"allow-undefined-check"]
|
|
3546
|
-
*
|
|
3547
|
-
* @type functionality
|
|
3548
|
-
*/
|
|
3549
|
-
'triple-equals'?: ("allow-null-check" | "allow-undefined-check")[],
|
|
3550
|
-
/**
|
|
3551
|
-
* Checks that type literal members are separated by semicolons.
|
|
3552
|
-
* Enforces a trailing semicolon for multiline type literals.
|
|
3553
|
-
*
|
|
3554
|
-
* @options
|
|
3555
|
-
* `{singleLine: "always"}` enforces semicolon for one liners
|
|
3556
|
-
*
|
|
3557
|
-
* @example
|
|
3558
|
-
* "type-literal-delimiter": true
|
|
3559
|
-
*
|
|
3560
|
-
* @type style
|
|
3561
|
-
*
|
|
3562
|
-
* @typescriptOnly
|
|
3563
|
-
*/
|
|
3564
|
-
'type-literal-delimiter'?: {
|
|
3565
|
-
singleLine?: "always" | "never",
|
|
3566
|
-
},
|
|
3567
|
-
/**
|
|
3568
|
-
* Requires type definitions to exist.
|
|
3569
|
-
*
|
|
3570
|
-
* @options
|
|
3571
|
-
* Several arguments may be optionally provided:
|
|
3572
|
-
*
|
|
3573
|
-
* * `"call-signature"` checks return type of functions.
|
|
3574
|
-
* * `"arrow-call-signature"` checks return type of arrow functions.
|
|
3575
|
-
* * `"parameter"` checks type specifier of function parameters for non-arrow functions.
|
|
3576
|
-
* * `"arrow-parameter"` checks type specifier of function parameters for arrow functions.
|
|
3577
|
-
* * `"property-declaration"` checks return types of interface properties.
|
|
3578
|
-
* * `"variable-declaration"` checks non-binding variable declarations.
|
|
3579
|
-
* * `"variable-declaration-ignore-function"` ignore variable declarations for non-arrow and arrow functions.
|
|
3580
|
-
* * `"member-variable-declaration"` checks member variable declarations.
|
|
3581
|
-
* * `"object-destructuring"` checks object destructuring declarations.
|
|
3582
|
-
* * `"array-destructuring"` checks array destructuring declarations.
|
|
3583
|
-
*
|
|
3584
|
-
* @example
|
|
3585
|
-
* "typedef": [true,"call-signature","parameter","member-variable-declaration"]
|
|
3586
|
-
*
|
|
3587
|
-
* @type typescript
|
|
3588
|
-
*
|
|
3589
|
-
* @typescriptOnly
|
|
3590
|
-
*/
|
|
3591
|
-
'typedef'?: ("call-signature" | "arrow-call-signature" | "parameter" | "arrow-parameter" | "property-declaration" | "variable-declaration" | "variable-declaration-ignore-function" | "member-variable-declaration" | "object-destructuring" | "array-destructuring")[],
|
|
3592
|
-
/**
|
|
3593
|
-
* Requires or disallows whitespace for type definitions.
|
|
3594
|
-
*
|
|
3595
|
-
* Determines if a space is required or not before the colon in a type specifier.
|
|
3596
|
-
*
|
|
3597
|
-
* @options
|
|
3598
|
-
* Two arguments which are both objects.
|
|
3599
|
-
* The first argument specifies how much space should be to the _left_ of a typedef colon.
|
|
3600
|
-
* The second argument specifies how much space should be to the _right_ of a typedef colon.
|
|
3601
|
-
* Each key should have a value of `"onespace"`, `"space"` or `"nospace"`.
|
|
3602
|
-
* Possible keys are:
|
|
3603
|
-
*
|
|
3604
|
-
* * `"call-signature"` checks return type of functions.
|
|
3605
|
-
* * `"index-signature"` checks index type specifier of indexers.
|
|
3606
|
-
* * `"parameter"` checks function parameters.
|
|
3607
|
-
* * `"property-declaration"` checks object property declarations.
|
|
3608
|
-
* * `"variable-declaration"` checks variable declaration.
|
|
3609
|
-
*
|
|
3610
|
-
* @example
|
|
3611
|
-
* "typedef-whitespace": [true,{"call-signature":"nospace","index-signature":"nospace","parameter":"nospace","property-declaration":"nospace","variable-declaration":"nospace"},{"call-signature":"onespace","index-signature":"onespace","parameter":"onespace","property-declaration":"onespace","variable-declaration":"onespace"}]
|
|
3612
|
-
*
|
|
3613
|
-
* @type formatting
|
|
3614
|
-
*
|
|
3615
|
-
* @typescriptOnly
|
|
3616
|
-
*/
|
|
3617
|
-
'typedef-whitespace'?: [{
|
|
3618
|
-
'call-signature'?: "nospace" | "onespace" | "space",
|
|
3619
|
-
'index-signature'?: "nospace" | "onespace" | "space",
|
|
3620
|
-
parameter?: "nospace" | "onespace" | "space",
|
|
3621
|
-
'property-declaration'?: "nospace" | "onespace" | "space",
|
|
3622
|
-
'variable-declaration'?: "nospace" | "onespace" | "space",
|
|
3623
|
-
}, {
|
|
3624
|
-
'call-signature'?: "nospace" | "onespace" | "space",
|
|
3625
|
-
'index-signature'?: "nospace" | "onespace" | "space",
|
|
3626
|
-
parameter?: "nospace" | "onespace" | "space",
|
|
3627
|
-
'property-declaration'?: "nospace" | "onespace" | "space",
|
|
3628
|
-
'variable-declaration'?: "nospace" | "onespace" | "space",
|
|
3629
|
-
}],
|
|
3630
|
-
/**
|
|
3631
|
-
* Makes sure result of `typeof` is compared to correct string values
|
|
3632
|
-
*
|
|
3633
|
-
* @options
|
|
3634
|
-
* Not configurable.
|
|
3635
|
-
*
|
|
3636
|
-
* @example
|
|
3637
|
-
* "typeof-compare": true
|
|
3638
|
-
*
|
|
3639
|
-
* @type functionality
|
|
3640
|
-
*/
|
|
3641
|
-
'typeof-compare'?: any[],
|
|
3642
|
-
/**
|
|
3643
|
-
* Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter.
|
|
3644
|
-
*
|
|
3645
|
-
* @options
|
|
3646
|
-
* Not configurable.
|
|
3647
|
-
*
|
|
3648
|
-
* @example
|
|
3649
|
-
* "unified-signatures": true
|
|
3650
|
-
*
|
|
3651
|
-
* @type typescript
|
|
3652
|
-
*
|
|
3653
|
-
* @typescriptOnly
|
|
3654
|
-
*/
|
|
3655
|
-
'unified-signatures'?: any[],
|
|
3656
|
-
/**
|
|
3657
|
-
* Prevents unnecessary and/or misleading scope bindings on functions.
|
|
3658
|
-
*
|
|
3659
|
-
* @rationale
|
|
3660
|
-
* `function` expressions that are immediately bound to `this` are equivalent to `() =>` arrow lambdas.
|
|
3661
|
-
* Additionally, there's no use in binding a scope to an arrow lambda, as it already has one.
|
|
3662
|
-
*
|
|
3663
|
-
* @options
|
|
3664
|
-
* Not configurable.
|
|
3665
|
-
*
|
|
3666
|
-
* @example
|
|
3667
|
-
* "unnecessary-bind": true
|
|
3668
|
-
*
|
|
3669
|
-
* @type style
|
|
3670
|
-
*/
|
|
3671
|
-
'unnecessary-bind'?: any[],
|
|
3672
|
-
/**
|
|
3673
|
-
* Prevents blank constructors, as they are redundant.
|
|
3674
|
-
*
|
|
3675
|
-
* @rationale
|
|
3676
|
-
* JavaScript implicitly adds a blank constructor when there isn't one.
|
|
3677
|
-
* It's not necessary to manually add one in.
|
|
3678
|
-
*
|
|
3679
|
-
* @options
|
|
3680
|
-
* An optional object with the property 'check-super-calls'.
|
|
3681
|
-
* This is to check for unnecessary constructor parameters for super call
|
|
3682
|
-
*
|
|
3683
|
-
* @example
|
|
3684
|
-
* "unnecessary-constructor": true
|
|
3685
|
-
* "unnecessary-constructor": [true,{"check-super-calls":true}]
|
|
3686
|
-
*
|
|
3687
|
-
* @type functionality
|
|
3688
|
-
*/
|
|
3689
|
-
'unnecessary-constructor'?: {
|
|
3690
|
-
'check-super-calls'?: boolean,
|
|
3691
|
-
},
|
|
3692
|
-
/**
|
|
3693
|
-
* Disallows `else` blocks following `if` blocks ending with a `break`, `continue`, `return`, or `throw` statement.
|
|
3694
|
-
*
|
|
3695
|
-
* @rationale
|
|
3696
|
-
* When an `if` block is guaranteed to exit control flow when entered,
|
|
3697
|
-
* it is unnecessary to add an `else` statement.
|
|
3698
|
-
* The contents that would be in the `else` block can be placed after the end of the `if` block.
|
|
3699
|
-
*
|
|
3700
|
-
* @options
|
|
3701
|
-
* You can optionally specify the option `"allow-else-if"` to allow "else if" statements.
|
|
3702
|
-
*
|
|
3703
|
-
* @example
|
|
3704
|
-
* "unnecessary-else": true
|
|
3705
|
-
* "unnecessary-else": [true,{"allow-else-if":true}]
|
|
3706
|
-
*
|
|
3707
|
-
* @type style
|
|
3708
|
-
*/
|
|
3709
|
-
'unnecessary-else'?: {
|
|
3710
|
-
'allow-else-if'?: boolean,
|
|
3711
|
-
},
|
|
3712
|
-
/**
|
|
3713
|
-
* Warns if an explicitly specified type argument is the default for that type parameter.
|
|
3714
|
-
*
|
|
3715
|
-
* @options
|
|
3716
|
-
* Not configurable.
|
|
3717
|
-
*
|
|
3718
|
-
* @example
|
|
3719
|
-
* true
|
|
3720
|
-
*
|
|
3721
|
-
* @type functionality
|
|
3722
|
-
*
|
|
3723
|
-
* @typescriptOnly
|
|
3724
|
-
*/
|
|
3725
|
-
'use-default-type-parameter'?: any[],
|
|
3726
|
-
/**
|
|
3727
|
-
* Enforces use of the `isNaN()` function to check for NaN references instead of a comparison to the `NaN` constant.
|
|
3728
|
-
*
|
|
3729
|
-
* @rationale
|
|
3730
|
-
* Since `NaN !== NaN`, comparisons with regular operators will produce unexpected results.
|
|
3731
|
-
* So, instead of `if (myVar === NaN)`, do `if (isNaN(myVar))`.
|
|
3732
|
-
*
|
|
3733
|
-
* @options
|
|
3734
|
-
* Not configurable.
|
|
3735
|
-
*
|
|
3736
|
-
* @example
|
|
3737
|
-
* "use-isnan": true
|
|
3738
|
-
*
|
|
3739
|
-
* @type functionality
|
|
3740
|
-
*/
|
|
3741
|
-
'use-isnan'?: any[],
|
|
3742
|
-
/**
|
|
3743
|
-
* Checks variable names for various errors.
|
|
3744
|
-
*
|
|
3745
|
-
* @options
|
|
3746
|
-
* Several arguments may be optionally provided:
|
|
3747
|
-
*
|
|
3748
|
-
* * `"check-format"` enbables enforcement of a certain naming format. By default, the rule only allows only lowerCamelCased or UPPER_CASED variable names.
|
|
3749
|
-
* * These additional options make the check stricter:
|
|
3750
|
-
* * `"require-const-for-all-caps"`: enforces that all variables with UPPER_CASED names should be `const`.
|
|
3751
|
-
* * These additional options make the check more permissive:
|
|
3752
|
-
* * `"allow-leading-underscore"` allows underscores at the beginning (only has an effect if "check-format" specified)
|
|
3753
|
-
* * `"allow-pascal-case"` allows PascalCase in addition to lowerCamelCase.
|
|
3754
|
-
* * `"allow-snake-case"` allows snake_case in addition to lowerCamelCase.
|
|
3755
|
-
* * `"allow-trailing-underscore"` allows underscores at the end. (only has an effect if "check-format" specified)
|
|
3756
|
-
* * `"ban-keywords"`: disallows the use of certain TypeScript keywords as variable or parameter names.
|
|
3757
|
-
* * These are: `any`, `Number`, `number`, `String`, `string`, `Boolean`, `boolean`, `Undefined`, `undefined`
|
|
3758
|
-
*
|
|
3759
|
-
* @example
|
|
3760
|
-
* "variable-name": {"options":["ban-keywords","check-format","allow-leading-underscore","allow-pascal-case"]}
|
|
3761
|
-
*
|
|
3762
|
-
* @type style
|
|
3763
|
-
*/
|
|
3764
|
-
'variable-name'?: ("check-format" | "allow-leading-underscore" | "allow-pascal-case" | "allow-snake-case" | "allow-trailing-underscore" | "require-const-for-all-caps" | "ban-keywords")[],
|
|
3765
|
-
/**
|
|
3766
|
-
* Enforces whitespace style conventions.
|
|
3767
|
-
*
|
|
3768
|
-
* @rationale
|
|
3769
|
-
* Helps maintain a readable, consistent style in your codebase.
|
|
3770
|
-
*
|
|
3771
|
-
* @options
|
|
3772
|
-
* Several arguments may be optionally provided:
|
|
3773
|
-
*
|
|
3774
|
-
* * `"check-branch"` checks branching statements (`if`/`else`/`for`/`while`) are followed by whitespace.
|
|
3775
|
-
* * `"check-decl"`checks that variable declarations have whitespace around the equals token.
|
|
3776
|
-
* * `"check-operator"` checks for whitespace around operator tokens.
|
|
3777
|
-
* * `"check-module"` checks for whitespace in import & export statements.
|
|
3778
|
-
* * `"check-separator"` checks for whitespace after separator tokens (`,`/`;`).
|
|
3779
|
-
* * `"check-rest-spread"` checks that there is no whitespace after rest/spread operator (`...`).
|
|
3780
|
-
* * `"check-type"` checks for whitespace before a variable type specification.
|
|
3781
|
-
* * `"check-typecast"` checks for whitespace between a typecast and its target.
|
|
3782
|
-
* * `"check-type-operator"` checks for whitespace between type operators `|` and `&`.
|
|
3783
|
-
* * `"check-preblock"` checks for whitespace before the opening brace of a block.
|
|
3784
|
-
* * `"check-postbrace"` checks for whitespace after an opening brace.
|
|
3785
|
-
*
|
|
3786
|
-
* @example
|
|
3787
|
-
* "whitespace": [true,"check-branch","check-operator","check-typecast"]
|
|
3788
|
-
*
|
|
3789
|
-
* @type formatting
|
|
3790
|
-
*/
|
|
3791
|
-
'whitespace'?: ("check-branch" | "check-decl" | "check-operator" | "check-module" | "check-separator" | "check-rest-spread" | "check-type" | "check-typecast" | "check-type-operator" | "check-preblock" | "check-postbrace")[],
|
|
1
|
+
export interface TSLintRulesConfig extends Record<string, any[]> {
|
|
2
|
+
[key: string]: any[];
|
|
3792
3
|
}
|
|
3793
|
-
|