@typescript-eslint/eslint-plugin 8.33.1-alpha.5 → 8.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -10
- package/docs/rules/README.md +0 -57
- package/docs/rules/TEMPLATE.md +0 -36
- package/docs/rules/adjacent-overload-signatures.mdx +0 -105
- package/docs/rules/array-type.mdx +0 -126
- package/docs/rules/await-thenable.mdx +0 -184
- package/docs/rules/ban-ts-comment.mdx +0 -165
- package/docs/rules/ban-tslint-comment.mdx +0 -45
- package/docs/rules/ban-types.md +0 -26
- package/docs/rules/block-spacing.md +0 -15
- package/docs/rules/brace-style.md +0 -15
- package/docs/rules/camelcase.md +0 -15
- package/docs/rules/class-literal-property-style.mdx +0 -112
- package/docs/rules/class-methods-use-this.mdx +0 -135
- package/docs/rules/comma-dangle.md +0 -15
- package/docs/rules/comma-spacing.md +0 -15
- package/docs/rules/consistent-generic-constructors.mdx +0 -87
- package/docs/rules/consistent-indexed-object-style.mdx +0 -105
- package/docs/rules/consistent-return.mdx +0 -51
- package/docs/rules/consistent-type-assertions.mdx +0 -196
- package/docs/rules/consistent-type-definitions.mdx +0 -133
- package/docs/rules/consistent-type-exports.mdx +0 -97
- package/docs/rules/consistent-type-imports.mdx +0 -139
- package/docs/rules/default-param-last.mdx +0 -59
- package/docs/rules/dot-notation.mdx +0 -94
- package/docs/rules/explicit-function-return-type.mdx +0 -359
- package/docs/rules/explicit-member-accessibility.mdx +0 -353
- package/docs/rules/explicit-module-boundary-types.mdx +0 -287
- package/docs/rules/func-call-spacing.md +0 -15
- package/docs/rules/indent.md +0 -15
- package/docs/rules/init-declarations.mdx +0 -12
- package/docs/rules/key-spacing.md +0 -15
- package/docs/rules/keyword-spacing.md +0 -15
- package/docs/rules/lines-around-comment.md +0 -15
- package/docs/rules/lines-between-class-members.md +0 -15
- package/docs/rules/max-params.mdx +0 -54
- package/docs/rules/member-delimiter-style.md +0 -15
- package/docs/rules/member-ordering.mdx +0 -1483
- package/docs/rules/method-signature-style.mdx +0 -124
- package/docs/rules/naming-convention.mdx +0 -755
- package/docs/rules/no-array-constructor.mdx +0 -34
- package/docs/rules/no-array-delete.mdx +0 -44
- package/docs/rules/no-base-to-string.mdx +0 -115
- package/docs/rules/no-confusing-non-null-assertion.mdx +0 -75
- package/docs/rules/no-confusing-void-expression.mdx +0 -148
- package/docs/rules/no-deprecated.mdx +0 -119
- package/docs/rules/no-dupe-class-members.mdx +0 -16
- package/docs/rules/no-duplicate-enum-values.mdx +0 -66
- package/docs/rules/no-duplicate-imports.mdx +0 -17
- package/docs/rules/no-duplicate-type-constituents.mdx +0 -89
- package/docs/rules/no-dynamic-delete.mdx +0 -64
- package/docs/rules/no-empty-function.mdx +0 -94
- package/docs/rules/no-empty-interface.mdx +0 -75
- package/docs/rules/no-empty-object-type.mdx +0 -150
- package/docs/rules/no-explicit-any.mdx +0 -177
- package/docs/rules/no-extra-non-null-assertion.mdx +0 -60
- package/docs/rules/no-extra-parens.md +0 -15
- package/docs/rules/no-extra-semi.md +0 -15
- package/docs/rules/no-extraneous-class.mdx +0 -329
- package/docs/rules/no-floating-promises.mdx +0 -282
- package/docs/rules/no-for-in-array.mdx +0 -67
- package/docs/rules/no-implied-eval.mdx +0 -106
- package/docs/rules/no-import-type-side-effects.mdx +0 -80
- package/docs/rules/no-inferrable-types.mdx +0 -113
- package/docs/rules/no-invalid-this.mdx +0 -16
- package/docs/rules/no-invalid-void-type.mdx +0 -119
- package/docs/rules/no-loop-func.mdx +0 -12
- package/docs/rules/no-loss-of-precision.mdx +0 -17
- package/docs/rules/no-magic-numbers.mdx +0 -131
- package/docs/rules/no-meaningless-void-operator.mdx +0 -61
- package/docs/rules/no-misused-new.mdx +0 -53
- package/docs/rules/no-misused-promises.mdx +0 -314
- package/docs/rules/no-misused-spread.mdx +0 -132
- package/docs/rules/no-mixed-enums.mdx +0 -96
- package/docs/rules/no-namespace.mdx +0 -157
- package/docs/rules/no-non-null-asserted-nullish-coalescing.mdx +0 -60
- package/docs/rules/no-non-null-asserted-optional-chain.mdx +0 -46
- package/docs/rules/no-non-null-assertion.mdx +0 -48
- package/docs/rules/no-parameter-properties.mdx +0 -16
- package/docs/rules/no-redeclare.mdx +0 -79
- package/docs/rules/no-redundant-type-constituents.mdx +0 -102
- package/docs/rules/no-require-imports.mdx +0 -114
- package/docs/rules/no-restricted-imports.mdx +0 -84
- package/docs/rules/no-restricted-types.mdx +0 -70
- package/docs/rules/no-shadow.mdx +0 -143
- package/docs/rules/no-this-alias.mdx +0 -124
- package/docs/rules/no-type-alias.mdx +0 -626
- package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +0 -165
- package/docs/rules/no-unnecessary-condition.mdx +0 -293
- package/docs/rules/no-unnecessary-parameter-property-assignment.mdx +0 -42
- package/docs/rules/no-unnecessary-qualifier.mdx +0 -57
- package/docs/rules/no-unnecessary-template-expression.mdx +0 -108
- package/docs/rules/no-unnecessary-type-arguments.mdx +0 -85
- package/docs/rules/no-unnecessary-type-assertion.mdx +0 -97
- package/docs/rules/no-unnecessary-type-constraint.mdx +0 -61
- package/docs/rules/no-unnecessary-type-conversion.mdx +0 -79
- package/docs/rules/no-unnecessary-type-parameters.mdx +0 -255
- package/docs/rules/no-unsafe-argument.mdx +0 -98
- package/docs/rules/no-unsafe-assignment.mdx +0 -101
- package/docs/rules/no-unsafe-call.mdx +0 -120
- package/docs/rules/no-unsafe-declaration-merging.mdx +0 -65
- package/docs/rules/no-unsafe-enum-comparison.mdx +0 -98
- package/docs/rules/no-unsafe-function-type.mdx +0 -65
- package/docs/rules/no-unsafe-member-access.mdx +0 -81
- package/docs/rules/no-unsafe-return.mdx +0 -126
- package/docs/rules/no-unsafe-type-assertion.mdx +0 -63
- package/docs/rules/no-unsafe-unary-minus.mdx +0 -60
- package/docs/rules/no-unused-expressions.mdx +0 -52
- package/docs/rules/no-unused-vars.mdx +0 -136
- package/docs/rules/no-use-before-define.mdx +0 -98
- package/docs/rules/no-useless-constructor.mdx +0 -21
- package/docs/rules/no-useless-empty-export.mdx +0 -53
- package/docs/rules/no-useless-template-literals.mdx +0 -9
- package/docs/rules/no-var-requires.mdx +0 -77
- package/docs/rules/no-wrapper-object-types.mdx +0 -75
- package/docs/rules/non-nullable-type-assertion-style.mdx +0 -47
- package/docs/rules/object-curly-spacing.md +0 -15
- package/docs/rules/only-throw-error.mdx +0 -150
- package/docs/rules/padding-line-between-statements.md +0 -15
- package/docs/rules/parameter-properties.mdx +0 -522
- package/docs/rules/prefer-as-const.mdx +0 -51
- package/docs/rules/prefer-destructuring.mdx +0 -101
- package/docs/rules/prefer-enum-initializers.mdx +0 -68
- package/docs/rules/prefer-find.mdx +0 -45
- package/docs/rules/prefer-for-of.mdx +0 -50
- package/docs/rules/prefer-function-type.mdx +0 -98
- package/docs/rules/prefer-includes.mdx +0 -81
- package/docs/rules/prefer-literal-enum-member.mdx +0 -111
- package/docs/rules/prefer-namespace-keyword.mdx +0 -51
- package/docs/rules/prefer-nullish-coalescing.mdx +0 -349
- package/docs/rules/prefer-optional-chain.mdx +0 -304
- package/docs/rules/prefer-promise-reject-errors.mdx +0 -78
- package/docs/rules/prefer-readonly-parameter-types.mdx +0 -408
- package/docs/rules/prefer-readonly.mdx +0 -111
- package/docs/rules/prefer-reduce-type-parameter.mdx +0 -66
- package/docs/rules/prefer-regexp-exec.mdx +0 -52
- package/docs/rules/prefer-return-this-type.mdx +0 -93
- package/docs/rules/prefer-string-starts-ends-with.mdx +0 -84
- package/docs/rules/prefer-ts-expect-error.mdx +0 -86
- package/docs/rules/promise-function-async.mdx +0 -143
- package/docs/rules/quotes.md +0 -15
- package/docs/rules/related-getter-setter-pairs.mdx +0 -61
- package/docs/rules/require-array-sort-compare.mdx +0 -89
- package/docs/rules/require-await.mdx +0 -53
- package/docs/rules/restrict-plus-operands.mdx +0 -245
- package/docs/rules/restrict-template-expressions.mdx +0 -167
- package/docs/rules/return-await.mdx +0 -339
- package/docs/rules/semi.md +0 -15
- package/docs/rules/sort-type-constituents.mdx +0 -209
- package/docs/rules/sort-type-union-intersection-members.mdx +0 -16
- package/docs/rules/space-before-blocks.md +0 -15
- package/docs/rules/space-before-function-paren.md +0 -15
- package/docs/rules/space-infix-ops.md +0 -15
- package/docs/rules/strict-boolean-expressions.mdx +0 -184
- package/docs/rules/switch-exhaustiveness-check.mdx +0 -280
- package/docs/rules/triple-slash-reference.mdx +0 -129
- package/docs/rules/type-annotation-spacing.md +0 -15
- package/docs/rules/typedef.mdx +0 -350
- package/docs/rules/unbound-method.mdx +0 -114
- package/docs/rules/unified-signatures.mdx +0 -132
- package/docs/rules/use-unknown-in-catch-callback-variable.mdx +0 -97
@@ -1,353 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Require explicit accessibility modifiers on class properties and methods.'
|
3
|
-
---
|
4
|
-
|
5
|
-
import Tabs from '@theme/Tabs';
|
6
|
-
import TabItem from '@theme/TabItem';
|
7
|
-
|
8
|
-
> 🛑 This file is source code, not the primary documentation location! 🛑
|
9
|
-
>
|
10
|
-
> See **https://typescript-eslint.io/rules/explicit-member-accessibility** for documentation.
|
11
|
-
|
12
|
-
TypeScript allows placing explicit `public`, `protected`, and `private` accessibility modifiers in front of class members.
|
13
|
-
The modifiers exist solely in the type system and just serve to describe who is allowed to access those members.
|
14
|
-
|
15
|
-
Leaving off accessibility modifiers makes for less code to read and write.
|
16
|
-
Members are `public` by default.
|
17
|
-
|
18
|
-
However, adding in explicit accessibility modifiers can be helpful in codebases with many classes for enforcing proper privacy of members.
|
19
|
-
Some developers also find it preferable for code readability to keep member publicity explicit.
|
20
|
-
|
21
|
-
## Examples
|
22
|
-
|
23
|
-
This rule aims to make code more readable and explicit about who can use
|
24
|
-
which properties.
|
25
|
-
|
26
|
-
## Options
|
27
|
-
|
28
|
-
### Configuring in a mixed JS/TS codebase
|
29
|
-
|
30
|
-
If you are working on a codebase within which you lint non-TypeScript code (i.e. `.js`/`.mjs`/`.cjs`/`.jsx`), you should ensure that you should use [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files) to only enable the rule on `.ts`/`.mts`/`.cts`/`.tsx` files. If you don't, then you will get unfixable lint errors reported within `.js`/`.mjs`/`.cjs`/`.jsx` files.
|
31
|
-
|
32
|
-
```jsonc
|
33
|
-
{
|
34
|
-
"rules": {
|
35
|
-
// disable the rule for all files
|
36
|
-
"@typescript-eslint/explicit-member-accessibility": "off",
|
37
|
-
},
|
38
|
-
"overrides": [
|
39
|
-
{
|
40
|
-
// enable the rule specifically for TypeScript files
|
41
|
-
"files": ["*.ts", "*.mts", "*.cts", "*.tsx"],
|
42
|
-
"rules": {
|
43
|
-
"@typescript-eslint/explicit-member-accessibility": "error",
|
44
|
-
},
|
45
|
-
},
|
46
|
-
],
|
47
|
-
}
|
48
|
-
```
|
49
|
-
|
50
|
-
### `accessibility`
|
51
|
-
|
52
|
-
{/* insert option description */}
|
53
|
-
|
54
|
-
This rule in its default state requires no configuration and will enforce that every class member has an accessibility modifier. If you would like to allow for some implicit public members then you have the following options:
|
55
|
-
|
56
|
-
```jsonc
|
57
|
-
{
|
58
|
-
"accessibility": "explicit",
|
59
|
-
"overrides": {
|
60
|
-
"accessors": "explicit",
|
61
|
-
"constructors": "no-public",
|
62
|
-
"methods": "explicit",
|
63
|
-
"properties": "off",
|
64
|
-
"parameterProperties": "explicit",
|
65
|
-
},
|
66
|
-
}
|
67
|
-
```
|
68
|
-
|
69
|
-
Note the above is an example of a possible configuration you could use - it is not the default configuration.
|
70
|
-
|
71
|
-
The following patterns are considered incorrect code if no options are provided:
|
72
|
-
|
73
|
-
```ts showPlaygroundButton
|
74
|
-
class Animal {
|
75
|
-
constructor(name) {
|
76
|
-
// No accessibility modifier
|
77
|
-
this.animalName = name;
|
78
|
-
}
|
79
|
-
animalName: string; // No accessibility modifier
|
80
|
-
get name(): string {
|
81
|
-
// No accessibility modifier
|
82
|
-
return this.animalName;
|
83
|
-
}
|
84
|
-
set name(value: string) {
|
85
|
-
// No accessibility modifier
|
86
|
-
this.animalName = value;
|
87
|
-
}
|
88
|
-
walk() {
|
89
|
-
// method
|
90
|
-
}
|
91
|
-
}
|
92
|
-
```
|
93
|
-
|
94
|
-
The following patterns are considered correct with the default options `{ accessibility: 'explicit' }`:
|
95
|
-
|
96
|
-
```ts option='{ "accessibility": "explicit" }' showPlaygroundButton
|
97
|
-
class Animal {
|
98
|
-
public constructor(
|
99
|
-
public breed,
|
100
|
-
name,
|
101
|
-
) {
|
102
|
-
// Parameter property and constructor
|
103
|
-
this.animalName = name;
|
104
|
-
}
|
105
|
-
private animalName: string; // Property
|
106
|
-
get name(): string {
|
107
|
-
// get accessor
|
108
|
-
return this.animalName;
|
109
|
-
}
|
110
|
-
set name(value: string) {
|
111
|
-
// set accessor
|
112
|
-
this.animalName = value;
|
113
|
-
}
|
114
|
-
public walk() {
|
115
|
-
// method
|
116
|
-
}
|
117
|
-
}
|
118
|
-
```
|
119
|
-
|
120
|
-
The following patterns are considered incorrect with the accessibility set to **no-public** `[{ accessibility: 'no-public' }]`:
|
121
|
-
|
122
|
-
```ts option='{ "accessibility": "no-public" }' showPlaygroundButton
|
123
|
-
class Animal {
|
124
|
-
public constructor(
|
125
|
-
public breed,
|
126
|
-
name,
|
127
|
-
) {
|
128
|
-
// Parameter property and constructor
|
129
|
-
this.animalName = name;
|
130
|
-
}
|
131
|
-
public animalName: string; // Property
|
132
|
-
public get name(): string {
|
133
|
-
// get accessor
|
134
|
-
return this.animalName;
|
135
|
-
}
|
136
|
-
public set name(value: string) {
|
137
|
-
// set accessor
|
138
|
-
this.animalName = value;
|
139
|
-
}
|
140
|
-
public walk() {
|
141
|
-
// method
|
142
|
-
}
|
143
|
-
}
|
144
|
-
```
|
145
|
-
|
146
|
-
The following patterns are considered correct with the accessibility set to **no-public** `[{ accessibility: 'no-public' }]`:
|
147
|
-
|
148
|
-
```ts option='{ "accessibility": "no-public" }' showPlaygroundButton
|
149
|
-
class Animal {
|
150
|
-
constructor(
|
151
|
-
protected breed,
|
152
|
-
name,
|
153
|
-
) {
|
154
|
-
// Parameter property and constructor
|
155
|
-
this.name = name;
|
156
|
-
}
|
157
|
-
private animalName: string; // Property
|
158
|
-
get name(): string {
|
159
|
-
// get accessor
|
160
|
-
return this.animalName;
|
161
|
-
}
|
162
|
-
private set name(value: string) {
|
163
|
-
// set accessor
|
164
|
-
this.animalName = value;
|
165
|
-
}
|
166
|
-
protected walk() {
|
167
|
-
// method
|
168
|
-
}
|
169
|
-
}
|
170
|
-
```
|
171
|
-
|
172
|
-
### `overrides`
|
173
|
-
|
174
|
-
{/* insert option description */}
|
175
|
-
|
176
|
-
There are three ways in which an override can be used.
|
177
|
-
|
178
|
-
- To disallow the use of public on a given member.
|
179
|
-
- To enforce explicit member accessibility when the root has allowed implicit public accessibility
|
180
|
-
- To disable any checks on given member type
|
181
|
-
|
182
|
-
#### Disallow the use of public on a given member
|
183
|
-
|
184
|
-
e.g. `[ { overrides: { constructors: 'no-public' } } ]`
|
185
|
-
|
186
|
-
The following patterns are considered incorrect with the example override
|
187
|
-
|
188
|
-
```ts option='{ "overrides": { "constructors": "no-public" } }' showPlaygroundButton
|
189
|
-
class Animal {
|
190
|
-
public constructor(protected animalName) {}
|
191
|
-
public get name() {
|
192
|
-
return this.animalName;
|
193
|
-
}
|
194
|
-
}
|
195
|
-
```
|
196
|
-
|
197
|
-
The following patterns are considered correct with the example override
|
198
|
-
|
199
|
-
```ts option='{ "overrides": { "constructors": "no-public" } }' showPlaygroundButton
|
200
|
-
class Animal {
|
201
|
-
constructor(protected animalName) {}
|
202
|
-
public get name() {
|
203
|
-
return this.animalName;
|
204
|
-
}
|
205
|
-
}
|
206
|
-
```
|
207
|
-
|
208
|
-
#### Require explicit accessibility for a given member
|
209
|
-
|
210
|
-
e.g. `[ { accessibility: 'no-public', overrides: { properties: 'explicit' } } ]`
|
211
|
-
|
212
|
-
The following patterns are considered incorrect with the example override
|
213
|
-
|
214
|
-
```ts option='{ "accessibility": "no-public", "overrides": { "properties": "explicit" } }' showPlaygroundButton
|
215
|
-
class Animal {
|
216
|
-
constructor(protected animalName) {}
|
217
|
-
get name() {
|
218
|
-
return this.animalName;
|
219
|
-
}
|
220
|
-
protected set name(value: string) {
|
221
|
-
this.animalName = value;
|
222
|
-
}
|
223
|
-
legs: number;
|
224
|
-
private hasFleas: boolean;
|
225
|
-
}
|
226
|
-
```
|
227
|
-
|
228
|
-
The following patterns are considered correct with the example override
|
229
|
-
|
230
|
-
```ts option='{ "accessibility": "no-public", "overrides": { "properties": "explicit" } }' showPlaygroundButton
|
231
|
-
class Animal {
|
232
|
-
constructor(protected animalName) {}
|
233
|
-
get name() {
|
234
|
-
return this.animalName;
|
235
|
-
}
|
236
|
-
protected set name(value: string) {
|
237
|
-
this.animalName = value;
|
238
|
-
}
|
239
|
-
public legs: number;
|
240
|
-
private hasFleas: boolean;
|
241
|
-
}
|
242
|
-
```
|
243
|
-
|
244
|
-
e.g. `[ { accessibility: 'off', overrides: { parameterProperties: 'explicit' } } ]`
|
245
|
-
|
246
|
-
The following code is considered incorrect with the example override
|
247
|
-
|
248
|
-
```ts option='{ "accessibility": "off", "overrides": { "parameterProperties": "explicit" } }' showPlaygroundButton
|
249
|
-
class Animal {
|
250
|
-
constructor(readonly animalName: string) {}
|
251
|
-
}
|
252
|
-
```
|
253
|
-
|
254
|
-
The following code patterns are considered correct with the example override
|
255
|
-
|
256
|
-
```ts option='{ "accessibility": "off", "overrides": { "parameterProperties": "explicit" } }' showPlaygroundButton
|
257
|
-
class Animal {
|
258
|
-
constructor(public readonly animalName: string) {}
|
259
|
-
}
|
260
|
-
|
261
|
-
class Animal {
|
262
|
-
constructor(public animalName: string) {}
|
263
|
-
}
|
264
|
-
|
265
|
-
class Animal {
|
266
|
-
constructor(animalName: string) {}
|
267
|
-
}
|
268
|
-
```
|
269
|
-
|
270
|
-
e.g. `[ { accessibility: 'off', overrides: { parameterProperties: 'no-public' } } ]`
|
271
|
-
|
272
|
-
The following code is considered incorrect with the example override
|
273
|
-
|
274
|
-
```ts option='{ "accessibility": "off", "overrides": { "parameterProperties": "no-public" } }' showPlaygroundButton
|
275
|
-
class Animal {
|
276
|
-
constructor(public readonly animalName: string) {}
|
277
|
-
}
|
278
|
-
```
|
279
|
-
|
280
|
-
The following code is considered correct with the example override
|
281
|
-
|
282
|
-
```ts option='{ "accessibility": "off", "overrides": { "parameterProperties": "no-public" } }' showPlaygroundButton
|
283
|
-
class Animal {
|
284
|
-
constructor(public animalName: string) {}
|
285
|
-
}
|
286
|
-
```
|
287
|
-
|
288
|
-
#### Disable any checks on given member type
|
289
|
-
|
290
|
-
e.g. `[{ overrides: { accessors : 'off' } } ]`
|
291
|
-
|
292
|
-
As no checks on the overridden member type are performed all permutations of visibility are permitted for that member type
|
293
|
-
|
294
|
-
The follow pattern is considered incorrect for the given configuration
|
295
|
-
|
296
|
-
```ts option='{ "overrides": { "accessors" : "off" } }' showPlaygroundButton
|
297
|
-
class Animal {
|
298
|
-
constructor(protected animalName) {}
|
299
|
-
public get name() {
|
300
|
-
return this.animalName;
|
301
|
-
}
|
302
|
-
get legs() {
|
303
|
-
return this.legCount;
|
304
|
-
}
|
305
|
-
}
|
306
|
-
```
|
307
|
-
|
308
|
-
The following patterns are considered correct with the example override
|
309
|
-
|
310
|
-
```ts option='{ "overrides": { "accessors" : "off" } }' showPlaygroundButton
|
311
|
-
class Animal {
|
312
|
-
public constructor(protected animalName) {}
|
313
|
-
public get name() {
|
314
|
-
return this.animalName;
|
315
|
-
}
|
316
|
-
get legs() {
|
317
|
-
return this.legCount;
|
318
|
-
}
|
319
|
-
}
|
320
|
-
```
|
321
|
-
|
322
|
-
### `ignoredMethodNames`
|
323
|
-
|
324
|
-
{/* insert option description */}
|
325
|
-
|
326
|
-
Note that this option does not care about context, and will ignore every method with these names, which could lead to it missing some cases. You should use this sparingly.
|
327
|
-
e.g. `[ { ignoredMethodNames: ['specificMethod', 'whateverMethod'] } ]`
|
328
|
-
|
329
|
-
```ts option='{ "ignoredMethodNames": ["specificMethod", "whateverMethod"] }' showPlaygroundButton
|
330
|
-
class Animal {
|
331
|
-
get specificMethod() {
|
332
|
-
console.log('No error because you specified this method on option');
|
333
|
-
}
|
334
|
-
get whateverMethod() {
|
335
|
-
console.log('No error because you specified this method on option');
|
336
|
-
}
|
337
|
-
public get otherMethod() {
|
338
|
-
console.log('This method comply with this rule');
|
339
|
-
}
|
340
|
-
}
|
341
|
-
```
|
342
|
-
|
343
|
-
## When Not To Use It
|
344
|
-
|
345
|
-
If you think defaulting to public is a good default, then you should consider using the `no-public` setting.
|
346
|
-
If you want to mix implicit and explicit public members then you can disable this rule.
|
347
|
-
|
348
|
-
However, keep in mind that inconsistent style can harm readability in a project.
|
349
|
-
We recommend picking a single option for this rule that works best for your project.
|
350
|
-
|
351
|
-
## Further Reading
|
352
|
-
|
353
|
-
- TypeScript [Accessibility Modifiers Handbook Docs](https://www.typescriptlang.org/docs/handbook/2/classes.html#member-visibility)
|
@@ -1,287 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: "Require explicit return and argument types on exported functions' and classes' public class methods."
|
3
|
-
---
|
4
|
-
|
5
|
-
import Tabs from '@theme/Tabs';
|
6
|
-
import TabItem from '@theme/TabItem';
|
7
|
-
|
8
|
-
> 🛑 This file is source code, not the primary documentation location! 🛑
|
9
|
-
>
|
10
|
-
> See **https://typescript-eslint.io/rules/explicit-module-boundary-types** for documentation.
|
11
|
-
|
12
|
-
Explicit types for function return values and arguments makes it clear to any calling code what is the module boundary's input and output.
|
13
|
-
Adding explicit type annotations for those types can help improve code readability.
|
14
|
-
It can also improve TypeScript type checking performance on larger codebases.
|
15
|
-
|
16
|
-
## Examples
|
17
|
-
|
18
|
-
<Tabs>
|
19
|
-
<TabItem value="❌ Incorrect">
|
20
|
-
|
21
|
-
```ts
|
22
|
-
// Should indicate that no value is returned (void)
|
23
|
-
export function test() {
|
24
|
-
return;
|
25
|
-
}
|
26
|
-
|
27
|
-
// Should indicate that a string is returned
|
28
|
-
export var arrowFn = () => 'test';
|
29
|
-
|
30
|
-
// All arguments should be typed
|
31
|
-
export var arrowFn = (arg): string => `test ${arg}`;
|
32
|
-
export var arrowFn = (arg: any): string => `test ${arg}`;
|
33
|
-
|
34
|
-
export class Test {
|
35
|
-
// Should indicate that no value is returned (void)
|
36
|
-
method() {
|
37
|
-
return;
|
38
|
-
}
|
39
|
-
}
|
40
|
-
```
|
41
|
-
|
42
|
-
</TabItem>
|
43
|
-
<TabItem value="✅ Correct">
|
44
|
-
|
45
|
-
```ts
|
46
|
-
// A function with no return value (void)
|
47
|
-
export function test(): void {
|
48
|
-
return;
|
49
|
-
}
|
50
|
-
|
51
|
-
// A return value of type string
|
52
|
-
export var arrowFn = (): string => 'test';
|
53
|
-
|
54
|
-
// All arguments should be typed
|
55
|
-
export var arrowFn = (arg: string): string => `test ${arg}`;
|
56
|
-
export var arrowFn = (arg: unknown): string => `test ${arg}`;
|
57
|
-
|
58
|
-
export class Test {
|
59
|
-
// A class method with no return value (void)
|
60
|
-
method(): void {
|
61
|
-
return;
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
// The function does not apply because it is not an exported function.
|
66
|
-
function test() {
|
67
|
-
return;
|
68
|
-
}
|
69
|
-
```
|
70
|
-
|
71
|
-
</TabItem>
|
72
|
-
</Tabs>
|
73
|
-
|
74
|
-
## Options
|
75
|
-
|
76
|
-
### Configuring in a mixed JS/TS codebase
|
77
|
-
|
78
|
-
If you are working on a codebase within which you lint non-TypeScript code (i.e. `.js`/`.mjs`/`.cjs`/`.jsx`), you should ensure that you should use [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files) to only enable the rule on `.ts`/`.mts`/`.cts`/`.tsx` files. If you don't, then you will get unfixable lint errors reported within `.js`/`.mjs`/`.cjs`/`.jsx` files.
|
79
|
-
|
80
|
-
```jsonc
|
81
|
-
{
|
82
|
-
"rules": {
|
83
|
-
// disable the rule for all files
|
84
|
-
"@typescript-eslint/explicit-module-boundary-types": "off",
|
85
|
-
},
|
86
|
-
"overrides": [
|
87
|
-
{
|
88
|
-
// enable the rule specifically for TypeScript files
|
89
|
-
"files": ["*.ts", "*.mts", "*.cts", "*.tsx"],
|
90
|
-
"rules": {
|
91
|
-
"@typescript-eslint/explicit-module-boundary-types": "error",
|
92
|
-
},
|
93
|
-
},
|
94
|
-
],
|
95
|
-
}
|
96
|
-
```
|
97
|
-
|
98
|
-
### `allowArgumentsExplicitlyTypedAsAny`
|
99
|
-
|
100
|
-
{/* insert option description */}
|
101
|
-
|
102
|
-
Examples of code for this rule with `{ allowArgumentsExplicitlyTypedAsAny: false }`:
|
103
|
-
|
104
|
-
<Tabs>
|
105
|
-
<TabItem value="❌ Incorrect">
|
106
|
-
|
107
|
-
```ts option='{ "allowArgumentsExplicitlyTypedAsAny": false }'
|
108
|
-
export const func = (value: any): number => value + 1;
|
109
|
-
```
|
110
|
-
|
111
|
-
</TabItem>
|
112
|
-
<TabItem value="✅ Correct">
|
113
|
-
|
114
|
-
```ts option='{ "allowArgumentsExplicitlyTypedAsAny": true }'
|
115
|
-
export const func = (value: any): number => value + 1;
|
116
|
-
```
|
117
|
-
|
118
|
-
</TabItem>
|
119
|
-
</Tabs>
|
120
|
-
|
121
|
-
### `allowDirectConstAssertionInArrowFunctions`
|
122
|
-
|
123
|
-
{/* insert option description */}
|
124
|
-
|
125
|
-
Examples of code for this rule with `{ allowDirectConstAssertionInArrowFunctions: false }`:
|
126
|
-
|
127
|
-
<Tabs>
|
128
|
-
<TabItem value="❌ Incorrect">
|
129
|
-
|
130
|
-
```ts option='{ "allowDirectConstAssertionInArrowFunctions": false }'
|
131
|
-
export const func = (value: number) => ({ type: 'X', value });
|
132
|
-
export const foo = () => ({
|
133
|
-
bar: true,
|
134
|
-
});
|
135
|
-
export const bar = () => 1;
|
136
|
-
```
|
137
|
-
|
138
|
-
</TabItem>
|
139
|
-
<TabItem value="✅ Correct">
|
140
|
-
|
141
|
-
```ts option='{ "allowDirectConstAssertionInArrowFunctions": true }'
|
142
|
-
export const func = (value: number) => ({ type: 'X', value }) as const;
|
143
|
-
export const foo = () =>
|
144
|
-
({
|
145
|
-
bar: true,
|
146
|
-
}) as const;
|
147
|
-
export const bar = () => 1 as const;
|
148
|
-
```
|
149
|
-
|
150
|
-
</TabItem>
|
151
|
-
</Tabs>
|
152
|
-
|
153
|
-
### `allowedNames`
|
154
|
-
|
155
|
-
{/* insert option description */}
|
156
|
-
|
157
|
-
You may pass function/method names you would like this rule to ignore, like so:
|
158
|
-
|
159
|
-
```json
|
160
|
-
{
|
161
|
-
"@typescript-eslint/explicit-module-boundary-types": [
|
162
|
-
"error",
|
163
|
-
{
|
164
|
-
"allowedNames": ["ignoredFunctionName", "ignoredMethodName"]
|
165
|
-
}
|
166
|
-
]
|
167
|
-
}
|
168
|
-
```
|
169
|
-
|
170
|
-
### `allowHigherOrderFunctions`
|
171
|
-
|
172
|
-
{/* insert option description */}
|
173
|
-
|
174
|
-
Examples of code for this rule with `{ allowHigherOrderFunctions: false }`:
|
175
|
-
|
176
|
-
<Tabs>
|
177
|
-
<TabItem value="❌ Incorrect">
|
178
|
-
|
179
|
-
```ts option='{ "allowHigherOrderFunctions": false }'
|
180
|
-
export const arrowFn = () => () => {};
|
181
|
-
|
182
|
-
export function fn() {
|
183
|
-
return function () {};
|
184
|
-
}
|
185
|
-
|
186
|
-
export function foo(outer: string) {
|
187
|
-
return function (inner: string) {};
|
188
|
-
}
|
189
|
-
```
|
190
|
-
|
191
|
-
</TabItem>
|
192
|
-
<TabItem value="✅ Correct">
|
193
|
-
|
194
|
-
```ts option='{ "allowHigherOrderFunctions": true }'
|
195
|
-
export const arrowFn = () => (): void => {};
|
196
|
-
|
197
|
-
export function fn() {
|
198
|
-
return function (): void {};
|
199
|
-
}
|
200
|
-
|
201
|
-
export function foo(outer: string) {
|
202
|
-
return function (inner: string): void {};
|
203
|
-
}
|
204
|
-
```
|
205
|
-
|
206
|
-
</TabItem>
|
207
|
-
</Tabs>
|
208
|
-
|
209
|
-
### `allowTypedFunctionExpressions`
|
210
|
-
|
211
|
-
{/* insert option description */}
|
212
|
-
|
213
|
-
Examples of code for this rule with `{ allowTypedFunctionExpressions: false }`:
|
214
|
-
|
215
|
-
<Tabs>
|
216
|
-
<TabItem value="❌ Incorrect">
|
217
|
-
|
218
|
-
```ts option='{ "allowTypedFunctionExpressions": false }'
|
219
|
-
export let arrowFn = () => 'test';
|
220
|
-
|
221
|
-
export let funcExpr = function () {
|
222
|
-
return 'test';
|
223
|
-
};
|
224
|
-
|
225
|
-
export let objectProp = {
|
226
|
-
foo: () => 1,
|
227
|
-
};
|
228
|
-
|
229
|
-
export const foo = bar => {};
|
230
|
-
```
|
231
|
-
|
232
|
-
</TabItem>
|
233
|
-
<TabItem value="✅ Correct">
|
234
|
-
|
235
|
-
```ts option='{ "allowTypedFunctionExpressions": true }'
|
236
|
-
type FuncType = () => string;
|
237
|
-
|
238
|
-
export let arrowFn: FuncType = () => 'test';
|
239
|
-
|
240
|
-
export let funcExpr: FuncType = function () {
|
241
|
-
return 'test';
|
242
|
-
};
|
243
|
-
|
244
|
-
export let asTyped = (() => '') as () => string;
|
245
|
-
|
246
|
-
interface ObjectType {
|
247
|
-
foo(): number;
|
248
|
-
}
|
249
|
-
export let objectProp: ObjectType = {
|
250
|
-
foo: () => 1,
|
251
|
-
};
|
252
|
-
export let objectPropAs = {
|
253
|
-
foo: () => 1,
|
254
|
-
} as ObjectType;
|
255
|
-
|
256
|
-
type FooType = (bar: string) => void;
|
257
|
-
export const foo: FooType = bar => {};
|
258
|
-
```
|
259
|
-
|
260
|
-
</TabItem>
|
261
|
-
</Tabs>
|
262
|
-
|
263
|
-
### `allowOverloadFunctions`
|
264
|
-
|
265
|
-
{/* insert option description */}
|
266
|
-
|
267
|
-
Examples of correct code when `allowOverloadFunctions` is set to `true`:
|
268
|
-
|
269
|
-
```ts option='{ "allowOverloadFunctions": true }' showPlaygroundButton
|
270
|
-
export function test(a: string): string;
|
271
|
-
export function test(a: number): number;
|
272
|
-
export function test(a: unknown) {
|
273
|
-
return a;
|
274
|
-
}
|
275
|
-
```
|
276
|
-
|
277
|
-
## When Not To Use It
|
278
|
-
|
279
|
-
If your project is not used by downstream consumers that are sensitive to API types, you can disable this rule.
|
280
|
-
|
281
|
-
## Further Reading
|
282
|
-
|
283
|
-
- TypeScript [Functions](https://www.typescriptlang.org/docs/handbook/functions.html#function-types)
|
284
|
-
|
285
|
-
## Related To
|
286
|
-
|
287
|
-
- [explicit-function-return-type](./explicit-function-return-type.mdx)
|
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
displayed_sidebar: rulesSidebar
|
3
|
-
---
|
4
|
-
|
5
|
-
:::danger Deprecated
|
6
|
-
|
7
|
-
This rule has been moved to the [ESLint stylistic plugin](https://eslint.style).
|
8
|
-
See [#8072](https://github.com/typescript-eslint/typescript-eslint/issues/8072) and [#8074](https://github.com/typescript-eslint/typescript-eslint/issues/8074) for more information.
|
9
|
-
|
10
|
-
:::
|
11
|
-
|
12
|
-
<!-- This doc file has been left on purpose to help direct people to the stylistic plugin.
|
13
|
-
|
14
|
-
Note that there is no actual way to get to this page in the normal navigation,
|
15
|
-
so end-users will only be able to get to this page from the search bar. -->
|
package/docs/rules/indent.md
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
displayed_sidebar: rulesSidebar
|
3
|
-
---
|
4
|
-
|
5
|
-
:::danger Deprecated
|
6
|
-
|
7
|
-
This rule has been moved to the [ESLint stylistic plugin](https://eslint.style).
|
8
|
-
See [#8072](https://github.com/typescript-eslint/typescript-eslint/issues/8072) and [#8074](https://github.com/typescript-eslint/typescript-eslint/issues/8074) for more information.
|
9
|
-
|
10
|
-
:::
|
11
|
-
|
12
|
-
<!-- This doc file has been left on purpose to help direct people to the stylistic plugin.
|
13
|
-
|
14
|
-
Note that there is no actual way to get to this page in the normal navigation,
|
15
|
-
so end-users will only be able to get to this page from the search bar. -->
|
@@ -1,12 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Require or disallow initialization in variable declarations.'
|
3
|
-
---
|
4
|
-
|
5
|
-
import Tabs from '@theme/Tabs';
|
6
|
-
import TabItem from '@theme/TabItem';
|
7
|
-
|
8
|
-
> 🛑 This file is source code, not the primary documentation location! 🛑
|
9
|
-
>
|
10
|
-
> See **https://typescript-eslint.io/rules/init-declarations** for documentation.
|
11
|
-
|
12
|
-
It adds support for TypeScript's `declare` variables.
|
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
displayed_sidebar: rulesSidebar
|
3
|
-
---
|
4
|
-
|
5
|
-
:::danger Deprecated
|
6
|
-
|
7
|
-
This rule has been moved to the [ESLint stylistic plugin](https://eslint.style).
|
8
|
-
See [#8072](https://github.com/typescript-eslint/typescript-eslint/issues/8072) and [#8074](https://github.com/typescript-eslint/typescript-eslint/issues/8074) for more information.
|
9
|
-
|
10
|
-
:::
|
11
|
-
|
12
|
-
<!-- This doc file has been left on purpose to help direct people to the stylistic plugin.
|
13
|
-
|
14
|
-
Note that there is no actual way to get to this page in the normal navigation,
|
15
|
-
so end-users will only be able to get to this page from the search bar. -->
|