Skip to content

Commit

Permalink
Move single use, not explicitly tested helpers into the file that use…
Browse files Browse the repository at this point in the history
…s them.
  • Loading branch information
DavidAnson committed Oct 7, 2024
1 parent df70ea5 commit c5d4a32
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 84 deletions.
78 changes: 36 additions & 42 deletions demo/markdownlint-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ const inlineCommentStartRe =
/(<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-line|disable-next-line|configure-file))(?:\s|-->)/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);$/;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 = {
Expand Down
39 changes: 1 addition & 38 deletions helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ const inlineCommentStartRe =
/(<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-line|disable-next-line|configure-file))(?:\s|-->)/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);$/;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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 =
Expand Down
17 changes: 16 additions & 1 deletion lib/md048.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
17 changes: 16 additions & 1 deletion lib/md049-md050.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions lib/md053.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit c5d4a32

Please sign in to comment.