@typescript-eslint/eslint-plugin 7.2.1-alpha.1 → 7.2.1-alpha.3
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/configs/all.js +1 -0
- package/dist/configs/all.js.map +1 -1
- package/dist/configs/disable-type-checked.js +1 -0
- package/dist/configs/disable-type-checked.js.map +1 -1
- package/dist/configs/strict-type-checked-only.js +23 -3
- package/dist/configs/strict-type-checked-only.js.map +1 -1
- package/dist/configs/strict-type-checked.js +27 -4
- package/dist/configs/strict-type-checked.js.map +1 -1
- package/dist/configs/strict.js +4 -1
- package/dist/configs/strict.js.map +1 -1
- package/dist/rules/ban-ts-comment.js +4 -1
- package/dist/rules/ban-ts-comment.js.map +1 -1
- package/dist/rules/consistent-type-imports.js +1 -0
- package/dist/rules/consistent-type-imports.js.map +1 -1
- package/dist/rules/index.js +2 -0
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/no-floating-promises.js +4 -1
- package/dist/rules/no-floating-promises.js.map +1 -1
- package/dist/rules/no-misused-promises.js +1 -1
- package/dist/rules/no-misused-promises.js.map +1 -1
- package/dist/rules/no-redundant-type-constituents.js +42 -0
- package/dist/rules/no-redundant-type-constituents.js.map +1 -1
- package/dist/rules/no-unnecessary-qualifier.js +1 -1
- package/dist/rules/no-unnecessary-qualifier.js.map +1 -1
- package/dist/rules/no-unsafe-argument.js +1 -25
- package/dist/rules/no-unsafe-argument.js.map +1 -1
- package/dist/rules/no-unused-expressions.js +6 -2
- package/dist/rules/no-unused-expressions.js.map +1 -1
- package/dist/rules/restrict-plus-operands.js +12 -1
- package/dist/rules/restrict-plus-operands.js.map +1 -1
- package/dist/rules/restrict-template-expressions.js +52 -87
- package/dist/rules/restrict-template-expressions.js.map +1 -1
- package/dist/rules/use-unknown-in-catch-callback-variable.js +283 -0
- package/dist/rules/use-unknown-in-catch-callback-variable.js.map +1 -0
- package/dist/util/misc.js +10 -1
- package/dist/util/misc.js.map +1 -1
- package/docs/rules/TEMPLATE.md +10 -4
- package/docs/rules/{adjacent-overload-signatures.md → adjacent-overload-signatures.mdx} +11 -5
- package/docs/rules/{array-type.md → array-type.mdx} +24 -12
- package/docs/rules/{await-thenable.md → await-thenable.mdx} +10 -4
- package/docs/rules/{ban-ts-comment.md → ban-ts-comment.mdx} +32 -18
- package/docs/rules/{ban-tslint-comment.md → ban-tslint-comment.mdx} +10 -4
- package/docs/rules/{ban-types.md → ban-types.mdx} +11 -5
- package/docs/rules/{block-spacing.md → block-spacing.mdx} +3 -0
- package/docs/rules/{brace-style.md → brace-style.mdx} +3 -0
- package/docs/rules/camelcase.md +3 -5
- package/docs/rules/{class-literal-property-style.md → class-literal-property-style.mdx} +18 -11
- package/docs/rules/{class-methods-use-this.md → class-methods-use-this.mdx} +12 -6
- package/docs/rules/{comma-dangle.md → comma-dangle.mdx} +3 -0
- package/docs/rules/{comma-spacing.md → comma-spacing.mdx} +3 -0
- package/docs/rules/{consistent-generic-constructors.md → consistent-generic-constructors.mdx} +17 -8
- package/docs/rules/{consistent-indexed-object-style.md → consistent-indexed-object-style.mdx} +17 -8
- package/docs/rules/{consistent-return.md → consistent-return.mdx} +10 -4
- package/docs/rules/{consistent-type-assertions.md → consistent-type-assertions.mdx} +15 -10
- package/docs/rules/{consistent-type-definitions.md → consistent-type-definitions.mdx} +17 -8
- package/docs/rules/{consistent-type-exports.md → consistent-type-exports.mdx} +17 -8
- package/docs/rules/{consistent-type-imports.md → consistent-type-imports.mdx} +13 -8
- package/docs/rules/{default-param-last.md → default-param-last.mdx} +10 -4
- package/docs/rules/{dot-notation.md → dot-notation.mdx} +3 -0
- package/docs/rules/{explicit-function-return-type.md → explicit-function-return-type.mdx} +59 -32
- package/docs/rules/{explicit-member-accessibility.md → explicit-member-accessibility.mdx} +3 -0
- package/docs/rules/{explicit-module-boundary-types.md → explicit-module-boundary-types.mdx} +39 -21
- package/docs/rules/{func-call-spacing.md → func-call-spacing.mdx} +3 -0
- package/docs/rules/{indent.md → indent.mdx} +3 -0
- package/docs/rules/{init-declarations.md → init-declarations.mdx} +3 -0
- package/docs/rules/{key-spacing.md → key-spacing.mdx} +3 -0
- package/docs/rules/{keyword-spacing.md → keyword-spacing.mdx} +3 -0
- package/docs/rules/{lines-around-comment.md → lines-around-comment.mdx} +3 -0
- package/docs/rules/{lines-between-class-members.md → lines-between-class-members.mdx} +3 -0
- package/docs/rules/{max-params.md → max-params.mdx} +3 -0
- package/docs/rules/{member-delimiter-style.md → member-delimiter-style.mdx} +13 -7
- package/docs/rules/{member-ordering.md → member-ordering.mdx} +92 -56
- package/docs/rules/{method-signature-style.md → method-signature-style.mdx} +17 -8
- package/docs/rules/{naming-convention.md → naming-convention.mdx} +3 -0
- package/docs/rules/{no-array-constructor.md → no-array-constructor.mdx} +10 -4
- package/docs/rules/{no-array-delete.md → no-array-delete.mdx} +9 -5
- package/docs/rules/{no-base-to-string.md → no-base-to-string.mdx} +12 -6
- package/docs/rules/{no-confusing-non-null-assertion.md → no-confusing-non-null-assertion.mdx} +11 -5
- package/docs/rules/{no-confusing-void-expression.md → no-confusing-void-expression.mdx} +10 -4
- package/docs/rules/{no-dupe-class-members.md → no-dupe-class-members.mdx} +4 -1
- package/docs/rules/{no-duplicate-enum-values.md → no-duplicate-enum-values.mdx} +10 -4
- package/docs/rules/{no-duplicate-imports.md → no-duplicate-imports.mdx} +1 -1
- package/docs/rules/{no-duplicate-type-constituents.md → no-duplicate-type-constituents.mdx} +10 -4
- package/docs/rules/{no-dynamic-delete.md → no-dynamic-delete.mdx} +10 -4
- package/docs/rules/{no-empty-function.md → no-empty-function.mdx} +3 -0
- package/docs/rules/{no-empty-interface.md → no-empty-interface.mdx} +9 -5
- package/docs/rules/{no-explicit-any.md → no-explicit-any.mdx} +15 -9
- package/docs/rules/{no-extra-non-null-assertion.md → no-extra-non-null-assertion.mdx} +11 -5
- package/docs/rules/{no-extra-parens.md → no-extra-parens.mdx} +3 -0
- package/docs/rules/{no-extra-semi.md → no-extra-semi.mdx} +3 -0
- package/docs/rules/{no-extraneous-class.md → no-extraneous-class.mdx} +61 -33
- package/docs/rules/{no-floating-promises.md → no-floating-promises.mdx} +12 -6
- package/docs/rules/{no-for-in-array.md → no-for-in-array.mdx} +10 -4
- package/docs/rules/{no-implied-eval.md → no-implied-eval.mdx} +10 -4
- package/docs/rules/{no-import-type-side-effects.md → no-import-type-side-effects.mdx} +12 -6
- package/docs/rules/{no-inferrable-types.md → no-inferrable-types.mdx} +9 -5
- package/docs/rules/{no-invalid-this.md → no-invalid-this.mdx} +4 -1
- package/docs/rules/{no-invalid-void-type.md → no-invalid-void-type.mdx} +10 -4
- package/docs/rules/{no-loop-func.md → no-loop-func.mdx} +3 -0
- package/docs/rules/{no-loss-of-precision.md → no-loss-of-precision.mdx} +3 -0
- package/docs/rules/{no-magic-numbers.md → no-magic-numbers.mdx} +3 -0
- package/docs/rules/{no-meaningless-void-operator.md → no-meaningless-void-operator.mdx} +12 -4
- package/docs/rules/{no-misused-new.md → no-misused-new.mdx} +10 -4
- package/docs/rules/{no-misused-promises.md → no-misused-promises.mdx} +24 -16
- package/docs/rules/{no-mixed-enums.md → no-mixed-enums.mdx} +14 -6
- package/docs/rules/{no-namespace.md → no-namespace.mdx} +29 -18
- package/docs/rules/{no-non-null-asserted-nullish-coalescing.md → no-non-null-asserted-nullish-coalescing.mdx} +10 -4
- package/docs/rules/{no-non-null-asserted-optional-chain.md → no-non-null-asserted-optional-chain.mdx} +10 -4
- package/docs/rules/{no-non-null-assertion.md → no-non-null-assertion.mdx} +10 -4
- package/docs/rules/{no-redeclare.md → no-redeclare.mdx} +4 -1
- package/docs/rules/{no-redundant-type-constituents.md → no-redundant-type-constituents.mdx} +10 -4
- package/docs/rules/{no-require-imports.md → no-require-imports.mdx} +18 -9
- package/docs/rules/{no-restricted-imports.md → no-restricted-imports.mdx} +10 -4
- package/docs/rules/{no-shadow.md → no-shadow.mdx} +4 -1
- package/docs/rules/{no-this-alias.md → no-this-alias.mdx} +24 -12
- package/docs/rules/{no-throw-literal.md → no-throw-literal.mdx} +11 -5
- package/docs/rules/{no-type-alias.md → no-type-alias.mdx} +5 -2
- package/docs/rules/{no-unnecessary-boolean-literal-compare.md → no-unnecessary-boolean-literal-compare.mdx} +24 -12
- package/docs/rules/{no-unnecessary-condition.md → no-unnecessary-condition.mdx} +11 -5
- package/docs/rules/{no-unnecessary-qualifier.md → no-unnecessary-qualifier.mdx} +10 -4
- package/docs/rules/{no-unnecessary-type-arguments.md → no-unnecessary-type-arguments.mdx} +10 -4
- package/docs/rules/{no-unnecessary-type-assertion.md → no-unnecessary-type-assertion.mdx} +10 -4
- package/docs/rules/{no-unnecessary-type-constraint.md → no-unnecessary-type-constraint.mdx} +10 -4
- package/docs/rules/{no-unsafe-argument.md → no-unsafe-argument.mdx} +14 -10
- package/docs/rules/{no-unsafe-assignment.md → no-unsafe-assignment.mdx} +14 -10
- package/docs/rules/{no-unsafe-call.md → no-unsafe-call.mdx} +15 -9
- package/docs/rules/{no-unsafe-declaration-merging.md → no-unsafe-declaration-merging.mdx} +10 -4
- package/docs/rules/{no-unsafe-enum-comparison.md → no-unsafe-enum-comparison.mdx} +9 -5
- package/docs/rules/{no-unsafe-member-access.md → no-unsafe-member-access.mdx} +15 -9
- package/docs/rules/{no-unsafe-return.md → no-unsafe-return.mdx} +14 -10
- package/docs/rules/{no-unsafe-unary-minus.md → no-unsafe-unary-minus.mdx} +11 -5
- package/docs/rules/{no-unused-expressions.md → no-unused-expressions.mdx} +3 -0
- package/docs/rules/{no-unused-vars.md → no-unused-vars.mdx} +3 -0
- package/docs/rules/{no-use-before-define.md → no-use-before-define.mdx} +10 -4
- package/docs/rules/{no-useless-constructor.md → no-useless-constructor.mdx} +3 -0
- package/docs/rules/{no-useless-empty-export.md → no-useless-empty-export.mdx} +10 -4
- package/docs/rules/{no-useless-template-literals.md → no-useless-template-literals.mdx} +10 -6
- package/docs/rules/{no-var-requires.md → no-var-requires.mdx} +18 -9
- package/docs/rules/{non-nullable-type-assertion-style.md → non-nullable-type-assertion-style.mdx} +10 -4
- package/docs/rules/{object-curly-spacing.md → object-curly-spacing.mdx} +3 -0
- package/docs/rules/{padding-line-between-statements.md → padding-line-between-statements.mdx} +3 -0
- package/docs/rules/{parameter-properties.md → parameter-properties.mdx} +66 -36
- package/docs/rules/{prefer-as-const.md → prefer-as-const.mdx} +9 -5
- package/docs/rules/{prefer-destructuring.md → prefer-destructuring.mdx} +23 -12
- package/docs/rules/{prefer-enum-initializers.md → prefer-enum-initializers.mdx} +10 -4
- package/docs/rules/{prefer-find.md → prefer-find.mdx} +10 -4
- package/docs/rules/{prefer-for-of.md → prefer-for-of.mdx} +11 -5
- package/docs/rules/{prefer-function-type.md → prefer-function-type.mdx} +10 -4
- package/docs/rules/{prefer-includes.md → prefer-includes.mdx} +11 -5
- package/docs/rules/{prefer-literal-enum-member.md → prefer-literal-enum-member.mdx} +16 -9
- package/docs/rules/{prefer-namespace-keyword.md → prefer-namespace-keyword.mdx} +9 -5
- package/docs/rules/{prefer-nullish-coalescing.md → prefer-nullish-coalescing.mdx} +3 -0
- package/docs/rules/{prefer-optional-chain.md → prefer-optional-chain.mdx} +58 -33
- package/docs/rules/{prefer-promise-reject-errors.md → prefer-promise-reject-errors.mdx} +10 -4
- package/docs/rules/{prefer-readonly-parameter-types.md → prefer-readonly-parameter-types.mdx} +36 -22
- package/docs/rules/{prefer-readonly.md → prefer-readonly.mdx} +17 -8
- package/docs/rules/{prefer-reduce-type-parameter.md → prefer-reduce-type-parameter.mdx} +10 -4
- package/docs/rules/{prefer-regexp-exec.md → prefer-regexp-exec.mdx} +10 -4
- package/docs/rules/{prefer-return-this-type.md → prefer-return-this-type.mdx} +10 -4
- package/docs/rules/{prefer-string-starts-ends-with.md → prefer-string-starts-ends-with.mdx} +9 -5
- package/docs/rules/{prefer-ts-expect-error.md → prefer-ts-expect-error.mdx} +10 -4
- package/docs/rules/{promise-function-async.md → promise-function-async.mdx} +24 -12
- package/docs/rules/{quotes.md → quotes.mdx} +3 -0
- package/docs/rules/{require-array-sort-compare.md → require-array-sort-compare.mdx} +17 -8
- package/docs/rules/{require-await.md → require-await.mdx} +3 -0
- package/docs/rules/{restrict-plus-operands.md → restrict-plus-operands.mdx} +54 -30
- package/docs/rules/{restrict-template-expressions.md → restrict-template-expressions.mdx} +24 -9
- package/docs/rules/{return-await.md → return-await.mdx} +24 -12
- package/docs/rules/{semi.md → semi.mdx} +4 -1
- package/docs/rules/{sort-type-constituents.md → sort-type-constituents.mdx} +31 -16
- package/docs/rules/{space-before-blocks.md → space-before-blocks.mdx} +10 -4
- package/docs/rules/{space-before-function-paren.md → space-before-function-paren.mdx} +3 -0
- package/docs/rules/{space-infix-ops.md → space-infix-ops.mdx} +3 -0
- package/docs/rules/{strict-boolean-expressions.md → strict-boolean-expressions.mdx} +11 -5
- package/docs/rules/{switch-exhaustiveness-check.md → switch-exhaustiveness-check.mdx} +19 -14
- package/docs/rules/{triple-slash-reference.md → triple-slash-reference.mdx} +30 -17
- package/docs/rules/{type-annotation-spacing.md → type-annotation-spacing.mdx} +49 -31
- package/docs/rules/{typedef.md → typedef.mdx} +60 -33
- package/docs/rules/{unbound-method.md → unbound-method.mdx} +12 -6
- package/docs/rules/{unified-signatures.md → unified-signatures.mdx} +18 -9
- package/docs/rules/use-unknown-in-catch-callback-variable.mdx +84 -0
- package/package.json +8 -8
- /package/docs/rules/{no-parameter-properties.md → no-parameter-properties.mdx} +0 -0
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow Promises in places not designed to handle them.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-misused-promises** for documentation.
|
|
@@ -12,7 +15,7 @@ functions are handled/awaited.
|
|
|
12
15
|
|
|
13
16
|
:::tip
|
|
14
17
|
`no-misused-promises` only detects code that provides Promises to incorrect _logical_ locations.
|
|
15
|
-
See [`no-floating-promises`](./no-floating-promises.
|
|
18
|
+
See [`no-floating-promises`](./no-floating-promises.mdx) for detecting unhandled Promise _statements_.
|
|
16
19
|
:::
|
|
17
20
|
|
|
18
21
|
## Options
|
|
@@ -36,9 +39,10 @@ Doing so prevents the rule from looking at code like `if (somePromise)`.
|
|
|
36
39
|
|
|
37
40
|
Examples of code for this rule with `checksConditionals: true`:
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
## Examples
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
<Tabs>
|
|
45
|
+
<TabItem value="❌ Incorrect">
|
|
42
46
|
|
|
43
47
|
```ts option='{ "checksConditionals": true }'
|
|
44
48
|
const promise = Promise.resolve('value');
|
|
@@ -54,7 +58,8 @@ while (promise) {
|
|
|
54
58
|
}
|
|
55
59
|
```
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
</TabItem>
|
|
62
|
+
<TabItem value="✅ Correct">
|
|
58
63
|
|
|
59
64
|
```ts option='{ "checksConditionals": true }'
|
|
60
65
|
const promise = Promise.resolve('value');
|
|
@@ -71,7 +76,8 @@ while (await promise) {
|
|
|
71
76
|
}
|
|
72
77
|
```
|
|
73
78
|
|
|
74
|
-
|
|
79
|
+
</TabItem>
|
|
80
|
+
</Tabs>
|
|
75
81
|
|
|
76
82
|
### `checksVoidReturn`
|
|
77
83
|
|
|
@@ -116,9 +122,8 @@ For example, if you don't mind that passing a `() => Promise<void>` to a `() =>
|
|
|
116
122
|
|
|
117
123
|
Examples of code for this rule with `checksVoidReturn: true`:
|
|
118
124
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
#### ❌ Incorrect
|
|
125
|
+
<Tabs>
|
|
126
|
+
<TabItem value="❌ Incorrect">
|
|
122
127
|
|
|
123
128
|
```ts option='{ "checksVoidReturn": true }'
|
|
124
129
|
[1, 2, 3].forEach(async value => {
|
|
@@ -138,7 +143,8 @@ eventEmitter.on('some-event', async () => {
|
|
|
138
143
|
});
|
|
139
144
|
```
|
|
140
145
|
|
|
141
|
-
|
|
146
|
+
</TabItem>
|
|
147
|
+
<TabItem value="✅ Correct">
|
|
142
148
|
|
|
143
149
|
```ts option='{ "checksVoidReturn": true }'
|
|
144
150
|
// for-of puts `await` in outer context
|
|
@@ -180,7 +186,8 @@ eventEmitter.on('some-event', () => {
|
|
|
180
186
|
});
|
|
181
187
|
```
|
|
182
188
|
|
|
183
|
-
|
|
189
|
+
</TabItem>
|
|
190
|
+
</Tabs>
|
|
184
191
|
|
|
185
192
|
### `checksSpreads`
|
|
186
193
|
|
|
@@ -199,9 +206,8 @@ If you don't want to check object spreads, you can add this configuration:
|
|
|
199
206
|
|
|
200
207
|
Examples of code for this rule with `checksSpreads: true`:
|
|
201
208
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
#### ❌ Incorrect
|
|
209
|
+
<Tabs>
|
|
210
|
+
<TabItem value="❌ Incorrect">
|
|
205
211
|
|
|
206
212
|
```ts option='{ "checksSpreads": true }'
|
|
207
213
|
const getData = () => someAsyncOperation({ myArg: 'foo' });
|
|
@@ -215,7 +221,8 @@ const getData2 = async () => {
|
|
|
215
221
|
return { foo: 42, ...getData2() };
|
|
216
222
|
```
|
|
217
223
|
|
|
218
|
-
|
|
224
|
+
</TabItem>
|
|
225
|
+
<TabItem value="✅ Correct">
|
|
219
226
|
|
|
220
227
|
```ts option='{ "checksSpreads": true }'
|
|
221
228
|
const getData = () => someAsyncOperation({ myArg: 'foo' });
|
|
@@ -229,7 +236,8 @@ const getData2 = async () => {
|
|
|
229
236
|
return { foo: 42, ...(await getData2()) };
|
|
230
237
|
```
|
|
231
238
|
|
|
232
|
-
|
|
239
|
+
</TabItem>
|
|
240
|
+
</Tabs>
|
|
233
241
|
|
|
234
242
|
## When Not To Use It
|
|
235
243
|
|
|
@@ -243,4 +251,4 @@ You might consider using [ESLint disable comments](https://eslint.org/docs/lates
|
|
|
243
251
|
|
|
244
252
|
## Related To
|
|
245
253
|
|
|
246
|
-
- [`no-floating-promises`](./no-floating-promises.
|
|
254
|
+
- [`no-floating-promises`](./no-floating-promises.mdx)
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow enums from having both number and string members.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-mixed-enums** for documentation.
|
|
@@ -12,9 +15,8 @@ Mixing enum member types is generally considered confusing and a bad practice.
|
|
|
12
15
|
|
|
13
16
|
## Examples
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
### ❌ Incorrect
|
|
18
|
+
<Tabs>
|
|
19
|
+
<TabItem value="❌ Incorrect">
|
|
18
20
|
|
|
19
21
|
```ts
|
|
20
22
|
enum Status {
|
|
@@ -24,7 +26,8 @@ enum Status {
|
|
|
24
26
|
}
|
|
25
27
|
```
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
</TabItem>
|
|
30
|
+
<TabItem value="✅ Correct (Explicit Numbers)">
|
|
28
31
|
|
|
29
32
|
```ts
|
|
30
33
|
enum Status {
|
|
@@ -34,7 +37,8 @@ enum Status {
|
|
|
34
37
|
}
|
|
35
38
|
```
|
|
36
39
|
|
|
37
|
-
|
|
40
|
+
</TabItem>
|
|
41
|
+
<TabItem value="✅ Correct (Implicit Numbers)">
|
|
38
42
|
|
|
39
43
|
```ts
|
|
40
44
|
enum Status {
|
|
@@ -44,7 +48,8 @@ enum Status {
|
|
|
44
48
|
}
|
|
45
49
|
```
|
|
46
50
|
|
|
47
|
-
|
|
51
|
+
</TabItem>
|
|
52
|
+
<TabItem value="✅ Correct (Strings)">
|
|
48
53
|
|
|
49
54
|
```ts
|
|
50
55
|
enum Status {
|
|
@@ -54,6 +59,9 @@ enum Status {
|
|
|
54
59
|
}
|
|
55
60
|
```
|
|
56
61
|
|
|
62
|
+
</TabItem>
|
|
63
|
+
</Tabs>
|
|
64
|
+
|
|
57
65
|
## Iteration Pitfalls of Mixed Enum Member Values
|
|
58
66
|
|
|
59
67
|
Enum values may be iterated over using `Object.entries`/`Object.keys`/`Object.values`.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow TypeScript namespaces.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-namespace** for documentation.
|
|
@@ -16,9 +19,8 @@ ES2015 module syntax is now preferred (`import`/`export`).
|
|
|
16
19
|
|
|
17
20
|
Examples of code with the default options:
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
### ❌ Incorrect
|
|
22
|
+
<Tabs>
|
|
23
|
+
<TabItem value="❌ Incorrect">
|
|
22
24
|
|
|
23
25
|
```ts
|
|
24
26
|
module foo {}
|
|
@@ -28,7 +30,8 @@ declare module foo {}
|
|
|
28
30
|
declare namespace foo {}
|
|
29
31
|
```
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
</TabItem>
|
|
34
|
+
<TabItem value="✅ Correct">
|
|
32
35
|
|
|
33
36
|
```ts
|
|
34
37
|
declare module 'foo' {}
|
|
@@ -36,7 +39,8 @@ declare module 'foo' {}
|
|
|
36
39
|
// anything inside a d.ts file
|
|
37
40
|
```
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
</TabItem>
|
|
43
|
+
</Tabs>
|
|
40
44
|
|
|
41
45
|
## Options
|
|
42
46
|
|
|
@@ -44,16 +48,16 @@ declare module 'foo' {}
|
|
|
44
48
|
|
|
45
49
|
Examples of code with the `{ "allowDeclarations": true }` option:
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
#### ❌ Incorrect
|
|
51
|
+
<Tabs>
|
|
52
|
+
<TabItem value="❌ Incorrect">
|
|
50
53
|
|
|
51
54
|
```ts option='{ "allowDeclarations": true }'
|
|
52
55
|
module foo {}
|
|
53
56
|
namespace foo {}
|
|
54
57
|
```
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
</TabItem>
|
|
60
|
+
<TabItem value="✅ Correct">
|
|
57
61
|
|
|
58
62
|
```ts option='{ "allowDeclarations": true }'
|
|
59
63
|
declare module 'foo' {}
|
|
@@ -69,13 +73,13 @@ declare module foo {
|
|
|
69
73
|
}
|
|
70
74
|
```
|
|
71
75
|
|
|
72
|
-
|
|
76
|
+
</TabItem>
|
|
77
|
+
</Tabs>
|
|
73
78
|
|
|
74
79
|
Examples of code for the `{ "allowDeclarations": false }` option:
|
|
75
80
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
#### ❌ Incorrect
|
|
81
|
+
<Tabs>
|
|
82
|
+
<TabItem value="❌ Incorrect">
|
|
79
83
|
|
|
80
84
|
```ts option='{ "allowDeclarations": false }'
|
|
81
85
|
module foo {}
|
|
@@ -84,19 +88,22 @@ declare module foo {}
|
|
|
84
88
|
declare namespace foo {}
|
|
85
89
|
```
|
|
86
90
|
|
|
87
|
-
|
|
91
|
+
</TabItem>
|
|
92
|
+
<TabItem value="✅ Correct">
|
|
88
93
|
|
|
89
94
|
```ts option='{ "allowDeclarations": false }'
|
|
90
95
|
declare module 'foo' {}
|
|
91
96
|
```
|
|
92
97
|
|
|
98
|
+
</TabItem>
|
|
99
|
+
</Tabs>
|
|
100
|
+
|
|
93
101
|
### `allowDefinitionFiles`
|
|
94
102
|
|
|
95
103
|
Examples of code for the `{ "allowDefinitionFiles": true }` option:
|
|
96
104
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
#### ❌ Incorrect
|
|
105
|
+
<Tabs>
|
|
106
|
+
<TabItem value="❌ Incorrect">
|
|
100
107
|
|
|
101
108
|
```ts option='{ "allowDefinitionFiles": true }'
|
|
102
109
|
// if outside a d.ts file
|
|
@@ -110,7 +117,8 @@ declare module foo {}
|
|
|
110
117
|
declare namespace foo {}
|
|
111
118
|
```
|
|
112
119
|
|
|
113
|
-
|
|
120
|
+
</TabItem>
|
|
121
|
+
<TabItem value="✅ Correct">
|
|
114
122
|
|
|
115
123
|
```ts option='{ "allowDefinitionFiles": true }'
|
|
116
124
|
declare module 'foo' {}
|
|
@@ -118,6 +126,9 @@ declare module 'foo' {}
|
|
|
118
126
|
// anything inside a d.ts file
|
|
119
127
|
```
|
|
120
128
|
|
|
129
|
+
</TabItem>
|
|
130
|
+
</Tabs>
|
|
131
|
+
|
|
121
132
|
## When Not To Use It
|
|
122
133
|
|
|
123
134
|
If your project was architected before modern modules and namespaces, it may be difficult to migrate off of namespaces.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow non-null assertions in the left operand of a nullish coalescing operator.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-non-null-asserted-nullish-coalescing** for documentation.
|
|
@@ -11,9 +14,8 @@ Using a `!` non-null assertion type operator in the left operand of a nullish co
|
|
|
11
14
|
|
|
12
15
|
## Examples
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
### ❌ Incorrect
|
|
17
|
+
<Tabs>
|
|
18
|
+
<TabItem value="❌ Incorrect">
|
|
17
19
|
|
|
18
20
|
```ts
|
|
19
21
|
foo! ?? bar;
|
|
@@ -29,7 +31,8 @@ x = foo();
|
|
|
29
31
|
x! ?? '';
|
|
30
32
|
```
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
</TabItem>
|
|
35
|
+
<TabItem value="✅ Correct">
|
|
33
36
|
|
|
34
37
|
```ts
|
|
35
38
|
foo ?? bar;
|
|
@@ -43,6 +46,9 @@ let x: string;
|
|
|
43
46
|
x! ?? '';
|
|
44
47
|
```
|
|
45
48
|
|
|
49
|
+
</TabItem>
|
|
50
|
+
</Tabs>
|
|
51
|
+
|
|
46
52
|
## When Not To Use It
|
|
47
53
|
|
|
48
54
|
If your project's types don't yet fully describe whether certain values may be nullable, such as if you're transitioning to `strictNullChecks`, this rule might create many false reports.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow non-null assertions after an optional chain expression.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-non-null-asserted-optional-chain** for documentation.
|
|
@@ -13,22 +16,25 @@ Using a `!` non-null assertion to assert the result of an `?.` optional chain ex
|
|
|
13
16
|
|
|
14
17
|
## Examples
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
### ❌ Incorrect
|
|
19
|
+
<Tabs>
|
|
20
|
+
<TabItem value="❌ Incorrect">
|
|
19
21
|
|
|
20
22
|
```ts
|
|
21
23
|
foo?.bar!;
|
|
22
24
|
foo?.bar()!;
|
|
23
25
|
```
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
</TabItem>
|
|
28
|
+
<TabItem value="✅ Correct">
|
|
26
29
|
|
|
27
30
|
```ts
|
|
28
31
|
foo?.bar;
|
|
29
32
|
foo?.bar();
|
|
30
33
|
```
|
|
31
34
|
|
|
35
|
+
</TabItem>
|
|
36
|
+
</Tabs>
|
|
37
|
+
|
|
32
38
|
## When Not To Use It
|
|
33
39
|
|
|
34
40
|
If your project's types don't yet fully describe whether certain values may be nullable, such as if you're transitioning to `strictNullChecks`, this rule might create many false reports.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow non-null assertions using the `!` postfix operator.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-non-null-assertion** for documentation.
|
|
@@ -12,9 +15,8 @@ It's generally better to structure program logic so that TypeScript understands
|
|
|
12
15
|
|
|
13
16
|
## Examples
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
### ❌ Incorrect
|
|
18
|
+
<Tabs>
|
|
19
|
+
<TabItem value="❌ Incorrect">
|
|
18
20
|
|
|
19
21
|
```ts
|
|
20
22
|
interface Example {
|
|
@@ -25,7 +27,8 @@ declare const example: Example;
|
|
|
25
27
|
const includesBaz = example.property!.includes('baz');
|
|
26
28
|
```
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
</TabItem>
|
|
31
|
+
<TabItem value="✅ Correct">
|
|
29
32
|
|
|
30
33
|
```ts
|
|
31
34
|
interface Example {
|
|
@@ -36,6 +39,9 @@ declare const example: Example;
|
|
|
36
39
|
const includesBaz = example.property?.includes('baz') ?? false;
|
|
37
40
|
```
|
|
38
41
|
|
|
42
|
+
</TabItem>
|
|
43
|
+
</Tabs>
|
|
44
|
+
|
|
39
45
|
## When Not To Use It
|
|
40
46
|
|
|
41
47
|
If your project's types don't yet fully describe whether certain values may be nullable, such as if you're transitioning to `strictNullChecks`, this rule might create many false reports.
|
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
description: 'Disallow variable redeclaration.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-redeclare** for documentation.
|
|
8
11
|
|
|
9
|
-
import TypeScriptOverlap from
|
|
12
|
+
import TypeScriptOverlap from '@site/src/components/TypeScriptOverlap';
|
|
10
13
|
|
|
11
14
|
<TypeScriptOverlap />
|
|
12
15
|
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow members of unions and intersections that do nothing or override type information.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-redundant-type-constituents** for documentation.
|
|
@@ -24,9 +27,8 @@ Within `&` intersections:
|
|
|
24
27
|
|
|
25
28
|
## Examples
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
### ❌ Incorrect
|
|
30
|
+
<Tabs>
|
|
31
|
+
<TabItem value="❌ Incorrect">
|
|
30
32
|
|
|
31
33
|
```ts
|
|
32
34
|
type UnionAny = any | 'foo';
|
|
@@ -46,7 +48,8 @@ type IntersectionNumberLiteral = number & 1;
|
|
|
46
48
|
type IntersectionStringLiteral = string & 'foo';
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
</TabItem>
|
|
52
|
+
<TabItem value="✅ Correct">
|
|
50
53
|
|
|
51
54
|
```ts
|
|
52
55
|
type UnionAny = any;
|
|
@@ -66,6 +69,9 @@ type IntersectionNumberLiteral = 1;
|
|
|
66
69
|
type IntersectionStringLiteral = 'foo';
|
|
67
70
|
```
|
|
68
71
|
|
|
72
|
+
</TabItem>
|
|
73
|
+
</Tabs>
|
|
74
|
+
|
|
69
75
|
## Limitations
|
|
70
76
|
|
|
71
77
|
This rule plays it safe and only works with bottom types, top types, and comparing literal types to primitive types.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow invocation of `require()`.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-require-imports** for documentation.
|
|
@@ -10,9 +13,8 @@ Prefer the newer ES6-style imports over `require()`.
|
|
|
10
13
|
|
|
11
14
|
## Examples
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
### ❌ Incorrect
|
|
16
|
+
<Tabs>
|
|
17
|
+
<TabItem value="❌ Incorrect">
|
|
16
18
|
|
|
17
19
|
```ts
|
|
18
20
|
const lib1 = require('lib1');
|
|
@@ -20,7 +22,8 @@ const { lib2 } = require('lib2');
|
|
|
20
22
|
import lib3 = require('lib3');
|
|
21
23
|
```
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
</TabItem>
|
|
26
|
+
<TabItem value="✅ Correct">
|
|
24
27
|
|
|
25
28
|
```ts
|
|
26
29
|
import * as lib1 from 'lib1';
|
|
@@ -28,6 +31,9 @@ import { lib2 } from 'lib2';
|
|
|
28
31
|
import * as lib3 from 'lib3';
|
|
29
32
|
```
|
|
30
33
|
|
|
34
|
+
</TabItem>
|
|
35
|
+
</Tabs>
|
|
36
|
+
|
|
31
37
|
## Options
|
|
32
38
|
|
|
33
39
|
### `allow`
|
|
@@ -36,20 +42,23 @@ A array of strings. These strings will be compiled into regular expressions with
|
|
|
36
42
|
|
|
37
43
|
With `{allow: ['/package\\.json$']}`:
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### ❌ Incorrect
|
|
45
|
+
<Tabs>
|
|
46
|
+
<TabItem value="❌ Incorrect">
|
|
42
47
|
|
|
43
48
|
```ts
|
|
44
49
|
console.log(require('../data.json').version);
|
|
45
50
|
```
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
</TabItem>
|
|
53
|
+
<TabItem value="✅ Correct">
|
|
48
54
|
|
|
49
55
|
```ts
|
|
50
56
|
console.log(require('../package.json').version);
|
|
51
57
|
```
|
|
52
58
|
|
|
59
|
+
</TabItem>
|
|
60
|
+
</Tabs>
|
|
61
|
+
|
|
53
62
|
## When Not To Use It
|
|
54
63
|
|
|
55
64
|
If your project frequently uses older CommonJS `require`s, then this rule might not be applicable to you.
|
|
@@ -57,4 +66,4 @@ If only a subset of your project uses `require`s then you might consider using [
|
|
|
57
66
|
|
|
58
67
|
## Related To
|
|
59
68
|
|
|
60
|
-
- [`no-var-requires`](./no-var-requires.
|
|
69
|
+
- [`no-var-requires`](./no-var-requires.mdx)
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow specified modules when loaded by `import`.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-restricted-imports** for documentation.
|
|
@@ -46,9 +49,8 @@ When set to `true`, the rule will allow [Type-Only Imports](https://www.typescri
|
|
|
46
49
|
|
|
47
50
|
Examples of code with the above config:
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
#### ❌ Incorrect
|
|
52
|
+
<Tabs>
|
|
53
|
+
<TabItem value="❌ Incorrect">
|
|
52
54
|
|
|
53
55
|
```ts option='{"paths":[{"name":"import-foo","message":"Please use import-bar instead.","allowTypeImports":true},{"name":"import-baz","message":"Please use import-quux instead.","allowTypeImports":true}]}'
|
|
54
56
|
import foo from 'import-foo';
|
|
@@ -58,7 +60,8 @@ import baz from 'import-baz';
|
|
|
58
60
|
export { Baz } from 'import-baz';
|
|
59
61
|
```
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
</TabItem>
|
|
64
|
+
<TabItem value="✅ Correct">
|
|
62
65
|
|
|
63
66
|
```ts option='{"paths":[{"name":"import-foo","message":"Please use import-bar instead.","allowTypeImports":true},{"name":"import-baz","message":"Please use import-quux instead.","allowTypeImports":true}]}'
|
|
64
67
|
import { foo } from 'other-module';
|
|
@@ -69,3 +72,6 @@ export type { Foo } from 'import-foo';
|
|
|
69
72
|
import type baz from 'import-baz';
|
|
70
73
|
export type { Baz } from 'import-baz';
|
|
71
74
|
```
|
|
75
|
+
|
|
76
|
+
</TabItem>
|
|
77
|
+
</Tabs>
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow variable declarations from shadowing variables declared in the outer scope.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/no-shadow** for documentation.
|
|
@@ -46,7 +49,7 @@ function f() {
|
|
|
46
49
|
|
|
47
50
|
:::note
|
|
48
51
|
|
|
49
|
-
_Shadowing_ specifically refers to two identical identifiers that are in different, nested scopes. This is different from _redeclaration_, which is when two identical identifiers are in the same scope. Redeclaration is covered by the [`no-redeclare`](./no-redeclare.
|
|
52
|
+
_Shadowing_ specifically refers to two identical identifiers that are in different, nested scopes. This is different from _redeclaration_, which is when two identical identifiers are in the same scope. Redeclaration is covered by the [`no-redeclare`](./no-redeclare.mdx) rule instead.
|
|
50
53
|
|
|
51
54
|
:::
|
|
52
55
|
|