@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.
Files changed (161) hide show
  1. package/package.json +9 -10
  2. package/docs/rules/README.md +0 -57
  3. package/docs/rules/TEMPLATE.md +0 -36
  4. package/docs/rules/adjacent-overload-signatures.mdx +0 -105
  5. package/docs/rules/array-type.mdx +0 -126
  6. package/docs/rules/await-thenable.mdx +0 -184
  7. package/docs/rules/ban-ts-comment.mdx +0 -165
  8. package/docs/rules/ban-tslint-comment.mdx +0 -45
  9. package/docs/rules/ban-types.md +0 -26
  10. package/docs/rules/block-spacing.md +0 -15
  11. package/docs/rules/brace-style.md +0 -15
  12. package/docs/rules/camelcase.md +0 -15
  13. package/docs/rules/class-literal-property-style.mdx +0 -112
  14. package/docs/rules/class-methods-use-this.mdx +0 -135
  15. package/docs/rules/comma-dangle.md +0 -15
  16. package/docs/rules/comma-spacing.md +0 -15
  17. package/docs/rules/consistent-generic-constructors.mdx +0 -87
  18. package/docs/rules/consistent-indexed-object-style.mdx +0 -105
  19. package/docs/rules/consistent-return.mdx +0 -51
  20. package/docs/rules/consistent-type-assertions.mdx +0 -196
  21. package/docs/rules/consistent-type-definitions.mdx +0 -133
  22. package/docs/rules/consistent-type-exports.mdx +0 -97
  23. package/docs/rules/consistent-type-imports.mdx +0 -139
  24. package/docs/rules/default-param-last.mdx +0 -59
  25. package/docs/rules/dot-notation.mdx +0 -94
  26. package/docs/rules/explicit-function-return-type.mdx +0 -359
  27. package/docs/rules/explicit-member-accessibility.mdx +0 -353
  28. package/docs/rules/explicit-module-boundary-types.mdx +0 -287
  29. package/docs/rules/func-call-spacing.md +0 -15
  30. package/docs/rules/indent.md +0 -15
  31. package/docs/rules/init-declarations.mdx +0 -12
  32. package/docs/rules/key-spacing.md +0 -15
  33. package/docs/rules/keyword-spacing.md +0 -15
  34. package/docs/rules/lines-around-comment.md +0 -15
  35. package/docs/rules/lines-between-class-members.md +0 -15
  36. package/docs/rules/max-params.mdx +0 -54
  37. package/docs/rules/member-delimiter-style.md +0 -15
  38. package/docs/rules/member-ordering.mdx +0 -1483
  39. package/docs/rules/method-signature-style.mdx +0 -124
  40. package/docs/rules/naming-convention.mdx +0 -755
  41. package/docs/rules/no-array-constructor.mdx +0 -34
  42. package/docs/rules/no-array-delete.mdx +0 -44
  43. package/docs/rules/no-base-to-string.mdx +0 -115
  44. package/docs/rules/no-confusing-non-null-assertion.mdx +0 -75
  45. package/docs/rules/no-confusing-void-expression.mdx +0 -148
  46. package/docs/rules/no-deprecated.mdx +0 -119
  47. package/docs/rules/no-dupe-class-members.mdx +0 -16
  48. package/docs/rules/no-duplicate-enum-values.mdx +0 -66
  49. package/docs/rules/no-duplicate-imports.mdx +0 -17
  50. package/docs/rules/no-duplicate-type-constituents.mdx +0 -89
  51. package/docs/rules/no-dynamic-delete.mdx +0 -64
  52. package/docs/rules/no-empty-function.mdx +0 -94
  53. package/docs/rules/no-empty-interface.mdx +0 -75
  54. package/docs/rules/no-empty-object-type.mdx +0 -150
  55. package/docs/rules/no-explicit-any.mdx +0 -177
  56. package/docs/rules/no-extra-non-null-assertion.mdx +0 -60
  57. package/docs/rules/no-extra-parens.md +0 -15
  58. package/docs/rules/no-extra-semi.md +0 -15
  59. package/docs/rules/no-extraneous-class.mdx +0 -329
  60. package/docs/rules/no-floating-promises.mdx +0 -282
  61. package/docs/rules/no-for-in-array.mdx +0 -67
  62. package/docs/rules/no-implied-eval.mdx +0 -106
  63. package/docs/rules/no-import-type-side-effects.mdx +0 -80
  64. package/docs/rules/no-inferrable-types.mdx +0 -113
  65. package/docs/rules/no-invalid-this.mdx +0 -16
  66. package/docs/rules/no-invalid-void-type.mdx +0 -119
  67. package/docs/rules/no-loop-func.mdx +0 -12
  68. package/docs/rules/no-loss-of-precision.mdx +0 -17
  69. package/docs/rules/no-magic-numbers.mdx +0 -131
  70. package/docs/rules/no-meaningless-void-operator.mdx +0 -61
  71. package/docs/rules/no-misused-new.mdx +0 -53
  72. package/docs/rules/no-misused-promises.mdx +0 -314
  73. package/docs/rules/no-misused-spread.mdx +0 -132
  74. package/docs/rules/no-mixed-enums.mdx +0 -96
  75. package/docs/rules/no-namespace.mdx +0 -157
  76. package/docs/rules/no-non-null-asserted-nullish-coalescing.mdx +0 -60
  77. package/docs/rules/no-non-null-asserted-optional-chain.mdx +0 -46
  78. package/docs/rules/no-non-null-assertion.mdx +0 -48
  79. package/docs/rules/no-parameter-properties.mdx +0 -16
  80. package/docs/rules/no-redeclare.mdx +0 -79
  81. package/docs/rules/no-redundant-type-constituents.mdx +0 -102
  82. package/docs/rules/no-require-imports.mdx +0 -114
  83. package/docs/rules/no-restricted-imports.mdx +0 -84
  84. package/docs/rules/no-restricted-types.mdx +0 -70
  85. package/docs/rules/no-shadow.mdx +0 -143
  86. package/docs/rules/no-this-alias.mdx +0 -124
  87. package/docs/rules/no-type-alias.mdx +0 -626
  88. package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +0 -165
  89. package/docs/rules/no-unnecessary-condition.mdx +0 -293
  90. package/docs/rules/no-unnecessary-parameter-property-assignment.mdx +0 -42
  91. package/docs/rules/no-unnecessary-qualifier.mdx +0 -57
  92. package/docs/rules/no-unnecessary-template-expression.mdx +0 -108
  93. package/docs/rules/no-unnecessary-type-arguments.mdx +0 -85
  94. package/docs/rules/no-unnecessary-type-assertion.mdx +0 -97
  95. package/docs/rules/no-unnecessary-type-constraint.mdx +0 -61
  96. package/docs/rules/no-unnecessary-type-conversion.mdx +0 -79
  97. package/docs/rules/no-unnecessary-type-parameters.mdx +0 -255
  98. package/docs/rules/no-unsafe-argument.mdx +0 -98
  99. package/docs/rules/no-unsafe-assignment.mdx +0 -101
  100. package/docs/rules/no-unsafe-call.mdx +0 -120
  101. package/docs/rules/no-unsafe-declaration-merging.mdx +0 -65
  102. package/docs/rules/no-unsafe-enum-comparison.mdx +0 -98
  103. package/docs/rules/no-unsafe-function-type.mdx +0 -65
  104. package/docs/rules/no-unsafe-member-access.mdx +0 -81
  105. package/docs/rules/no-unsafe-return.mdx +0 -126
  106. package/docs/rules/no-unsafe-type-assertion.mdx +0 -63
  107. package/docs/rules/no-unsafe-unary-minus.mdx +0 -60
  108. package/docs/rules/no-unused-expressions.mdx +0 -52
  109. package/docs/rules/no-unused-vars.mdx +0 -136
  110. package/docs/rules/no-use-before-define.mdx +0 -98
  111. package/docs/rules/no-useless-constructor.mdx +0 -21
  112. package/docs/rules/no-useless-empty-export.mdx +0 -53
  113. package/docs/rules/no-useless-template-literals.mdx +0 -9
  114. package/docs/rules/no-var-requires.mdx +0 -77
  115. package/docs/rules/no-wrapper-object-types.mdx +0 -75
  116. package/docs/rules/non-nullable-type-assertion-style.mdx +0 -47
  117. package/docs/rules/object-curly-spacing.md +0 -15
  118. package/docs/rules/only-throw-error.mdx +0 -150
  119. package/docs/rules/padding-line-between-statements.md +0 -15
  120. package/docs/rules/parameter-properties.mdx +0 -522
  121. package/docs/rules/prefer-as-const.mdx +0 -51
  122. package/docs/rules/prefer-destructuring.mdx +0 -101
  123. package/docs/rules/prefer-enum-initializers.mdx +0 -68
  124. package/docs/rules/prefer-find.mdx +0 -45
  125. package/docs/rules/prefer-for-of.mdx +0 -50
  126. package/docs/rules/prefer-function-type.mdx +0 -98
  127. package/docs/rules/prefer-includes.mdx +0 -81
  128. package/docs/rules/prefer-literal-enum-member.mdx +0 -111
  129. package/docs/rules/prefer-namespace-keyword.mdx +0 -51
  130. package/docs/rules/prefer-nullish-coalescing.mdx +0 -349
  131. package/docs/rules/prefer-optional-chain.mdx +0 -304
  132. package/docs/rules/prefer-promise-reject-errors.mdx +0 -78
  133. package/docs/rules/prefer-readonly-parameter-types.mdx +0 -408
  134. package/docs/rules/prefer-readonly.mdx +0 -111
  135. package/docs/rules/prefer-reduce-type-parameter.mdx +0 -66
  136. package/docs/rules/prefer-regexp-exec.mdx +0 -52
  137. package/docs/rules/prefer-return-this-type.mdx +0 -93
  138. package/docs/rules/prefer-string-starts-ends-with.mdx +0 -84
  139. package/docs/rules/prefer-ts-expect-error.mdx +0 -86
  140. package/docs/rules/promise-function-async.mdx +0 -143
  141. package/docs/rules/quotes.md +0 -15
  142. package/docs/rules/related-getter-setter-pairs.mdx +0 -61
  143. package/docs/rules/require-array-sort-compare.mdx +0 -89
  144. package/docs/rules/require-await.mdx +0 -53
  145. package/docs/rules/restrict-plus-operands.mdx +0 -245
  146. package/docs/rules/restrict-template-expressions.mdx +0 -167
  147. package/docs/rules/return-await.mdx +0 -339
  148. package/docs/rules/semi.md +0 -15
  149. package/docs/rules/sort-type-constituents.mdx +0 -209
  150. package/docs/rules/sort-type-union-intersection-members.mdx +0 -16
  151. package/docs/rules/space-before-blocks.md +0 -15
  152. package/docs/rules/space-before-function-paren.md +0 -15
  153. package/docs/rules/space-infix-ops.md +0 -15
  154. package/docs/rules/strict-boolean-expressions.mdx +0 -184
  155. package/docs/rules/switch-exhaustiveness-check.mdx +0 -280
  156. package/docs/rules/triple-slash-reference.mdx +0 -129
  157. package/docs/rules/type-annotation-spacing.md +0 -15
  158. package/docs/rules/typedef.mdx +0 -350
  159. package/docs/rules/unbound-method.mdx +0 -114
  160. package/docs/rules/unified-signatures.mdx +0 -132
  161. package/docs/rules/use-unknown-in-catch-callback-variable.mdx +0 -97
@@ -1,1483 +0,0 @@
1
- ---
2
- description: 'Require a consistent member declaration order.'
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/member-ordering** for documentation.
11
-
12
- This rule aims to standardize the way classes, interfaces, and type literals are structured and ordered.
13
- A consistent ordering of fields, methods and constructors can make code easier to read, navigate, and edit.
14
-
15
- :::note
16
- This rule is _feature frozen_: it will no longer receive new features such as new options.
17
- It still will accept bug and documentation fixes for its existing area of features.
18
-
19
- Stylistic rules that enforce naming and/or sorting conventions tend to grow incomprehensibly complex as increasingly obscure features are requested.
20
- This rule has reached the limit of what is reasonable for the typescript-eslint project to maintain.
21
- See [eslint-plugin: Feature freeze naming and sorting stylistic rules](https://github.com/typescript-eslint/typescript-eslint/issues/8792) for more information.
22
- :::
23
-
24
- ## Options
25
-
26
- ```ts
27
- interface Options {
28
- default?: OrderConfig;
29
- classes?: OrderConfig;
30
- classExpressions?: OrderConfig;
31
- interfaces?: OrderConfig;
32
- typeLiterals?: OrderConfig;
33
- }
34
-
35
- type OrderConfig = MemberType[] | SortedOrderConfig | 'never';
36
-
37
- interface SortedOrderConfig {
38
- memberTypes?: MemberType[] | 'never';
39
- optionalityOrder?: 'optional-first' | 'required-first';
40
- order?:
41
- | 'alphabetically'
42
- | 'alphabetically-case-insensitive'
43
- | 'as-written'
44
- | 'natural'
45
- | 'natural-case-insensitive';
46
- }
47
-
48
- // See below for the more specific MemberType strings
49
- type MemberType = string | string[];
50
- ```
51
-
52
- You can configure `OrderConfig` options for:
53
-
54
- - **`default`**: all constructs (used as a fallback)
55
- - **`classes`**?: override ordering specifically for classes
56
- - **`classExpressions`**?: override ordering specifically for class expressions
57
- - **`interfaces`**?: override ordering specifically for interfaces
58
- - **`typeLiterals`**?: override ordering specifically for type literals
59
-
60
- The `OrderConfig` settings for each kind of construct may configure sorting on up to three levels:
61
-
62
- - **`memberTypes`**: organizing on member type groups such as methods vs. properties
63
- - **`optionalityOrder`**: whether to put all optional members first or all required members first
64
- - **`order`**: organizing based on member names, such as alphabetically
65
-
66
- ### Groups
67
-
68
- You can define many different groups based on different attributes of members.
69
- The supported member attributes are, in order:
70
-
71
- - **Accessibility** (`'public' | 'protected' | 'private' | '#private'`)
72
- - **Decoration** (`'decorated'`): Whether the member has an explicit accessibility decorator
73
- - **Kind** (`'call-signature' | 'constructor' | 'field' | 'readonly-field' | 'get' | 'method' | 'set' | 'signature' | 'readonly-signature'`)
74
-
75
- Member attributes may be joined with a `'-'` to combine into more specific groups.
76
- For example, `'public-field'` would come before `'private-field'`.
77
-
78
- ### Orders
79
-
80
- The `order` value specifies what order members should be within a group.
81
- It defaults to `as-written`, meaning any order is fine.
82
- Other allowed values are:
83
-
84
- - `alphabetically`: Sorted in a-z alphabetical order, directly using string `<` comparison (so `B` comes before `a`)
85
- - `alphabetically-case-insensitive`: Sorted in a-z alphabetical order, ignoring case (so `a` comes before `B`)
86
- - `natural`: Same as `alphabetically`, but using [`natural-compare-lite`](https://github.com/litejs/natural-compare-lite) for more friendly sorting of numbers
87
- - `natural-case-insensitive`: Same as `alphabetically-case-insensitive`, but using [`natural-compare-lite`](https://github.com/litejs/natural-compare-lite) for more friendly sorting of numbers
88
-
89
- ### Default configuration
90
-
91
- The default configuration looks as follows:
92
-
93
- ```jsonc
94
- {
95
- "default": {
96
- "memberTypes": [
97
- // Index signature
98
- "signature",
99
- "call-signature",
100
-
101
- // Fields
102
- "public-static-field",
103
- "protected-static-field",
104
- "private-static-field",
105
- "#private-static-field",
106
-
107
- "public-decorated-field",
108
- "protected-decorated-field",
109
- "private-decorated-field",
110
-
111
- "public-instance-field",
112
- "protected-instance-field",
113
- "private-instance-field",
114
- "#private-instance-field",
115
-
116
- "public-abstract-field",
117
- "protected-abstract-field",
118
-
119
- "public-field",
120
- "protected-field",
121
- "private-field",
122
- "#private-field",
123
-
124
- "static-field",
125
- "instance-field",
126
- "abstract-field",
127
-
128
- "decorated-field",
129
-
130
- "field",
131
-
132
- // Static initialization
133
- "static-initialization",
134
-
135
- // Constructors
136
- "public-constructor",
137
- "protected-constructor",
138
- "private-constructor",
139
-
140
- "constructor",
141
-
142
- // Accessors
143
- "public-static-accessor",
144
- "protected-static-accessor",
145
- "private-static-accessor",
146
- "#private-static-accessor",
147
-
148
- "public-decorated-accessor",
149
- "protected-decorated-accessor",
150
- "private-decorated-accessor",
151
-
152
- "public-instance-accessor",
153
- "protected-instance-accessor",
154
- "private-instance-accessor",
155
- "#private-instance-accessor",
156
-
157
- "public-abstract-accessor",
158
- "protected-abstract-accessor",
159
-
160
- "public-accessor",
161
- "protected-accessor",
162
- "private-accessor",
163
- "#private-accessor",
164
-
165
- "static-accessor",
166
- "instance-accessor",
167
- "abstract-accessor",
168
-
169
- "decorated-accessor",
170
-
171
- "accessor",
172
-
173
- // Getters
174
- "public-static-get",
175
- "protected-static-get",
176
- "private-static-get",
177
- "#private-static-get",
178
-
179
- "public-decorated-get",
180
- "protected-decorated-get",
181
- "private-decorated-get",
182
-
183
- "public-instance-get",
184
- "protected-instance-get",
185
- "private-instance-get",
186
- "#private-instance-get",
187
-
188
- "public-abstract-get",
189
- "protected-abstract-get",
190
-
191
- "public-get",
192
- "protected-get",
193
- "private-get",
194
- "#private-get",
195
-
196
- "static-get",
197
- "instance-get",
198
- "abstract-get",
199
-
200
- "decorated-get",
201
-
202
- "get",
203
-
204
- // Setters
205
- "public-static-set",
206
- "protected-static-set",
207
- "private-static-set",
208
- "#private-static-set",
209
-
210
- "public-decorated-set",
211
- "protected-decorated-set",
212
- "private-decorated-set",
213
-
214
- "public-instance-set",
215
- "protected-instance-set",
216
- "private-instance-set",
217
- "#private-instance-set",
218
-
219
- "public-abstract-set",
220
- "protected-abstract-set",
221
-
222
- "public-set",
223
- "protected-set",
224
- "private-set",
225
- "#private-set",
226
-
227
- "static-set",
228
- "instance-set",
229
- "abstract-set",
230
-
231
- "decorated-set",
232
-
233
- "set",
234
-
235
- // Methods
236
- "public-static-method",
237
- "protected-static-method",
238
- "private-static-method",
239
- "#private-static-method",
240
-
241
- "public-decorated-method",
242
- "protected-decorated-method",
243
- "private-decorated-method",
244
-
245
- "public-instance-method",
246
- "protected-instance-method",
247
- "private-instance-method",
248
- "#private-instance-method",
249
-
250
- "public-abstract-method",
251
- "protected-abstract-method",
252
-
253
- "public-method",
254
- "protected-method",
255
- "private-method",
256
- "#private-method",
257
-
258
- "static-method",
259
- "instance-method",
260
- "abstract-method",
261
-
262
- "decorated-method",
263
-
264
- "method",
265
- ],
266
- },
267
- }
268
- ```
269
-
270
- :::note
271
- The default configuration contains member group types which contain other member types.
272
- This is intentional to provide better error messages.
273
- :::
274
-
275
- :::tip
276
- By default, the members are not sorted.
277
- If you want to sort them alphabetically, you have to provide a custom configuration.
278
- :::
279
-
280
- ## Examples
281
-
282
- ### General Order on All Constructs
283
-
284
- This config specifies the order for all constructs.
285
- It ignores member types other than signatures, methods, constructors, and fields.
286
- It also ignores accessibility and scope.
287
-
288
- ```jsonc
289
- // .eslintrc.json
290
- {
291
- "rules": {
292
- "@typescript-eslint/member-ordering": [
293
- "error",
294
- { "default": ["signature", "method", "constructor", "field"] },
295
- ],
296
- },
297
- }
298
- ```
299
-
300
- <Tabs>
301
- <TabItem value="❌ Incorrect">
302
-
303
- ```ts option='{ "default": ["signature", "method", "constructor", "field"] }'
304
- interface Foo {
305
- B: string; // -> field
306
-
307
- new (); // -> constructor
308
-
309
- A(): void; // -> method
310
-
311
- [Z: string]: any; // -> signature
312
- }
313
- ```
314
-
315
- ```ts option='{ "default": ["signature", "method", "constructor", "field"] }'
316
- type Foo = {
317
- B: string; // -> field
318
-
319
- // no constructor
320
-
321
- A(): void; // -> method
322
-
323
- // no signature
324
- };
325
- ```
326
-
327
- ```ts option='{ "default": ["signature", "method", "constructor", "field"] }'
328
- class Foo {
329
- private C: string; // -> field
330
- public D: string; // -> field
331
- protected static E: string; // -> field
332
-
333
- constructor() {} // -> constructor
334
-
335
- public static A(): void {} // -> method
336
- public B(): void {} // -> method
337
-
338
- [Z: string]: any; // -> signature
339
- }
340
- ```
341
-
342
- ```ts option='{ "default": ["signature", "method", "constructor", "field"] }'
343
- const Foo = class {
344
- private C: string; // -> field
345
- public D: string; // -> field
346
-
347
- constructor() {} // -> constructor
348
-
349
- public static A(): void {} // -> method
350
- public B(): void {} // -> method
351
-
352
- [Z: string]: any; // -> signature
353
-
354
- protected static E: string; // -> field
355
- };
356
- ```
357
-
358
- </TabItem>
359
- <TabItem value="✅ Correct">
360
-
361
- ```ts option='{ "default": ["signature", "method", "constructor", "field"] }'
362
- interface Foo {
363
- [Z: string]: any; // -> signature
364
-
365
- A(): void; // -> method
366
-
367
- new (); // -> constructor
368
-
369
- B: string; // -> field
370
- }
371
- ```
372
-
373
- ```ts option='{ "default": ["signature", "method", "constructor", "field"] }'
374
- type Foo = {
375
- // no signature
376
-
377
- A(): void; // -> method
378
-
379
- // no constructor
380
-
381
- B: string; // -> field
382
- };
383
- ```
384
-
385
- ```ts option='{ "default": ["signature", "method", "constructor", "field"] }'
386
- class Foo {
387
- [Z: string]: any; // -> signature
388
-
389
- public static A(): void {} // -> method
390
- public B(): void {} // -> method
391
-
392
- constructor() {} // -> constructor
393
-
394
- private C: string; // -> field
395
- public D: string; // -> field
396
- protected static E: string; // -> field
397
- }
398
- ```
399
-
400
- ```ts option='{ "default": ["signature", "method", "constructor", "field"] }'
401
- const Foo = class {
402
- [Z: string]: any; // -> signature
403
-
404
- public static A(): void {} // -> method
405
- public B(): void {} // -> method
406
-
407
- constructor() {} // -> constructor
408
-
409
- private C: string; // -> field
410
- public D: string; // -> field
411
- protected static E: string; // -> field
412
- };
413
- ```
414
-
415
- </TabItem>
416
- </Tabs>
417
-
418
- ### Classes
419
-
420
- #### Public Instance Methods Before Public Static Fields
421
-
422
- This config specifies that public instance methods should come first before public static fields.
423
- Everything else can be placed anywhere.
424
- It doesn't apply to interfaces or type literals as accessibility and scope are not part of them.
425
-
426
- ```jsonc
427
- // .eslintrc.json
428
- {
429
- "rules": {
430
- "@typescript-eslint/member-ordering": [
431
- "error",
432
- { "default": ["public-instance-method", "public-static-field"] },
433
- ],
434
- },
435
- }
436
- ```
437
-
438
- <Tabs>
439
- <TabItem value="❌ Incorrect">
440
-
441
- ```ts option='{ "default": ["public-instance-method", "public-static-field"] }'
442
- class Foo {
443
- private C: string; // (irrelevant)
444
-
445
- public D: string; // (irrelevant)
446
-
447
- public static E: string; // -> public static field
448
-
449
- constructor() {} // (irrelevant)
450
-
451
- public static A(): void {} // (irrelevant)
452
-
453
- [Z: string]: any; // (irrelevant)
454
-
455
- public B(): void {} // -> public instance method
456
- }
457
- ```
458
-
459
- ```ts option='{ "default": ["public-instance-method", "public-static-field"] }'
460
- const Foo = class {
461
- private C: string; // (irrelevant)
462
-
463
- [Z: string]: any; // (irrelevant)
464
-
465
- public static E: string; // -> public static field
466
-
467
- public D: string; // (irrelevant)
468
-
469
- constructor() {} // (irrelevant)
470
-
471
- public static A(): void {} // (irrelevant)
472
-
473
- public B(): void {} // -> public instance method
474
- };
475
- ```
476
-
477
- </TabItem>
478
- <TabItem value="✅ Correct">
479
-
480
- ```ts option='{ "default": ["public-instance-method", "public-static-field"] }'
481
- class Foo {
482
- public B(): void {} // -> public instance method
483
-
484
- private C: string; // (irrelevant)
485
-
486
- public D: string; // (irrelevant)
487
-
488
- public static E: string; // -> public static field
489
-
490
- constructor() {} // (irrelevant)
491
-
492
- public static A(): void {} // (irrelevant)
493
-
494
- [Z: string]: any; // (irrelevant)
495
- }
496
- ```
497
-
498
- ```ts option='{ "default": ["public-instance-method", "public-static-field"] }'
499
- const Foo = class {
500
- public B(): void {} // -> public instance method
501
-
502
- private C: string; // (irrelevant)
503
-
504
- [Z: string]: any; // (irrelevant)
505
-
506
- public D: string; // (irrelevant)
507
-
508
- constructor() {} // (irrelevant)
509
-
510
- public static A(): void {} // (irrelevant)
511
-
512
- public static E: string; // -> public static field
513
- };
514
- ```
515
-
516
- </TabItem>
517
- </Tabs>
518
-
519
- #### Static Fields Before Instance Fields
520
-
521
- This config specifies that static fields should come before instance fields, with public static fields first.
522
- It doesn't apply to interfaces or type literals as accessibility and scope are not part of them.
523
-
524
- ```jsonc
525
- {
526
- "rules": {
527
- "@typescript-eslint/member-ordering": [
528
- "error",
529
- { "default": ["public-static-field", "static-field", "instance-field"] },
530
- ],
531
- },
532
- }
533
- ```
534
-
535
- <Tabs>
536
- <TabItem value="❌ Incorrect">
537
-
538
- ```ts option='{ "default": ["public-static-field", "static-field", "instance-field"] }'
539
- class Foo {
540
- private E: string; // -> instance field
541
-
542
- private static B: string; // -> static field
543
- protected static C: string; // -> static field
544
- private static D: string; // -> static field
545
-
546
- public static A: string; // -> public static field
547
-
548
- [Z: string]: any; // (irrelevant)
549
- }
550
- ```
551
-
552
- ```ts option='{ "default": ["public-static-field", "static-field", "instance-field"] }'
553
- const foo = class {
554
- public T(): void {} // method (irrelevant)
555
-
556
- private static B: string; // -> static field
557
-
558
- constructor() {} // constructor (irrelevant)
559
-
560
- private E: string; // -> instance field
561
-
562
- protected static C: string; // -> static field
563
- private static D: string; // -> static field
564
-
565
- [Z: string]: any; // signature (irrelevant)
566
-
567
- public static A: string; // -> public static field
568
- };
569
- ```
570
-
571
- </TabItem>
572
- <TabItem value="✅ Correct">
573
-
574
- ```ts option='{ "default": ["public-static-field", "static-field", "instance-field"] }'
575
- class Foo {
576
- public static A: string; // -> public static field
577
-
578
- private static B: string; // -> static field
579
- protected static C: string; // -> static field
580
- private static D: string; // -> static field
581
-
582
- private E: string; // -> instance field
583
-
584
- [Z: string]: any; // (irrelevant)
585
- }
586
- ```
587
-
588
- ```ts option='{ "default": ["public-static-field", "static-field", "instance-field"] }'
589
- const foo = class {
590
- [Z: string]: any; // -> signature (irrelevant)
591
-
592
- public static A: string; // -> public static field
593
-
594
- constructor() {} // -> constructor (irrelevant)
595
-
596
- private static B: string; // -> static field
597
- protected static C: string; // -> static field
598
- private static D: string; // -> static field
599
-
600
- private E: string; // -> instance field
601
-
602
- public T(): void {} // -> method (irrelevant)
603
- };
604
- ```
605
-
606
- </TabItem>
607
- </Tabs>
608
-
609
- #### Class Declarations
610
-
611
- This config only specifies an order for classes: methods, then the constructor, then fields.
612
- It does not apply to class expressions (use `classExpressions` for them).
613
- Default settings will be used for class declarations and all other syntax constructs other than class declarations.
614
-
615
- ```jsonc
616
- // .eslintrc.json
617
- {
618
- "rules": {
619
- "@typescript-eslint/member-ordering": [
620
- "error",
621
- { "classes": ["method", "constructor", "field"] },
622
- ],
623
- },
624
- }
625
- ```
626
-
627
- <Tabs>
628
- <TabItem value="❌ Incorrect">
629
-
630
- ```ts option='{ "classes": ["method", "constructor", "field"] }'
631
- class Foo {
632
- private C: string; // -> field
633
- public D: string; // -> field
634
- protected static E: string; // -> field
635
-
636
- constructor() {} // -> constructor
637
-
638
- public static A(): void {} // -> method
639
- public B(): void {} // -> method
640
- }
641
- ```
642
-
643
- </TabItem>
644
- <TabItem value="✅ Correct">
645
-
646
- ```ts option='{ "classes": ["method", "constructor", "field"] }'
647
- class Foo {
648
- public static A(): void {} // -> method
649
- public B(): void {} // -> method
650
-
651
- constructor() {} // -> constructor
652
-
653
- private C: string; // -> field
654
- public D: string; // -> field
655
- protected static E: string; // -> field
656
- }
657
- ```
658
-
659
- </TabItem>
660
- </Tabs>
661
-
662
- #### Class Expressions
663
-
664
- This config only specifies an order for classes expressions: methods, then the constructor, then fields.
665
- It does not apply to class declarations (use `classes` for them).
666
- Default settings will be used for class declarations and all other syntax constructs other than class expressions.
667
-
668
- ```jsonc
669
- // .eslintrc.json
670
- {
671
- "rules": {
672
- "@typescript-eslint/member-ordering": [
673
- "error",
674
- { "classExpressions": ["method", "constructor", "field"] },
675
- ],
676
- },
677
- }
678
- ```
679
-
680
- <Tabs>
681
- <TabItem value="❌ Incorrect">
682
-
683
- ```ts option='{ "classExpressions": ["method", "constructor", "field"] }'
684
- const foo = class {
685
- private C: string; // -> field
686
- public D: string; // -> field
687
- protected static E: string; // -> field
688
-
689
- constructor() {} // -> constructor
690
-
691
- public static A(): void {} // -> method
692
- public B(): void {} // -> method
693
- };
694
- ```
695
-
696
- </TabItem>
697
- <TabItem value="✅ Correct">
698
-
699
- ```ts option='{ "classExpressions": ["method", "constructor", "field"] }'
700
- const foo = class {
701
- public static A(): void {} // -> method
702
- public B(): void {} // -> method
703
-
704
- constructor() {} // -> constructor
705
-
706
- private C: string; // -> field
707
- public D: string; // -> field
708
- protected static E: string; // -> field
709
- };
710
- ```
711
-
712
- </TabItem>
713
- </Tabs>
714
-
715
- ### Interfaces
716
-
717
- This config only specifies an order for interfaces: signatures, then methods, then constructors, then fields.
718
- It does not apply to type literals (use `typeLiterals` for them).
719
- Default settings will be used for type literals and all other syntax constructs other than class expressions.
720
-
721
- :::note
722
- These member types are the only ones allowed for `interfaces`.
723
- :::
724
-
725
- ```jsonc
726
- // .eslintrc.json
727
- {
728
- "rules": {
729
- "@typescript-eslint/member-ordering": [
730
- "error",
731
- { "interfaces": ["signature", "method", "constructor", "field"] },
732
- ],
733
- },
734
- }
735
- ```
736
-
737
- <Tabs>
738
- <TabItem value="❌ Incorrect">
739
-
740
- ```ts option='{ "interfaces": ["signature", "method", "constructor", "field"] }'
741
- interface Foo {
742
- B: string; // -> field
743
-
744
- new (); // -> constructor
745
-
746
- A(): void; // -> method
747
-
748
- [Z: string]: any; // -> signature
749
- }
750
- ```
751
-
752
- </TabItem>
753
- <TabItem value="✅ Correct">
754
-
755
- ```ts option='{ "interfaces": ["signature", "method", "constructor", "field"] }'
756
- interface Foo {
757
- [Z: string]: any; // -> signature
758
-
759
- A(): void; // -> method
760
-
761
- new (); // -> constructor
762
-
763
- B: string; // -> field
764
- }
765
- ```
766
-
767
- </TabItem>
768
- </Tabs>
769
-
770
- ### Type Literals
771
-
772
- This config only specifies an order for type literals: signatures, then methods, then constructors, then fields.
773
- It does not apply to interfaces (use `interfaces` for them).
774
- Default settings will be used for interfaces and all other syntax constructs other than class expressions.
775
-
776
- :::note
777
- These member types are the only ones allowed for `typeLiterals`.
778
- :::
779
-
780
- ```jsonc
781
- // .eslintrc.json
782
- {
783
- "rules": {
784
- "@typescript-eslint/member-ordering": [
785
- "error",
786
- { "typeLiterals": ["signature", "method", "constructor", "field"] },
787
- ],
788
- },
789
- }
790
- ```
791
-
792
- <Tabs>
793
- <TabItem value="❌ Incorrect">
794
-
795
- ```ts option='{ "typeLiterals": ["signature", "method", "constructor", "field"] }'
796
- type Foo = {
797
- B: string; // -> field
798
-
799
- A(): void; // -> method
800
-
801
- new (); // -> constructor
802
-
803
- [Z: string]: any; // -> signature
804
- };
805
- ```
806
-
807
- </TabItem>
808
- <TabItem value="✅ Correct">
809
-
810
- ```ts option='{ "typeLiterals": ["signature", "method", "constructor", "field"] }'
811
- type Foo = {
812
- [Z: string]: any; // -> signature
813
-
814
- A(): void; // -> method
815
-
816
- new (); // -> constructor
817
-
818
- B: string; // -> field
819
- };
820
- ```
821
-
822
- </TabItem>
823
- </Tabs>
824
-
825
- ### Sorting Options
826
-
827
- #### Sorting Alphabetically Within Member Groups
828
-
829
- The default member order will be applied if `memberTypes` is not specified.
830
- You can see the default order in [Default Configuration](#default-configuration).
831
-
832
- ```jsonc
833
- // .eslintrc.json
834
- {
835
- "rules": {
836
- "@typescript-eslint/member-ordering": [
837
- "error",
838
- {
839
- "default": {
840
- "order": "alphabetically",
841
- },
842
- },
843
- ],
844
- },
845
- }
846
- ```
847
-
848
- <Tabs>
849
- <TabItem value="❌ Incorrect">
850
-
851
- ```ts option='{"default":{"order":"alphabetically"}}'
852
- interface Foo {
853
- a: x;
854
- B: x;
855
- c: x;
856
-
857
- B(): void;
858
- c(): void;
859
- a(): void;
860
- }
861
- ```
862
-
863
- </TabItem>
864
- <TabItem value="✅ Correct">
865
-
866
- ```ts option='{"default":{"order":"alphabetically"}}'
867
- interface Foo {
868
- B: x;
869
- a: x;
870
- c: x;
871
-
872
- B(): void;
873
- a(): void;
874
- c(): void;
875
- }
876
- ```
877
-
878
- </TabItem>
879
- </Tabs>
880
-
881
- #### Sorting Alphabetically Within Custom Member Groups
882
-
883
- This config specifies that within each custom `memberTypes` group, members are in an alphabetic case-sensitive order.
884
-
885
- ```jsonc
886
- // .eslintrc.json
887
- {
888
- "rules": {
889
- "@typescript-eslint/member-ordering": [
890
- "error",
891
- {
892
- "default": {
893
- "memberTypes": ["method", "field"],
894
- "order": "alphabetically",
895
- },
896
- },
897
- ],
898
- },
899
- }
900
- ```
901
-
902
- <Tabs>
903
- <TabItem value="❌ Incorrect">
904
-
905
- ```ts option='{"default":{"memberTypes":["method","field"],"order":"alphabetically"}}'
906
- interface Foo {
907
- B(): void;
908
- c(): void;
909
- a(): void;
910
-
911
- a: x;
912
- B: x;
913
- c: x;
914
- }
915
- ```
916
-
917
- </TabItem>
918
- <TabItem value="✅ Correct">
919
-
920
- ```ts option='{"default":{"memberTypes":["method","field"],"order":"alphabetically"}}'
921
- interface Foo {
922
- B(): void;
923
- a(): void;
924
- c(): void;
925
-
926
- B: x;
927
- a: x;
928
- c: x;
929
- }
930
- ```
931
-
932
- </TabItem>
933
- </Tabs>
934
-
935
- #### Sorting Alphabetically Case Insensitive Within Member Groups
936
-
937
- The default member order will be applied if `memberTypes` is not specified.
938
- You can see the default order in [Default Configuration](#default-configuration).
939
-
940
- ```jsonc
941
- // .eslintrc.json
942
- {
943
- "rules": {
944
- "@typescript-eslint/member-ordering": [
945
- "error",
946
- {
947
- "default": {
948
- "order": "alphabetically-case-insensitive",
949
- },
950
- },
951
- ],
952
- },
953
- }
954
- ```
955
-
956
- <Tabs>
957
- <TabItem value="❌ Incorrect">
958
-
959
- ```ts option='{"default":{"order":"alphabetically-case-insensitive"}}'
960
- interface Foo {
961
- B: x;
962
- a: x;
963
- c: x;
964
-
965
- B(): void;
966
- c(): void;
967
- a(): void;
968
- }
969
- ```
970
-
971
- </TabItem>
972
- <TabItem value="✅ Correct">
973
-
974
- ```ts option='{"default":{"order":"alphabetically-case-insensitive"}}'
975
- interface Foo {
976
- a: x;
977
- B: x;
978
- c: x;
979
-
980
- a(): void;
981
- B(): void;
982
- c(): void;
983
- }
984
- ```
985
-
986
- </TabItem>
987
- </Tabs>
988
-
989
- #### Sorting Alphabetically Ignoring Member Groups
990
-
991
- This config specifies that members are all sorted in an alphabetic case-sensitive order.
992
- It ignores any member group types completely by specifying `"never"` for `memberTypes`.
993
-
994
- ```jsonc
995
- // .eslintrc.json
996
- {
997
- "rules": {
998
- "@typescript-eslint/member-ordering": [
999
- "error",
1000
- { "default": { "memberTypes": "never", "order": "alphabetically" } },
1001
- ],
1002
- },
1003
- }
1004
- ```
1005
-
1006
- <Tabs>
1007
- <TabItem value="❌ Incorrect">
1008
-
1009
- ```ts option='{ "default": { "memberTypes": "never", "order": "alphabetically" } }'
1010
- interface Foo {
1011
- b(): void;
1012
- a: boolean;
1013
-
1014
- [a: string]: number;
1015
- new (): Bar;
1016
- (): Baz;
1017
- }
1018
- ```
1019
-
1020
- </TabItem>
1021
- <TabItem value="✅ Correct">
1022
-
1023
- ```ts option='{ "default": { "memberTypes": "never", "order": "alphabetically" } }'
1024
- interface Foo {
1025
- [a: string]: number;
1026
- a: boolean;
1027
- b(): void;
1028
-
1029
- (): Baz;
1030
- new (): Bar;
1031
- }
1032
- ```
1033
-
1034
- </TabItem>
1035
- </Tabs>
1036
-
1037
- #### Sorting Optional Members First or Last
1038
-
1039
- The `optionalityOrder` option may be enabled to place all optional members in a group at the beginning or end of that group.
1040
-
1041
- This config places all optional members before all required members:
1042
-
1043
- ```jsonc
1044
- // .eslintrc.json
1045
- {
1046
- "rules": {
1047
- "@typescript-eslint/member-ordering": [
1048
- "error",
1049
- {
1050
- "default": {
1051
- "optionalityOrder": "optional-first",
1052
- "order": "alphabetically",
1053
- },
1054
- },
1055
- ],
1056
- },
1057
- }
1058
- ```
1059
-
1060
- <Tabs>
1061
- <TabItem value="❌ Incorrect">
1062
-
1063
- ```ts option='{ "default": { "optionalityOrder": "optional-first", "order": "alphabetically" } }'
1064
- interface Foo {
1065
- a: boolean;
1066
- b?: number;
1067
- c: string;
1068
- }
1069
- ```
1070
-
1071
- </TabItem>
1072
- <TabItem value="✅ Correct">
1073
-
1074
- ```ts option='{ "default": { "optionalityOrder": "optional-first", "order": "alphabetically" } }'
1075
- interface Foo {
1076
- b?: number;
1077
- a: boolean;
1078
- c: string;
1079
- }
1080
- ```
1081
-
1082
- </TabItem>
1083
- </Tabs>
1084
-
1085
- This config places all required members before all optional members:
1086
-
1087
- ```jsonc
1088
- // .eslintrc.json
1089
- {
1090
- "rules": {
1091
- "@typescript-eslint/member-ordering": [
1092
- "error",
1093
- {
1094
- "default": {
1095
- "optionalityOrder": "required-first",
1096
- "order": "alphabetically",
1097
- },
1098
- },
1099
- ],
1100
- },
1101
- }
1102
- ```
1103
-
1104
- <Tabs>
1105
- <TabItem value="❌ Incorrect">
1106
-
1107
- ```ts option='{ "default": { "optionalityOrder": "required-first", "order": "alphabetically" } }'
1108
- interface Foo {
1109
- a: boolean;
1110
- b?: number;
1111
- c: string;
1112
- }
1113
- ```
1114
-
1115
- </TabItem>
1116
- <TabItem value="✅ Correct">
1117
-
1118
- ```ts option='{ "default": { "optionalityOrder": "required-first", "order": "alphabetically" } }'
1119
- interface Foo {
1120
- a: boolean;
1121
- c: string;
1122
- b?: number;
1123
- }
1124
- ```
1125
-
1126
- </TabItem>
1127
- </Tabs>
1128
-
1129
- ## All Supported Options
1130
-
1131
- ### Member Types (Granular Form)
1132
-
1133
- There are multiple ways to specify the member types.
1134
- The most explicit and granular form is the following:
1135
-
1136
- ```jsonc
1137
- [
1138
- // Index signature
1139
- "signature",
1140
- "readonly-signature",
1141
-
1142
- // Fields
1143
- "public-static-field",
1144
- "public-static-readonly-field",
1145
- "protected-static-field",
1146
- "protected-static-readonly-field",
1147
- "private-static-field",
1148
- "private-static-readonly-field",
1149
- "#private-static-field",
1150
- "#private-static-readonly-field",
1151
-
1152
- "public-decorated-field",
1153
- "public-decorated-readonly-field",
1154
- "protected-decorated-field",
1155
- "protected-decorated-readonly-field",
1156
- "private-decorated-field",
1157
- "private-decorated-readonly-field",
1158
-
1159
- "public-instance-field",
1160
- "public-instance-readonly-field",
1161
- "protected-instance-field",
1162
- "protected-instance-readonly-field",
1163
- "private-instance-field",
1164
- "private-instance-readonly-field",
1165
- "#private-instance-field",
1166
- "#private-instance-readonly-field",
1167
-
1168
- "public-abstract-field",
1169
- "public-abstract-readonly-field",
1170
- "protected-abstract-field",
1171
- "protected-abstract-readonly-field",
1172
-
1173
- "public-field",
1174
- "public-readonly-field",
1175
- "protected-field",
1176
- "protected-readonly-field",
1177
- "private-field",
1178
- "private-readonly-field"
1179
- "#private-field",
1180
- "#private-readonly-field"
1181
-
1182
- "static-field",
1183
- "static-readonly-field",
1184
- "instance-field",
1185
- "instance-readonly-field"
1186
- "abstract-field",
1187
- "abstract-readonly-field",
1188
-
1189
- "decorated-field",
1190
- "decorated-readonly-field",
1191
-
1192
- "field",
1193
- "readonly-field",
1194
-
1195
- // Static initialization
1196
- "static-initialization",
1197
-
1198
- // Constructors
1199
- "public-constructor",
1200
- "protected-constructor",
1201
- "private-constructor",
1202
-
1203
- // Getters
1204
- "public-static-get",
1205
- "protected-static-get",
1206
- "private-static-get",
1207
- "#private-static-get",
1208
-
1209
- "public-decorated-get",
1210
- "protected-decorated-get",
1211
- "private-decorated-get",
1212
-
1213
- "public-instance-get",
1214
- "protected-instance-get",
1215
- "private-instance-get",
1216
- "#private-instance-get",
1217
-
1218
- "public-abstract-get",
1219
- "protected-abstract-get",
1220
-
1221
- "public-get",
1222
- "protected-get",
1223
- "private-get",
1224
- "#private-get",
1225
-
1226
- "static-get",
1227
- "instance-get",
1228
- "abstract-get",
1229
-
1230
- "decorated-get",
1231
-
1232
- "get",
1233
-
1234
- // Setters
1235
- "public-static-set",
1236
- "protected-static-set",
1237
- "private-static-set",
1238
- "#private-static-set",
1239
-
1240
- "public-decorated-set",
1241
- "protected-decorated-set",
1242
- "private-decorated-set",
1243
-
1244
- "public-instance-set",
1245
- "protected-instance-set",
1246
- "private-instance-set",
1247
- "#private-instance-set",
1248
-
1249
- "public-abstract-set",
1250
- "protected-abstract-set",
1251
-
1252
- "public-set",
1253
- "protected-set",
1254
- "private-set",
1255
-
1256
- "static-set",
1257
- "instance-set",
1258
- "abstract-set",
1259
-
1260
- "decorated-set",
1261
-
1262
- "set",
1263
-
1264
- // Methods
1265
- "public-static-method",
1266
- "protected-static-method",
1267
- "private-static-method",
1268
- "#private-static-method",
1269
- "public-decorated-method",
1270
- "protected-decorated-method",
1271
- "private-decorated-method",
1272
- "public-instance-method",
1273
- "protected-instance-method",
1274
- "private-instance-method",
1275
- "#private-instance-method",
1276
- "public-abstract-method",
1277
- "protected-abstract-method"
1278
- ]
1279
- ```
1280
-
1281
- :::note
1282
- If you only specify some of the possible types, the non-specified ones can have any particular order.
1283
- This means that they can be placed before, within or after the specified types and the linter won't complain about it.
1284
- :::
1285
-
1286
- ### Member Group Types (With Accessibility, Ignoring Scope)
1287
-
1288
- It is also possible to group member types by their accessibility (`static`, `instance`, `abstract`), ignoring their scope.
1289
-
1290
- ```jsonc
1291
- [
1292
- // Index signature
1293
- // No accessibility for index signature.
1294
-
1295
- // Fields
1296
- "public-field", // = ["public-static-field", "public-instance-field"]
1297
- "protected-field", // = ["protected-static-field", "protected-instance-field"]
1298
- "private-field", // = ["private-static-field", "private-instance-field"]
1299
-
1300
- // Static initialization
1301
- // No accessibility for static initialization.
1302
-
1303
- // Constructors
1304
- // Only the accessibility of constructors is configurable. See below.
1305
-
1306
- // Getters
1307
- "public-get", // = ["public-static-get", "public-instance-get"]
1308
- "protected-get", // = ["protected-static-get", "protected-instance-get"]
1309
- "private-get", // = ["private-static-get", "private-instance-get"]
1310
-
1311
- // Setters
1312
- "public-set", // = ["public-static-set", "public-instance-set"]
1313
- "protected-set", // = ["protected-static-set", "protected-instance-set"]
1314
- "private-set", // = ["private-static-set", "private-instance-set"]
1315
-
1316
- // Methods
1317
- "public-method", // = ["public-static-method", "public-instance-method"]
1318
- "protected-method", // = ["protected-static-method", "protected-instance-method"]
1319
- "private-method", // = ["private-static-method", "private-instance-method"]
1320
- ]
1321
- ```
1322
-
1323
- ### Member Group Types (With Accessibility and a Decorator)
1324
-
1325
- It is also possible to group methods or fields with a decorator separately, optionally specifying
1326
- their accessibility.
1327
-
1328
- ```jsonc
1329
- [
1330
- // Index signature
1331
- // No decorators for index signature.
1332
-
1333
- // Fields
1334
- "public-decorated-field",
1335
- "protected-decorated-field",
1336
- "private-decorated-field",
1337
-
1338
- "decorated-field", // = ["public-decorated-field", "protected-decorated-field", "private-decorated-field"]
1339
-
1340
- // Static initialization
1341
- // No decorators for static initialization.
1342
-
1343
- // Constructors
1344
- // There are no decorators for constructors.
1345
-
1346
- // Getters
1347
- "public-decorated-get",
1348
- "protected-decorated-get",
1349
- "private-decorated-get",
1350
-
1351
- "decorated-get", // = ["public-decorated-get", "protected-decorated-get", "private-decorated-get"]
1352
-
1353
- // Setters
1354
- "public-decorated-set",
1355
- "protected-decorated-set",
1356
- "private-decorated-set",
1357
-
1358
- "decorated-set", // = ["public-decorated-set", "protected-decorated-set", "private-decorated-set"]
1359
-
1360
- // Methods
1361
- "public-decorated-method",
1362
- "protected-decorated-method",
1363
- "private-decorated-method",
1364
-
1365
- "decorated-method", // = ["public-decorated-method", "protected-decorated-method", "private-decorated-method"]
1366
- ]
1367
- ```
1368
-
1369
- ### Member Group Types (With Scope, Ignoring Accessibility)
1370
-
1371
- Another option is to group the member types by their scope (`public`, `protected`, `private`), ignoring their accessibility.
1372
-
1373
- ```jsonc
1374
- [
1375
- // Index signature
1376
- // No scope for index signature.
1377
-
1378
- // Fields
1379
- "static-field", // = ["public-static-field", "protected-static-field", "private-static-field"]
1380
- "instance-field", // = ["public-instance-field", "protected-instance-field", "private-instance-field"]
1381
- "abstract-field", // = ["public-abstract-field", "protected-abstract-field"]
1382
-
1383
- // Static initialization
1384
- // No scope for static initialization.
1385
-
1386
- // Constructors
1387
- "constructor", // = ["public-constructor", "protected-constructor", "private-constructor"]
1388
-
1389
- // Getters
1390
- "static-get", // = ["public-static-get", "protected-static-get", "private-static-get"]
1391
- "instance-get", // = ["public-instance-get", "protected-instance-get", "private-instance-get"]
1392
- "abstract-get", // = ["public-abstract-get", "protected-abstract-get"]
1393
-
1394
- // Setters
1395
- "static-set", // = ["public-static-set", "protected-static-set", "private-static-set"]
1396
- "instance-set", // = ["public-instance-set", "protected-instance-set", "private-instance-set"]
1397
- "abstract-set", // = ["public-abstract-set", "protected-abstract-set"]
1398
-
1399
- // Methods
1400
- "static-method", // = ["public-static-method", "protected-static-method", "private-static-method"]
1401
- "instance-method", // = ["public-instance-method", "protected-instance-method", "private-instance-method"]
1402
- "abstract-method", // = ["public-abstract-method", "protected-abstract-method"]
1403
- ]
1404
- ```
1405
-
1406
- ### Member Group Types (With Scope and Accessibility)
1407
-
1408
- The third grouping option is to ignore both scope and accessibility.
1409
-
1410
- ```jsonc
1411
- [
1412
- // Index signature
1413
- // No grouping for index signature.
1414
-
1415
- // Fields
1416
- "field", // = ["public-static-field", "protected-static-field", "private-static-field", "public-instance-field", "protected-instance-field", "private-instance-field",
1417
- // "public-abstract-field", "protected-abstract-field"]
1418
-
1419
- // Static initialization
1420
- // No grouping for static initialization.
1421
-
1422
- // Constructors
1423
- // Only the accessibility of constructors is configurable.
1424
-
1425
- // Getters
1426
- "get", // = ["public-static-get", "protected-static-get", "private-static-get", "public-instance-get", "protected-instance-get", "private-instance-get",
1427
- // "public-abstract-get", "protected-abstract-get"]
1428
-
1429
- // Setters
1430
- "set", // = ["public-static-set", "protected-static-set", "private-static-set", "public-instance-set", "protected-instance-set", "private-instance-set",
1431
- // "public-abstract-set", "protected-abstract-set"]
1432
-
1433
- // Methods
1434
- "method", // = ["public-static-method", "protected-static-method", "private-static-method", "public-instance-method", "protected-instance-method", "private-instance-method",
1435
- // "public-abstract-method", "protected-abstract-method"]
1436
- ]
1437
- ```
1438
-
1439
- ### Member Group Types (Readonly Fields)
1440
-
1441
- It is possible to group fields by their `readonly` modifiers.
1442
-
1443
- ```jsonc
1444
- [
1445
- // Index signature
1446
- "readonly-signature",
1447
- "signature",
1448
-
1449
- // Fields
1450
- "readonly-field", // = ["public-static-readonly-field", "protected-static-readonly-field", "private-static-readonly-field", "public-instance-readonly-field", "protected-instance-readonly-field", "private-instance-readonly-field", "public-abstract-readonly-field", "protected-abstract-readonly-field"]
1451
- "field", // = ["public-static-field", "protected-static-field", "private-static-field", "public-instance-field", "protected-instance-field", "private-instance-field", "public-abstract-field", "protected-abstract-field"]
1452
- ]
1453
- ```
1454
-
1455
- ### Grouping Different Member Types at the Same Rank
1456
-
1457
- It is also possible to group different member types at the same rank.
1458
-
1459
- ```jsonc
1460
- [
1461
- // Index signature
1462
- "signature",
1463
-
1464
- // Fields
1465
- "field",
1466
-
1467
- // Static initialization
1468
- "static-initialization",
1469
-
1470
- // Constructors
1471
- "constructor",
1472
-
1473
- // Getters and Setters at the same rank
1474
- ["get", "set"],
1475
-
1476
- // Methods
1477
- "method",
1478
- ]
1479
- ```
1480
-
1481
- ## When Not To Use It
1482
-
1483
- If you don't care about the general order of your members, then you will not need this rule.