@typescript-eslint/eslint-plugin 8.3.1-alpha.0 → 8.3.1-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rules/ban-ts-comment.js +1 -0
- package/dist/rules/ban-ts-comment.js.map +1 -1
- package/dist/rules/consistent-type-assertions.js +3 -0
- package/dist/rules/consistent-type-assertions.js.map +1 -1
- package/dist/rules/consistent-type-exports.js +1 -0
- package/dist/rules/consistent-type-exports.js.map +1 -1
- package/dist/rules/consistent-type-imports.js +3 -0
- package/dist/rules/consistent-type-imports.js.map +1 -1
- package/dist/rules/dot-notation.js +5 -0
- package/dist/rules/dot-notation.js.map +1 -1
- package/dist/rules/explicit-member-accessibility.js +1 -0
- package/dist/rules/explicit-member-accessibility.js.map +1 -1
- package/dist/rules/max-params.js +5 -2
- package/dist/rules/max-params.js.map +1 -1
- package/dist/rules/no-base-to-string.js +1 -0
- package/dist/rules/no-base-to-string.js.map +1 -1
- package/dist/rules/no-confusing-void-expression.js +8 -2
- package/dist/rules/no-confusing-void-expression.js.map +1 -1
- package/dist/rules/no-duplicate-type-constituents.js +2 -0
- package/dist/rules/no-duplicate-type-constituents.js.map +1 -1
- package/dist/rules/no-empty-function.js +1 -0
- package/dist/rules/no-empty-function.js.map +1 -1
- package/dist/rules/no-empty-interface.js +1 -0
- package/dist/rules/no-empty-interface.js.map +1 -1
- package/dist/rules/no-empty-object-type.js +3 -0
- package/dist/rules/no-empty-object-type.js.map +1 -1
- package/dist/rules/no-floating-promises.js +8 -2
- package/dist/rules/no-floating-promises.js.map +1 -1
- package/dist/rules/no-inferrable-types.js +2 -0
- package/dist/rules/no-inferrable-types.js.map +1 -1
- package/dist/rules/no-invalid-void-type.js +2 -0
- package/dist/rules/no-invalid-void-type.js.map +1 -1
- package/dist/rules/no-magic-numbers.js +4 -0
- package/dist/rules/no-magic-numbers.js.map +1 -1
- package/dist/rules/no-meaningless-void-operator.js +1 -0
- package/dist/rules/no-meaningless-void-operator.js.map +1 -1
- package/dist/rules/no-misused-promises.js +25 -6
- package/dist/rules/no-misused-promises.js.map +1 -1
- package/dist/rules/no-redeclare.js +2 -0
- package/dist/rules/no-redeclare.js.map +1 -1
- package/dist/rules/no-shadow.js +6 -0
- package/dist/rules/no-shadow.js.map +1 -1
- package/dist/rules/no-unused-vars.js +13 -3
- package/dist/rules/no-unused-vars.js.map +1 -1
- package/dist/rules/no-use-before-define.js +24 -6
- package/dist/rules/no-use-before-define.js.map +1 -1
- package/dist/rules/only-throw-error.js +2 -0
- package/dist/rules/only-throw-error.js.map +1 -1
- package/dist/rules/parameter-properties.js +2 -0
- package/dist/rules/parameter-properties.js.map +1 -1
- package/dist/rules/prefer-literal-enum-member.js +1 -0
- package/dist/rules/prefer-literal-enum-member.js.map +1 -1
- package/dist/rules/prefer-nullish-coalescing.js +5 -0
- package/dist/rules/prefer-nullish-coalescing.js.map +1 -1
- package/dist/rules/prefer-promise-reject-errors.js +1 -0
- package/dist/rules/prefer-promise-reject-errors.js.map +1 -1
- package/dist/rules/prefer-readonly-parameter-types.js +10 -2
- package/dist/rules/prefer-readonly-parameter-types.js.map +1 -1
- package/dist/rules/prefer-readonly.js +1 -0
- package/dist/rules/prefer-readonly.js.map +1 -1
- package/dist/rules/promise-function-async.js +4 -0
- package/dist/rules/promise-function-async.js.map +1 -1
- package/dist/rules/return-await.js +21 -5
- package/dist/rules/return-await.js.map +1 -1
- package/dist/rules/strict-boolean-expressions.js +32 -8
- package/dist/rules/strict-boolean-expressions.js.map +1 -1
- package/dist/rules/triple-slash-reference.js +3 -0
- package/dist/rules/triple-slash-reference.js.map +1 -1
- package/dist/rules/typedef.js +32 -8
- package/dist/rules/typedef.js.map +1 -1
- package/docs/rules/ban-ts-comment.mdx +1 -1
- package/docs/rules/consistent-type-assertions.mdx +5 -2
- package/docs/rules/consistent-type-exports.mdx +1 -1
- package/docs/rules/consistent-type-imports.mdx +3 -3
- package/docs/rules/dot-notation.mdx +8 -0
- package/docs/rules/explicit-member-accessibility.mdx +2 -1
- package/docs/rules/max-params.mdx +42 -0
- package/docs/rules/no-base-to-string.mdx +2 -1
- package/docs/rules/no-confusing-void-expression.mdx +6 -2
- package/docs/rules/no-floating-promises.mdx +4 -9
- package/docs/rules/no-inferrable-types.mdx +4 -0
- package/docs/rules/no-invalid-void-type.mdx +2 -2
- package/docs/rules/no-magic-numbers.mdx +5 -3
- package/docs/rules/no-meaningless-void-operator.mdx +1 -1
- package/docs/rules/no-misused-promises.mdx +2 -0
- package/docs/rules/no-namespace.mdx +3 -0
- package/docs/rules/no-redeclare.mdx +1 -1
- package/docs/rules/no-restricted-imports.mdx +1 -1
- package/docs/rules/no-shadow.mdx +2 -2
- package/docs/rules/no-use-before-define.mdx +7 -1
- package/docs/rules/prefer-literal-enum-member.mdx +1 -1
- package/docs/rules/prefer-nullish-coalescing.mdx +6 -4
- package/docs/rules/prefer-readonly-parameter-types.mdx +12 -17
- package/docs/rules/promise-function-async.mdx +2 -2
- package/docs/rules/require-await.mdx +33 -4
- package/docs/rules/typedef.mdx +1 -1
- package/package.json +7 -7
package/docs/rules/no-shadow.mdx
CHANGED
@@ -31,7 +31,7 @@ const defaultOptions: Options = {
|
|
31
31
|
|
32
32
|
### `ignoreTypeValueShadow`
|
33
33
|
|
34
|
-
|
34
|
+
Whether to ignore types named the same as a variable. This is generally safe because you cannot use variables in type locations without a `typeof` operator, so there's little risk of confusion.
|
35
35
|
|
36
36
|
Examples of **correct** code with `{ ignoreTypeValueShadow: true }`:
|
37
37
|
|
@@ -55,7 +55,7 @@ _Shadowing_ specifically refers to two identical identifiers that are in differe
|
|
55
55
|
|
56
56
|
### `ignoreFunctionTypeParameterNameValueShadow`
|
57
57
|
|
58
|
-
|
58
|
+
Whether to ignore function parameters named the same as a variable.
|
59
59
|
|
60
60
|
Each of a function type's arguments creates a value variable within the scope of the function type. This is done so that you can reference the type later using the `typeof` operator:
|
61
61
|
|
@@ -33,6 +33,8 @@ const defaultOptions: Options = {
|
|
33
33
|
|
34
34
|
### `enums`
|
35
35
|
|
36
|
+
Whether to check references to enums before the enum declaration.
|
37
|
+
|
36
38
|
If this is `true`, this rule warns every reference to a enum before the enum declaration.
|
37
39
|
If this is `false`, this rule will ignore references to enums, when the reference is in a child scope.
|
38
40
|
|
@@ -67,6 +69,8 @@ enum Foo {
|
|
67
69
|
|
68
70
|
### `typedefs`
|
69
71
|
|
72
|
+
Whether to check references to types before the type declaration.
|
73
|
+
|
70
74
|
If this is `true`, this rule warns every reference to a type before the type declaration.
|
71
75
|
If this is `false`, this rule will ignore references to types.
|
72
76
|
|
@@ -79,7 +83,9 @@ type StringOrNumber = string | number;
|
|
79
83
|
|
80
84
|
### `ignoreTypeReferences`
|
81
85
|
|
82
|
-
|
86
|
+
Whether to ignore type references, such as in type annotations and assertions.
|
87
|
+
|
88
|
+
If this is `true`, this rule ignores all type references.
|
83
89
|
If this is `false`, this will check all type references.
|
84
90
|
|
85
91
|
Examples of **correct** code for the `{ "ignoreTypeReferences": true }` option:
|
@@ -67,7 +67,7 @@ enum Valid {
|
|
67
67
|
|
68
68
|
### `allowBitwiseExpressions`
|
69
69
|
|
70
|
-
|
70
|
+
Whether to allow using bitwise expressions in enum initializers (default: `false`).
|
71
71
|
|
72
72
|
Examples of code for the `{ "allowBitwiseExpressions": true }` option:
|
73
73
|
|
@@ -25,7 +25,7 @@ This rule will not work as expected if [`strictNullChecks`](https://www.typescri
|
|
25
25
|
|
26
26
|
### `ignoreTernaryTests`
|
27
27
|
|
28
|
-
|
28
|
+
Whether to ignore any ternary expressions that could be simplified by using the nullish coalescing operator. This is set to `false` by default.
|
29
29
|
|
30
30
|
Incorrect code for `ignoreTernaryTests: false`, and correct code for `ignoreTernaryTests: true`:
|
31
31
|
|
@@ -65,7 +65,7 @@ foo ?? 'a string';
|
|
65
65
|
|
66
66
|
### `ignoreConditionalTests`
|
67
67
|
|
68
|
-
|
68
|
+
Whether to ignore cases that are located within a conditional test. This is set to `true` by default.
|
69
69
|
|
70
70
|
Generally expressions within conditional tests intentionally use the falsy fallthrough behavior of the logical or operator, meaning that fixing the operator to the nullish coalesce operator could cause bugs.
|
71
71
|
|
@@ -107,7 +107,7 @@ a ?? b ? true : false;
|
|
107
107
|
|
108
108
|
### `ignoreMixedLogicalExpressions`
|
109
109
|
|
110
|
-
|
110
|
+
Whether to ignore any logical or expressions that are part of a mixed logical expression (with `&&`). This is set to `false` by default.
|
111
111
|
|
112
112
|
Generally expressions within mixed logical expressions intentionally use the falsy fallthrough behavior of the logical or operator, meaning that fixing the operator to the nullish coalesce operator could cause bugs.
|
113
113
|
|
@@ -147,6 +147,8 @@ a ?? (b && c && d);
|
|
147
147
|
|
148
148
|
### `ignorePrimitives`
|
149
149
|
|
150
|
+
Whether to ignore all (`true`) or some (an object with properties) primitive types.
|
151
|
+
|
150
152
|
If you would like to ignore expressions containing operands of certain primitive types that can be falsy then you may pass an object containing a boolean value for each primitive:
|
151
153
|
|
152
154
|
- `string: true`, ignores `null` or `undefined` unions with `string` (default: false).
|
@@ -172,7 +174,7 @@ Also, if you would like to ignore all primitives types, you can set `ignorePrimi
|
|
172
174
|
|
173
175
|
### `allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing`
|
174
176
|
|
175
|
-
|
177
|
+
Unless this is set to `true`, the rule will error on every file whose `tsconfig.json` does _not_ have the `strictNullChecks` compiler option (or `strict`) set to `true`.
|
176
178
|
|
177
179
|
Without `strictNullChecks`, TypeScript essentially erases `undefined` and `null` from the types. This means when this rule inspects the types from a variable, **it will not be able to tell that the variable might be `null` or `undefined`**, which essentially makes this rule useless.
|
178
180
|
|
@@ -140,23 +140,16 @@ interface Foo {
|
|
140
140
|
|
141
141
|
### `allow`
|
142
142
|
|
143
|
+
An array of type specifiers to ignore.
|
143
144
|
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
145
|
|
145
|
-
This option takes
|
146
|
-
Each item in the array must have one of the following forms:
|
147
|
-
|
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).
|
151
|
-
|
152
|
-
Additionally, a type may be defined just as a simple string, which then matches the type independently of its origin.
|
146
|
+
This option takes the shared [`TypeOrValueSpecifier` format](/packages/type-utils/type-or-value-specifier).
|
153
147
|
|
154
148
|
Examples of code for this rule with:
|
155
149
|
|
156
150
|
```json
|
157
151
|
{
|
158
152
|
"allow": [
|
159
|
-
"$",
|
160
153
|
{ "from": "file", "name": "Foo" },
|
161
154
|
{ "from": "lib", "name": "HTMLElement" },
|
162
155
|
{ "from": "package", "name": "Bar", "package": "bar-lib" }
|
@@ -167,7 +160,7 @@ Examples of code for this rule with:
|
|
167
160
|
<Tabs>
|
168
161
|
<TabItem value="❌ Incorrect">
|
169
162
|
|
170
|
-
```ts option='{"allow":[
|
163
|
+
```ts option='{"allow":[{"from":"file","name":"Foo"},{"from":"lib","name":"HTMLElement"},{"from":"package","name":"Bar","package":"bar-lib"}]}'
|
171
164
|
interface ThisIsMutable {
|
172
165
|
prop: string;
|
173
166
|
}
|
@@ -191,7 +184,7 @@ function fn2(arg: Wrapper) {}
|
|
191
184
|
function fn3(arg: WrapperWithOther) {}
|
192
185
|
```
|
193
186
|
|
194
|
-
```ts option='{"allow":[
|
187
|
+
```ts option='{"allow":[{"from":"file","name":"Foo"},{"from":"lib","name":"HTMLElement"},{"from":"package","name":"Bar","package":"bar-lib"}]}'
|
195
188
|
import { Foo } from 'some-lib';
|
196
189
|
import { Bar } from 'incorrect-lib';
|
197
190
|
|
@@ -212,7 +205,7 @@ function fn3(arg: Bar) {}
|
|
212
205
|
</TabItem>
|
213
206
|
<TabItem value="✅ Correct">
|
214
207
|
|
215
|
-
```ts option='{"allow":[
|
208
|
+
```ts option='{"allow":[{"from":"file","name":"Foo"},{"from":"lib","name":"HTMLElement"},{"from":"package","name":"Bar","package":"bar-lib"}]}'
|
216
209
|
interface Foo {
|
217
210
|
prop: string;
|
218
211
|
}
|
@@ -229,7 +222,7 @@ function fn1(arg: Foo) {}
|
|
229
222
|
function fn2(arg: Wrapper) {}
|
230
223
|
```
|
231
224
|
|
232
|
-
```ts option='{"allow":[
|
225
|
+
```ts option='{"allow":[{"from":"file","name":"Foo"},{"from":"lib","name":"HTMLElement"},{"from":"package","name":"Bar","package":"bar-lib"}]}'
|
233
226
|
import { Bar } from 'bar-lib';
|
234
227
|
|
235
228
|
interface Foo {
|
@@ -246,7 +239,7 @@ function fn2(arg: HTMLElement) {}
|
|
246
239
|
function fn3(arg: Bar) {}
|
247
240
|
```
|
248
241
|
|
249
|
-
```ts option='{"allow":[
|
242
|
+
```ts option='{"allow":[{"from":"file","name":"Foo"},{"from":"lib","name":"HTMLElement"},{"from":"package","name":"Bar","package":"bar-lib"}]}'
|
250
243
|
import { Foo } from './foo';
|
251
244
|
|
252
245
|
// Works because Foo is still a local type - it has to be in the same package
|
@@ -258,7 +251,7 @@ function fn(arg: Foo) {}
|
|
258
251
|
|
259
252
|
### `checkParameterProperties`
|
260
253
|
|
261
|
-
|
254
|
+
Whether to check class parameter properties.
|
262
255
|
Because parameter properties create properties on the class, it may be undesirable to force them to be readonly.
|
263
256
|
|
264
257
|
Examples of code for this rule with `{checkParameterProperties: true}`:
|
@@ -297,7 +290,8 @@ class Foo {
|
|
297
290
|
|
298
291
|
### `ignoreInferredTypes`
|
299
292
|
|
300
|
-
|
293
|
+
Whether to ignore parameters which don't explicitly specify a type.
|
294
|
+
This may be desirable in cases where an external dependency specifies a callback with mutable parameters, and manually annotating the callback's parameters is undesirable.
|
301
295
|
|
302
296
|
Examples of code for this rule with `{ignoreInferredTypes: true}`:
|
303
297
|
|
@@ -354,7 +348,8 @@ export const acceptsCallback: AcceptsCallback;
|
|
354
348
|
|
355
349
|
### `treatMethodsAsReadonly`
|
356
350
|
|
357
|
-
|
351
|
+
Whether to treat all mutable methods as though they are readonly.
|
352
|
+
This may be desirable when you are never reassigning methods.
|
358
353
|
|
359
354
|
Examples of code for this rule with `{treatMethodsAsReadonly: false}`:
|
360
355
|
|
@@ -68,7 +68,7 @@ async function functionReturnsUnionWithPromiseImplicitly(p: boolean) {
|
|
68
68
|
|
69
69
|
### `allowAny`
|
70
70
|
|
71
|
-
Whether to ignore functions that return `any`
|
71
|
+
Whether to ignore functions that return `any` or `unknown`.
|
72
72
|
If you want additional safety, consider turning this option off, as it makes the rule less able to catch incorrect Promise behaviors.
|
73
73
|
|
74
74
|
Examples of code with `{ "allowAny": false }`:
|
@@ -135,7 +135,7 @@ Whether to check inline function expressions.
|
|
135
135
|
|
136
136
|
### `checkMethodDeclarations`
|
137
137
|
|
138
|
-
Whether to check methods on classes and object literals
|
138
|
+
Whether to check methods on classes and object literals.
|
139
139
|
`true` by default, but can be set to `false` to ignore them.
|
140
140
|
|
141
141
|
## When Not To Use It
|
@@ -12,14 +12,43 @@ import TabItem from '@theme/TabItem';
|
|
12
12
|
This rule extends the base [`eslint/require-await`](https://eslint.org/docs/rules/require-await) rule.
|
13
13
|
It uses type information to allow promise-returning functions to be marked as `async` without containing an `await` expression.
|
14
14
|
|
15
|
+
:::note
|
16
|
+
`yield` expressions in [async generator functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function*) behave differently from sync generator functions (they unwrap promises), so the base rule never checks async generator functions. On the other hand, our rule uses type information and can detect async generator functions that both never use `await` and always yield non-promise values.
|
17
|
+
:::
|
18
|
+
|
15
19
|
## Examples
|
16
20
|
|
17
|
-
|
21
|
+
<Tabs>
|
22
|
+
<TabItem value="❌ Incorrect">
|
23
|
+
|
24
|
+
```ts
|
25
|
+
async function returnNumber() {
|
26
|
+
return 1;
|
27
|
+
}
|
28
|
+
|
29
|
+
async function* asyncGenerator() {
|
30
|
+
yield 1;
|
31
|
+
}
|
32
|
+
|
33
|
+
const num = returnNumber();
|
34
|
+
const callAsyncGenerator = () => asyncGenerator();
|
35
|
+
```
|
36
|
+
|
37
|
+
</TabItem>
|
38
|
+
<TabItem value="✅ Correct">
|
18
39
|
|
19
40
|
```ts
|
20
|
-
|
21
|
-
return
|
41
|
+
function returnNumber() {
|
42
|
+
return 1;
|
22
43
|
}
|
23
44
|
|
24
|
-
|
45
|
+
function* syncGenerator() {
|
46
|
+
yield 1;
|
47
|
+
}
|
48
|
+
|
49
|
+
const num = returnNumber();
|
50
|
+
const callSyncGenerator = () => syncGenerator();
|
25
51
|
```
|
52
|
+
|
53
|
+
</TabItem>
|
54
|
+
</Tabs>
|
package/docs/rules/typedef.mdx
CHANGED
@@ -306,7 +306,7 @@ let delayedText: string;
|
|
306
306
|
|
307
307
|
### `variableDeclarationIgnoreFunction`
|
308
308
|
|
309
|
-
|
309
|
+
Whether to ignore variable declarations for non-arrow and arrow functions.
|
310
310
|
|
311
311
|
Examples of code with `{ "variableDeclaration": true, "variableDeclarationIgnoreFunction": true }`:
|
312
312
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
3
|
-
"version": "8.3.1-alpha.
|
3
|
+
"version": "8.3.1-alpha.10",
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
5
5
|
"files": [
|
6
6
|
"dist",
|
@@ -60,10 +60,10 @@
|
|
60
60
|
},
|
61
61
|
"dependencies": {
|
62
62
|
"@eslint-community/regexpp": "^4.10.0",
|
63
|
-
"@typescript-eslint/scope-manager": "8.3.1-alpha.
|
64
|
-
"@typescript-eslint/type-utils": "8.3.1-alpha.
|
65
|
-
"@typescript-eslint/utils": "8.3.1-alpha.
|
66
|
-
"@typescript-eslint/visitor-keys": "8.3.1-alpha.
|
63
|
+
"@typescript-eslint/scope-manager": "8.3.1-alpha.10",
|
64
|
+
"@typescript-eslint/type-utils": "8.3.1-alpha.10",
|
65
|
+
"@typescript-eslint/utils": "8.3.1-alpha.10",
|
66
|
+
"@typescript-eslint/visitor-keys": "8.3.1-alpha.10",
|
67
67
|
"graphemer": "^1.4.0",
|
68
68
|
"ignore": "^5.3.1",
|
69
69
|
"natural-compare": "^1.4.0",
|
@@ -74,8 +74,8 @@
|
|
74
74
|
"@types/marked": "^5.0.2",
|
75
75
|
"@types/mdast": "^4.0.3",
|
76
76
|
"@types/natural-compare": "*",
|
77
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "8.3.1-alpha.
|
78
|
-
"@typescript-eslint/rule-tester": "8.3.1-alpha.
|
77
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.3.1-alpha.10",
|
78
|
+
"@typescript-eslint/rule-tester": "8.3.1-alpha.10",
|
79
79
|
"ajv": "^6.12.6",
|
80
80
|
"cross-env": "^7.0.3",
|
81
81
|
"cross-fetch": "*",
|