From 03afa3633474eeb23da6ef02fb0bc6945fc5ceea Mon Sep 17 00:00:00 2001 From: Sonu Kapoor Date: Tue, 12 May 2020 07:13:16 -0400 Subject: [PATCH] refactor(docs-infra): refactors `checkUnbalancedBackTicks` (#37065) This commit removes the dependency on the `lodash` module and refactors the `checkUnbalancedBackTicks` method. PR Close #37065 --- .../processors/checkUnbalancedBackTicks.js | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/aio/tools/transforms/angular-base-package/processors/checkUnbalancedBackTicks.js b/aio/tools/transforms/angular-base-package/processors/checkUnbalancedBackTicks.js index f79b1ba961..97302ca70e 100644 --- a/aio/tools/transforms/angular-base-package/processors/checkUnbalancedBackTicks.js +++ b/aio/tools/transforms/angular-base-package/processors/checkUnbalancedBackTicks.js @@ -1,5 +1,3 @@ -var _ = require('lodash'); - /** * @dgProcessor checkUnbalancedBackTicks * @description @@ -9,25 +7,28 @@ var _ = require('lodash'); */ module.exports = function checkUnbalancedBackTicks(log, createDocMessage) { - var BACKTICK_REGEX = /^ *```/gm; + const BACKTICK_REGEX = /^ *```/gm; + const UNBALANCED_BACKTICK_WARNING = 'checkUnbalancedBackTicks processor: unbalanced backticks found in rendered content'; return { - // $runAfter: ['checkAnchorLinksProcessor'], $runAfter: ['inlineTagProcessor'], $runBefore: ['writeFilesProcessor'], $process: function(docs) { - _.forEach(docs, function(doc) { - if (doc.renderedContent) { - var matches = doc.renderedContent.match(BACKTICK_REGEX); - if (matches && matches.length % 2 !== 0) { - doc.unbalancedBackTicks = true; - log.warn(createDocMessage( - 'checkUnbalancedBackTicks processor: unbalanced backticks found in rendered content', - doc)); - log.warn(doc.renderedContent); - } - } - }); + docs + .forEach(doc => setUnbalancedBackTicks(doc)); } }; + + function setUnbalancedBackTicks(doc) { + if (!doc.renderedContent) { + return; + } + + const matches = doc.renderedContent.match(BACKTICK_REGEX); + if (matches && matches.length % 2 !== 0) { + doc.unbalancedBackTicks = true; + log.warn(createDocMessage(UNBALANCED_BACKTICK_WARNING, doc)); + log.warn(doc.renderedContent); + } + } }; \ No newline at end of file