0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 20:29:23 +01:00
nodejs/tools/lint-readme-lists.mjs
Antoine du Hamel 7182503d90
tools: add a linter for README lists
PR-URL: https://github.com/nodejs/node/pull/52476
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2024-04-13 15:03:43 +00:00

49 lines
1.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
// Validates the list in the README are in the correct order.
import { open } from 'node:fs/promises';
const lists = [
'TSC voting members',
'TSC regular members',
'TSC emeriti members',
'Collaborators',
'Collaborator emeriti',
'Triagers',
];
const tscMembers = new Set();
const readme = await open(new URL('../README.md', import.meta.url), 'r');
let currentList = null;
let previousGithubHandle;
let lineNumber = 0;
for await (const line of readme.readLines()) {
lineNumber++;
if (line.startsWith('### ')) {
currentList = lists[lists.indexOf(line.slice(4))];
previousGithubHandle = null;
} else if (line.startsWith('#### ')) {
currentList = lists[lists.indexOf(line.slice(5))];
previousGithubHandle = null;
} else if (currentList && line.startsWith('* [')) {
const currentGithubHandle = line.slice(3, line.indexOf(']')).toLowerCase();
if (previousGithubHandle && previousGithubHandle >= currentGithubHandle) {
throw new Error(`${currentGithubHandle} should be listed before ${previousGithubHandle} in the ${currentList} list (README.md:${lineNumber})`);
}
if (currentList === 'TSC voting members' || currentList === 'TSC regular members') {
tscMembers.add(currentGithubHandle);
} else if (currentList === 'Collaborators') {
tscMembers.delete(currentGithubHandle);
}
previousGithubHandle = currentGithubHandle;
}
}
if (tscMembers.size !== 0) {
throw new Error(`Some TSC members are not listed as Collaborators: ${Array.from(tscMembers)}`);
}