Skip to content

Commit d6d6b05

Browse files
committed
tools: warn about duplicates when generating AUTHORS file
PR-URL: #40304 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
1 parent 0d50dfd commit d6d6b05

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎tools/update-authors.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class CaseIndifferentMap {
1111
_map=newMap();
1212

1313
get(key){returnthis._map.get(key.toLowerCase());}
14+
has(key){returnthis._map.has(key.toLowerCase());}
1415
set(key,value){returnthis._map.set(key.toLowerCase(),value);}
1516
}
1617

@@ -64,6 +65,30 @@ const mailmap = new CaseIndifferentMap();
6465
}
6566
}
6667

68+
constpreviousAuthors=newCaseIndifferentMap();
69+
{
70+
constlines=fs.readFileSync(path.resolve(__dirname,'../','AUTHORS'),
71+
{encoding: 'utf8'}).split('\n');
72+
for(letlineoflines){
73+
line=line.trim();
74+
if(line.startsWith('#')||line==='')continue;
75+
76+
letmatch;
77+
if(match=line.match(/^([^<]+)\s+(<[^>]+>)$/)){
78+
constname=match[1];
79+
constemail=match[2];
80+
if(previousAuthors.has(name)){
81+
constemails=previousAuthors.get(name);
82+
emails.push(email);
83+
}else{
84+
previousAuthors.set(name,[email]);
85+
}
86+
}else{
87+
console.warn('Unknown AUTHORS format:',line);
88+
}
89+
}
90+
}
91+
6792
constseen=newSet();
6893

6994
// Support regular git author metadata, as well as `Author:` and
@@ -93,6 +118,11 @@ rl.on('line', (line) => {
93118

94119
seen.add(email);
95120
output.write(`${author}${email}\n`);
121+
constduplicate=previousAuthors.get(author);
122+
if(duplicate&&!duplicate.includes(email)){
123+
console.warn('Author name already in AUTHORS file. Possible duplicate:');
124+
console.warn(` ${author} <${email}>`);
125+
}
96126
});
97127

98128
rl.on('close',()=>{

0 commit comments

Comments
 (0)