From 7d07e27caa5ee087b368866df0f100b9cb339fd5 Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Thu, 19 Jul 2018 12:12:38 -0400 Subject: [PATCH 1/5] tools: validate apidoc links --- tools/doc/allhtml.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/doc/allhtml.js b/tools/doc/allhtml.js index d185538ab683b6..4f813a7e9c8efd 100644 --- a/tools/doc/allhtml.js +++ b/tools/doc/allhtml.js @@ -73,3 +73,13 @@ 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 = {}; +all.replace(/ id="(\w+)"/g, (_text, id) => { + ids[id] = true; +}); + +all.replace(/ href="#(\w+)"/g, (_text, href) => { + if (!ids[href]) throw new Error(`link not found: ${href}`); +}); From fc0c16de6a7c7ed8a7fa67beba73886a93a035d9 Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Thu, 19 Jul 2018 12:24:51 -0400 Subject: [PATCH 2/5] object => set --- tools/doc/allhtml.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/doc/allhtml.js b/tools/doc/allhtml.js index 4f813a7e9c8efd..8cece651c4e888 100644 --- a/tools/doc/allhtml.js +++ b/tools/doc/allhtml.js @@ -75,11 +75,11 @@ all = all.slice(0, apiStart.index + apiStart[0].length) + fs.writeFileSync(source + '/all.html', all, 'utf8'); // Validate all hrefs have a target -const ids = {}; +const ids = new Set(); all.replace(/ id="(\w+)"/g, (_text, id) => { - ids[id] = true; + ids.add(id); }); all.replace(/ href="#(\w+)"/g, (_text, href) => { - if (!ids[href]) throw new Error(`link not found: ${href}`); + if (!ids.has(href)) throw new Error(`link not found: ${href}`); }); From c3d8ee9792a06392b885890f90798c158271ae59 Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Thu, 19 Jul 2018 13:40:50 -0400 Subject: [PATCH 3/5] comment punctuation --- tools/doc/allhtml.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/doc/allhtml.js b/tools/doc/allhtml.js index 8cece651c4e888..10f326b70cc82a 100644 --- a/tools/doc/allhtml.js +++ b/tools/doc/allhtml.js @@ -74,7 +74,7 @@ all = all.slice(0, apiStart.index + apiStart[0].length) + // Write results. fs.writeFileSync(source + '/all.html', all, 'utf8'); -// Validate all hrefs have a target +// Validate all hrefs have a target. const ids = new Set(); all.replace(/ id="(\w+)"/g, (_text, id) => { ids.add(id); From f8cf61b86799c326d75cea640e539e1298338adf Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Thu, 19 Jul 2018 17:01:36 -0400 Subject: [PATCH 4/5] .replace => .exec --- tools/doc/allhtml.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/doc/allhtml.js b/tools/doc/allhtml.js index 10f326b70cc82a..84d249b9fa9887 100644 --- a/tools/doc/allhtml.js +++ b/tools/doc/allhtml.js @@ -76,10 +76,13 @@ fs.writeFileSync(source + '/all.html', all, 'utf8'); // Validate all hrefs have a target. const ids = new Set(); -all.replace(/ id="(\w+)"/g, (_text, id) => { - ids.add(id); -}); +const id_re = / id="(\w+)"/g; +let match; +while (match = id_re.exec(all)) { + ids.add(match[1]); +} -all.replace(/ href="#(\w+)"/g, (_text, href) => { - if (!ids.has(href)) throw new Error(`link not found: ${href}`); -}); +const href_re = / href="#(\w+)"/g; +while (match = href_re.exec(all)) { + if (!ids.has(match[1])) throw new Error(`link not found: ${match[1]}`); +} From 930d192e0e5cbfd6ec1146850932712e2327ab4b Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Fri, 20 Jul 2018 15:42:40 -0400 Subject: [PATCH 5/5] camelCase --- tools/doc/allhtml.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/doc/allhtml.js b/tools/doc/allhtml.js index 84d249b9fa9887..3de538e42404a5 100644 --- a/tools/doc/allhtml.js +++ b/tools/doc/allhtml.js @@ -76,13 +76,13 @@ fs.writeFileSync(source + '/all.html', all, 'utf8'); // Validate all hrefs have a target. const ids = new Set(); -const id_re = / id="(\w+)"/g; +const idRe = / id="(\w+)"/g; let match; -while (match = id_re.exec(all)) { +while (match = idRe.exec(all)) { ids.add(match[1]); } -const href_re = / href="#(\w+)"/g; -while (match = href_re.exec(all)) { +const hrefRe = / href="#(\w+)"/g; +while (match = hrefRe.exec(all)) { if (!ids.has(match[1])) throw new Error(`link not found: ${match[1]}`); }