@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
@@ -1,339 +0,0 @@
1
- ---
2
- description: 'Enforce consistent awaiting of returned promises.'
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/return-await** for documentation.
11
-
12
- In `async` functions, it is valid to return a promise-wrapped value or a value directly, both of which ultimately produce a promise with the same fulfillment value. Returning a value rather than a promise-wrapped value can have several subtle benefits:
13
-
14
- - Returning an awaited promise [improves stack trace information](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#improving_stack_trace).
15
- - When the `return` statement is in `try...catch`, awaiting the promise allows the promise's rejection to be caught instead of leaving the error to the caller.
16
- - 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).
17
-
18
- This rule enforces consistent handling of whether to await promises before returning them.
19
-
20
- :::info
21
-
22
- This rule used to be considered an extension of the (now-deprecated) ESLint core rule [`no-return-await`](https://eslint.org/docs/latest/rules/no-return-await#options).
23
- Without type information, the only situations that could be flagged by `no-return-await` were of neutral-to-negative value, which eventually led to its deprecation.
24
- In contrast, with access to type information, `@typescript-eslint/return-await` delivers enough positive value to earn it a spot in our strict preset.
25
-
26
- If you previously used `no-return-await`, this rule's `in-try-catch` option has the closest behavior to the `no-return-await` rule.
27
-
28
- :::
29
-
30
- ## Options
31
-
32
- ```ts
33
- type Options =
34
- | 'in-try-catch'
35
- | 'always'
36
- | 'error-handling-correctness-only'
37
- | 'never';
38
-
39
- const defaultOptions: Options = 'in-try-catch';
40
- ```
41
-
42
- The options in this rule distinguish between "ordinary contexts" and "error-handling contexts".
43
- An error-handling context is anywhere where returning an unawaited promise would cause unexpected control flow regarding exceptions/rejections.
44
- See detailed examples in the sections for each option.
45
-
46
- - If you return a promise within a `try` block, it should be awaited in order to trigger subsequent `catch` or `finally` blocks as expected.
47
- - 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.
48
- - 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`.
49
-
50
- Ordinary contexts are anywhere else a promise may be returned.
51
- The choice of whether to await a returned promise in an ordinary context is mostly stylistic.
52
-
53
- With these terms defined, the options may be summarized as follows:
54
-
55
- | Option | Ordinary Context <br/> (stylistic preference 🎨) | Error-Handling Context <br/> (catches bugs 🐛) | Should I use this option? |
56
- | :-------------------------------: | :----------------------------------------------: | :----------------------------------------------------------: | :--------------------------------------------------------: |
57
- | `always` | `return await promise;` | `return await promise;` | ✅ Yes! |
58
- | `in-try-catch` | `return promise;` | `return await promise;` | ✅ Yes! |
59
- | `error-handling-correctness-only` | don't care 🤷 | `return await promise;` | 🟡 Okay to use, but the above options would be preferable. |
60
- | `never` | `return promise;` | `return promise;` <br/> (⚠️ This behavior may be harmful ⚠️) | ❌ No. This option is deprecated. |
61
-
62
- ### `in-try-catch`
63
-
64
- In error-handling contexts, the rule enforces that returned promises must be awaited.
65
- In ordinary contexts, the rule enforces that returned promises _must not_ be awaited.
66
-
67
- This is a good option if you prefer the shorter `return promise` form for stylistic reasons, wherever it's safe to use.
68
-
69
- Examples of code with `in-try-catch`:
70
-
71
- <Tabs>
72
- <TabItem value="❌ Incorrect">
73
-
74
- ```ts option='"in-try-catch"'
75
- async function invalidInTryCatch1() {
76
- try {
77
- return Promise.reject('try');
78
- } catch (e) {
79
- // Doesn't execute due to missing await.
80
- }
81
- }
82
-
83
- async function invalidInTryCatch2() {
84
- try {
85
- throw new Error('error');
86
- } catch (e) {
87
- // Unnecessary await; rejections here don't impact control flow.
88
- return await Promise.reject('catch');
89
- }
90
- }
91
-
92
- // Prints 'starting async work', 'cleanup', 'async work done'.
93
- async function invalidInTryCatch3() {
94
- async function doAsyncWork(): Promise<void> {
95
- console.log('starting async work');
96
- await new Promise(resolve => setTimeout(resolve, 1000));
97
- console.log('async work done');
98
- }
99
-
100
- try {
101
- throw new Error('error');
102
- } catch (e) {
103
- // Missing await.
104
- return doAsyncWork();
105
- } finally {
106
- console.log('cleanup');
107
- }
108
- }
109
-
110
- async function invalidInTryCatch4() {
111
- try {
112
- throw new Error('error');
113
- } catch (e) {
114
- throw new Error('error2');
115
- } finally {
116
- // Unnecessary await; rejections here don't impact control flow.
117
- return await Promise.reject('finally');
118
- }
119
- }
120
-
121
- async function invalidInTryCatch5() {
122
- return await Promise.resolve('try');
123
- }
124
-
125
- async function invalidInTryCatch6() {
126
- return await 'value';
127
- }
128
-
129
- async function invalidInTryCatch7() {
130
- using x = createDisposable();
131
- return Promise.reject('using in scope');
132
- }
133
- ```
134
-
135
- </TabItem>
136
- <TabItem value="✅ Correct">
137
-
138
- ```ts option='"in-try-catch"'
139
- async function validInTryCatch1() {
140
- try {
141
- return await Promise.reject('try');
142
- } catch (e) {
143
- // Executes as expected.
144
- }
145
- }
146
-
147
- async function validInTryCatch2() {
148
- try {
149
- throw new Error('error');
150
- } catch (e) {
151
- return Promise.reject('catch');
152
- }
153
- }
154
-
155
- // Prints 'starting async work', 'async work done', 'cleanup'.
156
- async function validInTryCatch3() {
157
- async function doAsyncWork(): Promise<void> {
158
- console.log('starting async work');
159
- await new Promise(resolve => setTimeout(resolve, 1000));
160
- console.log('async work done');
161
- }
162
-
163
- try {
164
- throw new Error('error');
165
- } catch (e) {
166
- return await doAsyncWork();
167
- } finally {
168
- console.log('cleanup');
169
- }
170
- }
171
-
172
- async function validInTryCatch4() {
173
- try {
174
- throw new Error('error');
175
- } catch (e) {
176
- throw new Error('error2');
177
- } finally {
178
- return Promise.reject('finally');
179
- }
180
- }
181
-
182
- async function validInTryCatch5() {
183
- return Promise.resolve('try');
184
- }
185
-
186
- async function validInTryCatch6() {
187
- return 'value';
188
- }
189
-
190
- async function validInTryCatch7() {
191
- using x = createDisposable();
192
- return await Promise.reject('using in scope');
193
- }
194
- ```
195
-
196
- </TabItem>
197
- </Tabs>
198
-
199
- ### `always`
200
-
201
- {/* insert option description */}
202
-
203
- Requires that all returned promises be awaited.
204
-
205
- 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.
206
-
207
- Examples of code with `always`:
208
-
209
- <Tabs>
210
- <TabItem value="❌ Incorrect">
211
-
212
- ```ts option='"always"'
213
- async function invalidAlways1() {
214
- try {
215
- return Promise.resolve('try');
216
- } catch (e) {}
217
- }
218
-
219
- async function invalidAlways2() {
220
- return Promise.resolve('try');
221
- }
222
-
223
- async function invalidAlways3() {
224
- return await 'value';
225
- }
226
- ```
227
-
228
- </TabItem>
229
- <TabItem value="✅ Correct">
230
-
231
- ```ts option='"always"'
232
- async function validAlways1() {
233
- try {
234
- return await Promise.resolve('try');
235
- } catch (e) {}
236
- }
237
-
238
- async function validAlways2() {
239
- return await Promise.resolve('try');
240
- }
241
-
242
- async function validAlways3() {
243
- return 'value';
244
- }
245
- ```
246
-
247
- </TabItem>
248
- </Tabs>
249
-
250
- ### `error-handling-correctness-only`
251
-
252
- In error-handling contexts, the rule enforces that returned promises must be awaited.
253
- In ordinary contexts, the rule does not enforce any particular behavior around whether returned promises are awaited.
254
-
255
- 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.
256
-
257
- :::info
258
- We recommend you configure either `in-try-catch` or `always` instead of this option.
259
- While the choice of whether to await promises outside of error-handling contexts is mostly stylistic, it's generally best to be consistent.
260
- :::
261
-
262
- Examples of additional correct code with `error-handling-correctness-only`:
263
-
264
- <Tabs>
265
- <TabItem value="✅ Correct">
266
-
267
- ```ts option='"error-handling-correctness-only"'
268
- async function asyncFunction(): Promise<void> {
269
- if (Math.random() < 0.5) {
270
- return await Promise.resolve();
271
- } else {
272
- return Promise.resolve();
273
- }
274
- }
275
- ```
276
-
277
- </TabItem>
278
- </Tabs>
279
-
280
- ### `never`
281
-
282
- {/* insert option description */}
283
-
284
- Disallows awaiting any returned promises.
285
-
286
- :::warning
287
-
288
- This option is deprecated and will be removed in a future major version of typescript-eslint.
289
-
290
- The `never` option introduces undesirable behavior in error-handling contexts.
291
- 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.
292
-
293
- See more details at [typescript-eslint#9433](https://github.com/typescript-eslint/typescript-eslint/issues/9433).
294
- :::
295
-
296
- Examples of code with `never`:
297
-
298
- <Tabs>
299
- <TabItem value="❌ Incorrect">
300
-
301
- ```ts option='"never"'
302
- async function invalidNever1() {
303
- try {
304
- return await Promise.resolve('try');
305
- } catch (e) {}
306
- }
307
-
308
- async function invalidNever2() {
309
- return await Promise.resolve('try');
310
- }
311
-
312
- async function invalidNever3() {
313
- return await 'value';
314
- }
315
- ```
316
-
317
- </TabItem>
318
- <TabItem value="✅ Correct">
319
-
320
- ```ts option='"never"'
321
- async function validNever1() {
322
- try {
323
- return Promise.resolve('try');
324
- } catch (e) {}
325
- }
326
-
327
- async function validNever2() {
328
- return Promise.resolve('try');
329
- }
330
-
331
- async function validNever3() {
332
- return 'value';
333
- }
334
- ```
335
-
336
- </TabItem>
337
- </Tabs>
338
-
339
- {/* Intentionally Omitted: When Not To Use It */}
@@ -1,15 +0,0 @@
1
- ---
2
- displayed_sidebar: rulesSidebar
3
- ---
4
-
5
- :::danger Deprecated
6
-
7
- This rule has been moved to the [ESLint stylistic plugin](https://eslint.style).
8
- See [#8072](https://github.com/typescript-eslint/typescript-eslint/issues/8072) and [#8074](https://github.com/typescript-eslint/typescript-eslint/issues/8074) for more information.
9
-
10
- :::
11
-
12
- <!-- This doc file has been left on purpose to help direct people to the stylistic plugin.
13
-
14
- Note that there is no actual way to get to this page in the normal navigation,
15
- so end-users will only be able to get to this page from the search bar. -->
@@ -1,209 +0,0 @@
1
- ---
2
- description: 'Enforce constituents of a type union/intersection to be sorted alphabetically.'
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/sort-type-constituents** for documentation.
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
-
18
- Sorting union (`|`) and intersection (`&`) types can help:
19
-
20
- - keep your codebase standardized
21
- - find repeated types
22
- - reduce diff churn
23
-
24
- This rule reports on any types that aren't sorted alphabetically.
25
-
26
- > Types are sorted case-insensitively and treating numbers like a human would, falling back to character code sorting in case of ties.
27
-
28
- ## Examples
29
-
30
- <Tabs>
31
- <TabItem value="❌ Incorrect">
32
-
33
- ```ts
34
- type T1 = B | A;
35
-
36
- type T2 = { b: string } & { a: string };
37
-
38
- type T3 = [1, 2, 4] & [1, 2, 3];
39
-
40
- type T4 =
41
- | [1, 2, 4]
42
- | [1, 2, 3]
43
- | { b: string }
44
- | { a: string }
45
- | (() => void)
46
- | (() => string)
47
- | 'b'
48
- | 'a'
49
- | 'b'
50
- | 'a'
51
- | readonly string[]
52
- | readonly number[]
53
- | string[]
54
- | number[]
55
- | B
56
- | A
57
- | string
58
- | any;
59
- ```
60
-
61
- </TabItem>
62
- <TabItem value="✅ Correct">
63
-
64
- ```ts
65
- type T1 = A | B;
66
-
67
- type T2 = { a: string } & { b: string };
68
-
69
- type T3 = [1, 2, 3] & [1, 2, 4];
70
-
71
- type T4 =
72
- | A
73
- | B
74
- | number[]
75
- | string[]
76
- | any
77
- | string
78
- | readonly number[]
79
- | readonly string[]
80
- | 'a'
81
- | 'a'
82
- | 'b'
83
- | 'b'
84
- | (() => string)
85
- | (() => void)
86
- | { a: string }
87
- | { b: string }
88
- | [1, 2, 3]
89
- | [1, 2, 4];
90
- ```
91
-
92
- </TabItem>
93
- </Tabs>
94
-
95
- ## Options
96
-
97
- ### `caseSensitive`
98
-
99
- {/* insert option description */}
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
-
120
- ### `checkIntersections`
121
-
122
- {/* insert option description */}
123
-
124
- Examples of code with `{ "checkIntersections": true }` (the default):
125
-
126
- <Tabs>
127
- <TabItem value="❌ Incorrect">
128
-
129
- ```ts option='{ "checkIntersections": true }'
130
- type ExampleIntersection = B & A;
131
- ```
132
-
133
- </TabItem>
134
- <TabItem value="✅ Correct">
135
-
136
- ```ts option='{ "checkIntersections": true }'
137
- type ExampleIntersection = A & B;
138
- ```
139
-
140
- </TabItem>
141
- </Tabs>
142
-
143
- ### `checkUnions`
144
-
145
- {/* insert option description */}
146
-
147
- Examples of code with `{ "checkUnions": true }` (the default):
148
-
149
- <Tabs>
150
- <TabItem value="❌ Incorrect">
151
-
152
- ```ts option='{ "checkUnions": true }'
153
- type ExampleUnion = B | A;
154
- ```
155
-
156
- </TabItem>
157
- <TabItem value="✅ Correct">
158
-
159
- ```ts option='{ "checkUnions": true }'
160
- type ExampleUnion = A | B;
161
- ```
162
-
163
- </TabItem>
164
- </Tabs>
165
-
166
- ### `groupOrder`
167
-
168
- {/* insert option description */}
169
-
170
- Each constituent of the type is placed into a group, and then the rule sorts alphabetically within each group.
171
- The ordering of groups is determined by this option.
172
-
173
- - `conditional` - Conditional types (`A extends B ? C : D`)
174
- - `function` - Function and constructor types (`() => void`, `new () => type`)
175
- - `import` - Import types (`import('path')`)
176
- - `intersection` - Intersection types (`A & B`)
177
- - `keyword` - Keyword types (`any`, `string`, etc)
178
- - `literal` - Literal types (`1`, `'b'`, `true`, etc)
179
- - `named` - Named types (`A`, `A['prop']`, `B[]`, `Array<C>`)
180
- - `object` - Object types (`{ a: string }`, `{ [key: string]: number }`)
181
- - `operator` - Operator types (`keyof A`, `typeof B`, `readonly C[]`)
182
- - `tuple` - Tuple types (`[A, B, C]`)
183
- - `union` - Union types (`A | B`)
184
- - `nullish` - `null` and `undefined`
185
-
186
- For example, configuring the rule with `{ "groupOrder": ["literal", "nullish" ]}`:
187
-
188
- <Tabs>
189
- <TabItem value="❌ Incorrect">
190
-
191
- ```ts option='{ "groupOrder": ["literal", "nullish" ]}'
192
- type ExampleGroup = null | 123;
193
- ```
194
-
195
- </TabItem>
196
- <TabItem value="✅ Correct">
197
-
198
- ```ts option='{ "groupOrder": ["literal", "nullish" ]}'
199
- type ExampleGroup = 123 | null;
200
- ```
201
-
202
- </TabItem>
203
- </Tabs>
204
-
205
- ## When Not To Use It
206
-
207
- This rule is purely a stylistic rule for maintaining consistency in your project.
208
- You can turn it off if you don't want to keep a consistent, predictable order for intersection and union types.
209
- However, keep in mind that inconsistent style can harm readability in a project.
@@ -1,16 +0,0 @@
1
- ---
2
- displayed_sidebar: rulesSidebar
3
- ---
4
-
5
- :::danger Deprecated
6
-
7
- This rule has been renamed to [`sort-type-constituents`](https://typescript-eslint.io/rules/sort-type-constituents).
8
-
9
- :::
10
-
11
- <!--
12
- This doc file has been left on purpose to help direct people to the replacement rule.
13
-
14
- Note that there is no actual way to get to this page in the normal navigation,
15
- so end-users will only be able to get to this page from the search bar.
16
- -->
@@ -1,15 +0,0 @@
1
- ---
2
- displayed_sidebar: rulesSidebar
3
- ---
4
-
5
- :::danger Deprecated
6
-
7
- This rule has been moved to the [ESLint stylistic plugin](https://eslint.style).
8
- See [#8072](https://github.com/typescript-eslint/typescript-eslint/issues/8072) and [#8074](https://github.com/typescript-eslint/typescript-eslint/issues/8074) for more information.
9
-
10
- :::
11
-
12
- <!-- This doc file has been left on purpose to help direct people to the stylistic plugin.
13
-
14
- Note that there is no actual way to get to this page in the normal navigation,
15
- so end-users will only be able to get to this page from the search bar. -->
@@ -1,15 +0,0 @@
1
- ---
2
- displayed_sidebar: rulesSidebar
3
- ---
4
-
5
- :::danger Deprecated
6
-
7
- This rule has been moved to the [ESLint stylistic plugin](https://eslint.style).
8
- See [#8072](https://github.com/typescript-eslint/typescript-eslint/issues/8072) and [#8074](https://github.com/typescript-eslint/typescript-eslint/issues/8074) for more information.
9
-
10
- :::
11
-
12
- <!-- This doc file has been left on purpose to help direct people to the stylistic plugin.
13
-
14
- Note that there is no actual way to get to this page in the normal navigation,
15
- so end-users will only be able to get to this page from the search bar. -->
@@ -1,15 +0,0 @@
1
- ---
2
- displayed_sidebar: rulesSidebar
3
- ---
4
-
5
- :::danger Deprecated
6
-
7
- This rule has been moved to the [ESLint stylistic plugin](https://eslint.style).
8
- See [#8072](https://github.com/typescript-eslint/typescript-eslint/issues/8072) and [#8074](https://github.com/typescript-eslint/typescript-eslint/issues/8074) for more information.
9
-
10
- :::
11
-
12
- <!-- This doc file has been left on purpose to help direct people to the stylistic plugin.
13
-
14
- Note that there is no actual way to get to this page in the normal navigation,
15
- so end-users will only be able to get to this page from the search bar. -->