@@ -19,8 +19,44 @@ export function checkDelegates(contents = fs.readFileSync('./delegates.txt', 'ut
19
19
'VM' , 'WH' , 'YK' , 'ZB' ,
20
20
] ) ;
21
21
22
+ // list of abbreviations that are not ideal.
23
+ // most of these are here because they are grandfathered in.
24
+ // new elements should only be false positives.
25
+ const NON_IDEAL_ABBRS = new Set ( [
26
+ 'AVP' , 'AC' , 'AK' , 'AEC' , 'AS' , 'AR' , 'ASH' , 'AWB' , 'ARB' , 'ACB' ,
27
+ 'AVK' , 'ABU' , 'ALH' , 'AEH' , 'AVC' , 'AYS' , 'BM' , 'RTM' , 'BZ' ,
28
+ 'BG' , 'BB' , 'BE' , 'BRK' , 'BT' , 'BNG' , 'CJT' , 'CP' , 'CZW' , 'CM' ,
29
+ 'CHU' , 'LCP' , 'CJI' , 'CF' , 'CJR' , 'CCN' , 'DHC' , 'DDC' , 'DJF' ,
30
+ 'DLM' , 'DAS' , 'DE' , 'DVE' , 'DH' , 'DMP' , 'DEN' , 'DTL' , 'DJW' ,
31
+ 'DFS' , 'DT' , 'DFV' , 'DL' , 'DS' , 'DD' , 'DMM' , 'EDB' , 'EY' , 'EF' ,
32
+ 'ET' , 'EA' , 'REK' , 'FED' , 'FP' , 'FN' , 'FRT' , 'FYT' , 'GI' , 'GN' ,
33
+ 'GKZ' , 'GY' , 'GRS' , 'GPT' , 'GCW' , 'LGY' , 'GB' , 'HUG' , 'IH' , 'IT' ,
34
+ 'IOA' , 'IVH' , 'IS' , 'JBS' , 'JPG' , 'JH' , 'JRB' , 'JSL' , 'JK' ,
35
+ 'JXF' , 'JAN' , 'JTO' , 'JS' , 'JFP' , 'JHL' , 'JSW' , 'JZY' , 'JAZ' ,
36
+ 'JMN' , 'YJM' , 'JN' , 'JP' , 'JDD' , 'JT' , 'JPB' , 'KGO' , 'KZM' , 'KM' ,
37
+ 'KCD' , 'KG' , 'KR' , 'KS' , 'XAX' , 'KHG' , 'KOT' , 'KBK' , 'LB' , 'LZH' ,
38
+ 'LM' , 'LWT' , 'LEO' , 'LIU' , 'LL' , 'LCA' , 'LFP' , 'MJN' , 'MHA' ,
39
+ 'MPC' , 'MED' , 'MH' , 'MM' , 'MJS' , 'MWS' , 'MAR' , 'MS' , 'MAG' , 'MF' ,
40
+ 'MLS' , 'MZG' , 'MP' , 'MCW' , 'JXZ' , 'MQW' , 'WMM' , 'MYC' , 'MGR' ,
41
+ 'MCM' , 'NH' , 'SNS' , 'NC' , 'NLY' , 'NM' , 'NL' , 'OH' , 'PBO' , 'PL' ,
42
+ 'PFM' , 'PJ' , 'PZE' , 'PFC' , 'PLH' , 'PMD' , 'RX' , 'JHJ' , 'RB' , 'RH' ,
43
+ 'ROF' , 'ZRJ' , 'STH' , 'SC' , 'SM' , 'SMK' , 'SYH' , 'SFC' , 'SJY' ,
44
+ 'SRK' , 'SYP' , 'SP' , 'SRL' , 'SZH' , 'SJL' , 'SSA' , 'SZT' , 'TAB' ,
45
+ 'TEK' , 'TS' , 'TW' , 'TOC' , 'YTX' , 'XTY' , 'TJC' , 'TD' , 'TC' , 'TVC' ,
46
+ 'VM' , 'WH' , 'XWC' , 'LWW' , 'WES' , 'WWW' , 'WXK' , 'HUX' , 'WYJ' ,
47
+ 'YKZ' , 'YIY' , 'YKL' , 'YRL' , 'YYC' , 'LZM' , 'ZYY' , 'LZJ' , 'ZB' ,
48
+ 'ZJL' ,
49
+ ] ) ;
50
+
51
+ // delegates with only one name. this list should be as close to zero as possible...
52
+ const MONONYMOUS = new Set ( [
53
+ 'Cuili' ,
54
+ 'Surma' ,
55
+ ] ) ;
56
+
57
+ const allAbbrs = new Set ( contents . match ( / (?< = \( ) [ ^ ) ] * (? = \) ) / g) ) ;
22
58
23
- const re = / ^ (?< name > [ ^ ( ] + ) (?: \( (?< abbr > [ ^ ) ] * ) \) ) ? $ / ;
59
+ const re = / ^ (?< firstName > [ ^ ( ] + ) ? (?< lastName > [ ^ ( ] + ) ? (?: \( (?< abbr > [ ^ ) ] * ) \) ) ? $ / ;
24
60
const abbrs = new Map ;
25
61
const lines = contents . split ( '\n' ) ;
26
62
@@ -30,7 +66,7 @@ export function checkDelegates(contents = fs.readFileSync('./delegates.txt', 'ut
30
66
for ( const line of lines ) {
31
67
if ( line . length === 0 ) continue ;
32
68
const match = re . exec ( line ) ;
33
- const { abbr } = match . groups ;
69
+ const { abbr, firstName , lastName } = match . groups ;
34
70
35
71
if ( previousLine . localeCompare ( line , 'en' ) > 0 ) {
36
72
throw new Error ( `Line ${ lineNumber } : Not in lexicographic order.` ) ;
@@ -57,9 +93,29 @@ export function checkDelegates(contents = fs.readFileSync('./delegates.txt', 'ut
57
93
}
58
94
abbrs . set ( abbr , lineNumber ) ;
59
95
96
+ const idealTLA = getIdealTLA ( firstName , lastName ) ;
97
+
98
+ if ( idealTLA ) {
99
+ if ( ! allAbbrs . has ( idealTLA ) && ! NON_IDEAL_ABBRS . has ( abbr ) ) {
100
+ throw new Error ( `Line ${ lineNumber } : Should be using ideal TLA (${ idealTLA } ). Note: because code cannot distinguish between a middle name vs a two-part last name, this may be a false positive.` )
101
+ }
102
+ } else if ( ! MONONYMOUS . has ( firstName ) ) {
103
+ throw new Error ( `Line ${ lineNumber } : Unexpected mononymous delegate.` )
104
+ }
105
+
60
106
previousLine = line ;
61
107
++ lineNumber ;
62
108
}
63
109
64
110
console . debug ( '...delegates are valid\n' ) ;
65
111
}
112
+
113
+ function getIdealTLA ( firstName , lastName ) {
114
+
115
+ if ( lastName ) {
116
+ return `${ firstName . slice ( 0 , 1 ) } ${ lastName . slice ( 0 , 1 ) } ${ lastName . slice ( lastName . length - 1 ) } ` . toUpperCase ( ) ;
117
+ }
118
+
119
+ return null ;
120
+
121
+ }
0 commit comments