From 9d72e9234d76251a32d49d8c1ea7a28de11aab82 Mon Sep 17 00:00:00 2001 From: Menai Ala Eddine Date: Fri, 3 Jul 2020 17:18:05 -0700 Subject: [PATCH] refactor : replace double [if] with one [if] The previous `if` are redundant because they return the same result. We combine their conditions together in single `if`. --- scripts/generateHeadingIDs.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/generateHeadingIDs.js b/scripts/generateHeadingIDs.js index a8130edf05d..776145a8cb9 100644 --- a/scripts/generateHeadingIDs.js +++ b/scripts/generateHeadingIDs.js @@ -23,14 +23,11 @@ function stripLinks(line) { } function addHeaderID(line, slugger) { - // check if we're a header at all - if (!line.startsWith('#')) { +// check if we're a header at all || it already has an id +if (!line.startsWith('#') || /\{#[^}]+\}/.test(line)) { return line; - } - // check if it already has an id - if (/\{#[^}]+\}/.test(line)) { - return line; - } +} + const headingText = line.slice(line.indexOf(' ')).trim(); const headingLevel = line.slice(0, line.indexOf(' ')); return `${headingLevel} ${headingText} {#${slugger.slug(