@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.
Files changed (183) hide show
  1. package/dist/configs/all.js +1 -0
  2. package/dist/configs/all.js.map +1 -1
  3. package/dist/configs/disable-type-checked.js +1 -0
  4. package/dist/configs/disable-type-checked.js.map +1 -1
  5. package/dist/configs/strict-type-checked-only.js +23 -3
  6. package/dist/configs/strict-type-checked-only.js.map +1 -1
  7. package/dist/configs/strict-type-checked.js +27 -4
  8. package/dist/configs/strict-type-checked.js.map +1 -1
  9. package/dist/configs/strict.js +4 -1
  10. package/dist/configs/strict.js.map +1 -1
  11. package/dist/rules/ban-ts-comment.js +4 -1
  12. package/dist/rules/ban-ts-comment.js.map +1 -1
  13. package/dist/rules/consistent-type-imports.js +1 -0
  14. package/dist/rules/consistent-type-imports.js.map +1 -1
  15. package/dist/rules/index.js +2 -0
  16. package/dist/rules/index.js.map +1 -1
  17. package/dist/rules/no-floating-promises.js +4 -1
  18. package/dist/rules/no-floating-promises.js.map +1 -1
  19. package/dist/rules/no-misused-promises.js +1 -1
  20. package/dist/rules/no-misused-promises.js.map +1 -1
  21. package/dist/rules/no-redundant-type-constituents.js +42 -0
  22. package/dist/rules/no-redundant-type-constituents.js.map +1 -1
  23. package/dist/rules/no-unnecessary-qualifier.js +1 -1
  24. package/dist/rules/no-unnecessary-qualifier.js.map +1 -1
  25. package/dist/rules/no-unsafe-argument.js +1 -25
  26. package/dist/rules/no-unsafe-argument.js.map +1 -1
  27. package/dist/rules/no-unused-expressions.js +6 -2
  28. package/dist/rules/no-unused-expressions.js.map +1 -1
  29. package/dist/rules/restrict-plus-operands.js +12 -1
  30. package/dist/rules/restrict-plus-operands.js.map +1 -1
  31. package/dist/rules/restrict-template-expressions.js +52 -87
  32. package/dist/rules/restrict-template-expressions.js.map +1 -1
  33. package/dist/rules/use-unknown-in-catch-callback-variable.js +283 -0
  34. package/dist/rules/use-unknown-in-catch-callback-variable.js.map +1 -0
  35. package/dist/util/misc.js +10 -1
  36. package/dist/util/misc.js.map +1 -1
  37. package/docs/rules/TEMPLATE.md +10 -4
  38. package/docs/rules/{adjacent-overload-signatures.md → adjacent-overload-signatures.mdx} +11 -5
  39. package/docs/rules/{array-type.md → array-type.mdx} +24 -12
  40. package/docs/rules/{await-thenable.md → await-thenable.mdx} +10 -4
  41. package/docs/rules/{ban-ts-comment.md → ban-ts-comment.mdx} +32 -18
  42. package/docs/rules/{ban-tslint-comment.md → ban-tslint-comment.mdx} +10 -4
  43. package/docs/rules/{ban-types.md → ban-types.mdx} +11 -5
  44. package/docs/rules/{block-spacing.md → block-spacing.mdx} +3 -0
  45. package/docs/rules/{brace-style.md → brace-style.mdx} +3 -0
  46. package/docs/rules/camelcase.md +3 -5
  47. package/docs/rules/{class-literal-property-style.md → class-literal-property-style.mdx} +18 -11
  48. package/docs/rules/{class-methods-use-this.md → class-methods-use-this.mdx} +12 -6
  49. package/docs/rules/{comma-dangle.md → comma-dangle.mdx} +3 -0
  50. package/docs/rules/{comma-spacing.md → comma-spacing.mdx} +3 -0
  51. package/docs/rules/{consistent-generic-constructors.md → consistent-generic-constructors.mdx} +17 -8
  52. package/docs/rules/{consistent-indexed-object-style.md → consistent-indexed-object-style.mdx} +17 -8
  53. package/docs/rules/{consistent-return.md → consistent-return.mdx} +10 -4
  54. package/docs/rules/{consistent-type-assertions.md → consistent-type-assertions.mdx} +15 -10
  55. package/docs/rules/{consistent-type-definitions.md → consistent-type-definitions.mdx} +17 -8
  56. package/docs/rules/{consistent-type-exports.md → consistent-type-exports.mdx} +17 -8
  57. package/docs/rules/{consistent-type-imports.md → consistent-type-imports.mdx} +13 -8
  58. package/docs/rules/{default-param-last.md → default-param-last.mdx} +10 -4
  59. package/docs/rules/{dot-notation.md → dot-notation.mdx} +3 -0
  60. package/docs/rules/{explicit-function-return-type.md → explicit-function-return-type.mdx} +59 -32
  61. package/docs/rules/{explicit-member-accessibility.md → explicit-member-accessibility.mdx} +3 -0
  62. package/docs/rules/{explicit-module-boundary-types.md → explicit-module-boundary-types.mdx} +39 -21
  63. package/docs/rules/{func-call-spacing.md → func-call-spacing.mdx} +3 -0
  64. package/docs/rules/{indent.md → indent.mdx} +3 -0
  65. package/docs/rules/{init-declarations.md → init-declarations.mdx} +3 -0
  66. package/docs/rules/{key-spacing.md → key-spacing.mdx} +3 -0
  67. package/docs/rules/{keyword-spacing.md → keyword-spacing.mdx} +3 -0
  68. package/docs/rules/{lines-around-comment.md → lines-around-comment.mdx} +3 -0
  69. package/docs/rules/{lines-between-class-members.md → lines-between-class-members.mdx} +3 -0
  70. package/docs/rules/{max-params.md → max-params.mdx} +3 -0
  71. package/docs/rules/{member-delimiter-style.md → member-delimiter-style.mdx} +13 -7
  72. package/docs/rules/{member-ordering.md → member-ordering.mdx} +92 -56
  73. package/docs/rules/{method-signature-style.md → method-signature-style.mdx} +17 -8
  74. package/docs/rules/{naming-convention.md → naming-convention.mdx} +3 -0
  75. package/docs/rules/{no-array-constructor.md → no-array-constructor.mdx} +10 -4
  76. package/docs/rules/{no-array-delete.md → no-array-delete.mdx} +9 -5
  77. package/docs/rules/{no-base-to-string.md → no-base-to-string.mdx} +12 -6
  78. package/docs/rules/{no-confusing-non-null-assertion.md → no-confusing-non-null-assertion.mdx} +11 -5
  79. package/docs/rules/{no-confusing-void-expression.md → no-confusing-void-expression.mdx} +10 -4
  80. package/docs/rules/{no-dupe-class-members.md → no-dupe-class-members.mdx} +4 -1
  81. package/docs/rules/{no-duplicate-enum-values.md → no-duplicate-enum-values.mdx} +10 -4
  82. package/docs/rules/{no-duplicate-imports.md → no-duplicate-imports.mdx} +1 -1
  83. package/docs/rules/{no-duplicate-type-constituents.md → no-duplicate-type-constituents.mdx} +10 -4
  84. package/docs/rules/{no-dynamic-delete.md → no-dynamic-delete.mdx} +10 -4
  85. package/docs/rules/{no-empty-function.md → no-empty-function.mdx} +3 -0
  86. package/docs/rules/{no-empty-interface.md → no-empty-interface.mdx} +9 -5
  87. package/docs/rules/{no-explicit-any.md → no-explicit-any.mdx} +15 -9
  88. package/docs/rules/{no-extra-non-null-assertion.md → no-extra-non-null-assertion.mdx} +11 -5
  89. package/docs/rules/{no-extra-parens.md → no-extra-parens.mdx} +3 -0
  90. package/docs/rules/{no-extra-semi.md → no-extra-semi.mdx} +3 -0
  91. package/docs/rules/{no-extraneous-class.md → no-extraneous-class.mdx} +61 -33
  92. package/docs/rules/{no-floating-promises.md → no-floating-promises.mdx} +12 -6
  93. package/docs/rules/{no-for-in-array.md → no-for-in-array.mdx} +10 -4
  94. package/docs/rules/{no-implied-eval.md → no-implied-eval.mdx} +10 -4
  95. package/docs/rules/{no-import-type-side-effects.md → no-import-type-side-effects.mdx} +12 -6
  96. package/docs/rules/{no-inferrable-types.md → no-inferrable-types.mdx} +9 -5
  97. package/docs/rules/{no-invalid-this.md → no-invalid-this.mdx} +4 -1
  98. package/docs/rules/{no-invalid-void-type.md → no-invalid-void-type.mdx} +10 -4
  99. package/docs/rules/{no-loop-func.md → no-loop-func.mdx} +3 -0
  100. package/docs/rules/{no-loss-of-precision.md → no-loss-of-precision.mdx} +3 -0
  101. package/docs/rules/{no-magic-numbers.md → no-magic-numbers.mdx} +3 -0
  102. package/docs/rules/{no-meaningless-void-operator.md → no-meaningless-void-operator.mdx} +12 -4
  103. package/docs/rules/{no-misused-new.md → no-misused-new.mdx} +10 -4
  104. package/docs/rules/{no-misused-promises.md → no-misused-promises.mdx} +24 -16
  105. package/docs/rules/{no-mixed-enums.md → no-mixed-enums.mdx} +14 -6
  106. package/docs/rules/{no-namespace.md → no-namespace.mdx} +29 -18
  107. package/docs/rules/{no-non-null-asserted-nullish-coalescing.md → no-non-null-asserted-nullish-coalescing.mdx} +10 -4
  108. package/docs/rules/{no-non-null-asserted-optional-chain.md → no-non-null-asserted-optional-chain.mdx} +10 -4
  109. package/docs/rules/{no-non-null-assertion.md → no-non-null-assertion.mdx} +10 -4
  110. package/docs/rules/{no-redeclare.md → no-redeclare.mdx} +4 -1
  111. package/docs/rules/{no-redundant-type-constituents.md → no-redundant-type-constituents.mdx} +10 -4
  112. package/docs/rules/{no-require-imports.md → no-require-imports.mdx} +18 -9
  113. package/docs/rules/{no-restricted-imports.md → no-restricted-imports.mdx} +10 -4
  114. package/docs/rules/{no-shadow.md → no-shadow.mdx} +4 -1
  115. package/docs/rules/{no-this-alias.md → no-this-alias.mdx} +24 -12
  116. package/docs/rules/{no-throw-literal.md → no-throw-literal.mdx} +11 -5
  117. package/docs/rules/{no-type-alias.md → no-type-alias.mdx} +5 -2
  118. package/docs/rules/{no-unnecessary-boolean-literal-compare.md → no-unnecessary-boolean-literal-compare.mdx} +24 -12
  119. package/docs/rules/{no-unnecessary-condition.md → no-unnecessary-condition.mdx} +11 -5
  120. package/docs/rules/{no-unnecessary-qualifier.md → no-unnecessary-qualifier.mdx} +10 -4
  121. package/docs/rules/{no-unnecessary-type-arguments.md → no-unnecessary-type-arguments.mdx} +10 -4
  122. package/docs/rules/{no-unnecessary-type-assertion.md → no-unnecessary-type-assertion.mdx} +10 -4
  123. package/docs/rules/{no-unnecessary-type-constraint.md → no-unnecessary-type-constraint.mdx} +10 -4
  124. package/docs/rules/{no-unsafe-argument.md → no-unsafe-argument.mdx} +14 -10
  125. package/docs/rules/{no-unsafe-assignment.md → no-unsafe-assignment.mdx} +14 -10
  126. package/docs/rules/{no-unsafe-call.md → no-unsafe-call.mdx} +15 -9
  127. package/docs/rules/{no-unsafe-declaration-merging.md → no-unsafe-declaration-merging.mdx} +10 -4
  128. package/docs/rules/{no-unsafe-enum-comparison.md → no-unsafe-enum-comparison.mdx} +9 -5
  129. package/docs/rules/{no-unsafe-member-access.md → no-unsafe-member-access.mdx} +15 -9
  130. package/docs/rules/{no-unsafe-return.md → no-unsafe-return.mdx} +14 -10
  131. package/docs/rules/{no-unsafe-unary-minus.md → no-unsafe-unary-minus.mdx} +11 -5
  132. package/docs/rules/{no-unused-expressions.md → no-unused-expressions.mdx} +3 -0
  133. package/docs/rules/{no-unused-vars.md → no-unused-vars.mdx} +3 -0
  134. package/docs/rules/{no-use-before-define.md → no-use-before-define.mdx} +10 -4
  135. package/docs/rules/{no-useless-constructor.md → no-useless-constructor.mdx} +3 -0
  136. package/docs/rules/{no-useless-empty-export.md → no-useless-empty-export.mdx} +10 -4
  137. package/docs/rules/{no-useless-template-literals.md → no-useless-template-literals.mdx} +10 -6
  138. package/docs/rules/{no-var-requires.md → no-var-requires.mdx} +18 -9
  139. package/docs/rules/{non-nullable-type-assertion-style.md → non-nullable-type-assertion-style.mdx} +10 -4
  140. package/docs/rules/{object-curly-spacing.md → object-curly-spacing.mdx} +3 -0
  141. package/docs/rules/{padding-line-between-statements.md → padding-line-between-statements.mdx} +3 -0
  142. package/docs/rules/{parameter-properties.md → parameter-properties.mdx} +66 -36
  143. package/docs/rules/{prefer-as-const.md → prefer-as-const.mdx} +9 -5
  144. package/docs/rules/{prefer-destructuring.md → prefer-destructuring.mdx} +23 -12
  145. package/docs/rules/{prefer-enum-initializers.md → prefer-enum-initializers.mdx} +10 -4
  146. package/docs/rules/{prefer-find.md → prefer-find.mdx} +10 -4
  147. package/docs/rules/{prefer-for-of.md → prefer-for-of.mdx} +11 -5
  148. package/docs/rules/{prefer-function-type.md → prefer-function-type.mdx} +10 -4
  149. package/docs/rules/{prefer-includes.md → prefer-includes.mdx} +11 -5
  150. package/docs/rules/{prefer-literal-enum-member.md → prefer-literal-enum-member.mdx} +16 -9
  151. package/docs/rules/{prefer-namespace-keyword.md → prefer-namespace-keyword.mdx} +9 -5
  152. package/docs/rules/{prefer-nullish-coalescing.md → prefer-nullish-coalescing.mdx} +3 -0
  153. package/docs/rules/{prefer-optional-chain.md → prefer-optional-chain.mdx} +58 -33
  154. package/docs/rules/{prefer-promise-reject-errors.md → prefer-promise-reject-errors.mdx} +10 -4
  155. package/docs/rules/{prefer-readonly-parameter-types.md → prefer-readonly-parameter-types.mdx} +36 -22
  156. package/docs/rules/{prefer-readonly.md → prefer-readonly.mdx} +17 -8
  157. package/docs/rules/{prefer-reduce-type-parameter.md → prefer-reduce-type-parameter.mdx} +10 -4
  158. package/docs/rules/{prefer-regexp-exec.md → prefer-regexp-exec.mdx} +10 -4
  159. package/docs/rules/{prefer-return-this-type.md → prefer-return-this-type.mdx} +10 -4
  160. package/docs/rules/{prefer-string-starts-ends-with.md → prefer-string-starts-ends-with.mdx} +9 -5
  161. package/docs/rules/{prefer-ts-expect-error.md → prefer-ts-expect-error.mdx} +10 -4
  162. package/docs/rules/{promise-function-async.md → promise-function-async.mdx} +24 -12
  163. package/docs/rules/{quotes.md → quotes.mdx} +3 -0
  164. package/docs/rules/{require-array-sort-compare.md → require-array-sort-compare.mdx} +17 -8
  165. package/docs/rules/{require-await.md → require-await.mdx} +3 -0
  166. package/docs/rules/{restrict-plus-operands.md → restrict-plus-operands.mdx} +54 -30
  167. package/docs/rules/{restrict-template-expressions.md → restrict-template-expressions.mdx} +24 -9
  168. package/docs/rules/{return-await.md → return-await.mdx} +24 -12
  169. package/docs/rules/{semi.md → semi.mdx} +4 -1
  170. package/docs/rules/{sort-type-constituents.md → sort-type-constituents.mdx} +31 -16
  171. package/docs/rules/{space-before-blocks.md → space-before-blocks.mdx} +10 -4
  172. package/docs/rules/{space-before-function-paren.md → space-before-function-paren.mdx} +3 -0
  173. package/docs/rules/{space-infix-ops.md → space-infix-ops.mdx} +3 -0
  174. package/docs/rules/{strict-boolean-expressions.md → strict-boolean-expressions.mdx} +11 -5
  175. package/docs/rules/{switch-exhaustiveness-check.md → switch-exhaustiveness-check.mdx} +19 -14
  176. package/docs/rules/{triple-slash-reference.md → triple-slash-reference.mdx} +30 -17
  177. package/docs/rules/{type-annotation-spacing.md → type-annotation-spacing.mdx} +49 -31
  178. package/docs/rules/{typedef.md → typedef.mdx} +60 -33
  179. package/docs/rules/{unbound-method.md → unbound-method.mdx} +12 -6
  180. package/docs/rules/{unified-signatures.md → unified-signatures.mdx} +18 -9
  181. package/docs/rules/use-unknown-in-catch-callback-variable.mdx +84 -0
  182. package/package.json +8 -8
  183. /package/docs/rules/{no-parameter-properties.md → no-parameter-properties.mdx} +0 -0
@@ -2,6 +2,9 @@
2
2
  description: 'Enforce using `String#startsWith` and `String#endsWith` over other equivalent methods of checking substrings.'
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/prefer-string-starts-ends-with** for documentation.
@@ -14,9 +17,8 @@ This rule reports when a string method can be replaced safely with `String#start
14
17
 
15
18
  ## Examples
16
19
 
17
- <!--tabs-->
18
-
19
- ### ❌ Incorrect
20
+ <Tabs>
21
+ <TabItem value="❌ Incorrect">
20
22
 
21
23
  ```ts
22
24
  declare const foo: string;
@@ -40,7 +42,8 @@ foo.match(/bar$/) != null;
40
42
  /bar$/.test(foo);
41
43
  ```
42
44
 
43
- ### ✅ Correct
45
+ </TabItem>
46
+ <TabItem value="✅ Correct">
44
47
 
45
48
  ```ts
46
49
  declare const foo: string;
@@ -52,7 +55,8 @@ foo.startsWith('bar');
52
55
  foo.endsWith('bar');
53
56
  ```
54
57
 
55
- <!--/tabs-->
58
+ </TabItem>
59
+ </Tabs>
56
60
 
57
61
  ## Options
58
62
 
@@ -2,6 +2,9 @@
2
2
  description: 'Enforce using `@ts-expect-error` over `@ts-ignore`.'
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/prefer-ts-expect-error** for documentation.
@@ -16,9 +19,8 @@ This is dangerous, as if a new error arises on that line it'll be suppressed by
16
19
 
17
20
  This rule reports any usage of `@ts-ignore`, including a fixer to replace with `@ts-expect-error`.
18
21
 
19
- <!--tabs-->
20
-
21
- ### ❌ Incorrect
22
+ <Tabs>
23
+ <TabItem value="❌ Incorrect">
22
24
 
23
25
  ```ts
24
26
  // @ts-ignore
@@ -39,7 +41,8 @@ const isOptionEnabled = (key: string): boolean => {
39
41
  };
40
42
  ```
41
43
 
42
- ### ✅ Correct
44
+ </TabItem>
45
+ <TabItem value="✅ Correct">
43
46
 
44
47
  ```ts
45
48
  // @ts-expect-error
@@ -60,6 +63,9 @@ const isOptionEnabled = (key: string): boolean => {
60
63
  };
61
64
  ```
62
65
 
66
+ </TabItem>
67
+ </Tabs>
68
+
63
69
  ## When Not To Use It
64
70
 
65
71
  If you are compiling against multiple versions of TypeScript and using `@ts-ignore` to ignore version-specific type errors, this rule might get in your way.
@@ -2,6 +2,9 @@
2
2
  description: 'Require any function or method that returns a Promise to be marked async.'
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/promise-function-async** for documentation.
@@ -21,9 +24,8 @@ This rule's practice removes a requirement for creating code to handle both case
21
24
 
22
25
  Examples of code for this rule
23
26
 
24
- <!--tabs-->
25
-
26
- ### ❌ Incorrect
27
+ <Tabs>
28
+ <TabItem value="❌ Incorrect">
27
29
 
28
30
  ```ts
29
31
  const arrowFunctionReturnsPromise = () => Promise.resolve('value');
@@ -37,7 +39,8 @@ function functionReturnsUnionWithPromiseImplicitly(p: boolean) {
37
39
  }
38
40
  ```
39
41
 
40
- ### ✅ Correct
42
+ </TabItem>
43
+ <TabItem value="✅ Correct">
41
44
 
42
45
  ```ts
43
46
  const arrowFunctionReturnsPromise = async () => Promise.resolve('value');
@@ -58,6 +61,9 @@ async function functionReturnsUnionWithPromiseImplicitly(p: boolean) {
58
61
  }
59
62
  ```
60
63
 
64
+ </TabItem>
65
+ </Tabs>
66
+
61
67
  ## Options
62
68
 
63
69
  ### `allowAny`
@@ -67,20 +73,23 @@ If you want additional safety, consider turning this option off, as it makes the
67
73
 
68
74
  Examples of code with `{ "allowAny": false }`:
69
75
 
70
- <!--tabs-->
71
-
72
- #### ❌ Incorrect
76
+ <Tabs>
77
+ <TabItem value="❌ Incorrect">
73
78
 
74
79
  ```ts option='{ "allowAny": false }'
75
80
  const returnsAny = () => ({}) as any;
76
81
  ```
77
82
 
78
- #### ✅ Correct
83
+ </TabItem>
84
+ <TabItem value="✅ Correct">
79
85
 
80
86
  ```ts option='{ "allowAny": false }'
81
87
  const returnsAny = async () => ({}) as any;
82
88
  ```
83
89
 
90
+ </TabItem>
91
+ </Tabs>
92
+
84
93
  ### `allowedPromiseNames`
85
94
 
86
95
  For projects that use constructs other than the global built-in `Promise` for asynchronous code.
@@ -88,9 +97,8 @@ This option allows specifying string names of classes or interfaces that cause a
88
97
 
89
98
  Examples of code with `{ "allowedPromiseNames": ["Bluebird"] }`:
90
99
 
91
- <!--tabs-->
92
-
93
- #### ❌ Incorrect
100
+ <Tabs>
101
+ <TabItem value="❌ Incorrect">
94
102
 
95
103
  ```ts option='{ "allowedPromiseNames": ["Bluebird"] }'
96
104
  import { Bluebird } from 'bluebird';
@@ -98,7 +106,8 @@ import { Bluebird } from 'bluebird';
98
106
  const returnsBluebird = () => new Bluebird(() => {});
99
107
  ```
100
108
 
101
- #### ✅ Correct
109
+ </TabItem>
110
+ <TabItem value="✅ Correct">
102
111
 
103
112
  ```ts option='{ "allowedPromiseNames": ["Bluebird"] }'
104
113
  import { Bluebird } from 'bluebird';
@@ -106,6 +115,9 @@ import { Bluebird } from 'bluebird';
106
115
  const returnsBluebird = async () => new Bluebird(() => {});
107
116
  ```
108
117
 
118
+ </TabItem>
119
+ </Tabs>
120
+
109
121
  ### `checkArrowFunctions`
110
122
 
111
123
  Whether to check arrow functions.
@@ -2,6 +2,9 @@
2
2
  description: 'Enforce the consistent use of either backticks, double, or single quotes.'
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/quotes** for documentation.
@@ -2,6 +2,9 @@
2
2
  description: 'Require `Array#sort` and `Array#toSorted` calls to always provide a `compareFunction`.'
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/require-array-sort-compare** for documentation.
@@ -21,9 +24,8 @@ This rule reports on any call to the sort methods that do not provide a `compare
21
24
 
22
25
  This rule aims to ensure all calls of the native sort methods provide a `compareFunction`, while ignoring calls to user-defined methods.
23
26
 
24
- <!--tabs-->
25
-
26
- ### ❌ Incorrect
27
+ <Tabs>
28
+ <TabItem value="❌ Incorrect">
27
29
 
28
30
  ```ts
29
31
  const array: any[];
@@ -35,7 +37,8 @@ array.sort();
35
37
  stringArray.sort();
36
38
  ```
37
39
 
38
- ### ✅ Correct
40
+ </TabItem>
41
+ <TabItem value="✅ Correct">
39
42
 
40
43
  ```ts
41
44
  const array: any[];
@@ -47,15 +50,17 @@ array.sort((a, b) => a.localeCompare(b));
47
50
  userDefinedType.sort();
48
51
  ```
49
52
 
53
+ </TabItem>
54
+ </Tabs>
55
+
50
56
  ## Options
51
57
 
52
58
  ### `ignoreStringArrays`
53
59
 
54
60
  Examples of code for this rule with `{ ignoreStringArrays: true }`:
55
61
 
56
- <!--tabs-->
57
-
58
- #### ❌ Incorrect
62
+ <Tabs>
63
+ <TabItem value="❌ Incorrect">
59
64
 
60
65
  ```ts option='{ "ignoreStringArrays": true }'
61
66
  const one = 1;
@@ -64,7 +69,8 @@ const three = 3;
64
69
  [one, two, three].sort();
65
70
  ```
66
71
 
67
- #### ✅ Correct
72
+ </TabItem>
73
+ <TabItem value="✅ Correct">
68
74
 
69
75
  ```ts option='{ "ignoreStringArrays": true }'
70
76
  const one = '1';
@@ -73,6 +79,9 @@ const three = '3';
73
79
  [one, two, three].sort();
74
80
  ```
75
81
 
82
+ </TabItem>
83
+ </Tabs>
84
+
76
85
  ## When Not To Use It
77
86
 
78
87
  If you intentionally want your arrays to be always sorted in a string-like manner, you can turn this rule off safely.
@@ -2,6 +2,9 @@
2
2
  description: 'Disallow async functions which have no `await` 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/require-await** for documentation.
@@ -2,6 +2,9 @@
2
2
  description: 'Require both operands of addition to be the same type and be `bigint`, `number`, or `string`.'
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/restrict-plus-operands** for documentation.
@@ -13,22 +16,25 @@ This rule reports when a `+` operation combines two values of different types, o
13
16
 
14
17
  ## Examples
15
18
 
16
- <!--tabs-->
17
-
18
- ### ❌ Incorrect
19
+ <Tabs>
20
+ <TabItem value="❌ Incorrect">
19
21
 
20
22
  ```ts
21
23
  let foo = 1n + 1;
22
24
  let fn = (a: string, b: never) => a + b;
23
25
  ```
24
26
 
25
- ### ✅ Correct
27
+ </TabItem>
28
+ <TabItem value="✅ Correct">
26
29
 
27
30
  ```ts
28
31
  let foo = 1n + 1n;
29
32
  let fn = (a: string, b: string) => a + b;
30
33
  ```
31
34
 
35
+ </TabItem>
36
+ </Tabs>
37
+
32
38
  ## Options
33
39
 
34
40
  :::caution
@@ -70,49 +76,54 @@ Safer alternatives to using the `allow*` options include:
70
76
 
71
77
  Examples of code for this rule with `{ allowAny: true }`:
72
78
 
73
- <!--tabs-->
74
-
75
- #### ❌ Incorrect
79
+ <Tabs>
80
+ <TabItem value="❌ Incorrect">
76
81
 
77
82
  ```ts option='{ "allowAny": true }'
78
83
  let fn = (a: number, b: []) => a + b;
79
84
  let fn = (a: string, b: []) => a + b;
80
85
  ```
81
86
 
82
- #### ✅ Correct
87
+ </TabItem>
88
+ <TabItem value="✅ Correct">
83
89
 
84
90
  ```ts option='{ "allowAny": true }'
85
91
  let fn = (a: number, b: any) => a + b;
86
92
  let fn = (a: string, b: any) => a + b;
87
93
  ```
88
94
 
95
+ </TabItem>
96
+ </Tabs>
97
+
89
98
  ### `allowBoolean`
90
99
 
91
100
  Examples of code for this rule with `{ allowBoolean: true }`:
92
101
 
93
- <!--tabs-->
94
-
95
- #### ❌ Incorrect
102
+ <Tabs>
103
+ <TabItem value="❌ Incorrect">
96
104
 
97
105
  ```ts option='{ "allowBoolean": true }'
98
106
  let fn = (a: number, b: unknown) => a + b;
99
107
  let fn = (a: string, b: unknown) => a + b;
100
108
  ```
101
109
 
102
- #### ✅ Correct
110
+ </TabItem>
111
+ <TabItem value="✅ Correct">
103
112
 
104
113
  ```ts option='{ "allowBoolean": true }'
105
114
  let fn = (a: number, b: boolean) => a + b;
106
115
  let fn = (a: string, b: boolean) => a + b;
107
116
  ```
108
117
 
118
+ </TabItem>
119
+ </Tabs>
120
+
109
121
  ### `allowNullish`
110
122
 
111
123
  Examples of code for this rule with `{ allowNullish: true }`:
112
124
 
113
- <!--tabs-->
114
-
115
- #### ❌ Incorrect
125
+ <Tabs>
126
+ <TabItem value="❌ Incorrect">
116
127
 
117
128
  ```ts option='{ "allowNullish": true }'
118
129
  let fn = (a: number, b: unknown) => a + b;
@@ -121,7 +132,8 @@ let fn = (a: string, b: unknown) => a + b;
121
132
  let fn = (a: string, b: never) => a + b;
122
133
  ```
123
134
 
124
- #### ✅ Correct
135
+ </TabItem>
136
+ <TabItem value="✅ Correct">
125
137
 
126
138
  ```ts option='{ "allowNullish": true }'
127
139
  let fn = (a: number, b: undefined) => a + b;
@@ -130,51 +142,59 @@ let fn = (a: string, b: undefined) => a + b;
130
142
  let fn = (a: string, b: null) => a + b;
131
143
  ```
132
144
 
145
+ </TabItem>
146
+ </Tabs>
147
+
133
148
  ### `allowNumberAndString`
134
149
 
135
150
  Examples of code for this rule with `{ allowNumberAndString: true }`:
136
151
 
137
- <!--tabs-->
138
-
139
- #### ❌ Incorrect
152
+ <Tabs>
153
+ <TabItem value="❌ Incorrect">
140
154
 
141
155
  ```ts option='{ "allowNumberAndString": true }'
142
156
  let fn = (a: number, b: unknown) => a + b;
143
157
  let fn = (a: number, b: never) => a + b;
144
158
  ```
145
159
 
146
- #### ✅ Correct
160
+ </TabItem>
161
+ <TabItem value="✅ Correct">
147
162
 
148
163
  ```ts option='{ "allowNumberAndString": true }'
149
164
  let fn = (a: number, b: string) => a + b;
150
165
  let fn = (a: number, b: number | string) => a + b;
151
166
  ```
152
167
 
168
+ </TabItem>
169
+ </Tabs>
170
+
153
171
  ### `allowRegExp`
154
172
 
155
173
  Examples of code for this rule with `{ allowRegExp: true }`:
156
174
 
157
- <!--tabs-->
158
-
159
- #### ❌ Incorrect
175
+ <Tabs>
176
+ <TabItem value="❌ Incorrect">
160
177
 
161
178
  ```ts option='{ "allowRegExp": true }'
162
179
  let fn = (a: number, b: RegExp) => a + b;
163
180
  ```
164
181
 
165
- #### ✅ Correct
182
+ </TabItem>
183
+ <TabItem value="✅ Correct">
166
184
 
167
185
  ```ts option='{ "allowRegExp": true }'
168
186
  let fn = (a: string, b: RegExp) => a + b;
169
187
  ```
170
188
 
189
+ </TabItem>
190
+ </Tabs>
191
+
171
192
  ### `skipCompoundAssignments`
172
193
 
173
194
  Examples of code for this rule with `{ skipCompoundAssignments: false }`:
174
195
 
175
- <!--tabs-->
176
-
177
- #### ❌ Incorrect
196
+ <Tabs>
197
+ <TabItem value="❌ Incorrect">
178
198
 
179
199
  ```ts option='{ "skipCompoundAssignments": true }'
180
200
  let foo: string | undefined;
@@ -184,7 +204,8 @@ let bar: string = '';
184
204
  bar += 0;
185
205
  ```
186
206
 
187
- #### ✅ Correct
207
+ </TabItem>
208
+ <TabItem value="✅ Correct">
188
209
 
189
210
  ```ts option='{ "skipCompoundAssignments": true }'
190
211
  let foo: number = 0;
@@ -194,14 +215,17 @@ let bar = '';
194
215
  bar += 'test';
195
216
  ```
196
217
 
218
+ </TabItem>
219
+ </Tabs>
220
+
197
221
  ## When Not To Use It
198
222
 
199
223
  If you don't mind a risk of `"[object Object]"` or incorrect type coercions in your values, then you will not need this rule.
200
224
 
201
225
  ## Related To
202
226
 
203
- - [`no-base-to-string`](./no-base-to-string.md)
204
- - [`restrict-template-expressions`](./restrict-template-expressions.md)
227
+ - [`no-base-to-string`](./no-base-to-string.mdx)
228
+ - [`restrict-template-expressions`](./restrict-template-expressions.mdx)
205
229
 
206
230
  ## Further Reading
207
231
 
@@ -2,6 +2,9 @@
2
2
  description: 'Enforce template literal expressions to be of `string` type.'
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/restrict-template-expressions** for documentation.
@@ -12,19 +15,18 @@ This rule reports on values used in a template literal string that aren't string
12
15
 
13
16
  :::note
14
17
 
15
- This rule intentionally does not allow objects with a custom `toString()` method to be used in template literals, because the stringification result may not be user-friendly.
18
+ The default settings of this rule intentionally do not allow objects with a custom `toString()` method to be used in template literals, because the stringification result may not be user-friendly.
16
19
 
17
20
  For example, arrays have a custom [`toString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString) method, which only calls `join()` internally, which joins the array elements with commas. This means that (1) array elements are not necessarily stringified to useful results (2) the commas don't have spaces after them, making the result not user-friendly. The best way to format arrays is to use [`Intl.ListFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat), which even supports adding the "and" conjunction where necessary.
18
- You must explicitly call `object.toString()` if you want to use this object in a template literal.
19
- The [`no-base-to-string`](./no-base-to-string.md) rule can be used to guard this case against producing `"[object Object]"` by accident.
21
+ You must explicitly call `object.toString()` if you want to use this object in a template literal, or turn on the `allowArray` option to specifically allow arrays.
22
+ The [`no-base-to-string`](./no-base-to-string.mdx) rule can be used to guard this case against producing `"[object Object]"` by accident.
20
23
 
21
24
  :::
22
25
 
23
26
  ## Examples
24
27
 
25
- <!--tabs-->
26
-
27
- ### ❌ Incorrect
28
+ <Tabs>
29
+ <TabItem value="❌ Incorrect">
28
30
 
29
31
  ```ts
30
32
  const arg1 = [1, 2];
@@ -34,7 +36,8 @@ const arg2 = { name: 'Foo' };
34
36
  const msg2 = `arg2 = ${arg2 || null}`;
35
37
  ```
36
38
 
37
- ### ✅ Correct
39
+ </TabItem>
40
+ <TabItem value="✅ Correct">
38
41
 
39
42
  ```ts
40
43
  const arg = 'foo';
@@ -45,6 +48,9 @@ const stringWithKindProp: string & { _kind?: 'MyString' } = 'foo';
45
48
  const msg3 = `stringWithKindProp = ${stringWithKindProp}`;
46
49
  ```
47
50
 
51
+ </TabItem>
52
+ </Tabs>
53
+
48
54
  ## Options
49
55
 
50
56
  ### `allowNumber`
@@ -111,11 +117,20 @@ const arg = 'something';
111
117
  const msg1 = typeof arg === 'string' ? arg : `arg = ${arg}`;
112
118
  ```
113
119
 
120
+ ### `allowArray`
121
+
122
+ Examples of additional **correct** code for this rule with `{ allowArray: true }`:
123
+
124
+ ```ts option='{ "allowArray": true }' showPlaygroundButton
125
+ const arg = ['foo', 'bar'];
126
+ const msg1 = `arg = ${arg}`;
127
+ ```
128
+
114
129
  ## When Not To Use It
115
130
 
116
131
  If you're not worried about incorrectly stringifying non-string values in template literals, then you likely don't need this rule.
117
132
 
118
133
  ## Related To
119
134
 
120
- - [`no-base-to-string`](./no-base-to-string.md)
121
- - [`restrict-plus-operands`](./restrict-plus-operands.md)
135
+ - [`no-base-to-string`](./no-base-to-string.mdx)
136
+ - [`restrict-plus-operands`](./restrict-plus-operands.mdx)
@@ -2,6 +2,9 @@
2
2
  description: 'Enforce consistent returning of awaited values.'
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/return-await** for documentation.
@@ -33,9 +36,8 @@ Specifically:
33
36
 
34
37
  Examples of code with `in-try-catch`:
35
38
 
36
- <!--tabs-->
37
-
38
- #### ❌ Incorrect
39
+ <Tabs>
40
+ <TabItem value="❌ Incorrect">
39
41
 
40
42
  ```ts option='"in-try-catch"'
41
43
  async function invalidInTryCatch1() {
@@ -81,7 +83,8 @@ async function invalidInTryCatch6() {
81
83
  }
82
84
  ```
83
85
 
84
- #### ✅ Correct
86
+ </TabItem>
87
+ <TabItem value="✅ Correct">
85
88
 
86
89
  ```ts option='"in-try-catch"'
87
90
  async function validInTryCatch1() {
@@ -127,15 +130,17 @@ async function validInTryCatch6() {
127
130
  }
128
131
  ```
129
132
 
133
+ </TabItem>
134
+ </Tabs>
135
+
130
136
  ### `always`
131
137
 
132
138
  Requires that all returned promises are `await`ed.
133
139
 
134
140
  Examples of code with `always`:
135
141
 
136
- <!--tabs-->
137
-
138
- #### ❌ Incorrect
142
+ <Tabs>
143
+ <TabItem value="❌ Incorrect">
139
144
 
140
145
  ```ts option='"always"'
141
146
  async function invalidAlways1() {
@@ -153,7 +158,8 @@ async function invalidAlways3() {
153
158
  }
154
159
  ```
155
160
 
156
- #### ✅ Correct
161
+ </TabItem>
162
+ <TabItem value="✅ Correct">
157
163
 
158
164
  ```ts option='"always"'
159
165
  async function validAlways1() {
@@ -171,15 +177,17 @@ async function validAlways3() {
171
177
  }
172
178
  ```
173
179
 
180
+ </TabItem>
181
+ </Tabs>
182
+
174
183
  ### `never`
175
184
 
176
185
  Disallows all `await`ing any returned promises.
177
186
 
178
187
  Examples of code with `never`:
179
188
 
180
- <!--tabs-->
181
-
182
- #### ❌ Incorrect
189
+ <Tabs>
190
+ <TabItem value="❌ Incorrect">
183
191
 
184
192
  ```ts option='"never"'
185
193
  async function invalidNever1() {
@@ -197,7 +205,8 @@ async function invalidNever3() {
197
205
  }
198
206
  ```
199
207
 
200
- #### ✅ Correct
208
+ </TabItem>
209
+ <TabItem value="✅ Correct">
201
210
 
202
211
  ```ts option='"never"'
203
212
  async function validNever1() {
@@ -214,3 +223,6 @@ async function validNever3() {
214
223
  return 'value';
215
224
  }
216
225
  ```
226
+
227
+ </TabItem>
228
+ </Tabs>
@@ -2,6 +2,9 @@
2
2
  description: 'Require or disallow semicolons instead of ASI.'
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/semi** for documentation.
@@ -9,4 +12,4 @@ description: 'Require or disallow semicolons instead of ASI.'
9
12
  This rule extends the base [`eslint/semi`](https://eslint.org/docs/rules/semi) rule.
10
13
  It adds support for TypeScript features that require semicolons.
11
14
 
12
- See also the [`@typescript-eslint/member-delimiter-style`](member-delimiter-style.md) rule, which allows you to specify the delimiter for `type` and `interface` members.
15
+ See also the [`@typescript-eslint/member-delimiter-style`](member-delimiter-style.mdx) rule, which allows you to specify the delimiter for `type` and `interface` members.