From 5e71d63bfeb0bad179d6c2e18c66b3a3a21df2e4 Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Thu, 19 Jul 2018 12:12:38 -0400 Subject: [PATCH] tools: validate apidoc links PR-URL: https://github.com/nodejs/node/pull/21889 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Vse Mozhet Byt Reviewed-By: Luigi Pinca Reviewed-By: Rich Trott --- tools/doc/allhtml.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/doc/allhtml.js b/tools/doc/allhtml.js index d185538ab683b6..3de538e42404a5 100644 --- a/tools/doc/allhtml.js +++ b/tools/doc/allhtml.js @@ -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]}`); +}