@@ -26,12 +26,12 @@ enum PredefinedFormats {
26
26
}
27
27
type PredefinedFormatsString = keyof typeof PredefinedFormats ;
28
28
29
- enum UnderscroreOptions {
29
+ enum UnderscoreOptions {
30
30
forbid = 1 << 0 ,
31
31
allow = 1 << 1 ,
32
32
require = 1 << 2 ,
33
33
}
34
- type UnderscroreOptionsString = keyof typeof UnderscroreOptions ;
34
+ type UnderscoreOptionsString = keyof typeof UnderscoreOptions ;
35
35
36
36
enum Selectors {
37
37
// variableLike
@@ -99,8 +99,8 @@ type TypeModifiersString = keyof typeof TypeModifiers;
99
99
interface Selector {
100
100
// format options
101
101
format : PredefinedFormatsString [ ] ;
102
- leadingUnderscore ?: UnderscroreOptionsString ;
103
- trailingUnderscore ?: UnderscroreOptionsString ;
102
+ leadingUnderscore ?: UnderscoreOptionsString ;
103
+ trailingUnderscore ?: UnderscoreOptionsString ;
104
104
prefix ?: string [ ] ;
105
105
suffix ?: string [ ] ;
106
106
// selector options
@@ -111,8 +111,8 @@ interface Selector {
111
111
}
112
112
interface NormalizedSelector {
113
113
// format options
114
- leadingUnderscore : UnderscroreOptions | null ;
115
- trailingUnderscore : UnderscroreOptions | null ;
114
+ leadingUnderscore : UnderscoreOptions | null ;
115
+ trailingUnderscore : UnderscoreOptions | null ;
116
116
prefix : string [ ] | null ;
117
117
suffix : string [ ] | null ;
118
118
format : PredefinedFormats [ ] ;
@@ -136,7 +136,7 @@ type Options = Selector[];
136
136
137
137
const UNDERSCORE_SCHEMA : JSONSchema . JSONSchema4 = {
138
138
type : 'string' ,
139
- enum : util . getEnumNames ( UnderscroreOptions ) ,
139
+ enum : util . getEnumNames ( UnderscoreOptions ) ,
140
140
} ;
141
141
const PREFIX_SUFFIX_SCHEMA : JSONSchema . JSONSchema4 = {
142
142
type : 'array' ,
@@ -336,27 +336,22 @@ export default util.createRule<Options, MessageIds>({
336
336
const validators = parseOptions ( context ) ;
337
337
338
338
function handleMember (
339
- validator : ValidatiorFunction | null ,
339
+ validator : ValidatorFunction | null ,
340
340
node :
341
- | TSESTree . Property
342
- | TSESTree . ClassProperty
343
- | TSESTree . TSAbstractClassProperty
344
- | TSESTree . TSPropertySignature
345
- | TSESTree . MethodDefinition
346
- | TSESTree . TSAbstractMethodDefinition
347
- | TSESTree . TSMethodSignature ,
341
+ | TSESTree . PropertyNonComputedName
342
+ | TSESTree . ClassPropertyNonComputedName
343
+ | TSESTree . TSAbstractClassPropertyNonComputedName
344
+ | TSESTree . TSPropertySignatureNonComputedName
345
+ | TSESTree . MethodDefinitionNonComputedName
346
+ | TSESTree . TSAbstractMethodDefinitionNonComputedName
347
+ | TSESTree . TSMethodSignatureNonComputedName ,
348
348
modifiers : Set < Modifiers > ,
349
349
) : void {
350
350
if ( ! validator ) {
351
351
return ;
352
352
}
353
353
354
354
const key = node . key ;
355
- /* istanbul ignore if */ if ( ! util . isLiteralOrIdentifier ( key ) ) {
356
- // shouldn't happen due to the selectors that are used
357
- return ;
358
- }
359
-
360
355
validator ( key , modifiers ) ;
361
356
}
362
357
@@ -479,7 +474,7 @@ export default util.createRule<Options, MessageIds>({
479
474
// #region property
480
475
481
476
'Property[computed = false][kind = "init"][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]' (
482
- node : TSESTree . Property ,
477
+ node : TSESTree . PropertyNonComputedName ,
483
478
) : void {
484
479
const modifiers = new Set < Modifiers > ( [ Modifiers . public ] ) ;
485
480
handleMember ( validators . property , node , modifiers ) ;
@@ -489,14 +484,16 @@ export default util.createRule<Options, MessageIds>({
489
484
'ClassProperty[computed = false][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]' ,
490
485
'TSAbstractClassProperty[computed = false][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]' ,
491
486
] . join ( ', ' ) ] (
492
- node : TSESTree . ClassProperty | TSESTree . TSAbstractClassProperty ,
487
+ node :
488
+ | TSESTree . ClassPropertyNonComputedName
489
+ | TSESTree . TSAbstractClassPropertyNonComputedName ,
493
490
) : void {
494
491
const modifiers = getMemberModifiers ( node ) ;
495
492
handleMember ( validators . property , node , modifiers ) ;
496
493
} ,
497
494
498
495
'TSPropertySignature[computed = false]' (
499
- node : TSESTree . TSPropertySignature ,
496
+ node : TSESTree . TSPropertySignatureNonComputedName ,
500
497
) : void {
501
498
const modifiers = new Set < Modifiers > ( [ Modifiers . public ] ) ;
502
499
if ( node . readonly ) {
@@ -516,7 +513,9 @@ export default util.createRule<Options, MessageIds>({
516
513
'Property[computed = false][kind = "init"][value.type = "TSEmptyBodyFunctionExpression"]' ,
517
514
'TSMethodSignature[computed = false]' ,
518
515
] . join ( ', ' ) ] (
519
- node : TSESTree . Property | TSESTree . TSMethodSignature ,
516
+ node :
517
+ | TSESTree . PropertyNonComputedName
518
+ | TSESTree . TSMethodSignatureNonComputedName ,
520
519
) : void {
521
520
const modifiers = new Set < Modifiers > ( [ Modifiers . public ] ) ;
522
521
handleMember ( validators . method , node , modifiers ) ;
@@ -533,10 +532,10 @@ export default util.createRule<Options, MessageIds>({
533
532
'TSAbstractMethodDefinition[computed = false][kind = "method"]' ,
534
533
] . join ( ', ' ) ] (
535
534
node :
536
- | TSESTree . ClassProperty
537
- | TSESTree . TSAbstractClassProperty
538
- | TSESTree . MethodDefinition
539
- | TSESTree . TSAbstractMethodDefinition ,
535
+ | TSESTree . ClassPropertyNonComputedName
536
+ | TSESTree . TSAbstractClassPropertyNonComputedName
537
+ | TSESTree . MethodDefinitionNonComputedName
538
+ | TSESTree . TSAbstractMethodDefinitionNonComputedName ,
540
539
) : void {
541
540
const modifiers = getMemberModifiers ( node ) ;
542
541
handleMember ( validators . method , node , modifiers ) ;
@@ -549,15 +548,15 @@ export default util.createRule<Options, MessageIds>({
549
548
[ [
550
549
'Property[computed = false][kind = "get"]' ,
551
550
'Property[computed = false][kind = "set"]' ,
552
- ] . join ( ', ' ) ] ( node : TSESTree . Property ) : void {
551
+ ] . join ( ', ' ) ] ( node : TSESTree . PropertyNonComputedName ) : void {
553
552
const modifiers = new Set < Modifiers > ( [ Modifiers . public ] ) ;
554
553
handleMember ( validators . accessor , node , modifiers ) ;
555
554
} ,
556
555
557
556
[ [
558
557
'MethodDefinition[computed = false][kind = "get"]' ,
559
558
'MethodDefinition[computed = false][kind = "set"]' ,
560
- ] . join ( ', ' ) ] ( node : TSESTree . MethodDefinition ) : void {
559
+ ] . join ( ', ' ) ] ( node : TSESTree . MethodDefinitionNonComputedName ) : void {
561
560
const modifiers = getMemberModifiers ( node ) ;
562
561
handleMember ( validators . accessor , node , modifiers ) ;
563
562
} ,
@@ -566,18 +565,16 @@ export default util.createRule<Options, MessageIds>({
566
565
567
566
// #region enumMember
568
567
569
- TSEnumMember ( node ) : void {
568
+ // computed is optional, so can't do [computed = false]
569
+ 'TSEnumMember[computed != true]' (
570
+ node : TSESTree . TSEnumMemberNonComputedName ,
571
+ ) : void {
570
572
const validator = validators . enumMember ;
571
573
if ( ! validator ) {
572
574
return ;
573
575
}
574
576
575
577
const id = node . id ;
576
- /* istanbul ignore if */ if ( ! util . isLiteralOrIdentifier ( id ) ) {
577
- // shouldn't happen in reality because it's not semantically valid code
578
- return ;
579
- }
580
-
581
578
validator ( id ) ;
582
579
} ,
583
580
@@ -586,7 +583,7 @@ export default util.createRule<Options, MessageIds>({
586
583
// #region class
587
584
588
585
'ClassDeclaration, ClassExpression' (
589
- node : TSESTree . ClassDeclaration | TSESTree . ClassDeclaration ,
586
+ node : TSESTree . ClassDeclaration | TSESTree . ClassExpression ,
590
587
) : void {
591
588
const validator = validators . class ;
592
589
if ( ! validator ) {
@@ -716,11 +713,11 @@ function getIdentifiersFromPattern(
716
713
}
717
714
}
718
715
719
- type ValidatiorFunction = (
716
+ type ValidatorFunction = (
720
717
node : TSESTree . Identifier | TSESTree . Literal ,
721
718
modifiers ?: Set < Modifiers > ,
722
719
) => void ;
723
- type ParsedOptions = Record < SelectorsString , null | ValidatiorFunction > ;
720
+ type ParsedOptions = Record < SelectorsString , null | ValidatorFunction > ;
724
721
type Context = TSESLint . RuleContext < MessageIds , Options > ;
725
722
function parseOptions ( context : Context ) : ParsedOptions {
726
723
const normalizedOptions = context . options . map ( opt => normalizeOption ( opt ) ) ;
@@ -863,11 +860,11 @@ function createValidator(
863
860
: ( ) : string => name . slice ( 0 , - 1 ) ;
864
861
865
862
switch ( option ) {
866
- case UnderscroreOptions . allow :
863
+ case UnderscoreOptions . allow :
867
864
// no check - the user doesn't care if it's there or not
868
865
break ;
869
866
870
- case UnderscroreOptions . forbid :
867
+ case UnderscoreOptions . forbid :
871
868
if ( hasUnderscore ) {
872
869
context . report ( {
873
870
node,
@@ -881,7 +878,7 @@ function createValidator(
881
878
}
882
879
break ;
883
880
884
- case UnderscroreOptions . require :
881
+ case UnderscoreOptions . require :
885
882
if ( ! hasUnderscore ) {
886
883
context . report ( {
887
884
node,
@@ -1116,11 +1113,11 @@ function normalizeOption(option: Selector): NormalizedSelector {
1116
1113
// format options
1117
1114
leadingUnderscore :
1118
1115
option . leadingUnderscore !== undefined
1119
- ? UnderscroreOptions [ option . leadingUnderscore ]
1116
+ ? UnderscoreOptions [ option . leadingUnderscore ]
1120
1117
: null ,
1121
1118
trailingUnderscore :
1122
1119
option . trailingUnderscore !== undefined
1123
- ? UnderscroreOptions [ option . trailingUnderscore ]
1120
+ ? UnderscoreOptions [ option . trailingUnderscore ]
1124
1121
: null ,
1125
1122
prefix : option . prefix ?? null ,
1126
1123
suffix : option . suffix ?? null ,
0 commit comments