@typescript-eslint/eslint-plugin 8.0.0-alpha.30 → 8.0.0-alpha.31
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/configs/all.js +3 -1
- package/dist/configs/all.js.map +1 -1
- package/dist/configs/recommended-type-checked.js +2 -1
- package/dist/configs/recommended-type-checked.js.map +1 -1
- package/dist/configs/recommended.js +2 -1
- package/dist/configs/recommended.js.map +1 -1
- package/dist/configs/strict-type-checked.js +2 -1
- package/dist/configs/strict-type-checked.js.map +1 -1
- package/dist/configs/strict.js +2 -1
- package/dist/configs/strict.js.map +1 -1
- package/dist/rules/adjacent-overload-signatures.js +2 -6
- package/dist/rules/adjacent-overload-signatures.js.map +1 -1
- package/dist/rules/class-literal-property-style.js +9 -7
- package/dist/rules/class-literal-property-style.js.map +1 -1
- package/dist/rules/consistent-type-assertions.js +2 -14
- package/dist/rules/consistent-type-assertions.js.map +1 -1
- package/dist/rules/consistent-type-definitions.js +1 -1
- package/dist/rules/consistent-type-definitions.js.map +1 -1
- package/dist/rules/default-param-last.js +6 -1
- package/dist/rules/default-param-last.js.map +1 -1
- package/dist/rules/enum-utils/shared.js +3 -4
- package/dist/rules/enum-utils/shared.js.map +1 -1
- package/dist/rules/explicit-member-accessibility.js +4 -54
- package/dist/rules/explicit-member-accessibility.js.map +1 -1
- package/dist/rules/index.js +6 -2
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/member-ordering.js +7 -0
- package/dist/rules/member-ordering.js.map +1 -1
- package/dist/rules/naming-convention-utils/parse-options.js +1 -2
- package/dist/rules/naming-convention-utils/parse-options.js.map +1 -1
- package/dist/rules/naming-convention-utils/shared.js +3 -4
- package/dist/rules/naming-convention-utils/shared.js.map +1 -1
- package/dist/rules/naming-convention-utils/validator.js +1 -2
- package/dist/rules/naming-convention-utils/validator.js.map +1 -1
- package/dist/rules/naming-convention.js +3 -1
- package/dist/rules/naming-convention.js.map +1 -1
- package/dist/rules/no-dynamic-delete.js +8 -40
- package/dist/rules/no-dynamic-delete.js.map +1 -1
- package/dist/rules/no-empty-object-type.js +1 -1
- package/dist/rules/no-empty-object-type.js.map +1 -1
- package/dist/rules/no-extraneous-class.js +11 -3
- package/dist/rules/no-extraneous-class.js.map +1 -1
- package/dist/rules/no-implied-eval.js +1 -8
- package/dist/rules/no-implied-eval.js.map +1 -1
- package/dist/rules/no-inferrable-types.js +1 -2
- package/dist/rules/no-inferrable-types.js.map +1 -1
- package/dist/rules/no-invalid-this.js +6 -0
- package/dist/rules/no-invalid-this.js.map +1 -1
- package/dist/rules/no-magic-numbers.js +32 -1
- package/dist/rules/no-magic-numbers.js.map +1 -1
- package/dist/rules/no-misused-new.js +4 -3
- package/dist/rules/no-misused-new.js.map +1 -1
- package/dist/rules/{ban-types.js → no-restricted-types.js} +17 -70
- package/dist/rules/no-restricted-types.js.map +1 -0
- package/dist/rules/no-shadow.js +1 -1
- package/dist/rules/no-shadow.js.map +1 -1
- package/dist/rules/no-unsafe-function-type.js +47 -0
- package/dist/rules/no-unsafe-function-type.js.map +1 -0
- package/dist/rules/no-unsafe-member-access.js +8 -2
- package/dist/rules/no-unsafe-member-access.js.map +1 -1
- package/dist/rules/no-unused-vars.js +178 -74
- package/dist/rules/no-unused-vars.js.map +1 -1
- package/dist/rules/no-useless-constructor.js +0 -1
- package/dist/rules/no-useless-constructor.js.map +1 -1
- package/dist/rules/no-wrapper-object-types.js +61 -0
- package/dist/rules/no-wrapper-object-types.js.map +1 -0
- package/dist/rules/prefer-as-const.js +1 -1
- package/dist/rules/prefer-as-const.js.map +1 -1
- package/dist/rules/prefer-destructuring.js +3 -1
- package/dist/rules/prefer-destructuring.js.map +1 -1
- package/dist/rules/prefer-includes.js.map +1 -1
- package/dist/rules/prefer-nullish-coalescing.js +8 -6
- package/dist/rules/prefer-nullish-coalescing.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/analyzeChain.js +1 -2
- package/dist/rules/prefer-optional-chain-utils/analyzeChain.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.js +1 -2
- package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/compareNodes.js +1 -2
- package/dist/rules/prefer-optional-chain-utils/compareNodes.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js +6 -11
- package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js.map +1 -1
- package/dist/rules/prefer-readonly.js +16 -7
- package/dist/rules/prefer-readonly.js.map +1 -1
- package/dist/rules/prefer-string-starts-ends-with.js.map +1 -1
- package/dist/rules/restrict-template-expressions.js +2 -2
- package/dist/rules/restrict-template-expressions.js.map +1 -1
- package/dist/rules/return-await.js +36 -2
- package/dist/rules/return-await.js.map +1 -1
- package/dist/util/astUtils.js +2 -3
- package/dist/util/astUtils.js.map +1 -1
- package/dist/util/collectUnusedVariables.js +60 -30
- package/dist/util/collectUnusedVariables.js.map +1 -1
- package/dist/util/escapeRegExp.js +1 -2
- package/dist/util/escapeRegExp.js.map +1 -1
- package/dist/util/explicitReturnTypeUtils.js +6 -7
- package/dist/util/explicitReturnTypeUtils.js.map +1 -1
- package/dist/util/getESLintCoreRule.js +2 -2
- package/dist/util/getESLintCoreRule.js.map +1 -1
- package/dist/util/getForStatementHeadLoc.js +1 -2
- package/dist/util/getForStatementHeadLoc.js.map +1 -1
- package/dist/util/getFunctionHeadLoc.js +1 -2
- package/dist/util/getFunctionHeadLoc.js.map +1 -1
- package/dist/util/getMemberHeadLoc.js +80 -0
- package/dist/util/getMemberHeadLoc.js.map +1 -0
- package/dist/util/getOperatorPrecedence.js +4 -4
- package/dist/util/getOperatorPrecedence.js.map +1 -1
- package/dist/util/getStaticStringValue.js +1 -2
- package/dist/util/getStaticStringValue.js.map +1 -1
- package/dist/util/getStringLength.js +1 -2
- package/dist/util/getStringLength.js.map +1 -1
- package/dist/util/getTextWithParentheses.js +17 -0
- package/dist/util/getTextWithParentheses.js.map +1 -0
- package/dist/util/getThisExpression.js +1 -2
- package/dist/util/getThisExpression.js.map +1 -1
- package/dist/util/getWrappedCode.js +1 -2
- package/dist/util/getWrappedCode.js.map +1 -1
- package/dist/util/getWrappingFixer.js +2 -3
- package/dist/util/getWrappingFixer.js.map +1 -1
- package/dist/util/index.js +2 -0
- package/dist/util/index.js.map +1 -1
- package/dist/util/isAssignee.js +1 -2
- package/dist/util/isAssignee.js.map +1 -1
- package/dist/util/isNodeEqual.js +1 -2
- package/dist/util/isNodeEqual.js.map +1 -1
- package/dist/util/isNullLiteral.js +1 -2
- package/dist/util/isNullLiteral.js.map +1 -1
- package/dist/util/isUndefinedIdentifier.js +1 -2
- package/dist/util/isUndefinedIdentifier.js.map +1 -1
- package/dist/util/misc.js +14 -14
- package/dist/util/misc.js.map +1 -1
- package/dist/util/objectIterators.js +3 -4
- package/dist/util/objectIterators.js.map +1 -1
- package/dist/util/scopeUtils.js +11 -0
- package/dist/util/scopeUtils.js.map +1 -0
- package/docs/rules/ban-types.md +22 -0
- package/docs/rules/consistent-indexed-object-style.mdx +1 -1
- package/docs/rules/no-dynamic-delete.mdx +6 -5
- package/docs/rules/no-extraneous-class.mdx +6 -0
- package/docs/rules/no-restricted-types.mdx +71 -0
- package/docs/rules/no-type-alias.mdx +1 -1
- package/docs/rules/no-unsafe-function-type.mdx +63 -0
- package/docs/rules/no-wrapper-object-types.mdx +67 -0
- package/docs/rules/return-await.mdx +17 -6
- package/package.json +7 -9
- package/dist/rules/ban-types.js.map +0 -1
- package/docs/rules/ban-types.mdx +0 -133
@@ -0,0 +1,63 @@
|
|
1
|
+
---
|
2
|
+
description: 'Disallow using the unsafe built-in Function type.'
|
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-unsafe-function-type** for documentation.
|
11
|
+
|
12
|
+
TypeScript's built-in `Function` type allows being called with any number of arguments and returns type `any`.
|
13
|
+
`Function` also allows classes or plain objects that happen to possess all properties of the `Function` class.
|
14
|
+
It's generally better to specify function parameters and return types with the function type syntax.
|
15
|
+
|
16
|
+
"Catch-all" function types include:
|
17
|
+
|
18
|
+
- `() => void`: a function that has no parameters and whose return is ignored
|
19
|
+
- `(...args: never) => unknown`: a "top type" for functions that can be assigned any function type, but can't be called
|
20
|
+
|
21
|
+
Examples of code for this rule:
|
22
|
+
|
23
|
+
<Tabs>
|
24
|
+
<TabItem value="❌ Incorrect">
|
25
|
+
|
26
|
+
```ts
|
27
|
+
let noParametersOrReturn: Function;
|
28
|
+
noParametersOrReturn = () => {};
|
29
|
+
|
30
|
+
let stringToNumber: Function;
|
31
|
+
stringToNumber = (text: string) => text.length;
|
32
|
+
|
33
|
+
let identity: Function;
|
34
|
+
identity = value => value;
|
35
|
+
```
|
36
|
+
|
37
|
+
</TabItem>
|
38
|
+
<TabItem value="✅ Correct">
|
39
|
+
|
40
|
+
```ts
|
41
|
+
let noParametersOrReturn: () => void;
|
42
|
+
noParametersOrReturn = () => {};
|
43
|
+
|
44
|
+
let stringToNumber: (text: string) => number;
|
45
|
+
stringToNumber = text => text.length;
|
46
|
+
|
47
|
+
let identity: <T>(value: T) => T;
|
48
|
+
identity = value => value;
|
49
|
+
```
|
50
|
+
|
51
|
+
</TabItem>
|
52
|
+
</Tabs>
|
53
|
+
|
54
|
+
## When Not To Use It
|
55
|
+
|
56
|
+
If your project is still onboarding to TypeScript, it might be difficult to fully replace all unsafe `Function` types with more precise function types.
|
57
|
+
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.
|
58
|
+
|
59
|
+
## Related To
|
60
|
+
|
61
|
+
- [`no-empty-object-type`](./no-empty-object-type.mdx)
|
62
|
+
- [`no-restricted-types`](./no-restricted-types.mdx)
|
63
|
+
- [`no-wrapper-object-types`](./no-wrapper-object-types.mdx)
|
@@ -0,0 +1,67 @@
|
|
1
|
+
---
|
2
|
+
description: 'Disallow using confusing built-in primitive class wrappers.'
|
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-wrapper-object-types** for documentation.
|
11
|
+
|
12
|
+
The JavaScript language has a set of language types, but some of them correspond to two TypeScript types, which look similar: `boolean`/`Boolean`, `number`/`Number`, `string`/`String`, `bigint`/`BigInt`, `symbol`/`Symbol`, `object`/`Object`.
|
13
|
+
The difference is that the lowercase variants are compiler intrinsics and specify the actual _runtime types_ (that is, the return value when you use the `typeof` operator), while the uppercase variants are _structural types_ defined in the library that can be satisfied by any user-defined object with the right properties, not just the real primitives.
|
14
|
+
JavaScript also has a "wrapper" class object for each of those primitives, such as [`Boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) and [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number).
|
15
|
+
These wrapper objects are assignable to the uppercase types, but not to the lowercase types.
|
16
|
+
|
17
|
+
Using the primitives like `0` instead of object wrappers like `new Number(0)` is generally considered a JavaScript best practice.
|
18
|
+
JavaScript programs typically work with the real number primitives, rather than objects that "look like" numbers.
|
19
|
+
Primitives are simpler to conceptualize and work with `==` and `===` equality checks -- which their object equivalents do notDeepEqual.
|
20
|
+
As a result, using the lowercase type names like `number` instead of the uppercase names like `Number` helps make your code behave more reliably.
|
21
|
+
|
22
|
+
Examples of code for this rule:
|
23
|
+
|
24
|
+
<Tabs>
|
25
|
+
<TabItem value="❌ Incorrect">
|
26
|
+
|
27
|
+
```ts
|
28
|
+
let myBigInt: BigInt;
|
29
|
+
let myBoolean: Boolean;
|
30
|
+
let myNumber: Number;
|
31
|
+
let myString: String;
|
32
|
+
let mySymbol: Symbol;
|
33
|
+
|
34
|
+
let myObject: Object = 'allowed by TypeScript';
|
35
|
+
```
|
36
|
+
|
37
|
+
</TabItem>
|
38
|
+
<TabItem value="✅ Correct">
|
39
|
+
|
40
|
+
```ts
|
41
|
+
let myBigint: bigint;
|
42
|
+
let myBoolean: boolean;
|
43
|
+
let myNumber: number;
|
44
|
+
let myString: string;
|
45
|
+
let mySymbol: symbol;
|
46
|
+
|
47
|
+
let myObject: object = "Type 'string' is not assignable to type 'object'.";
|
48
|
+
```
|
49
|
+
|
50
|
+
</TabItem>
|
51
|
+
</Tabs>
|
52
|
+
|
53
|
+
## When Not To Use It
|
54
|
+
|
55
|
+
If your project is a rare one that intentionally deals with the class equivalents of primitives, it might not be worthwhile to use this rule.
|
56
|
+
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.
|
57
|
+
|
58
|
+
## Further Reading
|
59
|
+
|
60
|
+
- [MDN documentation on primitives](https://developer.mozilla.org/en-US/docs/Glossary/Primitive)
|
61
|
+
- [MDN documentation on `string` primitives and `String` objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#string_primitives_and_string_objects)
|
62
|
+
|
63
|
+
## Related To
|
64
|
+
|
65
|
+
- [`no-empty-object-type`](./no-empty-object-type.mdx)
|
66
|
+
- [`no-restricted-types`](./no-restricted-types.mdx)
|
67
|
+
- [`no-unsafe-function-type`](./no-unsafe-function-type.mdx)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
---
|
2
|
-
description: 'Enforce consistent
|
2
|
+
description: 'Enforce consistent awaiting of returned promises.'
|
3
3
|
---
|
4
4
|
|
5
5
|
import Tabs from '@theme/Tabs';
|
@@ -9,12 +9,14 @@ import TabItem from '@theme/TabItem';
|
|
9
9
|
>
|
10
10
|
> See **https://typescript-eslint.io/rules/return-await** for documentation.
|
11
11
|
|
12
|
-
Returning an awaited promise can make sense for better stack trace information as well as for consistent error handling (returned promises will not be caught in an async function try/catch).
|
13
|
-
|
14
12
|
This rule builds on top of the [`eslint/no-return-await`](https://eslint.org/docs/rules/no-return-await) rule.
|
15
13
|
It expands upon the base rule to add support for optionally requiring `return await` in certain cases.
|
16
14
|
|
17
|
-
The extended rule is named `return-await` instead of `no-return-await` because the extended rule can enforce the positive or the negative. Additionally, while the core rule is now deprecated, the extended rule is still useful in many contexts
|
15
|
+
The extended rule is named `return-await` instead of `no-return-await` because the extended rule can enforce the positive or the negative. Additionally, while the core rule is now deprecated, the extended rule is still useful in many contexts:
|
16
|
+
|
17
|
+
- Returning an awaited promise [improves stack trace information](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#improving_stack_trace).
|
18
|
+
- When the `return` statement is in `try...catch`, awaiting the promise also allows the promise's rejection to be caught instead of leaving the error to the caller.
|
19
|
+
- Contrary to popular belief, `return await promise;` is [at least as fast as directly returning the promise](https://github.com/tc39/proposal-faster-promise-adoption).
|
18
20
|
|
19
21
|
## Options
|
20
22
|
|
@@ -35,8 +37,7 @@ Listing the error-handling cases exhaustively:
|
|
35
37
|
- if you `return` a promise within a `catch`, and there is _no_ `finally`, then it must _not_ be `await`ed.
|
36
38
|
- if you `return` a promise within a `catch`, and there _is_ a `finally`, then it _must_ be `await`ed.
|
37
39
|
- if you `return` a promise within a `finally`, then it must not be `await`ed.
|
38
|
-
|
39
|
-
Examples of code with `in-try-catch`:
|
40
|
+
- if you `return` a promise between a `using` or `await using` declaration and the end of its scope, it must be `await`ed, since it behaves equivalently to code wrapped in a `try` block.
|
40
41
|
|
41
42
|
<Tabs>
|
42
43
|
<TabItem value="❌ Incorrect">
|
@@ -95,6 +96,11 @@ async function invalidInTryCatch5() {
|
|
95
96
|
async function invalidInTryCatch6() {
|
96
97
|
return await 'value';
|
97
98
|
}
|
99
|
+
|
100
|
+
async function invalidInTryCatch7() {
|
101
|
+
using x = createDisposable();
|
102
|
+
return Promise.reject('using in scope');
|
103
|
+
}
|
98
104
|
```
|
99
105
|
|
100
106
|
</TabItem>
|
@@ -151,6 +157,11 @@ async function validInTryCatch5() {
|
|
151
157
|
async function validInTryCatch6() {
|
152
158
|
return 'value';
|
153
159
|
}
|
160
|
+
|
161
|
+
async function validInTryCatch7() {
|
162
|
+
using x = createDisposable();
|
163
|
+
return await Promise.reject('using in scope');
|
164
|
+
}
|
154
165
|
```
|
155
166
|
|
156
167
|
</TabItem>
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
3
|
-
"version": "8.0.0-alpha.
|
3
|
+
"version": "8.0.0-alpha.31",
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
5
5
|
"files": [
|
6
6
|
"dist",
|
@@ -48,8 +48,6 @@
|
|
48
48
|
],
|
49
49
|
"scripts": {
|
50
50
|
"build": "tsc -b tsconfig.build.json",
|
51
|
-
"check-docs": "jest tests/docs.test.ts --runTestsByPath --silent --runInBand",
|
52
|
-
"check-configs": "jest tests/configs.test.ts --runTestsByPath --silent --runInBand",
|
53
51
|
"clean": "tsc -b tsconfig.build.json --clean",
|
54
52
|
"postclean": "rimraf dist && rimraf coverage",
|
55
53
|
"format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
|
@@ -62,10 +60,10 @@
|
|
62
60
|
},
|
63
61
|
"dependencies": {
|
64
62
|
"@eslint-community/regexpp": "^4.10.0",
|
65
|
-
"@typescript-eslint/scope-manager": "8.0.0-alpha.
|
66
|
-
"@typescript-eslint/type-utils": "8.0.0-alpha.
|
67
|
-
"@typescript-eslint/utils": "8.0.0-alpha.
|
68
|
-
"@typescript-eslint/visitor-keys": "8.0.0-alpha.
|
63
|
+
"@typescript-eslint/scope-manager": "8.0.0-alpha.31",
|
64
|
+
"@typescript-eslint/type-utils": "8.0.0-alpha.31",
|
65
|
+
"@typescript-eslint/utils": "8.0.0-alpha.31",
|
66
|
+
"@typescript-eslint/visitor-keys": "8.0.0-alpha.31",
|
69
67
|
"graphemer": "^1.4.0",
|
70
68
|
"ignore": "^5.3.1",
|
71
69
|
"natural-compare": "^1.4.0",
|
@@ -76,8 +74,8 @@
|
|
76
74
|
"@types/marked": "^5.0.2",
|
77
75
|
"@types/mdast": "^4.0.3",
|
78
76
|
"@types/natural-compare": "*",
|
79
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "8.0.0-alpha.
|
80
|
-
"@typescript-eslint/rule-tester": "8.0.0-alpha.
|
77
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.0.0-alpha.31",
|
78
|
+
"@typescript-eslint/rule-tester": "8.0.0-alpha.31",
|
81
79
|
"ajv": "^6.12.6",
|
82
80
|
"cross-env": "^7.0.3",
|
83
81
|
"cross-fetch": "*",
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ban-types.js","sourceRoot":"","sources":["../../src/rules/ban-types.ts"],"names":[],"mappings":";;;AACA,oDAA0D;AAE1D,kCAAsD;AAsBtD,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,aAAa,CACpB,IAAmB,EACnB,UAA+B;IAE/B,OAAO,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,gBAAgB,CACvB,UAAyE;IAEzE,IAAI,UAAU,IAAI,IAAI,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QAC9C,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,OAAO,IAAI,UAAU,EAAE,CAAC;IAC1B,CAAC;IAED,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,OAAO,IAAI,UAAU,CAAC,OAAO,EAAE,CAA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B,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAEhC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;oBACvB,gBAAgB,CAAC,IAAI,CAAC,CAAC;gBACzB,CAAC;YACH,CAAC;YACD,mBAAmB,CAAC,IAAI;gBACtB,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;YACD,iBAAiB,CAAC,IAAI;gBACpB,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
package/docs/rules/ban-types.mdx
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow certain types.'
|
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/ban-types** for documentation.
|
11
|
-
|
12
|
-
Some built-in types have aliases, while some types are considered dangerous or harmful.
|
13
|
-
It's often a good idea to ban certain types to help with consistency and safety.
|
14
|
-
|
15
|
-
This rule bans specific types and can suggest alternatives.
|
16
|
-
Note that it does not ban the corresponding runtime objects from being used.
|
17
|
-
|
18
|
-
## Examples
|
19
|
-
|
20
|
-
Examples of code with the default options:
|
21
|
-
|
22
|
-
<Tabs>
|
23
|
-
<TabItem value="❌ Incorrect">
|
24
|
-
|
25
|
-
```ts
|
26
|
-
// use lower-case primitives for consistency
|
27
|
-
const str: String = 'foo';
|
28
|
-
const bool: Boolean = true;
|
29
|
-
const num: Number = 1;
|
30
|
-
const symb: Symbol = Symbol('foo');
|
31
|
-
const bigInt: BigInt = 1n;
|
32
|
-
|
33
|
-
// use a proper function type
|
34
|
-
const func: Function = () => 1;
|
35
|
-
|
36
|
-
// use safer object types
|
37
|
-
const lowerObj: Object = {};
|
38
|
-
const capitalObj: Object = { a: 'string' };
|
39
|
-
```
|
40
|
-
|
41
|
-
</TabItem>
|
42
|
-
<TabItem value="✅ Correct">
|
43
|
-
|
44
|
-
```ts
|
45
|
-
// use lower-case primitives for consistency
|
46
|
-
const str: string = 'foo';
|
47
|
-
const bool: boolean = true;
|
48
|
-
const num: number = 1;
|
49
|
-
const symb: symbol = Symbol('foo');
|
50
|
-
const bigInt: bigint = 1n;
|
51
|
-
|
52
|
-
// use a proper function type
|
53
|
-
const func: () => number = () => 1;
|
54
|
-
|
55
|
-
// use safer object types
|
56
|
-
const lowerObj: object = {};
|
57
|
-
const capitalObj: { a: string } = { a: 'string' };
|
58
|
-
```
|
59
|
-
|
60
|
-
</TabItem>
|
61
|
-
</Tabs>
|
62
|
-
|
63
|
-
## Options
|
64
|
-
|
65
|
-
The default options provide a set of "best practices", intended to provide safety and standardization in your codebase:
|
66
|
-
|
67
|
-
- Don't use the upper-case primitive types or `Object`, you should use the lower-case types for consistency.
|
68
|
-
- Avoid the `Function` type, as it provides little safety for the following reasons:
|
69
|
-
- It provides no type safety when calling the value, which means it's easy to provide the wrong arguments.
|
70
|
-
- It accepts class declarations, which will fail when called, as they are called without the `new` keyword.
|
71
|
-
|
72
|
-
<details>
|
73
|
-
<summary>Default Options</summary>
|
74
|
-
|
75
|
-
{/* Inject default options */}
|
76
|
-
|
77
|
-
</details>
|
78
|
-
|
79
|
-
### `types`
|
80
|
-
|
81
|
-
An object whose keys are the types you want to ban, and the values are error messages.
|
82
|
-
|
83
|
-
The type can either be a type name literal (`Foo`), a type name with generic parameter instantiation(s) (`Foo<Bar>`), the empty object literal (`{}`), or the empty tuple type (`[]`).
|
84
|
-
|
85
|
-
The values can be:
|
86
|
-
|
87
|
-
- A string, which is the error message to be reported; or
|
88
|
-
- `false` to specifically un-ban this type (useful when you are using `extendDefaults`); or
|
89
|
-
- An object with the following properties:
|
90
|
-
- `message: string` - the message to display when the type is matched.
|
91
|
-
- `fixWith?: string` - a string to replace the banned type with when the fixer is run. If this is omitted, no fix will be done.
|
92
|
-
- `suggest?: string[]` - a list of suggested replacements for the banned type.
|
93
|
-
|
94
|
-
### `extendDefaults`
|
95
|
-
|
96
|
-
If you're specifying custom `types`, you can set this to `true` to extend the default `types` configuration. This is a convenience option to save you copying across the defaults when adding another type.
|
97
|
-
|
98
|
-
If this is `false`, the rule will _only_ use the types defined in your configuration.
|
99
|
-
|
100
|
-
Example configuration:
|
101
|
-
|
102
|
-
```jsonc
|
103
|
-
{
|
104
|
-
"@typescript-eslint/ban-types": [
|
105
|
-
"error",
|
106
|
-
{
|
107
|
-
"types": {
|
108
|
-
// add a custom message to help explain why not to use it
|
109
|
-
"Foo": "Don't use Foo because it is unsafe",
|
110
|
-
|
111
|
-
// add a custom message, AND tell the plugin how to fix it
|
112
|
-
"OldAPI": {
|
113
|
-
"message": "Use NewAPI instead",
|
114
|
-
"fixWith": "NewAPI",
|
115
|
-
},
|
116
|
-
|
117
|
-
// un-ban a type that's banned by default
|
118
|
-
"{}": false,
|
119
|
-
},
|
120
|
-
"extendDefaults": true,
|
121
|
-
},
|
122
|
-
],
|
123
|
-
}
|
124
|
-
```
|
125
|
-
|
126
|
-
## When Not To Use It
|
127
|
-
|
128
|
-
If your project is a rare one that intentionally deals with the class equivalents of primitives, it might not be worthwhile to enable the default `ban-types` options.
|
129
|
-
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.
|
130
|
-
|
131
|
-
## Related To
|
132
|
-
|
133
|
-
- [`no-empty-object-type`](./no-empty-object-type.mdx)
|