@typescript-eslint/eslint-plugin 8.9.1-alpha.6 → 8.9.1-alpha.7
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/dist/rules/class-literal-property-style.js +1 -0
- package/dist/rules/class-literal-property-style.js.map +1 -1
- package/dist/rules/class-methods-use-this.js +3 -3
- package/dist/rules/class-methods-use-this.js.map +1 -1
- package/dist/rules/consistent-generic-constructors.js +1 -0
- package/dist/rules/consistent-generic-constructors.js.map +1 -1
- package/dist/rules/consistent-indexed-object-style.js +1 -0
- package/dist/rules/consistent-indexed-object-style.js.map +1 -1
- package/dist/rules/consistent-type-definitions.js +1 -0
- package/dist/rules/consistent-type-definitions.js.map +1 -1
- package/dist/rules/explicit-member-accessibility.js +5 -1
- package/dist/rules/explicit-member-accessibility.js.map +1 -1
- package/dist/rules/no-invalid-void-type.js +7 -3
- package/dist/rules/no-invalid-void-type.js.map +1 -1
- package/dist/rules/no-misused-promises.js +7 -1
- package/dist/rules/no-misused-promises.js.map +1 -1
- package/dist/rules/no-restricted-imports.js +1 -1
- package/dist/rules/no-restricted-imports.js.map +1 -1
- package/dist/rules/no-restricted-types.js +5 -4
- package/dist/rules/no-restricted-types.js.map +1 -1
- package/dist/rules/no-use-before-define.js +4 -1
- package/dist/rules/no-use-before-define.js.map +1 -1
- package/dist/rules/prefer-destructuring.js +2 -0
- package/dist/rules/prefer-destructuring.js.map +1 -1
- package/dist/rules/prefer-nullish-coalescing.js +18 -4
- package/dist/rules/prefer-nullish-coalescing.js.map +1 -1
- package/dist/rules/sort-type-constituents.js +3 -3
- package/dist/rules/sort-type-constituents.js.map +1 -1
- package/dist/rules/strict-boolean-expressions.js +5 -4
- package/dist/rules/strict-boolean-expressions.js.map +1 -1
- package/docs/rules/ban-ts-comment.mdx +4 -0
- package/docs/rules/class-methods-use-this.mdx +4 -1
- package/docs/rules/consistent-generic-constructors.mdx +6 -4
- package/docs/rules/consistent-indexed-object-style.mdx +6 -4
- package/docs/rules/consistent-type-assertions.mdx +4 -2
- package/docs/rules/consistent-type-definitions.mdx +8 -4
- package/docs/rules/consistent-type-exports.mdx +2 -1
- package/docs/rules/consistent-type-imports.mdx +7 -4
- package/docs/rules/dot-notation.mdx +5 -3
- package/docs/rules/explicit-function-return-type.mdx +16 -0
- package/docs/rules/explicit-member-accessibility.mdx +7 -2
- package/docs/rules/explicit-module-boundary-types.mdx +22 -12
- package/docs/rules/max-params.mdx +1 -1
- package/docs/rules/method-signature-style.mdx +4 -2
- package/docs/rules/no-base-to-string.mdx +5 -3
- package/docs/rules/no-confusing-void-expression.mdx +4 -0
- package/docs/rules/no-duplicate-type-constituents.mdx +4 -0
- package/docs/rules/no-empty-interface.mdx +3 -1
- package/docs/rules/no-empty-object-type.mdx +8 -3
- package/docs/rules/no-explicit-any.mdx +3 -1
- package/docs/rules/no-extraneous-class.mdx +4 -4
- package/docs/rules/no-floating-promises.mdx +12 -6
- package/docs/rules/no-inferrable-types.mdx +2 -2
- package/docs/rules/no-invalid-void-type.mdx +4 -3
- package/docs/rules/no-magic-numbers.mdx +8 -0
- package/docs/rules/no-meaningless-void-operator.mdx +1 -1
- package/docs/rules/no-misused-promises.mdx +11 -1
- package/docs/rules/no-namespace.mdx +4 -0
- package/docs/rules/no-redeclare.mdx +3 -1
- package/docs/rules/no-require-imports.mdx +6 -2
- package/docs/rules/no-restricted-imports.mdx +4 -1
- package/docs/rules/no-restricted-types.mdx +1 -1
- package/docs/rules/no-shadow.mdx +4 -2
- package/docs/rules/no-this-alias.mdx +4 -0
- package/docs/rules/no-type-alias.mdx +8 -8
- package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +4 -0
- package/docs/rules/no-unnecessary-condition.mdx +6 -0
- package/docs/rules/no-unnecessary-type-assertion.mdx +2 -0
- package/docs/rules/no-use-before-define.mdx +3 -3
- package/docs/rules/no-var-requires.mdx +2 -0
- package/docs/rules/parameter-properties.mdx +6 -2
- package/docs/rules/prefer-destructuring.mdx +1 -1
- package/docs/rules/prefer-literal-enum-member.mdx +1 -1
- package/docs/rules/prefer-nullish-coalescing.mdx +6 -4
- package/docs/rules/prefer-optional-chain.mdx +37 -28
- package/docs/rules/prefer-readonly-parameter-types.mdx +8 -4
- package/docs/rules/prefer-readonly.mdx +1 -1
- package/docs/rules/prefer-string-starts-ends-with.mdx +2 -0
- package/docs/rules/promise-function-async.mdx +8 -9
- package/docs/rules/require-array-sort-compare.mdx +2 -0
- package/docs/rules/restrict-plus-operands.mdx +12 -0
- package/docs/rules/restrict-template-expressions.mdx +9 -7
- package/docs/rules/return-await.mdx +4 -0
- package/docs/rules/sort-type-constituents.mdx +5 -3
- package/docs/rules/strict-boolean-expressions.mdx +22 -12
- package/docs/rules/switch-exhaustiveness-check.mdx +6 -2
- package/docs/rules/triple-slash-reference.mdx +6 -0
- package/docs/rules/typedef.mdx +8 -8
- package/docs/rules/unbound-method.mdx +2 -0
- package/docs/rules/unified-signatures.mdx +2 -0
- package/package.json +7 -7
@@ -97,17 +97,19 @@ If you are working on a codebase within which you lint non-TypeScript code (i.e.
|
|
97
97
|
|
98
98
|
### `allowArgumentsExplicitlyTypedAsAny`
|
99
99
|
|
100
|
-
|
100
|
+
{/* insert option description */}
|
101
|
+
|
102
|
+
Examples of code for this rule with `{ allowArgumentsExplicitlyTypedAsAny: false }`:
|
101
103
|
|
102
104
|
<Tabs>
|
103
|
-
<TabItem value="❌ Incorrect
|
105
|
+
<TabItem value="❌ Incorrect">
|
104
106
|
|
105
107
|
```ts option='{ "allowArgumentsExplicitlyTypedAsAny": false }'
|
106
108
|
export const func = (value: any): number => value + 1;
|
107
109
|
```
|
108
110
|
|
109
111
|
</TabItem>
|
110
|
-
<TabItem value="✅ Correct
|
112
|
+
<TabItem value="✅ Correct">
|
111
113
|
|
112
114
|
```ts option='{ "allowArgumentsExplicitlyTypedAsAny": true }'
|
113
115
|
export const func = (value: any): number => value + 1;
|
@@ -118,10 +120,12 @@ export const func = (value: any): number => value + 1;
|
|
118
120
|
|
119
121
|
### `allowDirectConstAssertionInArrowFunctions`
|
120
122
|
|
121
|
-
|
123
|
+
{/* insert option description */}
|
124
|
+
|
125
|
+
Examples of code for this rule with `{ allowDirectConstAssertionInArrowFunctions: false }`:
|
122
126
|
|
123
127
|
<Tabs>
|
124
|
-
<TabItem value="❌ Incorrect
|
128
|
+
<TabItem value="❌ Incorrect">
|
125
129
|
|
126
130
|
```ts option='{ "allowDirectConstAssertionInArrowFunctions": false }'
|
127
131
|
export const func = (value: number) => ({ type: 'X', value });
|
@@ -132,7 +136,7 @@ export const bar = () => 1;
|
|
132
136
|
```
|
133
137
|
|
134
138
|
</TabItem>
|
135
|
-
<TabItem value="✅ Correct
|
139
|
+
<TabItem value="✅ Correct">
|
136
140
|
|
137
141
|
```ts option='{ "allowDirectConstAssertionInArrowFunctions": true }'
|
138
142
|
export const func = (value: number) => ({ type: 'X', value }) as const;
|
@@ -148,6 +152,8 @@ export const bar = () => 1 as const;
|
|
148
152
|
|
149
153
|
### `allowedNames`
|
150
154
|
|
155
|
+
{/* insert option description */}
|
156
|
+
|
151
157
|
You may pass function/method names you would like this rule to ignore, like so:
|
152
158
|
|
153
159
|
```json
|
@@ -163,10 +169,12 @@ You may pass function/method names you would like this rule to ignore, like so:
|
|
163
169
|
|
164
170
|
### `allowHigherOrderFunctions`
|
165
171
|
|
166
|
-
|
172
|
+
{/* insert option description */}
|
173
|
+
|
174
|
+
Examples of code for this rule with `{ allowHigherOrderFunctions: false }`:
|
167
175
|
|
168
176
|
<Tabs>
|
169
|
-
<TabItem value="❌ Incorrect
|
177
|
+
<TabItem value="❌ Incorrect">
|
170
178
|
|
171
179
|
```ts option='{ "allowHigherOrderFunctions": false }'
|
172
180
|
export const arrowFn = () => () => {};
|
@@ -181,7 +189,7 @@ export function foo(outer: string) {
|
|
181
189
|
```
|
182
190
|
|
183
191
|
</TabItem>
|
184
|
-
<TabItem value="✅ Correct
|
192
|
+
<TabItem value="✅ Correct">
|
185
193
|
|
186
194
|
```ts option='{ "allowHigherOrderFunctions": true }'
|
187
195
|
export const arrowFn = () => (): void => {};
|
@@ -200,10 +208,12 @@ export function foo(outer: string) {
|
|
200
208
|
|
201
209
|
### `allowTypedFunctionExpressions`
|
202
210
|
|
203
|
-
|
211
|
+
{/* insert option description */}
|
212
|
+
|
213
|
+
Examples of code for this rule with `{ allowTypedFunctionExpressions: false }`:
|
204
214
|
|
205
215
|
<Tabs>
|
206
|
-
<TabItem value="❌ Incorrect
|
216
|
+
<TabItem value="❌ Incorrect">
|
207
217
|
|
208
218
|
```ts option='{ "allowTypedFunctionExpressions": false }'
|
209
219
|
export let arrowFn = () => 'test';
|
@@ -220,7 +230,7 @@ export const foo = bar => {};
|
|
220
230
|
```
|
221
231
|
|
222
232
|
</TabItem>
|
223
|
-
<TabItem value="✅ Correct
|
233
|
+
<TabItem value="✅ Correct">
|
224
234
|
|
225
235
|
```ts option='{ "allowTypedFunctionExpressions": true }'
|
226
236
|
type FuncType = () => string;
|
@@ -39,10 +39,10 @@ This rule accepts one string option:
|
|
39
39
|
- `"property"`: Enforce using property signature for functions. Use this to enforce maximum correctness together with TypeScript's strict mode.
|
40
40
|
- `"method"`: Enforce using method signature for functions. Use this if you aren't using TypeScript's strict mode and prefer this style.
|
41
41
|
|
42
|
-
The default is `"property"`.
|
43
|
-
|
44
42
|
### `property`
|
45
43
|
|
44
|
+
{/* insert option description */}
|
45
|
+
|
46
46
|
Examples of code with `property` option.
|
47
47
|
|
48
48
|
<Tabs>
|
@@ -85,6 +85,8 @@ interface T3 {
|
|
85
85
|
|
86
86
|
### `method`
|
87
87
|
|
88
|
+
{/* insert option description */}
|
89
|
+
|
88
90
|
Examples of code with `method` option.
|
89
91
|
|
90
92
|
<Tabs>
|
@@ -66,9 +66,10 @@ const literalWithToString = {
|
|
66
66
|
|
67
67
|
### `ignoredTypeNames`
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
{/* insert option description */}
|
70
|
+
|
71
|
+
This is useful for types whose declarations missing `toString()`, but are known to actually have `toString()`.
|
72
|
+
There are some types missing `toString()` in TypeScript, like `RegExp`, `URL`, `URLSearchParams` etc.
|
72
73
|
|
73
74
|
The following patterns are considered correct with the default options `{ ignoredTypeNames: ["RegExp"] }`:
|
74
75
|
|
@@ -93,3 +94,4 @@ If you don't mind a risk of `"[object Object]"` or incorrect type coercions in y
|
|
93
94
|
## Further Reading
|
94
95
|
|
95
96
|
- [`Object.prototype.toString()` MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
|
97
|
+
- [Microsoft/TypeScript Add missing toString declarations for base types that have them](https://github.com/microsoft/TypeScript/issues/38347)
|
@@ -77,6 +77,8 @@ cond ? console.log('true') : console.error('false');
|
|
77
77
|
|
78
78
|
### `ignoreArrowShorthand`
|
79
79
|
|
80
|
+
{/* insert option description */}
|
81
|
+
|
80
82
|
Whether to ignore "shorthand" `() =>` arrow functions: those without `{ ... }` braces.
|
81
83
|
|
82
84
|
It might be undesirable to wrap every arrow function shorthand expression.
|
@@ -90,6 +92,8 @@ promise.then(value => window.postMessage(value));
|
|
90
92
|
|
91
93
|
### `ignoreVoidOperator`
|
92
94
|
|
95
|
+
{/* insert option description */}
|
96
|
+
|
93
97
|
Whether to ignore returns that start with the `void` operator.
|
94
98
|
|
95
99
|
It might be preferable to only use some distinct syntax
|
@@ -67,10 +67,14 @@ const fn = (a?: string) => {};
|
|
67
67
|
|
68
68
|
### `ignoreIntersections`
|
69
69
|
|
70
|
+
{/* insert option description */}
|
71
|
+
|
70
72
|
When set to true, duplicate checks on intersection type constituents are ignored.
|
71
73
|
|
72
74
|
### `ignoreUnions`
|
73
75
|
|
76
|
+
{/* insert option description */}
|
77
|
+
|
74
78
|
When set to true, duplicate checks on union type constituents are ignored.
|
75
79
|
|
76
80
|
## When Not To Use It
|
@@ -62,7 +62,9 @@ interface Baz extends Foo, Bar {}
|
|
62
62
|
|
63
63
|
### `allowSingleExtends`
|
64
64
|
|
65
|
-
|
65
|
+
{/* insert option description */}
|
66
|
+
|
67
|
+
`allowSingleExtends: true` will silence warnings about extending a single interface without adding additional members.
|
66
68
|
|
67
69
|
## When Not To Use It
|
68
70
|
|
@@ -83,7 +83,9 @@ By default, this rule flags both interfaces and object types.
|
|
83
83
|
|
84
84
|
### `allowInterfaces`
|
85
85
|
|
86
|
-
|
86
|
+
{/* insert option description */}
|
87
|
+
|
88
|
+
Allowed values are:
|
87
89
|
|
88
90
|
- `'always'`: to always allow interfaces with no fields
|
89
91
|
- `'never'` _(default)_: to never allow interfaces with no fields
|
@@ -101,14 +103,17 @@ interface Derived extends Base {}
|
|
101
103
|
|
102
104
|
### `allowObjectTypes`
|
103
105
|
|
104
|
-
|
106
|
+
{/* insert option description */}
|
107
|
+
|
108
|
+
Allowed values are:
|
105
109
|
|
106
110
|
- `'always'`: to always allow object type literals with no fields
|
107
111
|
- `'never'` _(default)_: to never allow object type literals with no fields
|
108
112
|
|
109
113
|
### `allowWithName`
|
110
114
|
|
111
|
-
|
115
|
+
{/* insert option description */}
|
116
|
+
|
112
117
|
This can be useful if your existing code style includes a pattern of declaring empty types with `{}` instead of `object`.
|
113
118
|
|
114
119
|
Examples of code for this rule with `{ allowWithName: 'Props$' }`:
|
@@ -107,6 +107,8 @@ function greet(param: Array<string>): Array<string> {}
|
|
107
107
|
|
108
108
|
### `fixToUnknown`
|
109
109
|
|
110
|
+
{/* insert option description */}
|
111
|
+
|
110
112
|
By default, this rule will not provide automatic ESLint _fixes_: only opt-in _suggestions_.
|
111
113
|
Switching types to `unknown` is safer but is likely to cause additional type errors.
|
112
114
|
|
@@ -114,7 +116,7 @@ Enabling `{ "fixToUnknown": true }` gives the rule an auto-fixer to replace `: a
|
|
114
116
|
|
115
117
|
### `ignoreRestArgs`
|
116
118
|
|
117
|
-
|
119
|
+
{/* insert option description */}
|
118
120
|
|
119
121
|
The examples below are **incorrect** when `{ignoreRestArgs: false}`, but **correct** when `{ignoreRestArgs: true}`.
|
120
122
|
|
@@ -221,7 +221,7 @@ The rule's options each add an exemption for a specific type of class.
|
|
221
221
|
|
222
222
|
### `allowConstructorOnly`
|
223
223
|
|
224
|
-
|
224
|
+
{/* insert option description */}
|
225
225
|
|
226
226
|
<Tabs>
|
227
227
|
<TabItem value="❌ Incorrect">
|
@@ -246,7 +246,7 @@ class NoFields {
|
|
246
246
|
|
247
247
|
### `allowEmpty`
|
248
248
|
|
249
|
-
|
249
|
+
{/* insert option description */}
|
250
250
|
|
251
251
|
<Tabs>
|
252
252
|
<TabItem value="❌ Incorrect">
|
@@ -271,7 +271,7 @@ class NoFields {}
|
|
271
271
|
|
272
272
|
### `allowStaticOnly`
|
273
273
|
|
274
|
-
|
274
|
+
{/* insert option description */}
|
275
275
|
|
276
276
|
:::caution
|
277
277
|
We strongly recommend against the `allowStaticOnly` exemption.
|
@@ -299,7 +299,7 @@ class NotEmptyClass {
|
|
299
299
|
|
300
300
|
### `allowWithDecorator`
|
301
301
|
|
302
|
-
|
302
|
+
{/* insert option description */}
|
303
303
|
|
304
304
|
<Tabs>
|
305
305
|
<TabItem value="❌ Incorrect">
|
@@ -87,6 +87,8 @@ await Promise.all([1, 2, 3].map(async x => x + 1));
|
|
87
87
|
|
88
88
|
### `checkThenables`
|
89
89
|
|
90
|
+
{/* insert option description */}
|
91
|
+
|
90
92
|
A ["Thenable"](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#thenables) value is an object which has a `then` method, such as a `Promise`.
|
91
93
|
Other Thenables include TypeScript's built-in `PromiseLike` interface and any custom object that happens to have a `.then()`.
|
92
94
|
|
@@ -132,8 +134,9 @@ await createMyThenable();
|
|
132
134
|
|
133
135
|
### `ignoreVoid`
|
134
136
|
|
135
|
-
|
136
|
-
|
137
|
+
{/* insert option description */}
|
138
|
+
|
139
|
+
Placing the [`void` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void) in front of a Promise can be a convenient way to explicitly mark that Promise as intentionally not awaited.
|
137
140
|
|
138
141
|
:::warning
|
139
142
|
Voiding a Promise doesn't handle it or change the runtime behavior.
|
@@ -152,11 +155,11 @@ void returnsPromise();
|
|
152
155
|
void Promise.reject('value');
|
153
156
|
```
|
154
157
|
|
155
|
-
|
158
|
+
When this option is set to `true`, if you are using `no-void`, you should turn on the [`allowAsStatement`](https://eslint.org/docs/rules/no-void#allowasstatement) option.
|
156
159
|
|
157
160
|
### `ignoreIIFE`
|
158
161
|
|
159
|
-
|
162
|
+
{/* insert option description */}
|
160
163
|
|
161
164
|
Examples of **correct** code for this rule with `{ ignoreIIFE: true }`:
|
162
165
|
|
@@ -173,7 +176,9 @@ await (async function () {
|
|
173
176
|
|
174
177
|
### `allowForKnownSafePromises`
|
175
178
|
|
176
|
-
|
179
|
+
{/* insert option description */}
|
180
|
+
|
181
|
+
For example, you may need to do this in the case of libraries whose APIs return Promises whose rejections are safely handled by the library.
|
177
182
|
|
178
183
|
This option takes the shared [`TypeOrValueSpecifier` format](/packages/type-utils/type-or-value-specifier).
|
179
184
|
|
@@ -225,7 +230,8 @@ returnsSafePromise();
|
|
225
230
|
|
226
231
|
### `allowForKnownSafeCalls`
|
227
232
|
|
228
|
-
|
233
|
+
{/* insert option description */}
|
234
|
+
|
229
235
|
For example, you may need to do this in the case of libraries whose APIs may be called without handling the resultant Promises.
|
230
236
|
|
231
237
|
This option takes the shared [`TypeOrValueSpecifier` format](/packages/type-utils/type-or-value-specifier).
|
@@ -80,7 +80,7 @@ function fn(a = 5, b = true) {}
|
|
80
80
|
|
81
81
|
### `ignoreParameters`
|
82
82
|
|
83
|
-
|
83
|
+
{/* insert option description */}
|
84
84
|
|
85
85
|
When set to true, the following pattern is considered valid:
|
86
86
|
|
@@ -92,7 +92,7 @@ function foo(a: number = 5, b: boolean = true) {
|
|
92
92
|
|
93
93
|
### `ignoreProperties`
|
94
94
|
|
95
|
-
|
95
|
+
{/* insert option description */}
|
96
96
|
|
97
97
|
When set to true, the following pattern is considered valid:
|
98
98
|
|
@@ -62,9 +62,9 @@ type stillVoid = void | never;
|
|
62
62
|
|
63
63
|
### `allowInGenericTypeArguments`
|
64
64
|
|
65
|
-
|
65
|
+
{/* insert option description */}
|
66
66
|
|
67
|
-
Alternatively, you can provide an array of strings which
|
67
|
+
Alternatively, you can provide an array of strings which allowlist which types may accept `void` as a generic type parameter.
|
68
68
|
|
69
69
|
Any types considered valid by this option will be considered valid as part of a union type with `void`.
|
70
70
|
|
@@ -98,7 +98,8 @@ type AllowedVoidUnion = void | Ex.Mx.Tx<void>;
|
|
98
98
|
|
99
99
|
### `allowAsThisParameter`
|
100
100
|
|
101
|
-
|
101
|
+
{/* insert option description */}
|
102
|
+
|
102
103
|
This pattern can be useful to explicitly label function types that do not use a `this` argument. [See the TypeScript docs for more information](https://www.typescriptlang.org/docs/handbook/functions.html#this-parameters-in-callbacks).
|
103
104
|
|
104
105
|
This option is `false` by default.
|
@@ -39,6 +39,8 @@ const defaultOptions: Options = {
|
|
39
39
|
|
40
40
|
### `ignoreEnums`
|
41
41
|
|
42
|
+
{/* insert option description */}
|
43
|
+
|
42
44
|
Whether enums used in TypeScript are considered okay. `false` by default.
|
43
45
|
|
44
46
|
Examples of **incorrect** code for the `{ "ignoreEnums": false }` option:
|
@@ -59,6 +61,8 @@ enum foo {
|
|
59
61
|
|
60
62
|
### `ignoreNumericLiteralTypes`
|
61
63
|
|
64
|
+
{/* insert option description */}
|
65
|
+
|
62
66
|
Whether numbers used in TypeScript numeric literal types are considered okay. `false` by default.
|
63
67
|
|
64
68
|
Examples of **incorrect** code for the `{ "ignoreNumericLiteralTypes": false }` option:
|
@@ -75,6 +79,8 @@ type SmallPrimes = 2 | 3 | 5 | 7 | 11;
|
|
75
79
|
|
76
80
|
### `ignoreReadonlyClassProperties`
|
77
81
|
|
82
|
+
{/* insert option description */}
|
83
|
+
|
78
84
|
Whether `readonly` class properties are considered okay.
|
79
85
|
|
80
86
|
Examples of **incorrect** code for the `{ "ignoreReadonlyClassProperties": false }` option:
|
@@ -101,6 +107,8 @@ class Foo {
|
|
101
107
|
|
102
108
|
### `ignoreTypeIndexes`
|
103
109
|
|
110
|
+
{/* insert option description */}
|
111
|
+
|
104
112
|
Whether numbers used to index types are okay. `false` by default.
|
105
113
|
|
106
114
|
Examples of **incorrect** code for the `{ "ignoreTypeIndexes": false }` option:
|
@@ -22,6 +22,8 @@ See [`no-floating-promises`](./no-floating-promises.mdx) for detecting unhandled
|
|
22
22
|
|
23
23
|
### `checksConditionals`
|
24
24
|
|
25
|
+
{/* insert option description */}
|
26
|
+
|
25
27
|
If you don't want to check conditionals, you can configure the rule with `"checksConditionals": false`:
|
26
28
|
|
27
29
|
```json
|
@@ -39,6 +41,8 @@ Doing so prevents the rule from looking at code like `if (somePromise)`.
|
|
39
41
|
|
40
42
|
### `checksVoidReturn`
|
41
43
|
|
44
|
+
{/* insert option description */}
|
45
|
+
|
42
46
|
Likewise, if you don't want to check functions that return promises where a void return is
|
43
47
|
expected, your configuration will look like this:
|
44
48
|
|
@@ -101,7 +105,7 @@ Disables checking an asynchronous function used as a variable whose return type
|
|
101
105
|
|
102
106
|
### `checksSpreads`
|
103
107
|
|
104
|
-
|
108
|
+
{/* insert option description */}
|
105
109
|
|
106
110
|
If you don't want to check object spreads, you can add this configuration:
|
107
111
|
|
@@ -120,6 +124,8 @@ If you don't want to check object spreads, you can add this configuration:
|
|
120
124
|
|
121
125
|
### `checksConditionals`
|
122
126
|
|
127
|
+
{/* insert option description */}
|
128
|
+
|
123
129
|
Examples of code for this rule with `checksConditionals: true`:
|
124
130
|
|
125
131
|
<Tabs>
|
@@ -167,6 +173,8 @@ while (await promise) {
|
|
167
173
|
|
168
174
|
### `checksVoidReturn`
|
169
175
|
|
176
|
+
{/* insert option description */}
|
177
|
+
|
170
178
|
Examples of code for this rule with `checksVoidReturn: true`:
|
171
179
|
|
172
180
|
<Tabs>
|
@@ -254,6 +262,8 @@ class MyClass implements MyAsyncInterface {
|
|
254
262
|
|
255
263
|
### `checksSpreads`
|
256
264
|
|
265
|
+
{/* insert option description */}
|
266
|
+
|
257
267
|
Examples of code for this rule with `checksSpreads: true`:
|
258
268
|
|
259
269
|
<Tabs>
|
@@ -46,6 +46,8 @@ declare module 'foo' {}
|
|
46
46
|
|
47
47
|
### `allowDeclarations`
|
48
48
|
|
49
|
+
{/* insert option description */}
|
50
|
+
|
49
51
|
Examples of code with the `{ "allowDeclarations": true }` option:
|
50
52
|
|
51
53
|
<Tabs>
|
@@ -100,6 +102,8 @@ declare module 'foo' {}
|
|
100
102
|
|
101
103
|
### `allowDefinitionFiles`
|
102
104
|
|
105
|
+
{/* insert option description */}
|
106
|
+
|
103
107
|
Examples of code for the `{ "allowDefinitionFiles": true }` option:
|
104
108
|
|
105
109
|
<Tabs>
|
@@ -33,7 +33,9 @@ const defaultOptions: Options = {
|
|
33
33
|
|
34
34
|
### `ignoreDeclarationMerge`
|
35
35
|
|
36
|
-
|
36
|
+
{/* insert option description */}
|
37
|
+
|
38
|
+
The following sets will be ignored when this option is enabled:
|
37
39
|
|
38
40
|
- interface + interface
|
39
41
|
- namespace + namespace
|
@@ -38,7 +38,9 @@ import * as lib3 from 'lib3';
|
|
38
38
|
|
39
39
|
### `allow`
|
40
40
|
|
41
|
-
|
41
|
+
{/* insert option description */}
|
42
|
+
|
43
|
+
These strings will be compiled into regular expressions with the `u` flag and be used to test against the imported path. A common use case is to allow importing `package.json`. This is because `package.json` commonly lives outside of the TS root directory, so statically importing it would lead to root directory conflicts, especially with `resolveJsonModule` enabled. You can also use it to allow importing any JSON if your environment doesn't support JSON modules, or use it for other cases where `import` statements cannot work.
|
42
44
|
|
43
45
|
With `{allow: ['/package\\.json$']}`:
|
44
46
|
|
@@ -61,7 +63,9 @@ console.log(require('../package.json').version);
|
|
61
63
|
|
62
64
|
### `allowAsImport`
|
63
65
|
|
64
|
-
|
66
|
+
{/* insert option description */}
|
67
|
+
|
68
|
+
When set to `true`, `import ... = require(...)` declarations won't be reported.
|
65
69
|
This is useful if you use certain module options that require strict CommonJS interop semantics.
|
66
70
|
|
67
71
|
With `{allowAsImport: true}`:
|
@@ -17,7 +17,10 @@ This rule adds the following options:
|
|
17
17
|
|
18
18
|
### `allowTypeImports`
|
19
19
|
|
20
|
-
|
20
|
+
{/* insert option description */}
|
21
|
+
|
22
|
+
Whether to allow type-only imports for a path.
|
23
|
+
Default: `false`.
|
21
24
|
|
22
25
|
You can specify this option for a specific path or pattern as follows:
|
23
26
|
|
@@ -19,7 +19,7 @@ Note that it does not ban the corresponding runtime objects from being used.
|
|
19
19
|
|
20
20
|
### `types`
|
21
21
|
|
22
|
-
|
22
|
+
{/* insert option description */}
|
23
23
|
|
24
24
|
The type can either be a type name literal (`OldType`) or a a type name with generic parameter instantiation(s) (`OldType<MyArgument>`).
|
25
25
|
|
package/docs/rules/no-shadow.mdx
CHANGED
@@ -31,7 +31,9 @@ const defaultOptions: Options = {
|
|
31
31
|
|
32
32
|
### `ignoreTypeValueShadow`
|
33
33
|
|
34
|
-
|
34
|
+
{/* insert option description */}
|
35
|
+
|
36
|
+
This is generally safe because you cannot use variables in type locations without a `typeof` operator, so there's little risk of confusion.
|
35
37
|
|
36
38
|
Examples of **correct** code with `{ ignoreTypeValueShadow: true }`:
|
37
39
|
|
@@ -55,7 +57,7 @@ _Shadowing_ specifically refers to two identical identifiers that are in differe
|
|
55
57
|
|
56
58
|
### `ignoreFunctionTypeParameterNameValueShadow`
|
57
59
|
|
58
|
-
|
60
|
+
{/* insert option description */}
|
59
61
|
|
60
62
|
Each of a function type's arguments creates a value variable within the scope of the function type. This is done so that you can reference the type later using the `typeof` operator:
|
61
63
|
|
@@ -41,6 +41,8 @@ setTimeout(() => {
|
|
41
41
|
|
42
42
|
### `allowDestructuring`
|
43
43
|
|
44
|
+
{/* insert option description */}
|
45
|
+
|
44
46
|
It can sometimes be useful to destructure properties from a class instance, such as retrieving multiple properties from the instance in one of its methods.
|
45
47
|
`allowDestructuring` allows those destructures and is `true` by default.
|
46
48
|
You can explicitly disallow them by setting `allowDestructuring` to `false`.
|
@@ -84,6 +86,8 @@ class ComponentLike {
|
|
84
86
|
|
85
87
|
### `allowedNames`
|
86
88
|
|
89
|
+
{/* insert option description */}
|
90
|
+
|
87
91
|
`no-this-alias` can alternately be used to allow only a specific list of names as `this` aliases.
|
88
92
|
We recommend against this except as a transitory step towards fixing all rule violations.
|
89
93
|
|