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

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tools/update-authors.js

+30
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class CaseIndifferentMap {
1111
_map = new Map();
1212

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

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

68+
const previousAuthors = new CaseIndifferentMap();
69+
{
70+
const lines = fs.readFileSync(path.resolve(__dirname, '../', 'AUTHORS'),
71+
{ encoding: 'utf8' }).split('\n');
72+
for (let line of lines) {
73+
line = line.trim();
74+
if (line.startsWith('#') || line === '') continue;
75+
76+
let match;
77+
if (match = line.match(/^([^<]+)\s+(<[^>]+>)$/)) {
78+
const name = match[1];
79+
const email = match[2];
80+
if (previousAuthors.has(name)) {
81+
const emails = 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
const seen = new Set();
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+
const duplicate = 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)