diff --git a/delegates.txt b/delegates.txt index 30fe7fcc..72331a36 100644 --- a/delegates.txt +++ b/delegates.txt @@ -336,7 +336,7 @@ Nikolaus Papaspyrou (NPU) Noah Tye (NTE) Norbert Lindenberg (NL) Oliver Hunt (OH) -Pablo Gorostiaga Belio (PGB) +Pablo Gorostiaga Belio (PBO) Paolo Severini (PSI) Patrick Soquet (PST) Paul Leather (PLR) diff --git a/scripts/check-delegates-test.mjs b/scripts/check-delegates-test.mjs index b3265b12..3a727116 100644 --- a/scripts/check-delegates-test.mjs +++ b/scripts/check-delegates-test.mjs @@ -8,6 +8,8 @@ const twoLetter = `Chris de Almeida (CDA)\nRob Palmer (RP)\nUjjwal Sharma (USA)` const threeLetter = `Chris de Almeida (CDA)\nRob Palmer (ROBPALMER)\nUjjwal Sharma (USA)`; const duplicate = `Chris de Almeida (CDA)\nRob Palmer (RPR)\nUjjwal Sharma (USA)\nUjjwal Sharma (USA)`; const valid = `Chris de Almeida (CDA)\nMichael Ficarra (MF)\nRob Palmer (RPR)\nUjjwal Sharma (USA)`; +const mononymous = `Chris de Almeida (CDA)\nYee (YEE)\nRob Palmer (RPR)\nUjjwal Sharma (USA)`; +const idealTLA = `Chris de Almeida (CAA)\nMichael Ficarra (MF)\nRob Palmer (RPR)\nUjjwal Sharma (USA)`; assert.throws(() => checkDelegates(lex), { message: 'Line 3: Not in lexicographic order.' }); // also validates expected line number assert.throws(() => checkDelegates(missing), { message: /Missing abbreviation for/ }); @@ -15,5 +17,7 @@ assert.throws(() => checkDelegates(uppercaseLatin), { message: /Abbreviations mu assert.throws(() => checkDelegates(twoLetter), { message: /not in allowlist. New delegate abbreviations must be three letters/ }); assert.throws(() => checkDelegates(threeLetter), { message: /New delegate abbreviations must be three letters/ }); assert.throws(() => checkDelegates(duplicate), { message: /Conflicting usage on line/ }); +assert.throws(() => checkDelegates(mononymous), { message: /Unexpected mononymous delegate/ }); +assert.throws(() => checkDelegates(idealTLA), { message: /Should be using ideal TLA \(CDA\)/ }); assert.doesNotThrow(() => checkDelegates(valid)); diff --git a/scripts/check-delegates.mjs b/scripts/check-delegates.mjs index 862bbe5e..0a1f4060 100755 --- a/scripts/check-delegates.mjs +++ b/scripts/check-delegates.mjs @@ -19,8 +19,44 @@ export function checkDelegates(contents = fs.readFileSync('./delegates.txt', 'ut 'VM', 'WH', 'YK', 'ZB', ]); + // list of abbreviations that are not ideal. + // most of these are here because they are grandfathered in. + // new elements should only be false positives. + const NON_IDEAL_ABBRS = new Set([ + 'AVP', 'AC', 'AK', 'AEC', 'AS', 'AR', 'ASH', 'AWB', 'ARB', 'ACB', + 'AVK', 'ABU', 'ALH', 'AEH', 'AVC', 'AYS', 'BM', 'RTM', 'BZ', + 'BG', 'BB', 'BE', 'BRK', 'BT', 'BNG', 'CJT', 'CP', 'CZW', 'CM', + 'CHU', 'LCP', 'CJI', 'CF', 'CJR', 'CCN', 'DHC', 'DDC', 'DJF', + 'DLM', 'DAS', 'DE', 'DVE', 'DH', 'DMP', 'DEN', 'DTL', 'DJW', + 'DFS', 'DT', 'DFV', 'DL', 'DS', 'DD', 'DMM', 'EDB', 'EY', 'EF', + 'ET', 'EA', 'REK', 'FED', 'FP', 'FN', 'FRT', 'FYT', 'GI', 'GN', + 'GKZ', 'GY', 'GRS', 'GPT', 'GCW', 'LGY', 'GB', 'HUG', 'IH', 'IT', + 'IOA', 'IVH', 'IS', 'JBS', 'JPG', 'JH', 'JRB', 'JSL', 'JK', + 'JXF', 'JAN', 'JTO', 'JS', 'JFP', 'JHL', 'JSW', 'JZY', 'JAZ', + 'JMN', 'YJM', 'JN', 'JP', 'JDD', 'JT', 'JPB', 'KGO', 'KZM', 'KM', + 'KCD', 'KG', 'KR', 'KS', 'XAX', 'KHG', 'KOT', 'KBK', 'LB', 'LZH', + 'LM', 'LWT', 'LEO', 'LIU', 'LL', 'LCA', 'LFP', 'MJN', 'MHA', + 'MPC', 'MED', 'MH', 'MM', 'MJS', 'MWS', 'MAR', 'MS', 'MAG', 'MF', + 'MLS', 'MZG', 'MP', 'MCW', 'JXZ', 'MQW', 'WMM', 'MYC', 'MGR', + 'MCM', 'NH', 'SNS', 'NC', 'NLY', 'NM', 'NL', 'OH', 'PBO', 'PL', + 'PFM', 'PJ', 'PZE', 'PFC', 'PLH', 'PMD', 'RX', 'JHJ', 'RB', 'RH', + 'ROF', 'ZRJ', 'STH', 'SC', 'SM', 'SMK', 'SYH', 'SFC', 'SJY', + 'SRK', 'SYP', 'SP', 'SRL', 'SZH', 'SJL', 'SSA', 'SZT', 'TAB', + 'TEK', 'TS', 'TW', 'TOC', 'YTX', 'XTY', 'TJC', 'TD', 'TC', 'TVC', + 'VM', 'WH', 'XWC', 'LWW', 'WES', 'WWW', 'WXK', 'HUX', 'WYJ', + 'YKZ', 'YIY', 'YKL', 'YRL', 'YYC', 'LZM', 'ZYY', 'LZJ', 'ZB', + 'ZJL', + ]); + + // delegates with only one name. this list should be as close to zero as possible... + const MONONYMOUS = new Set([ + 'Cuili', + 'Surma', + ]); + + const allAbbrs = new Set(contents.match(/(?<=\()[^)]*(?=\))/g)); - const re = /^(?[^(]+)(?: \((?[^)]*)\))?$/; + const re = /^(?[^( ]+) ?(?[^(]+)?(?: \((?[^)]*)\))?$/; const abbrs = new Map; const lines = contents.split('\n'); @@ -30,7 +66,7 @@ export function checkDelegates(contents = fs.readFileSync('./delegates.txt', 'ut for (const line of lines) { if (line.length === 0) continue; const match = re.exec(line); - const { abbr } = match.groups; + const { abbr, firstName, lastName } = match.groups; if (previousLine.localeCompare(line, 'en') > 0) { throw new Error(`Line ${lineNumber}: Not in lexicographic order.`); @@ -57,9 +93,29 @@ export function checkDelegates(contents = fs.readFileSync('./delegates.txt', 'ut } abbrs.set(abbr, lineNumber); + const idealTLA = getIdealTLA(firstName, lastName); + + if (idealTLA){ + if (!allAbbrs.has(idealTLA) && !NON_IDEAL_ABBRS.has(abbr)){ + 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.`) + } + } else if (!MONONYMOUS.has(firstName)) { + throw new Error(`Line ${lineNumber}: Unexpected mononymous delegate.`) + } + previousLine = line; ++lineNumber; } console.debug('...delegates are valid\n'); } + +function getIdealTLA(firstName, lastName) { + + if (lastName) { + return `${firstName.slice(0, 1)}${lastName.slice(0, 1)}${lastName.slice(lastName.length - 1)}`.toUpperCase(); + } + + return null; + +}