@@ -9,19 +9,30 @@ export type MessageIds =
9
9
| 'incorrectOrder'
10
10
| 'incorrectRequiredMembersOrder' ;
11
11
12
+ type ReadonlyType = 'readonly-field' | 'readonly-signature' ;
13
+
12
14
type MemberKind =
13
15
| 'call-signature'
14
16
| 'constructor'
17
+ | ReadonlyType
15
18
| 'field'
16
19
| 'get'
17
20
| 'method'
18
21
| 'set'
19
22
| 'signature'
20
23
| 'static-initialization' ;
21
24
22
- type DecoratedMemberKind = 'field' | 'method' | 'get' | 'set' ;
25
+ type DecoratedMemberKind =
26
+ | Exclude < ReadonlyType , 'readonly-signature' >
27
+ | 'field'
28
+ | 'method'
29
+ | 'get'
30
+ | 'set' ;
23
31
24
- type NonCallableMemberKind = Exclude < MemberKind , 'constructor' | 'signature' > ;
32
+ type NonCallableMemberKind = Exclude <
33
+ MemberKind ,
34
+ 'constructor' | 'signature' | 'readonly-signature'
35
+ > ;
25
36
26
37
type MemberScope = 'static' | 'instance' | 'abstract' ;
27
38
@@ -31,7 +42,7 @@ type BaseMemberType =
31
42
| MemberKind
32
43
| `${Accessibility } -${Exclude <
33
44
MemberKind ,
34
- 'signature' | 'static-initialization'
45
+ 'signature' | 'readonly-signature' | ' static-initialization'
35
46
> } `
36
47
| `${Accessibility } -decorated-${DecoratedMemberKind } `
37
48
| `decorated-${DecoratedMemberKind } `
@@ -258,7 +269,9 @@ export const defaultOrder: MemberType[] = [
258
269
const allMemberTypes = Array . from (
259
270
(
260
271
[
272
+ 'readonly-signature' ,
261
273
'signature' ,
274
+ 'readonly-field' ,
262
275
'field' ,
263
276
'method' ,
264
277
'call-signature' ,
@@ -273,6 +286,7 @@ const allMemberTypes = Array.from(
273
286
( [ 'public' , 'protected' , 'private' , '#private' ] as const ) . forEach (
274
287
accessibility => {
275
288
if (
289
+ type !== 'readonly-signature' &&
276
290
type !== 'signature' &&
277
291
type !== 'static-initialization' &&
278
292
type !== 'call-signature' &&
@@ -284,7 +298,8 @@ const allMemberTypes = Array.from(
284
298
// Only class instance fields, methods, get and set can have decorators attached to them
285
299
if (
286
300
accessibility !== '#private' &&
287
- ( type === 'field' ||
301
+ ( type === 'readonly-field' ||
302
+ type === 'field' ||
288
303
type === 'method' ||
289
304
type === 'get' ||
290
305
type === 'set' )
@@ -295,6 +310,7 @@ const allMemberTypes = Array.from(
295
310
296
311
if (
297
312
type !== 'constructor' &&
313
+ type !== 'readonly-signature' &&
298
314
type !== 'signature' &&
299
315
type !== 'call-signature'
300
316
) {
@@ -340,15 +356,17 @@ function getNodeType(node: Member): MemberKind | null {
340
356
case AST_NODE_TYPES . TSConstructSignatureDeclaration :
341
357
return 'constructor' ;
342
358
case AST_NODE_TYPES . TSAbstractPropertyDefinition :
343
- return 'field' ;
359
+ return node . readonly ? 'readonly-field' : 'field' ;
344
360
case AST_NODE_TYPES . PropertyDefinition :
345
361
return node . value && functionExpressions . includes ( node . value . type )
346
362
? 'method'
363
+ : node . readonly
364
+ ? 'readonly-field'
347
365
: 'field' ;
348
366
case AST_NODE_TYPES . TSPropertySignature :
349
- return 'field' ;
367
+ return node . readonly ? 'readonly-field' : 'field' ;
350
368
case AST_NODE_TYPES . TSIndexSignature :
351
- return 'signature' ;
369
+ return node . readonly ? 'readonly-signature' : 'signature' ;
352
370
case AST_NODE_TYPES . StaticBlock :
353
371
return 'static-initialization' ;
354
372
default :
@@ -514,27 +532,50 @@ function getRank(
514
532
const decorated = 'decorators' in node && node . decorators ! . length > 0 ;
515
533
if (
516
534
decorated &&
517
- ( type === 'field' ||
535
+ ( type === 'readonly-field' ||
536
+ type === 'field' ||
518
537
type === 'method' ||
519
538
type === 'get' ||
520
539
type === 'set' )
521
540
) {
522
541
memberGroups . push ( `${ accessibility } -decorated-${ type } ` ) ;
523
542
memberGroups . push ( `decorated-${ type } ` ) ;
543
+
544
+ if ( type === 'readonly-field' ) {
545
+ memberGroups . push ( `${ accessibility } -decorated-field` ) ;
546
+ memberGroups . push ( `decorated-field` ) ;
547
+ }
524
548
}
525
549
526
- if ( type !== 'signature' && type !== 'static-initialization' ) {
550
+ if (
551
+ type !== 'readonly-signature' &&
552
+ type !== 'signature' &&
553
+ type !== 'static-initialization'
554
+ ) {
527
555
if ( type !== 'constructor' ) {
528
556
// Constructors have no scope
529
557
memberGroups . push ( `${ accessibility } -${ scope } -${ type } ` ) ;
530
558
memberGroups . push ( `${ scope } -${ type } ` ) ;
559
+
560
+ if ( type === 'readonly-field' ) {
561
+ memberGroups . push ( `${ accessibility } -${ scope } -field` ) ;
562
+ memberGroups . push ( `${ scope } -field` ) ;
563
+ }
531
564
}
532
565
533
566
memberGroups . push ( `${ accessibility } -${ type } ` ) ;
567
+ if ( type === 'readonly-field' ) {
568
+ memberGroups . push ( `${ accessibility } -field` ) ;
569
+ }
534
570
}
535
571
}
536
572
537
573
memberGroups . push ( type ) ;
574
+ if ( type === 'readonly-signature' ) {
575
+ memberGroups . push ( 'signature' ) ;
576
+ } else if ( type === 'readonly-field' ) {
577
+ memberGroups . push ( 'field' ) ;
578
+ }
538
579
539
580
// ...then get the rank order for those member groups based on the node
540
581
return getRankOrder ( memberGroups , orderConfig ) ;
@@ -621,15 +662,43 @@ export default util.createRule<Options, MessageIds>({
621
662
interfaces : {
622
663
oneOf : [
623
664
neverConfig ,
624
- arrayConfig ( [ 'signature' , 'field' , 'method' , 'constructor' ] ) ,
625
- objectConfig ( [ 'signature' , 'field' , 'method' , 'constructor' ] ) ,
665
+ arrayConfig ( [
666
+ 'readonly-signature' ,
667
+ 'signature' ,
668
+ 'readonly-field' ,
669
+ 'field' ,
670
+ 'method' ,
671
+ 'constructor' ,
672
+ ] ) ,
673
+ objectConfig ( [
674
+ 'readonly-signature' ,
675
+ 'signature' ,
676
+ 'readonly-field' ,
677
+ 'field' ,
678
+ 'method' ,
679
+ 'constructor' ,
680
+ ] ) ,
626
681
] ,
627
682
} ,
628
683
typeLiterals : {
629
684
oneOf : [
630
685
neverConfig ,
631
- arrayConfig ( [ 'signature' , 'field' , 'method' , 'constructor' ] ) ,
632
- objectConfig ( [ 'signature' , 'field' , 'method' , 'constructor' ] ) ,
686
+ arrayConfig ( [
687
+ 'readonly-signature' ,
688
+ 'signature' ,
689
+ 'readonly-field' ,
690
+ 'field' ,
691
+ 'method' ,
692
+ 'constructor' ,
693
+ ] ) ,
694
+ objectConfig ( [
695
+ 'readonly-signature' ,
696
+ 'signature' ,
697
+ 'readonly-field' ,
698
+ 'field' ,
699
+ 'method' ,
700
+ 'constructor' ,
701
+ ] ) ,
633
702
] ,
634
703
} ,
635
704
} ,
0 commit comments