@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,47 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Enforce non-null assertions over explicit type assertions.'
|
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/non-nullable-type-assertion-style** for documentation.
|
11
|
-
|
12
|
-
There are two common ways to assert to TypeScript that a value is its type without `null` or `undefined`:
|
13
|
-
|
14
|
-
- `!`: Non-null assertion
|
15
|
-
- `as`: Traditional type assertion with a coincidentally equivalent type
|
16
|
-
|
17
|
-
`!` non-null assertions are generally preferred for requiring less code and being harder to fall out of sync as types change.
|
18
|
-
This rule reports when an `as` assertion is doing the same job as a `!` would, and suggests fixing the code to be an `!`.
|
19
|
-
|
20
|
-
## Examples
|
21
|
-
|
22
|
-
<Tabs>
|
23
|
-
<TabItem value="❌ Incorrect">
|
24
|
-
|
25
|
-
```ts
|
26
|
-
const maybe: string | undefined = Math.random() > 0.5 ? '' : undefined;
|
27
|
-
|
28
|
-
const definitely = maybe as string;
|
29
|
-
const alsoDefinitely = <string>maybe;
|
30
|
-
```
|
31
|
-
|
32
|
-
</TabItem>
|
33
|
-
<TabItem value="✅ Correct">
|
34
|
-
|
35
|
-
```ts
|
36
|
-
const maybe: string | undefined = Math.random() > 0.5 ? '' : undefined;
|
37
|
-
|
38
|
-
const definitely = maybe!;
|
39
|
-
const alsoDefinitely = maybe!;
|
40
|
-
```
|
41
|
-
|
42
|
-
</TabItem>
|
43
|
-
</Tabs>
|
44
|
-
|
45
|
-
## When Not To Use It
|
46
|
-
|
47
|
-
If you don't mind having unnecessarily verbose type assertions, you can avoid this rule.
|
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
displayed_sidebar: rulesSidebar
|
3
|
-
---
|
4
|
-
|
5
|
-
:::danger Deprecated
|
6
|
-
|
7
|
-
This rule has been moved to the [ESLint stylistic plugin](https://eslint.style).
|
8
|
-
See [#8072](https://github.com/typescript-eslint/typescript-eslint/issues/8072) and [#8074](https://github.com/typescript-eslint/typescript-eslint/issues/8074) for more information.
|
9
|
-
|
10
|
-
:::
|
11
|
-
|
12
|
-
<!-- This doc file has been left on purpose to help direct people to the stylistic plugin.
|
13
|
-
|
14
|
-
Note that there is no actual way to get to this page in the normal navigation,
|
15
|
-
so end-users will only be able to get to this page from the search bar. -->
|
@@ -1,150 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow throwing non-`Error` values as exceptions.'
|
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/only-throw-error** for documentation.
|
11
|
-
|
12
|
-
It uses type information to determine which values are `Error`s.
|
13
|
-
|
14
|
-
It is considered good practice to only `throw` the `Error` object itself or an object using the `Error` object as base objects for user-defined exceptions.
|
15
|
-
The fundamental benefit of `Error` objects is that they automatically keep track of where they were built and originated.
|
16
|
-
|
17
|
-
:::info[Migration from `no-throw-literal`]
|
18
|
-
|
19
|
-
This extension rule was formerly known as `@typescript-eslint/no-throw-literal`.
|
20
|
-
The new name is a drop-in replacement with identical functionality.
|
21
|
-
|
22
|
-
:::
|
23
|
-
|
24
|
-
## Examples
|
25
|
-
|
26
|
-
This rule is aimed at maintaining consistency when throwing exception by disallowing to throw literals and other expressions which cannot possibly be an `Error` object.
|
27
|
-
|
28
|
-
<Tabs>
|
29
|
-
<TabItem value="❌ Incorrect">
|
30
|
-
|
31
|
-
```ts
|
32
|
-
throw 'error';
|
33
|
-
|
34
|
-
throw 0;
|
35
|
-
|
36
|
-
throw undefined;
|
37
|
-
|
38
|
-
throw null;
|
39
|
-
|
40
|
-
const err = new Error();
|
41
|
-
throw 'an ' + err;
|
42
|
-
|
43
|
-
const err = new Error();
|
44
|
-
throw `${err}`;
|
45
|
-
|
46
|
-
const err = '';
|
47
|
-
throw err;
|
48
|
-
|
49
|
-
function getError() {
|
50
|
-
return '';
|
51
|
-
}
|
52
|
-
throw getError();
|
53
|
-
|
54
|
-
const foo = {
|
55
|
-
bar: '',
|
56
|
-
};
|
57
|
-
throw foo.bar;
|
58
|
-
```
|
59
|
-
|
60
|
-
</TabItem>
|
61
|
-
<TabItem value="✅ Correct">
|
62
|
-
|
63
|
-
```ts
|
64
|
-
throw new Error();
|
65
|
-
|
66
|
-
throw new Error('error');
|
67
|
-
|
68
|
-
const e = new Error('error');
|
69
|
-
throw e;
|
70
|
-
|
71
|
-
try {
|
72
|
-
throw new Error('error');
|
73
|
-
} catch (e) {
|
74
|
-
throw e;
|
75
|
-
}
|
76
|
-
|
77
|
-
const err = new Error();
|
78
|
-
throw err;
|
79
|
-
|
80
|
-
function getError() {
|
81
|
-
return new Error();
|
82
|
-
}
|
83
|
-
throw getError();
|
84
|
-
|
85
|
-
const foo = {
|
86
|
-
bar: new Error(),
|
87
|
-
};
|
88
|
-
throw foo.bar;
|
89
|
-
|
90
|
-
class CustomError extends Error {
|
91
|
-
// ...
|
92
|
-
}
|
93
|
-
throw new CustomError();
|
94
|
-
```
|
95
|
-
|
96
|
-
</TabItem>
|
97
|
-
</Tabs>
|
98
|
-
|
99
|
-
## Options
|
100
|
-
|
101
|
-
This rule adds the following options:
|
102
|
-
|
103
|
-
```ts
|
104
|
-
interface Options {
|
105
|
-
/**
|
106
|
-
* Type specifiers that can be thrown.
|
107
|
-
*/
|
108
|
-
allow?: (
|
109
|
-
| {
|
110
|
-
from: 'file';
|
111
|
-
name: [string, ...string[]] | string;
|
112
|
-
path?: string;
|
113
|
-
}
|
114
|
-
| {
|
115
|
-
from: 'lib';
|
116
|
-
name: [string, ...string[]] | string;
|
117
|
-
}
|
118
|
-
| {
|
119
|
-
from: 'package';
|
120
|
-
name: [string, ...string[]] | string;
|
121
|
-
package: string;
|
122
|
-
}
|
123
|
-
| string
|
124
|
-
)[];
|
125
|
-
|
126
|
-
/**
|
127
|
-
* Whether to allow rethrowing caught values that are not `Error` objects.
|
128
|
-
*/
|
129
|
-
allowRethrowing?: boolean;
|
130
|
-
|
131
|
-
/**
|
132
|
-
* Whether to always allow throwing values typed as `any`.
|
133
|
-
*/
|
134
|
-
allowThrowingAny?: boolean;
|
135
|
-
|
136
|
-
/**
|
137
|
-
* Whether to always allow throwing values typed as `unknown`.
|
138
|
-
*/
|
139
|
-
allowThrowingUnknown?: boolean;
|
140
|
-
}
|
141
|
-
|
142
|
-
const defaultOptions: Options = {
|
143
|
-
allow: [],
|
144
|
-
allowRethrowing: false,
|
145
|
-
allowThrowingAny: true,
|
146
|
-
allowThrowingUnknown: true,
|
147
|
-
};
|
148
|
-
```
|
149
|
-
|
150
|
-
{/* Intentionally Omitted: When Not To Use It */}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
displayed_sidebar: rulesSidebar
|
3
|
-
---
|
4
|
-
|
5
|
-
:::danger Deprecated
|
6
|
-
|
7
|
-
This rule has been moved to the [ESLint stylistic plugin](https://eslint.style).
|
8
|
-
See [#8072](https://github.com/typescript-eslint/typescript-eslint/issues/8072) and [#8074](https://github.com/typescript-eslint/typescript-eslint/issues/8074) for more information.
|
9
|
-
|
10
|
-
:::
|
11
|
-
|
12
|
-
<!-- This doc file has been left on purpose to help direct people to the stylistic plugin.
|
13
|
-
|
14
|
-
Note that there is no actual way to get to this page in the normal navigation,
|
15
|
-
so end-users will only be able to get to this page from the search bar. -->
|