@typescript-eslint/eslint-plugin 8.33.1-alpha.5 → 8.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -10
- package/docs/rules/README.md +0 -57
- package/docs/rules/TEMPLATE.md +0 -36
- package/docs/rules/adjacent-overload-signatures.mdx +0 -105
- package/docs/rules/array-type.mdx +0 -126
- package/docs/rules/await-thenable.mdx +0 -184
- package/docs/rules/ban-ts-comment.mdx +0 -165
- package/docs/rules/ban-tslint-comment.mdx +0 -45
- package/docs/rules/ban-types.md +0 -26
- package/docs/rules/block-spacing.md +0 -15
- package/docs/rules/brace-style.md +0 -15
- package/docs/rules/camelcase.md +0 -15
- package/docs/rules/class-literal-property-style.mdx +0 -112
- package/docs/rules/class-methods-use-this.mdx +0 -135
- package/docs/rules/comma-dangle.md +0 -15
- package/docs/rules/comma-spacing.md +0 -15
- package/docs/rules/consistent-generic-constructors.mdx +0 -87
- package/docs/rules/consistent-indexed-object-style.mdx +0 -105
- package/docs/rules/consistent-return.mdx +0 -51
- package/docs/rules/consistent-type-assertions.mdx +0 -196
- package/docs/rules/consistent-type-definitions.mdx +0 -133
- package/docs/rules/consistent-type-exports.mdx +0 -97
- package/docs/rules/consistent-type-imports.mdx +0 -139
- package/docs/rules/default-param-last.mdx +0 -59
- package/docs/rules/dot-notation.mdx +0 -94
- package/docs/rules/explicit-function-return-type.mdx +0 -359
- package/docs/rules/explicit-member-accessibility.mdx +0 -353
- package/docs/rules/explicit-module-boundary-types.mdx +0 -287
- package/docs/rules/func-call-spacing.md +0 -15
- package/docs/rules/indent.md +0 -15
- package/docs/rules/init-declarations.mdx +0 -12
- package/docs/rules/key-spacing.md +0 -15
- package/docs/rules/keyword-spacing.md +0 -15
- package/docs/rules/lines-around-comment.md +0 -15
- package/docs/rules/lines-between-class-members.md +0 -15
- package/docs/rules/max-params.mdx +0 -54
- package/docs/rules/member-delimiter-style.md +0 -15
- package/docs/rules/member-ordering.mdx +0 -1483
- package/docs/rules/method-signature-style.mdx +0 -124
- package/docs/rules/naming-convention.mdx +0 -755
- package/docs/rules/no-array-constructor.mdx +0 -34
- package/docs/rules/no-array-delete.mdx +0 -44
- package/docs/rules/no-base-to-string.mdx +0 -115
- package/docs/rules/no-confusing-non-null-assertion.mdx +0 -75
- package/docs/rules/no-confusing-void-expression.mdx +0 -148
- package/docs/rules/no-deprecated.mdx +0 -119
- package/docs/rules/no-dupe-class-members.mdx +0 -16
- package/docs/rules/no-duplicate-enum-values.mdx +0 -66
- package/docs/rules/no-duplicate-imports.mdx +0 -17
- package/docs/rules/no-duplicate-type-constituents.mdx +0 -89
- package/docs/rules/no-dynamic-delete.mdx +0 -64
- package/docs/rules/no-empty-function.mdx +0 -94
- package/docs/rules/no-empty-interface.mdx +0 -75
- package/docs/rules/no-empty-object-type.mdx +0 -150
- package/docs/rules/no-explicit-any.mdx +0 -177
- package/docs/rules/no-extra-non-null-assertion.mdx +0 -60
- package/docs/rules/no-extra-parens.md +0 -15
- package/docs/rules/no-extra-semi.md +0 -15
- package/docs/rules/no-extraneous-class.mdx +0 -329
- package/docs/rules/no-floating-promises.mdx +0 -282
- package/docs/rules/no-for-in-array.mdx +0 -67
- package/docs/rules/no-implied-eval.mdx +0 -106
- package/docs/rules/no-import-type-side-effects.mdx +0 -80
- package/docs/rules/no-inferrable-types.mdx +0 -113
- package/docs/rules/no-invalid-this.mdx +0 -16
- package/docs/rules/no-invalid-void-type.mdx +0 -119
- package/docs/rules/no-loop-func.mdx +0 -12
- package/docs/rules/no-loss-of-precision.mdx +0 -17
- package/docs/rules/no-magic-numbers.mdx +0 -131
- package/docs/rules/no-meaningless-void-operator.mdx +0 -61
- package/docs/rules/no-misused-new.mdx +0 -53
- package/docs/rules/no-misused-promises.mdx +0 -314
- package/docs/rules/no-misused-spread.mdx +0 -132
- package/docs/rules/no-mixed-enums.mdx +0 -96
- package/docs/rules/no-namespace.mdx +0 -157
- package/docs/rules/no-non-null-asserted-nullish-coalescing.mdx +0 -60
- package/docs/rules/no-non-null-asserted-optional-chain.mdx +0 -46
- package/docs/rules/no-non-null-assertion.mdx +0 -48
- package/docs/rules/no-parameter-properties.mdx +0 -16
- package/docs/rules/no-redeclare.mdx +0 -79
- package/docs/rules/no-redundant-type-constituents.mdx +0 -102
- package/docs/rules/no-require-imports.mdx +0 -114
- package/docs/rules/no-restricted-imports.mdx +0 -84
- package/docs/rules/no-restricted-types.mdx +0 -70
- package/docs/rules/no-shadow.mdx +0 -143
- package/docs/rules/no-this-alias.mdx +0 -124
- package/docs/rules/no-type-alias.mdx +0 -626
- package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +0 -165
- package/docs/rules/no-unnecessary-condition.mdx +0 -293
- package/docs/rules/no-unnecessary-parameter-property-assignment.mdx +0 -42
- package/docs/rules/no-unnecessary-qualifier.mdx +0 -57
- package/docs/rules/no-unnecessary-template-expression.mdx +0 -108
- package/docs/rules/no-unnecessary-type-arguments.mdx +0 -85
- package/docs/rules/no-unnecessary-type-assertion.mdx +0 -97
- package/docs/rules/no-unnecessary-type-constraint.mdx +0 -61
- package/docs/rules/no-unnecessary-type-conversion.mdx +0 -79
- package/docs/rules/no-unnecessary-type-parameters.mdx +0 -255
- package/docs/rules/no-unsafe-argument.mdx +0 -98
- package/docs/rules/no-unsafe-assignment.mdx +0 -101
- package/docs/rules/no-unsafe-call.mdx +0 -120
- package/docs/rules/no-unsafe-declaration-merging.mdx +0 -65
- package/docs/rules/no-unsafe-enum-comparison.mdx +0 -98
- package/docs/rules/no-unsafe-function-type.mdx +0 -65
- package/docs/rules/no-unsafe-member-access.mdx +0 -81
- package/docs/rules/no-unsafe-return.mdx +0 -126
- package/docs/rules/no-unsafe-type-assertion.mdx +0 -63
- package/docs/rules/no-unsafe-unary-minus.mdx +0 -60
- package/docs/rules/no-unused-expressions.mdx +0 -52
- package/docs/rules/no-unused-vars.mdx +0 -136
- package/docs/rules/no-use-before-define.mdx +0 -98
- package/docs/rules/no-useless-constructor.mdx +0 -21
- package/docs/rules/no-useless-empty-export.mdx +0 -53
- package/docs/rules/no-useless-template-literals.mdx +0 -9
- package/docs/rules/no-var-requires.mdx +0 -77
- package/docs/rules/no-wrapper-object-types.mdx +0 -75
- package/docs/rules/non-nullable-type-assertion-style.mdx +0 -47
- package/docs/rules/object-curly-spacing.md +0 -15
- package/docs/rules/only-throw-error.mdx +0 -150
- package/docs/rules/padding-line-between-statements.md +0 -15
- package/docs/rules/parameter-properties.mdx +0 -522
- package/docs/rules/prefer-as-const.mdx +0 -51
- package/docs/rules/prefer-destructuring.mdx +0 -101
- package/docs/rules/prefer-enum-initializers.mdx +0 -68
- package/docs/rules/prefer-find.mdx +0 -45
- package/docs/rules/prefer-for-of.mdx +0 -50
- package/docs/rules/prefer-function-type.mdx +0 -98
- package/docs/rules/prefer-includes.mdx +0 -81
- package/docs/rules/prefer-literal-enum-member.mdx +0 -111
- package/docs/rules/prefer-namespace-keyword.mdx +0 -51
- package/docs/rules/prefer-nullish-coalescing.mdx +0 -349
- package/docs/rules/prefer-optional-chain.mdx +0 -304
- package/docs/rules/prefer-promise-reject-errors.mdx +0 -78
- package/docs/rules/prefer-readonly-parameter-types.mdx +0 -408
- package/docs/rules/prefer-readonly.mdx +0 -111
- package/docs/rules/prefer-reduce-type-parameter.mdx +0 -66
- package/docs/rules/prefer-regexp-exec.mdx +0 -52
- package/docs/rules/prefer-return-this-type.mdx +0 -93
- package/docs/rules/prefer-string-starts-ends-with.mdx +0 -84
- package/docs/rules/prefer-ts-expect-error.mdx +0 -86
- package/docs/rules/promise-function-async.mdx +0 -143
- package/docs/rules/quotes.md +0 -15
- package/docs/rules/related-getter-setter-pairs.mdx +0 -61
- package/docs/rules/require-array-sort-compare.mdx +0 -89
- package/docs/rules/require-await.mdx +0 -53
- package/docs/rules/restrict-plus-operands.mdx +0 -245
- package/docs/rules/restrict-template-expressions.mdx +0 -167
- package/docs/rules/return-await.mdx +0 -339
- package/docs/rules/semi.md +0 -15
- package/docs/rules/sort-type-constituents.mdx +0 -209
- package/docs/rules/sort-type-union-intersection-members.mdx +0 -16
- package/docs/rules/space-before-blocks.md +0 -15
- package/docs/rules/space-before-function-paren.md +0 -15
- package/docs/rules/space-infix-ops.md +0 -15
- package/docs/rules/strict-boolean-expressions.mdx +0 -184
- package/docs/rules/switch-exhaustiveness-check.mdx +0 -280
- package/docs/rules/triple-slash-reference.mdx +0 -129
- package/docs/rules/type-annotation-spacing.md +0 -15
- package/docs/rules/typedef.mdx +0 -350
- package/docs/rules/unbound-method.mdx +0 -114
- package/docs/rules/unified-signatures.mdx +0 -132
- package/docs/rules/use-unknown-in-catch-callback-variable.mdx +0 -97
@@ -1,34 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow generic `Array` constructors.'
|
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-array-constructor** for documentation.
|
11
|
-
|
12
|
-
It adds support for the generically typed `Array` constructor (`new Array<Foo>()`).
|
13
|
-
|
14
|
-
<Tabs>
|
15
|
-
<TabItem value="❌ Incorrect">
|
16
|
-
|
17
|
-
```ts
|
18
|
-
Array(0, 1, 2);
|
19
|
-
new Array(0, 1, 2);
|
20
|
-
```
|
21
|
-
|
22
|
-
</TabItem>
|
23
|
-
<TabItem value="✅ Correct">
|
24
|
-
|
25
|
-
```ts
|
26
|
-
Array<number>(0, 1, 2);
|
27
|
-
new Array<Foo>(x, y, z);
|
28
|
-
|
29
|
-
Array(500);
|
30
|
-
new Array(someOtherArray.length);
|
31
|
-
```
|
32
|
-
|
33
|
-
</TabItem>
|
34
|
-
</Tabs>
|
@@ -1,44 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow using the `delete` operator on array values.'
|
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-array-delete** for documentation.
|
11
|
-
|
12
|
-
When using the `delete` operator with an array value, the array's `length` property is not affected,
|
13
|
-
but the element at the specified index is removed and leaves an empty slot in the array.
|
14
|
-
This is likely to lead to unexpected behavior. As mentioned in the
|
15
|
-
[MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete#deleting_array_elements),
|
16
|
-
the recommended way to remove an element from an array is by using the
|
17
|
-
[`Array#splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) method.
|
18
|
-
|
19
|
-
## Examples
|
20
|
-
|
21
|
-
<Tabs>
|
22
|
-
<TabItem value="❌ Incorrect">
|
23
|
-
|
24
|
-
```ts
|
25
|
-
declare const arr: number[];
|
26
|
-
|
27
|
-
delete arr[0];
|
28
|
-
```
|
29
|
-
|
30
|
-
</TabItem>
|
31
|
-
<TabItem value="✅ Correct">
|
32
|
-
|
33
|
-
```ts
|
34
|
-
declare const arr: number[];
|
35
|
-
|
36
|
-
arr.splice(0, 1);
|
37
|
-
```
|
38
|
-
|
39
|
-
</TabItem>
|
40
|
-
</Tabs>
|
41
|
-
|
42
|
-
## When Not To Use It
|
43
|
-
|
44
|
-
When you want to allow the delete operator with array expressions.
|
@@ -1,115 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Require `.toString()` and `.toLocaleString()` to only be called on objects which provide useful information when stringified.'
|
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-base-to-string** for documentation.
|
11
|
-
|
12
|
-
JavaScript will call `toString()` on an object when it is converted to a string, such as when concatenated with a string (`expr + ''`), when interpolated into template literals (`${expr}`), or when passed as an argument to the String constructor (`String(expr)`).
|
13
|
-
The default Object `.toString()` and `toLocaleString()` use the format `"[object Object]"`, which is often not what was intended.
|
14
|
-
This rule reports on stringified values that aren't primitives and don't define a more useful `.toString()` or `toLocaleString()` method.
|
15
|
-
|
16
|
-
> Note that `Function` provides its own `.toString()` and `toLocaleString()` that return the function's code.
|
17
|
-
> Functions are not flagged by this rule.
|
18
|
-
|
19
|
-
## Examples
|
20
|
-
|
21
|
-
<Tabs>
|
22
|
-
<TabItem value="❌ Incorrect">
|
23
|
-
|
24
|
-
```ts
|
25
|
-
// Passing an object or class instance to string concatenation:
|
26
|
-
'' + {};
|
27
|
-
|
28
|
-
class MyClass {}
|
29
|
-
const value = new MyClass();
|
30
|
-
value + '';
|
31
|
-
|
32
|
-
// Interpolation and manual .toString() and `toLocaleString()` calls too:
|
33
|
-
`Value: ${value}`;
|
34
|
-
String({});
|
35
|
-
({}).toString();
|
36
|
-
({}).toLocaleString();
|
37
|
-
|
38
|
-
// Stringifying objects or instances in an array with the `Array.prototype.join`.
|
39
|
-
[{}, new MyClass()].join('');
|
40
|
-
```
|
41
|
-
|
42
|
-
</TabItem>
|
43
|
-
<TabItem value="✅ Correct">
|
44
|
-
|
45
|
-
```ts
|
46
|
-
// These types all have useful .toString() and `toLocaleString()` methods
|
47
|
-
'Text' + true;
|
48
|
-
`Value: ${123}`;
|
49
|
-
`Arrays too: ${[1, 2, 3]}`;
|
50
|
-
(() => {}).toString();
|
51
|
-
String(42);
|
52
|
-
(() => {}).toLocaleString();
|
53
|
-
|
54
|
-
// Defining a custom .toString class is considered acceptable
|
55
|
-
class CustomToString {
|
56
|
-
toString() {
|
57
|
-
return 'Hello, world!';
|
58
|
-
}
|
59
|
-
}
|
60
|
-
`Value: ${new CustomToString()}`;
|
61
|
-
|
62
|
-
const literalWithToString = {
|
63
|
-
toString: () => 'Hello, world!',
|
64
|
-
};
|
65
|
-
|
66
|
-
`Value: ${literalWithToString}`;
|
67
|
-
```
|
68
|
-
|
69
|
-
</TabItem>
|
70
|
-
</Tabs>
|
71
|
-
|
72
|
-
## Alternatives
|
73
|
-
|
74
|
-
Consider using `JSON.stringify` when you want to convert non-primitive things to string for logging, debugging, etc.
|
75
|
-
|
76
|
-
```typescript
|
77
|
-
declare const o: object;
|
78
|
-
const errorMessage = 'Found unexpected value: ' + JSON.stringify(o);
|
79
|
-
```
|
80
|
-
|
81
|
-
## Options
|
82
|
-
|
83
|
-
### `ignoredTypeNames`
|
84
|
-
|
85
|
-
{/* insert option description */}
|
86
|
-
|
87
|
-
This is useful for types missing `toString()` or `toLocaleString()` (but actually has `toString()` or `toLocaleString()`).
|
88
|
-
There are some types missing `toString()` or `toLocaleString()` in old versions of TypeScript, like `RegExp`, `URL`, `URLSearchParams` etc.
|
89
|
-
|
90
|
-
The following patterns are considered correct with the default options `{ ignoredTypeNames: ["RegExp"] }`:
|
91
|
-
|
92
|
-
```ts option='{ "ignoredTypeNames": ["RegExp"] }' showPlaygroundButton
|
93
|
-
`${/regex/}`;
|
94
|
-
'' + /regex/;
|
95
|
-
/regex/.toString();
|
96
|
-
let value = /regex/;
|
97
|
-
value.toString();
|
98
|
-
let text = `${value}`;
|
99
|
-
String(/regex/);
|
100
|
-
```
|
101
|
-
|
102
|
-
## When Not To Use It
|
103
|
-
|
104
|
-
If you don't mind a risk of `"[object Object]"` or incorrect type coercions in your values, then you will not need this rule.
|
105
|
-
|
106
|
-
## Related To
|
107
|
-
|
108
|
-
- [`restrict-plus-operands`](./restrict-plus-operands.mdx)
|
109
|
-
- [`restrict-template-expressions`](./restrict-template-expressions.mdx)
|
110
|
-
|
111
|
-
## Further Reading
|
112
|
-
|
113
|
-
- [`Object.prototype.toString()` MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
|
114
|
-
- [`Object.prototype.toLocaleString()` MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
|
115
|
-
- [Microsoft/TypeScript Add missing toString declarations for base types that have them](https://github.com/microsoft/TypeScript/issues/38347)
|
@@ -1,75 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow non-null assertion in locations that may be confusing.'
|
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-confusing-non-null-assertion** for documentation.
|
11
|
-
|
12
|
-
Using a non-null assertion (`!`) next to an assignment or equality check (`=` or `==` or `===`) creates code that is confusing as it looks similar to an inequality check (`!=` `!==`).
|
13
|
-
|
14
|
-
```typescript
|
15
|
-
a! == b; // a non-null assertion(`!`) and an equals test(`==`)
|
16
|
-
a !== b; // not equals test(`!==`)
|
17
|
-
a! === b; // a non-null assertion(`!`) and a triple equals test(`===`)
|
18
|
-
```
|
19
|
-
|
20
|
-
Using a non-null assertion (`!`) next to an in test (`in`) or an instanceof test (`instanceof`) creates code that is confusing since it may look like the operator is negated, but it is actually not.
|
21
|
-
|
22
|
-
{/* prettier-ignore */}
|
23
|
-
```typescript
|
24
|
-
a! in b; // a non-null assertion(`!`) and an in test(`in`)
|
25
|
-
a !in b; // also a non-null assertion(`!`) and an in test(`in`)
|
26
|
-
!(a in b); // a negated in test
|
27
|
-
|
28
|
-
a! instanceof b; // a non-null assertion(`!`) and an instanceof test(`instanceof`)
|
29
|
-
a !instanceof b; // also a non-null assertion(`!`) and an instanceof test(`instanceof`)
|
30
|
-
!(a instanceof b); // a negated instanceof test
|
31
|
-
````
|
32
|
-
|
33
|
-
This rule flags confusing `!` assertions and suggests either removing them or wrapping the asserted expression in `()` parenthesis.
|
34
|
-
|
35
|
-
## Examples
|
36
|
-
|
37
|
-
<Tabs>
|
38
|
-
<TabItem value="❌ Incorrect">
|
39
|
-
|
40
|
-
```ts
|
41
|
-
interface Foo {
|
42
|
-
bar?: string;
|
43
|
-
num?: number;
|
44
|
-
}
|
45
|
-
|
46
|
-
const foo: Foo = getFoo();
|
47
|
-
const isEqualsBar = foo.bar! == 'hello';
|
48
|
-
const isEqualsNum = 1 + foo.num! == 2;
|
49
|
-
```
|
50
|
-
|
51
|
-
</TabItem>
|
52
|
-
<TabItem value="✅ Correct">
|
53
|
-
|
54
|
-
{/* prettier-ignore */}
|
55
|
-
```ts
|
56
|
-
interface Foo {
|
57
|
-
bar?: string;
|
58
|
-
num?: number;
|
59
|
-
}
|
60
|
-
|
61
|
-
const foo: Foo = getFoo();
|
62
|
-
const isEqualsBar = foo.bar == 'hello';
|
63
|
-
const isEqualsNum = (1 + foo.num!) == 2;
|
64
|
-
```
|
65
|
-
|
66
|
-
</TabItem>
|
67
|
-
</Tabs>
|
68
|
-
|
69
|
-
## When Not To Use It
|
70
|
-
|
71
|
-
If you don't care about this confusion, then you will not need this rule.
|
72
|
-
|
73
|
-
## Further Reading
|
74
|
-
|
75
|
-
- [`Issue: Easy misunderstanding: "! ==="`](https://github.com/microsoft/TypeScript/issues/37837) in [TypeScript repo](https://github.com/microsoft/TypeScript)
|
@@ -1,148 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Require expressions of type void to appear in statement position.'
|
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-confusing-void-expression** for documentation.
|
11
|
-
|
12
|
-
`void` in TypeScript refers to a function return that is meant to be ignored.
|
13
|
-
Attempting to use a `void`-typed value, such as storing the result of a called function in a variable, is often a sign of a programmer error.
|
14
|
-
`void` can also be misleading for other developers even if used correctly.
|
15
|
-
|
16
|
-
This rule prevents `void` type expressions from being used in misleading locations such as being assigned to a variable, provided as a function argument, or returned from a function.
|
17
|
-
|
18
|
-
## Examples
|
19
|
-
|
20
|
-
<Tabs>
|
21
|
-
<TabItem value="❌ Incorrect">
|
22
|
-
|
23
|
-
```ts
|
24
|
-
// somebody forgot that `alert` doesn't return anything
|
25
|
-
const response = alert('Are you sure?');
|
26
|
-
console.log(alert('Are you sure?'));
|
27
|
-
|
28
|
-
// it's not obvious whether the chained promise will contain the response (fixable)
|
29
|
-
promise.then(value => window.postMessage(value));
|
30
|
-
|
31
|
-
// it looks like we are returning the result of `console.error` (fixable)
|
32
|
-
function doSomething() {
|
33
|
-
if (!somethingToDo) {
|
34
|
-
return console.error('Nothing to do!');
|
35
|
-
}
|
36
|
-
|
37
|
-
console.log('Doing a thing...');
|
38
|
-
}
|
39
|
-
```
|
40
|
-
|
41
|
-
</TabItem>
|
42
|
-
<TabItem value="✅ Correct">
|
43
|
-
|
44
|
-
```ts
|
45
|
-
// just a regular void function in a statement position
|
46
|
-
alert('Hello, world!');
|
47
|
-
|
48
|
-
// this function returns a boolean value so it's ok
|
49
|
-
const response = confirm('Are you sure?');
|
50
|
-
console.log(confirm('Are you sure?'));
|
51
|
-
|
52
|
-
// now it's obvious that `postMessage` doesn't return any response
|
53
|
-
promise.then(value => {
|
54
|
-
window.postMessage(value);
|
55
|
-
});
|
56
|
-
|
57
|
-
// now it's explicit that we want to log the error and return early
|
58
|
-
function doSomething() {
|
59
|
-
if (!somethingToDo) {
|
60
|
-
console.error('Nothing to do!');
|
61
|
-
return;
|
62
|
-
}
|
63
|
-
|
64
|
-
console.log('Doing a thing...');
|
65
|
-
}
|
66
|
-
|
67
|
-
// using logical expressions for their side effects is fine
|
68
|
-
cond && console.log('true');
|
69
|
-
cond || console.error('false');
|
70
|
-
cond ? console.log('true') : console.error('false');
|
71
|
-
```
|
72
|
-
|
73
|
-
</TabItem>
|
74
|
-
</Tabs>
|
75
|
-
|
76
|
-
## Options
|
77
|
-
|
78
|
-
### `ignoreArrowShorthand`
|
79
|
-
|
80
|
-
{/* insert option description */}
|
81
|
-
|
82
|
-
It might be undesirable to wrap every arrow function shorthand expression.
|
83
|
-
Especially when using the Prettier formatter, which spreads such code across 3 lines instead of 1.
|
84
|
-
|
85
|
-
Examples of additional **correct** code with this option enabled:
|
86
|
-
|
87
|
-
```ts option='{ "ignoreArrowShorthand": true }' showPlaygroundButton
|
88
|
-
promise.then(value => window.postMessage(value));
|
89
|
-
```
|
90
|
-
|
91
|
-
### `ignoreVoidOperator`
|
92
|
-
|
93
|
-
{/* insert option description */}
|
94
|
-
|
95
|
-
It might be preferable to only use some distinct syntax
|
96
|
-
to explicitly mark the confusing but valid usage of void expressions.
|
97
|
-
This option allows void expressions which are explicitly wrapped in the `void` operator.
|
98
|
-
This can help avoid confusion among other developers as long as they are made aware of this code style.
|
99
|
-
|
100
|
-
This option also changes the automatic fixes for common cases to use the `void` operator.
|
101
|
-
It also enables a suggestion fix to wrap the void expression with `void` operator for every problem reported.
|
102
|
-
|
103
|
-
Examples of additional **correct** code with this option enabled:
|
104
|
-
|
105
|
-
```ts option='{ "ignoreVoidOperator": true }' showPlaygroundButton
|
106
|
-
// now it's obvious that we don't expect any response
|
107
|
-
promise.then(value => void window.postMessage(value));
|
108
|
-
|
109
|
-
// now it's explicit that we don't want to return anything
|
110
|
-
function doSomething() {
|
111
|
-
if (!somethingToDo) {
|
112
|
-
return void console.error('Nothing to do!');
|
113
|
-
}
|
114
|
-
|
115
|
-
console.log('Doing a thing...');
|
116
|
-
}
|
117
|
-
|
118
|
-
// we are sure that we want to always log `undefined`
|
119
|
-
console.log(void alert('Hello, world!'));
|
120
|
-
```
|
121
|
-
|
122
|
-
### `ignoreVoidReturningFunctions`
|
123
|
-
|
124
|
-
{/* insert option description */}
|
125
|
-
|
126
|
-
Some projects prefer allowing functions that explicitly return `void` to return `void` expressions. Doing so allows more writing more succinct functions.
|
127
|
-
|
128
|
-
:::note
|
129
|
-
This is technically risky as the `void`-returning function might actually be returning a value not seen by the type system.
|
130
|
-
:::
|
131
|
-
|
132
|
-
```ts option='{ "ignoreVoidReturningFunctions": true }' showPlaygroundButton
|
133
|
-
function foo(): void {
|
134
|
-
return console.log();
|
135
|
-
}
|
136
|
-
|
137
|
-
function onError(callback: () => void): void {
|
138
|
-
callback();
|
139
|
-
}
|
140
|
-
|
141
|
-
onError(() => console.log('oops'));
|
142
|
-
```
|
143
|
-
|
144
|
-
## When Not To Use It
|
145
|
-
|
146
|
-
The return type of a function can be inspected by going to its definition or hovering over it in an IDE.
|
147
|
-
If you don't care about being explicit about the void type in actual code then don't use this rule.
|
148
|
-
Also, if you strongly prefer a concise coding style more strongly than any fear of `void`-related bugs then you can avoid this rule.
|
@@ -1,119 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow using code marked as `@deprecated`.'
|
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-deprecated** for documentation.
|
11
|
-
|
12
|
-
The [JSDoc `@deprecated` tag](https://jsdoc.app/tags-deprecated) can be used to document some piece of code being deprecated.
|
13
|
-
It's best to avoid using code marked as deprecated.
|
14
|
-
This rule reports on any references to code marked as `@deprecated`.
|
15
|
-
|
16
|
-
:::note
|
17
|
-
[TypeScript recognizes the `@deprecated` tag](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#deprecated), allowing editors to visually indicate deprecated code — usually with a ~strikethrough~.
|
18
|
-
However, TypeScript doesn't report type errors for deprecated code on its own.
|
19
|
-
:::
|
20
|
-
|
21
|
-
## Examples
|
22
|
-
|
23
|
-
<Tabs>
|
24
|
-
<TabItem value="❌ Incorrect">
|
25
|
-
|
26
|
-
```ts
|
27
|
-
/** @deprecated Use apiV2 instead. */
|
28
|
-
declare function apiV1(): Promise<string>;
|
29
|
-
|
30
|
-
declare function apiV2(): Promise<string>;
|
31
|
-
|
32
|
-
await apiV1();
|
33
|
-
```
|
34
|
-
|
35
|
-
```ts
|
36
|
-
import { parse } from 'node:url';
|
37
|
-
|
38
|
-
// 'parse' is deprecated. Use the WHATWG URL API instead.
|
39
|
-
const url = parse('/foo');
|
40
|
-
```
|
41
|
-
|
42
|
-
</TabItem>
|
43
|
-
<TabItem value="✅ Correct">
|
44
|
-
|
45
|
-
```ts
|
46
|
-
/** @deprecated Use apiV2 instead. */
|
47
|
-
declare function apiV1(): Promise<string>;
|
48
|
-
|
49
|
-
declare function apiV2(): Promise<string>;
|
50
|
-
|
51
|
-
await apiV2();
|
52
|
-
```
|
53
|
-
|
54
|
-
```ts
|
55
|
-
// Modern Node.js API, uses `new URL()`
|
56
|
-
const url2 = new URL('/foo', 'http://www.example.com');
|
57
|
-
```
|
58
|
-
|
59
|
-
</TabItem>
|
60
|
-
</Tabs>
|
61
|
-
|
62
|
-
## Options
|
63
|
-
|
64
|
-
### `allow`
|
65
|
-
|
66
|
-
{/* insert option description */}
|
67
|
-
|
68
|
-
This option takes the shared [`TypeOrValueSpecifier` format](/packages/type-utils/type-or-value-specifier).
|
69
|
-
|
70
|
-
Examples of code for this rule with:
|
71
|
-
|
72
|
-
```json
|
73
|
-
{
|
74
|
-
"allow": [
|
75
|
-
{ "from": "file", "name": "apiV1" },
|
76
|
-
{ "from": "lib", "name": "escape" }
|
77
|
-
]
|
78
|
-
}
|
79
|
-
```
|
80
|
-
|
81
|
-
<Tabs>
|
82
|
-
<TabItem value="❌ Incorrect">
|
83
|
-
|
84
|
-
```ts option='{"allow":[{"from":"file","name":"apiV1"},{"from":"lib","name":"escape"}]}'
|
85
|
-
/** @deprecated */
|
86
|
-
declare function apiV2(): Promise<string>;
|
87
|
-
|
88
|
-
await apiV2();
|
89
|
-
|
90
|
-
// `unescape` has been deprecated since ES5.
|
91
|
-
unescape('...');
|
92
|
-
```
|
93
|
-
|
94
|
-
</TabItem>
|
95
|
-
|
96
|
-
<TabItem value="✅ Correct">
|
97
|
-
|
98
|
-
```ts option='{"allow":[{"from":"file","name":"apiV1"},{"from":"lib","name":"escape"}]}'
|
99
|
-
import { Bar } from 'bar-lib';
|
100
|
-
/** @deprecated */
|
101
|
-
declare function apiV1(): Promise<string>;
|
102
|
-
|
103
|
-
await apiV1();
|
104
|
-
|
105
|
-
// `escape` has been deprecated since ES5.
|
106
|
-
escape('...');
|
107
|
-
```
|
108
|
-
|
109
|
-
</TabItem>
|
110
|
-
</Tabs>
|
111
|
-
|
112
|
-
## When Not To Use It
|
113
|
-
|
114
|
-
If portions of your project heavily use deprecated APIs and have no plan for moving to non-deprecated ones, you might want to disable this rule in those portions.
|
115
|
-
|
116
|
-
## Related To
|
117
|
-
|
118
|
-
- [`import/no-deprecated`](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-deprecated.md) and [`import-x/no-deprecated`](https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-deprecated.md): Does not use type information, but does also support [TomDoc](http://tomdoc.org)
|
119
|
-
- [`eslint-plugin-deprecation`](https://github.com/gund/eslint-plugin-deprecation) ([`deprecation/deprecation`](https://github.com/gund/eslint-plugin-deprecation?tab=readme-ov-file#rules)): Predecessor to this rule in a separate plugin
|
@@ -1,16 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow duplicate class members.'
|
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-dupe-class-members** for documentation.
|
11
|
-
|
12
|
-
import TypeScriptOverlap from '@site/src/components/TypeScriptOverlap';
|
13
|
-
|
14
|
-
<TypeScriptOverlap />
|
15
|
-
|
16
|
-
It adds support for TypeScript's method overload definitions.
|
@@ -1,66 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow duplicate enum member values.'
|
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-duplicate-enum-values** for documentation.
|
11
|
-
|
12
|
-
Although TypeScript supports duplicate enum member values, people usually expect members to have unique values within the same enum. Duplicate values can lead to bugs that are hard to track down.
|
13
|
-
|
14
|
-
## Examples
|
15
|
-
|
16
|
-
This rule disallows defining an enum with multiple members initialized to the same value.
|
17
|
-
|
18
|
-
> This rule only enforces on enum members initialized with string or number literals.
|
19
|
-
> Members without an initializer or initialized with an expression are not checked by this rule.
|
20
|
-
|
21
|
-
<Tabs>
|
22
|
-
<TabItem value="❌ Incorrect">
|
23
|
-
|
24
|
-
```ts
|
25
|
-
enum E {
|
26
|
-
A = 0,
|
27
|
-
B = 0,
|
28
|
-
}
|
29
|
-
```
|
30
|
-
|
31
|
-
```ts
|
32
|
-
enum E {
|
33
|
-
A = 'A',
|
34
|
-
B = 'A',
|
35
|
-
C = `A`,
|
36
|
-
}
|
37
|
-
```
|
38
|
-
|
39
|
-
</TabItem>
|
40
|
-
<TabItem value="✅ Correct">
|
41
|
-
|
42
|
-
```ts
|
43
|
-
enum E {
|
44
|
-
A = 0,
|
45
|
-
B = 1,
|
46
|
-
}
|
47
|
-
```
|
48
|
-
|
49
|
-
```ts
|
50
|
-
enum E {
|
51
|
-
A = 'A',
|
52
|
-
B = 'B',
|
53
|
-
C = `C`,
|
54
|
-
}
|
55
|
-
```
|
56
|
-
|
57
|
-
</TabItem>
|
58
|
-
</Tabs>
|
59
|
-
|
60
|
-
## When Not To Use It
|
61
|
-
|
62
|
-
It can sometimes be useful to include duplicate enum members for very specific use cases.
|
63
|
-
For example, when renaming an enum member, it can sometimes be useful to keep the old name until a scheduled major breaking change.
|
64
|
-
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.
|
65
|
-
|
66
|
-
In general, if your project intentionally duplicates enum member values, you can avoid this rule.
|
@@ -1,17 +0,0 @@
|
|
1
|
-
---
|
2
|
-
displayed_sidebar: rulesSidebar
|
3
|
-
---
|
4
|
-
|
5
|
-
:::danger Deprecated
|
6
|
-
|
7
|
-
This rule has been deprecated in favour of the [`import/no-duplicates`](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-duplicates.md) rule.
|
8
|
-
|
9
|
-
:::
|
10
|
-
|
11
|
-
<!--
|
12
|
-
This doc file has been left on purpose because `import/no-duplicates` is
|
13
|
-
commonly requested. This exists to help direct people to the replacement rule.
|
14
|
-
|
15
|
-
Note that there is no actual way to get to this page in the normal navigation,
|
16
|
-
so end-users will only be able to get to this page from the search bar.
|
17
|
-
-->
|