@typescript-eslint/eslint-plugin 8.33.1-alpha.5 → 8.33.1

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.
Files changed (161) hide show
  1. package/package.json +9 -10
  2. package/docs/rules/README.md +0 -57
  3. package/docs/rules/TEMPLATE.md +0 -36
  4. package/docs/rules/adjacent-overload-signatures.mdx +0 -105
  5. package/docs/rules/array-type.mdx +0 -126
  6. package/docs/rules/await-thenable.mdx +0 -184
  7. package/docs/rules/ban-ts-comment.mdx +0 -165
  8. package/docs/rules/ban-tslint-comment.mdx +0 -45
  9. package/docs/rules/ban-types.md +0 -26
  10. package/docs/rules/block-spacing.md +0 -15
  11. package/docs/rules/brace-style.md +0 -15
  12. package/docs/rules/camelcase.md +0 -15
  13. package/docs/rules/class-literal-property-style.mdx +0 -112
  14. package/docs/rules/class-methods-use-this.mdx +0 -135
  15. package/docs/rules/comma-dangle.md +0 -15
  16. package/docs/rules/comma-spacing.md +0 -15
  17. package/docs/rules/consistent-generic-constructors.mdx +0 -87
  18. package/docs/rules/consistent-indexed-object-style.mdx +0 -105
  19. package/docs/rules/consistent-return.mdx +0 -51
  20. package/docs/rules/consistent-type-assertions.mdx +0 -196
  21. package/docs/rules/consistent-type-definitions.mdx +0 -133
  22. package/docs/rules/consistent-type-exports.mdx +0 -97
  23. package/docs/rules/consistent-type-imports.mdx +0 -139
  24. package/docs/rules/default-param-last.mdx +0 -59
  25. package/docs/rules/dot-notation.mdx +0 -94
  26. package/docs/rules/explicit-function-return-type.mdx +0 -359
  27. package/docs/rules/explicit-member-accessibility.mdx +0 -353
  28. package/docs/rules/explicit-module-boundary-types.mdx +0 -287
  29. package/docs/rules/func-call-spacing.md +0 -15
  30. package/docs/rules/indent.md +0 -15
  31. package/docs/rules/init-declarations.mdx +0 -12
  32. package/docs/rules/key-spacing.md +0 -15
  33. package/docs/rules/keyword-spacing.md +0 -15
  34. package/docs/rules/lines-around-comment.md +0 -15
  35. package/docs/rules/lines-between-class-members.md +0 -15
  36. package/docs/rules/max-params.mdx +0 -54
  37. package/docs/rules/member-delimiter-style.md +0 -15
  38. package/docs/rules/member-ordering.mdx +0 -1483
  39. package/docs/rules/method-signature-style.mdx +0 -124
  40. package/docs/rules/naming-convention.mdx +0 -755
  41. package/docs/rules/no-array-constructor.mdx +0 -34
  42. package/docs/rules/no-array-delete.mdx +0 -44
  43. package/docs/rules/no-base-to-string.mdx +0 -115
  44. package/docs/rules/no-confusing-non-null-assertion.mdx +0 -75
  45. package/docs/rules/no-confusing-void-expression.mdx +0 -148
  46. package/docs/rules/no-deprecated.mdx +0 -119
  47. package/docs/rules/no-dupe-class-members.mdx +0 -16
  48. package/docs/rules/no-duplicate-enum-values.mdx +0 -66
  49. package/docs/rules/no-duplicate-imports.mdx +0 -17
  50. package/docs/rules/no-duplicate-type-constituents.mdx +0 -89
  51. package/docs/rules/no-dynamic-delete.mdx +0 -64
  52. package/docs/rules/no-empty-function.mdx +0 -94
  53. package/docs/rules/no-empty-interface.mdx +0 -75
  54. package/docs/rules/no-empty-object-type.mdx +0 -150
  55. package/docs/rules/no-explicit-any.mdx +0 -177
  56. package/docs/rules/no-extra-non-null-assertion.mdx +0 -60
  57. package/docs/rules/no-extra-parens.md +0 -15
  58. package/docs/rules/no-extra-semi.md +0 -15
  59. package/docs/rules/no-extraneous-class.mdx +0 -329
  60. package/docs/rules/no-floating-promises.mdx +0 -282
  61. package/docs/rules/no-for-in-array.mdx +0 -67
  62. package/docs/rules/no-implied-eval.mdx +0 -106
  63. package/docs/rules/no-import-type-side-effects.mdx +0 -80
  64. package/docs/rules/no-inferrable-types.mdx +0 -113
  65. package/docs/rules/no-invalid-this.mdx +0 -16
  66. package/docs/rules/no-invalid-void-type.mdx +0 -119
  67. package/docs/rules/no-loop-func.mdx +0 -12
  68. package/docs/rules/no-loss-of-precision.mdx +0 -17
  69. package/docs/rules/no-magic-numbers.mdx +0 -131
  70. package/docs/rules/no-meaningless-void-operator.mdx +0 -61
  71. package/docs/rules/no-misused-new.mdx +0 -53
  72. package/docs/rules/no-misused-promises.mdx +0 -314
  73. package/docs/rules/no-misused-spread.mdx +0 -132
  74. package/docs/rules/no-mixed-enums.mdx +0 -96
  75. package/docs/rules/no-namespace.mdx +0 -157
  76. package/docs/rules/no-non-null-asserted-nullish-coalescing.mdx +0 -60
  77. package/docs/rules/no-non-null-asserted-optional-chain.mdx +0 -46
  78. package/docs/rules/no-non-null-assertion.mdx +0 -48
  79. package/docs/rules/no-parameter-properties.mdx +0 -16
  80. package/docs/rules/no-redeclare.mdx +0 -79
  81. package/docs/rules/no-redundant-type-constituents.mdx +0 -102
  82. package/docs/rules/no-require-imports.mdx +0 -114
  83. package/docs/rules/no-restricted-imports.mdx +0 -84
  84. package/docs/rules/no-restricted-types.mdx +0 -70
  85. package/docs/rules/no-shadow.mdx +0 -143
  86. package/docs/rules/no-this-alias.mdx +0 -124
  87. package/docs/rules/no-type-alias.mdx +0 -626
  88. package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +0 -165
  89. package/docs/rules/no-unnecessary-condition.mdx +0 -293
  90. package/docs/rules/no-unnecessary-parameter-property-assignment.mdx +0 -42
  91. package/docs/rules/no-unnecessary-qualifier.mdx +0 -57
  92. package/docs/rules/no-unnecessary-template-expression.mdx +0 -108
  93. package/docs/rules/no-unnecessary-type-arguments.mdx +0 -85
  94. package/docs/rules/no-unnecessary-type-assertion.mdx +0 -97
  95. package/docs/rules/no-unnecessary-type-constraint.mdx +0 -61
  96. package/docs/rules/no-unnecessary-type-conversion.mdx +0 -79
  97. package/docs/rules/no-unnecessary-type-parameters.mdx +0 -255
  98. package/docs/rules/no-unsafe-argument.mdx +0 -98
  99. package/docs/rules/no-unsafe-assignment.mdx +0 -101
  100. package/docs/rules/no-unsafe-call.mdx +0 -120
  101. package/docs/rules/no-unsafe-declaration-merging.mdx +0 -65
  102. package/docs/rules/no-unsafe-enum-comparison.mdx +0 -98
  103. package/docs/rules/no-unsafe-function-type.mdx +0 -65
  104. package/docs/rules/no-unsafe-member-access.mdx +0 -81
  105. package/docs/rules/no-unsafe-return.mdx +0 -126
  106. package/docs/rules/no-unsafe-type-assertion.mdx +0 -63
  107. package/docs/rules/no-unsafe-unary-minus.mdx +0 -60
  108. package/docs/rules/no-unused-expressions.mdx +0 -52
  109. package/docs/rules/no-unused-vars.mdx +0 -136
  110. package/docs/rules/no-use-before-define.mdx +0 -98
  111. package/docs/rules/no-useless-constructor.mdx +0 -21
  112. package/docs/rules/no-useless-empty-export.mdx +0 -53
  113. package/docs/rules/no-useless-template-literals.mdx +0 -9
  114. package/docs/rules/no-var-requires.mdx +0 -77
  115. package/docs/rules/no-wrapper-object-types.mdx +0 -75
  116. package/docs/rules/non-nullable-type-assertion-style.mdx +0 -47
  117. package/docs/rules/object-curly-spacing.md +0 -15
  118. package/docs/rules/only-throw-error.mdx +0 -150
  119. package/docs/rules/padding-line-between-statements.md +0 -15
  120. package/docs/rules/parameter-properties.mdx +0 -522
  121. package/docs/rules/prefer-as-const.mdx +0 -51
  122. package/docs/rules/prefer-destructuring.mdx +0 -101
  123. package/docs/rules/prefer-enum-initializers.mdx +0 -68
  124. package/docs/rules/prefer-find.mdx +0 -45
  125. package/docs/rules/prefer-for-of.mdx +0 -50
  126. package/docs/rules/prefer-function-type.mdx +0 -98
  127. package/docs/rules/prefer-includes.mdx +0 -81
  128. package/docs/rules/prefer-literal-enum-member.mdx +0 -111
  129. package/docs/rules/prefer-namespace-keyword.mdx +0 -51
  130. package/docs/rules/prefer-nullish-coalescing.mdx +0 -349
  131. package/docs/rules/prefer-optional-chain.mdx +0 -304
  132. package/docs/rules/prefer-promise-reject-errors.mdx +0 -78
  133. package/docs/rules/prefer-readonly-parameter-types.mdx +0 -408
  134. package/docs/rules/prefer-readonly.mdx +0 -111
  135. package/docs/rules/prefer-reduce-type-parameter.mdx +0 -66
  136. package/docs/rules/prefer-regexp-exec.mdx +0 -52
  137. package/docs/rules/prefer-return-this-type.mdx +0 -93
  138. package/docs/rules/prefer-string-starts-ends-with.mdx +0 -84
  139. package/docs/rules/prefer-ts-expect-error.mdx +0 -86
  140. package/docs/rules/promise-function-async.mdx +0 -143
  141. package/docs/rules/quotes.md +0 -15
  142. package/docs/rules/related-getter-setter-pairs.mdx +0 -61
  143. package/docs/rules/require-array-sort-compare.mdx +0 -89
  144. package/docs/rules/require-await.mdx +0 -53
  145. package/docs/rules/restrict-plus-operands.mdx +0 -245
  146. package/docs/rules/restrict-template-expressions.mdx +0 -167
  147. package/docs/rules/return-await.mdx +0 -339
  148. package/docs/rules/semi.md +0 -15
  149. package/docs/rules/sort-type-constituents.mdx +0 -209
  150. package/docs/rules/sort-type-union-intersection-members.mdx +0 -16
  151. package/docs/rules/space-before-blocks.md +0 -15
  152. package/docs/rules/space-before-function-paren.md +0 -15
  153. package/docs/rules/space-infix-ops.md +0 -15
  154. package/docs/rules/strict-boolean-expressions.mdx +0 -184
  155. package/docs/rules/switch-exhaustiveness-check.mdx +0 -280
  156. package/docs/rules/triple-slash-reference.mdx +0 -129
  157. package/docs/rules/type-annotation-spacing.md +0 -15
  158. package/docs/rules/typedef.mdx +0 -350
  159. package/docs/rules/unbound-method.mdx +0 -114
  160. package/docs/rules/unified-signatures.mdx +0 -132
  161. package/docs/rules/use-unknown-in-catch-callback-variable.mdx +0 -97
package/package.json CHANGED
@@ -1,16 +1,15 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.33.1-alpha.5",
3
+ "version": "8.33.1",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
7
7
  "!*.tsbuildinfo",
8
- "docs",
9
8
  "index.d.ts",
10
9
  "raw-plugin.d.ts",
11
10
  "rules.d.ts",
12
11
  "package.json",
13
- "README.md",
12
+ "./README.md",
14
13
  "LICENSE"
15
14
  ],
16
15
  "type": "commonjs",
@@ -61,10 +60,10 @@
61
60
  },
62
61
  "dependencies": {
63
62
  "@eslint-community/regexpp": "^4.10.0",
64
- "@typescript-eslint/scope-manager": "8.33.1-alpha.5",
65
- "@typescript-eslint/type-utils": "8.33.1-alpha.5",
66
- "@typescript-eslint/utils": "8.33.1-alpha.5",
67
- "@typescript-eslint/visitor-keys": "8.33.1-alpha.5",
63
+ "@typescript-eslint/scope-manager": "8.33.1",
64
+ "@typescript-eslint/type-utils": "8.33.1",
65
+ "@typescript-eslint/utils": "8.33.1",
66
+ "@typescript-eslint/visitor-keys": "8.33.1",
68
67
  "graphemer": "^1.4.0",
69
68
  "ignore": "^7.0.0",
70
69
  "natural-compare": "^1.4.0",
@@ -73,8 +72,8 @@
73
72
  "devDependencies": {
74
73
  "@types/mdast": "^4.0.3",
75
74
  "@types/natural-compare": "*",
76
- "@typescript-eslint/rule-schema-to-typescript-types": "8.33.1-alpha.5",
77
- "@typescript-eslint/rule-tester": "8.33.1-alpha.5",
75
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.33.1",
76
+ "@typescript-eslint/rule-tester": "8.33.1",
78
77
  "@vitest/coverage-v8": "^3.1.3",
79
78
  "ajv": "^6.12.6",
80
79
  "cross-fetch": "*",
@@ -94,7 +93,7 @@
94
93
  "vitest": "^3.1.3"
95
94
  },
96
95
  "peerDependencies": {
97
- "@typescript-eslint/parser": "^8.33.1-alpha.5",
96
+ "@typescript-eslint/parser": "^8.33.1",
98
97
  "eslint": "^8.57.0 || ^9.0.0",
99
98
  "typescript": ">=4.8.4 <5.9.0"
100
99
  },
@@ -1,57 +0,0 @@
1
- ---
2
- title: Overview
3
- sidebar_label: Overview
4
- pagination_next: null
5
- pagination_prev: null
6
- slug: /
7
- ---
8
-
9
- `@typescript-eslint/eslint-plugin` includes over 100 rules that detect best practice violations, bugs, and/or stylistic issues specifically for TypeScript code. All of our rules are listed below.
10
-
11
- :::tip
12
- Instead of enabling rules one by one, we recommend using one of [our pre-defined configs](/users/configs) to enable a large set of recommended rules.
13
- :::
14
-
15
- ## Rules
16
-
17
- The rules are listed in alphabetical order. You can optionally filter them based on these categories:
18
-
19
- import RulesTable from "@site/src/components/RulesTable";
20
-
21
- <RulesTable />
22
-
23
- ## Filtering
24
-
25
- ### Config Group (⚙️)
26
-
27
- "Config Group" refers to the [pre-defined config](/users/configs) that includes the rule. Extending from a configuration preset allow for enabling a large set of recommended rules all at once.
28
-
29
- ### Metadata
30
-
31
- - `🔧 fixable` refers to whether the rule contains an [ESLint `--fix` auto-fixer](https://eslint.org/docs/latest/use/command-line-interface#--fix).
32
- - `💡 has suggestions` refers to whether the rule contains an ESLint suggestion fixer.
33
- - Sometimes, it is not safe to automatically fix the code with an auto-fixer. But in these cases, we often have a good guess of what the correct fix should be, and we can provide it as a suggestion to the developer.
34
- - `💭 requires type information` refers to whether the rule requires [typed linting](/getting-started/typed-linting).
35
- - `🧱 extension rule` means that the rule is an extension of an [core ESLint rule](https://eslint.org/docs/latest/rules) (see [Extension Rules](#extension-rules)).
36
- - `💀 deprecated rule` means that the rule should no longer be used and will be removed from the plugin in a future version.
37
-
38
- ## Extension Rules
39
-
40
- Some core ESLint rules do not support TypeScript syntax: either they crash, ignore the syntax, or falsely report against it.
41
- In these cases, we create what we call an "extension rule": a rule within our plugin that has the same functionality, but also supports TypeScript.
42
-
43
- Extension rules generally completely replace the base rule from ESLint core.
44
- If the base rule is enabled in a config you extend from, you'll need to disable the base rule:
45
-
46
- ```js
47
- module.exports = {
48
- extends: ['eslint:recommended'],
49
- rules: {
50
- // Note: you must disable the base rule as it can report incorrect errors
51
- 'no-unused-vars': 'off',
52
- '@typescript-eslint/no-unused-vars': 'error',
53
- },
54
- };
55
- ```
56
-
57
- [Search for `🧱 extension rule`s](?=extension#rules) in this page to see all extension rules.
@@ -1,36 +0,0 @@
1
- ---
2
- description: '<Description from rule metadata here>'
3
- ---
4
-
5
- import Tabs from '@theme/Tabs';
6
- import TabItem from '@theme/TabItem';
7
-
8
- > 🛑 This file is source code, not the primary documentation location! 🛑
9
- >
10
- > See **https://typescript-eslint.io/rules/RULE_NAME_REPLACEME** for documentation.
11
-
12
- ## Examples
13
-
14
- To fill out: tell us more about this rule.
15
-
16
- <Tabs>
17
- <TabItem value="❌ Incorrect">
18
-
19
- ```ts
20
- // To fill out: incorrect code
21
- ```
22
-
23
- </TabItem>
24
- <TabItem value="✅ Correct">
25
-
26
- ```ts
27
- // To fill out: correct code
28
- ```
29
-
30
- </TabItem>
31
- </Tabs>
32
-
33
- ## When Not To Use It
34
-
35
- To fill out: why wouldn't you want to use this rule?
36
- For example if this rule requires a feature released in a certain TS version.
@@ -1,105 +0,0 @@
1
- ---
2
- description: 'Require that function overload signatures be consecutive.'
3
- ---
4
-
5
- import Tabs from '@theme/Tabs';
6
- import TabItem from '@theme/TabItem';
7
-
8
- > 🛑 This file is source code, not the primary documentation location! 🛑
9
- >
10
- > See **https://typescript-eslint.io/rules/adjacent-overload-signatures** for documentation.
11
-
12
- Function overload signatures represent multiple ways a function can be called, potentially with different return types.
13
- It's typical for an interface or type alias describing a function to place all overload signatures next to each other.
14
- If Signatures placed elsewhere in the type are easier to be missed by future developers reading the code.
15
-
16
- ## Examples
17
-
18
- <Tabs>
19
- <TabItem value="❌ Incorrect">
20
-
21
- ```ts
22
- declare namespace Foo {
23
- export function foo(s: string): void;
24
- export function foo(n: number): void;
25
- export function bar(): void;
26
- export function foo(sn: string | number): void;
27
- }
28
-
29
- type Foo = {
30
- foo(s: string): void;
31
- foo(n: number): void;
32
- bar(): void;
33
- foo(sn: string | number): void;
34
- };
35
-
36
- interface Foo {
37
- foo(s: string): void;
38
- foo(n: number): void;
39
- bar(): void;
40
- foo(sn: string | number): void;
41
- }
42
-
43
- class Foo {
44
- foo(s: string): void;
45
- foo(n: number): void;
46
- bar(): void {}
47
- foo(sn: string | number): void {}
48
- }
49
-
50
- export function foo(s: string): void;
51
- export function foo(n: number): void;
52
- export function bar(): void;
53
- export function foo(sn: string | number): void;
54
- ```
55
-
56
- </TabItem>
57
- <TabItem value="✅ Correct">
58
-
59
- ```ts
60
- declare namespace Foo {
61
- export function foo(s: string): void;
62
- export function foo(n: number): void;
63
- export function foo(sn: string | number): void;
64
- export function bar(): void;
65
- }
66
-
67
- type Foo = {
68
- foo(s: string): void;
69
- foo(n: number): void;
70
- foo(sn: string | number): void;
71
- bar(): void;
72
- };
73
-
74
- interface Foo {
75
- foo(s: string): void;
76
- foo(n: number): void;
77
- foo(sn: string | number): void;
78
- bar(): void;
79
- }
80
-
81
- class Foo {
82
- foo(s: string): void;
83
- foo(n: number): void;
84
- foo(sn: string | number): void {}
85
- bar(): void {}
86
- }
87
-
88
- export function bar(): void;
89
- export function foo(s: string): void;
90
- export function foo(n: number): void;
91
- export function foo(sn: string | number): void;
92
- ```
93
-
94
- </TabItem>
95
- </Tabs>
96
-
97
- ## When Not To Use It
98
-
99
- It can sometimes be useful to place overload signatures alongside other meaningful parts of a type.
100
- For example, if each of a function's overloads corresponds to a different property, you might wish to put each overloads next to its corresponding property.
101
- 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.
102
-
103
- ## Related To
104
-
105
- - [`unified-signatures`](./unified-signatures.mdx)
@@ -1,126 +0,0 @@
1
- ---
2
- description: 'Require consistently using either `T[]` or `Array<T>` for arrays.'
3
- ---
4
-
5
- import Tabs from '@theme/Tabs';
6
- import TabItem from '@theme/TabItem';
7
-
8
- > 🛑 This file is source code, not the primary documentation location! 🛑
9
- >
10
- > See **https://typescript-eslint.io/rules/array-type** for documentation.
11
-
12
- TypeScript provides two equivalent ways to define an array type: `T[]` and `Array<T>`.
13
- The two styles are functionally equivalent.
14
- Using the same style consistently across your codebase makes it easier for developers to read and understand array types.
15
-
16
- ## Options
17
-
18
- The default config will enforce that all mutable and readonly arrays use the `'array'` syntax.
19
-
20
- ### `"array"`
21
-
22
- Always use `T[]` or `readonly T[]` for all array types.
23
-
24
- <Tabs>
25
- <TabItem value="❌ Incorrect">
26
-
27
- ```ts option='{ "default": "array" }'
28
- const x: Array<string> = ['a', 'b'];
29
- const y: ReadonlyArray<string> = ['a', 'b'];
30
- ```
31
-
32
- </TabItem>
33
- <TabItem value="✅ Correct">
34
-
35
- ```ts option='{ "default": "array" }'
36
- const x: string[] = ['a', 'b'];
37
- const y: readonly string[] = ['a', 'b'];
38
- ```
39
-
40
- </TabItem>
41
- </Tabs>
42
-
43
- ### `"generic"`
44
-
45
- Always use `Array<T>`, `ReadonlyArray<T>`, or `Readonly<Array<T>>` for all array types.
46
- `readonly T[]` will be modified to `ReadonlyArray<T>` and `Readonly<T[]>` will be modified to `Readonly<Array<T>>`.
47
-
48
- <Tabs>
49
- <TabItem value="❌ Incorrect">
50
-
51
- ```ts option='{ "default": "generic" }'
52
- const x: string[] = ['a', 'b'];
53
- const y: readonly string[] = ['a', 'b'];
54
- const z: Readonly<string[]> = ['a', 'b'];
55
- ```
56
-
57
- </TabItem>
58
- <TabItem value="✅ Correct">
59
-
60
- ```ts option='{ "default": "generic" }'
61
- const x: Array<string> = ['a', 'b'];
62
- const y: ReadonlyArray<string> = ['a', 'b'];
63
- const z: Readonly<Array<string>> = ['a', 'b'];
64
- ```
65
-
66
- </TabItem>
67
- </Tabs>
68
-
69
- ### `"array-simple"`
70
-
71
- Use `T[]` or `readonly T[]` for simple types (i.e. types which are just primitive names or type references).
72
- Use `Array<T>` or `ReadonlyArray<T>` for all other types (union types, intersection types, object types, function types, etc).
73
-
74
- <Tabs>
75
- <TabItem value="❌ Incorrect">
76
-
77
- ```ts option='{ "default": "array-simple" }'
78
- const a: (string | number)[] = ['a', 'b'];
79
- const b: { prop: string }[] = [{ prop: 'a' }];
80
- const c: (() => void)[] = [() => {}];
81
- const d: Array<MyType> = ['a', 'b'];
82
- const e: Array<string> = ['a', 'b'];
83
- const f: ReadonlyArray<string> = ['a', 'b'];
84
- ```
85
-
86
- </TabItem>
87
- <TabItem value="✅ Correct">
88
-
89
- ```ts option='{ "default": "array-simple" }'
90
- const a: Array<string | number> = ['a', 'b'];
91
- const b: Array<{ prop: string }> = [{ prop: 'a' }];
92
- const c: Array<() => void> = [() => {}];
93
- const d: MyType[] = ['a', 'b'];
94
- const e: string[] = ['a', 'b'];
95
- const f: readonly string[] = ['a', 'b'];
96
- ```
97
-
98
- </TabItem>
99
- </Tabs>
100
-
101
- ## Combination Matrix
102
-
103
- This matrix lists all possible option combinations and their expected results for different types of Arrays.
104
-
105
- | defaultOption | readonlyOption | Array with simple type | Array with non simple type | Readonly array with simple type | Readonly array with non simple type |
106
- | -------------- | -------------- | ---------------------- | -------------------------- | ------------------------------- | ----------------------------------- |
107
- | `array` | | `number[]` | `(Foo & Bar)[]` | `readonly number[]` | `readonly (Foo & Bar)[]` |
108
- | `array` | `array` | `number[]` | `(Foo & Bar)[]` | `readonly number[]` | `readonly (Foo & Bar)[]` |
109
- | `array` | `array-simple` | `number[]` | `(Foo & Bar)[]` | `readonly number[]` | `ReadonlyArray<Foo & Bar>` |
110
- | `array` | `generic` | `number[]` | `(Foo & Bar)[]` | `ReadonlyArray<number>` | `ReadonlyArray<Foo & Bar>` |
111
- | `array-simple` | | `number[]` | `Array<Foo & Bar>` | `readonly number[]` | `ReadonlyArray<Foo & Bar>` |
112
- | `array-simple` | `array` | `number[]` | `Array<Foo & Bar>` | `readonly number[]` | `readonly (Foo & Bar)[]` |
113
- | `array-simple` | `array-simple` | `number[]` | `Array<Foo & Bar>` | `readonly number[]` | `ReadonlyArray<Foo & Bar>` |
114
- | `array-simple` | `generic` | `number[]` | `Array<Foo & Bar>` | `ReadonlyArray<number>` | `ReadonlyArray<Foo & Bar>` |
115
- | `generic` | | `Array<number>` | `Array<Foo & Bar>` | `ReadonlyArray<number>` | `ReadonlyArray<Foo & Bar>` |
116
- | `generic` | `array` | `Array<number>` | `Array<Foo & Bar>` | `readonly number[]` | `readonly (Foo & Bar)[]` |
117
- | `generic` | `array-simple` | `Array<number>` | `Array<Foo & Bar>` | `readonly number[]` | `ReadonlyArray<Foo & Bar>` |
118
- | `generic` | `generic` | `Array<number>` | `Array<Foo & Bar>` | `ReadonlyArray<number>` | `ReadonlyArray<Foo & Bar>` |
119
-
120
- ## When Not To Use It
121
-
122
- This rule is purely a stylistic rule for maintaining consistency in your project.
123
- You can turn it off if you don't want to keep a consistent style for array types.
124
-
125
- However, keep in mind that inconsistent style can harm readability in a project.
126
- We recommend picking a single option for this rule that works best for your project.
@@ -1,184 +0,0 @@
1
- ---
2
- description: 'Disallow awaiting a value that is not a Thenable.'
3
- ---
4
-
5
- import Tabs from '@theme/Tabs';
6
- import TabItem from '@theme/TabItem';
7
-
8
- > 🛑 This file is source code, not the primary documentation location! 🛑
9
- >
10
- > See **https://typescript-eslint.io/rules/await-thenable** for documentation.
11
-
12
- A "Thenable" value is an object which has a `then` method, such as a Promise.
13
- The [`await` keyword](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await) is generally used to retrieve the result of calling a Thenable's `then` method.
14
-
15
- If the `await` keyword is used on a value that is not a Thenable, the value is directly resolved, but will still pause execution until the next microtask.
16
- While doing so is valid JavaScript, it is often a programmer error, such as forgetting to add parenthesis to call a function that returns a Promise.
17
-
18
- ## Examples
19
-
20
- <Tabs>
21
- <TabItem value="❌ Incorrect">
22
-
23
- ```ts
24
- await 'value';
25
-
26
- const createValue = () => 'value';
27
- await createValue();
28
- ```
29
-
30
- </TabItem>
31
- <TabItem value="✅ Correct">
32
-
33
- ```ts
34
- await Promise.resolve('value');
35
-
36
- const createValue = async () => 'value';
37
- await createValue();
38
- ```
39
-
40
- </TabItem>
41
- </Tabs>
42
-
43
- ## Async Iteration (`for await...of` Loops)
44
-
45
- This rule also inspects [`for await...of` statements](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of), and reports if the value being iterated over is not async-iterable.
46
-
47
- :::info[Why does the rule report on `for await...of` loops used on an array of Promises?]
48
-
49
- While `for await...of` can be used with synchronous iterables, and it will await each promise produced by the iterable, it is inadvisable to do so.
50
- There are some tiny nuances that you may want to consider.
51
-
52
- The biggest difference between using `for await...of` and using `for...of` (apart from awaiting each result yourself) is error handling.
53
- When an error occurs within the loop body, `for await...of` does _not_ close the original sync iterable, while `for...of` does.
54
- For detailed examples of this, see the [MDN documentation on using `for await...of` with sync-iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of#iterating_over_sync_iterables_and_generators).
55
-
56
- Also consider whether you need sequential awaiting at all. Using `for await...of` may obscure potential opportunities for concurrent processing, such as those reported by [`no-await-in-loop`](https://eslint.org/docs/latest/rules/no-await-in-loop). Consider instead using one of the [promise concurrency methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#promise_concurrency) for better performance.
57
-
58
- :::
59
-
60
- ### Examples
61
-
62
- <Tabs>
63
- <TabItem value="❌ Incorrect">
64
-
65
- ```ts
66
- async function syncIterable() {
67
- const arrayOfValues = [1, 2, 3];
68
- for await (const value of arrayOfValues) {
69
- console.log(value);
70
- }
71
- }
72
-
73
- async function syncIterableOfPromises() {
74
- const arrayOfPromises = [
75
- Promise.resolve(1),
76
- Promise.resolve(2),
77
- Promise.resolve(3),
78
- ];
79
- for await (const promisedValue of arrayOfPromises) {
80
- console.log(promisedValue);
81
- }
82
- }
83
- ```
84
-
85
- </TabItem>
86
- <TabItem value="✅ Correct">
87
-
88
- ```ts
89
- async function syncIterable() {
90
- const arrayOfValues = [1, 2, 3];
91
- for (const value of arrayOfValues) {
92
- console.log(value);
93
- }
94
- }
95
-
96
- async function syncIterableOfPromises() {
97
- const arrayOfPromises = [
98
- Promise.resolve(1),
99
- Promise.resolve(2),
100
- Promise.resolve(3),
101
- ];
102
- for (const promisedValue of await Promise.all(arrayOfPromises)) {
103
- console.log(promisedValue);
104
- }
105
- }
106
-
107
- async function validUseOfForAwaitOnAsyncIterable() {
108
- async function* yieldThingsAsynchronously() {
109
- yield 1;
110
- await new Promise(resolve => setTimeout(resolve, 1000));
111
- yield 2;
112
- }
113
-
114
- for await (const promisedValue of yieldThingsAsynchronously()) {
115
- console.log(promisedValue);
116
- }
117
- }
118
- ```
119
-
120
- </TabItem>
121
- </Tabs>
122
-
123
- ## Explicit Resource Management (`await using` Statements)
124
-
125
- This rule also inspects [`await using` statements](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management).
126
- If the disposable being used is not async-disposable, an `await using` statement is unnecessary.
127
-
128
- ### Examples
129
-
130
- <Tabs>
131
- <TabItem value="❌ Incorrect">
132
-
133
- ```ts
134
- function makeSyncDisposable(): Disposable {
135
- return {
136
- [Symbol.dispose](): void {
137
- // Dispose of the resource
138
- },
139
- };
140
- }
141
-
142
- async function shouldNotAwait() {
143
- await using resource = makeSyncDisposable();
144
- }
145
- ```
146
-
147
- </TabItem>
148
- <TabItem value="✅ Correct">
149
-
150
- ```ts
151
- function makeSyncDisposable(): Disposable {
152
- return {
153
- [Symbol.dispose](): void {
154
- // Dispose of the resource
155
- },
156
- };
157
- }
158
-
159
- async function shouldNotAwait() {
160
- using resource = makeSyncDisposable();
161
- }
162
-
163
- function makeAsyncDisposable(): AsyncDisposable {
164
- return {
165
- async [Symbol.asyncDispose](): Promise<void> {
166
- // Dispose of the resource asynchronously
167
- },
168
- };
169
- }
170
-
171
- async function shouldAwait() {
172
- await using resource = makeAsyncDisposable();
173
- }
174
- ```
175
-
176
- </TabItem>
177
- </Tabs>
178
-
179
- ## When Not To Use It
180
-
181
- If you want to allow code to `await` non-Promise values.
182
- For example, if your framework is in transition from one style of asynchronous code to another, it may be useful to include `await`s unnecessarily.
183
- This is generally not preferred but can sometimes be useful for visual consistency.
184
- 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.