@typescript-eslint/eslint-plugin 8.0.2-alpha.1 → 8.0.2-alpha.11
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/member-ordering.js +9 -3
- package/dist/rules/member-ordering.js.map +1 -1
- package/dist/rules/naming-convention.js +5 -7
- package/dist/rules/naming-convention.js.map +1 -1
- package/dist/rules/no-floating-promises.js +19 -14
- package/dist/rules/no-floating-promises.js.map +1 -1
- package/dist/rules/no-misused-promises.js +69 -2
- package/dist/rules/no-misused-promises.js.map +1 -1
- package/dist/rules/no-shadow.js +2 -2
- package/dist/rules/no-shadow.js.map +1 -1
- package/dist/rules/no-unnecessary-type-parameters.js +7 -3
- package/dist/rules/no-unnecessary-type-parameters.js.map +1 -1
- package/dist/rules/no-unsafe-return.js +31 -8
- package/dist/rules/no-unsafe-return.js.map +1 -1
- package/dist/rules/no-use-before-define.js +2 -2
- package/dist/rules/no-use-before-define.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/analyzeChain.js +47 -14
- package/dist/rules/prefer-optional-chain-utils/analyzeChain.js.map +1 -1
- package/dist/rules/prefer-optional-chain.js +2 -2
- package/dist/rules/prefer-optional-chain.js.map +1 -1
- package/dist/util/getFixOrSuggest.js +7 -0
- package/dist/util/getFixOrSuggest.js.map +1 -0
- package/dist/util/getWrappingFixer.js +1 -1
- package/dist/util/index.js +1 -0
- package/dist/util/index.js.map +1 -1
- package/dist/util/misc.js.map +1 -1
- package/docs/rules/ban-types.md +4 -0
- package/docs/rules/block-spacing.md +4 -0
- package/docs/rules/brace-style.md +4 -0
- package/docs/rules/camelcase.md +4 -0
- package/docs/rules/comma-dangle.md +4 -0
- package/docs/rules/comma-spacing.md +4 -0
- package/docs/rules/func-call-spacing.md +4 -0
- package/docs/rules/indent.md +4 -0
- package/docs/rules/key-spacing.md +4 -0
- package/docs/rules/keyword-spacing.md +4 -0
- package/docs/rules/lines-around-comment.md +4 -0
- package/docs/rules/lines-between-class-members.md +4 -0
- package/docs/rules/member-delimiter-style.md +4 -0
- package/docs/rules/no-duplicate-imports.mdx +4 -0
- package/docs/rules/no-extra-parens.md +4 -0
- package/docs/rules/no-extra-semi.md +4 -0
- package/docs/rules/no-misused-promises.mdx +98 -53
- package/docs/rules/no-parameter-properties.mdx +4 -0
- package/docs/rules/no-unsafe-return.mdx +9 -1
- package/docs/rules/no-useless-template-literals.mdx +4 -0
- package/docs/rules/object-curly-spacing.md +4 -0
- package/docs/rules/padding-line-between-statements.md +4 -0
- package/docs/rules/quotes.md +4 -0
- package/docs/rules/semi.md +4 -0
- package/docs/rules/sort-type-union-intersection-members.mdx +4 -0
- package/docs/rules/space-before-blocks.md +4 -0
- package/docs/rules/space-before-function-paren.md +4 -0
- package/docs/rules/space-infix-ops.md +4 -0
- package/docs/rules/strict-boolean-expressions.mdx +2 -2
- package/docs/rules/type-annotation-spacing.md +4 -0
- package/package.json +7 -7
package/docs/rules/indent.md
CHANGED
@@ -37,10 +37,89 @@ If you don't want to check conditionals, you can configure the rule with `"check
|
|
37
37
|
|
38
38
|
Doing so prevents the rule from looking at code like `if (somePromise)`.
|
39
39
|
|
40
|
-
|
40
|
+
### `checksVoidReturn`
|
41
|
+
|
42
|
+
Likewise, if you don't want to check functions that return promises where a void return is
|
43
|
+
expected, your configuration will look like this:
|
44
|
+
|
45
|
+
```json
|
46
|
+
{
|
47
|
+
"@typescript-eslint/no-misused-promises": [
|
48
|
+
"error",
|
49
|
+
{
|
50
|
+
"checksVoidReturn": false
|
51
|
+
}
|
52
|
+
]
|
53
|
+
}
|
54
|
+
```
|
55
|
+
|
56
|
+
You can disable selective parts of the `checksVoidReturn` option by providing an object that disables specific checks. For example, if you don't mind that passing a `() => Promise<void>` to a `() => void` parameter or JSX attribute can lead to a floating unhandled Promise:
|
57
|
+
|
58
|
+
```json
|
59
|
+
{
|
60
|
+
"@typescript-eslint/no-misused-promises": [
|
61
|
+
"error",
|
62
|
+
{
|
63
|
+
"checksVoidReturn": {
|
64
|
+
"arguments": false,
|
65
|
+
"attributes": false
|
66
|
+
}
|
67
|
+
}
|
68
|
+
]
|
69
|
+
}
|
70
|
+
```
|
71
|
+
|
72
|
+
The following sub-options are supported:
|
73
|
+
|
74
|
+
#### `arguments`
|
75
|
+
|
76
|
+
Disables checking an asynchronous function passed as argument where the parameter type expects a function that returns `void`.
|
77
|
+
|
78
|
+
#### `attributes`
|
79
|
+
|
80
|
+
Disables checking an asynchronous function passed as a JSX attribute expected to be a function that returns `void`.
|
81
|
+
|
82
|
+
#### `inheritedMethods`
|
83
|
+
|
84
|
+
Disables checking an asynchronous method in a type that extends or implements another type expecting that method to return `void`.
|
85
|
+
|
86
|
+
:::note
|
87
|
+
For now, `no-misused-promises` only checks _named_ methods against extended/implemented types: that is, call/construct/index signatures are ignored. Call signatures are not required in TypeScript to be consistent with one another, and construct signatures cannot be `async` in the first place. Index signature checking may be implemented in the future.
|
88
|
+
:::
|
89
|
+
|
90
|
+
#### `properties`
|
91
|
+
|
92
|
+
Disables checking an asynchronous function passed as an object property expected to be a function that returns `void`.
|
93
|
+
|
94
|
+
#### `returns`
|
95
|
+
|
96
|
+
Disables checking an asynchronous function returned in a function whose return type is a function that returns `void`.
|
97
|
+
|
98
|
+
#### `variables`
|
99
|
+
|
100
|
+
Disables checking an asynchronous function used as a variable whose return type is a function that returns `void`.
|
101
|
+
|
102
|
+
### `checksSpreads`
|
103
|
+
|
104
|
+
If you don't want to check object spreads, you can add this configuration:
|
105
|
+
|
106
|
+
```json
|
107
|
+
{
|
108
|
+
"@typescript-eslint/no-misused-promises": [
|
109
|
+
"error",
|
110
|
+
{
|
111
|
+
"checksSpreads": false
|
112
|
+
}
|
113
|
+
]
|
114
|
+
}
|
115
|
+
```
|
41
116
|
|
42
117
|
## Examples
|
43
118
|
|
119
|
+
### `checksConditionals`
|
120
|
+
|
121
|
+
Examples of code for this rule with `checksConditionals: true`:
|
122
|
+
|
44
123
|
<Tabs>
|
45
124
|
<TabItem value="❌ Incorrect">
|
46
125
|
|
@@ -81,45 +160,6 @@ while (await promise) {
|
|
81
160
|
|
82
161
|
### `checksVoidReturn`
|
83
162
|
|
84
|
-
Likewise, if you don't want to check functions that return promises where a void return is
|
85
|
-
expected, your configuration will look like this:
|
86
|
-
|
87
|
-
```json
|
88
|
-
{
|
89
|
-
"@typescript-eslint/no-misused-promises": [
|
90
|
-
"error",
|
91
|
-
{
|
92
|
-
"checksVoidReturn": false
|
93
|
-
}
|
94
|
-
]
|
95
|
-
}
|
96
|
-
```
|
97
|
-
|
98
|
-
You can disable selective parts of the `checksVoidReturn` option by providing an object that disables specific checks.
|
99
|
-
The following options are supported:
|
100
|
-
|
101
|
-
- `arguments`: Disables checking an asynchronous function passed as argument where the parameter type expects a function that returns `void`
|
102
|
-
- `attributes`: Disables checking an asynchronous function passed as a JSX attribute expected to be a function that returns `void`
|
103
|
-
- `properties`: Disables checking an asynchronous function passed as an object property expected to be a function that returns `void`
|
104
|
-
- `returns`: Disables checking an asynchronous function returned in a function whose return type is a function that returns `void`
|
105
|
-
- `variables`: Disables checking an asynchronous function used as a variable whose return type is a function that returns `void`
|
106
|
-
|
107
|
-
For example, if you don't mind that passing a `() => Promise<void>` to a `() => void` parameter or JSX attribute can lead to a floating unhandled Promise:
|
108
|
-
|
109
|
-
```json
|
110
|
-
{
|
111
|
-
"@typescript-eslint/no-misused-promises": [
|
112
|
-
"error",
|
113
|
-
{
|
114
|
-
"checksVoidReturn": {
|
115
|
-
"arguments": false,
|
116
|
-
"attributes": false
|
117
|
-
}
|
118
|
-
}
|
119
|
-
]
|
120
|
-
}
|
121
|
-
```
|
122
|
-
|
123
163
|
Examples of code for this rule with `checksVoidReturn: true`:
|
124
164
|
|
125
165
|
<Tabs>
|
@@ -140,6 +180,15 @@ document.addEventListener('click', async () => {
|
|
140
180
|
await fetch('/');
|
141
181
|
console.log('synchronous call');
|
142
182
|
});
|
183
|
+
|
184
|
+
interface MySyncInterface {
|
185
|
+
setThing(): void;
|
186
|
+
}
|
187
|
+
class MyClass implements MySyncInterface {
|
188
|
+
async setThing(): Promise<void> {
|
189
|
+
this.thing = await fetchThing();
|
190
|
+
}
|
191
|
+
}
|
143
192
|
```
|
144
193
|
|
145
194
|
</TabItem>
|
@@ -182,6 +231,15 @@ document.addEventListener('click', () => {
|
|
182
231
|
|
183
232
|
handler().catch(handleError);
|
184
233
|
});
|
234
|
+
|
235
|
+
interface MyAsyncInterface {
|
236
|
+
setThing(): Promise<void>;
|
237
|
+
}
|
238
|
+
class MyClass implements MyAsyncInterface {
|
239
|
+
async setThing(): Promise<void> {
|
240
|
+
this.thing = await fetchThing();
|
241
|
+
}
|
242
|
+
}
|
185
243
|
```
|
186
244
|
|
187
245
|
</TabItem>
|
@@ -189,19 +247,6 @@ document.addEventListener('click', () => {
|
|
189
247
|
|
190
248
|
### `checksSpreads`
|
191
249
|
|
192
|
-
If you don't want to check object spreads, you can add this configuration:
|
193
|
-
|
194
|
-
```json
|
195
|
-
{
|
196
|
-
"@typescript-eslint/no-misused-promises": [
|
197
|
-
"error",
|
198
|
-
{
|
199
|
-
"checksSpreads": false
|
200
|
-
}
|
201
|
-
]
|
202
|
-
}
|
203
|
-
```
|
204
|
-
|
205
250
|
Examples of code for this rule with `checksSpreads: true`:
|
206
251
|
|
207
252
|
<Tabs>
|
@@ -15,7 +15,7 @@ Using `any` disables many type checking rules and is generally best used only as
|
|
15
15
|
Despite your best intentions, the `any` type can sometimes leak into your codebase.
|
16
16
|
Returning an an `any`-typed value from a function creates a potential type safety hole and source of bugs in your codebase.
|
17
17
|
|
18
|
-
This rule disallows returning `any` or `any[]` from a function.
|
18
|
+
This rule disallows returning `any` or `any[]` from a function and returning `Promise<any>` from an async function.
|
19
19
|
|
20
20
|
This rule also compares generic type argument types to ensure you don't return an unsafe `any` in a generic position to a function that's expecting a specific type.
|
21
21
|
For example, it will error if you return `Set<any>` from a function declared as returning `Set<string>`.
|
@@ -56,6 +56,10 @@ const foo10 = () => [] as any[];
|
|
56
56
|
|
57
57
|
const foo11 = (): string[] => [1, 2, 3] as any[];
|
58
58
|
|
59
|
+
async function foo13() {
|
60
|
+
return Promise.resolve({} as any);
|
61
|
+
}
|
62
|
+
|
59
63
|
// generic position examples
|
60
64
|
function assignability1(): Set<string> {
|
61
65
|
return new Set<any>([1]);
|
@@ -78,6 +82,10 @@ function foo2() {
|
|
78
82
|
const foo3 = () => [];
|
79
83
|
const foo4 = () => ['a'];
|
80
84
|
|
85
|
+
async function foo5() {
|
86
|
+
return Promise.resolve(1);
|
87
|
+
}
|
88
|
+
|
81
89
|
function assignability1(): Set<string> {
|
82
90
|
return new Set<string>(['foo']);
|
83
91
|
}
|
@@ -1,3 +1,7 @@
|
|
1
|
+
---
|
2
|
+
displayed_sidebar: rulesSidebar
|
3
|
+
---
|
4
|
+
|
1
5
|
:::danger Deprecated
|
2
6
|
|
3
7
|
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.
|
package/docs/rules/quotes.md
CHANGED
package/docs/rules/semi.md
CHANGED
@@ -30,13 +30,13 @@ The following nodes are considered boolean expressions and their type is checked
|
|
30
30
|
|
31
31
|
```ts
|
32
32
|
// nullable numbers are considered unsafe by default
|
33
|
-
|
33
|
+
declare const num: number | undefined;
|
34
34
|
if (num) {
|
35
35
|
console.log('num is defined');
|
36
36
|
}
|
37
37
|
|
38
38
|
// nullable strings are considered unsafe by default
|
39
|
-
|
39
|
+
declare const str: string | null;
|
40
40
|
if (!str) {
|
41
41
|
console.log('str is empty');
|
42
42
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
3
|
-
"version": "8.0.2-alpha.
|
3
|
+
"version": "8.0.2-alpha.11",
|
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.0.2-alpha.
|
64
|
-
"@typescript-eslint/type-utils": "8.0.2-alpha.
|
65
|
-
"@typescript-eslint/utils": "8.0.2-alpha.
|
66
|
-
"@typescript-eslint/visitor-keys": "8.0.2-alpha.
|
63
|
+
"@typescript-eslint/scope-manager": "8.0.2-alpha.11",
|
64
|
+
"@typescript-eslint/type-utils": "8.0.2-alpha.11",
|
65
|
+
"@typescript-eslint/utils": "8.0.2-alpha.11",
|
66
|
+
"@typescript-eslint/visitor-keys": "8.0.2-alpha.11",
|
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.0.2-alpha.
|
78
|
-
"@typescript-eslint/rule-tester": "8.0.2-alpha.
|
77
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.0.2-alpha.11",
|
78
|
+
"@typescript-eslint/rule-tester": "8.0.2-alpha.11",
|
79
79
|
"ajv": "^6.12.6",
|
80
80
|
"cross-env": "^7.0.3",
|
81
81
|
"cross-fetch": "*",
|