@typescript-eslint/eslint-plugin 7.5.1-alpha.4 → 7.5.1-alpha.6
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/docs/rules/ban-ts-comment.mdx +2 -6
- package/docs/rules/class-methods-use-this.mdx +2 -2
- package/docs/rules/consistent-type-exports.mdx +0 -18
- package/docs/rules/default-param-last.mdx +0 -4
- package/docs/rules/explicit-module-boundary-types.mdx +18 -18
- package/docs/rules/member-ordering.mdx +6 -6
- package/docs/rules/no-extraneous-class.mdx +2 -2
- package/docs/rules/no-floating-promises.mdx +1 -1
- package/docs/rules/no-implied-eval.mdx +0 -4
- package/docs/rules/no-meaningless-void-operator.mdx +1 -1
- package/docs/rules/no-require-imports.mdx +2 -2
- package/docs/rules/no-unnecessary-type-assertion.mdx +5 -5
- package/docs/rules/no-var-requires.mdx +2 -2
- package/docs/rules/non-nullable-type-assertion-style.mdx +2 -2
- package/docs/rules/only-throw-error.mdx +4 -4
- package/docs/rules/prefer-destructuring.mdx +2 -2
- package/docs/rules/prefer-optional-chain.mdx +17 -3
- package/docs/rules/prefer-readonly-parameter-types.mdx +2 -2
- package/docs/rules/promise-function-async.mdx +2 -2
- package/docs/rules/restrict-plus-operands.mdx +10 -10
- package/docs/rules/space-before-blocks.mdx +1 -1
- package/docs/rules/strict-boolean-expressions.mdx +0 -6
- package/docs/rules/type-annotation-spacing.mdx +1 -1
- package/package.json +13 -8
|
@@ -41,9 +41,7 @@ if (false) {
|
|
|
41
41
|
console.log('hello');
|
|
42
42
|
}
|
|
43
43
|
if (false) {
|
|
44
|
-
/*
|
|
45
|
-
@ts-ignore: Unreachable code error
|
|
46
|
-
*/
|
|
44
|
+
/* @ts-ignore: Unreachable code error */
|
|
47
45
|
console.log('hello');
|
|
48
46
|
}
|
|
49
47
|
```
|
|
@@ -90,9 +88,7 @@ if (false) {
|
|
|
90
88
|
console.log('hello');
|
|
91
89
|
}
|
|
92
90
|
if (false) {
|
|
93
|
-
/*
|
|
94
|
-
@ts-expect-error: Unreachable code error
|
|
95
|
-
*/
|
|
91
|
+
/* @ts-expect-error: Unreachable code error */
|
|
96
92
|
console.log('hello');
|
|
97
93
|
}
|
|
98
94
|
```
|
|
@@ -70,7 +70,7 @@ Example of incorrect code when `ignoreClassesThatImplementAnInterface` is set to
|
|
|
70
70
|
<Tabs>
|
|
71
71
|
<TabItem value="❌ Incorrect">
|
|
72
72
|
|
|
73
|
-
```ts
|
|
73
|
+
```ts option='{ "ignoreClassesThatImplementAnInterface": "public-fields" }'
|
|
74
74
|
class X implements Y {
|
|
75
75
|
method() {}
|
|
76
76
|
property = () => {};
|
|
@@ -86,7 +86,7 @@ class X implements Y {
|
|
|
86
86
|
</TabItem>
|
|
87
87
|
<TabItem value="✅ Correct">
|
|
88
88
|
|
|
89
|
-
```ts
|
|
89
|
+
```ts option='{ "ignoreClassesThatImplementAnInterface": "public-fields" }'
|
|
90
90
|
class X implements Y {
|
|
91
91
|
method() {}
|
|
92
92
|
property = () => {};
|
|
@@ -85,24 +85,6 @@ export type { T };
|
|
|
85
85
|
export { x };
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
<Tabs>
|
|
89
|
-
<TabItem value="❌ Incorrect">
|
|
90
|
-
|
|
91
|
-
```ts option='{ "fixMixedExportsWithInlineTypeSpecifier": true }'
|
|
92
|
-
export { Button } from 'some-library';
|
|
93
|
-
export type { ButtonProps } from 'some-library';
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
</TabItem>
|
|
97
|
-
<TabItem value="✅ Correct">
|
|
98
|
-
|
|
99
|
-
```ts option='{ "fixMixedExportsWithInlineTypeSpecifier": true }'
|
|
100
|
-
export { Button, type ButtonProps } from 'some-library';
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
</TabItem>
|
|
104
|
-
</Tabs>
|
|
105
|
-
|
|
106
88
|
## When Not To Use It
|
|
107
89
|
|
|
108
90
|
If you use `--isolatedModules` the compiler would error if a type is not re-exported using `export type`.
|
|
@@ -16,8 +16,6 @@ It adds support for optional parameters.
|
|
|
16
16
|
<TabItem value="❌ Incorrect">
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
|
-
/* eslint @typescript-eslint/default-param-last: "error" */
|
|
20
|
-
|
|
21
19
|
function f(a = 0, b: number) {}
|
|
22
20
|
function f(a: number, b = 0, c: number) {}
|
|
23
21
|
function f(a: number, b?: number, c: number) {}
|
|
@@ -39,8 +37,6 @@ class Foo {
|
|
|
39
37
|
<TabItem value="✅ Correct">
|
|
40
38
|
|
|
41
39
|
```ts
|
|
42
|
-
/* eslint @typescript-eslint/default-param-last: "error" */
|
|
43
|
-
|
|
44
40
|
function f(a = 0) {}
|
|
45
41
|
function f(a: number, b = 0) {}
|
|
46
42
|
function f(a: number, b?: number) {}
|
|
@@ -97,20 +97,20 @@ If you are working on a codebase within which you lint non-TypeScript code (i.e.
|
|
|
97
97
|
|
|
98
98
|
### `allowArgumentsExplicitlyTypedAsAny`
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
When this option is `true`, the rule ignores arguments that are explicitly typed as any.
|
|
101
101
|
|
|
102
102
|
<Tabs>
|
|
103
|
-
<TabItem value="❌ Incorrect">
|
|
103
|
+
<TabItem value="❌ Incorrect for `allowArgumentsExplicitlyTypedAsAny: false`">
|
|
104
104
|
|
|
105
105
|
```ts option='{ "allowArgumentsExplicitlyTypedAsAny": false }'
|
|
106
106
|
export const func = (value: any): number => value + 1;
|
|
107
107
|
```
|
|
108
108
|
|
|
109
109
|
</TabItem>
|
|
110
|
-
<TabItem value="✅ Correct">
|
|
110
|
+
<TabItem value="✅ Correct for `allowArgumentsExplicitlyTypedAsAny: true`">
|
|
111
111
|
|
|
112
|
-
```ts option='{ "allowArgumentsExplicitlyTypedAsAny":
|
|
113
|
-
export const func = (value:
|
|
112
|
+
```ts option='{ "allowArgumentsExplicitlyTypedAsAny": true }'
|
|
113
|
+
export const func = (value: any): number => value + 1;
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
</TabItem>
|
|
@@ -118,12 +118,12 @@ export const func = (value: number): number => value + 1;
|
|
|
118
118
|
|
|
119
119
|
### `allowDirectConstAssertionInArrowFunctions`
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
When this option is `true`, the rule ignores return type annotations on body-less arrow functions that return an `as const` type assertion.
|
|
122
122
|
|
|
123
123
|
<Tabs>
|
|
124
|
-
<TabItem value="❌ Incorrect">
|
|
124
|
+
<TabItem value="❌ Incorrect for `allowDirectConstAssertionInArrowFunctions: false`">
|
|
125
125
|
|
|
126
|
-
```ts option='{ "
|
|
126
|
+
```ts option='{ "allowDirectConstAssertionInArrowFunctions": false }'
|
|
127
127
|
export const func = (value: number) => ({ type: 'X', value });
|
|
128
128
|
export const foo = () => ({
|
|
129
129
|
bar: true,
|
|
@@ -132,9 +132,9 @@ export const bar = () => 1;
|
|
|
132
132
|
```
|
|
133
133
|
|
|
134
134
|
</TabItem>
|
|
135
|
-
<TabItem value="✅ Correct">
|
|
135
|
+
<TabItem value="✅ Correct for `allowDirectConstAssertionInArrowFunctions: true`">
|
|
136
136
|
|
|
137
|
-
```ts option='{ "
|
|
137
|
+
```ts option='{ "allowDirectConstAssertionInArrowFunctions": true }'
|
|
138
138
|
export const func = (value: number) => ({ type: 'X', value }) as const;
|
|
139
139
|
export const foo = () =>
|
|
140
140
|
({
|
|
@@ -163,10 +163,10 @@ You may pass function/method names you would like this rule to ignore, like so:
|
|
|
163
163
|
|
|
164
164
|
### `allowHigherOrderFunctions`
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
When this option is `true`, the rule ignores return type annotations on function, which is immediately returning another function expression.
|
|
167
167
|
|
|
168
168
|
<Tabs>
|
|
169
|
-
<TabItem value="❌ Incorrect">
|
|
169
|
+
<TabItem value="❌ Incorrect for `allowHigherOrderFunctions: false`">
|
|
170
170
|
|
|
171
171
|
```ts option='{ "allowHigherOrderFunctions": false }'
|
|
172
172
|
export const arrowFn = () => () => {};
|
|
@@ -181,9 +181,9 @@ export function foo(outer: string) {
|
|
|
181
181
|
```
|
|
182
182
|
|
|
183
183
|
</TabItem>
|
|
184
|
-
<TabItem value="✅ Correct">
|
|
184
|
+
<TabItem value="✅ Correct for `allowHigherOrderFunctions: true`">
|
|
185
185
|
|
|
186
|
-
```ts option='{ "allowHigherOrderFunctions":
|
|
186
|
+
```ts option='{ "allowHigherOrderFunctions": true }'
|
|
187
187
|
export const arrowFn = () => (): void => {};
|
|
188
188
|
|
|
189
189
|
export function fn() {
|
|
@@ -200,10 +200,10 @@ export function foo(outer: string) {
|
|
|
200
200
|
|
|
201
201
|
### `allowTypedFunctionExpressions`
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
When this option is `true`, the rule ignores type annotations on the variable of a function expression.
|
|
204
204
|
|
|
205
205
|
<Tabs>
|
|
206
|
-
<TabItem value="❌ Incorrect">
|
|
206
|
+
<TabItem value="❌ Incorrect for `allowTypedFunctionExpressions: false`">
|
|
207
207
|
|
|
208
208
|
```ts option='{ "allowTypedFunctionExpressions": false }'
|
|
209
209
|
export let arrowFn = () => 'test';
|
|
@@ -220,9 +220,9 @@ export const foo = bar => {};
|
|
|
220
220
|
```
|
|
221
221
|
|
|
222
222
|
</TabItem>
|
|
223
|
-
<TabItem value="✅ Correct">
|
|
223
|
+
<TabItem value="✅ Correct for `allowTypedFunctionExpressions: true`">
|
|
224
224
|
|
|
225
|
-
```ts option='{ "allowTypedFunctionExpressions":
|
|
225
|
+
```ts option='{ "allowTypedFunctionExpressions": true }'
|
|
226
226
|
type FuncType = () => string;
|
|
227
227
|
|
|
228
228
|
export let arrowFn: FuncType = () => 'test';
|
|
@@ -1011,9 +1011,9 @@ interface Foo {
|
|
|
1011
1011
|
b(): void;
|
|
1012
1012
|
a: boolean;
|
|
1013
1013
|
|
|
1014
|
-
[a: string]: number;
|
|
1015
|
-
new (): Bar;
|
|
1016
|
-
(): Baz;
|
|
1014
|
+
[a: string]: number;
|
|
1015
|
+
new (): Bar;
|
|
1016
|
+
(): Baz;
|
|
1017
1017
|
}
|
|
1018
1018
|
```
|
|
1019
1019
|
|
|
@@ -1022,12 +1022,12 @@ interface Foo {
|
|
|
1022
1022
|
|
|
1023
1023
|
```ts option='{ "default": { "memberTypes": "never", "order": "alphabetically" } }'
|
|
1024
1024
|
interface Foo {
|
|
1025
|
+
[a: string]: number;
|
|
1025
1026
|
a: boolean;
|
|
1026
1027
|
b(): void;
|
|
1027
1028
|
|
|
1028
|
-
|
|
1029
|
-
new (): Bar;
|
|
1030
|
-
(): Baz; // Order doesn't matter (no sortable identifier)
|
|
1029
|
+
(): Baz;
|
|
1030
|
+
new (): Bar;
|
|
1031
1031
|
}
|
|
1032
1032
|
```
|
|
1033
1033
|
|
|
@@ -293,7 +293,7 @@ class NotEmptyClass {
|
|
|
293
293
|
|
|
294
294
|
### `allowWithDecorator`
|
|
295
295
|
|
|
296
|
-
The `allowWithDecorator` option adds an exemption for classes
|
|
296
|
+
The `allowWithDecorator` option adds an exemption for classes decorated with a `@` decorator.
|
|
297
297
|
|
|
298
298
|
<Tabs>
|
|
299
299
|
<TabItem value="❌ Incorrect">
|
|
@@ -308,8 +308,8 @@ class Constants {
|
|
|
308
308
|
<TabItem value="✅ Correct">
|
|
309
309
|
|
|
310
310
|
```ts option='{ "allowWithDecorator": true }'
|
|
311
|
+
@logOnRead()
|
|
311
312
|
class Constants {
|
|
312
|
-
@logOnRead()
|
|
313
313
|
static readonly version = 42;
|
|
314
314
|
}
|
|
315
315
|
```
|
|
@@ -104,7 +104,7 @@ This allows you to skip checking of async IIFEs (Immediately Invoked function Ex
|
|
|
104
104
|
|
|
105
105
|
Examples of **correct** code for this rule with `{ ignoreIIFE: true }`:
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
{/* prettier-ignore */}
|
|
108
108
|
```ts option='{ "ignoreIIFE": true }' showPlaygroundButton
|
|
109
109
|
await (async function () {
|
|
110
110
|
await res(1);
|
|
@@ -36,8 +36,6 @@ This rule aims to eliminate implied `eval()` through the use of `new Function()`
|
|
|
36
36
|
<TabItem value="❌ Incorrect">
|
|
37
37
|
|
|
38
38
|
```ts
|
|
39
|
-
/* eslint @typescript-eslint/no-implied-eval: "error" */
|
|
40
|
-
|
|
41
39
|
setTimeout('alert(`Hi!`);', 100);
|
|
42
40
|
|
|
43
41
|
setInterval('alert(`Hi!`);', 100);
|
|
@@ -65,8 +63,6 @@ const fn = new Function('a', 'b', 'return a + b');
|
|
|
65
63
|
<TabItem value="✅ Correct">
|
|
66
64
|
|
|
67
65
|
```ts
|
|
68
|
-
/* eslint @typescript-eslint/no-implied-eval: "error" */
|
|
69
|
-
|
|
70
66
|
setTimeout(function () {
|
|
71
67
|
alert('Hi!');
|
|
72
68
|
}, 100);
|
|
@@ -45,14 +45,14 @@ With `{allow: ['/package\\.json$']}`:
|
|
|
45
45
|
<Tabs>
|
|
46
46
|
<TabItem value="❌ Incorrect">
|
|
47
47
|
|
|
48
|
-
```ts
|
|
48
|
+
```ts option='{ "allow": ["/package.json$"] }'
|
|
49
49
|
console.log(require('../data.json').version);
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
</TabItem>
|
|
53
53
|
<TabItem value="✅ Correct">
|
|
54
54
|
|
|
55
|
-
```ts
|
|
55
|
+
```ts option='{ "allow": ["/package.json$"] }'
|
|
56
56
|
console.log(require('../package.json').version);
|
|
57
57
|
```
|
|
58
58
|
|
|
@@ -24,17 +24,17 @@ const bar = foo!;
|
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
```ts
|
|
27
|
-
const foo = <
|
|
27
|
+
const foo = <number>(3 + 5);
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
```ts
|
|
31
|
-
type Foo =
|
|
32
|
-
const foo = <Foo>3;
|
|
31
|
+
type Foo = number;
|
|
32
|
+
const foo = <Foo>(3 + 5);
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
```ts
|
|
36
|
-
type Foo =
|
|
37
|
-
const foo = 3 as Foo;
|
|
36
|
+
type Foo = number;
|
|
37
|
+
const foo = (3 + 5) as Foo;
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
```ts
|
|
@@ -45,14 +45,14 @@ With `{allow: ['/package\\.json$']}`:
|
|
|
45
45
|
<Tabs>
|
|
46
46
|
<TabItem value="❌ Incorrect">
|
|
47
47
|
|
|
48
|
-
```ts
|
|
48
|
+
```ts option='{ "allow": ["/package.json$"] }'
|
|
49
49
|
const foo = require('../data.json');
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
</TabItem>
|
|
53
53
|
<TabItem value="✅ Correct">
|
|
54
54
|
|
|
55
|
-
```ts
|
|
55
|
+
```ts option='{ "allow": ["/package.json$"] }'
|
|
56
56
|
const foo = require('../package.json');
|
|
57
57
|
```
|
|
58
58
|
|
|
@@ -23,7 +23,7 @@ This rule reports when an `as` cast is doing the same job as a `!` would, and su
|
|
|
23
23
|
<TabItem value="❌ Incorrect">
|
|
24
24
|
|
|
25
25
|
```ts
|
|
26
|
-
const maybe = Math.random() > 0.5 ? '' : undefined;
|
|
26
|
+
const maybe: string | undefined = Math.random() > 0.5 ? '' : undefined;
|
|
27
27
|
|
|
28
28
|
const definitely = maybe as string;
|
|
29
29
|
const alsoDefinitely = <string>maybe;
|
|
@@ -33,7 +33,7 @@ const alsoDefinitely = <string>maybe;
|
|
|
33
33
|
<TabItem value="✅ Correct">
|
|
34
34
|
|
|
35
35
|
```ts
|
|
36
|
-
const maybe = Math.random() > 0.5 ? '' : undefined;
|
|
36
|
+
const maybe: string | undefined = Math.random() > 0.5 ? '' : undefined;
|
|
37
37
|
|
|
38
38
|
const definitely = maybe!;
|
|
39
39
|
const alsoDefinitely = maybe!;
|
|
@@ -39,10 +39,10 @@ throw `${err}`;
|
|
|
39
39
|
const err = '';
|
|
40
40
|
throw err;
|
|
41
41
|
|
|
42
|
-
function
|
|
42
|
+
function getError() {
|
|
43
43
|
return '';
|
|
44
44
|
}
|
|
45
|
-
throw
|
|
45
|
+
throw getError();
|
|
46
46
|
|
|
47
47
|
const foo = {
|
|
48
48
|
bar: '',
|
|
@@ -70,10 +70,10 @@ try {
|
|
|
70
70
|
const err = new Error();
|
|
71
71
|
throw err;
|
|
72
72
|
|
|
73
|
-
function
|
|
73
|
+
function getError() {
|
|
74
74
|
return new Error();
|
|
75
75
|
}
|
|
76
|
-
throw
|
|
76
|
+
throw getError();
|
|
77
77
|
|
|
78
78
|
const foo = {
|
|
79
79
|
bar: new Error(),
|
|
@@ -87,14 +87,14 @@ Examples with `{ enforceForDeclarationWithTypeAnnotation: true }`:
|
|
|
87
87
|
<Tabs>
|
|
88
88
|
<TabItem value="❌ Incorrect">
|
|
89
89
|
|
|
90
|
-
```ts
|
|
90
|
+
```ts option='{ "object": true }, { "enforceForDeclarationWithTypeAnnotation": true }'
|
|
91
91
|
const x: string = obj.x;
|
|
92
92
|
```
|
|
93
93
|
|
|
94
94
|
</TabItem>
|
|
95
95
|
<TabItem value="✅ Correct">
|
|
96
96
|
|
|
97
|
-
```ts
|
|
97
|
+
```ts option='{ "object": true }, { "enforceForDeclarationWithTypeAnnotation": true }'
|
|
98
98
|
const { x }: { x: string } = obj;
|
|
99
99
|
```
|
|
100
100
|
|
|
@@ -199,12 +199,26 @@ thing && thing.toString();
|
|
|
199
199
|
|
|
200
200
|
When this option is `true` the rule will check operands that are typed as `boolean` when inspecting "loose boolean" operands.
|
|
201
201
|
|
|
202
|
+
:::note
|
|
203
|
+
|
|
204
|
+
This rule intentionally ignores the following case:
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
declare const x: false | { a: string };
|
|
208
|
+
x && x.a;
|
|
209
|
+
!x || x.a;
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
The boolean expression narrows out the non-nullish falsy cases - so converting the chain to `x?.a` would introduce a type error.
|
|
213
|
+
|
|
214
|
+
:::
|
|
215
|
+
|
|
202
216
|
<Tabs>
|
|
203
217
|
|
|
204
218
|
<TabItem value="❌ Incorrect for `checkBoolean: true`">
|
|
205
219
|
|
|
206
220
|
```ts option='{ "checkBoolean": true }'
|
|
207
|
-
declare const thing:
|
|
221
|
+
declare const thing: true;
|
|
208
222
|
|
|
209
223
|
thing && thing.toString();
|
|
210
224
|
```
|
|
@@ -214,7 +228,7 @@ thing && thing.toString();
|
|
|
214
228
|
for `checkBoolean: false`
|
|
215
229
|
|
|
216
230
|
```ts option='{ "checkBoolean": false }'
|
|
217
|
-
declare const thing:
|
|
231
|
+
declare const thing: true;
|
|
218
232
|
|
|
219
233
|
thing && thing.toString();
|
|
220
234
|
```
|
|
@@ -257,7 +271,7 @@ When this option is `true` the rule will skip operands that are not typed with `
|
|
|
257
271
|
|
|
258
272
|
<TabItem value="❌ Incorrect for `requireNullish: true`">
|
|
259
273
|
|
|
260
|
-
```ts option='{ "requireNullish": true }'
|
|
274
|
+
```ts option='{ "requireNullish": true }' skipValidation
|
|
261
275
|
declare const thing1: string | null;
|
|
262
276
|
thing1 && thing1.toString();
|
|
263
277
|
```
|
|
@@ -303,7 +303,7 @@ Examples of code for this rule with `{ignoreInferredTypes: true}`:
|
|
|
303
303
|
<Tabs>
|
|
304
304
|
<TabItem value="❌ Incorrect">
|
|
305
305
|
|
|
306
|
-
```ts option='{ "ignoreInferredTypes": true }'
|
|
306
|
+
```ts option='{ "ignoreInferredTypes": true }' skipValidation
|
|
307
307
|
import { acceptsCallback, CallbackOptions } from 'external-dependency';
|
|
308
308
|
|
|
309
309
|
acceptsCallback((options: CallbackOptions) => {});
|
|
@@ -336,7 +336,7 @@ acceptsCallback(options => {});
|
|
|
336
336
|
<details>
|
|
337
337
|
<summary>external-dependency.d.ts</summary>
|
|
338
338
|
|
|
339
|
-
```ts option='{ "ignoreInferredTypes": true }'
|
|
339
|
+
```ts option='{ "ignoreInferredTypes": true }' skipValidation
|
|
340
340
|
export interface CallbackOptions {
|
|
341
341
|
prop: string;
|
|
342
342
|
}
|
|
@@ -101,7 +101,7 @@ Examples of code with `{ "allowedPromiseNames": ["Bluebird"] }`:
|
|
|
101
101
|
<TabItem value="❌ Incorrect">
|
|
102
102
|
|
|
103
103
|
```ts option='{ "allowedPromiseNames": ["Bluebird"] }'
|
|
104
|
-
|
|
104
|
+
class Bluebird {}
|
|
105
105
|
|
|
106
106
|
const returnsBluebird = () => new Bluebird(() => {});
|
|
107
107
|
```
|
|
@@ -110,7 +110,7 @@ const returnsBluebird = () => new Bluebird(() => {});
|
|
|
110
110
|
<TabItem value="✅ Correct">
|
|
111
111
|
|
|
112
112
|
```ts option='{ "allowedPromiseNames": ["Bluebird"] }'
|
|
113
|
-
|
|
113
|
+
class Bluebird {}
|
|
114
114
|
|
|
115
115
|
const returnsBluebird = async () => new Bluebird(() => {});
|
|
116
116
|
```
|
|
@@ -196,23 +196,23 @@ Examples of code for this rule with `{ skipCompoundAssignments: false }`:
|
|
|
196
196
|
<Tabs>
|
|
197
197
|
<TabItem value="❌ Incorrect">
|
|
198
198
|
|
|
199
|
-
```ts option='{ "skipCompoundAssignments":
|
|
200
|
-
let foo:
|
|
201
|
-
foo +=
|
|
199
|
+
```ts option='{ "skipCompoundAssignments": false }'
|
|
200
|
+
let foo: bigint = 0n;
|
|
201
|
+
foo += 1;
|
|
202
202
|
|
|
203
|
-
let bar:
|
|
204
|
-
bar +=
|
|
203
|
+
let bar: number[] = [1];
|
|
204
|
+
bar += 1;
|
|
205
205
|
```
|
|
206
206
|
|
|
207
207
|
</TabItem>
|
|
208
208
|
<TabItem value="✅ Correct">
|
|
209
209
|
|
|
210
|
-
```ts option='{ "skipCompoundAssignments":
|
|
211
|
-
let foo:
|
|
212
|
-
foo +=
|
|
210
|
+
```ts option='{ "skipCompoundAssignments": false }'
|
|
211
|
+
let foo: bigint = 0n;
|
|
212
|
+
foo += 1n;
|
|
213
213
|
|
|
214
|
-
let bar =
|
|
215
|
-
bar +=
|
|
214
|
+
let bar: number = 1;
|
|
215
|
+
bar += 1;
|
|
216
216
|
```
|
|
217
217
|
|
|
218
218
|
</TabItem>
|
|
@@ -61,12 +61,6 @@ while (obj) {
|
|
|
61
61
|
<TabItem value="✅ Correct">
|
|
62
62
|
|
|
63
63
|
```tsx
|
|
64
|
-
// Using logical operator short-circuiting is allowed
|
|
65
|
-
const Component = () => {
|
|
66
|
-
const entry = map.get('foo') || {};
|
|
67
|
-
return entry && <p>Name: {entry.name}</p>;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
64
|
// nullable values should be checked explicitly against null or undefined
|
|
71
65
|
let num: number | undefined = 0;
|
|
72
66
|
if (num != null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
|
3
|
-
"version": "7.5.1-alpha.
|
|
3
|
+
"version": "7.5.1-alpha.6",
|
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -62,10 +62,10 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@eslint-community/regexpp": "^4.5.1",
|
|
65
|
-
"@typescript-eslint/scope-manager": "7.5.1-alpha.
|
|
66
|
-
"@typescript-eslint/type-utils": "7.5.1-alpha.
|
|
67
|
-
"@typescript-eslint/utils": "7.5.1-alpha.
|
|
68
|
-
"@typescript-eslint/visitor-keys": "7.5.1-alpha.
|
|
65
|
+
"@typescript-eslint/scope-manager": "7.5.1-alpha.6",
|
|
66
|
+
"@typescript-eslint/type-utils": "7.5.1-alpha.6",
|
|
67
|
+
"@typescript-eslint/utils": "7.5.1-alpha.6",
|
|
68
|
+
"@typescript-eslint/visitor-keys": "7.5.1-alpha.6",
|
|
69
69
|
"debug": "^4.3.4",
|
|
70
70
|
"graphemer": "^1.4.0",
|
|
71
71
|
"ignore": "^5.2.4",
|
|
@@ -76,9 +76,10 @@
|
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@types/debug": "*",
|
|
78
78
|
"@types/marked": "*",
|
|
79
|
+
"@types/mdast": "^4.0.3",
|
|
79
80
|
"@types/natural-compare": "*",
|
|
80
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "7.5.1-alpha.
|
|
81
|
-
"@typescript-eslint/rule-tester": "7.5.1-alpha.
|
|
81
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "7.5.1-alpha.6",
|
|
82
|
+
"@typescript-eslint/rule-tester": "7.5.1-alpha.6",
|
|
82
83
|
"ajv": "^6.12.6",
|
|
83
84
|
"chalk": "^5.3.0",
|
|
84
85
|
"cross-env": "^7.0.3",
|
|
@@ -90,11 +91,15 @@
|
|
|
90
91
|
"json-schema": "*",
|
|
91
92
|
"markdown-table": "^3.0.3",
|
|
92
93
|
"marked": "^5.1.1",
|
|
94
|
+
"mdast-util-from-markdown": "^2.0.0",
|
|
95
|
+
"mdast-util-mdx": "^3.0.0",
|
|
96
|
+
"micromark-extension-mdxjs": "^3.0.0",
|
|
93
97
|
"prettier": "^3.0.3",
|
|
94
98
|
"rimraf": "*",
|
|
95
99
|
"title-case": "^3.0.3",
|
|
96
100
|
"tsx": "*",
|
|
97
|
-
"typescript": "*"
|
|
101
|
+
"typescript": "*",
|
|
102
|
+
"unist-util-visit": "^5.0.0"
|
|
98
103
|
},
|
|
99
104
|
"peerDependencies": {
|
|
100
105
|
"@typescript-eslint/parser": "^7.0.0",
|