@typescript-eslint/eslint-plugin 8.0.0-alpha.3 → 8.0.0-alpha.30

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 (144) hide show
  1. package/dist/configs/all.js +2 -5
  2. package/dist/configs/all.js.map +1 -1
  3. package/dist/configs/disable-type-checked.js +1 -2
  4. package/dist/configs/disable-type-checked.js.map +1 -1
  5. package/dist/configs/recommended-type-checked-only.js +6 -0
  6. package/dist/configs/recommended-type-checked-only.js.map +1 -1
  7. package/dist/configs/recommended-type-checked.js +11 -1
  8. package/dist/configs/recommended-type-checked.js.map +1 -1
  9. package/dist/configs/recommended.js +5 -1
  10. package/dist/configs/recommended.js.map +1 -1
  11. package/dist/configs/strict-type-checked-only.js +2 -2
  12. package/dist/configs/strict-type-checked-only.js.map +1 -1
  13. package/dist/configs/strict-type-checked.js +7 -4
  14. package/dist/configs/strict-type-checked.js.map +1 -1
  15. package/dist/configs/strict.js +5 -2
  16. package/dist/configs/strict.js.map +1 -1
  17. package/dist/configs/stylistic-type-checked-only.js +3 -0
  18. package/dist/configs/stylistic-type-checked-only.js.map +1 -1
  19. package/dist/configs/stylistic-type-checked.js +3 -2
  20. package/dist/configs/stylistic-type-checked.js.map +1 -1
  21. package/dist/configs/stylistic.js +0 -2
  22. package/dist/configs/stylistic.js.map +1 -1
  23. package/dist/rules/ban-types.js +4 -25
  24. package/dist/rules/ban-types.js.map +1 -1
  25. package/dist/rules/consistent-type-assertions.js +3 -5
  26. package/dist/rules/consistent-type-assertions.js.map +1 -1
  27. package/dist/rules/dot-notation.js +8 -1
  28. package/dist/rules/dot-notation.js.map +1 -1
  29. package/dist/rules/explicit-member-accessibility.js +98 -36
  30. package/dist/rules/explicit-member-accessibility.js.map +1 -1
  31. package/dist/rules/index.js +4 -4
  32. package/dist/rules/index.js.map +1 -1
  33. package/dist/rules/init-declarations.js +57 -1
  34. package/dist/rules/init-declarations.js.map +1 -1
  35. package/dist/rules/member-ordering.js +1 -2
  36. package/dist/rules/member-ordering.js.map +1 -1
  37. package/dist/rules/naming-convention-utils/parse-options.js +1 -3
  38. package/dist/rules/naming-convention-utils/parse-options.js.map +1 -1
  39. package/dist/rules/no-array-delete.js +1 -1
  40. package/dist/rules/no-array-delete.js.map +1 -1
  41. package/dist/rules/no-base-to-string.js +1 -1
  42. package/dist/rules/no-base-to-string.js.map +1 -1
  43. package/dist/rules/no-duplicate-type-constituents.js +1 -1
  44. package/dist/rules/no-duplicate-type-constituents.js.map +1 -1
  45. package/dist/rules/no-empty-interface.js +2 -1
  46. package/dist/rules/no-empty-interface.js.map +1 -1
  47. package/dist/rules/no-empty-object-type.js +141 -0
  48. package/dist/rules/no-empty-object-type.js.map +1 -0
  49. package/dist/rules/no-floating-promises.js +62 -39
  50. package/dist/rules/no-floating-promises.js.map +1 -1
  51. package/dist/rules/no-implied-eval.js.map +1 -1
  52. package/dist/rules/no-require-imports.js +13 -3
  53. package/dist/rules/no-require-imports.js.map +1 -1
  54. package/dist/rules/no-restricted-imports.js +3 -6
  55. package/dist/rules/no-restricted-imports.js.map +1 -1
  56. package/dist/rules/{no-useless-template-literals.js → no-unnecessary-template-expression.js} +6 -6
  57. package/dist/rules/no-unnecessary-template-expression.js.map +1 -0
  58. package/dist/rules/no-unnecessary-type-assertion.js +15 -13
  59. package/dist/rules/no-unnecessary-type-assertion.js.map +1 -1
  60. package/dist/rules/no-unsafe-argument.js +4 -2
  61. package/dist/rules/no-unsafe-argument.js.map +1 -1
  62. package/dist/rules/no-unsafe-assignment.js +24 -9
  63. package/dist/rules/no-unsafe-assignment.js.map +1 -1
  64. package/dist/rules/no-unsafe-return.js +1 -1
  65. package/dist/rules/no-unsafe-return.js.map +1 -1
  66. package/dist/rules/no-unsafe-unary-minus.js +1 -0
  67. package/dist/rules/no-unsafe-unary-minus.js.map +1 -1
  68. package/dist/rules/no-unused-expressions.js +1 -0
  69. package/dist/rules/no-unused-expressions.js.map +1 -1
  70. package/dist/rules/no-unused-vars.js +13 -3
  71. package/dist/rules/no-unused-vars.js.map +1 -1
  72. package/dist/rules/no-var-requires.js +2 -1
  73. package/dist/rules/no-var-requires.js.map +1 -1
  74. package/dist/rules/only-throw-error.js +1 -1
  75. package/dist/rules/only-throw-error.js.map +1 -1
  76. package/dist/rules/prefer-find.js +1 -0
  77. package/dist/rules/prefer-find.js.map +1 -1
  78. package/dist/rules/prefer-includes.js +1 -1
  79. package/dist/rules/prefer-includes.js.map +1 -1
  80. package/dist/rules/prefer-literal-enum-member.js +43 -2
  81. package/dist/rules/prefer-literal-enum-member.js.map +1 -1
  82. package/dist/rules/prefer-namespace-keyword.js +1 -1
  83. package/dist/rules/prefer-namespace-keyword.js.map +1 -1
  84. package/dist/rules/prefer-promise-reject-errors.js +1 -1
  85. package/dist/rules/prefer-promise-reject-errors.js.map +1 -1
  86. package/dist/rules/prefer-readonly.js +8 -5
  87. package/dist/rules/prefer-readonly.js.map +1 -1
  88. package/dist/rules/prefer-regexp-exec.js +15 -6
  89. package/dist/rules/prefer-regexp-exec.js.map +1 -1
  90. package/dist/rules/prefer-ts-expect-error.js +2 -1
  91. package/dist/rules/prefer-ts-expect-error.js.map +1 -1
  92. package/dist/rules/require-await.js +1 -1
  93. package/dist/rules/require-await.js.map +1 -1
  94. package/dist/rules/return-await.js +86 -55
  95. package/dist/rules/return-await.js.map +1 -1
  96. package/dist/rules/sort-type-constituents.js +23 -1
  97. package/dist/rules/sort-type-constituents.js.map +1 -1
  98. package/dist/rules/strict-boolean-expressions.js +1 -3
  99. package/dist/rules/strict-boolean-expressions.js.map +1 -1
  100. package/dist/rules/switch-exhaustiveness-check.js +7 -9
  101. package/dist/rules/switch-exhaustiveness-check.js.map +1 -1
  102. package/dist/rules/unified-signatures.js +3 -1
  103. package/dist/rules/unified-signatures.js.map +1 -1
  104. package/dist/util/collectUnusedVariables.js +22 -35
  105. package/dist/util/collectUnusedVariables.js.map +1 -1
  106. package/dist/util/createRule.js.map +1 -1
  107. package/dist/util/explicitReturnTypeUtils.js +5 -0
  108. package/dist/util/explicitReturnTypeUtils.js.map +1 -1
  109. package/dist/util/getFunctionHeadLoc.js.map +1 -1
  110. package/dist/util/getOperatorPrecedence.js +1 -1
  111. package/dist/util/getOperatorPrecedence.js.map +1 -1
  112. package/docs/rules/ban-types.mdx +5 -10
  113. package/docs/rules/consistent-type-imports.mdx +1 -1
  114. package/docs/rules/naming-convention.mdx +16 -0
  115. package/docs/rules/no-base-to-string.mdx +1 -1
  116. package/docs/rules/no-duplicate-imports.mdx +1 -1
  117. package/docs/rules/no-dynamic-delete.mdx +6 -2
  118. package/docs/rules/no-empty-interface.mdx +10 -0
  119. package/docs/rules/no-empty-object-type.mdx +145 -0
  120. package/docs/rules/no-floating-promises.mdx +103 -4
  121. package/docs/rules/no-import-type-side-effects.mdx +1 -1
  122. package/docs/rules/no-misused-promises.mdx +18 -20
  123. package/docs/rules/no-require-imports.mdx +28 -1
  124. package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +12 -12
  125. package/docs/rules/no-unnecessary-template-expression.mdx +85 -0
  126. package/docs/rules/no-unused-expressions.mdx +41 -1
  127. package/docs/rules/no-unused-vars.mdx +5 -0
  128. package/docs/rules/no-useless-template-literals.mdx +3 -59
  129. package/docs/rules/no-var-requires.mdx +6 -0
  130. package/docs/rules/only-throw-error.mdx +7 -0
  131. package/docs/rules/prefer-readonly-parameter-types.mdx +10 -4
  132. package/docs/rules/prefer-ts-expect-error.mdx +10 -0
  133. package/docs/rules/require-await.mdx +2 -2
  134. package/docs/rules/restrict-template-expressions.mdx +1 -1
  135. package/docs/rules/return-await.mdx +39 -16
  136. package/docs/rules/sort-type-constituents.mdx +29 -9
  137. package/docs/rules/sort-type-union-intersection-members.mdx +12 -0
  138. package/docs/rules/unbound-method.mdx +3 -2
  139. package/package.json +14 -17
  140. package/rules.d.ts +6 -2
  141. package/dist/rules/no-throw-literal.js +0 -97
  142. package/dist/rules/no-throw-literal.js.map +0 -1
  143. package/dist/rules/no-useless-template-literals.js.map +0 -1
  144. package/docs/rules/no-throw-literal.mdx +0 -25
@@ -114,11 +114,11 @@ if (someNullCondition !== false) {
114
114
 
115
115
  ```ts option='{ "allowComparingNullableBooleansToFalse": false }'
116
116
  declare const someUndefinedCondition: boolean | undefined;
117
- if (someUndefinedCondition ?? true) {
117
+ if (!(someUndefinedCondition ?? true)) {
118
118
  }
119
119
 
120
120
  declare const someNullCondition: boolean | null;
121
- if (!(someNullCondition ?? true)) {
121
+ if (someNullCondition ?? true) {
122
122
  }
123
123
  ```
124
124
 
@@ -127,16 +127,16 @@ if (!(someNullCondition ?? true)) {
127
127
 
128
128
  ## Fixer
129
129
 
130
- | Comparison | Fixer Output | Notes |
131
- | :-------------------------------: | ------------------------------- | ----------------------------------------------------------------------------------- |
132
- | `booleanVar === true` | `booleanVar` | |
133
- | `booleanVar !== true` | `!booleanVar` | |
134
- | `booleanVar === false` | `!booleanVar` | |
135
- | `booleanVar !== false` | `booleanVar` | |
136
- | `nullableBooleanVar === true` | `nullableBooleanVar` | Only checked/fixed if the `allowComparingNullableBooleansToTrue` option is `false` |
137
- | `nullableBooleanVar !== true` | `!nullableBooleanVar` | Only checked/fixed if the `allowComparingNullableBooleansToTrue` option is `false` |
138
- | `!(nullableBooleanVar === false)` | `nullableBooleanVar ?? true` | Only checked/fixed if the `allowComparingNullableBooleansToFalse` option is `false` |
139
- | `!(nullableBooleanVar !== false)` | `!(nullableBooleanVar ?? true)` | Only checked/fixed if the `allowComparingNullableBooleansToFalse` option is `false` |
130
+ | Comparison | Fixer Output | Notes |
131
+ | :----------------------------: | ------------------------------- | ----------------------------------------------------------------------------------- |
132
+ | `booleanVar === true` | `booleanVar` | |
133
+ | `booleanVar !== true` | `!booleanVar` | |
134
+ | `booleanVar === false` | `!booleanVar` | |
135
+ | `booleanVar !== false` | `booleanVar` | |
136
+ | `nullableBooleanVar === true` | `nullableBooleanVar` | Only checked/fixed if the `allowComparingNullableBooleansToTrue` option is `false` |
137
+ | `nullableBooleanVar !== true` | `!nullableBooleanVar` | Only checked/fixed if the `allowComparingNullableBooleansToTrue` option is `false` |
138
+ | `nullableBooleanVar === false` | `!(nullableBooleanVar ?? true)` | Only checked/fixed if the `allowComparingNullableBooleansToFalse` option is `false` |
139
+ | `nullableBooleanVar !== false` | `nullableBooleanVar ?? true` | Only checked/fixed if the `allowComparingNullableBooleansToFalse` option is `false` |
140
140
 
141
141
  ## When Not To Use It
142
142
 
@@ -0,0 +1,85 @@
1
+ ---
2
+ description: 'Disallow unnecessary template expressions.'
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/no-unnecessary-template-expression** for documentation.
11
+
12
+ This rule reports template literals that contain substitution expressions (also variously referred to as embedded expressions or string interpolations) that are unnecessary and can be simplified.
13
+
14
+ :::info[Migration from `no-useless-template-literals`]
15
+
16
+ This rule was formerly known as [`no-useless-template-literals`](./no-useless-template-literals.mdx).
17
+ The new name is a drop-in replacement with identical functionality.
18
+
19
+ :::
20
+
21
+ ## Examples
22
+
23
+ <Tabs>
24
+ <TabItem value="❌ Incorrect">
25
+
26
+ ```ts
27
+ // Static values can be incorporated into the surrounding template.
28
+
29
+ const ab1 = `${'a'}${'b'}`;
30
+ const ab2 = `a${'b'}`;
31
+
32
+ const stringWithNumber = `${'1 + 1 = '}${2}`;
33
+
34
+ const stringWithBoolean = `${'true is '}${true}`;
35
+
36
+ // Some simple expressions that are already strings
37
+ // can be rewritten without a template at all.
38
+
39
+ const text = 'a';
40
+ const wrappedText = `${text}`;
41
+
42
+ declare const intersectionWithString: string & { _brand: 'test-brand' };
43
+ const wrappedIntersection = `${intersectionWithString}`;
44
+ ```
45
+
46
+ </TabItem>
47
+ <TabItem value="✅ Correct">
48
+
49
+ ```ts
50
+ // Static values can be incorporated into the surrounding template.
51
+
52
+ const ab1 = `ab`;
53
+ const ab2 = `ab`;
54
+
55
+ const stringWithNumber = `1 + 1 = 2`;
56
+
57
+ const stringWithBoolean = `true is true`;
58
+
59
+ // Some simple expressions that are already strings
60
+ // can be rewritten without a template at all.
61
+
62
+ const text = 'a';
63
+ const wrappedText = text;
64
+
65
+ declare const intersectionWithString: string & { _brand: 'test-brand' };
66
+ const wrappedIntersection = intersectionWithString;
67
+ ```
68
+
69
+ </TabItem>
70
+ </Tabs>
71
+
72
+ :::info
73
+ This rule does not aim to flag template literals without substitution expressions that could have been written as an ordinary string.
74
+ That is to say, this rule will not help you turn `` `this` `` into `"this"`.
75
+ If you are looking for such a rule, you can configure the [`@stylistic/ts/quotes`](https://eslint.style/rules/ts/quotes) rule to do this.
76
+ :::
77
+
78
+ ## When Not To Use It
79
+
80
+ When you want to allow string expressions inside template literals.
81
+
82
+ ## Related To
83
+
84
+ - [`restrict-template-expressions`](./restrict-template-expressions.mdx)
85
+ - [`@stylistic/ts/quotes`](https://eslint.style/rules/ts/quotes)
@@ -10,4 +10,44 @@ import TabItem from '@theme/TabItem';
10
10
  > See **https://typescript-eslint.io/rules/no-unused-expressions** for documentation.
11
11
 
12
12
  This rule extends the base [`eslint/no-unused-expressions`](https://eslint.org/docs/rules/no-unused-expressions) rule.
13
- It adds support for optional call expressions `x?.()`, and directive in module declarations.
13
+ It supports TypeScript-specific expressions:
14
+
15
+ - Marks directives in modules declarations (`"use strict"`, etc.) as not unused
16
+ - Marks the following expressions as unused if their wrapped value expressions are unused:
17
+ - Assertion expressions: `x as number;`, `x!;`, `<number>x;`
18
+ - Instantiation expressions: `Set<number>;`
19
+
20
+ Although the type expressions never have runtime side effects (that is, `x!;` is the same as `x;`), they can be used to assert types for testing purposes.
21
+
22
+ ## Examples
23
+
24
+ <Tabs>
25
+ <TabItem value="❌ Incorrect">
26
+
27
+ ```ts
28
+ Set<number>;
29
+ 1 as number;
30
+ window!;
31
+ ```
32
+
33
+ </TabItem>
34
+ <TabItem value="✅ Correct">
35
+
36
+ ```ts
37
+ function getSet() {
38
+ return Set;
39
+ }
40
+
41
+ // Funtion calls are allowed, so type expressions that wrap function calls are allowed
42
+ getSet()<number>;
43
+ getSet() as Set<unknown>;
44
+ getSet()!;
45
+
46
+ // Namespaces can have directives
47
+ namespace A {
48
+ 'use strict';
49
+ }
50
+ ```
51
+
52
+ </TabItem>
53
+ </Tabs>
@@ -47,3 +47,8 @@ We generally recommend using `@typescript-eslint/no-unused-vars` to flag unused
47
47
  :::tip
48
48
  Editors such as VS Code will still generally "grey out" unused variables even if `noUnusedLocals` and `noUnusedParameters` are not enabled in a project.
49
49
  :::
50
+
51
+ Also see similar rules provided by ESLint:
52
+
53
+ - [`no-unused-private-class-members`](https://eslint.org/docs/latest/rules/no-unused-private-class-members)
54
+ - [`no-unused-labels`](https://eslint.org/docs/latest/rules/no-unused-labels)
@@ -1,61 +1,5 @@
1
- ---
2
- description: 'Disallow unnecessary template literals.'
3
- ---
1
+ :::danger Deprecated
4
2
 
5
- import Tabs from '@theme/Tabs';
6
- import TabItem from '@theme/TabItem';
3
+ This rule has been renamed to [`no-unnecessary-template-expression`](./no-unnecessary-template-expression.mdx). See [#8544](https://github.com/typescript-eslint/typescript-eslint/issues/8544) for more information.
7
4
 
8
- > 🛑 This file is source code, not the primary documentation location! 🛑
9
- >
10
- > See **https://typescript-eslint.io/rules/no-useless-template-literals** for documentation.
11
-
12
- This rule reports template literals that can be simplified to a normal string literal.
13
-
14
- ## Examples
15
-
16
- <Tabs>
17
- <TabItem value="❌ Incorrect">
18
-
19
- ```ts
20
- const ab1 = `${'a'}${'b'}`;
21
- const ab2 = `a${'b'}`;
22
-
23
- const stringWithNumber = `${'1 + 1 = '}${2}`;
24
-
25
- const stringWithBoolean = `${'true is '}${true}`;
26
-
27
- const text = 'a';
28
- const wrappedText = `${text}`;
29
-
30
- declare const intersectionWithString: string & { _brand: 'test-brand' };
31
- const wrappedIntersection = `${intersectionWithString}`;
32
- ```
33
-
34
- </TabItem>
35
- <TabItem value="✅ Correct">
36
-
37
- ```ts
38
- const ab1 = 'ab';
39
- const ab2 = 'ab';
40
-
41
- const stringWithNumber = `1 + 1 = 2`;
42
-
43
- const stringWithBoolean = `true is true`;
44
-
45
- const text = 'a';
46
- const wrappedText = text;
47
-
48
- declare const intersectionWithString: string & { _brand: 'test-brand' };
49
- const wrappedIntersection = intersectionWithString;
50
- ```
51
-
52
- </TabItem>
53
- </Tabs>
54
-
55
- ## When Not To Use It
56
-
57
- When you want to allow string expressions inside template literals.
58
-
59
- ## Related To
60
-
61
- - [`restrict-template-expressions`](./restrict-template-expressions.mdx)
5
+ :::
@@ -9,6 +9,12 @@ import TabItem from '@theme/TabItem';
9
9
  >
10
10
  > See **https://typescript-eslint.io/rules/no-var-requires** for documentation.
11
11
 
12
+ :::danger Deprecated
13
+
14
+ This rule has been deprecated in favour of the [`@typescript-eslint/no-require-imports`](./no-require-imports.mdx) rule.
15
+
16
+ :::
17
+
12
18
  In other words, the use of forms such as `var foo = require("foo")` are banned. Instead use ES6 style imports or `import foo = require("foo")` imports.
13
19
 
14
20
  ## Examples
@@ -14,6 +14,13 @@ The fundamental benefit of `Error` objects is that they automatically keep track
14
14
 
15
15
  This rule restricts what can be thrown as an exception.
16
16
 
17
+ :::info[Migration from `no-throw-literal`]
18
+
19
+ This rule was formerly known as `no-throw-literal`.
20
+ The new name is a drop-in replacement with identical functionality.
21
+
22
+ :::
23
+
17
24
  ## Examples
18
25
 
19
26
  This rule is aimed at maintaining consistency when throwing exception by disallowing to throw literals and other expressions which cannot possibly be an `Error` object.
@@ -142,11 +142,12 @@ interface Foo {
142
142
 
143
143
  Some complex types cannot easily be made readonly, for example the `HTMLElement` type or the `JQueryStatic` type from `@types/jquery`. This option allows you to globally disable reporting of such types.
144
144
 
145
- Each item must be one of:
145
+ This option takes an array of type specifiers to ignore.
146
+ Each item in the array must have one of the following forms:
146
147
 
147
- - A type defined in a file (`{from: "file", name: "Foo", path: "src/foo-file.ts"}` with `path` being an optional path relative to the project root directory)
148
- - A type from the default library (`{from: "lib", name: "Foo"}`)
149
- - A type from a package (`{from: "package", name: "Foo", package: "foo-lib"}`, this also works for types defined in a typings package).
148
+ - A type defined in a file (`{ from: "file", name: "Foo", path: "src/foo-file.ts" }` with `path` being an optional path relative to the project root directory)
149
+ - A type from the default library (`{ from: "lib", name: "Foo" }`)
150
+ - A type from a package (`{ from: "package", name: "Foo", package: "foo-lib" }`, this also works for types defined in a typings package).
150
151
 
151
152
  Additionally, a type may be defined just as a simple string, which then matches the type independently of its origin.
152
153
 
@@ -401,3 +402,8 @@ function foo(arg: MyType) {}
401
402
  ## When Not To Use It
402
403
 
403
404
  If your project does not attempt to enforce strong immutability guarantees of parameters, you can avoid this rule.
405
+
406
+ This rule is very strict on what it considers mutable.
407
+ Many types that describe themselves as readonly are considered mutable because they have mutable properties such as arrays or tuples.
408
+ To work around these limitations, you might need to use the rule's options.
409
+ In particular, the [`allow` option](#allow) can explicitly mark a type as readonly.
@@ -9,6 +9,16 @@ import TabItem from '@theme/TabItem';
9
9
  >
10
10
  > See **https://typescript-eslint.io/rules/prefer-ts-expect-error** for documentation.
11
11
 
12
+ :::danger Deprecated
13
+
14
+ This rule has been deprecated in favor of [`@typescript-eslint/ban-ts-comment`](./ban-ts-comment.mdx).
15
+ This rule (`@typescript-eslint/prefer-ts-expect-error`) will be removed in a future major version of typescript-eslint.
16
+
17
+ When it was first created, `@typescript-eslint/ban-ts-comment` rule was only responsible for suggesting to remove `@ts-ignore` directive.
18
+ It was later updated to suggest replacing `@ts-ignore` with `@ts-expect-error` directive, so that it replaces `@typescript-eslint/prefer-ts-expect-error` entirely.
19
+
20
+ :::
21
+
12
22
  TypeScript allows you to suppress all errors on a line by placing a comment starting with `@ts-ignore` or `@ts-expect-error` immediately before the erroring line.
13
23
  The two directives work the same, except `@ts-expect-error` causes a type error if placed before a line that's not erroring in the first place.
14
24
 
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: 'Disallow async functions which have no `await` expression.'
2
+ description: 'Disallow async functions which do not return promises and have no `await` expression.'
3
3
  ---
4
4
 
5
5
  import Tabs from '@theme/Tabs';
@@ -10,7 +10,7 @@ import TabItem from '@theme/TabItem';
10
10
  > See **https://typescript-eslint.io/rules/require-await** for documentation.
11
11
 
12
12
  This rule extends the base [`eslint/require-await`](https://eslint.org/docs/rules/require-await) rule.
13
- It uses type information to add support for `async` functions that return a `Promise`.
13
+ It uses type information to allow promise-returning functions to be marked as `async` without containing an `await` expression.
14
14
 
15
15
  ## Examples
16
16
 
@@ -10,7 +10,7 @@ import TabItem from '@theme/TabItem';
10
10
  > See **https://typescript-eslint.io/rules/restrict-template-expressions** for documentation.
11
11
 
12
12
  JavaScript automatically [converts an object to a string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#string_coercion) in a string context, such as when concatenating it with a string using `+` or embedding it in a template literal using `${}`.
13
- The default `toString()` method of objects returns `"[object Object]"`, which is often not what was intended.
13
+ The default `toString()` method of objects uses the format `"[object Object]"`, which is often not what was intended.
14
14
  This rule reports on values used in a template literal string that aren't strings, optionally allowing other data types that provide useful stringification results.
15
15
 
16
16
  :::note
@@ -26,13 +26,15 @@ const defaultOptions: Options = 'in-try-catch';
26
26
 
27
27
  ### `in-try-catch`
28
28
 
29
- Requires that a returned promise must be `await`ed in `try-catch-finally` blocks, and disallows it elsewhere.
30
- Specifically:
29
+ In cases where returning an unawaited promise would cause unexpected error-handling control flow, the rule enforces that `await` must be used.
30
+ Otherwise, the rule enforces that `await` must _not_ be used.
31
31
 
32
- - if you `return` a promise within a `try`, then it must be `await`ed.
33
- - if you `return` a promise within a `catch`, and there **_is no_** `finally`, then it **_must not_** be `await`ed.
34
- - if you `return` a promise within a `catch`, and there **_is a_** `finally`, then it **_must_** be `await`ed.
35
- - if you `return` a promise within a `finally`, then it **_must not_** be `await`ed.
32
+ Listing the error-handling cases exhaustively:
33
+
34
+ - if you `return` a promise within a `try`, then it must be `await`ed, since it will always be followed by a `catch` or `finally`.
35
+ - if you `return` a promise within a `catch`, and there is _no_ `finally`, then it must _not_ be `await`ed.
36
+ - if you `return` a promise within a `catch`, and there _is_ a `finally`, then it _must_ be `await`ed.
37
+ - if you `return` a promise within a `finally`, then it must not be `await`ed.
36
38
 
37
39
  Examples of code with `in-try-catch`:
38
40
 
@@ -42,23 +44,34 @@ Examples of code with `in-try-catch`:
42
44
  ```ts option='"in-try-catch"'
43
45
  async function invalidInTryCatch1() {
44
46
  try {
45
- return Promise.resolve('try');
46
- } catch (e) {}
47
+ return Promise.reject('try');
48
+ } catch (e) {
49
+ // Doesn't execute due to missing await.
50
+ }
47
51
  }
48
52
 
49
53
  async function invalidInTryCatch2() {
50
54
  try {
51
55
  throw new Error('error');
52
56
  } catch (e) {
53
- return await Promise.resolve('catch');
57
+ // Unnecessary await; rejections here don't impact control flow.
58
+ return await Promise.reject('catch');
54
59
  }
55
60
  }
56
61
 
62
+ // Prints 'starting async work', 'cleanup', 'async work done'.
57
63
  async function invalidInTryCatch3() {
64
+ async function doAsyncWork(): Promise<void> {
65
+ console.log('starting async work');
66
+ await new Promise(resolve => setTimeout(resolve, 1000));
67
+ console.log('async work done');
68
+ }
69
+
58
70
  try {
59
71
  throw new Error('error');
60
72
  } catch (e) {
61
- return Promise.resolve('catch');
73
+ // Missing await.
74
+ return doAsyncWork();
62
75
  } finally {
63
76
  console.log('cleanup');
64
77
  }
@@ -70,7 +83,8 @@ async function invalidInTryCatch4() {
70
83
  } catch (e) {
71
84
  throw new Error('error2');
72
85
  } finally {
73
- return await Promise.resolve('finally');
86
+ // Unnecessary await; rejections here don't impact control flow.
87
+ return await Promise.reject('finally');
74
88
  }
75
89
  }
76
90
 
@@ -89,23 +103,32 @@ async function invalidInTryCatch6() {
89
103
  ```ts option='"in-try-catch"'
90
104
  async function validInTryCatch1() {
91
105
  try {
92
- return await Promise.resolve('try');
93
- } catch (e) {}
106
+ return await Promise.reject('try');
107
+ } catch (e) {
108
+ // Executes as expected.
109
+ }
94
110
  }
95
111
 
96
112
  async function validInTryCatch2() {
97
113
  try {
98
114
  throw new Error('error');
99
115
  } catch (e) {
100
- return Promise.resolve('catch');
116
+ return Promise.reject('catch');
101
117
  }
102
118
  }
103
119
 
120
+ // Prints 'starting async work', 'async work done', 'cleanup'.
104
121
  async function validInTryCatch3() {
122
+ async function doAsyncWork(): Promise<void> {
123
+ console.log('starting async work');
124
+ await new Promise(resolve => setTimeout(resolve, 1000));
125
+ console.log('async work done');
126
+ }
127
+
105
128
  try {
106
129
  throw new Error('error');
107
130
  } catch (e) {
108
- return await Promise.resolve('catch');
131
+ return await doAsyncWork();
109
132
  } finally {
110
133
  console.log('cleanup');
111
134
  }
@@ -117,7 +140,7 @@ async function validInTryCatch4() {
117
140
  } catch (e) {
118
141
  throw new Error('error2');
119
142
  } finally {
120
- return Promise.resolve('finally');
143
+ return Promise.reject('finally');
121
144
  }
122
145
  }
123
146
 
@@ -9,6 +9,12 @@ import TabItem from '@theme/TabItem';
9
9
  >
10
10
  > See **https://typescript-eslint.io/rules/sort-type-constituents** for documentation.
11
11
 
12
+ :::danger Deprecated
13
+ This rule has been deprecated in favor of the [`perfectionist/sort-intersection-types`](https://eslint-plugin-perfectionist.azat.io/rules/sort-intersection-types) and [`perfectionist/sort-union-types`](https://eslint-plugin-perfectionist.azat.io/rules/sort-union-types) rules.
14
+
15
+ See [Docs: Deprecate sort-type-constituents in favor of eslint-plugin-perfectionist](https://github.com/typescript-eslint/typescript-eslint/issues/8915) and [eslint-plugin: Feature freeze naming and sorting stylistic rules](https://github.com/typescript-eslint/typescript-eslint/issues/8792) for more information.
16
+ :::
17
+
12
18
  Sorting union (`|`) and intersection (`&`) types can help:
13
19
 
14
20
  - keep your codebase standardized
@@ -19,15 +25,6 @@ This rule reports on any types that aren't sorted alphabetically.
19
25
 
20
26
  > Types are sorted case-insensitively and treating numbers like a human would, falling back to character code sorting in case of ties.
21
27
 
22
- :::note
23
- This rule is _feature frozen_: it will no longer receive new features such as new options.
24
- It still will accept bug and documentation fixes for its existing area of features.
25
-
26
- Stylistic rules that enforce naming and/or sorting conventions tend to grow incomprehensibly complex as increasingly obscure features are requested.
27
- This rule has reached the limit of what is reasonable for the typescript-eslint project to maintain.
28
- See [eslint-plugin: Feature freeze naming and sorting stylistic rules](https://github.com/typescript-eslint/typescript-eslint/issues/8792) for more information.
29
- :::
30
-
31
28
  ## Examples
32
29
 
33
30
  <Tabs>
@@ -97,6 +94,29 @@ type T4 =
97
94
 
98
95
  ## Options
99
96
 
97
+ ### `caseSensitive`
98
+
99
+ Whether to sort using case sensitive string comparisons.
100
+
101
+ Examples of code with `{ "caseSensitive": true }`:
102
+
103
+ <Tabs>
104
+ <TabItem value="❌ Incorrect">
105
+
106
+ ```ts option='{ "caseSensitive": true }'
107
+ type T = 'DeletedAt' | 'DeleteForever';
108
+ ```
109
+
110
+ </TabItem>
111
+ <TabItem value="✅ Correct">
112
+
113
+ ```ts option='{ "caseSensitive": true }'
114
+ type T = 'DeleteForever' | 'DeletedAt';
115
+ ```
116
+
117
+ </TabItem>
118
+ </Tabs>
119
+
100
120
  ### `checkIntersections`
101
121
 
102
122
  Whether to check intersection types (`&`).
@@ -0,0 +1,12 @@
1
+ :::danger Deprecated
2
+
3
+ This rule has been renamed to [`sort-type-constituents`](https://typescript-eslint.io/rules/sort-type-constituents).
4
+
5
+ :::
6
+
7
+ <!--
8
+ This doc file has been left on purpose to help direct people to the replacement rule.
9
+
10
+ Note that there is no actual way to get to this page in the normal navigation,
11
+ so end-users will only be able to get to this page from the search bar.
12
+ -->
@@ -16,7 +16,7 @@ Otherwise, passing class methods around as values can remove type safety by fail
16
16
  This rule reports when a class method is referenced in an unbound manner.
17
17
 
18
18
  :::note Tip
19
- If you're working with `jest`, you can use [`eslint-plugin-jest`'s version of this rule](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/unbound-method.mdx) to lint your test files, which knows when it's ok to pass an unbound method to `expect` calls.
19
+ If you're working with `jest`, you can use [`eslint-plugin-jest`'s version of this rule](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/unbound-method.md) to lint your test files, which knows when it's ok to pass an unbound method to `expect` calls.
20
20
  :::
21
21
 
22
22
  ## Examples
@@ -105,7 +105,8 @@ log();
105
105
  ## When Not To Use It
106
106
 
107
107
  If your project dynamically changes `this` scopes around in a way TypeScript has difficulties modeling, this rule may not be viable to use.
108
- One likely difficult pattern is if your code intentionally waits to bind methods after use, such as by passing a `scope: this` along with the method.
108
+ For example, some functions have an additional parameter for specifying the `this` context, such as `Reflect.apply`, and array methods like `Array.prototype.map`.
109
+ This semantic is not easily expressed by TypeScript.
109
110
  You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
110
111
 
111
112
  If you're wanting to use `toBeCalled` and similar matches in `jest` tests, you can disable this rule for your test files in favor of [`eslint-plugin-jest`'s version of this rule](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/unbound-method.mdx).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.0.0-alpha.3",
3
+ "version": "8.0.0-alpha.30",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -53,39 +53,36 @@
53
53
  "clean": "tsc -b tsconfig.build.json --clean",
54
54
  "postclean": "rimraf dist && rimraf coverage",
55
55
  "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
56
- "generate:breaking-changes": "yarn tsx tools/generate-breaking-changes.mts",
56
+ "generate:breaking-changes": "tsx tools/generate-breaking-changes.mts",
57
57
  "generate:configs": "npx nx run repo-tools:generate-configs",
58
58
  "lint": "npx nx lint",
59
59
  "test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --coverage --logHeapUsage",
60
60
  "test-single": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --no-coverage",
61
- "typecheck": "tsc -p tsconfig.json --noEmit"
61
+ "typecheck": "tsc --noEmit"
62
62
  },
63
63
  "dependencies": {
64
64
  "@eslint-community/regexpp": "^4.10.0",
65
- "@typescript-eslint/scope-manager": "8.0.0-alpha.3",
66
- "@typescript-eslint/type-utils": "8.0.0-alpha.3",
67
- "@typescript-eslint/utils": "8.0.0-alpha.3",
68
- "@typescript-eslint/visitor-keys": "8.0.0-alpha.3",
69
- "debug": "^4.3.4",
65
+ "@typescript-eslint/scope-manager": "8.0.0-alpha.30",
66
+ "@typescript-eslint/type-utils": "8.0.0-alpha.30",
67
+ "@typescript-eslint/utils": "8.0.0-alpha.30",
68
+ "@typescript-eslint/visitor-keys": "8.0.0-alpha.30",
70
69
  "graphemer": "^1.4.0",
71
70
  "ignore": "^5.3.1",
72
71
  "natural-compare": "^1.4.0",
73
- "semver": "^7.6.0",
74
72
  "ts-api-utils": "^1.3.0"
75
73
  },
76
74
  "devDependencies": {
77
- "@types/debug": "*",
78
- "@types/marked": "*",
75
+ "@jest/types": "29.6.3",
76
+ "@types/marked": "^5.0.2",
79
77
  "@types/mdast": "^4.0.3",
80
78
  "@types/natural-compare": "*",
81
- "@typescript-eslint/rule-schema-to-typescript-types": "8.0.0-alpha.3",
82
- "@typescript-eslint/rule-tester": "8.0.0-alpha.3",
79
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.0.0-alpha.30",
80
+ "@typescript-eslint/rule-tester": "8.0.0-alpha.30",
83
81
  "ajv": "^6.12.6",
84
- "chalk": "^5.3.0",
85
82
  "cross-env": "^7.0.3",
86
83
  "cross-fetch": "*",
87
84
  "eslint": "*",
88
- "grapheme-splitter": "^1.0.4",
85
+ "espree": "^10.0.1",
89
86
  "jest": "29.7.0",
90
87
  "jest-specific-snapshot": "^8.0.0",
91
88
  "json-schema": "*",
@@ -102,8 +99,8 @@
102
99
  "unist-util-visit": "^5.0.0"
103
100
  },
104
101
  "peerDependencies": {
105
- "@typescript-eslint/parser": "^7.0.0",
106
- "eslint": "^8.57.0"
102
+ "@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0",
103
+ "eslint": "^8.57.0 || ^9.0.0"
107
104
  },
108
105
  "peerDependenciesMeta": {
109
106
  "typescript": {
package/rules.d.ts CHANGED
@@ -35,11 +35,15 @@ This is likely not portable. A type annotation is necessary. ts(2742)
35
35
  ```
36
36
  */
37
37
 
38
- import type { RuleModule } from '@typescript-eslint/utils/ts-eslint';
38
+ import type { RuleModuleWithMetaDocs } from '@typescript-eslint/utils/ts-eslint';
39
+
40
+ import type { ESLintPluginDocs, ESLintPluginRuleModule } from './src/util';
41
+
42
+ export { ESLintPluginDocs, ESLintPluginRuleModule };
39
43
 
40
44
  export type TypeScriptESLintRules = Record<
41
45
  string,
42
- RuleModule<string, unknown[]>
46
+ RuleModuleWithMetaDocs<string, unknown[], ESLintPluginDocs>
43
47
  >;
44
48
  declare const rules: TypeScriptESLintRules;
45
49
  // eslint-disable-next-line import/no-default-export