tools: warn about duplicates when generating AUTHORS file

PR-URL: https://github.com/nodejs/node/pull/40304
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
This commit is contained in:
Rich Trott 2021-10-03 15:07:14 -07:00
parent 0d50dfdf61
commit d6d6b050ff
1 changed files with 30 additions and 0 deletions

View File

@ -11,6 +11,7 @@ class CaseIndifferentMap {
_map = new Map();
get(key) { return this._map.get(key.toLowerCase()); }
has(key) { return this._map.has(key.toLowerCase()); }
set(key, value) { return this._map.set(key.toLowerCase(), value); }
}
@ -64,6 +65,30 @@ const mailmap = new CaseIndifferentMap();
}
}
const previousAuthors = new CaseIndifferentMap();
{
const lines = fs.readFileSync(path.resolve(__dirname, '../', 'AUTHORS'),
{ encoding: 'utf8' }).split('\n');
for (let line of lines) {
line = line.trim();
if (line.startsWith('#') || line === '') continue;
let match;
if (match = line.match(/^([^<]+)\s+(<[^>]+>)$/)) {
const name = match[1];
const email = match[2];
if (previousAuthors.has(name)) {
const emails = previousAuthors.get(name);
emails.push(email);
} else {
previousAuthors.set(name, [email]);
}
} else {
console.warn('Unknown AUTHORS format:', line);
}
}
}
const seen = new Set();
// Support regular git author metadata, as well as `Author:` and
@ -93,6 +118,11 @@ rl.on('line', (line) => {
seen.add(email);
output.write(`${author} ${email}\n`);
const duplicate = previousAuthors.get(author);
if (duplicate && !duplicate.includes(email)) {
console.warn('Author name already in AUTHORS file. Possible duplicate:');
console.warn(` ${author} <${email}>`);
}
});
rl.on('close', () => {