@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: 'Require or disallow parameter properties in class constructors.'
|
|
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/parameter-properties** for documentation.
|
|
@@ -59,9 +62,8 @@ In `"parameter-property"` mode, the rule will issue a report when:
|
|
|
59
62
|
|
|
60
63
|
Examples of code for this rule with no options at all:
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
#### ❌ Incorrect
|
|
65
|
+
<Tabs>
|
|
66
|
+
<TabItem value="❌ Incorrect">
|
|
65
67
|
|
|
66
68
|
```ts
|
|
67
69
|
class Foo {
|
|
@@ -93,7 +95,8 @@ class Foo {
|
|
|
93
95
|
}
|
|
94
96
|
```
|
|
95
97
|
|
|
96
|
-
|
|
98
|
+
</TabItem>
|
|
99
|
+
<TabItem value="✅ Correct">
|
|
97
100
|
|
|
98
101
|
```ts
|
|
99
102
|
class Foo {
|
|
@@ -101,13 +104,15 @@ class Foo {
|
|
|
101
104
|
}
|
|
102
105
|
```
|
|
103
106
|
|
|
107
|
+
</TabItem>
|
|
108
|
+
</Tabs>
|
|
109
|
+
|
|
104
110
|
### readonly
|
|
105
111
|
|
|
106
112
|
Examples of code for the `{ "allow": ["readonly"] }` options:
|
|
107
113
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
#### ❌ Incorrect
|
|
114
|
+
<Tabs>
|
|
115
|
+
<TabItem value="❌ Incorrect">
|
|
111
116
|
|
|
112
117
|
```ts option='{ "allow": ["readonly"] }'
|
|
113
118
|
class Foo {
|
|
@@ -135,7 +140,8 @@ class Foo {
|
|
|
135
140
|
}
|
|
136
141
|
```
|
|
137
142
|
|
|
138
|
-
|
|
143
|
+
</TabItem>
|
|
144
|
+
<TabItem value="✅ Correct">
|
|
139
145
|
|
|
140
146
|
```ts option='{ "allow": ["readonly"] }'
|
|
141
147
|
class Foo {
|
|
@@ -147,13 +153,15 @@ class Foo {
|
|
|
147
153
|
}
|
|
148
154
|
```
|
|
149
155
|
|
|
156
|
+
</TabItem>
|
|
157
|
+
</Tabs>
|
|
158
|
+
|
|
150
159
|
### private
|
|
151
160
|
|
|
152
161
|
Examples of code for the `{ "allow": ["private"] }` options:
|
|
153
162
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
#### ❌ Incorrect
|
|
163
|
+
<Tabs>
|
|
164
|
+
<TabItem value="❌ Incorrect">
|
|
157
165
|
|
|
158
166
|
```ts option='{ "allow": ["private"] }'
|
|
159
167
|
class Foo {
|
|
@@ -181,7 +189,8 @@ class Foo {
|
|
|
181
189
|
}
|
|
182
190
|
```
|
|
183
191
|
|
|
184
|
-
|
|
192
|
+
</TabItem>
|
|
193
|
+
<TabItem value="✅ Correct">
|
|
185
194
|
|
|
186
195
|
```ts option='{ "allow": ["private"] }'
|
|
187
196
|
class Foo {
|
|
@@ -193,13 +202,15 @@ class Foo {
|
|
|
193
202
|
}
|
|
194
203
|
```
|
|
195
204
|
|
|
205
|
+
</TabItem>
|
|
206
|
+
</Tabs>
|
|
207
|
+
|
|
196
208
|
### protected
|
|
197
209
|
|
|
198
210
|
Examples of code for the `{ "allow": ["protected"] }` options:
|
|
199
211
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
#### ❌ Incorrect
|
|
212
|
+
<Tabs>
|
|
213
|
+
<TabItem value="❌ Incorrect">
|
|
203
214
|
|
|
204
215
|
```ts option='{ "allow": ["protected"] }'
|
|
205
216
|
class Foo {
|
|
@@ -227,7 +238,8 @@ class Foo {
|
|
|
227
238
|
}
|
|
228
239
|
```
|
|
229
240
|
|
|
230
|
-
|
|
241
|
+
</TabItem>
|
|
242
|
+
<TabItem value="✅ Correct">
|
|
231
243
|
|
|
232
244
|
```ts option='{ "allow": ["protected"] }'
|
|
233
245
|
class Foo {
|
|
@@ -239,13 +251,15 @@ class Foo {
|
|
|
239
251
|
}
|
|
240
252
|
```
|
|
241
253
|
|
|
254
|
+
</TabItem>
|
|
255
|
+
</Tabs>
|
|
256
|
+
|
|
242
257
|
### public
|
|
243
258
|
|
|
244
259
|
Examples of code for the `{ "allow": ["public"] }` options:
|
|
245
260
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
#### ❌ Incorrect
|
|
261
|
+
<Tabs>
|
|
262
|
+
<TabItem value="❌ Incorrect">
|
|
249
263
|
|
|
250
264
|
```ts option='{ "allow": ["public"] }'
|
|
251
265
|
class Foo {
|
|
@@ -273,7 +287,8 @@ class Foo {
|
|
|
273
287
|
}
|
|
274
288
|
```
|
|
275
289
|
|
|
276
|
-
|
|
290
|
+
</TabItem>
|
|
291
|
+
<TabItem value="✅ Correct">
|
|
277
292
|
|
|
278
293
|
```ts option='{ "allow": ["public"] }'
|
|
279
294
|
class Foo {
|
|
@@ -285,13 +300,15 @@ class Foo {
|
|
|
285
300
|
}
|
|
286
301
|
```
|
|
287
302
|
|
|
303
|
+
</TabItem>
|
|
304
|
+
</Tabs>
|
|
305
|
+
|
|
288
306
|
### private readonly
|
|
289
307
|
|
|
290
308
|
Examples of code for the `{ "allow": ["private readonly"] }` options:
|
|
291
309
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
#### ❌ Incorrect
|
|
310
|
+
<Tabs>
|
|
311
|
+
<TabItem value="❌ Incorrect">
|
|
295
312
|
|
|
296
313
|
```ts option='{ "allow": ["private readonly"] }'
|
|
297
314
|
class Foo {
|
|
@@ -319,7 +336,8 @@ class Foo {
|
|
|
319
336
|
}
|
|
320
337
|
```
|
|
321
338
|
|
|
322
|
-
|
|
339
|
+
</TabItem>
|
|
340
|
+
<TabItem value="✅ Correct">
|
|
323
341
|
|
|
324
342
|
```ts option='{ "allow": ["private readonly"] }'
|
|
325
343
|
class Foo {
|
|
@@ -331,13 +349,15 @@ class Foo {
|
|
|
331
349
|
}
|
|
332
350
|
```
|
|
333
351
|
|
|
352
|
+
</TabItem>
|
|
353
|
+
</Tabs>
|
|
354
|
+
|
|
334
355
|
### protected readonly
|
|
335
356
|
|
|
336
357
|
Examples of code for the `{ "allow": ["protected readonly"] }` options:
|
|
337
358
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
#### ❌ Incorrect
|
|
359
|
+
<Tabs>
|
|
360
|
+
<TabItem value="❌ Incorrect">
|
|
341
361
|
|
|
342
362
|
```ts option='{ "allow": ["protected readonly"] }'
|
|
343
363
|
class Foo {
|
|
@@ -365,7 +385,8 @@ class Foo {
|
|
|
365
385
|
}
|
|
366
386
|
```
|
|
367
387
|
|
|
368
|
-
|
|
388
|
+
</TabItem>
|
|
389
|
+
<TabItem value="✅ Correct">
|
|
369
390
|
|
|
370
391
|
```ts option='{ "allow": ["protected readonly"] }'
|
|
371
392
|
class Foo {
|
|
@@ -377,13 +398,15 @@ class Foo {
|
|
|
377
398
|
}
|
|
378
399
|
```
|
|
379
400
|
|
|
401
|
+
</TabItem>
|
|
402
|
+
</Tabs>
|
|
403
|
+
|
|
380
404
|
### public readonly
|
|
381
405
|
|
|
382
406
|
Examples of code for the `{ "allow": ["public readonly"] }` options:
|
|
383
407
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
#### ❌ Incorrect
|
|
408
|
+
<Tabs>
|
|
409
|
+
<TabItem value="❌ Incorrect">
|
|
387
410
|
|
|
388
411
|
```ts option='{ "allow": ["public readonly"] }'
|
|
389
412
|
class Foo {
|
|
@@ -411,7 +434,8 @@ class Foo {
|
|
|
411
434
|
}
|
|
412
435
|
```
|
|
413
436
|
|
|
414
|
-
|
|
437
|
+
</TabItem>
|
|
438
|
+
<TabItem value="✅ Correct">
|
|
415
439
|
|
|
416
440
|
```ts option='{ "allow": ["public readonly"] }'
|
|
417
441
|
class Foo {
|
|
@@ -423,13 +447,15 @@ class Foo {
|
|
|
423
447
|
}
|
|
424
448
|
```
|
|
425
449
|
|
|
450
|
+
</TabItem>
|
|
451
|
+
</Tabs>
|
|
452
|
+
|
|
426
453
|
### `"parameter-property"`
|
|
427
454
|
|
|
428
455
|
Examples of code for the `{ "prefer": "parameter-property" }` option:
|
|
429
456
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
#### ❌ Incorrect
|
|
457
|
+
<Tabs>
|
|
458
|
+
<TabItem value="❌ Incorrect">
|
|
433
459
|
|
|
434
460
|
```ts option='{ "prefer": "parameter-property" }'
|
|
435
461
|
class Foo {
|
|
@@ -454,7 +480,8 @@ class Foo {
|
|
|
454
480
|
}
|
|
455
481
|
```
|
|
456
482
|
|
|
457
|
-
|
|
483
|
+
</TabItem>
|
|
484
|
+
<TabItem value="✅ Correct">
|
|
458
485
|
|
|
459
486
|
```ts option='{ "prefer": "parameter-property" }'
|
|
460
487
|
class Foo {
|
|
@@ -480,6 +507,9 @@ class Foo {
|
|
|
480
507
|
}
|
|
481
508
|
```
|
|
482
509
|
|
|
510
|
+
</TabItem>
|
|
511
|
+
</Tabs>
|
|
512
|
+
|
|
483
513
|
## When Not To Use It
|
|
484
514
|
|
|
485
515
|
If you don't care about which style of parameter properties in constructors is used in your classes, then you will not need this rule.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Enforce the use of `as const` over literal type.'
|
|
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/prefer-as-const** for documentation.
|
|
@@ -16,9 +19,8 @@ This rule reports when an `as` with an explicit literal type can be replaced wit
|
|
|
16
19
|
|
|
17
20
|
## Examples
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
### ❌ Incorrect
|
|
22
|
+
<Tabs>
|
|
23
|
+
<TabItem value="❌ Incorrect">
|
|
22
24
|
|
|
23
25
|
```ts
|
|
24
26
|
let bar: 2 = 2;
|
|
@@ -26,7 +28,8 @@ let foo = <'bar'>'bar';
|
|
|
26
28
|
let foo = { bar: 'baz' as 'baz' };
|
|
27
29
|
```
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
</TabItem>
|
|
32
|
+
<TabItem value="✅ Correct">
|
|
30
33
|
|
|
31
34
|
```ts
|
|
32
35
|
let foo = 'bar';
|
|
@@ -37,7 +40,8 @@ let foo = <string>'bar';
|
|
|
37
40
|
let foo = { bar: 'baz' };
|
|
38
41
|
```
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
</TabItem>
|
|
44
|
+
</Tabs>
|
|
41
45
|
|
|
42
46
|
## When Not To Use It
|
|
43
47
|
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Require destructuring from arrays and/or objects.'
|
|
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/prefer-destructuring** for documentation.
|
|
@@ -11,35 +14,37 @@ description: 'Require destructuring from arrays and/or objects.'
|
|
|
11
14
|
This rule extends the base [`eslint/prefer-destructuring`](https://eslint.org/docs/latest/rules/prefer-destructuring) rule.
|
|
12
15
|
It adds support for TypeScript's type annotations in variable declarations.
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
<Tabs>
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
<TabItem value="`eslint/prefer-destructuring`">
|
|
17
20
|
|
|
18
21
|
```ts
|
|
19
22
|
const x: string = obj.x; // This is incorrect and the auto fixer provides following untyped fix.
|
|
20
23
|
// const { x } = obj;
|
|
21
24
|
```
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
</TabItem>
|
|
27
|
+
<TabItem value="`@typescript-eslint/prefer-destructuring`">
|
|
24
28
|
|
|
25
29
|
```ts
|
|
26
30
|
const x: string = obj.x; // This is correct by default. You can also forbid this by an option.
|
|
27
31
|
```
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
</TabItem>
|
|
34
|
+
</Tabs>
|
|
30
35
|
|
|
31
36
|
And it infers binding patterns more accurately thanks to the type checker.
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
### ❌ Incorrect
|
|
38
|
+
<Tabs>
|
|
39
|
+
<TabItem value="❌ Incorrect">
|
|
36
40
|
|
|
37
41
|
```ts
|
|
38
42
|
const x = ['a'];
|
|
39
43
|
const y = x[0];
|
|
40
44
|
```
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
</TabItem>
|
|
47
|
+
<TabItem value="✅ Correct">
|
|
43
48
|
|
|
44
49
|
```ts
|
|
45
50
|
const x = { 0: 'a' };
|
|
@@ -49,6 +54,9 @@ const y = x[0];
|
|
|
49
54
|
It is correct when `enforceForRenamedProperties` is not true.
|
|
50
55
|
Valid destructuring syntax is renamed style like `{ 0: y } = x` rather than `[y] = x` because `x` is not iterable.
|
|
51
56
|
|
|
57
|
+
</TabItem>
|
|
58
|
+
</Tabs>
|
|
59
|
+
|
|
52
60
|
## Options
|
|
53
61
|
|
|
54
62
|
This rule adds the following options:
|
|
@@ -76,16 +84,19 @@ When set to `true`, type annotated variable declarations are enforced to use des
|
|
|
76
84
|
|
|
77
85
|
Examples with `{ enforceForDeclarationWithTypeAnnotation: true }`:
|
|
78
86
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
### ❌ Incorrect
|
|
87
|
+
<Tabs>
|
|
88
|
+
<TabItem value="❌ Incorrect">
|
|
82
89
|
|
|
83
90
|
```ts
|
|
84
91
|
const x: string = obj.x;
|
|
85
92
|
```
|
|
86
93
|
|
|
87
|
-
|
|
94
|
+
</TabItem>
|
|
95
|
+
<TabItem value="✅ Correct">
|
|
88
96
|
|
|
89
97
|
```ts
|
|
90
98
|
const { x }: { x: string } = obj;
|
|
91
99
|
```
|
|
100
|
+
|
|
101
|
+
</TabItem>
|
|
102
|
+
</Tabs>
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Require each enum member value to be explicitly initialized.'
|
|
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/prefer-enum-initializers** for documentation.
|
|
@@ -15,9 +18,8 @@ This rule recommends having each `enum` member value explicitly initialized.
|
|
|
15
18
|
|
|
16
19
|
## Examples
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
### ❌ Incorrect
|
|
21
|
+
<Tabs>
|
|
22
|
+
<TabItem value="❌ Incorrect">
|
|
21
23
|
|
|
22
24
|
```ts
|
|
23
25
|
enum Status {
|
|
@@ -37,7 +39,8 @@ enum Color {
|
|
|
37
39
|
}
|
|
38
40
|
```
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
</TabItem>
|
|
43
|
+
<TabItem value="✅ Correct">
|
|
41
44
|
|
|
42
45
|
```ts
|
|
43
46
|
enum Status {
|
|
@@ -57,6 +60,9 @@ enum Color {
|
|
|
57
60
|
}
|
|
58
61
|
```
|
|
59
62
|
|
|
63
|
+
</TabItem>
|
|
64
|
+
</Tabs>
|
|
65
|
+
|
|
60
66
|
## When Not To Use It
|
|
61
67
|
|
|
62
68
|
If you don't care about `enum`s having implicit values you can safely disable this rule.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Enforce the use of Array.prototype.find() over Array.prototype.filter() followed by [0] when looking for a single result.'
|
|
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/prefer-find** for documentation.
|
|
@@ -18,9 +21,8 @@ Therefore, when fixing errors from this rule, be sure that your `.filter()` call
|
|
|
18
21
|
|
|
19
22
|
:::
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
### ❌ Incorrect
|
|
24
|
+
<Tabs>
|
|
25
|
+
<TabItem value="❌ Incorrect">
|
|
24
26
|
|
|
25
27
|
```ts
|
|
26
28
|
[1, 2, 3].filter(x => x > 1)[0];
|
|
@@ -28,12 +30,16 @@ Therefore, when fixing errors from this rule, be sure that your `.filter()` call
|
|
|
28
30
|
[1, 2, 3].filter(x => x > 1).at(0);
|
|
29
31
|
```
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
</TabItem>
|
|
34
|
+
<TabItem value="✅ Correct">
|
|
32
35
|
|
|
33
36
|
```ts
|
|
34
37
|
[1, 2, 3].find(x => x > 1);
|
|
35
38
|
```
|
|
36
39
|
|
|
40
|
+
</TabItem>
|
|
41
|
+
</Tabs>
|
|
42
|
+
|
|
37
43
|
## When Not To Use It
|
|
38
44
|
|
|
39
45
|
If you intentionally use patterns like `.filter(callback)[0]` to execute side effects in `callback` on all array elements, you will want to avoid this rule.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Enforce the use of `for-of` loop over the standard `for` loop where possible.'
|
|
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/prefer-for-of** for documentation.
|
|
@@ -14,9 +17,8 @@ This rule recommends a for-of loop when the loop index is only used to read from
|
|
|
14
17
|
|
|
15
18
|
## Examples
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
### ❌ Incorrect
|
|
20
|
+
<Tabs>
|
|
21
|
+
<TabItem value="❌ Incorrect">
|
|
20
22
|
|
|
21
23
|
```ts
|
|
22
24
|
declare const array: string[];
|
|
@@ -26,7 +28,8 @@ for (let i = 0; i < array.length; i++) {
|
|
|
26
28
|
}
|
|
27
29
|
```
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
</TabItem>
|
|
32
|
+
<TabItem value="✅ Correct">
|
|
30
33
|
|
|
31
34
|
```ts
|
|
32
35
|
declare const array: string[];
|
|
@@ -41,4 +44,7 @@ for (let i = 0; i < array.length; i++) {
|
|
|
41
44
|
}
|
|
42
45
|
```
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
</TabItem>
|
|
48
|
+
</Tabs>
|
|
49
|
+
|
|
50
|
+
{/* Intentionally Omitted: When Not To Use It */}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Enforce using function types instead of interfaces with call signatures.'
|
|
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/prefer-function-type** for documentation.
|
|
@@ -17,9 +20,8 @@ This rule suggests using a function type instead of an interface or object type
|
|
|
17
20
|
|
|
18
21
|
## Examples
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
### ❌ Incorrect
|
|
23
|
+
<Tabs>
|
|
24
|
+
<TabItem value="❌ Incorrect">
|
|
23
25
|
|
|
24
26
|
```ts
|
|
25
27
|
interface Example {
|
|
@@ -40,7 +42,8 @@ interface ReturnsSelf {
|
|
|
40
42
|
}
|
|
41
43
|
```
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
</TabItem>
|
|
46
|
+
<TabItem value="✅ Correct">
|
|
44
47
|
|
|
45
48
|
```ts
|
|
46
49
|
type Example = () => string;
|
|
@@ -82,6 +85,9 @@ interface Overloaded {
|
|
|
82
85
|
type Intersection = ((data: string) => number) & ((id: number) => string);
|
|
83
86
|
```
|
|
84
87
|
|
|
88
|
+
</TabItem>
|
|
89
|
+
</Tabs>
|
|
90
|
+
|
|
85
91
|
## When Not To Use It
|
|
86
92
|
|
|
87
93
|
If you specifically want to use an interface or type literal with a single call signature for stylistic reasons, you can avoid this rule.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Enforce `includes` method over `indexOf` method.'
|
|
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/prefer-includes** for documentation.
|
|
@@ -17,9 +20,8 @@ Additionally, this rule reports the tests of simple regular expressions in favor
|
|
|
17
20
|
|
|
18
21
|
## Examples
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
### ❌ Incorrect
|
|
23
|
+
<Tabs>
|
|
24
|
+
<TabItem value="❌ Incorrect">
|
|
23
25
|
|
|
24
26
|
```ts
|
|
25
27
|
const str: string;
|
|
@@ -42,7 +44,8 @@ userDefined.indexOf(value) >= 0;
|
|
|
42
44
|
/example/.test(str);
|
|
43
45
|
```
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
</TabItem>
|
|
48
|
+
<TabItem value="✅ Correct">
|
|
46
49
|
|
|
47
50
|
```ts
|
|
48
51
|
const str: string;
|
|
@@ -72,4 +75,7 @@ declare const mismatchExample: {
|
|
|
72
75
|
mismatchExample.indexOf(value) >= 0;
|
|
73
76
|
```
|
|
74
77
|
|
|
75
|
-
|
|
78
|
+
</TabItem>
|
|
79
|
+
</Tabs>
|
|
80
|
+
|
|
81
|
+
{/* Intentionally Omitted: When Not To Use It */}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Require all enum members to be literal values.'
|
|
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/prefer-literal-enum-member** for documentation.
|
|
@@ -30,9 +33,8 @@ This rule reports when an enum member is given a value that is not a literal.
|
|
|
30
33
|
|
|
31
34
|
## Examples
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
### ❌ Incorrect
|
|
36
|
+
<Tabs>
|
|
37
|
+
<TabItem value="❌ Incorrect">
|
|
36
38
|
|
|
37
39
|
```ts
|
|
38
40
|
const str = 'Test';
|
|
@@ -45,7 +47,8 @@ enum Invalid {
|
|
|
45
47
|
}
|
|
46
48
|
```
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
</TabItem>
|
|
51
|
+
<TabItem value="✅ Correct">
|
|
49
52
|
|
|
50
53
|
```ts
|
|
51
54
|
enum Valid {
|
|
@@ -57,7 +60,8 @@ enum Valid {
|
|
|
57
60
|
}
|
|
58
61
|
```
|
|
59
62
|
|
|
60
|
-
|
|
63
|
+
</TabItem>
|
|
64
|
+
</Tabs>
|
|
61
65
|
|
|
62
66
|
## Options
|
|
63
67
|
|
|
@@ -67,9 +71,8 @@ When set to `true` will allow you to use bitwise expressions in enum initializer
|
|
|
67
71
|
|
|
68
72
|
Examples of code for the `{ "allowBitwiseExpressions": true }` option:
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
### ❌ Incorrect
|
|
74
|
+
<Tabs>
|
|
75
|
+
<TabItem value="❌ Incorrect">
|
|
73
76
|
|
|
74
77
|
```ts option='{ "allowBitwiseExpressions": true }'
|
|
75
78
|
const x = 1;
|
|
@@ -84,7 +87,8 @@ enum Foo {
|
|
|
84
87
|
}
|
|
85
88
|
```
|
|
86
89
|
|
|
87
|
-
|
|
90
|
+
</TabItem>
|
|
91
|
+
<TabItem value="✅ Correct">
|
|
88
92
|
|
|
89
93
|
```ts option='{ "allowBitwiseExpressions": true }'
|
|
90
94
|
enum Foo {
|
|
@@ -98,6 +102,9 @@ enum Foo {
|
|
|
98
102
|
}
|
|
99
103
|
```
|
|
100
104
|
|
|
105
|
+
</TabItem>
|
|
106
|
+
</Tabs>
|
|
107
|
+
|
|
101
108
|
## When Not To Use It
|
|
102
109
|
|
|
103
110
|
If you want use anything other than simple literals as an enum value, this rule might not be for you.
|