@typescript-eslint/eslint-plugin 8.0.0-alpha.6 → 8.0.0-alpha.61
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 +7 -6
- package/dist/configs/all.js.map +1 -1
- package/dist/configs/disable-type-checked.js +3 -3
- package/dist/configs/disable-type-checked.js.map +1 -1
- package/dist/configs/recommended-type-checked-only.js +6 -0
- package/dist/configs/recommended-type-checked-only.js.map +1 -1
- package/dist/configs/recommended-type-checked.js +13 -2
- package/dist/configs/recommended-type-checked.js.map +1 -1
- package/dist/configs/recommended.js +7 -2
- package/dist/configs/recommended.js.map +1 -1
- package/dist/configs/strict-type-checked-only.js +8 -2
- package/dist/configs/strict-type-checked-only.js.map +1 -1
- package/dist/configs/strict-type-checked.js +15 -5
- package/dist/configs/strict-type-checked.js.map +1 -1
- package/dist/configs/strict.js +7 -3
- package/dist/configs/strict.js.map +1 -1
- package/dist/configs/stylistic-type-checked-only.js +3 -0
- package/dist/configs/stylistic-type-checked-only.js.map +1 -1
- package/dist/configs/stylistic-type-checked.js +3 -2
- package/dist/configs/stylistic-type-checked.js.map +1 -1
- package/dist/configs/stylistic.js +0 -2
- package/dist/configs/stylistic.js.map +1 -1
- package/dist/rules/adjacent-overload-signatures.js +2 -6
- package/dist/rules/adjacent-overload-signatures.js.map +1 -1
- package/dist/rules/array-type.js +14 -5
- package/dist/rules/array-type.js.map +1 -1
- package/dist/rules/class-literal-property-style.js +16 -16
- package/dist/rules/class-literal-property-style.js.map +1 -1
- package/dist/rules/class-methods-use-this.js.map +1 -1
- package/dist/rules/consistent-type-assertions.js +5 -19
- package/dist/rules/consistent-type-assertions.js.map +1 -1
- package/dist/rules/consistent-type-definitions.js +1 -1
- package/dist/rules/consistent-type-definitions.js.map +1 -1
- package/dist/rules/consistent-type-imports.js +13 -13
- package/dist/rules/consistent-type-imports.js.map +1 -1
- package/dist/rules/default-param-last.js +6 -1
- package/dist/rules/default-param-last.js.map +1 -1
- package/dist/rules/dot-notation.js +8 -1
- package/dist/rules/dot-notation.js.map +1 -1
- package/dist/rules/enum-utils/shared.js +3 -4
- package/dist/rules/enum-utils/shared.js.map +1 -1
- package/dist/rules/explicit-member-accessibility.js +49 -37
- package/dist/rules/explicit-member-accessibility.js.map +1 -1
- package/dist/rules/index.js +14 -6
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/init-declarations.js +57 -1
- package/dist/rules/init-declarations.js.map +1 -1
- package/dist/rules/member-ordering.js +8 -2
- package/dist/rules/member-ordering.js.map +1 -1
- package/dist/rules/method-signature-style.js +1 -3
- package/dist/rules/method-signature-style.js.map +1 -1
- package/dist/rules/naming-convention-utils/parse-options.js +2 -5
- package/dist/rules/naming-convention-utils/parse-options.js.map +1 -1
- package/dist/rules/naming-convention-utils/shared.js +3 -4
- package/dist/rules/naming-convention-utils/shared.js.map +1 -1
- package/dist/rules/naming-convention-utils/validator.js +1 -2
- package/dist/rules/naming-convention-utils/validator.js.map +1 -1
- package/dist/rules/naming-convention.js +3 -1
- package/dist/rules/naming-convention.js.map +1 -1
- package/dist/rules/no-array-delete.js +1 -1
- package/dist/rules/no-array-delete.js.map +1 -1
- package/dist/rules/no-base-to-string.js +1 -1
- package/dist/rules/no-base-to-string.js.map +1 -1
- package/dist/rules/no-duplicate-type-constituents.js +29 -3
- package/dist/rules/no-duplicate-type-constituents.js.map +1 -1
- package/dist/rules/no-dynamic-delete.js +8 -40
- package/dist/rules/no-dynamic-delete.js.map +1 -1
- package/dist/rules/no-empty-interface.js +2 -1
- package/dist/rules/no-empty-interface.js.map +1 -1
- package/dist/rules/no-empty-object-type.js +141 -0
- package/dist/rules/no-empty-object-type.js.map +1 -0
- package/dist/rules/no-extraneous-class.js +11 -3
- package/dist/rules/no-extraneous-class.js.map +1 -1
- package/dist/rules/no-floating-promises.js +91 -55
- package/dist/rules/no-floating-promises.js.map +1 -1
- package/dist/rules/no-implied-eval.js +6 -24
- package/dist/rules/no-implied-eval.js.map +1 -1
- package/dist/rules/no-inferrable-types.js +1 -2
- package/dist/rules/no-inferrable-types.js.map +1 -1
- package/dist/rules/no-invalid-this.js +6 -0
- package/dist/rules/no-invalid-this.js.map +1 -1
- package/dist/rules/no-magic-numbers.js +32 -1
- package/dist/rules/no-magic-numbers.js.map +1 -1
- package/dist/rules/no-misused-new.js +4 -3
- package/dist/rules/no-misused-new.js.map +1 -1
- package/dist/rules/no-misused-promises.js +76 -1
- package/dist/rules/no-misused-promises.js.map +1 -1
- package/dist/rules/no-mixed-enums.js +6 -9
- package/dist/rules/no-mixed-enums.js.map +1 -1
- package/dist/rules/no-non-null-assertion.js +12 -14
- package/dist/rules/no-non-null-assertion.js.map +1 -1
- package/dist/rules/no-require-imports.js +13 -3
- package/dist/rules/no-require-imports.js.map +1 -1
- package/dist/rules/no-restricted-imports.js +5 -6
- package/dist/rules/no-restricted-imports.js.map +1 -1
- package/dist/rules/{ban-types.js → no-restricted-types.js} +17 -91
- package/dist/rules/no-restricted-types.js.map +1 -0
- package/dist/rules/no-shadow.js +4 -9
- package/dist/rules/no-shadow.js.map +1 -1
- package/dist/rules/no-unnecessary-condition.js +8 -6
- package/dist/rules/no-unnecessary-condition.js.map +1 -1
- package/dist/rules/no-unnecessary-parameter-property-assignment.js +151 -0
- package/dist/rules/no-unnecessary-parameter-property-assignment.js.map +1 -0
- package/dist/rules/no-unnecessary-qualifier.js.map +1 -1
- package/dist/rules/no-unnecessary-template-expression.js +223 -0
- package/dist/rules/no-unnecessary-template-expression.js.map +1 -0
- package/dist/rules/no-unnecessary-type-assertion.js +16 -13
- package/dist/rules/no-unnecessary-type-assertion.js.map +1 -1
- package/dist/rules/no-unnecessary-type-parameters.js +309 -0
- package/dist/rules/no-unnecessary-type-parameters.js.map +1 -0
- package/dist/rules/no-unsafe-argument.js +4 -2
- package/dist/rules/no-unsafe-argument.js.map +1 -1
- package/dist/rules/no-unsafe-assignment.js +24 -9
- package/dist/rules/no-unsafe-assignment.js.map +1 -1
- package/dist/rules/no-unsafe-call.js +5 -1
- package/dist/rules/no-unsafe-call.js.map +1 -1
- package/dist/rules/no-unsafe-enum-comparison.js +1 -5
- package/dist/rules/no-unsafe-enum-comparison.js.map +1 -1
- package/dist/rules/no-unsafe-function-type.js +47 -0
- package/dist/rules/no-unsafe-function-type.js.map +1 -0
- package/dist/rules/no-unsafe-member-access.js +10 -4
- package/dist/rules/no-unsafe-member-access.js.map +1 -1
- package/dist/rules/no-unsafe-return.js +9 -3
- package/dist/rules/no-unsafe-return.js.map +1 -1
- package/dist/rules/no-unsafe-unary-minus.js +1 -0
- package/dist/rules/no-unsafe-unary-minus.js.map +1 -1
- package/dist/rules/no-unused-expressions.js +1 -0
- package/dist/rules/no-unused-expressions.js.map +1 -1
- package/dist/rules/no-unused-vars.js +198 -79
- package/dist/rules/no-unused-vars.js.map +1 -1
- package/dist/rules/no-use-before-define.js +2 -16
- package/dist/rules/no-use-before-define.js.map +1 -1
- package/dist/rules/no-useless-constructor.js +1 -3
- package/dist/rules/no-useless-constructor.js.map +1 -1
- package/dist/rules/no-var-requires.js +2 -1
- package/dist/rules/no-var-requires.js.map +1 -1
- package/dist/rules/no-wrapper-object-types.js +61 -0
- package/dist/rules/no-wrapper-object-types.js.map +1 -0
- package/dist/rules/only-throw-error.js +1 -1
- package/dist/rules/only-throw-error.js.map +1 -1
- package/dist/rules/prefer-as-const.js +1 -1
- package/dist/rules/prefer-as-const.js.map +1 -1
- package/dist/rules/prefer-destructuring.js +3 -1
- package/dist/rules/prefer-destructuring.js.map +1 -1
- package/dist/rules/prefer-find.js +2 -1
- package/dist/rules/prefer-find.js.map +1 -1
- package/dist/rules/prefer-includes.js +1 -1
- package/dist/rules/prefer-includes.js.map +1 -1
- package/dist/rules/prefer-literal-enum-member.js +43 -2
- package/dist/rules/prefer-literal-enum-member.js.map +1 -1
- package/dist/rules/prefer-namespace-keyword.js +1 -1
- package/dist/rules/prefer-namespace-keyword.js.map +1 -1
- package/dist/rules/prefer-nullish-coalescing.js +8 -6
- package/dist/rules/prefer-nullish-coalescing.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/analyzeChain.js +32 -37
- package/dist/rules/prefer-optional-chain-utils/analyzeChain.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.js +1 -2
- package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/compareNodes.js +1 -2
- package/dist/rules/prefer-optional-chain-utils/compareNodes.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js +6 -11
- package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js.map +1 -1
- package/dist/rules/prefer-promise-reject-errors.js +1 -1
- package/dist/rules/prefer-promise-reject-errors.js.map +1 -1
- package/dist/rules/prefer-readonly.js +24 -12
- package/dist/rules/prefer-readonly.js.map +1 -1
- package/dist/rules/prefer-regexp-exec.js +15 -6
- package/dist/rules/prefer-regexp-exec.js.map +1 -1
- package/dist/rules/prefer-string-starts-ends-with.js.map +1 -1
- package/dist/rules/prefer-ts-expect-error.js +2 -1
- package/dist/rules/prefer-ts-expect-error.js.map +1 -1
- package/dist/rules/require-await.js +1 -1
- package/dist/rules/require-await.js.map +1 -1
- package/dist/rules/restrict-template-expressions.js +3 -3
- package/dist/rules/restrict-template-expressions.js.map +1 -1
- package/dist/rules/return-await.js +167 -86
- package/dist/rules/return-await.js.map +1 -1
- package/dist/rules/sort-type-constituents.js +23 -1
- package/dist/rules/sort-type-constituents.js.map +1 -1
- package/dist/rules/strict-boolean-expressions.js +112 -5
- package/dist/rules/strict-boolean-expressions.js.map +1 -1
- package/dist/rules/switch-exhaustiveness-check.js +7 -9
- package/dist/rules/switch-exhaustiveness-check.js.map +1 -1
- package/dist/rules/unbound-method.js +96 -27
- package/dist/rules/unbound-method.js.map +1 -1
- package/dist/rules/unified-signatures.js +3 -1
- package/dist/rules/unified-signatures.js.map +1 -1
- package/dist/util/astUtils.js +2 -3
- package/dist/util/astUtils.js.map +1 -1
- package/dist/util/collectUnusedVariables.js +110 -73
- package/dist/util/collectUnusedVariables.js.map +1 -1
- package/dist/util/createRule.js.map +1 -1
- package/dist/util/escapeRegExp.js +1 -2
- package/dist/util/escapeRegExp.js.map +1 -1
- package/dist/util/explicitReturnTypeUtils.js +11 -7
- package/dist/util/explicitReturnTypeUtils.js.map +1 -1
- package/dist/util/getESLintCoreRule.js +2 -2
- package/dist/util/getESLintCoreRule.js.map +1 -1
- package/dist/util/getForStatementHeadLoc.js +1 -2
- package/dist/util/getForStatementHeadLoc.js.map +1 -1
- package/dist/util/getFunctionHeadLoc.js +3 -4
- package/dist/util/getFunctionHeadLoc.js.map +1 -1
- package/dist/util/getMemberHeadLoc.js +80 -0
- package/dist/util/getMemberHeadLoc.js.map +1 -0
- package/dist/util/getOperatorPrecedence.js +5 -5
- package/dist/util/getOperatorPrecedence.js.map +1 -1
- package/dist/util/getStaticStringValue.js +1 -2
- package/dist/util/getStaticStringValue.js.map +1 -1
- package/dist/util/getStringLength.js +1 -2
- package/dist/util/getStringLength.js.map +1 -1
- package/dist/util/getTextWithParentheses.js +17 -0
- package/dist/util/getTextWithParentheses.js.map +1 -0
- package/dist/util/getThisExpression.js +1 -2
- package/dist/util/getThisExpression.js.map +1 -1
- package/dist/util/getWrappedCode.js +1 -2
- package/dist/util/getWrappedCode.js.map +1 -1
- package/dist/util/getWrappingFixer.js +2 -3
- package/dist/util/getWrappingFixer.js.map +1 -1
- package/dist/util/index.js +2 -0
- package/dist/util/index.js.map +1 -1
- package/dist/util/isAssignee.js +1 -2
- package/dist/util/isAssignee.js.map +1 -1
- package/dist/util/isNodeEqual.js +1 -2
- package/dist/util/isNodeEqual.js.map +1 -1
- package/dist/util/isNullLiteral.js +1 -2
- package/dist/util/isNullLiteral.js.map +1 -1
- package/dist/util/isTypeImport.js +22 -0
- package/dist/util/isTypeImport.js.map +1 -0
- package/dist/util/isUndefinedIdentifier.js +1 -2
- package/dist/util/isUndefinedIdentifier.js.map +1 -1
- package/dist/util/misc.js +15 -15
- package/dist/util/misc.js.map +1 -1
- package/dist/util/objectIterators.js +3 -4
- package/dist/util/objectIterators.js.map +1 -1
- package/dist/util/referenceContainsTypeQuery.js +20 -0
- package/dist/util/referenceContainsTypeQuery.js.map +1 -0
- package/dist/util/scopeUtils.js +11 -0
- package/dist/util/scopeUtils.js.map +1 -0
- package/docs/rules/array-type.mdx +4 -1
- package/docs/rules/ban-types.md +22 -0
- package/docs/rules/class-methods-use-this.mdx +1 -1
- package/docs/rules/consistent-indexed-object-style.mdx +1 -1
- package/docs/rules/consistent-type-imports.mdx +1 -1
- package/docs/rules/naming-convention.mdx +16 -0
- package/docs/rules/no-base-to-string.mdx +1 -1
- package/docs/rules/no-duplicate-imports.mdx +1 -1
- package/docs/rules/no-duplicate-type-constituents.mdx +6 -2
- package/docs/rules/no-dynamic-delete.mdx +12 -7
- package/docs/rules/no-empty-interface.mdx +10 -0
- package/docs/rules/no-empty-object-type.mdx +145 -0
- package/docs/rules/no-extraneous-class.mdx +6 -0
- package/docs/rules/no-floating-promises.mdx +148 -4
- package/docs/rules/no-import-type-side-effects.mdx +1 -1
- package/docs/rules/no-misused-promises.mdx +18 -20
- package/docs/rules/no-redundant-type-constituents.mdx +4 -0
- package/docs/rules/no-require-imports.mdx +28 -1
- package/docs/rules/no-restricted-types.mdx +71 -0
- package/docs/rules/no-type-alias.mdx +1 -1
- package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +12 -12
- package/docs/rules/no-unnecessary-parameter-property-assignment.mdx +42 -0
- package/docs/rules/no-unnecessary-template-expression.mdx +85 -0
- package/docs/rules/no-unnecessary-type-parameters.mdx +109 -0
- package/docs/rules/no-unsafe-function-type.mdx +63 -0
- package/docs/rules/no-unused-expressions.mdx +41 -1
- package/docs/rules/no-unused-vars.mdx +5 -0
- package/docs/rules/no-useless-template-literals.mdx +3 -59
- package/docs/rules/no-var-requires.mdx +6 -0
- package/docs/rules/no-wrapper-object-types.mdx +75 -0
- package/docs/rules/only-throw-error.mdx +7 -0
- package/docs/rules/prefer-readonly-parameter-types.mdx +10 -4
- package/docs/rules/prefer-ts-expect-error.mdx +10 -0
- package/docs/rules/require-await.mdx +2 -2
- package/docs/rules/restrict-template-expressions.mdx +1 -1
- package/docs/rules/return-await.mdx +119 -23
- package/docs/rules/sort-type-constituents.mdx +29 -9
- package/docs/rules/sort-type-union-intersection-members.mdx +12 -0
- package/docs/rules/strict-boolean-expressions.mdx +6 -0
- package/docs/rules/unbound-method.mdx +3 -2
- package/package.json +14 -20
- package/rules.d.ts +34 -3
- package/dist/rules/ban-types.js.map +0 -1
- package/dist/rules/no-throw-literal.js +0 -97
- package/dist/rules/no-throw-literal.js.map +0 -1
- package/dist/rules/no-useless-template-literals.js +0 -153
- package/dist/rules/no-useless-template-literals.js.map +0 -1
- package/docs/rules/ban-types.mdx +0 -138
- package/docs/rules/no-throw-literal.mdx +0 -25
@@ -1,5 +1,5 @@
|
|
1
1
|
---
|
2
|
-
description: 'Enforce consistent
|
2
|
+
description: 'Enforce consistent awaiting of returned promises.'
|
3
3
|
---
|
4
4
|
|
5
5
|
import Tabs from '@theme/Tabs';
|
@@ -9,30 +9,53 @@ import TabItem from '@theme/TabItem';
|
|
9
9
|
>
|
10
10
|
> See **https://typescript-eslint.io/rules/return-await** for documentation.
|
11
11
|
|
12
|
-
Returning an awaited promise can make sense for better stack trace information as well as for consistent error handling (returned promises will not be caught in an async function try/catch).
|
13
|
-
|
14
12
|
This rule builds on top of the [`eslint/no-return-await`](https://eslint.org/docs/rules/no-return-await) rule.
|
15
13
|
It expands upon the base rule to add support for optionally requiring `return await` in certain cases.
|
16
14
|
|
17
|
-
The extended rule is named `return-await` instead of `no-return-await` because the extended rule can enforce the positive or the negative. Additionally, while the core rule is now deprecated, the extended rule is still useful in many contexts
|
15
|
+
The extended rule is named `return-await` instead of `no-return-await` because the extended rule can enforce the positive or the negative. Additionally, while the core rule is now deprecated, the extended rule is still useful in many contexts:
|
16
|
+
|
17
|
+
- Returning an awaited promise [improves stack trace information](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#improving_stack_trace).
|
18
|
+
- When the `return` statement is in `try...catch`, awaiting the promise also allows the promise's rejection to be caught instead of leaving the error to the caller.
|
19
|
+
- Contrary to popular belief, `return await promise;` is [at least as fast as directly returning the promise](https://github.com/tc39/proposal-faster-promise-adoption).
|
18
20
|
|
19
21
|
## Options
|
20
22
|
|
21
23
|
```ts
|
22
|
-
type Options =
|
24
|
+
type Options =
|
25
|
+
| 'in-try-catch'
|
26
|
+
| 'always'
|
27
|
+
| 'error-handling-correctness-only'
|
28
|
+
| 'never';
|
23
29
|
|
24
30
|
const defaultOptions: Options = 'in-try-catch';
|
25
31
|
```
|
26
32
|
|
33
|
+
The options in this rule distinguish between "ordinary contexts" and "error-handling contexts".
|
34
|
+
An error-handling context is anywhere where returning an unawaited promise would cause unexpected control flow regarding exceptions/rejections.
|
35
|
+
See detailed examples in the sections for each option.
|
36
|
+
|
37
|
+
- If you return a promise within a `try` block, it should be awaited in order to trigger subsequent `catch` or `finally` blocks as expected.
|
38
|
+
- If you return a promise within a `catch` block, and there _is_ a `finally` block, it should be awaited in order to trigger the `finally` block as expected.
|
39
|
+
- If you return a promise between a `using` or `await using` declaration and the end of its scope, it should be awaited, since it behaves equivalently to code wrapped in a `try` block followed by a `finally`.
|
40
|
+
|
41
|
+
Ordinary contexts are anywhere else a promise may be returned.
|
42
|
+
The choice of whether to await a returned promise in an ordinary context is mostly stylistic.
|
43
|
+
|
44
|
+
With these terms defined, the options may be summarized as follows:
|
45
|
+
|
46
|
+
| Option | Ordinary Context <br/> (stylistic preference 🎨) | Error-Handling Context <br/> (catches bugs 🐛) | Should I use this option? |
|
47
|
+
| :-------------------------------: | :----------------------------------------------: | :----------------------------------------------------------: | :--------------------------------------------------------: |
|
48
|
+
| `always` | `return await promise;` | `return await promise;` | ✅ Yes! |
|
49
|
+
| `in-try-catch` | `return promise;` | `return await promise;` | ✅ Yes! |
|
50
|
+
| `error-handling-correctness-only` | don't care 🤷 | `return await promise;` | 🟡 Okay to use, but the above options would be preferable. |
|
51
|
+
| `never` | `return promise;` | `return promise;` <br/> (⚠️ This behavior may be harmful ⚠️) | ❌ No. This option is deprecated. |
|
52
|
+
|
27
53
|
### `in-try-catch`
|
28
54
|
|
29
|
-
|
30
|
-
|
55
|
+
In error-handling contexts, the rule enforces that returned promises must be awaited.
|
56
|
+
In ordinary contexts, the rule enforces that returned promises _must not_ be awaited.
|
31
57
|
|
32
|
-
|
33
|
-
- if you `return` a promise within a `catch`, and there **_is no_** `finally`, then it **_must not_** be `await`ed.
|
34
|
-
- if you `return` a promise within a `catch`, and there **_is a_** `finally`, then it **_must_** be `await`ed.
|
35
|
-
- if you `return` a promise within a `finally`, then it **_must not_** be `await`ed.
|
58
|
+
This is a good option if you prefer the shorter `return promise` form for stylistic reasons, wherever it's safe to use.
|
36
59
|
|
37
60
|
Examples of code with `in-try-catch`:
|
38
61
|
|
@@ -42,23 +65,34 @@ Examples of code with `in-try-catch`:
|
|
42
65
|
```ts option='"in-try-catch"'
|
43
66
|
async function invalidInTryCatch1() {
|
44
67
|
try {
|
45
|
-
return Promise.
|
46
|
-
} catch (e) {
|
68
|
+
return Promise.reject('try');
|
69
|
+
} catch (e) {
|
70
|
+
// Doesn't execute due to missing await.
|
71
|
+
}
|
47
72
|
}
|
48
73
|
|
49
74
|
async function invalidInTryCatch2() {
|
50
75
|
try {
|
51
76
|
throw new Error('error');
|
52
77
|
} catch (e) {
|
53
|
-
|
78
|
+
// Unnecessary await; rejections here don't impact control flow.
|
79
|
+
return await Promise.reject('catch');
|
54
80
|
}
|
55
81
|
}
|
56
82
|
|
83
|
+
// Prints 'starting async work', 'cleanup', 'async work done'.
|
57
84
|
async function invalidInTryCatch3() {
|
85
|
+
async function doAsyncWork(): Promise<void> {
|
86
|
+
console.log('starting async work');
|
87
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
88
|
+
console.log('async work done');
|
89
|
+
}
|
90
|
+
|
58
91
|
try {
|
59
92
|
throw new Error('error');
|
60
93
|
} catch (e) {
|
61
|
-
|
94
|
+
// Missing await.
|
95
|
+
return doAsyncWork();
|
62
96
|
} finally {
|
63
97
|
console.log('cleanup');
|
64
98
|
}
|
@@ -70,7 +104,8 @@ async function invalidInTryCatch4() {
|
|
70
104
|
} catch (e) {
|
71
105
|
throw new Error('error2');
|
72
106
|
} finally {
|
73
|
-
|
107
|
+
// Unnecessary await; rejections here don't impact control flow.
|
108
|
+
return await Promise.reject('finally');
|
74
109
|
}
|
75
110
|
}
|
76
111
|
|
@@ -81,6 +116,11 @@ async function invalidInTryCatch5() {
|
|
81
116
|
async function invalidInTryCatch6() {
|
82
117
|
return await 'value';
|
83
118
|
}
|
119
|
+
|
120
|
+
async function invalidInTryCatch7() {
|
121
|
+
using x = createDisposable();
|
122
|
+
return Promise.reject('using in scope');
|
123
|
+
}
|
84
124
|
```
|
85
125
|
|
86
126
|
</TabItem>
|
@@ -89,23 +129,32 @@ async function invalidInTryCatch6() {
|
|
89
129
|
```ts option='"in-try-catch"'
|
90
130
|
async function validInTryCatch1() {
|
91
131
|
try {
|
92
|
-
return await Promise.
|
93
|
-
} catch (e) {
|
132
|
+
return await Promise.reject('try');
|
133
|
+
} catch (e) {
|
134
|
+
// Executes as expected.
|
135
|
+
}
|
94
136
|
}
|
95
137
|
|
96
138
|
async function validInTryCatch2() {
|
97
139
|
try {
|
98
140
|
throw new Error('error');
|
99
141
|
} catch (e) {
|
100
|
-
return Promise.
|
142
|
+
return Promise.reject('catch');
|
101
143
|
}
|
102
144
|
}
|
103
145
|
|
146
|
+
// Prints 'starting async work', 'async work done', 'cleanup'.
|
104
147
|
async function validInTryCatch3() {
|
148
|
+
async function doAsyncWork(): Promise<void> {
|
149
|
+
console.log('starting async work');
|
150
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
151
|
+
console.log('async work done');
|
152
|
+
}
|
153
|
+
|
105
154
|
try {
|
106
155
|
throw new Error('error');
|
107
156
|
} catch (e) {
|
108
|
-
return await
|
157
|
+
return await doAsyncWork();
|
109
158
|
} finally {
|
110
159
|
console.log('cleanup');
|
111
160
|
}
|
@@ -117,7 +166,7 @@ async function validInTryCatch4() {
|
|
117
166
|
} catch (e) {
|
118
167
|
throw new Error('error2');
|
119
168
|
} finally {
|
120
|
-
return Promise.
|
169
|
+
return Promise.reject('finally');
|
121
170
|
}
|
122
171
|
}
|
123
172
|
|
@@ -128,6 +177,11 @@ async function validInTryCatch5() {
|
|
128
177
|
async function validInTryCatch6() {
|
129
178
|
return 'value';
|
130
179
|
}
|
180
|
+
|
181
|
+
async function validInTryCatch7() {
|
182
|
+
using x = createDisposable();
|
183
|
+
return await Promise.reject('using in scope');
|
184
|
+
}
|
131
185
|
```
|
132
186
|
|
133
187
|
</TabItem>
|
@@ -135,7 +189,9 @@ async function validInTryCatch6() {
|
|
135
189
|
|
136
190
|
### `always`
|
137
191
|
|
138
|
-
Requires that all returned promises
|
192
|
+
Requires that all returned promises be awaited.
|
193
|
+
|
194
|
+
This is a good option if you like the consistency of simply always awaiting promises, or prefer not having to consider the distinction between error-handling contexts and ordinary contexts.
|
139
195
|
|
140
196
|
Examples of code with `always`:
|
141
197
|
|
@@ -180,9 +236,49 @@ async function validAlways3() {
|
|
180
236
|
</TabItem>
|
181
237
|
</Tabs>
|
182
238
|
|
239
|
+
### `error-handling-correctness-only`
|
240
|
+
|
241
|
+
In error-handling contexts, the rule enforces that returned promises must be awaited.
|
242
|
+
In ordinary contexts, the rule does not enforce any particular behavior around whether returned promises are awaited.
|
243
|
+
|
244
|
+
This is a good option if you only want to benefit from rule's ability to catch control flow bugs in error-handling contexts, but don't want to enforce a particular style otherwise.
|
245
|
+
|
246
|
+
:::info
|
247
|
+
We recommend you configure either `in-try-catch` or `always` instead of this option.
|
248
|
+
While the choice of whether to await promises outside of error-handling contexts is mostly stylistic, it's generally best to be consistent.
|
249
|
+
:::
|
250
|
+
|
251
|
+
Examples of additional correct code with `error-handling-correctness-only`:
|
252
|
+
|
253
|
+
<Tabs>
|
254
|
+
<TabItem value="✅ Correct">
|
255
|
+
|
256
|
+
```ts option='"error-handling-correctness-only"'
|
257
|
+
async function asyncFunction(): Promise<void> {
|
258
|
+
if (Math.random() < 0.5) {
|
259
|
+
return await Promise.resolve();
|
260
|
+
} else {
|
261
|
+
return Promise.resolve();
|
262
|
+
}
|
263
|
+
}
|
264
|
+
```
|
265
|
+
|
266
|
+
</TabItem>
|
267
|
+
</Tabs>
|
268
|
+
|
183
269
|
### `never`
|
184
270
|
|
185
|
-
Disallows
|
271
|
+
Disallows awaiting any returned promises.
|
272
|
+
|
273
|
+
:::warning
|
274
|
+
|
275
|
+
This option is deprecated and will be removed in a future major version of typescript-eslint.
|
276
|
+
|
277
|
+
The `never` option introduces undesirable behavior in error-handling contexts.
|
278
|
+
If you prefer to minimize returning awaited promises, consider instead using `in-try-catch` instead, which also generally bans returning awaited promises, but only where it is _safe_ not to await a promise.
|
279
|
+
|
280
|
+
See more details at [typescript-eslint#9433](https://github.com/typescript-eslint/typescript-eslint/issues/9433).
|
281
|
+
:::
|
186
282
|
|
187
283
|
Examples of code with `never`:
|
188
284
|
|
@@ -9,6 +9,12 @@ import TabItem from '@theme/TabItem';
|
|
9
9
|
>
|
10
10
|
> See **https://typescript-eslint.io/rules/sort-type-constituents** for documentation.
|
11
11
|
|
12
|
+
:::danger Deprecated
|
13
|
+
This rule has been deprecated in favor of the [`perfectionist/sort-intersection-types`](https://perfectionist.dev/rules/sort-intersection-types) and [`perfectionist/sort-union-types`](https://perfectionist.dev/rules/sort-union-types) rules.
|
14
|
+
|
15
|
+
See [Docs: Deprecate sort-type-constituents in favor of eslint-plugin-perfectionist](https://github.com/typescript-eslint/typescript-eslint/issues/8915) and [eslint-plugin: Feature freeze naming and sorting stylistic rules](https://github.com/typescript-eslint/typescript-eslint/issues/8792) for more information.
|
16
|
+
:::
|
17
|
+
|
12
18
|
Sorting union (`|`) and intersection (`&`) types can help:
|
13
19
|
|
14
20
|
- keep your codebase standardized
|
@@ -19,15 +25,6 @@ This rule reports on any types that aren't sorted alphabetically.
|
|
19
25
|
|
20
26
|
> Types are sorted case-insensitively and treating numbers like a human would, falling back to character code sorting in case of ties.
|
21
27
|
|
22
|
-
:::note
|
23
|
-
This rule is _feature frozen_: it will no longer receive new features such as new options.
|
24
|
-
It still will accept bug and documentation fixes for its existing area of features.
|
25
|
-
|
26
|
-
Stylistic rules that enforce naming and/or sorting conventions tend to grow incomprehensibly complex as increasingly obscure features are requested.
|
27
|
-
This rule has reached the limit of what is reasonable for the typescript-eslint project to maintain.
|
28
|
-
See [eslint-plugin: Feature freeze naming and sorting stylistic rules](https://github.com/typescript-eslint/typescript-eslint/issues/8792) for more information.
|
29
|
-
:::
|
30
|
-
|
31
28
|
## Examples
|
32
29
|
|
33
30
|
<Tabs>
|
@@ -97,6 +94,29 @@ type T4 =
|
|
97
94
|
|
98
95
|
## Options
|
99
96
|
|
97
|
+
### `caseSensitive`
|
98
|
+
|
99
|
+
Whether to sort using case sensitive string comparisons.
|
100
|
+
|
101
|
+
Examples of code with `{ "caseSensitive": true }`:
|
102
|
+
|
103
|
+
<Tabs>
|
104
|
+
<TabItem value="❌ Incorrect">
|
105
|
+
|
106
|
+
```ts option='{ "caseSensitive": true }'
|
107
|
+
type T = 'DeletedAt' | 'DeleteForever';
|
108
|
+
```
|
109
|
+
|
110
|
+
</TabItem>
|
111
|
+
<TabItem value="✅ Correct">
|
112
|
+
|
113
|
+
```ts option='{ "caseSensitive": true }'
|
114
|
+
type T = 'DeleteForever' | 'DeletedAt';
|
115
|
+
```
|
116
|
+
|
117
|
+
</TabItem>
|
118
|
+
</Tabs>
|
119
|
+
|
100
120
|
### `checkIntersections`
|
101
121
|
|
102
122
|
Whether to check intersection types (`&`).
|
@@ -0,0 +1,12 @@
|
|
1
|
+
:::danger Deprecated
|
2
|
+
|
3
|
+
This rule has been renamed to [`sort-type-constituents`](https://typescript-eslint.io/rules/sort-type-constituents).
|
4
|
+
|
5
|
+
:::
|
6
|
+
|
7
|
+
<!--
|
8
|
+
This doc file has been left on purpose to help direct people to the replacement rule.
|
9
|
+
|
10
|
+
Note that there is no actual way to get to this page in the normal navigation,
|
11
|
+
so end-users will only be able to get to this page from the search bar.
|
12
|
+
-->
|
@@ -21,6 +21,7 @@ The following nodes are considered boolean expressions and their type is checked
|
|
21
21
|
- Operands of logical binary operators (`lhs || rhs` and `lhs && rhs`).
|
22
22
|
- Right-hand side operand is ignored when it's not a descendant of another boolean expression.
|
23
23
|
This is to allow usage of boolean operators for their short-circuiting behavior.
|
24
|
+
- Asserted argument of an assertion function (`assert(arg)`).
|
24
25
|
|
25
26
|
## Examples
|
26
27
|
|
@@ -55,6 +56,11 @@ let obj = {};
|
|
55
56
|
while (obj) {
|
56
57
|
obj = getObj();
|
57
58
|
}
|
59
|
+
|
60
|
+
// assertion functions without an `is` are boolean contexts.
|
61
|
+
declare function assert(value: unknown): asserts value;
|
62
|
+
let maybeString = Math.random() > 0.5 ? '' : undefined;
|
63
|
+
assert(maybeString);
|
58
64
|
```
|
59
65
|
|
60
66
|
</TabItem>
|
@@ -16,7 +16,7 @@ Otherwise, passing class methods around as values can remove type safety by fail
|
|
16
16
|
This rule reports when a class method is referenced in an unbound manner.
|
17
17
|
|
18
18
|
:::note Tip
|
19
|
-
If you're working with `jest`, you can use [`eslint-plugin-jest`'s version of this rule](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/unbound-method.
|
19
|
+
If you're working with `jest`, you can use [`eslint-plugin-jest`'s version of this rule](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/unbound-method.md) to lint your test files, which knows when it's ok to pass an unbound method to `expect` calls.
|
20
20
|
:::
|
21
21
|
|
22
22
|
## Examples
|
@@ -105,7 +105,8 @@ log();
|
|
105
105
|
## When Not To Use It
|
106
106
|
|
107
107
|
If your project dynamically changes `this` scopes around in a way TypeScript has difficulties modeling, this rule may not be viable to use.
|
108
|
-
|
108
|
+
For example, some functions have an additional parameter for specifying the `this` context, such as `Reflect.apply`, and array methods like `Array.prototype.map`.
|
109
|
+
This semantic is not easily expressed by TypeScript.
|
109
110
|
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
|
110
111
|
|
111
112
|
If you're wanting to use `toBeCalled` and similar matches in `jest` tests, you can disable this rule for your test files in favor of [`eslint-plugin-jest`'s version of this rule](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/unbound-method.mdx).
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
3
|
-
"version": "8.0.0-alpha.
|
3
|
+
"version": "8.0.0-alpha.61",
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
5
5
|
"files": [
|
6
6
|
"dist",
|
@@ -48,44 +48,38 @@
|
|
48
48
|
],
|
49
49
|
"scripts": {
|
50
50
|
"build": "tsc -b tsconfig.build.json",
|
51
|
-
"check-docs": "jest tests/docs.test.ts --runTestsByPath --silent --runInBand",
|
52
|
-
"check-configs": "jest tests/configs.test.ts --runTestsByPath --silent --runInBand",
|
53
51
|
"clean": "tsc -b tsconfig.build.json --clean",
|
54
52
|
"postclean": "rimraf dist && rimraf coverage",
|
55
53
|
"format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
|
56
|
-
"generate:breaking-changes": "
|
57
|
-
"generate:configs": "npx nx
|
54
|
+
"generate:breaking-changes": "tsx tools/generate-breaking-changes.mts",
|
55
|
+
"generate:configs": "npx nx generate-configs repo",
|
58
56
|
"lint": "npx nx lint",
|
59
57
|
"test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --coverage --logHeapUsage",
|
60
58
|
"test-single": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --no-coverage",
|
61
|
-
"typecheck": "tsc
|
59
|
+
"typecheck": "tsc --noEmit"
|
62
60
|
},
|
63
61
|
"dependencies": {
|
64
62
|
"@eslint-community/regexpp": "^4.10.0",
|
65
|
-
"@typescript-eslint/scope-manager": "8.0.0-alpha.
|
66
|
-
"@typescript-eslint/type-utils": "8.0.0-alpha.
|
67
|
-
"@typescript-eslint/utils": "8.0.0-alpha.
|
68
|
-
"@typescript-eslint/visitor-keys": "8.0.0-alpha.
|
69
|
-
"debug": "^4.3.4",
|
63
|
+
"@typescript-eslint/scope-manager": "8.0.0-alpha.61",
|
64
|
+
"@typescript-eslint/type-utils": "8.0.0-alpha.61",
|
65
|
+
"@typescript-eslint/utils": "8.0.0-alpha.61",
|
66
|
+
"@typescript-eslint/visitor-keys": "8.0.0-alpha.61",
|
70
67
|
"graphemer": "^1.4.0",
|
71
68
|
"ignore": "^5.3.1",
|
72
69
|
"natural-compare": "^1.4.0",
|
73
|
-
"semver": "^7.6.0",
|
74
70
|
"ts-api-utils": "^1.3.0"
|
75
71
|
},
|
76
72
|
"devDependencies": {
|
77
|
-
"@types
|
78
|
-
"@types/marked": "
|
73
|
+
"@jest/types": "29.6.3",
|
74
|
+
"@types/marked": "^5.0.2",
|
79
75
|
"@types/mdast": "^4.0.3",
|
80
76
|
"@types/natural-compare": "*",
|
81
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "8.0.0-alpha.
|
82
|
-
"@typescript-eslint/rule-tester": "8.0.0-alpha.
|
77
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.0.0-alpha.61",
|
78
|
+
"@typescript-eslint/rule-tester": "8.0.0-alpha.61",
|
83
79
|
"ajv": "^6.12.6",
|
84
|
-
"chalk": "^5.3.0",
|
85
80
|
"cross-env": "^7.0.3",
|
86
81
|
"cross-fetch": "*",
|
87
82
|
"eslint": "*",
|
88
|
-
"grapheme-splitter": "^1.0.4",
|
89
83
|
"jest": "29.7.0",
|
90
84
|
"jest-specific-snapshot": "^8.0.0",
|
91
85
|
"json-schema": "*",
|
@@ -102,8 +96,8 @@
|
|
102
96
|
"unist-util-visit": "^5.0.0"
|
103
97
|
},
|
104
98
|
"peerDependencies": {
|
105
|
-
"@typescript-eslint/parser": "^
|
106
|
-
"eslint": "^8.57.0"
|
99
|
+
"@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0",
|
100
|
+
"eslint": "^8.57.0 || ^9.0.0"
|
107
101
|
},
|
108
102
|
"peerDependenciesMeta": {
|
109
103
|
"typescript": {
|
package/rules.d.ts
CHANGED
@@ -35,12 +35,43 @@ This is likely not portable. A type annotation is necessary. ts(2742)
|
|
35
35
|
```
|
36
36
|
*/
|
37
37
|
|
38
|
-
import type {
|
38
|
+
import type {
|
39
|
+
RuleModuleWithMetaDocs,
|
40
|
+
RuleRecommendation,
|
41
|
+
RuleRecommendationAcrossConfigs,
|
42
|
+
} from '@typescript-eslint/utils/ts-eslint';
|
43
|
+
|
44
|
+
export interface ESLintPluginDocs {
|
45
|
+
/**
|
46
|
+
* Does the rule extend (or is it based off of) an ESLint code rule?
|
47
|
+
* Alternately accepts the name of the base rule, in case the rule has been renamed.
|
48
|
+
* This is only used for documentation purposes.
|
49
|
+
*/
|
50
|
+
extendsBaseRule?: boolean | string;
|
51
|
+
|
52
|
+
/**
|
53
|
+
* If a string config name, which starting config this rule is enabled in.
|
54
|
+
* If an object, which settings it has enabled in each of those configs.
|
55
|
+
*/
|
56
|
+
recommended?: RuleRecommendation | RuleRecommendationAcrossConfigs<unknown[]>;
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Does the rule require us to create a full TypeScript Program in order for it
|
60
|
+
* to type-check code. This is only used for documentation purposes.
|
61
|
+
*/
|
62
|
+
requiresTypeChecking?: boolean;
|
63
|
+
}
|
64
|
+
|
65
|
+
export type ESLintPluginRuleModule = RuleModuleWithMetaDocs<
|
66
|
+
string,
|
67
|
+
readonly unknown[],
|
68
|
+
ESLintPluginDocs
|
69
|
+
>;
|
39
70
|
|
40
71
|
export type TypeScriptESLintRules = Record<
|
41
72
|
string,
|
42
|
-
|
73
|
+
RuleModuleWithMetaDocs<string, unknown[], ESLintPluginDocs>
|
43
74
|
>;
|
75
|
+
|
44
76
|
declare const rules: TypeScriptESLintRules;
|
45
|
-
// eslint-disable-next-line import/no-default-export
|
46
77
|
export default rules;
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ban-types.js","sourceRoot":"","sources":["../../src/rules/ban-types.ts"],"names":[],"mappings":";;;AACA,oDAA0D;AAE1D,kCAAsD;AAsBtD,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,aAAa,CACpB,IAAmB,EACnB,UAA+B;IAE/B,OAAO,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,gBAAgB,CACvB,UAAyE;IAEzE,IAAI,UAAU,IAAI,IAAI,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QAC9C,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,OAAO,IAAI,UAAU,EAAE,CAAC;IAC1B,CAAC;IAED,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,OAAO,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;IAClC,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,YAAY,GAAU;IAC1B,MAAM,EAAE;QACN,OAAO,EAAE,oBAAoB;QAC7B,OAAO,EAAE,QAAQ;KAClB;IACD,OAAO,EAAE;QACP,OAAO,EAAE,qBAAqB;QAC9B,OAAO,EAAE,SAAS;KACnB;IACD,MAAM,EAAE;QACN,OAAO,EAAE,oBAAoB;QAC7B,OAAO,EAAE,QAAQ;KAClB;IACD,MAAM,EAAE;QACN,OAAO,EAAE,oBAAoB;QAC7B,OAAO,EAAE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gB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAEhC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;oBACvB,gBAAgB,CAAC,IAAI,CAAC,CAAC;gBACzB,CAAC;YACH,CAAC;YACD,mBAAmB,CAAC,IAAI;gBACtB,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;YACD,iBAAiB,CAAC,IAAI;gBACpB,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
@@ -1,97 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
24
|
-
};
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
const utils_1 = require("@typescript-eslint/utils");
|
27
|
-
const ts = __importStar(require("typescript"));
|
28
|
-
const util_1 = require("../util");
|
29
|
-
exports.default = (0, util_1.createRule)({
|
30
|
-
name: 'no-throw-literal',
|
31
|
-
meta: {
|
32
|
-
type: 'problem',
|
33
|
-
deprecated: true,
|
34
|
-
replacedBy: ['@typescript-eslint/only-throw-error'],
|
35
|
-
docs: {
|
36
|
-
description: 'Disallow throwing literals as exceptions',
|
37
|
-
extendsBaseRule: true,
|
38
|
-
requiresTypeChecking: true,
|
39
|
-
},
|
40
|
-
schema: [
|
41
|
-
{
|
42
|
-
type: 'object',
|
43
|
-
properties: {
|
44
|
-
allowThrowingAny: {
|
45
|
-
type: 'boolean',
|
46
|
-
},
|
47
|
-
allowThrowingUnknown: {
|
48
|
-
type: 'boolean',
|
49
|
-
},
|
50
|
-
},
|
51
|
-
additionalProperties: false,
|
52
|
-
},
|
53
|
-
],
|
54
|
-
messages: {
|
55
|
-
object: 'Expected an error object to be thrown.',
|
56
|
-
undef: 'Do not throw undefined.',
|
57
|
-
},
|
58
|
-
},
|
59
|
-
defaultOptions: [
|
60
|
-
{
|
61
|
-
allowThrowingAny: true,
|
62
|
-
allowThrowingUnknown: true,
|
63
|
-
},
|
64
|
-
],
|
65
|
-
create(context, [options]) {
|
66
|
-
const services = (0, util_1.getParserServices)(context);
|
67
|
-
function checkThrowArgument(node) {
|
68
|
-
if (node.type === utils_1.AST_NODE_TYPES.AwaitExpression ||
|
69
|
-
node.type === utils_1.AST_NODE_TYPES.YieldExpression) {
|
70
|
-
return;
|
71
|
-
}
|
72
|
-
const type = services.getTypeAtLocation(node);
|
73
|
-
if (type.flags & ts.TypeFlags.Undefined) {
|
74
|
-
context.report({ node, messageId: 'undef' });
|
75
|
-
return;
|
76
|
-
}
|
77
|
-
if (options.allowThrowingAny && (0, util_1.isTypeAnyType)(type)) {
|
78
|
-
return;
|
79
|
-
}
|
80
|
-
if (options.allowThrowingUnknown && (0, util_1.isTypeUnknownType)(type)) {
|
81
|
-
return;
|
82
|
-
}
|
83
|
-
if ((0, util_1.isErrorLike)(services.program, type)) {
|
84
|
-
return;
|
85
|
-
}
|
86
|
-
context.report({ node, messageId: 'object' });
|
87
|
-
}
|
88
|
-
return {
|
89
|
-
ThrowStatement(node) {
|
90
|
-
if (node.argument) {
|
91
|
-
checkThrowArgument(node.argument);
|
92
|
-
}
|
93
|
-
},
|
94
|
-
};
|
95
|
-
},
|
96
|
-
});
|
97
|
-
//# sourceMappingURL=no-throw-literal.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"no-throw-literal.js","sourceRoot":"","sources":["../../src/rules/no-throw-literal.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAA0D;AAC1D,+CAAiC;AAEjC,kCAMiB;AAWjB,kBAAe,IAAA,iBAAU,EAAsB;IAC7C,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,UAAU,EAAE,IAAI;QAChB,UAAU,EAAE,CAAC,qCAAqC,CAAC;QACnD,IAAI,EAAE;YACJ,WAAW,EAAE,0CAA0C;YACvD,eAAe,EAAE,IAAI;YACrB,oBAAoB,EAAE,IAAI;SAC3B;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,gBAAgB,EAAE;wBAChB,IAAI,EAAE,SAAS;qBAChB;oBACD,oBAAoB,EAAE;wBACpB,IAAI,EAAE,SAAS;qBAChB;iBACF;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,QAAQ,EAAE;YACR,MAAM,EAAE,wCAAwC;YAChD,KAAK,EAAE,yBAAyB;SACjC;KACF;IACD,cAAc,EAAE;QACd;YACE,gBAAgB,EAAE,IAAI;YACtB,oBAAoB,EAAE,IAAI;SAC3B;KACF;IACD,MAAM,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC;QACvB,MAAM,QAAQ,GAAG,IAAA,wBAAiB,EAAC,OAAO,CAAC,CAAC;QAE5C,SAAS,kB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