@typescript-eslint/eslint-plugin 7.2.1-alpha.1 → 7.2.1-alpha.3
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 +1 -0
- package/dist/configs/all.js.map +1 -1
- package/dist/configs/disable-type-checked.js +1 -0
- package/dist/configs/disable-type-checked.js.map +1 -1
- package/dist/configs/strict-type-checked-only.js +23 -3
- package/dist/configs/strict-type-checked-only.js.map +1 -1
- package/dist/configs/strict-type-checked.js +27 -4
- package/dist/configs/strict-type-checked.js.map +1 -1
- package/dist/configs/strict.js +4 -1
- package/dist/configs/strict.js.map +1 -1
- package/dist/rules/ban-ts-comment.js +4 -1
- package/dist/rules/ban-ts-comment.js.map +1 -1
- package/dist/rules/consistent-type-imports.js +1 -0
- package/dist/rules/consistent-type-imports.js.map +1 -1
- package/dist/rules/index.js +2 -0
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/no-floating-promises.js +4 -1
- package/dist/rules/no-floating-promises.js.map +1 -1
- package/dist/rules/no-misused-promises.js +1 -1
- package/dist/rules/no-misused-promises.js.map +1 -1
- package/dist/rules/no-redundant-type-constituents.js +42 -0
- package/dist/rules/no-redundant-type-constituents.js.map +1 -1
- package/dist/rules/no-unnecessary-qualifier.js +1 -1
- package/dist/rules/no-unnecessary-qualifier.js.map +1 -1
- package/dist/rules/no-unsafe-argument.js +1 -25
- package/dist/rules/no-unsafe-argument.js.map +1 -1
- package/dist/rules/no-unused-expressions.js +6 -2
- package/dist/rules/no-unused-expressions.js.map +1 -1
- package/dist/rules/restrict-plus-operands.js +12 -1
- package/dist/rules/restrict-plus-operands.js.map +1 -1
- package/dist/rules/restrict-template-expressions.js +52 -87
- package/dist/rules/restrict-template-expressions.js.map +1 -1
- package/dist/rules/use-unknown-in-catch-callback-variable.js +283 -0
- package/dist/rules/use-unknown-in-catch-callback-variable.js.map +1 -0
- package/dist/util/misc.js +10 -1
- package/dist/util/misc.js.map +1 -1
- package/docs/rules/TEMPLATE.md +10 -4
- package/docs/rules/{adjacent-overload-signatures.md → adjacent-overload-signatures.mdx} +11 -5
- package/docs/rules/{array-type.md → array-type.mdx} +24 -12
- package/docs/rules/{await-thenable.md → await-thenable.mdx} +10 -4
- package/docs/rules/{ban-ts-comment.md → ban-ts-comment.mdx} +32 -18
- package/docs/rules/{ban-tslint-comment.md → ban-tslint-comment.mdx} +10 -4
- package/docs/rules/{ban-types.md → ban-types.mdx} +11 -5
- package/docs/rules/{block-spacing.md → block-spacing.mdx} +3 -0
- package/docs/rules/{brace-style.md → brace-style.mdx} +3 -0
- package/docs/rules/camelcase.md +3 -5
- package/docs/rules/{class-literal-property-style.md → class-literal-property-style.mdx} +18 -11
- package/docs/rules/{class-methods-use-this.md → class-methods-use-this.mdx} +12 -6
- package/docs/rules/{comma-dangle.md → comma-dangle.mdx} +3 -0
- package/docs/rules/{comma-spacing.md → comma-spacing.mdx} +3 -0
- package/docs/rules/{consistent-generic-constructors.md → consistent-generic-constructors.mdx} +17 -8
- package/docs/rules/{consistent-indexed-object-style.md → consistent-indexed-object-style.mdx} +17 -8
- package/docs/rules/{consistent-return.md → consistent-return.mdx} +10 -4
- package/docs/rules/{consistent-type-assertions.md → consistent-type-assertions.mdx} +15 -10
- package/docs/rules/{consistent-type-definitions.md → consistent-type-definitions.mdx} +17 -8
- package/docs/rules/{consistent-type-exports.md → consistent-type-exports.mdx} +17 -8
- package/docs/rules/{consistent-type-imports.md → consistent-type-imports.mdx} +13 -8
- package/docs/rules/{default-param-last.md → default-param-last.mdx} +10 -4
- package/docs/rules/{dot-notation.md → dot-notation.mdx} +3 -0
- package/docs/rules/{explicit-function-return-type.md → explicit-function-return-type.mdx} +59 -32
- package/docs/rules/{explicit-member-accessibility.md → explicit-member-accessibility.mdx} +3 -0
- package/docs/rules/{explicit-module-boundary-types.md → explicit-module-boundary-types.mdx} +39 -21
- package/docs/rules/{func-call-spacing.md → func-call-spacing.mdx} +3 -0
- package/docs/rules/{indent.md → indent.mdx} +3 -0
- package/docs/rules/{init-declarations.md → init-declarations.mdx} +3 -0
- package/docs/rules/{key-spacing.md → key-spacing.mdx} +3 -0
- package/docs/rules/{keyword-spacing.md → keyword-spacing.mdx} +3 -0
- package/docs/rules/{lines-around-comment.md → lines-around-comment.mdx} +3 -0
- package/docs/rules/{lines-between-class-members.md → lines-between-class-members.mdx} +3 -0
- package/docs/rules/{max-params.md → max-params.mdx} +3 -0
- package/docs/rules/{member-delimiter-style.md → member-delimiter-style.mdx} +13 -7
- package/docs/rules/{member-ordering.md → member-ordering.mdx} +92 -56
- package/docs/rules/{method-signature-style.md → method-signature-style.mdx} +17 -8
- package/docs/rules/{naming-convention.md → naming-convention.mdx} +3 -0
- package/docs/rules/{no-array-constructor.md → no-array-constructor.mdx} +10 -4
- package/docs/rules/{no-array-delete.md → no-array-delete.mdx} +9 -5
- package/docs/rules/{no-base-to-string.md → no-base-to-string.mdx} +12 -6
- package/docs/rules/{no-confusing-non-null-assertion.md → no-confusing-non-null-assertion.mdx} +11 -5
- package/docs/rules/{no-confusing-void-expression.md → no-confusing-void-expression.mdx} +10 -4
- package/docs/rules/{no-dupe-class-members.md → no-dupe-class-members.mdx} +4 -1
- package/docs/rules/{no-duplicate-enum-values.md → no-duplicate-enum-values.mdx} +10 -4
- package/docs/rules/{no-duplicate-imports.md → no-duplicate-imports.mdx} +1 -1
- package/docs/rules/{no-duplicate-type-constituents.md → no-duplicate-type-constituents.mdx} +10 -4
- package/docs/rules/{no-dynamic-delete.md → no-dynamic-delete.mdx} +10 -4
- package/docs/rules/{no-empty-function.md → no-empty-function.mdx} +3 -0
- package/docs/rules/{no-empty-interface.md → no-empty-interface.mdx} +9 -5
- package/docs/rules/{no-explicit-any.md → no-explicit-any.mdx} +15 -9
- package/docs/rules/{no-extra-non-null-assertion.md → no-extra-non-null-assertion.mdx} +11 -5
- package/docs/rules/{no-extra-parens.md → no-extra-parens.mdx} +3 -0
- package/docs/rules/{no-extra-semi.md → no-extra-semi.mdx} +3 -0
- package/docs/rules/{no-extraneous-class.md → no-extraneous-class.mdx} +61 -33
- package/docs/rules/{no-floating-promises.md → no-floating-promises.mdx} +12 -6
- package/docs/rules/{no-for-in-array.md → no-for-in-array.mdx} +10 -4
- package/docs/rules/{no-implied-eval.md → no-implied-eval.mdx} +10 -4
- package/docs/rules/{no-import-type-side-effects.md → no-import-type-side-effects.mdx} +12 -6
- package/docs/rules/{no-inferrable-types.md → no-inferrable-types.mdx} +9 -5
- package/docs/rules/{no-invalid-this.md → no-invalid-this.mdx} +4 -1
- package/docs/rules/{no-invalid-void-type.md → no-invalid-void-type.mdx} +10 -4
- package/docs/rules/{no-loop-func.md → no-loop-func.mdx} +3 -0
- package/docs/rules/{no-loss-of-precision.md → no-loss-of-precision.mdx} +3 -0
- package/docs/rules/{no-magic-numbers.md → no-magic-numbers.mdx} +3 -0
- package/docs/rules/{no-meaningless-void-operator.md → no-meaningless-void-operator.mdx} +12 -4
- package/docs/rules/{no-misused-new.md → no-misused-new.mdx} +10 -4
- package/docs/rules/{no-misused-promises.md → no-misused-promises.mdx} +24 -16
- package/docs/rules/{no-mixed-enums.md → no-mixed-enums.mdx} +14 -6
- package/docs/rules/{no-namespace.md → no-namespace.mdx} +29 -18
- package/docs/rules/{no-non-null-asserted-nullish-coalescing.md → no-non-null-asserted-nullish-coalescing.mdx} +10 -4
- package/docs/rules/{no-non-null-asserted-optional-chain.md → no-non-null-asserted-optional-chain.mdx} +10 -4
- package/docs/rules/{no-non-null-assertion.md → no-non-null-assertion.mdx} +10 -4
- package/docs/rules/{no-redeclare.md → no-redeclare.mdx} +4 -1
- package/docs/rules/{no-redundant-type-constituents.md → no-redundant-type-constituents.mdx} +10 -4
- package/docs/rules/{no-require-imports.md → no-require-imports.mdx} +18 -9
- package/docs/rules/{no-restricted-imports.md → no-restricted-imports.mdx} +10 -4
- package/docs/rules/{no-shadow.md → no-shadow.mdx} +4 -1
- package/docs/rules/{no-this-alias.md → no-this-alias.mdx} +24 -12
- package/docs/rules/{no-throw-literal.md → no-throw-literal.mdx} +11 -5
- package/docs/rules/{no-type-alias.md → no-type-alias.mdx} +5 -2
- package/docs/rules/{no-unnecessary-boolean-literal-compare.md → no-unnecessary-boolean-literal-compare.mdx} +24 -12
- package/docs/rules/{no-unnecessary-condition.md → no-unnecessary-condition.mdx} +11 -5
- package/docs/rules/{no-unnecessary-qualifier.md → no-unnecessary-qualifier.mdx} +10 -4
- package/docs/rules/{no-unnecessary-type-arguments.md → no-unnecessary-type-arguments.mdx} +10 -4
- package/docs/rules/{no-unnecessary-type-assertion.md → no-unnecessary-type-assertion.mdx} +10 -4
- package/docs/rules/{no-unnecessary-type-constraint.md → no-unnecessary-type-constraint.mdx} +10 -4
- package/docs/rules/{no-unsafe-argument.md → no-unsafe-argument.mdx} +14 -10
- package/docs/rules/{no-unsafe-assignment.md → no-unsafe-assignment.mdx} +14 -10
- package/docs/rules/{no-unsafe-call.md → no-unsafe-call.mdx} +15 -9
- package/docs/rules/{no-unsafe-declaration-merging.md → no-unsafe-declaration-merging.mdx} +10 -4
- package/docs/rules/{no-unsafe-enum-comparison.md → no-unsafe-enum-comparison.mdx} +9 -5
- package/docs/rules/{no-unsafe-member-access.md → no-unsafe-member-access.mdx} +15 -9
- package/docs/rules/{no-unsafe-return.md → no-unsafe-return.mdx} +14 -10
- package/docs/rules/{no-unsafe-unary-minus.md → no-unsafe-unary-minus.mdx} +11 -5
- package/docs/rules/{no-unused-expressions.md → no-unused-expressions.mdx} +3 -0
- package/docs/rules/{no-unused-vars.md → no-unused-vars.mdx} +3 -0
- package/docs/rules/{no-use-before-define.md → no-use-before-define.mdx} +10 -4
- package/docs/rules/{no-useless-constructor.md → no-useless-constructor.mdx} +3 -0
- package/docs/rules/{no-useless-empty-export.md → no-useless-empty-export.mdx} +10 -4
- package/docs/rules/{no-useless-template-literals.md → no-useless-template-literals.mdx} +10 -6
- package/docs/rules/{no-var-requires.md → no-var-requires.mdx} +18 -9
- package/docs/rules/{non-nullable-type-assertion-style.md → non-nullable-type-assertion-style.mdx} +10 -4
- package/docs/rules/{object-curly-spacing.md → object-curly-spacing.mdx} +3 -0
- package/docs/rules/{padding-line-between-statements.md → padding-line-between-statements.mdx} +3 -0
- package/docs/rules/{parameter-properties.md → parameter-properties.mdx} +66 -36
- package/docs/rules/{prefer-as-const.md → prefer-as-const.mdx} +9 -5
- package/docs/rules/{prefer-destructuring.md → prefer-destructuring.mdx} +23 -12
- package/docs/rules/{prefer-enum-initializers.md → prefer-enum-initializers.mdx} +10 -4
- package/docs/rules/{prefer-find.md → prefer-find.mdx} +10 -4
- package/docs/rules/{prefer-for-of.md → prefer-for-of.mdx} +11 -5
- package/docs/rules/{prefer-function-type.md → prefer-function-type.mdx} +10 -4
- package/docs/rules/{prefer-includes.md → prefer-includes.mdx} +11 -5
- package/docs/rules/{prefer-literal-enum-member.md → prefer-literal-enum-member.mdx} +16 -9
- package/docs/rules/{prefer-namespace-keyword.md → prefer-namespace-keyword.mdx} +9 -5
- package/docs/rules/{prefer-nullish-coalescing.md → prefer-nullish-coalescing.mdx} +3 -0
- package/docs/rules/{prefer-optional-chain.md → prefer-optional-chain.mdx} +58 -33
- package/docs/rules/{prefer-promise-reject-errors.md → prefer-promise-reject-errors.mdx} +10 -4
- package/docs/rules/{prefer-readonly-parameter-types.md → prefer-readonly-parameter-types.mdx} +36 -22
- package/docs/rules/{prefer-readonly.md → prefer-readonly.mdx} +17 -8
- package/docs/rules/{prefer-reduce-type-parameter.md → prefer-reduce-type-parameter.mdx} +10 -4
- package/docs/rules/{prefer-regexp-exec.md → prefer-regexp-exec.mdx} +10 -4
- package/docs/rules/{prefer-return-this-type.md → prefer-return-this-type.mdx} +10 -4
- package/docs/rules/{prefer-string-starts-ends-with.md → prefer-string-starts-ends-with.mdx} +9 -5
- package/docs/rules/{prefer-ts-expect-error.md → prefer-ts-expect-error.mdx} +10 -4
- package/docs/rules/{promise-function-async.md → promise-function-async.mdx} +24 -12
- package/docs/rules/{quotes.md → quotes.mdx} +3 -0
- package/docs/rules/{require-array-sort-compare.md → require-array-sort-compare.mdx} +17 -8
- package/docs/rules/{require-await.md → require-await.mdx} +3 -0
- package/docs/rules/{restrict-plus-operands.md → restrict-plus-operands.mdx} +54 -30
- package/docs/rules/{restrict-template-expressions.md → restrict-template-expressions.mdx} +24 -9
- package/docs/rules/{return-await.md → return-await.mdx} +24 -12
- package/docs/rules/{semi.md → semi.mdx} +4 -1
- package/docs/rules/{sort-type-constituents.md → sort-type-constituents.mdx} +31 -16
- package/docs/rules/{space-before-blocks.md → space-before-blocks.mdx} +10 -4
- package/docs/rules/{space-before-function-paren.md → space-before-function-paren.mdx} +3 -0
- package/docs/rules/{space-infix-ops.md → space-infix-ops.mdx} +3 -0
- package/docs/rules/{strict-boolean-expressions.md → strict-boolean-expressions.mdx} +11 -5
- package/docs/rules/{switch-exhaustiveness-check.md → switch-exhaustiveness-check.mdx} +19 -14
- package/docs/rules/{triple-slash-reference.md → triple-slash-reference.mdx} +30 -17
- package/docs/rules/{type-annotation-spacing.md → type-annotation-spacing.mdx} +49 -31
- package/docs/rules/{typedef.md → typedef.mdx} +60 -33
- package/docs/rules/{unbound-method.md → unbound-method.mdx} +12 -6
- package/docs/rules/{unified-signatures.md → unified-signatures.mdx} +18 -9
- package/docs/rules/use-unknown-in-catch-callback-variable.mdx +84 -0
- package/package.json +8 -8
- /package/docs/rules/{no-parameter-properties.md → no-parameter-properties.mdx} +0 -0
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Enforce constituents of a type union/intersection to be sorted alphabetically.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/sort-type-constituents** for documentation.
|
|
@@ -18,9 +21,8 @@ This rule reports on any types that aren't sorted alphabetically.
|
|
|
18
21
|
|
|
19
22
|
## Examples
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
### ❌ Incorrect
|
|
24
|
+
<Tabs>
|
|
25
|
+
<TabItem value="❌ Incorrect">
|
|
24
26
|
|
|
25
27
|
```ts
|
|
26
28
|
type T1 = B | A;
|
|
@@ -50,7 +52,8 @@ type T4 =
|
|
|
50
52
|
| any;
|
|
51
53
|
```
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
</TabItem>
|
|
56
|
+
<TabItem value="✅ Correct">
|
|
54
57
|
|
|
55
58
|
```ts
|
|
56
59
|
type T1 = A | B;
|
|
@@ -80,6 +83,9 @@ type T4 =
|
|
|
80
83
|
| [1, 2, 4];
|
|
81
84
|
```
|
|
82
85
|
|
|
86
|
+
</TabItem>
|
|
87
|
+
</Tabs>
|
|
88
|
+
|
|
83
89
|
## Options
|
|
84
90
|
|
|
85
91
|
### `checkIntersections`
|
|
@@ -88,40 +94,46 @@ Whether to check intersection types (`&`).
|
|
|
88
94
|
|
|
89
95
|
Examples of code with `{ "checkIntersections": true }` (the default):
|
|
90
96
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
#### ❌ Incorrect
|
|
97
|
+
<Tabs>
|
|
98
|
+
<TabItem value="❌ Incorrect">
|
|
94
99
|
|
|
95
100
|
```ts option='{ "checkIntersections": true }'
|
|
96
101
|
type ExampleIntersection = B & A;
|
|
97
102
|
```
|
|
98
103
|
|
|
99
|
-
|
|
104
|
+
</TabItem>
|
|
105
|
+
<TabItem value="✅ Correct">
|
|
100
106
|
|
|
101
107
|
```ts option='{ "checkIntersections": true }'
|
|
102
108
|
type ExampleIntersection = A & B;
|
|
103
109
|
```
|
|
104
110
|
|
|
111
|
+
</TabItem>
|
|
112
|
+
</Tabs>
|
|
113
|
+
|
|
105
114
|
### `checkUnions`
|
|
106
115
|
|
|
107
116
|
Whether to check union types (`|`).
|
|
108
117
|
|
|
109
118
|
Examples of code with `{ "checkUnions": true }` (the default):
|
|
110
119
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
#### ❌ Incorrect
|
|
120
|
+
<Tabs>
|
|
121
|
+
<TabItem value="❌ Incorrect">
|
|
114
122
|
|
|
115
123
|
```ts option='{ "checkUnions": true }'
|
|
116
124
|
type ExampleUnion = B | A;
|
|
117
125
|
```
|
|
118
126
|
|
|
119
|
-
|
|
127
|
+
</TabItem>
|
|
128
|
+
<TabItem value="✅ Correct">
|
|
120
129
|
|
|
121
130
|
```ts option='{ "checkUnions": true }'
|
|
122
131
|
type ExampleUnion = A | B;
|
|
123
132
|
```
|
|
124
133
|
|
|
134
|
+
</TabItem>
|
|
135
|
+
</Tabs>
|
|
136
|
+
|
|
125
137
|
### `groupOrder`
|
|
126
138
|
|
|
127
139
|
Each constituent of the type is placed into a group, and then the rule sorts alphabetically within each group.
|
|
@@ -142,20 +154,23 @@ The ordering of groups is determined by this option.
|
|
|
142
154
|
|
|
143
155
|
For example, configuring the rule with `{ "groupOrder": ["literal", "nullish" ]}`:
|
|
144
156
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
#### ❌ Incorrect
|
|
157
|
+
<Tabs>
|
|
158
|
+
<TabItem value="❌ Incorrect">
|
|
148
159
|
|
|
149
160
|
```ts option='{ "groupOrder": ["literal", "nullish" ]}'
|
|
150
161
|
type ExampleGroup = null | 123;
|
|
151
162
|
```
|
|
152
163
|
|
|
153
|
-
|
|
164
|
+
</TabItem>
|
|
165
|
+
<TabItem value="✅ Correct">
|
|
154
166
|
|
|
155
167
|
```ts option='{ "groupOrder": ["literal", "nullish" ]}'
|
|
156
168
|
type ExampleGroup = 123 | null;
|
|
157
169
|
```
|
|
158
170
|
|
|
171
|
+
</TabItem>
|
|
172
|
+
</Tabs>
|
|
173
|
+
|
|
159
174
|
## When Not To Use It
|
|
160
175
|
|
|
161
176
|
This rule is purely a stylistic rule for maintaining consistency in your project.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Enforce consistent spacing before blocks.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/space-before-blocks** for documentation.
|
|
@@ -9,9 +12,8 @@ description: 'Enforce consistent spacing before blocks.'
|
|
|
9
12
|
This rule extends the base [`eslint/space-before-blocks`](https://eslint.org/docs/rules/space-before-blocks) rule.
|
|
10
13
|
It adds support for interfaces and enums.
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
### ❌ Incorrect
|
|
15
|
+
<Tabs>
|
|
16
|
+
<TabItem value="❌ Incorrect">
|
|
15
17
|
|
|
16
18
|
<!-- prettier-ignore -->
|
|
17
19
|
```ts
|
|
@@ -25,7 +27,8 @@ interface State{
|
|
|
25
27
|
}
|
|
26
28
|
```
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
</TabItem>
|
|
31
|
+
<TabItem value="✅ Correct">
|
|
29
32
|
|
|
30
33
|
```ts
|
|
31
34
|
enum Breakpoint {
|
|
@@ -38,6 +41,9 @@ interface State {
|
|
|
38
41
|
}
|
|
39
42
|
```
|
|
40
43
|
|
|
44
|
+
</TabItem>
|
|
45
|
+
</Tabs>
|
|
46
|
+
|
|
41
47
|
## Options
|
|
42
48
|
|
|
43
49
|
In case a more specific options object is passed these blocks will follow `classes` configuration option.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Enforce consistent spacing before function parenthesis.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/space-before-function-paren** for documentation.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Require spacing around infix operators.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/space-infix-ops** for documentation.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow certain types in boolean expressions.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/strict-boolean-expressions** for documentation.
|
|
@@ -21,9 +24,8 @@ The following nodes are considered boolean expressions and their type is checked
|
|
|
21
24
|
|
|
22
25
|
## Examples
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
### ❌ Incorrect
|
|
27
|
+
<Tabs>
|
|
28
|
+
<TabItem value="❌ Incorrect">
|
|
27
29
|
|
|
28
30
|
```ts
|
|
29
31
|
// nullable numbers are considered unsafe by default
|
|
@@ -55,7 +57,8 @@ while (obj) {
|
|
|
55
57
|
}
|
|
56
58
|
```
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
</TabItem>
|
|
61
|
+
<TabItem value="✅ Correct">
|
|
59
62
|
|
|
60
63
|
```tsx
|
|
61
64
|
// Using logical operator short-circuiting is allowed
|
|
@@ -85,6 +88,9 @@ function foo(bool?: boolean) {
|
|
|
85
88
|
const foo = (arg: any) => (Boolean(arg) ? 1 : 0);
|
|
86
89
|
```
|
|
87
90
|
|
|
91
|
+
</TabItem>
|
|
92
|
+
</Tabs>
|
|
93
|
+
|
|
88
94
|
## Options
|
|
89
95
|
|
|
90
96
|
### `allowString`
|
|
@@ -187,4 +193,4 @@ If you prefer more succinct checks over more precise boolean logic, this rule mi
|
|
|
187
193
|
|
|
188
194
|
## Related To
|
|
189
195
|
|
|
190
|
-
- [no-unnecessary-condition](./no-unnecessary-condition.
|
|
196
|
+
- [no-unnecessary-condition](./no-unnecessary-condition.mdx) - Similar rule which reports always-truthy and always-falsy values in conditions
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Require switch-case statements to be exhaustive.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/switch-exhaustiveness-check** for documentation.
|
|
@@ -50,17 +53,14 @@ switch (value) {
|
|
|
50
53
|
|
|
51
54
|
Since `value` is a non-union type it requires the switch case to have a default clause only with `requireDefaultForNonUnion` enabled.
|
|
52
55
|
|
|
53
|
-
<!--/tabs-->
|
|
54
|
-
|
|
55
56
|
## Examples
|
|
56
57
|
|
|
57
58
|
When the switch doesn't have exhaustive cases, either filling them all out or adding a default will correct the rule's complaint.
|
|
58
59
|
|
|
59
60
|
Here are some examples of code working with a union of literals:
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
### ❌ Incorrect
|
|
62
|
+
<Tabs>
|
|
63
|
+
<TabItem value="❌ Incorrect">
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
66
|
type Day =
|
|
@@ -82,7 +82,8 @@ switch (day) {
|
|
|
82
82
|
}
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
</TabItem>
|
|
86
|
+
<TabItem value="✅ Correct (Exhaustive)">
|
|
86
87
|
|
|
87
88
|
```ts
|
|
88
89
|
type Day =
|
|
@@ -122,7 +123,8 @@ switch (day) {
|
|
|
122
123
|
}
|
|
123
124
|
```
|
|
124
125
|
|
|
125
|
-
|
|
126
|
+
</TabItem>
|
|
127
|
+
<TabItem value="✅ Correct (Defaulted)">
|
|
126
128
|
|
|
127
129
|
```ts
|
|
128
130
|
type Day =
|
|
@@ -146,13 +148,13 @@ switch (day) {
|
|
|
146
148
|
}
|
|
147
149
|
```
|
|
148
150
|
|
|
149
|
-
|
|
151
|
+
</TabItem>
|
|
152
|
+
</Tabs>
|
|
150
153
|
|
|
151
154
|
Likewise, here are some examples of code working with an enum:
|
|
152
155
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
### ❌ Incorrect
|
|
156
|
+
<Tabs>
|
|
157
|
+
<TabItem value="❌ Incorrect">
|
|
156
158
|
|
|
157
159
|
```ts
|
|
158
160
|
enum Fruit {
|
|
@@ -170,7 +172,8 @@ switch (fruit) {
|
|
|
170
172
|
}
|
|
171
173
|
```
|
|
172
174
|
|
|
173
|
-
|
|
175
|
+
</TabItem>
|
|
176
|
+
<TabItem value="✅ Correct (Exhaustive)">
|
|
174
177
|
|
|
175
178
|
```ts
|
|
176
179
|
enum Fruit {
|
|
@@ -196,7 +199,8 @@ switch (fruit) {
|
|
|
196
199
|
}
|
|
197
200
|
```
|
|
198
201
|
|
|
199
|
-
|
|
202
|
+
</TabItem>
|
|
203
|
+
<TabItem value="✅ Correct (Defaulted)">
|
|
200
204
|
|
|
201
205
|
```ts
|
|
202
206
|
enum Fruit {
|
|
@@ -218,7 +222,8 @@ switch (fruit) {
|
|
|
218
222
|
}
|
|
219
223
|
```
|
|
220
224
|
|
|
221
|
-
|
|
225
|
+
</TabItem>
|
|
226
|
+
</Tabs>
|
|
222
227
|
|
|
223
228
|
## When Not To Use It
|
|
224
229
|
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow certain triple slash directives in favor of ES6-style import declarations.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/triple-slash-reference** for documentation.
|
|
@@ -19,9 +22,8 @@ Specifying `'always'` disables this lint rule for that kind of reference.
|
|
|
19
22
|
|
|
20
23
|
When set to `'never'`, bans `/// <reference lib="..." />` and enforces using an `import` instead:
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
#### ❌ Incorrect
|
|
25
|
+
<Tabs>
|
|
26
|
+
<TabItem value="❌ Incorrect">
|
|
25
27
|
|
|
26
28
|
```ts option='{ "lib": "never" }'
|
|
27
29
|
/// <reference lib="code" />
|
|
@@ -29,19 +31,22 @@ When set to `'never'`, bans `/// <reference lib="..." />` and enforces using an
|
|
|
29
31
|
globalThis.value;
|
|
30
32
|
```
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
</TabItem>
|
|
35
|
+
<TabItem value="✅ Correct">
|
|
33
36
|
|
|
34
37
|
```ts option='{ "lib": "never" }'
|
|
35
38
|
import { value } from 'code';
|
|
36
39
|
```
|
|
37
40
|
|
|
41
|
+
</TabItem>
|
|
42
|
+
</Tabs>
|
|
43
|
+
|
|
38
44
|
### `path`
|
|
39
45
|
|
|
40
46
|
When set to `'never'`, bans `/// <reference path="..." />` and enforces using an `import` instead:
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
#### ❌ Incorrect
|
|
48
|
+
<Tabs>
|
|
49
|
+
<TabItem value="❌ Incorrect">
|
|
45
50
|
|
|
46
51
|
```ts option='{ "path": "never" }'
|
|
47
52
|
/// <reference path="code" />
|
|
@@ -49,19 +54,22 @@ When set to `'never'`, bans `/// <reference path="..." />` and enforces using an
|
|
|
49
54
|
globalThis.value;
|
|
50
55
|
```
|
|
51
56
|
|
|
52
|
-
|
|
57
|
+
</TabItem>
|
|
58
|
+
<TabItem value="✅ Correct">
|
|
53
59
|
|
|
54
60
|
```ts option='{ "path": "never" }'
|
|
55
61
|
import { value } from 'code';
|
|
56
62
|
```
|
|
57
63
|
|
|
64
|
+
</TabItem>
|
|
65
|
+
</Tabs>
|
|
66
|
+
|
|
58
67
|
### `types`
|
|
59
68
|
|
|
60
69
|
When set to `'never'`, bans `/// <reference types="..." />` and enforces using an `import` instead:
|
|
61
70
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
#### ❌ Incorrect
|
|
71
|
+
<Tabs>
|
|
72
|
+
<TabItem value="❌ Incorrect">
|
|
65
73
|
|
|
66
74
|
```ts option='{ "types": "never" }'
|
|
67
75
|
/// <reference types="code" />
|
|
@@ -69,20 +77,21 @@ When set to `'never'`, bans `/// <reference types="..." />` and enforces using a
|
|
|
69
77
|
globalThis.value;
|
|
70
78
|
```
|
|
71
79
|
|
|
72
|
-
|
|
80
|
+
</TabItem>
|
|
81
|
+
<TabItem value="✅ Correct">
|
|
73
82
|
|
|
74
83
|
```ts option='{ "types": "never" }'
|
|
75
84
|
import { value } from 'code';
|
|
76
85
|
```
|
|
77
86
|
|
|
78
|
-
|
|
87
|
+
</TabItem>
|
|
88
|
+
</Tabs>
|
|
79
89
|
|
|
80
90
|
The `types` option may alternately be given a `"prefer-import"` value.
|
|
81
91
|
Doing so indicates the rule should only report if there is already an `import` from the same location:
|
|
82
92
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
#### ❌ Incorrect
|
|
93
|
+
<Tabs>
|
|
94
|
+
<TabItem value="❌ Incorrect">
|
|
86
95
|
|
|
87
96
|
```ts option='{ "types": "prefer-import" }'
|
|
88
97
|
/// <reference types="code" />
|
|
@@ -92,12 +101,16 @@ import { valueA } from 'code';
|
|
|
92
101
|
globalThis.valueB;
|
|
93
102
|
```
|
|
94
103
|
|
|
95
|
-
|
|
104
|
+
</TabItem>
|
|
105
|
+
<TabItem value="✅ Correct">
|
|
96
106
|
|
|
97
107
|
```ts option='{ "types": "prefer-import" }'
|
|
98
108
|
import { valueA, valueB } from 'code';
|
|
99
109
|
```
|
|
100
110
|
|
|
111
|
+
</TabItem>
|
|
112
|
+
</Tabs>
|
|
113
|
+
|
|
101
114
|
## When Not To Use It
|
|
102
115
|
|
|
103
116
|
Most modern TypeScript projects generally use `import` statements to bring in types.
|
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
description: 'Require consistent spacing around type annotations.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
import Tabs from '@theme/Tabs';
|
|
6
|
+
import TabItem from '@theme/TabItem';
|
|
7
|
+
|
|
5
8
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
9
|
>
|
|
7
10
|
> See **https://typescript-eslint.io/rules/type-annotation-spacing** for documentation.
|
|
8
11
|
|
|
9
12
|
Spacing around type annotations improves readability of the code. Although the most commonly used style guideline for type annotations in TypeScript prescribes adding a space after the colon, but not before it, it is subjective to the preferences of a project. For example:
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
{/* prettier-ignore */}
|
|
12
15
|
```ts
|
|
13
16
|
// with space after, but not before (default if no option is specified)
|
|
14
17
|
let foo: string = "bar";
|
|
@@ -39,11 +42,10 @@ type Foo = (string: name) =>string;
|
|
|
39
42
|
|
|
40
43
|
This rule aims to enforce specific spacing patterns around type annotations and function types in type literals.
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
### ❌ Incorrect
|
|
45
|
+
<Tabs>
|
|
46
|
+
<TabItem value="❌ Incorrect">
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
{/* prettier-ignore */}
|
|
47
49
|
```ts
|
|
48
50
|
let foo:string = "bar";
|
|
49
51
|
let foo :string = "bar";
|
|
@@ -70,9 +72,10 @@ type Foo = () =>{};
|
|
|
70
72
|
type Foo = ()=> {};
|
|
71
73
|
```
|
|
72
74
|
|
|
73
|
-
|
|
75
|
+
</TabItem>
|
|
76
|
+
<TabItem value="✅ Correct">
|
|
74
77
|
|
|
75
|
-
|
|
78
|
+
{/* prettier-ignore */}
|
|
76
79
|
```ts
|
|
77
80
|
let foo: string = "bar";
|
|
78
81
|
|
|
@@ -85,6 +88,9 @@ class Foo {
|
|
|
85
88
|
type Foo = () => {};
|
|
86
89
|
```
|
|
87
90
|
|
|
91
|
+
</TabItem>
|
|
92
|
+
</Tabs>
|
|
93
|
+
|
|
88
94
|
## Options
|
|
89
95
|
|
|
90
96
|
### after
|
|
@@ -93,11 +99,10 @@ type Foo = () => {};
|
|
|
93
99
|
{ "before": false, "after": true }
|
|
94
100
|
```
|
|
95
101
|
|
|
96
|
-
|
|
102
|
+
<Tabs>
|
|
103
|
+
<TabItem value="❌ Incorrect">
|
|
97
104
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
<!-- prettier-ignore -->
|
|
105
|
+
{/* prettier-ignore */}
|
|
101
106
|
```ts option='{ "before": false, "after": true }'
|
|
102
107
|
let foo:string = "bar";
|
|
103
108
|
let foo :string = "bar";
|
|
@@ -124,9 +129,10 @@ type Foo = () =>{};
|
|
|
124
129
|
type Foo = () => {};
|
|
125
130
|
```
|
|
126
131
|
|
|
127
|
-
|
|
132
|
+
</TabItem>
|
|
133
|
+
<TabItem value="✅ Correct">
|
|
128
134
|
|
|
129
|
-
|
|
135
|
+
{/* prettier-ignore */}
|
|
130
136
|
```ts option='{ "before": false, "after": true }'
|
|
131
137
|
let foo: string = "bar";
|
|
132
138
|
|
|
@@ -139,17 +145,19 @@ class Foo {
|
|
|
139
145
|
type Foo = ()=> {};
|
|
140
146
|
```
|
|
141
147
|
|
|
148
|
+
</TabItem>
|
|
149
|
+
</Tabs>
|
|
150
|
+
|
|
142
151
|
### before
|
|
143
152
|
|
|
144
153
|
```json
|
|
145
154
|
{ "before": true, "after": true }
|
|
146
155
|
```
|
|
147
156
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
#### ❌ Incorrect
|
|
157
|
+
<Tabs>
|
|
158
|
+
<TabItem value="❌ Incorrect">
|
|
151
159
|
|
|
152
|
-
|
|
160
|
+
{/* prettier-ignore */}
|
|
153
161
|
```ts option='{ "before": true, "after": true }'
|
|
154
162
|
let foo: string = "bar";
|
|
155
163
|
let foo:string = "bar";
|
|
@@ -176,9 +184,10 @@ type Foo = () =>{};
|
|
|
176
184
|
type Foo = ()=> {};
|
|
177
185
|
```
|
|
178
186
|
|
|
179
|
-
|
|
187
|
+
</TabItem>
|
|
188
|
+
<TabItem value="✅ Correct">
|
|
180
189
|
|
|
181
|
-
|
|
190
|
+
{/* prettier-ignore */}
|
|
182
191
|
```ts option='{ "before": true, "after": true }'
|
|
183
192
|
let foo : string = "bar";
|
|
184
193
|
|
|
@@ -191,6 +200,9 @@ class Foo {
|
|
|
191
200
|
type Foo = () => {};
|
|
192
201
|
```
|
|
193
202
|
|
|
203
|
+
</TabItem>
|
|
204
|
+
</Tabs>
|
|
205
|
+
|
|
194
206
|
### overrides - colon
|
|
195
207
|
|
|
196
208
|
```json
|
|
@@ -201,11 +213,10 @@ type Foo = () => {};
|
|
|
201
213
|
}
|
|
202
214
|
```
|
|
203
215
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
#### ❌ Incorrect
|
|
216
|
+
<Tabs>
|
|
217
|
+
<TabItem value="❌ Incorrect">
|
|
207
218
|
|
|
208
|
-
|
|
219
|
+
{/* prettier-ignore */}
|
|
209
220
|
```ts option='{"before":false,"after":false,"overrides":{"colon":{"before":true,"after":true}}}'
|
|
210
221
|
let foo: string = "bar";
|
|
211
222
|
let foo:string = "bar";
|
|
@@ -232,9 +243,10 @@ type Foo = ()=> {};
|
|
|
232
243
|
type Foo = () => {};
|
|
233
244
|
```
|
|
234
245
|
|
|
235
|
-
|
|
246
|
+
</TabItem>
|
|
247
|
+
<TabItem value="✅ Correct">
|
|
236
248
|
|
|
237
|
-
|
|
249
|
+
{/* prettier-ignore */}
|
|
238
250
|
```ts option='{"before":false,"after":false,"overrides":{"colon":{"before":true,"after":true}}}'
|
|
239
251
|
let foo : string = "bar";
|
|
240
252
|
|
|
@@ -251,6 +263,9 @@ type Foo = {
|
|
|
251
263
|
type Foo = ()=>{};
|
|
252
264
|
```
|
|
253
265
|
|
|
266
|
+
</TabItem>
|
|
267
|
+
</Tabs>
|
|
268
|
+
|
|
254
269
|
### overrides - arrow
|
|
255
270
|
|
|
256
271
|
```json
|
|
@@ -261,11 +276,10 @@ type Foo = ()=>{};
|
|
|
261
276
|
}
|
|
262
277
|
```
|
|
263
278
|
|
|
264
|
-
|
|
279
|
+
<Tabs>
|
|
280
|
+
<TabItem value="❌ Incorrect">
|
|
265
281
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
<!-- prettier-ignore -->
|
|
282
|
+
{/* prettier-ignore */}
|
|
269
283
|
```ts option='{"before":false,"after":false,"overrides":{"arrow":{"before":true,"after":true}}}'
|
|
270
284
|
let foo: string = "bar";
|
|
271
285
|
let foo : string = "bar";
|
|
@@ -292,9 +306,10 @@ type Foo = () =>{};
|
|
|
292
306
|
type Foo = ()=> {};
|
|
293
307
|
```
|
|
294
308
|
|
|
295
|
-
|
|
309
|
+
</TabItem>
|
|
310
|
+
<TabItem value="✅ Correct">
|
|
296
311
|
|
|
297
|
-
|
|
312
|
+
{/* prettier-ignore */}
|
|
298
313
|
```ts option='{"before":false,"after":false,"overrides":{"arrow":{"before":true,"after":true}}}'
|
|
299
314
|
let foo:string = "bar";
|
|
300
315
|
|
|
@@ -307,6 +322,9 @@ class Foo {
|
|
|
307
322
|
type Foo = () => {};
|
|
308
323
|
```
|
|
309
324
|
|
|
325
|
+
</TabItem>
|
|
326
|
+
</Tabs>
|
|
327
|
+
|
|
310
328
|
## When Not To Use It
|
|
311
329
|
|
|
312
330
|
If you don't want to enforce spacing for your type annotations, you can safely turn this rule off.
|