@@ -66,6 +66,8 @@ type Selector<TType extends Selectors> = FormatOptions &
66
66
type NormalizedSelector < TType extends Selectors > = FormatOptions &
67
67
SelectorBase < TType > & {
68
68
filter : RegExp | null ;
69
+ // calculated ordering weight based on modifiers
70
+ weight : number ;
69
71
} ;
70
72
71
73
// Note that this intentionally does not strictly type the modifiers/types properties.
@@ -617,6 +619,9 @@ function createValidator(
617
619
context : Context ,
618
620
configs : Config [ ] ,
619
621
) : ( node : TSESTree . Identifier | TSESTree . Literal ) => void {
622
+ // make sure the "highest priority" configs are checked first
623
+ configs = [ ...configs ] . sort ( ( a , b ) => b . weight - a . weight ) ;
624
+
620
625
return (
621
626
node : TSESTree . Identifier | TSESTree . Literal ,
622
627
modifiers : Set < Modifiers > = new Set < Modifiers > ( ) ,
@@ -663,7 +668,8 @@ function createValidator(
663
668
return ;
664
669
}
665
670
666
- // it's valid for this config!
671
+ // it's valid for this config, so we don't need to check any more configs
672
+ return ;
667
673
}
668
674
} ;
669
675
@@ -946,12 +952,41 @@ function selectorTypeToMessageString(selectorType: Selectors): string {
946
952
return notCamelCase . charAt ( 0 ) . toUpperCase ( ) + notCamelCase . slice ( 1 ) ;
947
953
}
948
954
955
+ const ModifierWeight = ( ( ) : Readonly <
956
+ Record < Modifiers | TypeModifiers , number >
957
+ > => {
958
+ let i = 0 ;
959
+ return {
960
+ // Modifiers
961
+ readonly : 1 << i ++ ,
962
+ static : 1 << i ++ ,
963
+ public : 1 << i ++ ,
964
+ protected : 1 << i ++ ,
965
+ private : 1 << i ++ ,
966
+ abstract : 1 << i ++ ,
967
+ // TypeModifiers
968
+ boolean : 1 << i ++ ,
969
+ string : 1 << i ++ ,
970
+ number : 1 << i ++ ,
971
+ function : 1 << i ++ ,
972
+ array : 1 << i ++ ,
973
+ } ;
974
+ } ) ( ) ;
949
975
function normalizeOption < TType extends Selectors > (
950
976
option : Selector < TType > ,
951
977
) : NormalizedSelector < TType > {
978
+ let weight = 0 ;
979
+ option . modifiers ?. forEach ( mod => {
980
+ weight |= ModifierWeight [ mod ] ;
981
+ } ) ;
982
+ option . types ?. forEach ( mod => {
983
+ weight |= ModifierWeight [ mod ] ;
984
+ } ) ;
985
+
952
986
return {
953
987
...option ,
954
988
filter : option . filter !== undefined ? new RegExp ( option . filter ) : null ,
989
+ weight,
955
990
} ;
956
991
}
957
992
0 commit comments