@typescript-eslint/eslint-plugin 8.9.1-alpha.0 → 8.9.1-alpha.10
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/consistent-type-exports.js +10 -4
- package/dist/rules/consistent-type-exports.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/explicit-module-boundary-types.js.map +1 -1
- package/dist/rules/naming-convention.js +2 -1
- package/dist/rules/naming-convention.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-unnecessary-condition.js +0 -1
- package/dist/rules/no-unnecessary-condition.js.map +1 -1
- package/dist/rules/no-unsafe-argument.js +2 -1
- package/dist/rules/no-unsafe-argument.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
@@ -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
|
|
@@ -114,7 +114,7 @@ and simplified types (primitives, tuples, unions, intersections, etc).
|
|
114
114
|
|
115
115
|
### `allowAliases`
|
116
116
|
|
117
|
-
|
117
|
+
{/* insert option description */}
|
118
118
|
|
119
119
|
The setting accepts the following values:
|
120
120
|
|
@@ -268,7 +268,7 @@ type Foo = Bar & Baz;
|
|
268
268
|
|
269
269
|
### `allowCallbacks`
|
270
270
|
|
271
|
-
|
271
|
+
{/* insert option description */}
|
272
272
|
|
273
273
|
The setting accepts the following values:
|
274
274
|
|
@@ -290,7 +290,7 @@ type Foo = (name: string, age: number) => string & Person;
|
|
290
290
|
|
291
291
|
### `allowConditionalTypes`
|
292
292
|
|
293
|
-
|
293
|
+
{/* insert option description */}
|
294
294
|
|
295
295
|
Examples of **correct** code for the `{ "allowConditionalTypes": "always" }` option:
|
296
296
|
|
@@ -300,7 +300,7 @@ type Foo<T> = T extends number ? number : null;
|
|
300
300
|
|
301
301
|
### `allowConstructors`
|
302
302
|
|
303
|
-
|
303
|
+
{/* insert option description */}
|
304
304
|
|
305
305
|
The setting accepts the following values:
|
306
306
|
|
@@ -314,7 +314,7 @@ type Foo = new () => void;
|
|
314
314
|
|
315
315
|
### `allowLiterals`
|
316
316
|
|
317
|
-
|
317
|
+
{/* insert option description */}
|
318
318
|
|
319
319
|
The setting accepts the following options:
|
320
320
|
|
@@ -421,7 +421,7 @@ type Foo = { name: string } & { age: number };
|
|
421
421
|
|
422
422
|
### `allowMappedTypes`
|
423
423
|
|
424
|
-
|
424
|
+
{/* insert option description */}
|
425
425
|
|
426
426
|
The setting accepts the following values:
|
427
427
|
|
@@ -524,7 +524,7 @@ type Foo<T, U> = { [P in keyof T]?: T[P] } & { [P in keyof U]?: U[P] };
|
|
524
524
|
|
525
525
|
### `allowTupleTypes`
|
526
526
|
|
527
|
-
|
527
|
+
{/* insert option description */}
|
528
528
|
|
529
529
|
The setting accepts the following options:
|
530
530
|
|
@@ -599,7 +599,7 @@ type Foo = [string] | [number];
|
|
599
599
|
|
600
600
|
### `allowGenerics`
|
601
601
|
|
602
|
-
|
602
|
+
{/* insert option description */}
|
603
603
|
|
604
604
|
The setting accepts the following options:
|
605
605
|
|
@@ -61,6 +61,8 @@ are **not** checked by default.
|
|
61
61
|
|
62
62
|
### `allowComparingNullableBooleansToTrue`
|
63
63
|
|
64
|
+
{/* insert option description */}
|
65
|
+
|
64
66
|
Examples of code for this rule with `{ allowComparingNullableBooleansToTrue: false }`:
|
65
67
|
|
66
68
|
<Tabs>
|
@@ -94,6 +96,8 @@ if (!someNullCondition) {
|
|
94
96
|
|
95
97
|
### `allowComparingNullableBooleansToFalse`
|
96
98
|
|
99
|
+
{/* insert option description */}
|
100
|
+
|
97
101
|
Examples of code for this rule with `{ allowComparingNullableBooleansToFalse: false }`:
|
98
102
|
|
99
103
|
<Tabs>
|
@@ -82,6 +82,8 @@ function bar(arg?: string | null) {
|
|
82
82
|
|
83
83
|
### `allowConstantLoopConditions`
|
84
84
|
|
85
|
+
{/* insert option description */}
|
86
|
+
|
85
87
|
Example of correct code for `{ allowConstantLoopConditions: true }`:
|
86
88
|
|
87
89
|
```ts option='{ "allowConstantLoopConditions": true }' showPlaygroundButton
|
@@ -92,6 +94,8 @@ do {} while (true);
|
|
92
94
|
|
93
95
|
### `checkTypePredicates`
|
94
96
|
|
97
|
+
{/* insert option description */}
|
98
|
+
|
95
99
|
Example of additional incorrect code with `{ checkTypePredicates: true }`:
|
96
100
|
|
97
101
|
```ts option='{ "checkTypePredicates": true }' showPlaygroundButton
|
@@ -132,6 +136,8 @@ However, in some contexts, it may be more appropriate to keep this option disabl
|
|
132
136
|
|
133
137
|
### `allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing`
|
134
138
|
|
139
|
+
{/* insert option description */}
|
140
|
+
|
135
141
|
:::danger Deprecated
|
136
142
|
This option will be removed in the next major version of typescript-eslint.
|
137
143
|
:::
|
@@ -75,6 +75,8 @@ function foo(x: number | undefined): number {
|
|
75
75
|
|
76
76
|
### `typesToIgnore`
|
77
77
|
|
78
|
+
{/* insert option description */}
|
79
|
+
|
78
80
|
With `@typescript-eslint/no-unnecessary-type-assertion: ["error", { typesToIgnore: ['Foo'] }]`, the following is **correct** code:
|
79
81
|
|
80
82
|
```ts option='{ "typesToIgnore": ["Foo"] }' showPlaygroundButton
|
@@ -33,7 +33,7 @@ const defaultOptions: Options = {
|
|
33
33
|
|
34
34
|
### `enums`
|
35
35
|
|
36
|
-
|
36
|
+
{/* insert option description */}
|
37
37
|
|
38
38
|
If this is `true`, this rule warns every reference to a enum before the enum declaration.
|
39
39
|
If this is `false`, this rule will ignore references to enums, when the reference is in a child scope.
|
@@ -69,7 +69,7 @@ enum Foo {
|
|
69
69
|
|
70
70
|
### `typedefs`
|
71
71
|
|
72
|
-
|
72
|
+
{/* insert option description */}
|
73
73
|
|
74
74
|
If this is `true`, this rule warns every reference to a type before the type declaration.
|
75
75
|
If this is `false`, this rule will ignore references to types.
|
@@ -83,7 +83,7 @@ type StringOrNumber = string | number;
|
|
83
83
|
|
84
84
|
### `ignoreTypeReferences`
|
85
85
|
|
86
|
-
|
86
|
+
{/* insert option description */}
|
87
87
|
|
88
88
|
If this is `true`, this rule ignores all type references.
|
89
89
|
If this is `false`, this will check all type references.
|
@@ -44,6 +44,8 @@ import foo from 'foo';
|
|
44
44
|
|
45
45
|
### `allow`
|
46
46
|
|
47
|
+
{/* insert option description */}
|
48
|
+
|
47
49
|
A array of strings. 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.
|
48
50
|
|
49
51
|
With `{allow: ['/package\\.json$']}`:
|
@@ -24,6 +24,8 @@ It may take an options object containing either or both of:
|
|
24
24
|
|
25
25
|
### `allow`
|
26
26
|
|
27
|
+
{/* insert option description */}
|
28
|
+
|
27
29
|
If you would like to ignore certain kinds of properties then you may pass an object containing `"allow"` as an array of any of the following options:
|
28
30
|
|
29
31
|
- `allow`, an array containing one or more of the allowed modifiers. Valid values are:
|
@@ -50,8 +52,10 @@ For example, to ignore `public` properties:
|
|
50
52
|
|
51
53
|
### `prefer`
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
+
{/* insert option description */}
|
56
|
+
|
57
|
+
By default, the rule prefers class properties.
|
58
|
+
You can switch it to instead preferring parameter properties with (`"parameter-property"`).
|
55
59
|
|
56
60
|
In `"parameter-property"` mode, the rule will issue a report when:
|
57
61
|
|
@@ -80,7 +80,7 @@ const defaultOptions: Options = [
|
|
80
80
|
|
81
81
|
### `enforceForDeclarationWithTypeAnnotation`
|
82
82
|
|
83
|
-
|
83
|
+
{/* insert option description */}
|
84
84
|
|
85
85
|
Examples with `{ enforceForDeclarationWithTypeAnnotation: true }`:
|
86
86
|
|
@@ -25,7 +25,7 @@ This rule will not work as expected if [`strictNullChecks`](https://www.typescri
|
|
25
25
|
|
26
26
|
### `ignoreTernaryTests`
|
27
27
|
|
28
|
-
|
28
|
+
{/* insert option description */}
|
29
29
|
|
30
30
|
Incorrect code for `ignoreTernaryTests: false`, and correct code for `ignoreTernaryTests: true`:
|
31
31
|
|
@@ -65,7 +65,7 @@ foo ?? 'a string';
|
|
65
65
|
|
66
66
|
### `ignoreConditionalTests`
|
67
67
|
|
68
|
-
|
68
|
+
{/* insert option description */}
|
69
69
|
|
70
70
|
Generally expressions within conditional tests intentionally use the falsy fallthrough behavior of the logical or operator, meaning that fixing the operator to the nullish coalesce operator could cause bugs.
|
71
71
|
|
@@ -107,7 +107,7 @@ a ?? b ? true : false;
|
|
107
107
|
|
108
108
|
### `ignoreMixedLogicalExpressions`
|
109
109
|
|
110
|
-
|
110
|
+
{/* insert option description */}
|
111
111
|
|
112
112
|
Generally expressions within mixed logical expressions intentionally use the falsy fallthrough behavior of the logical or operator, meaning that fixing the operator to the nullish coalesce operator could cause bugs.
|
113
113
|
|
@@ -147,7 +147,7 @@ a ?? (b && c && d);
|
|
147
147
|
|
148
148
|
### `ignorePrimitives`
|
149
149
|
|
150
|
-
|
150
|
+
{/* insert option description */}
|
151
151
|
|
152
152
|
If you would like to ignore expressions containing operands of certain primitive types that can be falsy then you may pass an object containing a boolean value for each primitive:
|
153
153
|
|
@@ -174,6 +174,8 @@ Also, if you would like to ignore all primitives types, you can set `ignorePrimi
|
|
174
174
|
|
175
175
|
### `allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing`
|
176
176
|
|
177
|
+
{/* insert option description */}
|
178
|
+
|
177
179
|
:::danger Deprecated
|
178
180
|
|
179
181
|
> This option will be removed in the next major version of typescript-eslint.
|