diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index e7b0cce1..6d8b34ed 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -32,33 +32,33 @@ module.exports = webpackEmptyContext; // Regular expression for matching common newline characters // See NEWLINES_RE in markdown-it/lib/rules_core/normalize.js -var newLineRe = /\r\n?|\n/g; +const newLineRe = /\r\n?|\n/g; module.exports.newLineRe = newLineRe; // Regular expression for matching common front matter (YAML and TOML) module.exports.frontMatterRe = // eslint-disable-next-line max-len /((^---\s*$[^]*?^---\s*$)|(^\+\+\+\s*$[^]*?^(\+\+\+|\.\.\.)\s*$)|(^\{\s*$[^]*?^\}\s*$))(\r\n|\r|\n|$)/m; // Regular expression for matching the start of inline disable/enable comments -var inlineCommentStartRe = +const inlineCommentStartRe = // eslint-disable-next-line max-len /()/ig; module.exports.inlineCommentStartRe = inlineCommentStartRe; // Regular expression for matching HTML elements -var htmlElementRe = /<(([A-Za-z][A-Za-z0-9-]*)(?:\s[^>]*)?)\/?>/g; +const htmlElementRe = /<(([A-Za-z][A-Za-z0-9-]*)(?:\s[^>]*)?)\/?>/g; module.exports.htmlElementRe = htmlElementRe; // Regular expressions for range matching module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s\]"']*(?:\/|[^\s\]"'\W])/ig; module.exports.listItemMarkerRe = /^([\s>]*)(?:[*+-]|\d+[.)])\s+/; module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/; // Regular expression for all instances of emphasis markers -var emphasisMarkersRe = /[_*]/g; +const emphasisMarkersRe = /[_*]/g; // Regular expression for reference links (full and collapsed but not shortcut) -var referenceLinkRe = /!?\\?\[((?:\[[^\]]*]|[^\]])*)](?:(?:\[([^\]]*)\])|[^(]|$)/g; +const referenceLinkRe = /!?\\?\[((?:\[[^\]]*]|[^\]])*)](?:(?:\[([^\]]*)\])|[^(]|$)/g; // Regular expression for link reference definitions -var linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])]:/; +const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])]:/; module.exports.linkReferenceDefinitionRe = linkReferenceDefinitionRe; // All punctuation characters (normal and full-width) -var allPunctuation = ".,;:!?。,;:!?"; +const allPunctuation = ".,;:!?。,;:!?"; module.exports.allPunctuation = allPunctuation; // All punctuation characters without question mark (normal and full-width) module.exports.allPunctuationNoQuestion = allPunctuation.replace(/[??]/gu, ""); @@ -86,13 +86,13 @@ module.exports.isObject = function isObject(obj) { * @returns {boolean} True iff line is blank. */ function isBlankLine(line) { - var startComment = ""; - var removeComments = function (s) { + const startComment = ""; + const removeComments = (s) => { // eslint-disable-next-line no-constant-condition while (true) { - var start = s.indexOf(startComment); - var end = s.indexOf(endComment); + const start = s.indexOf(startComment); + const end = s.indexOf(endComment); if ((end !== -1) && ((start === -1) || (end < start))) { // Unmatched end comment is first s = s.slice(end + endComment.length); @@ -128,11 +128,11 @@ module.exports.numericSortAscending = function numericSortAscending(a, b) { }; // Returns true iff the sorted array contains the specified element module.exports.includesSorted = function includesSorted(array, element) { - var left = 0; - var right = array.length - 1; + let left = 0; + let right = array.length - 1; while (left <= right) { // eslint-disable-next-line no-bitwise - var mid = (left + right) >> 1; + const mid = (left + right) >> 1; if (array[mid] < element) { left = mid + 1; } @@ -149,32 +149,32 @@ module.exports.includesSorted = function includesSorted(array, element) { // This preserves the line/column information for the rest of the document // https://spec.commonmark.org/0.29/#html-blocks // https://spec.commonmark.org/0.29/#html-comment -var htmlCommentBegin = ""; +const htmlCommentBegin = ""; module.exports.clearHtmlCommentText = function clearHtmlCommentText(text) { - var i = 0; + let i = 0; while ((i = text.indexOf(htmlCommentBegin, i)) !== -1) { - var j = text.indexOf(htmlCommentEnd, i + 2); + const j = text.indexOf(htmlCommentEnd, i + 2); if (j === -1) { // Un-terminated comments are treated as text break; } // If the comment has content... if (j > i + htmlCommentBegin.length) { - var k = i - 1; + let k = i - 1; while (text[k] === " ") { k--; } // If comment is not within an indented code block... if (k >= i - 4) { - var content = text.slice(i + htmlCommentBegin.length, j); - var isBlock = (k < 0) || (text[k] === "\n"); - var isValid = isBlock || + const content = text.slice(i + htmlCommentBegin.length, j); + const isBlock = (k < 0) || (text[k] === "\n"); + const isValid = isBlock || (!content.startsWith(">") && !content.startsWith("->") && !content.endsWith("-") && !content.includes("--")); // If a valid block/inline comment... if (isValid) { - var inlineCommentIndex = text + const inlineCommentIndex = text .slice(i, j + htmlCommentEnd.length) .search(inlineCommentStartRe); // If not a markdownlint inline directive... @@ -196,11 +196,11 @@ module.exports.escapeForRegExp = function escapeForRegExp(str) { return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); }; // Un-escapes Markdown content (simple algorithm; not a parser) -var escapedMarkdownRe = /\\./g; +const escapedMarkdownRe = /\\./g; module.exports.unescapeMarkdown = function unescapeMarkdown(markdown, replacement) { - return markdown.replace(escapedMarkdownRe, function (match) { - var char = match[1]; + return markdown.replace(escapedMarkdownRe, (match) => { + const char = match[1]; if ("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~".includes(char)) { return replacement || char; } @@ -244,7 +244,7 @@ module.exports.emphasisOrStrongStyleFor = * @returns {number} Characters of indent. */ function indentFor(token) { - var line = token.line.replace(/^[\s>]*(> |>)/, ""); + const line = token.line.replace(/^[\s>]*(> |>)/, ""); return line.length - line.trimStart().length; } module.exports.indentFor = indentFor; @@ -305,36 +305,36 @@ function isMathBlock(token) { module.exports.isMathBlock = isMathBlock; // Get line metadata array module.exports.getLineMetadata = function getLineMetadata(params) { - var lineMetadata = params.lines.map(function (line, index) { return [line, index, false, 0, false, false, false, false]; }); - filterTokens(params, "fence", function (token) { + const lineMetadata = params.lines.map((line, index) => [line, index, false, 0, false, false, false, false]); + filterTokens(params, "fence", (token) => { lineMetadata[token.map[0]][3] = 1; lineMetadata[token.map[1] - 1][3] = -1; - for (var i = token.map[0] + 1; i < token.map[1] - 1; i++) { + for (let i = token.map[0] + 1; i < token.map[1] - 1; i++) { lineMetadata[i][2] = true; } }); - filterTokens(params, "code_block", function (token) { - for (var i = token.map[0]; i < token.map[1]; i++) { + filterTokens(params, "code_block", (token) => { + for (let i = token.map[0]; i < token.map[1]; i++) { lineMetadata[i][2] = true; } }); - filterTokens(params, "table_open", function (token) { - for (var i = token.map[0]; i < token.map[1]; i++) { + filterTokens(params, "table_open", (token) => { + for (let i = token.map[0]; i < token.map[1]; i++) { lineMetadata[i][4] = true; } }); - filterTokens(params, "list_item_open", function (token) { - var count = 1; - for (var i = token.map[0]; i < token.map[1]; i++) { + filterTokens(params, "list_item_open", (token) => { + let count = 1; + for (let i = token.map[0]; i < token.map[1]; i++) { lineMetadata[i][5] = count; count++; } }); - filterTokens(params, "hr", function (token) { + filterTokens(params, "hr", (token) => { lineMetadata[token.map[0]][6] = true; }); - params.tokens.filter(isMathBlock).forEach(function (token) { - for (var i = token.map[0]; i < token.map[1]; i++) { + params.tokens.filter(isMathBlock).forEach((token) => { + for (let i = token.map[0]; i < token.map[1]; i++) { lineMetadata[i][7] = true; } }); @@ -350,19 +350,19 @@ module.exports.getLineMetadata = function getLineMetadata(params) { */ function forEachLine(lineMetadata, handler) { lineMetadata.forEach(function forMetadata(metadata) { - handler.apply(void 0, metadata); + handler(...metadata); }); } module.exports.forEachLine = forEachLine; // Returns (nested) lists as a flat array (in order) module.exports.flattenLists = function flattenLists(tokens) { - var flattenedLists = []; - var stack = []; - var current = null; - var nesting = 0; - var nestingStack = []; - var lastWithMap = { "map": [0, 1] }; - tokens.forEach(function (token) { + const flattenedLists = []; + const stack = []; + let current = null; + let nesting = 0; + const nestingStack = []; + let lastWithMap = { "map": [0, 1] }; + tokens.forEach((token) => { if ((token.type === "bullet_list_open") || (token.type === "ordered_list_open")) { // Save current context and start a new one @@ -421,7 +421,7 @@ module.exports.forEachInlineChild = }; // Calls the provided function for each heading's content module.exports.forEachHeading = function forEachHeading(params, handler) { - var heading = null; + let heading = null; params.tokens.forEach(function forToken(token) { if (token.type === "heading_open") { heading = token; @@ -443,20 +443,20 @@ module.exports.forEachHeading = function forEachHeading(params, handler) { * @returns {void} */ function forEachInlineCodeSpan(input, handler) { - var currentLine = 0; - var currentColumn = 0; - var index = 0; + let currentLine = 0; + let currentColumn = 0; + let index = 0; while (index < input.length) { - var startIndex = -1; - var startLine = -1; - var startColumn = -1; - var tickCount = 0; - var currentTicks = 0; - var state = "normal"; + let startIndex = -1; + let startLine = -1; + let startColumn = -1; + let tickCount = 0; + let currentTicks = 0; + let state = "normal"; // Deliberate <= so trailing 0 completes the last span (ex: "text `code`") // False-positive for js/index-out-of-bounds for (; index <= input.length; index++) { - var char = input[index]; + const char = input[index]; // Ignore backticks in link destination if ((char === "[") && (state === "normal")) { state = "linkTextOpen"; @@ -561,11 +561,11 @@ module.exports.ellipsify = ellipsify; */ function addError(onError, lineNumber, detail, context, range, fixInfo) { onError({ - lineNumber: lineNumber, - detail: detail, - context: context, - range: range, - fixInfo: fixInfo + lineNumber, + detail, + context, + range, + fixInfo }); } module.exports.addError = addError; @@ -588,27 +588,27 @@ module.exports.addErrorContext = function addErrorContext(onError, lineNumber, c * @param {Object} lineMetadata Line metadata object. * @returns {number[][]} Array of ranges (lineIndex, columnIndex, length). */ -module.exports.codeBlockAndSpanRanges = function (params, lineMetadata) { - var exclusions = []; +module.exports.codeBlockAndSpanRanges = (params, lineMetadata) => { + const exclusions = []; // Add code block ranges (excludes fences) - forEachLine(lineMetadata, function (line, lineIndex, inCode, onFence) { + forEachLine(lineMetadata, (line, lineIndex, inCode, onFence) => { if (inCode && !onFence) { exclusions.push([lineIndex, 0, line.length]); } }); // Add code span ranges (excludes ticks) - filterTokens(params, "inline", function (token) { - if (token.children.some(function (child) { return child.type === "code_inline"; })) { - var tokenLines = params.lines.slice(token.map[0], token.map[1]); - forEachInlineCodeSpan(tokenLines.join("\n"), function (code, lineIndex, columnIndex) { - var codeLines = code.split(newLineRe); - codeLines.forEach(function (line, i) { + filterTokens(params, "inline", (token) => { + if (token.children.some((child) => child.type === "code_inline")) { + const tokenLines = params.lines.slice(token.map[0], token.map[1]); + forEachInlineCodeSpan(tokenLines.join("\n"), (code, lineIndex, columnIndex) => { + const codeLines = code.split(newLineRe); + for (const [i, line] of codeLines.entries()) { exclusions.push([ token.lineNumber - 1 + lineIndex + i, i ? 0 : columnIndex, line.length ]); - }); + } }); } }); @@ -621,10 +621,10 @@ module.exports.codeBlockAndSpanRanges = function (params, lineMetadata) { * @param {Object} lineMetadata Line metadata object. * @returns {number[][]} Array of ranges (lineIndex, columnIndex, length). */ -module.exports.htmlElementRanges = function (params, lineMetadata) { - var exclusions = []; - forEachLine(lineMetadata, function (line, lineIndex, inCode) { - var match = null; +module.exports.htmlElementRanges = (params, lineMetadata) => { + const exclusions = []; + forEachLine(lineMetadata, (line, lineIndex, inCode) => { + let match = null; // eslint-disable-next-line no-unmodified-loop-condition while (!inCode && ((match = htmlElementRe.exec(line)) !== null)) { exclusions.push([lineIndex, match.index, match[0].length]); @@ -641,9 +641,9 @@ module.exports.htmlElementRanges = function (params, lineMetadata) { * @param {number} length Length to check. * @returns {boolean} True iff the specified range overlaps. */ -module.exports.overlapsAnyRange = function (ranges, lineIndex, index, length) { return (!ranges.every(function (span) { return ((lineIndex !== span[0]) || +module.exports.overlapsAnyRange = (ranges, lineIndex, index, length) => (!ranges.every((span) => ((lineIndex !== span[0]) || (index + length < span[1]) || - (index > span[1] + span[2])); })); }; + (index > span[1] + span[2])))); /** * Determines whether the specified range is within another range. * @@ -653,16 +653,16 @@ module.exports.overlapsAnyRange = function (ranges, lineIndex, index, length) { * @param {number} length Length to check. * @returns {boolean} True iff the specified range is within. */ -var withinAnyRange = function (ranges, lineIndex, index, length) { return (!ranges.every(function (span) { return ((lineIndex !== span[0]) || +const withinAnyRange = (ranges, lineIndex, index, length) => (!ranges.every((span) => ((lineIndex !== span[0]) || (index < span[1]) || - (index + length > span[1] + span[2])); })); }; + (index + length > span[1] + span[2])))); // Returns a range object for a line by applying a RegExp module.exports.rangeFromRegExp = function rangeFromRegExp(line, regexp) { - var range = null; - var match = line.match(regexp); + let range = null; + const match = line.match(regexp); if (match) { - var column = match.index + 1; - var length = match[0].length; + const column = match.index + 1; + const length = match[0].length; range = [column, length]; } return range; @@ -670,10 +670,10 @@ module.exports.rangeFromRegExp = function rangeFromRegExp(line, regexp) { // Determines if the front matter includes a title module.exports.frontMatterHasTitle = function frontMatterHasTitle(frontMatterLines, frontMatterTitlePattern) { - var ignoreFrontMatter = (frontMatterTitlePattern !== undefined) && !frontMatterTitlePattern; - var frontMatterTitleRe = new RegExp(String(frontMatterTitlePattern || "^\\s*\"?title\"?\\s*[:=]"), "i"); + const ignoreFrontMatter = (frontMatterTitlePattern !== undefined) && !frontMatterTitlePattern; + const frontMatterTitleRe = new RegExp(String(frontMatterTitlePattern || "^\\s*\"?title\"?\\s*[:=]"), "i"); return !ignoreFrontMatter && - frontMatterLines.some(function (line) { return frontMatterTitleRe.test(line); }); + frontMatterLines.some((line) => frontMatterTitleRe.test(line)); }; /** * Calls the provided function for each link. @@ -684,14 +684,14 @@ module.exports.frontMatterHasTitle = */ function forEachLink(line, handler) { // Helper to find matching close symbol for link text/destination - var findClosingSymbol = function (index) { - var begin = line[index]; - var end = (begin === "[") ? "]" : ")"; - var nesting = 0; - var escaping = false; - var pointy = false; - for (var i = index + 1; i < line.length; i++) { - var current = line[i]; + const findClosingSymbol = (index) => { + const begin = line[index]; + const end = (begin === "[") ? "]" : ")"; + let nesting = 0; + let escaping = false; + let pointy = false; + for (let i = index + 1; i < line.length; i++) { + const current = line[i]; if (current === "\\") { escaping = !escaping; } @@ -722,31 +722,31 @@ function forEachLink(line, handler) { return -1; }; // Scan line for unescaped "[" character - var escaping = false; - for (var i = 0; i < line.length; i++) { - var current = line[i]; + let escaping = false; + for (let i = 0; i < line.length; i++) { + const current = line[i]; if (current === "\\") { escaping = !escaping; } else if (!escaping && (current === "[")) { // Scan for matching close "]" of link text - var textEnd = findClosingSymbol(i); + const textEnd = findClosingSymbol(i); if (textEnd !== -1) { if ((line[textEnd] === "(") || (line[textEnd] === "[")) { // Scan for matching close ")" or "]" of link destination - var destEnd = findClosingSymbol(textEnd); + const destEnd = findClosingSymbol(textEnd); if (destEnd !== -1) { // Call handler with link text and destination - var link = line.slice(i, destEnd); - var text = line.slice(i, textEnd); - var dest = line.slice(textEnd, destEnd); + const link = line.slice(i, destEnd); + const text = line.slice(i, textEnd); + const dest = line.slice(textEnd, destEnd); handler(i, link, text, dest); i = destEnd; } } if (i < textEnd) { // Call handler with link text only - var text = line.slice(i, textEnd); + const text = line.slice(i, textEnd); handler(i, text, text); i = textEnd; } @@ -765,13 +765,13 @@ module.exports.forEachLink = forEachLink; * @returns {number[][]} List of markers. */ function emphasisMarkersInContent(params) { - var lines = params.lines; - var byLine = new Array(lines.length); + const { lines } = params; + const byLine = new Array(lines.length); // Search links - lines.forEach(function (tokenLine, tokenLineIndex) { - var inLine = []; - forEachLink(tokenLine, function (index, match) { - var markerMatch = null; + lines.forEach((tokenLine, tokenLineIndex) => { + const inLine = []; + forEachLink(tokenLine, (index, match) => { + let markerMatch = null; while ((markerMatch = emphasisMarkersRe.exec(match))) { inLine.push(index + markerMatch.index); } @@ -779,17 +779,17 @@ function emphasisMarkersInContent(params) { byLine[tokenLineIndex] = inLine; }); // Search code spans - filterTokens(params, "inline", function (token) { - var children = token.children, lineNumber = token.lineNumber, map = token.map; - if (children.some(function (child) { return child.type === "code_inline"; })) { - var tokenLines = lines.slice(map[0], map[1]); - forEachInlineCodeSpan(tokenLines.join("\n"), function (code, lineIndex, column, tickCount) { - var codeLines = code.split(newLineRe); - codeLines.forEach(function (codeLine, codeLineIndex) { - var byLineIndex = lineNumber - 1 + lineIndex + codeLineIndex; - var inLine = byLine[byLineIndex]; - var codeLineOffset = codeLineIndex ? 0 : column - 1 + tickCount; - var match = null; + filterTokens(params, "inline", (token) => { + const { children, lineNumber, map } = token; + if (children.some((child) => child.type === "code_inline")) { + const tokenLines = lines.slice(map[0], map[1]); + forEachInlineCodeSpan(tokenLines.join("\n"), (code, lineIndex, column, tickCount) => { + const codeLines = code.split(newLineRe); + codeLines.forEach((codeLine, codeLineIndex) => { + const byLineIndex = lineNumber - 1 + lineIndex + codeLineIndex; + const inLine = byLine[byLineIndex]; + const codeLineOffset = codeLineIndex ? 0 : column - 1 + tickCount; + let match = null; while ((match = emphasisMarkersRe.exec(codeLine))) { inLine.push(codeLineOffset + match.index); } @@ -810,19 +810,19 @@ module.exports.emphasisMarkersInContent = emphasisMarkersInContent; */ function getReferenceLinkImageData(params, lineMetadata) { // Initialize return values - var references = new Map(); - var shortcuts = new Set(); - var definitions = new Map(); - var duplicateDefinitions = []; + const references = new Map(); + const shortcuts = new Set(); + const definitions = new Map(); + const duplicateDefinitions = []; // Define helper functions - var normalizeLabel = function (s) { return s.toLowerCase().trim().replace(/\s+/g, " "); }; - var exclusions = []; - var excluded = function (match) { return withinAnyRange(exclusions, 0, match.index, match[0].length); }; + const normalizeLabel = (s) => s.toLowerCase().trim().replace(/\s+/g, " "); + const exclusions = []; + const excluded = (match) => withinAnyRange(exclusions, 0, match.index, match[0].length); // Convert input to single-line so multi-line links/images are easier - var lineOffsets = []; - var currentOffset = 0; - var contentLines = []; - forEachLine(lineMetadata, function (line, lineIndex, inCode) { + const lineOffsets = []; + let currentOffset = 0; + const contentLines = []; + forEachLine(lineMetadata, (line, lineIndex, inCode) => { lineOffsets[lineIndex] = currentOffset; if (!inCode) { if (line.trim().length === 0) { @@ -834,17 +834,17 @@ function getReferenceLinkImageData(params, lineMetadata) { } }); lineOffsets.push(currentOffset); - var contentLine = contentLines.join(" "); + const contentLine = contentLines.join(" "); // Determine single-line exclusions for inline code spans - forEachInlineCodeSpan(contentLine, function (code, lineIndex, columnIndex) { + forEachInlineCodeSpan(contentLine, (code, lineIndex, columnIndex) => { exclusions.push([0, columnIndex, code.length]); }); // Identify all link/image reference definitions - forEachLine(lineMetadata, function (line, lineIndex, inCode) { + forEachLine(lineMetadata, (line, lineIndex, inCode) => { if (!inCode) { - var linkReferenceDefinitionMatch = linkReferenceDefinitionRe.exec(line); + const linkReferenceDefinitionMatch = linkReferenceDefinitionRe.exec(line); if (linkReferenceDefinitionMatch) { - var label = normalizeLabel(linkReferenceDefinitionMatch[1]); + const label = normalizeLabel(linkReferenceDefinitionMatch[1]); if (definitions.has(label)) { duplicateDefinitions.push([label, lineIndex]); } @@ -856,8 +856,8 @@ function getReferenceLinkImageData(params, lineMetadata) { } }); // Identify all link and image references - var lineIndex = 0; - var pendingContents = [ + let lineIndex = 0; + const pendingContents = [ { "content": contentLine, "contentLineIndex": 0, @@ -865,28 +865,28 @@ function getReferenceLinkImageData(params, lineMetadata) { "topLevel": true } ]; - var pendingContent = null; + let pendingContent = null; while ((pendingContent = pendingContents.shift())) { - var content = pendingContent.content, contentLineIndex = pendingContent.contentLineIndex, contentIndex = pendingContent.contentIndex, topLevel = pendingContent.topLevel; - var referenceLinkMatch = null; + const { content, contentLineIndex, contentIndex, topLevel } = pendingContent; + let referenceLinkMatch = null; while ((referenceLinkMatch = referenceLinkRe.exec(content)) !== null) { - var matchString = referenceLinkMatch[0], matchText = referenceLinkMatch[1], matchLabel = referenceLinkMatch[2]; + const [matchString, matchText, matchLabel] = referenceLinkMatch; if (!matchString.startsWith("\\") && !matchString.startsWith("!\\") && !matchText.endsWith("\\") && !(matchLabel || "").endsWith("\\") && (topLevel || matchString.startsWith("!")) && !excluded(referenceLinkMatch)) { - var shortcutLink = (matchLabel === undefined); - var collapsedLink = (!shortcutLink && (matchLabel.length === 0)); - var label = normalizeLabel((shortcutLink || collapsedLink) ? matchText : matchLabel); + const shortcutLink = (matchLabel === undefined); + const collapsedLink = (!shortcutLink && (matchLabel.length === 0)); + const label = normalizeLabel((shortcutLink || collapsedLink) ? matchText : matchLabel); if (label.length > 0) { if (shortcutLink) { // Track, but don't validate due to ambiguity: "text [text] text" shortcuts.add(label); } else { - var referenceindex = referenceLinkMatch.index; + const referenceindex = referenceLinkMatch.index; if (topLevel) { // Calculate line index while (lineOffsets[lineIndex + 1] <= referenceindex) { @@ -897,10 +897,10 @@ function getReferenceLinkImageData(params, lineMetadata) { // Use provided line index lineIndex = contentLineIndex; } - var referenceIndex = referenceindex + + const referenceIndex = referenceindex + (topLevel ? -lineOffsets[lineIndex] : contentIndex); // Track reference and location - var referenceData = references.get(label) || []; + const referenceData = references.get(label) || []; referenceData.push([ lineIndex, referenceIndex, @@ -922,10 +922,10 @@ function getReferenceLinkImageData(params, lineMetadata) { } } return { - references: references, - shortcuts: shortcuts, - definitions: definitions, - duplicateDefinitions: duplicateDefinitions + references, + shortcuts, + definitions, + duplicateDefinitions }; } module.exports.getReferenceLinkImageData = getReferenceLinkImageData; @@ -937,11 +937,11 @@ module.exports.getReferenceLinkImageData = getReferenceLinkImageData; * @returns {string} Preferred line ending. */ function getPreferredLineEnding(input, os) { - var cr = 0; - var lf = 0; - var crlf = 0; - var endings = input.match(newLineRe) || []; - endings.forEach(function (ending) { + let cr = 0; + let lf = 0; + let crlf = 0; + const endings = input.match(newLineRe) || []; + endings.forEach((ending) => { // eslint-disable-next-line default-case switch (ending) { case "\r": @@ -955,7 +955,7 @@ function getPreferredLineEnding(input, os) { break; } }); - var preferredLineEnding = null; + let preferredLineEnding = null; if (!cr && !lf && !crlf) { preferredLineEnding = (os && os.EOL) || "\n"; } @@ -995,8 +995,8 @@ function normalizeFixInfo(fixInfo, lineNumber) { * @returns {string} Fixed content. */ function applyFix(line, fixInfo, lineEnding) { - var _a = normalizeFixInfo(fixInfo), editColumn = _a.editColumn, deleteCount = _a.deleteCount, insertText = _a.insertText; - var editIndex = editColumn - 1; + const { editColumn, deleteCount, insertText } = normalizeFixInfo(fixInfo); + const editIndex = editColumn - 1; return (deleteCount === -1) ? null : line.slice(0, editIndex) + @@ -1012,25 +1012,25 @@ module.exports.applyFix = applyFix; * @returns {string} Corrected content. */ function applyFixes(input, errors) { - var lineEnding = getPreferredLineEnding(input, __webpack_require__(/*! os */ "?591e")); - var lines = input.split(newLineRe); + const lineEnding = getPreferredLineEnding(input, __webpack_require__(/*! os */ "?591e")); + const lines = input.split(newLineRe); // Normalize fixInfo objects - var fixInfos = errors - .filter(function (error) { return error.fixInfo; }) - .map(function (error) { return normalizeFixInfo(error.fixInfo, error.lineNumber); }); + let fixInfos = errors + .filter((error) => error.fixInfo) + .map((error) => normalizeFixInfo(error.fixInfo, error.lineNumber)); // Sort bottom-to-top, line-deletes last, right-to-left, long-to-short - fixInfos.sort(function (a, b) { - var aDeletingLine = (a.deleteCount === -1); - var bDeletingLine = (b.deleteCount === -1); + fixInfos.sort((a, b) => { + const aDeletingLine = (a.deleteCount === -1); + const bDeletingLine = (b.deleteCount === -1); return ((b.lineNumber - a.lineNumber) || (aDeletingLine ? 1 : (bDeletingLine ? -1 : 0)) || (b.editColumn - a.editColumn) || (b.insertText.length - a.insertText.length)); }); // Remove duplicate entries (needed for following collapse step) - var lastFixInfo = {}; - fixInfos = fixInfos.filter(function (fixInfo) { - var unique = ((fixInfo.lineNumber !== lastFixInfo.lineNumber) || + let lastFixInfo = {}; + fixInfos = fixInfos.filter((fixInfo) => { + const unique = ((fixInfo.lineNumber !== lastFixInfo.lineNumber) || (fixInfo.editColumn !== lastFixInfo.editColumn) || (fixInfo.deleteCount !== lastFixInfo.deleteCount) || (fixInfo.insertText !== lastFixInfo.insertText)); @@ -1039,7 +1039,7 @@ function applyFixes(input, errors) { }); // Collapse insert/no-delete and no-insert/delete for same line/column lastFixInfo = {}; - fixInfos.forEach(function (fixInfo) { + fixInfos.forEach((fixInfo) => { if ((fixInfo.lineNumber === lastFixInfo.lineNumber) && (fixInfo.editColumn === lastFixInfo.editColumn) && !fixInfo.insertText && @@ -1051,14 +1051,14 @@ function applyFixes(input, errors) { } lastFixInfo = fixInfo; }); - fixInfos = fixInfos.filter(function (fixInfo) { return fixInfo.lineNumber; }); + fixInfos = fixInfos.filter((fixInfo) => fixInfo.lineNumber); // Apply all (remaining/updated) fixes - var lastLineIndex = -1; - var lastEditIndex = -1; - fixInfos.forEach(function (fixInfo) { - var lineNumber = fixInfo.lineNumber, editColumn = fixInfo.editColumn, deleteCount = fixInfo.deleteCount; - var lineIndex = lineNumber - 1; - var editIndex = editColumn - 1; + let lastLineIndex = -1; + let lastEditIndex = -1; + fixInfos.forEach((fixInfo) => { + const { lineNumber, editColumn, deleteCount } = fixInfo; + const lineIndex = lineNumber - 1; + const editIndex = editColumn - 1; if ((lineIndex !== lastLineIndex) || (deleteCount === -1) || ((editIndex + deleteCount) <= @@ -1069,7 +1069,7 @@ function applyFixes(input, errors) { lastEditIndex = editIndex; }); // Return corrected input - return lines.filter(function (line) { return line !== null; }).join(lineEnding); + return lines.filter((line) => line !== null).join(lineEnding); } module.exports.applyFixes = applyFixes; /** @@ -1084,18 +1084,17 @@ module.exports.applyFixes = applyFixes; * @returns {Object} Range and fixInfo wrapper. */ module.exports.getRangeAndFixInfoIfFound = - function (lines, lineIndex, search, replace, instance) { - if (instance === void 0) { instance = 1; } - var range = null; - var fixInfo = null; - var searchIndex = -1; + (lines, lineIndex, search, replace, instance = 1) => { + let range = null; + let fixInfo = null; + let searchIndex = -1; while (instance > 0) { searchIndex = lines[lineIndex].indexOf(search, searchIndex + 1); instance--; } if (searchIndex !== -1) { - var column = searchIndex + 1; - var length = search.length; + const column = searchIndex + 1; + const length = search.length; range = [column, length]; fixInfo = { "editColumn": column, @@ -1104,8 +1103,8 @@ module.exports.getRangeAndFixInfoIfFound = }; } return { - range: range, - fixInfo: fixInfo + range, + fixInfo }; }; /** @@ -1118,8 +1117,8 @@ module.exports.getRangeAndFixInfoIfFound = * @returns {Object} Next token. */ function getNextChildToken(parentToken, childToken, nextType, nextNextType) { - var children = parentToken.children; - var index = children.indexOf(childToken); + const { children } = parentToken; + const index = children.indexOf(childToken); if ((index !== -1) && (children.length > index + 2) && (children[index + 1].type === nextType) && @@ -1136,13 +1135,12 @@ module.exports.getNextChildToken = getNextChildToken; * @returns {Object} Object passed to the function. */ function deepFreeze(obj) { - var pending = [obj]; - var current = null; + const pending = [obj]; + let current = null; while ((current = pending.shift())) { Object.freeze(current); - for (var _i = 0, _a = Object.getOwnPropertyNames(current); _i < _a.length; _i++) { - var name = _a[_i]; - var value = current[name]; + for (const name of Object.getOwnPropertyNames(current)) { + const value = current[name]; if (value && (typeof value === "object")) { pending.push(value); } @@ -1159,8 +1157,8 @@ module.exports.deepFreeze = deepFreeze; * @returns {string} Absolute path (or original path). */ function expandTildePath(file, os) { - var homedir = os && os.homedir(); - return homedir ? file.replace(/^~($|\/|\\)/, "".concat(homedir, "$1")) : file; + const homedir = os && os.homedir(); + return homedir ? file.replace(/^~($|\/|\\)/, `${homedir}$1`) : file; } module.exports.expandTildePath = expandTildePath; @@ -1237,24 +1235,23 @@ module.exports = markdownit; "use strict"; // @ts-check -var map = new Map(); -module.exports.set = function (keyValuePairs) { - for (var _i = 0, _a = Object.entries(keyValuePairs); _i < _a.length; _i++) { - var _b = _a[_i], key = _b[0], value = _b[1]; +const map = new Map(); +module.exports.set = (keyValuePairs) => { + for (const [key, value] of Object.entries(keyValuePairs)) { map.set(key, value); } }; -module.exports.clear = function () { return map.clear(); }; +module.exports.clear = () => map.clear(); module.exports.codeBlockAndSpanRanges = - function () { return map.get("codeBlockAndSpanRanges"); }; + () => map.get("codeBlockAndSpanRanges"); module.exports.flattenedLists = - function () { return map.get("flattenedLists"); }; + () => map.get("flattenedLists"); module.exports.htmlElementRanges = - function () { return map.get("htmlElementRanges"); }; + () => map.get("htmlElementRanges"); module.exports.lineMetadata = - function () { return map.get("lineMetadata"); }; + () => map.get("lineMetadata"); module.exports.referenceLinkImageData = - function () { return map.get("referenceLinkImageData"); }; + () => map.get("referenceLinkImageData"); /***/ }), @@ -1279,41 +1276,21 @@ module.exports.version = "0.25.1"; /*!******************************!*\ !*** ../lib/markdownlint.js ***! \******************************/ -/***/ (function(module, __unused_webpack_exports, __webpack_require__) { +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; // @ts-check -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; -var path = __webpack_require__(/*! path */ "?b85c"); -var promisify = (__webpack_require__(/*! util */ "?96a2").promisify); -var markdownIt = __webpack_require__(/*! markdown-it */ "markdown-it"); -var deprecatedRuleNames = (__webpack_require__(/*! ./constants */ "../lib/constants.js").deprecatedRuleNames); -var rules = __webpack_require__(/*! ./rules */ "../lib/rules.js"); -var helpers = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -var cache = __webpack_require__(/*! ./cache */ "../lib/cache.js"); +const path = __webpack_require__(/*! path */ "?b85c"); +const { promisify } = __webpack_require__(/*! util */ "?96a2"); +const markdownIt = __webpack_require__(/*! markdown-it */ "markdown-it"); +const { deprecatedRuleNames } = __webpack_require__(/*! ./constants */ "../lib/constants.js"); +const rules = __webpack_require__(/*! ./rules */ "../lib/rules.js"); +const helpers = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const cache = __webpack_require__(/*! ./cache */ "../lib/cache.js"); // @ts-ignore // eslint-disable-next-line camelcase, max-len, no-inline-comments, no-undef -var dynamicRequire = (typeof require === "undefined") ? __webpack_require__("../lib sync recursive") : /* c8 ignore next */ require; +const dynamicRequire = (typeof require === "undefined") ? __webpack_require__("../lib sync recursive") : /* c8 ignore next */ require; // Capture native require implementation for dynamic loading of modules /** * Validate the list of rules for structure and reuse. @@ -1323,21 +1300,21 @@ var dynamicRequire = (typeof require === "undefined") ? __webpack_require__("../ * @returns {string} Error message if validation fails. */ function validateRuleList(ruleList, synchronous) { - var result = null; + let result = null; if (ruleList.length === rules.length) { // No need to validate if only using built-in rules return result; } - var allIds = {}; + const allIds = {}; ruleList.forEach(function forRule(rule, index) { - var customIndex = index - rules.length; + const customIndex = index - rules.length; // eslint-disable-next-line jsdoc/require-jsdoc function newError(property) { return new Error("Property '" + property + "' of custom rule at index " + customIndex + " is incorrect."); } ["names", "tags"].forEach(function forProperty(property) { - var value = rule[property]; + const value = rule[property]; if (!result && (!value || !Array.isArray(value) || (value.length === 0) || !value.every(helpers.isString) || value.some(helpers.isEmptyString))) { @@ -1348,8 +1325,8 @@ function validateRuleList(ruleList, synchronous) { ["description", "string"], ["function", "function"] ].forEach(function forProperty(propertyInfo) { - var property = propertyInfo[0]; - var value = rule[property]; + const property = propertyInfo[0]; + const value = rule[property]; if (!result && (!value || (typeof value !== propertyInfo[1]))) { result = newError(property); } @@ -1370,7 +1347,7 @@ function validateRuleList(ruleList, synchronous) { } if (!result) { rule.names.forEach(function forName(name) { - var nameUpper = name.toUpperCase(); + const nameUpper = name.toUpperCase(); if (!result && (allIds[nameUpper] !== undefined)) { result = new Error("Name '" + name + "' of custom rule at index " + customIndex + " is already used as a name or tag."); @@ -1378,7 +1355,7 @@ function validateRuleList(ruleList, synchronous) { allIds[nameUpper] = true; }); rule.tags.forEach(function forTag(tag) { - var tagUpper = tag.toUpperCase(); + const tagUpper = tag.toUpperCase(); if (!result && allIds[tagUpper]) { result = new Error("Tag '" + tag + "' of custom rule at index " + customIndex + " is already used as a name."); @@ -1396,18 +1373,18 @@ function validateRuleList(ruleList, synchronous) { * @returns {LintResults} New LintResults instance. */ function newResults(ruleList) { - var lintResults = {}; + const lintResults = {}; // eslint-disable-next-line jsdoc/require-jsdoc function toString(useAlias) { - var ruleNameToRule = null; - var results = []; - var keys = Object.keys(lintResults); + let ruleNameToRule = null; + const results = []; + const keys = Object.keys(lintResults); keys.sort(); keys.forEach(function forFile(file) { - var fileResults = lintResults[file]; + const fileResults = lintResults[file]; if (Array.isArray(fileResults)) { fileResults.forEach(function forResult(result) { - var ruleMoniker = result.ruleNames ? + const ruleMoniker = result.ruleNames ? result.ruleNames.join("/") : (result.ruleName + "/" + result.ruleAlias); results.push(file + ": " + @@ -1426,16 +1403,16 @@ function newResults(ruleList) { if (!ruleNameToRule) { ruleNameToRule = {}; ruleList.forEach(function forRule(rule) { - var ruleName = rule.names[0].toUpperCase(); + const ruleName = rule.names[0].toUpperCase(); ruleNameToRule[ruleName] = rule; }); } Object.keys(fileResults).forEach(function forRule(ruleName) { - var rule = ruleNameToRule[ruleName.toUpperCase()]; - var ruleResults = fileResults[ruleName]; + const rule = ruleNameToRule[ruleName.toUpperCase()]; + const ruleResults = fileResults[ruleName]; ruleResults.forEach(function forLine(lineNumber) { - var nameIndex = Math.min(useAlias ? 1 : 0, rule.names.length - 1); - var result = file + ": " + + const nameIndex = Math.min(useAlias ? 1 : 0, rule.names.length - 1); + const result = file + ": " + lineNumber + ": " + rule.names[nameIndex] + " " + rule.description; @@ -1458,11 +1435,11 @@ function newResults(ruleList) { * @returns {Object} Trimmed content and front matter lines. */ function removeFrontMatter(content, frontMatter) { - var frontMatterLines = []; + let frontMatterLines = []; if (frontMatter) { - var frontMatterMatch = content.match(frontMatter); + const frontMatterMatch = content.match(frontMatter); if (frontMatterMatch && !frontMatterMatch.index) { - var contentMatched = frontMatterMatch[0]; + const contentMatched = frontMatterMatch[0]; content = content.slice(contentMatched.length); frontMatterLines = contentMatched.split(helpers.newLineRe); if ((frontMatterLines.length > 0) && @@ -1484,7 +1461,7 @@ function removeFrontMatter(content, frontMatter) { * @returns {void} */ function annotateTokens(tokens, lines) { - var trMap = null; + let trMap = null; tokens.forEach(function forToken(token) { // Provide missing maps for table content if (token.type === "tr_open") { @@ -1494,7 +1471,7 @@ function annotateTokens(tokens, lines) { trMap = null; } if (!token.map && trMap) { - token.map = __spreadArray([], trMap, true); + token.map = [...trMap]; } // Adjust maps for math blocks if (helpers.isMathBlock(token) && token.map[1]) { @@ -1510,19 +1487,19 @@ function annotateTokens(tokens, lines) { token.map[1]--; } // Annotate children with lineNumber - var lineNumber_1 = token.lineNumber; - var codeSpanExtraLines_1 = []; + let lineNumber = token.lineNumber; + const codeSpanExtraLines = []; helpers.forEachInlineCodeSpan(token.content, function handleInlineCodeSpan(code) { - codeSpanExtraLines_1.push(code.split(helpers.newLineRe).length - 1); + codeSpanExtraLines.push(code.split(helpers.newLineRe).length - 1); }); (token.children || []).forEach(function forChild(child) { - child.lineNumber = lineNumber_1; - child.line = lines[lineNumber_1 - 1]; + child.lineNumber = lineNumber; + child.line = lines[lineNumber - 1]; if ((child.type === "softbreak") || (child.type === "hardbreak")) { - lineNumber_1++; + lineNumber++; } else if (child.type === "code_inline") { - lineNumber_1 += codeSpanExtraLines_1.shift(); + lineNumber += codeSpanExtraLines.shift(); } }); } @@ -1535,21 +1512,21 @@ function annotateTokens(tokens, lines) { * @returns {Object.} Map of alias to rule name. */ function mapAliasToRuleNames(ruleList) { - var aliasToRuleNames = {}; + const aliasToRuleNames = {}; // const tagToRuleNames = {}; ruleList.forEach(function forRule(rule) { - var ruleName = rule.names[0].toUpperCase(); + const ruleName = rule.names[0].toUpperCase(); // The following is useful for updating README.md: // console.log( // "* **[" + ruleName + "](doc/Rules.md#" + ruleName.toLowerCase() + // ")** *" + rule.names.slice(1).join("/") + "* - " + rule.description); rule.names.forEach(function forName(name) { - var nameUpper = name.toUpperCase(); + const nameUpper = name.toUpperCase(); aliasToRuleNames[nameUpper] = [ruleName]; }); rule.tags.forEach(function forTag(tag) { - var tagUpper = tag.toUpperCase(); - var ruleNames = aliasToRuleNames[tagUpper] || []; + const tagUpper = tag.toUpperCase(); + const ruleNames = aliasToRuleNames[tagUpper] || []; ruleNames.push(ruleName); aliasToRuleNames[tagUpper] = ruleNames; // tagToRuleNames[tag] = ruleName; @@ -1573,18 +1550,18 @@ function mapAliasToRuleNames(ruleList) { * @returns {Configuration} Effective configuration. */ function getEffectiveConfig(ruleList, config, aliasToRuleNames) { - var defaultKey = Object.keys(config).filter(function (key) { return key.toUpperCase() === "DEFAULT"; }); - var ruleDefault = (defaultKey.length === 0) || !!config[defaultKey[0]]; - var effectiveConfig = {}; - ruleList.forEach(function (rule) { - var ruleName = rule.names[0].toUpperCase(); + const defaultKey = Object.keys(config).filter((key) => key.toUpperCase() === "DEFAULT"); + const ruleDefault = (defaultKey.length === 0) || !!config[defaultKey[0]]; + const effectiveConfig = {}; + ruleList.forEach((rule) => { + const ruleName = rule.names[0].toUpperCase(); effectiveConfig[ruleName] = ruleDefault; }); - deprecatedRuleNames.forEach(function (ruleName) { + deprecatedRuleNames.forEach((ruleName) => { effectiveConfig[ruleName] = false; }); - Object.keys(config).forEach(function (key) { - var value = config[key]; + Object.keys(config).forEach((key) => { + let value = config[key]; if (value) { if (!(value instanceof Object)) { value = {}; @@ -1593,8 +1570,8 @@ function getEffectiveConfig(ruleList, config, aliasToRuleNames) { else { value = false; } - var keyUpper = key.toUpperCase(); - (aliasToRuleNames[keyUpper] || []).forEach(function (ruleName) { + const keyUpper = key.toUpperCase(); + (aliasToRuleNames[keyUpper] || []).forEach((ruleName) => { effectiveConfig[ruleName] = value; }); }); @@ -1614,24 +1591,24 @@ function getEffectiveConfig(ruleList, config, aliasToRuleNames) { */ function getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlineConfig, config, aliasToRuleNames) { // Shared variables - var enabledRules = {}; - var capturedRules = {}; - var allRuleNames = []; - var enabledRulesPerLineNumber = new Array(1 + frontMatterLines.length); + let enabledRules = {}; + let capturedRules = {}; + const allRuleNames = []; + const enabledRulesPerLineNumber = new Array(1 + frontMatterLines.length); // Helper functions // eslint-disable-next-line jsdoc/require-jsdoc function handleInlineConfig(input, forEachMatch, forEachLine) { - input.forEach(function (line, lineIndex) { + input.forEach((line, lineIndex) => { if (!noInlineConfig) { - var match = null; + let match = null; while ((match = helpers.inlineCommentStartRe.exec(line))) { - var action = match[2].toUpperCase(); - var startIndex = match.index + match[1].length; - var endIndex = line.indexOf("-->", startIndex); + const action = match[2].toUpperCase(); + const startIndex = match.index + match[1].length; + const endIndex = line.indexOf("-->", startIndex); if (endIndex === -1) { break; } - var parameter = line.slice(startIndex, endIndex); + const parameter = line.slice(startIndex, endIndex); forEachMatch(action, parameter, lineIndex + 1); } } @@ -1644,8 +1621,8 @@ function getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlin function configureFile(action, parameter) { if (action === "CONFIGURE-FILE") { try { - var json = JSON.parse(parameter); - config = __assign(__assign({}, config), json); + const json = JSON.parse(parameter); + config = Object.assign(Object.assign({}, config), json); } catch (_a) { // Ignore parse errors for inline configuration @@ -1654,12 +1631,12 @@ function getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlin } // eslint-disable-next-line jsdoc/require-jsdoc function applyEnableDisable(action, parameter, state) { - state = __assign({}, state); - var enabled = (action.startsWith("ENABLE")); - var trimmed = parameter && parameter.trim(); - var items = trimmed ? trimmed.toUpperCase().split(/\s+/) : allRuleNames; - items.forEach(function (nameUpper) { - (aliasToRuleNames[nameUpper] || []).forEach(function (ruleName) { + state = Object.assign({}, state); + const enabled = (action.startsWith("ENABLE")); + const trimmed = parameter && parameter.trim(); + const items = trimmed ? trimmed.toUpperCase().split(/\s+/) : allRuleNames; + items.forEach((nameUpper) => { + (aliasToRuleNames[nameUpper] || []).forEach((ruleName) => { state[ruleName] = enabled; }); }); @@ -1689,19 +1666,19 @@ function getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlin } // eslint-disable-next-line jsdoc/require-jsdoc function disableLineNextLine(action, parameter, lineNumber) { - var disableLine = (action === "DISABLE-LINE"); - var disableNextLine = (action === "DISABLE-NEXT-LINE"); + const disableLine = (action === "DISABLE-LINE"); + const disableNextLine = (action === "DISABLE-NEXT-LINE"); if (disableLine || disableNextLine) { - var nextLineNumber = frontMatterLines.length + lineNumber + (disableNextLine ? 1 : 0); + const nextLineNumber = frontMatterLines.length + lineNumber + (disableNextLine ? 1 : 0); enabledRulesPerLineNumber[nextLineNumber] = applyEnableDisable(action, parameter, enabledRulesPerLineNumber[nextLineNumber] || {}); } } // Handle inline comments handleInlineConfig([lines.join("\n")], configureFile); - var effectiveConfig = getEffectiveConfig(ruleList, config, aliasToRuleNames); - ruleList.forEach(function (rule) { - var ruleName = rule.names[0].toUpperCase(); + const effectiveConfig = getEffectiveConfig(ruleList, config, aliasToRuleNames); + ruleList.forEach((rule) => { + const ruleName = rule.names[0].toUpperCase(); allRuleNames.push(ruleName); enabledRules[ruleName] = !!effectiveConfig[ruleName]; }); @@ -1711,8 +1688,8 @@ function getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlin handleInlineConfig(lines, disableLineNextLine); // Return results return { - effectiveConfig: effectiveConfig, - enabledRulesPerLineNumber: enabledRulesPerLineNumber + effectiveConfig, + enabledRulesPerLineNumber }; } /** @@ -1734,42 +1711,42 @@ function lintContent(ruleList, name, content, md, config, frontMatter, handleRul // Remove UTF-8 byte order marker (if present) content = content.replace(/^\uFEFF/, ""); // Remove front matter - var removeFrontMatterResult = removeFrontMatter(content, frontMatter); - var frontMatterLines = removeFrontMatterResult.frontMatterLines; + const removeFrontMatterResult = removeFrontMatter(content, frontMatter); + const frontMatterLines = removeFrontMatterResult.frontMatterLines; // Ignore the content of HTML comments content = helpers.clearHtmlCommentText(removeFrontMatterResult.content); // Parse content into tokens and lines - var tokens = md.parse(content, {}); - var lines = content.split(helpers.newLineRe); + const tokens = md.parse(content, {}); + const lines = content.split(helpers.newLineRe); annotateTokens(tokens, lines); - var aliasToRuleNames = mapAliasToRuleNames(ruleList); - var _a = getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlineConfig, config, aliasToRuleNames), effectiveConfig = _a.effectiveConfig, enabledRulesPerLineNumber = _a.enabledRulesPerLineNumber; + const aliasToRuleNames = mapAliasToRuleNames(ruleList); + const { effectiveConfig, enabledRulesPerLineNumber } = getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlineConfig, config, aliasToRuleNames); // Create parameters for rules - var paramsBase = helpers.deepFreeze({ - name: name, - tokens: tokens, - lines: lines, - frontMatterLines: frontMatterLines + const paramsBase = helpers.deepFreeze({ + name, + tokens, + lines, + frontMatterLines }); - var lineMetadata = helpers.getLineMetadata(paramsBase); - var codeBlockAndSpanRanges = helpers.codeBlockAndSpanRanges(paramsBase, lineMetadata); - var flattenedLists = helpers.flattenLists(paramsBase.tokens); - var htmlElementRanges = helpers.htmlElementRanges(paramsBase, lineMetadata); - var referenceLinkImageData = helpers.getReferenceLinkImageData(paramsBase, lineMetadata); + const lineMetadata = helpers.getLineMetadata(paramsBase); + const codeBlockAndSpanRanges = helpers.codeBlockAndSpanRanges(paramsBase, lineMetadata); + const flattenedLists = helpers.flattenLists(paramsBase.tokens); + const htmlElementRanges = helpers.htmlElementRanges(paramsBase, lineMetadata); + const referenceLinkImageData = helpers.getReferenceLinkImageData(paramsBase, lineMetadata); cache.set({ - codeBlockAndSpanRanges: codeBlockAndSpanRanges, - flattenedLists: flattenedLists, - htmlElementRanges: htmlElementRanges, - lineMetadata: lineMetadata, - referenceLinkImageData: referenceLinkImageData + codeBlockAndSpanRanges, + flattenedLists, + htmlElementRanges, + lineMetadata, + referenceLinkImageData }); // Function to run for each rule - var results = []; + let results = []; // eslint-disable-next-line jsdoc/require-jsdoc function forRule(rule) { // Configure rule - var ruleName = rule.names[0].toUpperCase(); - var params = __assign(__assign({}, paramsBase), { "config": effectiveConfig[ruleName] }); + const ruleName = rule.names[0].toUpperCase(); + const params = Object.assign(Object.assign({}, paramsBase), { "config": effectiveConfig[ruleName] }); // eslint-disable-next-line jsdoc/require-jsdoc function throwError(property) { throw new Error("Property '" + property + "' of onError parameter is incorrect."); @@ -1782,7 +1759,7 @@ function lintContent(ruleList, name, content, md, config, frontMatter, handleRul (errorInfo.lineNumber > lines.length)) { throwError("lineNumber"); } - var lineNumber = errorInfo.lineNumber + frontMatterLines.length; + const lineNumber = errorInfo.lineNumber + frontMatterLines.length; if (!enabledRulesPerLineNumber[lineNumber][ruleName]) { return; } @@ -1805,8 +1782,8 @@ function lintContent(ruleList, name, content, md, config, frontMatter, handleRul lines[errorInfo.lineNumber - 1].length))) { throwError("range"); } - var fixInfo = errorInfo.fixInfo; - var cleanFixInfo = {}; + const fixInfo = errorInfo.fixInfo; + const cleanFixInfo = {}; if (fixInfo) { if (!helpers.isObject(fixInfo)) { throwError("fixInfo"); @@ -1820,7 +1797,7 @@ function lintContent(ruleList, name, content, md, config, frontMatter, handleRul cleanFixInfo.lineNumber = fixInfo.lineNumber + frontMatterLines.length; } - var effectiveLineNumber = fixInfo.lineNumber || errorInfo.lineNumber; + const effectiveLineNumber = fixInfo.lineNumber || errorInfo.lineNumber; if (fixInfo.editColumn !== undefined) { if ((!helpers.isNumber(fixInfo.editColumn) || (fixInfo.editColumn < 1) || @@ -1847,26 +1824,26 @@ function lintContent(ruleList, name, content, md, config, frontMatter, handleRul } } results.push({ - lineNumber: lineNumber, + lineNumber, "ruleName": rule.names[0], "ruleNames": rule.names, "ruleDescription": rule.description, "ruleInformation": rule.information ? rule.information.href : null, "errorDetail": errorInfo.detail || null, "errorContext": errorInfo.context || null, - "errorRange": errorInfo.range ? __spreadArray([], errorInfo.range, true) : null, + "errorRange": errorInfo.range ? [...errorInfo.range] : null, "fixInfo": fixInfo ? cleanFixInfo : null }); } // Call (possibly external) rule function to report errors - var catchCallsOnError = function (error) { return onError({ + const catchCallsOnError = (error) => onError({ "lineNumber": 1, - "detail": "This rule threw an exception: ".concat(error.message || error) - }); }; - var invokeRuleFunction = function () { return rule.function(params, onError); }; + "detail": `This rule threw an exception: ${error.message || error}` + }); + const invokeRuleFunction = () => rule.function(params, onError); if (rule.asynchronous) { // Asynchronous rule, ensure it returns a Promise - var ruleFunctionPromise = Promise.resolve().then(invokeRuleFunction); + const ruleFunctionPromise = Promise.resolve().then(invokeRuleFunction); return handleRuleFailures ? ruleFunctionPromise.catch(catchCallsOnError) : ruleFunctionPromise; @@ -1888,27 +1865,26 @@ function lintContent(ruleList, name, content, md, config, frontMatter, handleRul // eslint-disable-next-line jsdoc/require-jsdoc function formatResults() { // Sort results by rule name by line number - results.sort(function (a, b) { return (a.ruleName.localeCompare(b.ruleName) || - a.lineNumber - b.lineNumber); }); + results.sort((a, b) => (a.ruleName.localeCompare(b.ruleName) || + a.lineNumber - b.lineNumber)); if (resultVersion < 3) { // Remove fixInfo and multiple errors for the same rule and line number - var noPrevious_1 = { + const noPrevious = { "ruleName": null, "lineNumber": -1 }; - results = results.filter(function (error, index, array) { + results = results.filter((error, index, array) => { delete error.fixInfo; - var previous = array[index - 1] || noPrevious_1; + const previous = array[index - 1] || noPrevious; return ((error.ruleName !== previous.ruleName) || (error.lineNumber !== previous.lineNumber)); }); } if (resultVersion === 0) { // Return a dictionary of rule->[line numbers] - var dictionary = {}; - for (var _i = 0, results_1 = results; _i < results_1.length; _i++) { - var error = results_1[_i]; - var ruleLines = dictionary[error.ruleName] || []; + const dictionary = {}; + for (const error of results) { + const ruleLines = dictionary[error.ruleName] || []; ruleLines.push(error.lineNumber); dictionary[error.ruleName] = ruleLines; } @@ -1917,29 +1893,30 @@ function lintContent(ruleList, name, content, md, config, frontMatter, handleRul } else if (resultVersion === 1) { // Use ruleAlias instead of ruleNames - for (var _a = 0, results_2 = results; _a < results_2.length; _a++) { - var error = results_2[_a]; + for (const error of results) { error.ruleAlias = error.ruleNames[1] || error.ruleName; delete error.ruleNames; } } else { // resultVersion 2 or 3: Remove unwanted ruleName - for (var _b = 0, results_3 = results; _b < results_3.length; _b++) { - var error = results_3[_b]; + for (const error of results) { delete error.ruleName; } } return results; } // Run all rules - var ruleListAsync = ruleList.filter(function (rule) { return rule.asynchronous; }); - var ruleListSync = ruleList.filter(function (rule) { return !rule.asynchronous; }); - var ruleListAsyncFirst = __spreadArray(__spreadArray([], ruleListAsync, true), ruleListSync, true); - var callbackSuccess = function () { return callback(null, formatResults()); }; - var callbackError = function (error) { return callback(error instanceof Error ? error : new Error(error)); }; + const ruleListAsync = ruleList.filter((rule) => rule.asynchronous); + const ruleListSync = ruleList.filter((rule) => !rule.asynchronous); + const ruleListAsyncFirst = [ + ...ruleListAsync, + ...ruleListSync + ]; + const callbackSuccess = () => callback(null, formatResults()); + const callbackError = (error) => callback(error instanceof Error ? error : new Error(error)); try { - var ruleResults = ruleListAsyncFirst.map(forRule); + const ruleResults = ruleListAsyncFirst.map(forRule); if (ruleListAsync.length > 0) { Promise.all(ruleResults.slice(0, ruleListAsync.length)) .then(callbackSuccess) @@ -2001,40 +1978,40 @@ function lintInput(options, synchronous, callback) { options = options || {}; callback = callback || function noop() { }; // eslint-disable-next-line unicorn/prefer-spread - var ruleList = rules.concat(options.customRules || []); - var ruleErr = validateRuleList(ruleList, synchronous); + const ruleList = rules.concat(options.customRules || []); + const ruleErr = validateRuleList(ruleList, synchronous); if (ruleErr) { return callback(ruleErr); } - var files = []; + let files = []; if (Array.isArray(options.files)) { - files = __spreadArray([], options.files, true); + files = [...options.files]; } else if (options.files) { files = [String(options.files)]; } - var strings = options.strings || {}; - var stringsKeys = Object.keys(strings); - var config = options.config || { "default": true }; - var frontMatter = (options.frontMatter === undefined) ? + const strings = options.strings || {}; + const stringsKeys = Object.keys(strings); + const config = options.config || { "default": true }; + const frontMatter = (options.frontMatter === undefined) ? helpers.frontMatterRe : options.frontMatter; - var handleRuleFailures = !!options.handleRuleFailures; - var noInlineConfig = !!options.noInlineConfig; - var resultVersion = (options.resultVersion === undefined) ? + const handleRuleFailures = !!options.handleRuleFailures; + const noInlineConfig = !!options.noInlineConfig; + const resultVersion = (options.resultVersion === undefined) ? 3 : options.resultVersion; - var md = markdownIt({ "html": true }); - var markdownItPlugins = options.markdownItPlugins || []; + const md = markdownIt({ "html": true }); + const markdownItPlugins = options.markdownItPlugins || []; markdownItPlugins.forEach(function forPlugin(plugin) { // @ts-ignore - md.use.apply(md, plugin); + md.use(...plugin); }); - var fs = options.fs || __webpack_require__(/*! fs */ "?ec0a"); - var results = newResults(ruleList); - var done = false; - var concurrency = 0; + const fs = options.fs || __webpack_require__(/*! fs */ "?ec0a"); + const results = newResults(ruleList); + let done = false; + let concurrency = 0; // eslint-disable-next-line jsdoc/require-jsdoc function lintWorker() { - var currentItem = null; + let currentItem = null; // eslint-disable-next-line jsdoc/require-jsdoc function lintWorkerCallback(err, result) { concurrency--; @@ -2100,7 +2077,7 @@ function lintInput(options, synchronous, callback) { function markdownlint(options, callback) { return lintInput(options, false, callback); } -var markdownlintPromisify = promisify && promisify(markdownlint); +const markdownlintPromisify = promisify && promisify(markdownlint); /** * Lint specified Markdown files. * @@ -2117,7 +2094,7 @@ function markdownlintPromise(options) { * @returns {LintResults} Results object. */ function markdownlintSync(options) { - var results = null; + let results = null; lintInput(options, true, function callback(error, res) { if (error) { throw error; @@ -2135,28 +2112,28 @@ function markdownlintSync(options) { * @returns {Object} Configuration object and error message. */ function parseConfiguration(name, content, parsers) { - var config = null; - var message = ""; - var errors = []; - var index = 0; + let config = null; + let message = ""; + const errors = []; + let index = 0; // Try each parser - (parsers || [JSON.parse]).every(function (parser) { + (parsers || [JSON.parse]).every((parser) => { try { config = parser(content); } catch (error) { - errors.push("Parser ".concat(index++, ": ").concat(error.message)); + errors.push(`Parser ${index++}: ${error.message}`); } return !config; }); // Message if unable to parse if (!config) { - errors.unshift("Unable to parse '".concat(name, "'")); + errors.unshift(`Unable to parse '${name}'`); message = errors.join("; "); } return { - config: config, - message: message + config, + message }; } /** @@ -2171,9 +2148,9 @@ function parseConfiguration(name, content, parsers) { * @returns {void} */ function resolveConfigExtends(configFile, referenceId, fs, callback) { - var configFileDirname = path.dirname(configFile); - var resolvedExtendsFile = path.resolve(configFileDirname, referenceId); - fs.access(resolvedExtendsFile, function (err) { + const configFileDirname = path.dirname(configFile); + const resolvedExtendsFile = path.resolve(configFileDirname, referenceId); + fs.access(resolvedExtendsFile, (err) => { if (err) { // Not a file, try require.resolve try { @@ -2196,8 +2173,8 @@ function resolveConfigExtends(configFile, referenceId, fs, callback) { * @returns {string} Resolved path to file. */ function resolveConfigExtendsSync(configFile, referenceId, fs) { - var configFileDirname = path.dirname(configFile); - var resolvedExtendsFile = path.resolve(configFileDirname, referenceId); + const configFileDirname = path.dirname(configFile); + const resolvedExtendsFile = path.resolve(configFileDirname, referenceId); try { fs.accessSync(resolvedExtendsFile); return resolvedExtendsFile; @@ -2239,33 +2216,33 @@ function readConfig(file, parsers, fs, callback) { fs = __webpack_require__(/*! fs */ "?ec0a"); } // Read file - var os = __webpack_require__(/*! os */ "?a32b"); + const os = __webpack_require__(/*! os */ "?a32b"); file = helpers.expandTildePath(file, os); - fs.readFile(file, "utf8", function (err, content) { + fs.readFile(file, "utf8", (err, content) => { if (err) { return callback(err); } // Try to parse file // @ts-ignore - var _a = parseConfiguration(file, content, parsers), config = _a.config, message = _a.message; + const { config, message } = parseConfiguration(file, content, parsers); if (!config) { return callback(new Error(message)); } // Extend configuration - var configExtends = config.extends; + const configExtends = config.extends; if (configExtends) { delete config.extends; - return resolveConfigExtends(file, helpers.expandTildePath(configExtends, os), fs, function (_, resolvedExtends) { return readConfig(resolvedExtends, parsers, fs, function (errr, extendsConfig) { + return resolveConfigExtends(file, helpers.expandTildePath(configExtends, os), fs, (_, resolvedExtends) => readConfig(resolvedExtends, parsers, fs, (errr, extendsConfig) => { if (errr) { return callback(errr); } - return callback(null, __assign(__assign({}, extendsConfig), config)); - }); }); + return callback(null, Object.assign(Object.assign({}, extendsConfig), config)); + })); } return callback(null, config); }); } -var readConfigPromisify = promisify && promisify(readConfig); +const readConfigPromisify = promisify && promisify(readConfig); /** * Read specified configuration file. * @@ -2292,20 +2269,20 @@ function readConfigSync(file, parsers, fs) { fs = __webpack_require__(/*! fs */ "?ec0a"); } // Read file - var os = __webpack_require__(/*! os */ "?a32b"); + const os = __webpack_require__(/*! os */ "?a32b"); file = helpers.expandTildePath(file, os); - var content = fs.readFileSync(file, "utf8"); + const content = fs.readFileSync(file, "utf8"); // Try to parse file - var _a = parseConfiguration(file, content, parsers), config = _a.config, message = _a.message; + const { config, message } = parseConfiguration(file, content, parsers); if (!config) { throw new Error(message); } // Extend configuration - var configExtends = config.extends; + const configExtends = config.extends; if (configExtends) { delete config.extends; - var resolvedExtends = resolveConfigExtendsSync(file, helpers.expandTildePath(configExtends, os), fs); - return __assign(__assign({}, readConfigSync(resolvedExtends, parsers, fs)), config); + const resolvedExtends = resolveConfigExtendsSync(file, helpers.expandTildePath(configExtends, os), fs); + return Object.assign(Object.assign({}, readConfigSync(resolvedExtends, parsers, fs)), config); } return config; } @@ -2340,15 +2317,15 @@ module.exports = markdownlint; "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorDetailIf = _a.addErrorDetailIf, filterTokens = _a.filterTokens; +const { addErrorDetailIf, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); module.exports = { "names": ["MD001", "heading-increment", "header-increment"], "description": "Heading levels should only increment by one level at a time", "tags": ["headings", "headers"], "function": function MD001(params, onError) { - var prevLevel = 0; + let prevLevel = 0; filterTokens(params, "heading_open", function forToken(token) { - var level = Number.parseInt(token.tag.slice(1), 10); + const level = Number.parseInt(token.tag.slice(1), 10); if (prevLevel && (level > prevLevel)) { addErrorDetailIf(onError, token.lineNumber, "h" + (prevLevel + 1), "h" + level); } @@ -2369,14 +2346,14 @@ module.exports = { "use strict"; // @ts-check -var addErrorDetailIf = (__webpack_require__(/*! ../helpers */ "../helpers/helpers.js").addErrorDetailIf); +const { addErrorDetailIf } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); module.exports = { "names": ["MD002", "first-heading-h1", "first-header-h1"], "description": "First heading should be a top-level heading", "tags": ["headings", "headers"], "function": function MD002(params, onError) { - var level = Number(params.config.level || 1); - var tag = "h" + level; + const level = Number(params.config.level || 1); + const tag = "h" + level; params.tokens.every(function forToken(token) { if (token.type === "heading_open") { addErrorDetailIf(onError, token.lineNumber, tag, token.tag); @@ -2399,28 +2376,28 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorDetailIf = _a.addErrorDetailIf, filterTokens = _a.filterTokens, headingStyleFor = _a.headingStyleFor; +const { addErrorDetailIf, filterTokens, headingStyleFor } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); module.exports = { "names": ["MD003", "heading-style", "header-style"], "description": "Heading style", "tags": ["headings", "headers"], "function": function MD003(params, onError) { - var style = String(params.config.style || "consistent"); + let style = String(params.config.style || "consistent"); filterTokens(params, "heading_open", function forToken(token) { - var styleForToken = headingStyleFor(token); + const styleForToken = headingStyleFor(token); if (style === "consistent") { style = styleForToken; } if (styleForToken !== style) { - var h12 = /h[12]/.test(token.tag); - var setextWithAtx = (style === "setext_with_atx") && + const h12 = /h[12]/.test(token.tag); + const setextWithAtx = (style === "setext_with_atx") && ((h12 && (styleForToken === "setext")) || (!h12 && (styleForToken === "atx"))); - var setextWithAtxClosed = (style === "setext_with_atx_closed") && + const setextWithAtxClosed = (style === "setext_with_atx_closed") && ((h12 && (styleForToken === "setext")) || (!h12 && (styleForToken === "atx_closed"))); if (!setextWithAtx && !setextWithAtxClosed) { - var expected = style; + let expected = style; if (style === "setext_with_atx") { expected = h12 ? "setext" : "atx"; } @@ -2446,36 +2423,36 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorDetailIf = _a.addErrorDetailIf, listItemMarkerRe = _a.listItemMarkerRe, unorderedListStyleFor = _a.unorderedListStyleFor; -var flattenedLists = (__webpack_require__(/*! ./cache */ "../lib/cache.js").flattenedLists); -var expectedStyleToMarker = { +const { addErrorDetailIf, listItemMarkerRe, unorderedListStyleFor } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { flattenedLists } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); +const expectedStyleToMarker = { "dash": "-", "plus": "+", "asterisk": "*" }; -var differentItemStyle = { +const differentItemStyle = { "dash": "plus", "plus": "asterisk", "asterisk": "dash" }; -var validStyles = Object.keys(expectedStyleToMarker); +const validStyles = Object.keys(expectedStyleToMarker); module.exports = { "names": ["MD004", "ul-style"], "description": "Unordered list style", "tags": ["bullet", "ul"], "function": function MD004(params, onError) { - var style = String(params.config.style || "consistent"); - var expectedStyle = style; - var nestingStyles = []; - flattenedLists().forEach(function (list) { + const style = String(params.config.style || "consistent"); + let expectedStyle = style; + const nestingStyles = []; + flattenedLists().forEach((list) => { if (list.unordered) { if (expectedStyle === "consistent") { expectedStyle = unorderedListStyleFor(list.items[0]); } - list.items.forEach(function (item) { - var itemStyle = unorderedListStyleFor(item); + list.items.forEach((item) => { + const itemStyle = unorderedListStyleFor(item); if (style === "sublist") { - var nesting = list.nesting; + const nesting = list.nesting; if (!nestingStyles[nesting]) { nestingStyles[nesting] = (itemStyle === nestingStyles[nesting - 1]) ? @@ -2487,12 +2464,12 @@ module.exports = { if (!validStyles.includes(expectedStyle)) { expectedStyle = validStyles[0]; } - var range = null; - var fixInfo = null; - var match = item.line.match(listItemMarkerRe); + let range = null; + let fixInfo = null; + const match = item.line.match(listItemMarkerRe); if (match) { - var column = match.index + 1; - var length = match[0].length; + const column = match.index + 1; + const length = match[0].length; range = [column, length]; fixInfo = { "editColumn": match[1].length + 1, @@ -2519,22 +2496,22 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addError = _a.addError, addErrorDetailIf = _a.addErrorDetailIf, indentFor = _a.indentFor, listItemMarkerRe = _a.listItemMarkerRe, orderedListItemMarkerRe = _a.orderedListItemMarkerRe, rangeFromRegExp = _a.rangeFromRegExp; -var flattenedLists = (__webpack_require__(/*! ./cache */ "../lib/cache.js").flattenedLists); +const { addError, addErrorDetailIf, indentFor, listItemMarkerRe, orderedListItemMarkerRe, rangeFromRegExp } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { flattenedLists } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); module.exports = { "names": ["MD005", "list-indent"], "description": "Inconsistent indentation for list items at the same level", "tags": ["bullet", "ul", "indentation"], "function": function MD005(params, onError) { - flattenedLists().forEach(function (list) { - var expectedIndent = list.indent; - var expectedEnd = 0; - var actualEnd = -1; - var endMatching = false; - list.items.forEach(function (item) { - var line = item.line, lineNumber = item.lineNumber; - var actualIndent = indentFor(item); - var match = null; + flattenedLists().forEach((list) => { + const expectedIndent = list.indent; + let expectedEnd = 0; + let actualEnd = -1; + let endMatching = false; + list.items.forEach((item) => { + const { line, lineNumber } = item; + const actualIndent = indentFor(item); + let match = null; if (list.unordered) { addErrorDetailIf(onError, lineNumber, expectedIndent, actualIndent, null, null, rangeFromRegExp(line, listItemMarkerRe) // No fixInfo; MD007 handles this scenario better @@ -2543,19 +2520,19 @@ module.exports = { else if ((match = orderedListItemMarkerRe.exec(line))) { actualEnd = match[0].length; expectedEnd = expectedEnd || actualEnd; - var markerLength = match[1].length + 1; + const markerLength = match[1].length + 1; if ((expectedIndent !== actualIndent) || endMatching) { if (expectedEnd === actualEnd) { endMatching = true; } else { - var detail = endMatching ? - "Expected: (".concat(expectedEnd, "); Actual: (").concat(actualEnd, ")") : - "Expected: ".concat(expectedIndent, "; Actual: ").concat(actualIndent); - var expected = endMatching ? + const detail = endMatching ? + `Expected: (${expectedEnd}); Actual: (${actualEnd})` : + `Expected: ${expectedIndent}; Actual: ${actualIndent}`; + const expected = endMatching ? expectedEnd - markerLength : expectedIndent; - var actual = endMatching ? + const actual = endMatching ? actualEnd - markerLength : actualIndent; addError(onError, lineNumber, detail, null, rangeFromRegExp(line, listItemMarkerRe), { @@ -2583,17 +2560,17 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorDetailIf = _a.addErrorDetailIf, listItemMarkerRe = _a.listItemMarkerRe, rangeFromRegExp = _a.rangeFromRegExp; -var flattenedLists = (__webpack_require__(/*! ./cache */ "../lib/cache.js").flattenedLists); +const { addErrorDetailIf, listItemMarkerRe, rangeFromRegExp } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { flattenedLists } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); module.exports = { "names": ["MD006", "ul-start-left"], "description": "Consider starting bulleted lists at the beginning of the line", "tags": ["bullet", "ul", "indentation"], "function": function MD006(params, onError) { - flattenedLists().forEach(function (list) { + flattenedLists().forEach((list) => { if (list.unordered && !list.nesting && (list.indent !== 0)) { - list.items.forEach(function (item) { - var lineNumber = item.lineNumber, line = item.line; + list.items.forEach((item) => { + const { lineNumber, line } = item; addErrorDetailIf(onError, lineNumber, 0, list.indent, null, null, rangeFromRegExp(line, listItemMarkerRe), { "deleteCount": line.length - line.trimStart().length }); @@ -2615,32 +2592,32 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorDetailIf = _a.addErrorDetailIf, indentFor = _a.indentFor, listItemMarkerRe = _a.listItemMarkerRe; -var flattenedLists = (__webpack_require__(/*! ./cache */ "../lib/cache.js").flattenedLists); +const { addErrorDetailIf, indentFor, listItemMarkerRe } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { flattenedLists } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); module.exports = { "names": ["MD007", "ul-indent"], "description": "Unordered list indentation", "tags": ["bullet", "ul", "indentation"], "function": function MD007(params, onError) { - var indent = Number(params.config.indent || 2); - var startIndented = !!params.config.start_indented; - var startIndent = Number(params.config.start_indent || indent); - flattenedLists().forEach(function (list) { + const indent = Number(params.config.indent || 2); + const startIndented = !!params.config.start_indented; + const startIndent = Number(params.config.start_indent || indent); + flattenedLists().forEach((list) => { if (list.unordered && list.parentsUnordered) { - list.items.forEach(function (item) { - var lineNumber = item.lineNumber, line = item.line; - var expectedIndent = (startIndented ? startIndent : 0) + + list.items.forEach((item) => { + const { lineNumber, line } = item; + const expectedIndent = (startIndented ? startIndent : 0) + (list.nesting * indent); - var actualIndent = indentFor(item); - var range = null; - var editColumn = 1; - var match = line.match(listItemMarkerRe); + const actualIndent = indentFor(item); + let range = null; + let editColumn = 1; + const match = line.match(listItemMarkerRe); if (match) { range = [1, match[0].length]; editColumn += match[1].length - actualIndent; } addErrorDetailIf(onError, lineNumber, expectedIndent, actualIndent, null, null, range, { - editColumn: editColumn, + editColumn, "deleteCount": actualIndent, "insertText": "".padEnd(expectedIndent) }); @@ -2662,41 +2639,41 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addError = _a.addError, filterTokens = _a.filterTokens, forEachInlineCodeSpan = _a.forEachInlineCodeSpan, forEachLine = _a.forEachLine, includesSorted = _a.includesSorted, newLineRe = _a.newLineRe, numericSortAscending = _a.numericSortAscending; -var lineMetadata = (__webpack_require__(/*! ./cache */ "../lib/cache.js").lineMetadata); +const { addError, filterTokens, forEachInlineCodeSpan, forEachLine, includesSorted, newLineRe, numericSortAscending } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); module.exports = { "names": ["MD009", "no-trailing-spaces"], "description": "Trailing spaces", "tags": ["whitespace"], "function": function MD009(params, onError) { - var brSpaces = params.config.br_spaces; + let brSpaces = params.config.br_spaces; brSpaces = Number((brSpaces === undefined) ? 2 : brSpaces); - var listItemEmptyLines = !!params.config.list_item_empty_lines; - var strict = !!params.config.strict; - var listItemLineNumbers = []; + const listItemEmptyLines = !!params.config.list_item_empty_lines; + const strict = !!params.config.strict; + const listItemLineNumbers = []; if (listItemEmptyLines) { - filterTokens(params, "list_item_open", function (token) { - for (var i = token.map[0]; i < token.map[1]; i++) { + filterTokens(params, "list_item_open", (token) => { + for (let i = token.map[0]; i < token.map[1]; i++) { listItemLineNumbers.push(i + 1); } }); listItemLineNumbers.sort(numericSortAscending); } - var paragraphLineNumbers = []; - var codeInlineLineNumbers = []; + const paragraphLineNumbers = []; + const codeInlineLineNumbers = []; if (strict) { - filterTokens(params, "paragraph_open", function (token) { - for (var i = token.map[0]; i < token.map[1] - 1; i++) { + filterTokens(params, "paragraph_open", (token) => { + for (let i = token.map[0]; i < token.map[1] - 1; i++) { paragraphLineNumbers.push(i + 1); } }); paragraphLineNumbers.sort(numericSortAscending); - filterTokens(params, "inline", function (token) { - if (token.children.some(function (child) { return child.type === "code_inline"; })) { - var tokenLines = params.lines.slice(token.map[0], token.map[1]); - forEachInlineCodeSpan(tokenLines.join("\n"), function (code, lineIndex) { - var codeLineCount = code.split(newLineRe).length; - for (var i = 0; i < codeLineCount; i++) { + filterTokens(params, "inline", (token) => { + if (token.children.some((child) => child.type === "code_inline")) { + const tokenLines = params.lines.slice(token.map[0], token.map[1]); + forEachInlineCodeSpan(tokenLines.join("\n"), (code, lineIndex) => { + const codeLineCount = code.split(newLineRe).length; + for (let i = 0; i < codeLineCount; i++) { codeInlineLineNumbers.push(token.lineNumber + lineIndex + i); } }); @@ -2704,10 +2681,10 @@ module.exports = { }); codeInlineLineNumbers.sort(numericSortAscending); } - var expected = (brSpaces < 2) ? 0 : brSpaces; - forEachLine(lineMetadata(), function (line, lineIndex, inCode) { - var lineNumber = lineIndex + 1; - var trailingSpaces = line.length - line.trimEnd().length; + const expected = (brSpaces < 2) ? 0 : brSpaces; + forEachLine(lineMetadata(), (line, lineIndex, inCode) => { + const lineNumber = lineIndex + 1; + const trailingSpaces = line.length - line.trimEnd().length; if (trailingSpaces && !inCode && !includesSorted(listItemLineNumbers, lineNumber) && @@ -2715,7 +2692,7 @@ module.exports = { (strict && (!includesSorted(paragraphLineNumbers, lineNumber) || includesSorted(codeInlineLineNumbers, lineNumber))))) { - var column = line.length - trailingSpaces + 1; + const column = line.length - trailingSpaces + 1; addError(onError, lineNumber, "Expected: " + (expected === 0 ? "" : "0 or ") + expected + "; Actual: " + trailingSpaces, null, [column, trailingSpaces], { "editColumn": column, @@ -2738,38 +2715,38 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addError = _a.addError, filterTokens = _a.filterTokens, forEachLine = _a.forEachLine, overlapsAnyRange = _a.overlapsAnyRange; -var _b = __webpack_require__(/*! ./cache */ "../lib/cache.js"), codeBlockAndSpanRanges = _b.codeBlockAndSpanRanges, lineMetadata = _b.lineMetadata; -var tabRe = /\t+/g; +const { addError, filterTokens, forEachLine, overlapsAnyRange } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { codeBlockAndSpanRanges, lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); +const tabRe = /\t+/g; module.exports = { "names": ["MD010", "no-hard-tabs"], "description": "Hard tabs", "tags": ["whitespace", "hard_tab"], "function": function MD010(params, onError) { - var codeBlocks = params.config.code_blocks; - var includeCode = (codeBlocks === undefined) ? true : !!codeBlocks; - var ignoreCodeLanguages = new Set((params.config.ignore_code_languages || []) - .map(function (language) { return language.toLowerCase(); })); - var spacesPerTab = params.config.spaces_per_tab; - var spaceMultiplier = (spacesPerTab === undefined) ? + const codeBlocks = params.config.code_blocks; + const includeCode = (codeBlocks === undefined) ? true : !!codeBlocks; + const ignoreCodeLanguages = new Set((params.config.ignore_code_languages || []) + .map((language) => language.toLowerCase())); + const spacesPerTab = params.config.spaces_per_tab; + const spaceMultiplier = (spacesPerTab === undefined) ? 1 : Math.max(0, Number(spacesPerTab)); - var exclusions = includeCode ? [] : codeBlockAndSpanRanges(); - filterTokens(params, "fence", function (token) { - var language = token.info.trim().toLowerCase(); + const exclusions = includeCode ? [] : codeBlockAndSpanRanges(); + filterTokens(params, "fence", (token) => { + const language = token.info.trim().toLowerCase(); if (ignoreCodeLanguages.has(language)) { - for (var i = token.map[0] + 1; i < token.map[1] - 1; i++) { + for (let i = token.map[0] + 1; i < token.map[1] - 1; i++) { exclusions.push([i, 0, params.lines[i].length]); } } }); - forEachLine(lineMetadata(), function (line, lineIndex, inCode) { + forEachLine(lineMetadata(), (line, lineIndex, inCode) => { if (includeCode || !inCode) { - var match = null; + let match = null; while ((match = tabRe.exec(line)) !== null) { - var index = match.index; - var column = index + 1; - var length = match[0].length; + const { index } = match; + const column = index + 1; + const length = match[0].length; if (!overlapsAnyRange(exclusions, lineIndex, index, length)) { addError(onError, lineIndex + 1, "Column: " + column, null, [column, length], { "editColumn": column, @@ -2795,29 +2772,29 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addError = _a.addError, forEachLine = _a.forEachLine, overlapsAnyRange = _a.overlapsAnyRange; -var _b = __webpack_require__(/*! ./cache */ "../lib/cache.js"), codeBlockAndSpanRanges = _b.codeBlockAndSpanRanges, lineMetadata = _b.lineMetadata; -var reversedLinkRe = /(^|[^\\])\(([^)]+)\)\[([^\]^][^\]]*)](?!\()/g; +const { addError, forEachLine, overlapsAnyRange } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { codeBlockAndSpanRanges, lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); +const reversedLinkRe = /(^|[^\\])\(([^)]+)\)\[([^\]^][^\]]*)](?!\()/g; module.exports = { "names": ["MD011", "no-reversed-links"], "description": "Reversed link syntax", "tags": ["links"], "function": function MD011(params, onError) { - var exclusions = codeBlockAndSpanRanges(); - forEachLine(lineMetadata(), function (line, lineIndex, inCode, onFence) { + const exclusions = codeBlockAndSpanRanges(); + forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence) => { if (!inCode && !onFence) { - var match = null; + let match = null; while ((match = reversedLinkRe.exec(line)) !== null) { - var reversedLink = match[0], preChar = match[1], linkText = match[2], linkDestination = match[3]; - var index = match.index + preChar.length; - var length = match[0].length - preChar.length; + const [reversedLink, preChar, linkText, linkDestination] = match; + const index = match.index + preChar.length; + const length = match[0].length - preChar.length; if (!linkText.endsWith("\\") && !linkDestination.endsWith("\\") && !overlapsAnyRange(exclusions, lineIndex, index, length)) { addError(onError, lineIndex + 1, reversedLink.slice(preChar.length), null, [index + 1, length], { "editColumn": index + 1, "deleteCount": length, - "insertText": "[".concat(linkText, "](").concat(linkDestination, ")") + "insertText": `[${linkText}](${linkDestination})` }); } } @@ -2838,16 +2815,16 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorDetailIf = _a.addErrorDetailIf, forEachLine = _a.forEachLine; -var lineMetadata = (__webpack_require__(/*! ./cache */ "../lib/cache.js").lineMetadata); +const { addErrorDetailIf, forEachLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); module.exports = { "names": ["MD012", "no-multiple-blanks"], "description": "Multiple consecutive blank lines", "tags": ["whitespace", "blank_lines"], "function": function MD012(params, onError) { - var maximum = Number(params.config.maximum || 1); - var count = 0; - forEachLine(lineMetadata(), function (line, lineIndex, inCode) { + const maximum = Number(params.config.maximum || 1); + let count = 0; + forEachLine(lineMetadata(), (line, lineIndex, inCode) => { count = (inCode || (line.trim().length > 0)) ? 0 : count + 1; if (maximum < count) { addErrorDetailIf(onError, lineIndex + 1, maximum, count, null, null, null, { @@ -2870,14 +2847,14 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorDetailIf = _a.addErrorDetailIf, filterTokens = _a.filterTokens, forEachHeading = _a.forEachHeading, forEachLine = _a.forEachLine, includesSorted = _a.includesSorted, linkReferenceDefinitionRe = _a.linkReferenceDefinitionRe; -var lineMetadata = (__webpack_require__(/*! ./cache */ "../lib/cache.js").lineMetadata); -var longLineRePrefix = "^.{"; -var longLineRePostfixRelaxed = "}.*\\s.*$"; -var longLineRePostfixStrict = "}.+$"; -var linkOrImageOnlyLineRe = /^[es]*(lT?L|I)[ES]*$/; -var sternModeRe = /^([#>\s]*\s)?\S*$/; -var tokenTypeMap = { +const { addErrorDetailIf, filterTokens, forEachHeading, forEachLine, includesSorted, linkReferenceDefinitionRe } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); +const longLineRePrefix = "^.{"; +const longLineRePostfixRelaxed = "}.*\\s.*$"; +const longLineRePostfixStrict = "}.+$"; +const linkOrImageOnlyLineRe = /^[es]*(lT?L|I)[ES]*$/; +const sternModeRe = /^([#>\s]*\s)?\S*$/; +const tokenTypeMap = { "em_open": "e", "em_close": "E", "image": "I", @@ -2892,32 +2869,32 @@ module.exports = { "description": "Line length", "tags": ["line_length"], "function": function MD013(params, onError) { - var lineLength = Number(params.config.line_length || 80); - var headingLineLength = Number(params.config.heading_line_length || lineLength); - var codeLineLength = Number(params.config.code_block_line_length || lineLength); - var strict = !!params.config.strict; - var stern = !!params.config.stern; - var longLineRePostfix = (strict || stern) ? longLineRePostfixStrict : longLineRePostfixRelaxed; - var longLineRe = new RegExp(longLineRePrefix + lineLength + longLineRePostfix); - var longHeadingLineRe = new RegExp(longLineRePrefix + headingLineLength + longLineRePostfix); - var longCodeLineRe = new RegExp(longLineRePrefix + codeLineLength + longLineRePostfix); - var codeBlocks = params.config.code_blocks; - var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks; - var tables = params.config.tables; - var includeTables = (tables === undefined) ? true : !!tables; - var headings = params.config.headings; + const lineLength = Number(params.config.line_length || 80); + const headingLineLength = Number(params.config.heading_line_length || lineLength); + const codeLineLength = Number(params.config.code_block_line_length || lineLength); + const strict = !!params.config.strict; + const stern = !!params.config.stern; + const longLineRePostfix = (strict || stern) ? longLineRePostfixStrict : longLineRePostfixRelaxed; + const longLineRe = new RegExp(longLineRePrefix + lineLength + longLineRePostfix); + const longHeadingLineRe = new RegExp(longLineRePrefix + headingLineLength + longLineRePostfix); + const longCodeLineRe = new RegExp(longLineRePrefix + codeLineLength + longLineRePostfix); + const codeBlocks = params.config.code_blocks; + const includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks; + const tables = params.config.tables; + const includeTables = (tables === undefined) ? true : !!tables; + let headings = params.config.headings; if (headings === undefined) { headings = params.config.headers; } - var includeHeadings = (headings === undefined) ? true : !!headings; - var headingLineNumbers = []; - forEachHeading(params, function (heading) { + const includeHeadings = (headings === undefined) ? true : !!headings; + const headingLineNumbers = []; + forEachHeading(params, (heading) => { headingLineNumbers.push(heading.lineNumber); }); - var linkOnlyLineNumbers = []; - filterTokens(params, "inline", function (token) { - var childTokenTypes = ""; - token.children.forEach(function (child) { + const linkOnlyLineNumbers = []; + filterTokens(params, "inline", (token) => { + let childTokenTypes = ""; + token.children.forEach((child) => { if (child.type !== "text" || child.content !== "") { childTokenTypes += tokenTypeMap[child.type] || "x"; } @@ -2926,13 +2903,13 @@ module.exports = { linkOnlyLineNumbers.push(token.lineNumber); } }); - forEachLine(lineMetadata(), function (line, lineIndex, inCode, onFence, inTable) { - var lineNumber = lineIndex + 1; - var isHeading = includesSorted(headingLineNumbers, lineNumber); - var length = inCode ? + forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence, inTable) => { + const lineNumber = lineIndex + 1; + const isHeading = includesSorted(headingLineNumbers, lineNumber); + const length = inCode ? codeLineLength : (isHeading ? headingLineLength : lineLength); - var lengthRe = inCode ? + const lengthRe = inCode ? longCodeLineRe : (isHeading ? longHeadingLineRe : longLineRe); if ((includeCodeBlocks || !inCode) && @@ -2961,26 +2938,26 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, filterTokens = _a.filterTokens; -var dollarCommandRe = /^(\s*)(\$\s+)/; +const { addErrorContext, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const dollarCommandRe = /^(\s*)(\$\s+)/; module.exports = { "names": ["MD014", "commands-show-output"], "description": "Dollar signs used before commands without showing output", "tags": ["code"], "function": function MD014(params, onError) { - ["code_block", "fence"].forEach(function (type) { - filterTokens(params, type, function (token) { - var margin = (token.type === "fence") ? 1 : 0; - var dollarInstances = []; - var allDollars = true; - for (var i = token.map[0] + margin; i < token.map[1] - margin; i++) { - var line = params.lines[i]; - var lineTrim = line.trim(); + ["code_block", "fence"].forEach((type) => { + filterTokens(params, type, (token) => { + const margin = (token.type === "fence") ? 1 : 0; + const dollarInstances = []; + let allDollars = true; + for (let i = token.map[0] + margin; i < token.map[1] - margin; i++) { + const line = params.lines[i]; + const lineTrim = line.trim(); if (lineTrim) { - var match = dollarCommandRe.exec(line); + const match = dollarCommandRe.exec(line); if (match) { - var column = match[1].length + 1; - var length = match[2].length; + const column = match[1].length + 1; + const length = match[2].length; dollarInstances.push([i, lineTrim, column, length]); } else { @@ -2989,8 +2966,8 @@ module.exports = { } } if (allDollars) { - dollarInstances.forEach(function (instance) { - var i = instance[0], lineTrim = instance[1], column = instance[2], length = instance[3]; + dollarInstances.forEach((instance) => { + const [i, lineTrim, column, length] = instance; addErrorContext(onError, i + 1, lineTrim, null, null, [column, length], { "editColumn": column, "deleteCount": length @@ -3014,19 +2991,19 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, forEachLine = _a.forEachLine; -var lineMetadata = (__webpack_require__(/*! ./cache */ "../lib/cache.js").lineMetadata); +const { addErrorContext, forEachLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); module.exports = { "names": ["MD018", "no-missing-space-atx"], "description": "No space after hash on atx style heading", "tags": ["headings", "headers", "atx", "spaces"], "function": function MD018(params, onError) { - forEachLine(lineMetadata(), function (line, lineIndex, inCode) { + forEachLine(lineMetadata(), (line, lineIndex, inCode) => { if (!inCode && /^#+[^# \t]/.test(line) && !/#\s*$/.test(line) && !line.startsWith("#️⃣")) { - var hashCount = /^#+/.exec(line)[0].length; + const hashCount = /^#+/.exec(line)[0].length; addErrorContext(onError, lineIndex + 1, line.trim(), null, null, [1, hashCount + 1], { "editColumn": hashCount + 1, "insertText": " " @@ -3048,18 +3025,18 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, filterTokens = _a.filterTokens, headingStyleFor = _a.headingStyleFor; +const { addErrorContext, filterTokens, headingStyleFor } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); module.exports = { "names": ["MD019", "no-multiple-space-atx"], "description": "Multiple spaces after hash on atx style heading", "tags": ["headings", "headers", "atx", "spaces"], "function": function MD019(params, onError) { - filterTokens(params, "heading_open", function (token) { + filterTokens(params, "heading_open", (token) => { if (headingStyleFor(token) === "atx") { - var line = token.line, lineNumber = token.lineNumber; - var match = /^(#+)([ \t]{2,})(?:\S)/.exec(line); + const { line, lineNumber } = token; + const match = /^(#+)([ \t]{2,})(?:\S)/.exec(line); if (match) { - var hashLength = match[1]["length"], spacesLength = match[2]["length"]; + const [, { "length": hashLength }, { "length": spacesLength }] = match; addErrorContext(onError, lineNumber, line.trim(), null, null, [1, hashLength + spacesLength + 1], { "editColumn": hashLength + 1, "deleteCount": spacesLength - 1 @@ -3082,25 +3059,25 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, forEachLine = _a.forEachLine; -var lineMetadata = (__webpack_require__(/*! ./cache */ "../lib/cache.js").lineMetadata); +const { addErrorContext, forEachLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); module.exports = { "names": ["MD020", "no-missing-space-closed-atx"], "description": "No space inside hashes on closed atx style heading", "tags": ["headings", "headers", "atx_closed", "spaces"], "function": function MD020(params, onError) { - forEachLine(lineMetadata(), function (line, lineIndex, inCode) { + forEachLine(lineMetadata(), (line, lineIndex, inCode) => { if (!inCode) { - var match = /^(#+)([ \t]*)([^#]*?[^#\\])([ \t]*)((?:\\#)?)(#+)(\s*)$/.exec(line); + const match = /^(#+)([ \t]*)([^#]*?[^#\\])([ \t]*)((?:\\#)?)(#+)(\s*)$/.exec(line); if (match) { - var leftHash = match[1], leftSpaceLength = match[2]["length"], content = match[3], rightSpaceLength = match[4]["length"], rightEscape = match[5], rightHash = match[6], trailSpaceLength = match[7]["length"]; - var leftHashLength = leftHash.length; - var rightHashLength = rightHash.length; - var left = !leftSpaceLength; - var right = !rightSpaceLength || rightEscape; - var rightEscapeReplacement = rightEscape ? "".concat(rightEscape, " ") : ""; + const [, leftHash, { "length": leftSpaceLength }, content, { "length": rightSpaceLength }, rightEscape, rightHash, { "length": trailSpaceLength }] = match; + const leftHashLength = leftHash.length; + const rightHashLength = rightHash.length; + const left = !leftSpaceLength; + const right = !rightSpaceLength || rightEscape; + const rightEscapeReplacement = rightEscape ? `${rightEscape} ` : ""; if (left || right) { - var range = left ? + const range = left ? [ 1, leftHashLength + 1 @@ -3112,7 +3089,7 @@ module.exports = { addErrorContext(onError, lineIndex + 1, line.trim(), left, right, range, { "editColumn": 1, "deleteCount": line.length, - "insertText": "".concat(leftHash, " ").concat(content, " ").concat(rightEscapeReplacement).concat(rightHash) + "insertText": `${leftHash} ${content} ${rightEscapeReplacement}${rightHash}` }); } } @@ -3133,26 +3110,26 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, filterTokens = _a.filterTokens, headingStyleFor = _a.headingStyleFor; -var closedAtxRe = /^(#+)([ \t]+)([^ \t]|[^ \t].*[^ \t])([ \t]+)(#+)(\s*)$/; +const { addErrorContext, filterTokens, headingStyleFor } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const closedAtxRe = /^(#+)([ \t]+)([^ \t]|[^ \t].*[^ \t])([ \t]+)(#+)(\s*)$/; module.exports = { "names": ["MD021", "no-multiple-space-closed-atx"], "description": "Multiple spaces inside hashes on closed atx style heading", "tags": ["headings", "headers", "atx_closed", "spaces"], "function": function MD021(params, onError) { - filterTokens(params, "heading_open", function (token) { + filterTokens(params, "heading_open", (token) => { if (headingStyleFor(token) === "atx_closed") { - var line = token.line, lineNumber = token.lineNumber; - var match = closedAtxRe.exec(line); + const { line, lineNumber } = token; + const match = closedAtxRe.exec(line); if (match) { - var leftHash = match[1], leftSpaceLength = match[2]["length"], content = match[3], rightSpaceLength = match[4]["length"], rightHash = match[5], trailSpaceLength = match[6]["length"]; - var left = leftSpaceLength > 1; - var right = rightSpaceLength > 1; + const [, leftHash, { "length": leftSpaceLength }, content, { "length": rightSpaceLength }, rightHash, { "length": trailSpaceLength }] = match; + const left = leftSpaceLength > 1; + const right = rightSpaceLength > 1; if (left || right) { - var length = line.length; - var leftHashLength = leftHash.length; - var rightHashLength = rightHash.length; - var range = left ? + const length = line.length; + const leftHashLength = leftHash.length; + const rightHashLength = rightHash.length; + const range = left ? [ 1, leftHashLength + leftSpaceLength + 1 @@ -3164,7 +3141,7 @@ module.exports = { addErrorContext(onError, lineNumber, line.trim(), left, right, range, { "editColumn": 1, "deleteCount": length, - "insertText": "".concat(leftHash, " ").concat(content, " ").concat(rightHash) + "insertText": `${leftHash} ${content} ${rightHash}` }); } } @@ -3185,21 +3162,21 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorDetailIf = _a.addErrorDetailIf, filterTokens = _a.filterTokens, isBlankLine = _a.isBlankLine; +const { addErrorDetailIf, filterTokens, isBlankLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); module.exports = { "names": ["MD022", "blanks-around-headings", "blanks-around-headers"], "description": "Headings should be surrounded by blank lines", "tags": ["headings", "headers", "blank_lines"], "function": function MD022(params, onError) { - var linesAbove = params.config.lines_above; + let linesAbove = params.config.lines_above; linesAbove = Number((linesAbove === undefined) ? 1 : linesAbove); - var linesBelow = params.config.lines_below; + let linesBelow = params.config.lines_below; linesBelow = Number((linesBelow === undefined) ? 1 : linesBelow); - var lines = params.lines; - filterTokens(params, "heading_open", function (token) { - var _a = token.map, topIndex = _a[0], nextIndex = _a[1]; - var actualAbove = 0; - for (var i = 0; i < linesAbove; i++) { + const { lines } = params; + filterTokens(params, "heading_open", (token) => { + const [topIndex, nextIndex] = token.map; + let actualAbove = 0; + for (let i = 0; i < linesAbove; i++) { if (isBlankLine(lines[topIndex - i - 1])) { actualAbove++; } @@ -3207,8 +3184,8 @@ module.exports = { addErrorDetailIf(onError, topIndex + 1, linesAbove, actualAbove, "Above", lines[topIndex].trim(), null, { "insertText": "".padEnd(linesAbove - actualAbove, "\n") }); - var actualBelow = 0; - for (var i = 0; i < linesBelow; i++) { + let actualBelow = 0; + for (let i = 0; i < linesBelow; i++) { if (isBlankLine(lines[nextIndex + i])) { actualBelow++; } @@ -3233,20 +3210,20 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, filterTokens = _a.filterTokens; -var spaceBeforeHeadingRe = /^((?:\s+)|(?:[>\s]+\s\s))[^>\s]/; +const { addErrorContext, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const spaceBeforeHeadingRe = /^((?:\s+)|(?:[>\s]+\s\s))[^>\s]/; module.exports = { "names": ["MD023", "heading-start-left", "header-start-left"], "description": "Headings must start at the beginning of the line", "tags": ["headings", "headers", "spaces"], "function": function MD023(params, onError) { filterTokens(params, "heading_open", function forToken(token) { - var lineNumber = token.lineNumber, line = token.line; - var match = line.match(spaceBeforeHeadingRe); + const { lineNumber, line } = token; + const match = line.match(spaceBeforeHeadingRe); if (match) { - var prefixAndFirstChar = match[0], prefix = match[1]; - var deleteCount = prefix.length; - var prefixLengthNoSpace = prefix.trimEnd().length; + const [prefixAndFirstChar, prefix] = match; + let deleteCount = prefix.length; + const prefixLengthNoSpace = prefix.trimEnd().length; if (prefixLengthNoSpace) { deleteCount -= prefixLengthNoSpace - 1; } @@ -3271,20 +3248,20 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, forEachHeading = _a.forEachHeading; +const { addErrorContext, forEachHeading } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); module.exports = { "names": ["MD024", "no-duplicate-heading", "no-duplicate-header"], "description": "Multiple headings with the same content", "tags": ["headings", "headers"], "function": function MD024(params, onError) { - var siblingsOnly = !!params.config.siblings_only || + const siblingsOnly = !!params.config.siblings_only || !!params.config.allow_different_nesting || false; - var knownContents = [null, []]; - var lastLevel = 1; - var knownContent = knownContents[lastLevel]; - forEachHeading(params, function (heading, content) { + const knownContents = [null, []]; + let lastLevel = 1; + let knownContent = knownContents[lastLevel]; + forEachHeading(params, (heading, content) => { if (siblingsOnly) { - var newLevel = heading.tag.slice(1); + const newLevel = heading.tag.slice(1); while (lastLevel < newLevel) { lastLevel++; knownContents[lastLevel] = []; @@ -3317,16 +3294,16 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, filterTokens = _a.filterTokens, frontMatterHasTitle = _a.frontMatterHasTitle; +const { addErrorContext, filterTokens, frontMatterHasTitle } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); module.exports = { "names": ["MD025", "single-title", "single-h1"], "description": "Multiple top-level headings in the same document", "tags": ["headings", "headers"], "function": function MD025(params, onError) { - var level = Number(params.config.level || 1); - var tag = "h" + level; - var foundFrontMatterTitle = frontMatterHasTitle(params.frontMatterLines, params.config.front_matter_title); - var hasTopLevelHeading = false; + const level = Number(params.config.level || 1); + const tag = "h" + level; + const foundFrontMatterTitle = frontMatterHasTitle(params.frontMatterLines, params.config.front_matter_title); + let hasTopLevelHeading = false; filterTokens(params, "heading_open", function forToken(token) { if (token.tag === tag) { if (hasTopLevelHeading || foundFrontMatterTitle) { @@ -3352,25 +3329,25 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addError = _a.addError, allPunctuationNoQuestion = _a.allPunctuationNoQuestion, escapeForRegExp = _a.escapeForRegExp, forEachHeading = _a.forEachHeading; -var endOfLineHtmlEntityRe = /&#?[0-9a-zA-Z]+;$/; +const { addError, allPunctuationNoQuestion, escapeForRegExp, forEachHeading } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const endOfLineHtmlEntityRe = /&#?[0-9a-zA-Z]+;$/; module.exports = { "names": ["MD026", "no-trailing-punctuation"], "description": "Trailing punctuation in heading", "tags": ["headings", "headers"], "function": function MD026(params, onError) { - var punctuation = params.config.punctuation; + let punctuation = params.config.punctuation; punctuation = String((punctuation === undefined) ? allPunctuationNoQuestion : punctuation); - var trailingPunctuationRe = new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$"); - forEachHeading(params, function (heading) { - var line = heading.line, lineNumber = heading.lineNumber; - var trimmedLine = line.replace(/([^\s#])[\s#]+$/, "$1"); - var match = trailingPunctuationRe.exec(trimmedLine); + const trailingPunctuationRe = new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$"); + forEachHeading(params, (heading) => { + const { line, lineNumber } = heading; + const trimmedLine = line.replace(/([^\s#])[\s#]+$/, "$1"); + const match = trailingPunctuationRe.exec(trimmedLine); if (match && !endOfLineHtmlEntityRe.test(trimmedLine)) { - var fullMatch = match[0]; - var column = match.index + 1; - var length = fullMatch.length; - addError(onError, lineNumber, "Punctuation: '".concat(fullMatch, "'"), null, [column, length], { + const fullMatch = match[0]; + const column = match.index + 1; + const length = fullMatch.length; + addError(onError, lineNumber, `Punctuation: '${fullMatch}'`, null, [column, length], { "editColumn": column, "deleteCount": length }); @@ -3391,17 +3368,17 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, newLineRe = _a.newLineRe; -var spaceAfterBlockQuoteRe = /^((?:\s*>)+)(\s{2,})\S/; +const { addErrorContext, newLineRe } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const spaceAfterBlockQuoteRe = /^((?:\s*>)+)(\s{2,})\S/; module.exports = { "names": ["MD027", "no-multiple-space-blockquote"], "description": "Multiple spaces after blockquote symbol", "tags": ["blockquote", "whitespace", "indentation"], "function": function MD027(params, onError) { - var blockquoteNesting = 0; - var listItemNesting = 0; - params.tokens.forEach(function (token) { - var content = token.content, lineNumber = token.lineNumber, type = token.type; + let blockquoteNesting = 0; + let listItemNesting = 0; + params.tokens.forEach((token) => { + const { content, lineNumber, type } = token; if (type === "blockquote_open") { blockquoteNesting++; } @@ -3415,12 +3392,12 @@ module.exports = { listItemNesting--; } else if ((type === "inline") && blockquoteNesting) { - var lineCount = content.split(newLineRe).length; - for (var i = 0; i < lineCount; i++) { - var line = params.lines[lineNumber + i - 1]; - var match = line.match(spaceAfterBlockQuoteRe); + const lineCount = content.split(newLineRe).length; + for (let i = 0; i < lineCount; i++) { + const line = params.lines[lineNumber + i - 1]; + const match = line.match(spaceAfterBlockQuoteRe); if (match) { - var fullMatch = match[0], blockquoteLength = match[1]["length"], spaceLength = match[2]["length"]; + const [fullMatch, { "length": blockquoteLength }, { "length": spaceLength }] = match; if (!listItemNesting || (fullMatch[fullMatch.length - 1] === ">")) { addErrorContext(onError, lineNumber + i, line, null, null, [1, fullMatch.length], { "editColumn": blockquoteLength + 1, @@ -3446,18 +3423,18 @@ module.exports = { "use strict"; // @ts-check -var addError = (__webpack_require__(/*! ../helpers */ "../helpers/helpers.js").addError); +const { addError } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); module.exports = { "names": ["MD028", "no-blanks-blockquote"], "description": "Blank line inside blockquote", "tags": ["blockquote", "whitespace"], "function": function MD028(params, onError) { - var prevToken = {}; - var prevLineNumber = null; + let prevToken = {}; + let prevLineNumber = null; params.tokens.forEach(function forToken(token) { if ((token.type === "blockquote_open") && (prevToken.type === "blockquote_close")) { - for (var lineNumber = prevLineNumber; lineNumber < token.lineNumber; lineNumber++) { + for (let lineNumber = prevLineNumber; lineNumber < token.lineNumber; lineNumber++) { addError(onError, lineNumber); } } @@ -3481,9 +3458,9 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorDetailIf = _a.addErrorDetailIf, listItemMarkerRe = _a.listItemMarkerRe, orderedListItemMarkerRe = _a.orderedListItemMarkerRe, rangeFromRegExp = _a.rangeFromRegExp; -var flattenedLists = (__webpack_require__(/*! ./cache */ "../lib/cache.js").flattenedLists); -var listStyleExamples = { +const { addErrorDetailIf, listItemMarkerRe, orderedListItemMarkerRe, rangeFromRegExp } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { flattenedLists } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); +const listStyleExamples = { "one": "1/1/1", "ordered": "1/2/3", "zero": "0/0/0" @@ -3493,18 +3470,18 @@ module.exports = { "description": "Ordered list item prefix", "tags": ["ol"], "function": function MD029(params, onError) { - var style = String(params.config.style || "one_or_ordered"); - flattenedLists().filter(function (list) { return !list.unordered; }).forEach(function (list) { - var items = list.items; - var current = 1; - var incrementing = false; + const style = String(params.config.style || "one_or_ordered"); + flattenedLists().filter((list) => !list.unordered).forEach((list) => { + const { items } = list; + let current = 1; + let incrementing = false; // Check for incrementing number pattern 1/2/3 or 0/1/2 if (items.length >= 2) { - var first = orderedListItemMarkerRe.exec(items[0].line); - var second = orderedListItemMarkerRe.exec(items[1].line); + const first = orderedListItemMarkerRe.exec(items[0].line); + const second = orderedListItemMarkerRe.exec(items[1].line); if (first && second) { - var firstNumber = first[1]; - var secondNumber = second[1]; + const [, firstNumber] = first; + const [, secondNumber] = second; if ((secondNumber !== "1") || (firstNumber === "0")) { incrementing = true; if (firstNumber === "0") { @@ -3514,7 +3491,7 @@ module.exports = { } } // Determine effective style - var listStyle = style; + let listStyle = style; if (listStyle === "one_or_ordered") { listStyle = incrementing ? "ordered" : "one"; } @@ -3526,8 +3503,8 @@ module.exports = { current = 1; } // Validate each list item marker - items.forEach(function (item) { - var match = orderedListItemMarkerRe.exec(item.line); + items.forEach((item) => { + const match = orderedListItemMarkerRe.exec(item.line); if (match) { addErrorDetailIf(onError, item.lineNumber, String(current), match[1], "Style: " + listStyleExamples[listStyle], null, rangeFromRegExp(item.line, listItemMarkerRe)); if (listStyle === "ordered") { @@ -3551,29 +3528,29 @@ module.exports = { "use strict"; // @ts-check -var addErrorDetailIf = (__webpack_require__(/*! ../helpers */ "../helpers/helpers.js").addErrorDetailIf); -var flattenedLists = (__webpack_require__(/*! ./cache */ "../lib/cache.js").flattenedLists); +const { addErrorDetailIf } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { flattenedLists } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); module.exports = { "names": ["MD030", "list-marker-space"], "description": "Spaces after list markers", "tags": ["ol", "ul", "whitespace"], "function": function MD030(params, onError) { - var ulSingle = Number(params.config.ul_single || 1); - var olSingle = Number(params.config.ol_single || 1); - var ulMulti = Number(params.config.ul_multi || 1); - var olMulti = Number(params.config.ol_multi || 1); - flattenedLists().forEach(function (list) { - var lineCount = list.lastLineIndex - list.open.map[0]; - var allSingle = lineCount === list.items.length; - var expectedSpaces = list.unordered ? + const ulSingle = Number(params.config.ul_single || 1); + const olSingle = Number(params.config.ol_single || 1); + const ulMulti = Number(params.config.ul_multi || 1); + const olMulti = Number(params.config.ol_multi || 1); + flattenedLists().forEach((list) => { + const lineCount = list.lastLineIndex - list.open.map[0]; + const allSingle = lineCount === list.items.length; + const expectedSpaces = list.unordered ? (allSingle ? ulSingle : ulMulti) : (allSingle ? olSingle : olMulti); - list.items.forEach(function (item) { - var line = item.line, lineNumber = item.lineNumber; - var match = /^[\s>]*\S+(\s*)/.exec(line); - var matchLength = match[0]["length"], actualSpaces = match[1]["length"]; + list.items.forEach((item) => { + const { line, lineNumber } = item; + const match = /^[\s>]*\S+(\s*)/.exec(line); + const [{ "length": matchLength }, { "length": actualSpaces }] = match; if (matchLength < line.length) { - var fixInfo = null; + let fixInfo = null; if (expectedSpaces !== actualSpaces) { fixInfo = { "editColumn": matchLength - actualSpaces + 1, @@ -3600,27 +3577,27 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, forEachLine = _a.forEachLine, isBlankLine = _a.isBlankLine; -var lineMetadata = (__webpack_require__(/*! ./cache */ "../lib/cache.js").lineMetadata); -var codeFencePrefixRe = /^(.*?)[`~]/; +const { addErrorContext, forEachLine, isBlankLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); +const codeFencePrefixRe = /^(.*?)[`~]/; module.exports = { "names": ["MD031", "blanks-around-fences"], "description": "Fenced code blocks should be surrounded by blank lines", "tags": ["code", "blank_lines"], "function": function MD031(params, onError) { - var listItems = params.config.list_items; - var includeListItems = (listItems === undefined) ? true : !!listItems; - var lines = params.lines; - forEachLine(lineMetadata(), function (line, i, inCode, onFence, inTable, inItem) { - var onTopFence = (onFence > 0); - var onBottomFence = (onFence < 0); + const listItems = params.config.list_items; + const includeListItems = (listItems === undefined) ? true : !!listItems; + const { lines } = params; + forEachLine(lineMetadata(), (line, i, inCode, onFence, inTable, inItem) => { + const onTopFence = (onFence > 0); + const onBottomFence = (onFence < 0); if ((includeListItems || !inItem) && ((onTopFence && !isBlankLine(lines[i - 1])) || (onBottomFence && !isBlankLine(lines[i + 1])))) { - var _a = line.match(codeFencePrefixRe) || [], prefix = _a[1]; - var fixInfo = (prefix === undefined) ? null : { + const [, prefix] = line.match(codeFencePrefixRe) || []; + const fixInfo = (prefix === undefined) ? null : { "lineNumber": i + (onTopFence ? 1 : 2), - "insertText": "".concat(prefix.replace(/[^>]/g, " ").trim(), "\n") + "insertText": `${prefix.replace(/[^>]/g, " ").trim()}\n` }; addErrorContext(onError, i + 1, lines[i].trim(), null, null, null, fixInfo); } @@ -3640,31 +3617,31 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, isBlankLine = _a.isBlankLine; -var flattenedLists = (__webpack_require__(/*! ./cache */ "../lib/cache.js").flattenedLists); -var quotePrefixRe = /^[>\s]*/; +const { addErrorContext, isBlankLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { flattenedLists } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); +const quotePrefixRe = /^[>\s]*/; module.exports = { "names": ["MD032", "blanks-around-lists"], "description": "Lists should be surrounded by blank lines", "tags": ["bullet", "ul", "ol", "blank_lines"], "function": function MD032(params, onError) { - var lines = params.lines; - flattenedLists().filter(function (list) { return !list.nesting; }).forEach(function (list) { - var firstIndex = list.open.map[0]; + const { lines } = params; + flattenedLists().filter((list) => !list.nesting).forEach((list) => { + const firstIndex = list.open.map[0]; if (!isBlankLine(lines[firstIndex - 1])) { - var line = lines[firstIndex]; - var quotePrefix = line.match(quotePrefixRe)[0].trimEnd(); + const line = lines[firstIndex]; + const quotePrefix = line.match(quotePrefixRe)[0].trimEnd(); addErrorContext(onError, firstIndex + 1, line.trim(), null, null, null, { - "insertText": "".concat(quotePrefix, "\n") + "insertText": `${quotePrefix}\n` }); } - var lastIndex = list.lastLineIndex - 1; + const lastIndex = list.lastLineIndex - 1; if (!isBlankLine(lines[lastIndex + 1])) { - var line = lines[lastIndex]; - var quotePrefix = line.match(quotePrefixRe)[0].trimEnd(); + const line = lines[lastIndex]; + const quotePrefix = line.match(quotePrefixRe)[0].trimEnd(); addErrorContext(onError, lastIndex + 1, line.trim(), null, null, null, { "lineNumber": lastIndex + 2, - "insertText": "".concat(quotePrefix, "\n") + "insertText": `${quotePrefix}\n` }); } }); @@ -3683,11 +3660,11 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addError = _a.addError, forEachLine = _a.forEachLine, htmlElementRe = _a.htmlElementRe, overlapsAnyRange = _a.overlapsAnyRange, unescapeMarkdown = _a.unescapeMarkdown; -var _b = __webpack_require__(/*! ./cache */ "../lib/cache.js"), codeBlockAndSpanRanges = _b.codeBlockAndSpanRanges, lineMetadata = _b.lineMetadata; -var linkDestinationRe = /]\(\s*$/; +const { addError, forEachLine, htmlElementRe, overlapsAnyRange, unescapeMarkdown } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { codeBlockAndSpanRanges, lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); +const linkDestinationRe = /]\(\s*$/; // See https://spec.commonmark.org/0.29/#autolinks -var emailAddressRe = +const emailAddressRe = // eslint-disable-next-line max-len /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; module.exports = { @@ -3695,22 +3672,22 @@ module.exports = { "description": "Inline HTML", "tags": ["html"], "function": function MD033(params, onError) { - var allowedElements = params.config.allowed_elements; + let allowedElements = params.config.allowed_elements; allowedElements = Array.isArray(allowedElements) ? allowedElements : []; - allowedElements = allowedElements.map(function (element) { return element.toLowerCase(); }); - var exclusions = codeBlockAndSpanRanges(); - forEachLine(lineMetadata(), function (line, lineIndex, inCode) { - var match = null; + allowedElements = allowedElements.map((element) => element.toLowerCase()); + const exclusions = codeBlockAndSpanRanges(); + forEachLine(lineMetadata(), (line, lineIndex, inCode) => { + let match = null; // eslint-disable-next-line no-unmodified-loop-condition while (!inCode && ((match = htmlElementRe.exec(line)) !== null)) { - var tag = match[0], content = match[1], element = match[2]; + const [tag, content, element] = match; if (!allowedElements.includes(element.toLowerCase()) && !tag.endsWith("\\>") && !emailAddressRe.test(content) && !overlapsAnyRange(exclusions, lineIndex, match.index, match[0].length)) { - var prefix = line.substring(0, match.index); + const prefix = line.substring(0, match.index); if (!linkDestinationRe.test(prefix)) { - var unescaped = unescapeMarkdown(prefix + "<", "_"); + const unescaped = unescapeMarkdown(prefix + "<", "_"); if (!unescaped.endsWith("_")) { addError(onError, lineIndex + 1, "Element: " + element, null, [match.index + 1, tag.length]); } @@ -3733,17 +3710,17 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, bareUrlRe = _a.bareUrlRe, filterTokens = _a.filterTokens; +const { addErrorContext, bareUrlRe, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); module.exports = { "names": ["MD034", "no-bare-urls"], "description": "Bare URL used", "tags": ["links", "url"], "function": function MD034(params, onError) { - filterTokens(params, "inline", function (token) { - var inLink = false; - token.children.forEach(function (child) { - var content = child.content, line = child.line, lineNumber = child.lineNumber, type = child.type; - var match = null; + filterTokens(params, "inline", (token) => { + let inLink = false; + token.children.forEach((child) => { + const { content, line, lineNumber, type } = child; + let match = null; if (type === "link_open") { inLink = true; } @@ -3752,26 +3729,26 @@ module.exports = { } else if ((type === "text") && !inLink) { while ((match = bareUrlRe.exec(content)) !== null) { - var bareUrl = match[0]; - var matchIndex = match.index; - var bareUrlLength = bareUrl.length; + const [bareUrl] = match; + const matchIndex = match.index; + const bareUrlLength = bareUrl.length; // Allow "[https://example.com]" to avoid conflicts with // MD011/no-reversed-links; allow quoting as another way // of deliberately including a bare URL - var leftChar = content[matchIndex - 1]; - var rightChar = content[matchIndex + bareUrlLength]; + const leftChar = content[matchIndex - 1]; + const rightChar = content[matchIndex + bareUrlLength]; if (!((leftChar === "[") && (rightChar === "]")) && !((leftChar === "\"") && (rightChar === "\"")) && !((leftChar === "'") && (rightChar === "'"))) { - var index = line.indexOf(content); - var range = (index === -1) ? null : [ + const index = line.indexOf(content); + const range = (index === -1) ? null : [ index + matchIndex + 1, bareUrlLength ]; - var fixInfo = range ? { + const fixInfo = range ? { "editColumn": range[0], "deleteCount": range[1], - "insertText": "<".concat(bareUrl, ">") + "insertText": `<${bareUrl}>` } : null; addErrorContext(onError, lineNumber, bareUrl, null, null, range, fixInfo); } @@ -3794,17 +3771,17 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorDetailIf = _a.addErrorDetailIf, filterTokens = _a.filterTokens; +const { addErrorDetailIf, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); module.exports = { "names": ["MD035", "hr-style"], "description": "Horizontal rule style", "tags": ["hr"], "function": function MD035(params, onError) { - var style = String(params.config.style || "consistent").trim(); - filterTokens(params, "hr", function (token) { - var line = token.line, lineNumber = token.lineNumber; - var markup = token.markup; - var match = line.match(/[_*\-\s\t]+$/); + let style = String(params.config.style || "consistent").trim(); + filterTokens(params, "hr", (token) => { + const { line, lineNumber } = token; + let { markup } = token; + const match = line.match(/[_*\-\s\t]+$/); if (match) { markup = match[0].trim(); } @@ -3828,22 +3805,22 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, allPunctuation = _a.allPunctuation; +const { addErrorContext, allPunctuation } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); module.exports = { "names": ["MD036", "no-emphasis-as-heading", "no-emphasis-as-header"], "description": "Emphasis used instead of a heading", "tags": ["headings", "headers", "emphasis"], "function": function MD036(params, onError) { - var punctuation = params.config.punctuation; + let punctuation = params.config.punctuation; punctuation = String((punctuation === undefined) ? allPunctuation : punctuation); - var re = new RegExp("[" + punctuation + "]$"); + const re = new RegExp("[" + punctuation + "]$"); // eslint-disable-next-line jsdoc/require-jsdoc function base(token) { if (token.type === "paragraph_open") { return function inParagraph(t) { // Always paragraph_open/inline/paragraph_close, - var children = t.children.filter(function notEmptyText(child) { + const children = t.children.filter(function notEmptyText(child) { return (child.type !== "text") || (child.content !== ""); }); if ((children.length === 3) && @@ -3874,7 +3851,7 @@ module.exports = { } return base; } - var state = base; + let state = base; params.tokens.forEach(function forToken(token) { state = state(token); }); @@ -3893,21 +3870,21 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, emphasisMarkersInContent = _a.emphasisMarkersInContent, forEachLine = _a.forEachLine, isBlankLine = _a.isBlankLine; -var lineMetadata = (__webpack_require__(/*! ./cache */ "../lib/cache.js").lineMetadata); -var emphasisRe = /(^|[^\\]|\\\\)(?:(\*\*?\*?)|(__?_?))/g; -var embeddedUnderscoreRe = /([A-Za-z0-9])_([A-Za-z0-9])/g; -var asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/; -var leftSpaceRe = /^\s+/; -var rightSpaceRe = /\s+$/; -var tablePipeRe = /\|/; +const { addErrorContext, emphasisMarkersInContent, forEachLine, isBlankLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const { lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); +const emphasisRe = /(^|[^\\]|\\\\)(?:(\*\*?\*?)|(__?_?))/g; +const embeddedUnderscoreRe = /([A-Za-z0-9])_([A-Za-z0-9])/g; +const asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/; +const leftSpaceRe = /^\s+/; +const rightSpaceRe = /\s+$/; +const tablePipeRe = /\|/; module.exports = { "names": ["MD037", "no-space-in-emphasis"], "description": "Spaces inside emphasis markers", "tags": ["whitespace", "emphasis"], "function": function MD037(params, onError) { // eslint-disable-next-line init-declarations - var effectiveEmphasisLength, emphasisIndex, emphasisKind, emphasisLength, pendingError = null; + let effectiveEmphasisLength, emphasisIndex, emphasisKind, emphasisLength, pendingError = null; // eslint-disable-next-line jsdoc/require-jsdoc function resetRunTracking() { emphasisIndex = -1; @@ -3919,26 +3896,26 @@ module.exports = { // eslint-disable-next-line jsdoc/require-jsdoc function handleRunEnd(line, lineIndex, contextLength, match, matchIndex, inTable) { // Close current run - var content = line.substring(emphasisIndex, matchIndex); + let content = line.substring(emphasisIndex, matchIndex); if (!emphasisLength) { content = content.trimStart(); } if (!match) { content = content.trimEnd(); } - var leftSpace = leftSpaceRe.test(content); - var rightSpace = rightSpaceRe.test(content); + const leftSpace = leftSpaceRe.test(content); + const rightSpace = rightSpaceRe.test(content); if ((leftSpace || rightSpace) && (!inTable || !tablePipeRe.test(content))) { // Report the violation - var contextStart = emphasisIndex - emphasisLength; - var contextEnd = matchIndex + contextLength; - var context = line.substring(contextStart, contextEnd); - var column = contextStart + 1; - var length = contextEnd - contextStart; - var leftMarker = line.substring(contextStart, emphasisIndex); - var rightMarker = match ? (match[2] || match[3]) : ""; - var fixedText = "".concat(leftMarker).concat(content.trim()).concat(rightMarker); + const contextStart = emphasisIndex - emphasisLength; + const contextEnd = matchIndex + contextLength; + const context = line.substring(contextStart, contextEnd); + const column = contextStart + 1; + const length = contextEnd - contextStart; + const leftMarker = line.substring(contextStart, emphasisIndex); + const rightMarker = match ? (match[2] || match[3]) : ""; + const fixedText = `${leftMarker}${content.trim()}${rightMarker}`; return [ onError, lineIndex + 1, @@ -3956,10 +3933,10 @@ module.exports = { return null; } // Initialize - var ignoreMarkersByLine = emphasisMarkersInContent(params); + const ignoreMarkersByLine = emphasisMarkersInContent(params); resetRunTracking(); - forEachLine(lineMetadata(), function (line, lineIndex, inCode, onFence, inTable, inItem, onBreak, inMath) { - var onItemStart = (inItem === 1); + forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence, inTable, inItem, onBreak, inMath) => { + const onItemStart = (inItem === 1); if (inCode || onFence || inTable || @@ -3976,22 +3953,22 @@ module.exports = { // Emphasis has no meaning here return; } - var patchedLine = line.replace(embeddedUnderscoreRe, "$1 $2"); + let patchedLine = line.replace(embeddedUnderscoreRe, "$1 $2"); if (onItemStart) { // Trim overlapping '*' list item marker patchedLine = patchedLine.replace(asteriskListItemMarkerRe, "$1 $2"); } - var match = null; + let match = null; // Match all emphasis-looking runs in the line... while ((match = emphasisRe.exec(patchedLine))) { - var ignoreMarkersForLine = ignoreMarkersByLine[lineIndex]; - var matchIndex = match.index + match[1].length; + const ignoreMarkersForLine = ignoreMarkersByLine[lineIndex]; + const matchIndex = match.index + match[1].length; if (ignoreMarkersForLine.includes(matchIndex)) { // Ignore emphasis markers inside code spans and links continue; } - var matchLength = match[0].length - match[1].length; - var matchKind = (match[2] || match[3])[0]; + const matchLength = match[0].length - match[1].length; + const matchKind = (match[2] || match[3])[0]; if (emphasisIndex === -1) { // New run emphasisIndex = matchIndex + matchLength; @@ -4005,13 +3982,13 @@ module.exports = { // Ending an existing run, report any pending error if (pendingError) { // @ts-ignore - addErrorContext.apply(void 0, pendingError); + addErrorContext(...pendingError); pendingError = null; } - var error = handleRunEnd(line, lineIndex, effectiveEmphasisLength, match, matchIndex, inTable); + const error = handleRunEnd(line, lineIndex, effectiveEmphasisLength, match, matchIndex, inTable); if (error) { // @ts-ignore - addErrorContext.apply(void 0, error); + addErrorContext(...error); } // Reset resetRunTracking(); @@ -4063,43 +4040,43 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, filterTokens = _a.filterTokens, forEachInlineCodeSpan = _a.forEachInlineCodeSpan, newLineRe = _a.newLineRe; -var leftSpaceRe = /^\s([^`]|$)/; -var rightSpaceRe = /[^`]\s$/; -var singleLeftRightSpaceRe = /^\s(?:\S.*\S|\S)\s$/; +const { addErrorContext, filterTokens, forEachInlineCodeSpan, newLineRe } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const leftSpaceRe = /^\s([^`]|$)/; +const rightSpaceRe = /[^`]\s$/; +const singleLeftRightSpaceRe = /^\s(?:\S.*\S|\S)\s$/; module.exports = { "names": ["MD038", "no-space-in-code"], "description": "Spaces inside code span elements", "tags": ["whitespace", "code"], "function": function MD038(params, onError) { - filterTokens(params, "inline", function (token) { - if (token.children.some(function (child) { return child.type === "code_inline"; })) { - var tokenLines_1 = params.lines.slice(token.map[0], token.map[1]); - forEachInlineCodeSpan(tokenLines_1.join("\n"), function (code, lineIndex, columnIndex, tickCount) { - var rangeIndex = columnIndex - tickCount; - var rangeLength = code.length + (2 * tickCount); - var rangeLineOffset = 0; - var fixIndex = columnIndex; - var fixLength = code.length; - var codeLines = code.split(newLineRe); - var left = leftSpaceRe.test(code); - var right = !left && rightSpaceRe.test(code); + filterTokens(params, "inline", (token) => { + if (token.children.some((child) => child.type === "code_inline")) { + const tokenLines = params.lines.slice(token.map[0], token.map[1]); + forEachInlineCodeSpan(tokenLines.join("\n"), (code, lineIndex, columnIndex, tickCount) => { + let rangeIndex = columnIndex - tickCount; + let rangeLength = code.length + (2 * tickCount); + let rangeLineOffset = 0; + let fixIndex = columnIndex; + let fixLength = code.length; + const codeLines = code.split(newLineRe); + const left = leftSpaceRe.test(code); + const right = !left && rightSpaceRe.test(code); if (right && (codeLines.length > 1)) { rangeIndex = 0; rangeLineOffset = codeLines.length - 1; fixIndex = 0; } - var allowed = singleLeftRightSpaceRe.test(code); + const allowed = singleLeftRightSpaceRe.test(code); if ((left || right) && !allowed) { - var codeLinesRange = codeLines[rangeLineOffset]; + const codeLinesRange = codeLines[rangeLineOffset]; if (codeLines.length > 1) { rangeLength = codeLinesRange.length + tickCount; fixLength = codeLinesRange.length; } - var context = tokenLines_1[lineIndex + rangeLineOffset] + const context = tokenLines[lineIndex + rangeLineOffset] .substring(rangeIndex, rangeIndex + rangeLength); - var codeLinesRangeTrim = codeLinesRange.trim(); - var fixText = (codeLinesRangeTrim.startsWith("`") ? " " : "") + + const codeLinesRangeTrim = codeLinesRange.trim(); + const fixText = (codeLinesRangeTrim.startsWith("`") ? " " : "") + codeLinesRangeTrim + (codeLinesRangeTrim.endsWith("`") ? " " : ""); addErrorContext(onError, token.lineNumber + lineIndex + rangeLineOffset, context, left, right, [rangeIndex + 1, rangeLength], { @@ -4126,37 +4103,37 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, filterTokens = _a.filterTokens; -var spaceInLinkRe = /\[(?:\s+(?:[^\]]*?)\s*|(?:[^\]]*?)\s+)](?=((?:\([^)]*\))|(?:\[[^\]]*\])))/; +const { addErrorContext, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +const spaceInLinkRe = /\[(?:\s+(?:[^\]]*?)\s*|(?:[^\]]*?)\s+)](?=((?:\([^)]*\))|(?:\[[^\]]*\])))/; module.exports = { "names": ["MD039", "no-space-in-links"], "description": "Spaces inside link text", "tags": ["whitespace", "links"], "function": function MD039(params, onError) { - filterTokens(params, "inline", function (token) { - var children = token.children; - var lineNumber = token.lineNumber; - var inLink = false; - var linkText = ""; - var lineIndex = 0; - children.forEach(function (child) { - var content = child.content, markup = child.markup, type = child.type; + filterTokens(params, "inline", (token) => { + const { children } = token; + let { lineNumber } = token; + let inLink = false; + let linkText = ""; + let lineIndex = 0; + children.forEach((child) => { + const { content, markup, type } = child; if (type === "link_open") { inLink = true; linkText = ""; } else if (type === "link_close") { inLink = false; - var left = linkText.trimStart().length !== linkText.length; - var right = linkText.trimEnd().length !== linkText.length; + const left = linkText.trimStart().length !== linkText.length; + const right = linkText.trimEnd().length !== linkText.length; if (left || right) { - var line = params.lines[lineNumber - 1]; - var range = null; - var fixInfo = null; - var match = line.slice(lineIndex).match(spaceInLinkRe); + const line = params.lines[lineNumber - 1]; + let range = null; + let fixInfo = null; + const match = line.slice(lineIndex).match(spaceInLinkRe); if (match) { - var column = match.index + lineIndex + 1; - var length = match[0].length; + const column = match.index + lineIndex + 1; + const length = match[0].length; range = [column, length]; fixInfo = { "editColumn": column + 1, @@ -4165,7 +4142,7 @@ module.exports = { }; lineIndex = column + length - 1; } - addErrorContext(onError, lineNumber, "[".concat(linkText, "]"), left, right, range, fixInfo); + addErrorContext(onError, lineNumber, `[${linkText}]`, left, right, range, fixInfo); } } else if ((type === "softbreak") || (type === "hardbreak")) { @@ -4174,7 +4151,7 @@ module.exports = { } else if (inLink) { linkText += type.endsWith("_inline") ? - "".concat(markup).concat(content).concat(markup) : + `${markup}${content}${markup}` : (content || markup); } }); @@ -4194,7 +4171,7 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, filterTokens = _a.filterTokens; +const { addErrorContext, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); module.exports = { "names": ["MD040", "fenced-code-language"], "description": "Fenced code blocks should have a language specified", @@ -4220,25 +4197,25 @@ module.exports = { "use strict"; // @ts-check -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, frontMatterHasTitle = _a.frontMatterHasTitle; +const { addErrorContext, frontMatterHasTitle } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); module.exports = { "names": ["MD041", "first-line-heading", "first-line-h1"], "description": "First line in a file should be a top-level heading", "tags": ["headings", "headers"], "function": function MD041(params, onError) { - var level = Number(params.config.level || 1); - var tag = "h" + level; - var foundFrontMatterTitle = frontMatterHasTitle(params.frontMatterLines, params.config.front_matter_title); + const level = Number(params.config.level || 1); + const tag = "h" + level; + const foundFrontMatterTitle = frontMatterHasTitle(params.frontMatterLines, params.config.front_matter_title); if (!foundFrontMatterTitle) { - var htmlHeadingRe_1 = new RegExp("^]"), "i"); - params.tokens.every(function (token) { - var isError = false; + const htmlHeadingRe = new RegExp(`^]`, "i"); + params.tokens.every((token) => { + let isError = false; if (token.type === "html_block") { if (token.content.startsWith("