tools: validate apidoc links

PR-URL: https://github.com/nodejs/node/pull/21889
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Sam Ruby 2018-07-19 12:12:38 -04:00 committed by Vse Mozhet Byt
parent 2ba3b57c76
commit 78039b5f87

View File

@ -73,3 +73,16 @@ all = all.slice(0, apiStart.index + apiStart[0].length) +
// Write results.
fs.writeFileSync(source + '/all.html', all, 'utf8');
// Validate all hrefs have a target.
const ids = new Set();
const idRe = / id="(\w+)"/g;
let match;
while (match = idRe.exec(all)) {
ids.add(match[1]);
}
const hrefRe = / href="#(\w+)"/g;
while (match = hrefRe.exec(all)) {
if (!ids.has(match[1])) throw new Error(`link not found: ${match[1]}`);
}