From c5d4a3297fa652224126f54eae89f5179d8e3845 Mon Sep 17 00:00:00 2001 From: David Anson Date: Sun, 6 Oct 2024 20:59:09 -0700 Subject: [PATCH] Move single use, not explicitly tested helpers into the file that uses them. --- demo/markdownlint-browser.js | 78 +++++++++++++++++------------------- helpers/helpers.js | 39 +----------------- lib/md048.js | 17 +++++++- lib/md049-md050.js | 17 +++++++- lib/md053.js | 5 ++- 5 files changed, 72 insertions(+), 84 deletions(-) diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 80dbfa01..1c5c4e37 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -33,10 +33,6 @@ const inlineCommentStartRe = /()/gi; module.exports.inlineCommentStartRe = inlineCommentStartRe; -// Regular expression for link reference definitions -const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/; -module.exports.linkReferenceDefinitionRe = linkReferenceDefinitionRe; - // Regular expression for identifying an HTML entity at the end of a line module.exports.endOfLineHtmlEntityRe = /&(?:#\d+|#[xX][\da-fA-F]+|[a-zA-Z]{2,31}|blk\d{2}|emsp1[34]|frac\d{2}|sup\d|there4);$/; @@ -234,38 +230,6 @@ module.exports.escapeForRegExp = function escapeForRegExp(str) { return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); }; -/** - * Return the string representation of a fence markup character. - * - * @param {string} markup Fence string. - * @returns {string} String representation. - */ -module.exports.fencedCodeBlockStyleFor = - function fencedCodeBlockStyleFor(markup) { - switch (markup[0]) { - case "~": - return "tilde"; - default: - return "backtick"; - } - }; - -/** - * Return the string representation of a emphasis or strong markup character. - * - * @param {string} markup Emphasis or strong string. - * @returns {"asterisk" | "underscore"} String representation. - */ -module.exports.emphasisOrStrongStyleFor = - function emphasisOrStrongStyleFor(markup) { - switch (markup[0]) { - case "*": - return "asterisk"; - default: - return "underscore"; - } - }; - /** * Adds ellipsis to the left/right/middle of the specified text. * @@ -388,13 +352,12 @@ const positionLessThanOrEqual = (lineA, columnA, lineB, columnB) => ( * @param {FileRange|import("../lib/markdownlint.js").MicromarkToken} rangeB Range B. * @returns {boolean} True iff the two ranges overlap. */ -const hasOverlap = (rangeA, rangeB) => { +module.exports.hasOverlap = function hasOverlap(rangeA, rangeB) { const lte = positionLessThanOrEqual(rangeA.startLine, rangeA.startColumn, rangeB.startLine, rangeB.startColumn); const first = lte ? rangeA : rangeB; const second = lte ? rangeB : rangeA; return positionLessThanOrEqual(second.startLine, second.startColumn, first.endLine, first.endColumn); }; -module.exports.hasOverlap = hasOverlap; // Determines if the front matter includes a title module.exports.frontMatterHasTitle = @@ -6092,10 +6055,25 @@ module.exports = { -const { addErrorDetailIf, fencedCodeBlockStyleFor } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { addErrorDetailIf } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); const { getDescendantsByType } = __webpack_require__(/*! ../helpers/micromark-helpers.cjs */ "../helpers/micromark-helpers.cjs"); const { filterByTypesCached } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); +/** + * Return the string representation of a fence markup character. + * + * @param {string} markup Fence string. + * @returns {"tilde" | "backtick"} String representation. + */ +function fencedCodeBlockStyleFor(markup) { + switch (markup[0]) { + case "~": + return "tilde"; + default: + return "backtick"; + } +}; + // eslint-disable-next-line jsdoc/valid-types /** @type import("./markdownlint").Rule */ module.exports = { @@ -6138,11 +6116,26 @@ module.exports = { -const { addError, emphasisOrStrongStyleFor } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { addError } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); const { filterByPredicate, getDescendantsByType } = __webpack_require__(/*! ../helpers/micromark-helpers.cjs */ "../helpers/micromark-helpers.cjs"); const intrawordRe = /^\w$/; +/** + * Return the string representation of a emphasis or strong markup character. + * + * @param {string} markup Emphasis or strong string. + * @returns {"asterisk" | "underscore"} String representation. + */ +function emphasisOrStrongStyleFor(markup) { + switch (markup[0]) { + case "*": + return "asterisk"; + default: + return "underscore"; + } +}; + /** * @param {import("./markdownlint").RuleParams} params Rule parameters. * @param {import("./markdownlint").RuleOnError} onError Error-reporting callback. @@ -6486,10 +6479,11 @@ module.exports = { -const { addError, ellipsify, linkReferenceDefinitionRe } = - __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { addError, ellipsify } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); const { getReferenceLinkImageData } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); +const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/; + // eslint-disable-next-line jsdoc/valid-types /** @type import("./markdownlint").Rule */ module.exports = { diff --git a/helpers/helpers.js b/helpers/helpers.js index 9c7ae4e3..3c2720e2 100644 --- a/helpers/helpers.js +++ b/helpers/helpers.js @@ -21,10 +21,6 @@ const inlineCommentStartRe = /()/gi; module.exports.inlineCommentStartRe = inlineCommentStartRe; -// Regular expression for link reference definitions -const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/; -module.exports.linkReferenceDefinitionRe = linkReferenceDefinitionRe; - // Regular expression for identifying an HTML entity at the end of a line module.exports.endOfLineHtmlEntityRe = /&(?:#\d+|#[xX][\da-fA-F]+|[a-zA-Z]{2,31}|blk\d{2}|emsp1[34]|frac\d{2}|sup\d|there4);$/; @@ -222,38 +218,6 @@ module.exports.escapeForRegExp = function escapeForRegExp(str) { return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); }; -/** - * Return the string representation of a fence markup character. - * - * @param {string} markup Fence string. - * @returns {string} String representation. - */ -module.exports.fencedCodeBlockStyleFor = - function fencedCodeBlockStyleFor(markup) { - switch (markup[0]) { - case "~": - return "tilde"; - default: - return "backtick"; - } - }; - -/** - * Return the string representation of a emphasis or strong markup character. - * - * @param {string} markup Emphasis or strong string. - * @returns {"asterisk" | "underscore"} String representation. - */ -module.exports.emphasisOrStrongStyleFor = - function emphasisOrStrongStyleFor(markup) { - switch (markup[0]) { - case "*": - return "asterisk"; - default: - return "underscore"; - } - }; - /** * Adds ellipsis to the left/right/middle of the specified text. * @@ -376,13 +340,12 @@ const positionLessThanOrEqual = (lineA, columnA, lineB, columnB) => ( * @param {FileRange|import("../lib/markdownlint.js").MicromarkToken} rangeB Range B. * @returns {boolean} True iff the two ranges overlap. */ -const hasOverlap = (rangeA, rangeB) => { +module.exports.hasOverlap = function hasOverlap(rangeA, rangeB) { const lte = positionLessThanOrEqual(rangeA.startLine, rangeA.startColumn, rangeB.startLine, rangeB.startColumn); const first = lte ? rangeA : rangeB; const second = lte ? rangeB : rangeA; return positionLessThanOrEqual(second.startLine, second.startColumn, first.endLine, first.endColumn); }; -module.exports.hasOverlap = hasOverlap; // Determines if the front matter includes a title module.exports.frontMatterHasTitle = diff --git a/lib/md048.js b/lib/md048.js index 739f1f19..5b46833d 100644 --- a/lib/md048.js +++ b/lib/md048.js @@ -2,10 +2,25 @@ "use strict"; -const { addErrorDetailIf, fencedCodeBlockStyleFor } = require("../helpers"); +const { addErrorDetailIf } = require("../helpers"); const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs"); const { filterByTypesCached } = require("./cache"); +/** + * Return the string representation of a fence markup character. + * + * @param {string} markup Fence string. + * @returns {"tilde" | "backtick"} String representation. + */ +function fencedCodeBlockStyleFor(markup) { + switch (markup[0]) { + case "~": + return "tilde"; + default: + return "backtick"; + } +}; + // eslint-disable-next-line jsdoc/valid-types /** @type import("./markdownlint").Rule */ module.exports = { diff --git a/lib/md049-md050.js b/lib/md049-md050.js index ad9ef8c4..a117b077 100644 --- a/lib/md049-md050.js +++ b/lib/md049-md050.js @@ -2,11 +2,26 @@ "use strict"; -const { addError, emphasisOrStrongStyleFor } = require("../helpers"); +const { addError } = require("../helpers"); const { filterByPredicate, getDescendantsByType } = require("../helpers/micromark-helpers.cjs"); const intrawordRe = /^\w$/; +/** + * Return the string representation of a emphasis or strong markup character. + * + * @param {string} markup Emphasis or strong string. + * @returns {"asterisk" | "underscore"} String representation. + */ +function emphasisOrStrongStyleFor(markup) { + switch (markup[0]) { + case "*": + return "asterisk"; + default: + return "underscore"; + } +}; + /** * @param {import("./markdownlint").RuleParams} params Rule parameters. * @param {import("./markdownlint").RuleOnError} onError Error-reporting callback. diff --git a/lib/md053.js b/lib/md053.js index 2578dddd..67de4316 100644 --- a/lib/md053.js +++ b/lib/md053.js @@ -2,10 +2,11 @@ "use strict"; -const { addError, ellipsify, linkReferenceDefinitionRe } = - require("../helpers"); +const { addError, ellipsify } = require("../helpers"); const { getReferenceLinkImageData } = require("./cache"); +const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/; + // eslint-disable-next-line jsdoc/valid-types /** @type import("./markdownlint").Rule */ module.exports = {