@typescript-eslint/eslint-plugin 7.2.1-alpha.2 → 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/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-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 +13 -1
- 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} +13 -7
- 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 +7 -7
- /package/docs/rules/{no-parameter-properties.md → no-parameter-properties.mdx} +0 -0
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow `@ts-<directive>` comments or require descriptions after directives.'
|
|
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/ban-ts-comment** for documentation.
|
|
@@ -29,9 +32,8 @@ By default, only `@ts-check` is allowed, as it enables rather than suppresses er
|
|
|
29
32
|
|
|
30
33
|
A value of `true` for a particular directive means that this rule will report if it finds any usage of said directive.
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
#### ❌ Incorrect
|
|
35
|
+
<Tabs>
|
|
36
|
+
<TabItem value="❌ Incorrect">
|
|
35
37
|
|
|
36
38
|
```ts option='{ "ts-ignore": true }'
|
|
37
39
|
if (false) {
|
|
@@ -46,7 +48,8 @@ if (false) {
|
|
|
46
48
|
}
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
</TabItem>
|
|
52
|
+
<TabItem value="✅ Correct">
|
|
50
53
|
|
|
51
54
|
```ts option='{ "ts-ignore": true }'
|
|
52
55
|
if (false) {
|
|
@@ -55,15 +58,17 @@ if (false) {
|
|
|
55
58
|
}
|
|
56
59
|
```
|
|
57
60
|
|
|
61
|
+
</TabItem>
|
|
62
|
+
</Tabs>
|
|
63
|
+
|
|
58
64
|
### `allow-with-description`
|
|
59
65
|
|
|
60
66
|
A value of `'allow-with-description'` for a particular directive means that this rule will report if it finds a directive that does not have a description following the directive (on the same line).
|
|
61
67
|
|
|
62
68
|
For example, with `{ 'ts-expect-error': 'allow-with-description' }`:
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
#### ❌ Incorrect
|
|
70
|
+
<Tabs>
|
|
71
|
+
<TabItem value="❌ Incorrect">
|
|
67
72
|
|
|
68
73
|
```ts option='{ "ts-expect-error": "allow-with-description" }'
|
|
69
74
|
if (false) {
|
|
@@ -76,7 +81,8 @@ if (false) {
|
|
|
76
81
|
}
|
|
77
82
|
```
|
|
78
83
|
|
|
79
|
-
|
|
84
|
+
</TabItem>
|
|
85
|
+
<TabItem value="✅ Correct">
|
|
80
86
|
|
|
81
87
|
```ts option='{ "ts-expect-error": "allow-with-description" }'
|
|
82
88
|
if (false) {
|
|
@@ -91,39 +97,43 @@ if (false) {
|
|
|
91
97
|
}
|
|
92
98
|
```
|
|
93
99
|
|
|
100
|
+
</TabItem>
|
|
101
|
+
</Tabs>
|
|
94
102
|
### `descriptionFormat`
|
|
95
103
|
|
|
96
104
|
For each directive type, you can specify a custom format in the form of a regular expression. Only description that matches the pattern will be allowed.
|
|
97
105
|
|
|
98
106
|
For example, with `{ 'ts-expect-error': { descriptionFormat: '^: TS\\d+ because .+$' } }`:
|
|
99
107
|
|
|
100
|
-
|
|
108
|
+
<Tabs>
|
|
109
|
+
<TabItem value="❌ Incorrect">
|
|
101
110
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
<!-- prettier-ignore -->
|
|
111
|
+
{/* prettier-ignore */}
|
|
105
112
|
```ts option='{ "ts-expect-error": { "descriptionFormat": "^: TS\\\\d+ because .+$" } }'
|
|
106
113
|
// @ts-expect-error: the library definition is wrong
|
|
107
114
|
const a = doSomething('hello');
|
|
108
115
|
```
|
|
109
116
|
|
|
110
|
-
|
|
117
|
+
</TabItem>
|
|
118
|
+
<TabItem value="✅ Correct">
|
|
111
119
|
|
|
112
|
-
|
|
120
|
+
{/* prettier-ignore */}
|
|
113
121
|
```ts option='{ "ts-expect-error": { "descriptionFormat": "^: TS\\\\d+ because .+$" } }'
|
|
114
122
|
// @ts-expect-error: TS1234 because the library definition is wrong
|
|
115
123
|
const a = doSomething('hello');
|
|
116
124
|
```
|
|
117
125
|
|
|
126
|
+
</TabItem>
|
|
127
|
+
</Tabs>
|
|
128
|
+
|
|
118
129
|
### `minimumDescriptionLength`
|
|
119
130
|
|
|
120
131
|
Use `minimumDescriptionLength` to set a minimum length for descriptions when using the `allow-with-description` option for a directive.
|
|
121
132
|
|
|
122
133
|
For example, with `{ 'ts-expect-error': 'allow-with-description', minimumDescriptionLength: 10 }` the following pattern is:
|
|
123
134
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
#### ❌ Incorrect
|
|
135
|
+
<Tabs>
|
|
136
|
+
<TabItem value="❌ Incorrect">
|
|
127
137
|
|
|
128
138
|
```ts option='{ "ts-expect-error": "allow-with-description", "minimumDescriptionLength": 10 }'
|
|
129
139
|
if (false) {
|
|
@@ -132,7 +142,8 @@ if (false) {
|
|
|
132
142
|
}
|
|
133
143
|
```
|
|
134
144
|
|
|
135
|
-
|
|
145
|
+
</TabItem>
|
|
146
|
+
<TabItem value="✅ Correct">
|
|
136
147
|
|
|
137
148
|
```ts option='{ "ts-expect-error": "allow-with-description", "minimumDescriptionLength": 10 }'
|
|
138
149
|
if (false) {
|
|
@@ -141,6 +152,9 @@ if (false) {
|
|
|
141
152
|
}
|
|
142
153
|
```
|
|
143
154
|
|
|
155
|
+
</TabItem>
|
|
156
|
+
</Tabs>
|
|
157
|
+
|
|
144
158
|
## When Not To Use It
|
|
145
159
|
|
|
146
160
|
If your project or its dependencies were not architected with strong type safety in mind, it can be difficult to always adhere to proper TypeScript semantics.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow `// tslint:<rule-flag>` comments.'
|
|
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/ban-tslint-comment** for documentation.
|
|
@@ -12,9 +15,8 @@ Useful when migrating from TSLint to ESLint. Once TSLint has been removed, this
|
|
|
12
15
|
|
|
13
16
|
## Examples
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
### ❌ Incorrect
|
|
18
|
+
<Tabs>
|
|
19
|
+
<TabItem value="❌ Incorrect">
|
|
18
20
|
|
|
19
21
|
```ts
|
|
20
22
|
/* tslint:disable */
|
|
@@ -26,7 +28,8 @@ someCode(); // tslint:disable-line
|
|
|
26
28
|
// tslint:disable-next-line:rule1 rule2 rule3...
|
|
27
29
|
```
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
</TabItem>
|
|
32
|
+
<TabItem value="✅ Correct">
|
|
30
33
|
|
|
31
34
|
```ts
|
|
32
35
|
// This is a comment that just happens to mention tslint
|
|
@@ -34,6 +37,9 @@ someCode(); // tslint:disable-line
|
|
|
34
37
|
someCode(); // This is a comment that just happens to mention tslint
|
|
35
38
|
```
|
|
36
39
|
|
|
40
|
+
</TabItem>
|
|
41
|
+
</Tabs>
|
|
42
|
+
|
|
37
43
|
## When Not To Use It
|
|
38
44
|
|
|
39
45
|
If you are still using TSLint alongside ESLint.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow certain types.'
|
|
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/ban-types** for documentation.
|
|
@@ -16,9 +19,8 @@ Note that it does not ban the corresponding runtime objects from being used.
|
|
|
16
19
|
|
|
17
20
|
Examples of code with the default options:
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
### ❌ Incorrect
|
|
22
|
+
<Tabs>
|
|
23
|
+
<TabItem value="❌ Incorrect">
|
|
22
24
|
|
|
23
25
|
```ts
|
|
24
26
|
// use lower-case primitives for consistency
|
|
@@ -39,7 +41,8 @@ const curly1: {} = 1;
|
|
|
39
41
|
const curly2: {} = { a: 'string' };
|
|
40
42
|
```
|
|
41
43
|
|
|
42
|
-
|
|
44
|
+
</TabItem>
|
|
45
|
+
<TabItem value="✅ Correct">
|
|
43
46
|
|
|
44
47
|
```ts
|
|
45
48
|
// use lower-case primitives for consistency
|
|
@@ -60,6 +63,9 @@ const curly1: number = 1;
|
|
|
60
63
|
const curly2: Record<'a', string> = { a: 'string' };
|
|
61
64
|
```
|
|
62
65
|
|
|
66
|
+
</TabItem>
|
|
67
|
+
</Tabs>
|
|
68
|
+
|
|
63
69
|
## Options
|
|
64
70
|
|
|
65
71
|
The default options provide a set of "best practices", intended to provide safety and standardization in your codebase:
|
|
@@ -75,7 +81,7 @@ The default options provide a set of "best practices", intended to provide safet
|
|
|
75
81
|
<details>
|
|
76
82
|
<summary>Default Options</summary>
|
|
77
83
|
|
|
78
|
-
|
|
84
|
+
{/* Inject default options */}
|
|
79
85
|
|
|
80
86
|
</details>
|
|
81
87
|
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Disallow or enforce spaces inside of blocks after opening block and before closing block.'
|
|
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/block-spacing** for documentation.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Enforce consistent brace style for 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/brace-style** for documentation.
|
package/docs/rules/camelcase.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
:::danger Deprecated
|
|
2
2
|
|
|
3
|
-
This rule has been deprecated in favour of the [`naming-convention`](./naming-convention.
|
|
3
|
+
This rule has been deprecated in favour of the [`naming-convention`](./naming-convention.mdx) rule.
|
|
4
4
|
|
|
5
5
|
:::
|
|
6
6
|
|
|
7
|
-
<!--
|
|
8
|
-
This doc file has been left on purpose because `camelcase` is a core ESLint
|
|
7
|
+
<!-- This doc file has been left on purpose because `camelcase` is a core ESLint
|
|
9
8
|
rule. This exists to help direct people to the replacement rule.
|
|
10
9
|
|
|
11
10
|
Note that there is no actual way to get to this page in the normal navigation,
|
|
12
|
-
so end-users will only be able to get to this page from the search bar.
|
|
13
|
-
-->
|
|
11
|
+
so end-users will only be able to get to this page from the search bar. -->
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Enforce that literals on classes are exposed in a consistent style.'
|
|
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/class-literal-property-style** for documentation.
|
|
@@ -15,10 +18,8 @@ By default this rule prefers the `fields` style as it means JS doesn't have to s
|
|
|
15
18
|
## Options
|
|
16
19
|
|
|
17
20
|
:::note
|
|
18
|
-
|
|
19
21
|
This rule only checks for constant _literal_ values (string, template string, number, bigint, boolean, regexp, null). It does not check objects or arrays, because a readonly field behaves differently to a getter in those cases. It also does not check functions, as it is a common pattern to use readonly fields with arrow function values as auto-bound methods.
|
|
20
22
|
This is because these types can be mutated and carry with them more complex implications about their usage.
|
|
21
|
-
|
|
22
23
|
:::
|
|
23
24
|
|
|
24
25
|
### `"fields"`
|
|
@@ -27,9 +28,8 @@ This style checks for any getter methods that return literal values, and require
|
|
|
27
28
|
|
|
28
29
|
Examples of code with the `fields` style:
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
#### ❌ Incorrect
|
|
31
|
+
<Tabs>
|
|
32
|
+
<TabItem value="❌ Incorrect">
|
|
33
33
|
|
|
34
34
|
```ts option='"fields"'
|
|
35
35
|
class Mx {
|
|
@@ -43,7 +43,8 @@ class Mx {
|
|
|
43
43
|
}
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
</TabItem>
|
|
47
|
+
<TabItem value="✅ Correct">
|
|
47
48
|
|
|
48
49
|
```ts option='"fields"'
|
|
49
50
|
class Mx {
|
|
@@ -60,17 +61,19 @@ class Mx {
|
|
|
60
61
|
}
|
|
61
62
|
```
|
|
62
63
|
|
|
64
|
+
</TabItem>
|
|
65
|
+
</Tabs>
|
|
66
|
+
|
|
63
67
|
### `"getters"`
|
|
64
68
|
|
|
65
69
|
This style checks for any `readonly` fields that are assigned literal values, and requires them to be defined as getters instead.
|
|
66
|
-
This style pairs well with the [`@typescript-eslint/prefer-readonly`](prefer-readonly.
|
|
70
|
+
This style pairs well with the [`@typescript-eslint/prefer-readonly`](prefer-readonly.mdx) rule,
|
|
67
71
|
as it will identify fields that can be `readonly`, and thus should be made into getters.
|
|
68
72
|
|
|
69
73
|
Examples of code with the `getters` style:
|
|
70
74
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
#### ❌ Incorrect
|
|
75
|
+
<Tabs>
|
|
76
|
+
<TabItem value="❌ Incorrect">
|
|
74
77
|
|
|
75
78
|
```ts option='"getters"'
|
|
76
79
|
class Mx {
|
|
@@ -80,7 +83,8 @@ class Mx {
|
|
|
80
83
|
}
|
|
81
84
|
```
|
|
82
85
|
|
|
83
|
-
|
|
86
|
+
</TabItem>
|
|
87
|
+
<TabItem value="✅ Correct">
|
|
84
88
|
|
|
85
89
|
```ts option='"getters"'
|
|
86
90
|
class Mx {
|
|
@@ -100,6 +104,9 @@ class Mx {
|
|
|
100
104
|
}
|
|
101
105
|
```
|
|
102
106
|
|
|
107
|
+
</TabItem>
|
|
108
|
+
</Tabs>
|
|
109
|
+
|
|
103
110
|
## When Not To Use It
|
|
104
111
|
|
|
105
112
|
When you have no strong preference, or do not wish to enforce a particular style for how literal values are exposed by your classes.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Enforce that class methods utilize `this`.'
|
|
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/class-methods-use-this** for documentation.
|
|
@@ -51,7 +54,7 @@ It's important to note that this option does not only apply to members defined i
|
|
|
51
54
|
|
|
52
55
|
#### `true`
|
|
53
56
|
|
|
54
|
-
Example of
|
|
57
|
+
Example of correct code when `ignoreClassesThatImplementAnInterface` is set to `true`:
|
|
55
58
|
|
|
56
59
|
```ts option='{ "ignoreClassesThatImplementAnInterface": true }' showPlaygroundButton
|
|
57
60
|
class X implements Y {
|
|
@@ -62,11 +65,10 @@ class X implements Y {
|
|
|
62
65
|
|
|
63
66
|
#### `'public-fields'`
|
|
64
67
|
|
|
65
|
-
Example of
|
|
66
|
-
|
|
67
|
-
<!--tabs-->
|
|
68
|
+
Example of incorrect code when `ignoreClassesThatImplementAnInterface` is set to `'public-fields'`:
|
|
68
69
|
|
|
69
|
-
|
|
70
|
+
<Tabs>
|
|
71
|
+
<TabItem value="❌ Incorrect">
|
|
70
72
|
|
|
71
73
|
```ts
|
|
72
74
|
class X implements Y {
|
|
@@ -81,7 +83,8 @@ class X implements Y {
|
|
|
81
83
|
}
|
|
82
84
|
```
|
|
83
85
|
|
|
84
|
-
|
|
86
|
+
</TabItem>
|
|
87
|
+
<TabItem value="✅ Correct">
|
|
85
88
|
|
|
86
89
|
```ts
|
|
87
90
|
class X implements Y {
|
|
@@ -90,6 +93,9 @@ class X implements Y {
|
|
|
90
93
|
}
|
|
91
94
|
```
|
|
92
95
|
|
|
96
|
+
</TabItem>
|
|
97
|
+
</Tabs>
|
|
98
|
+
|
|
93
99
|
## When Not To Use It
|
|
94
100
|
|
|
95
101
|
If your project dynamically changes `this` scopes around in a way TypeScript has difficulties modeling, this rule may not be viable to use.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Require or disallow trailing commas.'
|
|
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/comma-dangle** for documentation.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Enforce consistent spacing before and after commas.'
|
|
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/comma-spacing** for documentation.
|
package/docs/rules/{consistent-generic-constructors.md → consistent-generic-constructors.mdx}
RENAMED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Enforce specifying generic type arguments on type annotation or constructor name of a constructor call.'
|
|
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/consistent-generic-constructors** for documentation.
|
|
@@ -29,16 +32,16 @@ Keeping to one side consistently improve code readability.
|
|
|
29
32
|
|
|
30
33
|
### `constructor`
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
#### ❌ Incorrect
|
|
35
|
+
<Tabs>
|
|
36
|
+
<TabItem value="❌ Incorrect">
|
|
35
37
|
|
|
36
38
|
```ts option='"constructor"'
|
|
37
39
|
const map: Map<string, number> = new Map();
|
|
38
40
|
const set: Set<string> = new Set();
|
|
39
41
|
```
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
</TabItem>
|
|
44
|
+
<TabItem value="✅ Correct">
|
|
42
45
|
|
|
43
46
|
```ts option='"constructor"'
|
|
44
47
|
const map = new Map<string, number>();
|
|
@@ -48,18 +51,21 @@ const set = new Set();
|
|
|
48
51
|
const set: Set<string> = new Set<string>();
|
|
49
52
|
```
|
|
50
53
|
|
|
51
|
-
|
|
54
|
+
</TabItem>
|
|
55
|
+
</Tabs>
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
### `type-annotation`
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
<Tabs>
|
|
60
|
+
<TabItem value="❌ Incorrect">
|
|
56
61
|
|
|
57
62
|
```ts option='"type-annotation"'
|
|
58
63
|
const map = new Map<string, number>();
|
|
59
64
|
const set = new Set<string>();
|
|
60
65
|
```
|
|
61
66
|
|
|
62
|
-
|
|
67
|
+
</TabItem>
|
|
68
|
+
<TabItem value="✅ Correct">
|
|
63
69
|
|
|
64
70
|
```ts option='"type-annotation"'
|
|
65
71
|
const map: Map<string, number> = new Map();
|
|
@@ -68,6 +74,9 @@ const set = new Set();
|
|
|
68
74
|
const set: Set<string> = new Set<string>();
|
|
69
75
|
```
|
|
70
76
|
|
|
77
|
+
</TabItem>
|
|
78
|
+
</Tabs>
|
|
79
|
+
|
|
71
80
|
## When Not To Use It
|
|
72
81
|
|
|
73
82
|
You can turn this rule off if you don't want to enforce one kind of generic constructor style over the other.
|
package/docs/rules/{consistent-indexed-object-style.md → consistent-indexed-object-style.mdx}
RENAMED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Require or disallow the `Record` 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/consistent-indexed-object-style** for documentation.
|
|
@@ -29,9 +32,8 @@ Keeping to one declaration form consistently improve code readability.
|
|
|
29
32
|
|
|
30
33
|
### `record`
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
#### ❌ Incorrect
|
|
35
|
+
<Tabs>
|
|
36
|
+
<TabItem value="❌ Incorrect">
|
|
35
37
|
|
|
36
38
|
```ts option='"record"'
|
|
37
39
|
interface Foo {
|
|
@@ -43,23 +45,27 @@ type Foo = {
|
|
|
43
45
|
};
|
|
44
46
|
```
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
</TabItem>
|
|
49
|
+
<TabItem value="✅ Correct">
|
|
47
50
|
|
|
48
51
|
```ts option='"record"'
|
|
49
52
|
type Foo = Record<string, unknown>;
|
|
50
53
|
```
|
|
51
54
|
|
|
52
|
-
|
|
55
|
+
</TabItem>
|
|
56
|
+
</Tabs>
|
|
53
57
|
|
|
54
|
-
|
|
58
|
+
### `index-signature`
|
|
55
59
|
|
|
56
|
-
|
|
60
|
+
<Tabs>
|
|
61
|
+
<TabItem value="❌ Incorrect">
|
|
57
62
|
|
|
58
63
|
```ts option='"index-signature"'
|
|
59
64
|
type Foo = Record<string, unknown>;
|
|
60
65
|
```
|
|
61
66
|
|
|
62
|
-
|
|
67
|
+
</TabItem>
|
|
68
|
+
<TabItem value="✅ Correct">
|
|
63
69
|
|
|
64
70
|
```ts option='"index-signature"'
|
|
65
71
|
interface Foo {
|
|
@@ -71,6 +77,9 @@ type Foo = {
|
|
|
71
77
|
};
|
|
72
78
|
```
|
|
73
79
|
|
|
80
|
+
</TabItem>
|
|
81
|
+
</Tabs>
|
|
82
|
+
|
|
74
83
|
## When Not To Use It
|
|
75
84
|
|
|
76
85
|
This rule is purely a stylistic rule for maintaining consistency in your project.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Require `return` statements to either always or never specify 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/consistent-return** for documentation.
|
|
@@ -9,9 +12,8 @@ description: 'Require `return` statements to either always or never specify valu
|
|
|
9
12
|
This rule extends the base [`eslint/consistent-return`](https://eslint.org/docs/rules/consistent-return) rule.
|
|
10
13
|
This version adds support for functions that return `void` or `Promise<void>`.
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
### ❌ Incorrect
|
|
15
|
+
<Tabs>
|
|
16
|
+
<TabItem value="❌ Incorrect">
|
|
15
17
|
|
|
16
18
|
```ts
|
|
17
19
|
function foo(): undefined {}
|
|
@@ -26,7 +28,8 @@ async function baz(flag: boolean): Promise<undefined> {
|
|
|
26
28
|
}
|
|
27
29
|
```
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
</TabItem>
|
|
32
|
+
<TabItem value="✅ Correct">
|
|
30
33
|
|
|
31
34
|
```ts
|
|
32
35
|
function foo(): void {}
|
|
@@ -40,3 +43,6 @@ async function baz(flag: boolean): Promise<void | number> {
|
|
|
40
43
|
return;
|
|
41
44
|
}
|
|
42
45
|
```
|
|
46
|
+
|
|
47
|
+
</TabItem>
|
|
48
|
+
</Tabs>
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
description: 'Enforce consistent usage of type assertions.'
|
|
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/consistent-type-assertions** for documentation.
|
|
@@ -49,9 +52,8 @@ Assertions to `any` are also ignored by this option.
|
|
|
49
52
|
|
|
50
53
|
Examples of code for `{ assertionStyle: 'as', objectLiteralTypeAssertions: 'never' }`:
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
#### ❌ Incorrect
|
|
55
|
+
<Tabs>
|
|
56
|
+
<TabItem value="❌ Incorrect">
|
|
55
57
|
|
|
56
58
|
```ts option='{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }'
|
|
57
59
|
const x = { foo: 1 } as T;
|
|
@@ -61,7 +63,8 @@ function bar() {
|
|
|
61
63
|
}
|
|
62
64
|
```
|
|
63
65
|
|
|
64
|
-
|
|
66
|
+
</TabItem>
|
|
67
|
+
<TabItem value="✅ Correct">
|
|
65
68
|
|
|
66
69
|
```ts option='{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }'
|
|
67
70
|
const x: T = { foo: 1 };
|
|
@@ -73,13 +76,13 @@ function bar(): T {
|
|
|
73
76
|
}
|
|
74
77
|
```
|
|
75
78
|
|
|
76
|
-
|
|
79
|
+
</TabItem>
|
|
80
|
+
</Tabs>
|
|
77
81
|
|
|
78
82
|
Examples of code for `{ assertionStyle: 'as', objectLiteralTypeAssertions: 'allow-as-parameter' }`:
|
|
79
83
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
#### ❌ Incorrect
|
|
84
|
+
<Tabs>
|
|
85
|
+
<TabItem value="❌ Incorrect">
|
|
83
86
|
|
|
84
87
|
```ts option='{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter" }'
|
|
85
88
|
const x = { foo: 1 } as T;
|
|
@@ -89,7 +92,8 @@ function bar() {
|
|
|
89
92
|
}
|
|
90
93
|
```
|
|
91
94
|
|
|
92
|
-
|
|
95
|
+
</TabItem>
|
|
96
|
+
<TabItem value="✅ Correct">
|
|
93
97
|
|
|
94
98
|
```tsx option='{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter" }'
|
|
95
99
|
const x: T = { foo: 1 };
|
|
@@ -103,7 +107,8 @@ function bar() {
|
|
|
103
107
|
const foo = <Foo props={{ bar: 1 } as Bar} />;
|
|
104
108
|
```
|
|
105
109
|
|
|
106
|
-
|
|
110
|
+
</TabItem>
|
|
111
|
+
</Tabs>
|
|
107
112
|
|
|
108
113
|
## When Not To Use It
|
|
109
114
|
|