mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 05:50:13 +01:00
Reimplement MD013/line-length using micromark tokens.
This commit is contained in:
parent
4072cf7417
commit
3b581a7f6d
10 changed files with 173 additions and 185 deletions
|
|
@ -181,24 +181,6 @@ function isBlankLine(line) {
|
||||||
}
|
}
|
||||||
module.exports.isBlankLine = isBlankLine;
|
module.exports.isBlankLine = isBlankLine;
|
||||||
|
|
||||||
// Returns true iff the sorted array contains the specified element
|
|
||||||
module.exports.includesSorted = function includesSorted(array, element) {
|
|
||||||
let left = 0;
|
|
||||||
let right = array.length - 1;
|
|
||||||
while (left <= right) {
|
|
||||||
// eslint-disable-next-line no-bitwise
|
|
||||||
const mid = (left + right) >> 1;
|
|
||||||
if (array[mid] < element) {
|
|
||||||
left = mid + 1;
|
|
||||||
} else if (array[mid] > element) {
|
|
||||||
right = mid - 1;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Replaces the content of properly-formatted CommonMark comments with "."
|
// Replaces the content of properly-formatted CommonMark comments with "."
|
||||||
// This preserves the line/column information for the rest of the document
|
// 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-blocks
|
||||||
|
|
@ -472,20 +454,6 @@ module.exports.flattenLists = function flattenLists(tokens) {
|
||||||
return flattenedLists;
|
return flattenedLists;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calls the provided function for each heading's content
|
|
||||||
module.exports.forEachHeading = function forEachHeading(params, handler) {
|
|
||||||
let heading = null;
|
|
||||||
for (const token of params.parsers.markdownit.tokens) {
|
|
||||||
if (token.type === "heading_open") {
|
|
||||||
heading = token;
|
|
||||||
} else if (token.type === "heading_close") {
|
|
||||||
heading = null;
|
|
||||||
} else if ((token.type === "inline") && heading) {
|
|
||||||
handler(heading, token.content, token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @callback InlineCodeSpanCallback
|
* @callback InlineCodeSpanCallback
|
||||||
* @param {string} code Code content.
|
* @param {string} code Code content.
|
||||||
|
|
@ -1445,6 +1413,20 @@ function micromarkParse(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a range of numbers to a set.
|
||||||
|
*
|
||||||
|
* @param {Set<number>} set Set of numbers.
|
||||||
|
* @param {number} start Starting number.
|
||||||
|
* @param {number} end Ending number.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function addRangeToSet(set, start, end) {
|
||||||
|
for (let i = start; i <= end; i++) {
|
||||||
|
set.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @callback AllowedPredicate
|
* @callback AllowedPredicate
|
||||||
* @param {Token} token Micromark token.
|
* @param {Token} token Micromark token.
|
||||||
|
|
@ -1699,6 +1681,7 @@ const nonContentTokens = new Set([
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"parse": micromarkParse,
|
"parse": micromarkParse,
|
||||||
|
addRangeToSet,
|
||||||
filterByPredicate,
|
filterByPredicate,
|
||||||
filterByTypes,
|
filterByTypes,
|
||||||
getDescendantsByType,
|
getDescendantsByType,
|
||||||
|
|
@ -3737,21 +3720,7 @@ module.exports = {
|
||||||
|
|
||||||
|
|
||||||
const { addError } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
const { addError } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||||
const { filterByTypes } = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs");
|
const { addRangeToSet, filterByTypes } = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs");
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a range of numbers to a set.
|
|
||||||
*
|
|
||||||
* @param {Set<number>} set Set of numbers.
|
|
||||||
* @param {number} start Starting number.
|
|
||||||
* @param {number} end Ending number.
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function addRangeToSet(set, start, end) {
|
|
||||||
for (let i = start; i <= end; i++) {
|
|
||||||
set.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line jsdoc/valid-types
|
// eslint-disable-next-line jsdoc/valid-types
|
||||||
/** @type import("./markdownlint").Rule */
|
/** @type import("./markdownlint").Rule */
|
||||||
|
|
@ -4061,25 +4030,14 @@ module.exports = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const { addErrorDetailIf, filterTokens, forEachHeading, forEachLine,
|
const { addErrorDetailIf } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||||
includesSorted } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
const { referenceLinkImageData } = __webpack_require__(/*! ./cache */ "../lib/cache.js");
|
||||||
const { lineMetadata, referenceLinkImageData } = __webpack_require__(/*! ./cache */ "../lib/cache.js");
|
const { addRangeToSet, filterByTypes, getDescendantsByType } = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs");
|
||||||
|
|
||||||
const longLineRePrefix = "^.{";
|
const longLineRePrefix = "^.{";
|
||||||
const longLineRePostfixRelaxed = "}.*\\s.*$";
|
const longLineRePostfixRelaxed = "}.*\\s.*$";
|
||||||
const longLineRePostfixStrict = "}.+$";
|
const longLineRePostfixStrict = "}.+$";
|
||||||
const linkOrImageOnlyLineRe = /^[es]*(?:lT?L|I)[ES]*$/;
|
|
||||||
const sternModeRe = /^(?:[#>\s]*\s)?\S*$/;
|
const sternModeRe = /^(?:[#>\s]*\s)?\S*$/;
|
||||||
const tokenTypeMap = {
|
|
||||||
"em_open": "e",
|
|
||||||
"em_close": "E",
|
|
||||||
"image": "I",
|
|
||||||
"link_open": "l",
|
|
||||||
"link_close": "L",
|
|
||||||
"strong_open": "s",
|
|
||||||
"strong_close": "S",
|
|
||||||
"text": "T"
|
|
||||||
};
|
|
||||||
|
|
||||||
// eslint-disable-next-line jsdoc/valid-types
|
// eslint-disable-next-line jsdoc/valid-types
|
||||||
/** @type import("./markdownlint").Rule */
|
/** @type import("./markdownlint").Rule */
|
||||||
|
|
@ -4087,7 +4045,7 @@ module.exports = {
|
||||||
"names": [ "MD013", "line-length" ],
|
"names": [ "MD013", "line-length" ],
|
||||||
"description": "Line length",
|
"description": "Line length",
|
||||||
"tags": [ "line_length" ],
|
"tags": [ "line_length" ],
|
||||||
"parser": "markdownit",
|
"parser": "micromark",
|
||||||
"function": function MD013(params, onError) {
|
"function": function MD013(params, onError) {
|
||||||
const lineLength = Number(params.config.line_length || 80);
|
const lineLength = Number(params.config.line_length || 80);
|
||||||
const headingLineLength =
|
const headingLineLength =
|
||||||
|
|
@ -4110,26 +4068,42 @@ module.exports = {
|
||||||
const includeTables = (tables === undefined) ? true : !!tables;
|
const includeTables = (tables === undefined) ? true : !!tables;
|
||||||
const headings = params.config.headings;
|
const headings = params.config.headings;
|
||||||
const includeHeadings = (headings === undefined) ? true : !!headings;
|
const includeHeadings = (headings === undefined) ? true : !!headings;
|
||||||
const headingLineNumbers = [];
|
const { tokens } = params.parsers.micromark;
|
||||||
forEachHeading(params, (heading) => {
|
const headingLineNumbers = new Set();
|
||||||
headingLineNumbers.push(heading.lineNumber);
|
for (const heading of filterByTypes(tokens, [ "atxHeading", "setextHeading" ])) {
|
||||||
});
|
addRangeToSet(headingLineNumbers, heading.startLine, heading.endLine);
|
||||||
const linkOnlyLineNumbers = [];
|
}
|
||||||
filterTokens(params, "inline", (token) => {
|
const codeBlockLineNumbers = new Set();
|
||||||
let childTokenTypes = "";
|
for (const codeBlock of filterByTypes(tokens, [ "codeFenced", "codeIndented" ])) {
|
||||||
for (const child of token.children) {
|
addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
|
||||||
if (child.type !== "text" || child.content !== "") {
|
}
|
||||||
childTokenTypes += tokenTypeMap[child.type] || "x";
|
const tableLineNumbers = new Set();
|
||||||
}
|
for (const table of filterByTypes(tokens, [ "table" ])) {
|
||||||
|
addRangeToSet(tableLineNumbers, table.startLine, table.endLine);
|
||||||
|
}
|
||||||
|
const linkLineNumbers = new Set();
|
||||||
|
for (const link of filterByTypes(tokens, [ "autolink", "image", "link", "literalAutolink" ])) {
|
||||||
|
addRangeToSet(linkLineNumbers, link.startLine, link.endLine);
|
||||||
|
}
|
||||||
|
const paragraphDataLineNumbers = new Set();
|
||||||
|
for (const paragraph of filterByTypes(tokens, [ "paragraph" ])) {
|
||||||
|
for (const data of getDescendantsByType(paragraph, [ "data" ])) {
|
||||||
|
addRangeToSet(paragraphDataLineNumbers, data.startLine, data.endLine);
|
||||||
}
|
}
|
||||||
if (linkOrImageOnlyLineRe.test(childTokenTypes)) {
|
}
|
||||||
linkOnlyLineNumbers.push(token.lineNumber);
|
const linkOnlyLineNumbers = new Set();
|
||||||
|
for (const lineNumber of linkLineNumbers) {
|
||||||
|
if (!paragraphDataLineNumbers.has(lineNumber)) {
|
||||||
|
linkOnlyLineNumbers.add(lineNumber);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
const { definitionLineIndices } = referenceLinkImageData();
|
const definitionLineIndices = new Set(referenceLinkImageData().definitionLineIndices);
|
||||||
forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence, inTable) => {
|
for (let lineIndex = 0; lineIndex < params.lines.length; lineIndex++) {
|
||||||
|
const line = params.lines[lineIndex];
|
||||||
const lineNumber = lineIndex + 1;
|
const lineNumber = lineIndex + 1;
|
||||||
const isHeading = includesSorted(headingLineNumbers, lineNumber);
|
const isHeading = headingLineNumbers.has(lineNumber);
|
||||||
|
const inCode = codeBlockLineNumbers.has(lineNumber);
|
||||||
|
const inTable = tableLineNumbers.has(lineNumber);
|
||||||
const length = inCode ?
|
const length = inCode ?
|
||||||
codeLineLength :
|
codeLineLength :
|
||||||
(isHeading ? headingLineLength : lineLength);
|
(isHeading ? headingLineLength : lineLength);
|
||||||
|
|
@ -4139,10 +4113,10 @@ module.exports = {
|
||||||
if ((includeCodeBlocks || !inCode) &&
|
if ((includeCodeBlocks || !inCode) &&
|
||||||
(includeTables || !inTable) &&
|
(includeTables || !inTable) &&
|
||||||
(includeHeadings || !isHeading) &&
|
(includeHeadings || !isHeading) &&
|
||||||
!includesSorted(definitionLineIndices, lineIndex) &&
|
!definitionLineIndices.has(lineIndex) &&
|
||||||
(strict ||
|
(strict ||
|
||||||
(!(stern && sternModeRe.test(line)) &&
|
(!(stern && sternModeRe.test(line)) &&
|
||||||
!includesSorted(linkOnlyLineNumbers, lineNumber))) &&
|
!linkOnlyLineNumbers.has(lineNumber))) &&
|
||||||
lengthRe.test(line)) {
|
lengthRe.test(line)) {
|
||||||
addErrorDetailIf(
|
addErrorDetailIf(
|
||||||
onError,
|
onError,
|
||||||
|
|
@ -4151,9 +4125,10 @@ module.exports = {
|
||||||
line.length,
|
line.length,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
[ length + 1, line.length - length ]);
|
[ length + 1, line.length - length ]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -169,24 +169,6 @@ function isBlankLine(line) {
|
||||||
}
|
}
|
||||||
module.exports.isBlankLine = isBlankLine;
|
module.exports.isBlankLine = isBlankLine;
|
||||||
|
|
||||||
// Returns true iff the sorted array contains the specified element
|
|
||||||
module.exports.includesSorted = function includesSorted(array, element) {
|
|
||||||
let left = 0;
|
|
||||||
let right = array.length - 1;
|
|
||||||
while (left <= right) {
|
|
||||||
// eslint-disable-next-line no-bitwise
|
|
||||||
const mid = (left + right) >> 1;
|
|
||||||
if (array[mid] < element) {
|
|
||||||
left = mid + 1;
|
|
||||||
} else if (array[mid] > element) {
|
|
||||||
right = mid - 1;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Replaces the content of properly-formatted CommonMark comments with "."
|
// Replaces the content of properly-formatted CommonMark comments with "."
|
||||||
// This preserves the line/column information for the rest of the document
|
// 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-blocks
|
||||||
|
|
@ -460,20 +442,6 @@ module.exports.flattenLists = function flattenLists(tokens) {
|
||||||
return flattenedLists;
|
return flattenedLists;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calls the provided function for each heading's content
|
|
||||||
module.exports.forEachHeading = function forEachHeading(params, handler) {
|
|
||||||
let heading = null;
|
|
||||||
for (const token of params.parsers.markdownit.tokens) {
|
|
||||||
if (token.type === "heading_open") {
|
|
||||||
heading = token;
|
|
||||||
} else if (token.type === "heading_close") {
|
|
||||||
heading = null;
|
|
||||||
} else if ((token.type === "inline") && heading) {
|
|
||||||
handler(heading, token.content, token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @callback InlineCodeSpanCallback
|
* @callback InlineCodeSpanCallback
|
||||||
* @param {string} code Code content.
|
* @param {string} code Code content.
|
||||||
|
|
|
||||||
|
|
@ -231,6 +231,20 @@ function micromarkParse(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a range of numbers to a set.
|
||||||
|
*
|
||||||
|
* @param {Set<number>} set Set of numbers.
|
||||||
|
* @param {number} start Starting number.
|
||||||
|
* @param {number} end Ending number.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function addRangeToSet(set, start, end) {
|
||||||
|
for (let i = start; i <= end; i++) {
|
||||||
|
set.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @callback AllowedPredicate
|
* @callback AllowedPredicate
|
||||||
* @param {Token} token Micromark token.
|
* @param {Token} token Micromark token.
|
||||||
|
|
@ -485,6 +499,7 @@ const nonContentTokens = new Set([
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"parse": micromarkParse,
|
"parse": micromarkParse,
|
||||||
|
addRangeToSet,
|
||||||
filterByPredicate,
|
filterByPredicate,
|
||||||
filterByTypes,
|
filterByTypes,
|
||||||
getDescendantsByType,
|
getDescendantsByType,
|
||||||
|
|
|
||||||
16
lib/md009.js
16
lib/md009.js
|
|
@ -3,21 +3,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { addError } = require("../helpers");
|
const { addError } = require("../helpers");
|
||||||
const { filterByTypes } = require("../helpers/micromark.cjs");
|
const { addRangeToSet, filterByTypes } = require("../helpers/micromark.cjs");
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a range of numbers to a set.
|
|
||||||
*
|
|
||||||
* @param {Set<number>} set Set of numbers.
|
|
||||||
* @param {number} start Starting number.
|
|
||||||
* @param {number} end Ending number.
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function addRangeToSet(set, start, end) {
|
|
||||||
for (let i = start; i <= end; i++) {
|
|
||||||
set.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line jsdoc/valid-types
|
// eslint-disable-next-line jsdoc/valid-types
|
||||||
/** @type import("./markdownlint").Rule */
|
/** @type import("./markdownlint").Rule */
|
||||||
|
|
|
||||||
78
lib/md013.js
78
lib/md013.js
|
|
@ -2,25 +2,14 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { addErrorDetailIf, filterTokens, forEachHeading, forEachLine,
|
const { addErrorDetailIf } = require("../helpers");
|
||||||
includesSorted } = require("../helpers");
|
const { referenceLinkImageData } = require("./cache");
|
||||||
const { lineMetadata, referenceLinkImageData } = require("./cache");
|
const { addRangeToSet, filterByTypes, getDescendantsByType } = require("../helpers/micromark.cjs");
|
||||||
|
|
||||||
const longLineRePrefix = "^.{";
|
const longLineRePrefix = "^.{";
|
||||||
const longLineRePostfixRelaxed = "}.*\\s.*$";
|
const longLineRePostfixRelaxed = "}.*\\s.*$";
|
||||||
const longLineRePostfixStrict = "}.+$";
|
const longLineRePostfixStrict = "}.+$";
|
||||||
const linkOrImageOnlyLineRe = /^[es]*(?:lT?L|I)[ES]*$/;
|
|
||||||
const sternModeRe = /^(?:[#>\s]*\s)?\S*$/;
|
const sternModeRe = /^(?:[#>\s]*\s)?\S*$/;
|
||||||
const tokenTypeMap = {
|
|
||||||
"em_open": "e",
|
|
||||||
"em_close": "E",
|
|
||||||
"image": "I",
|
|
||||||
"link_open": "l",
|
|
||||||
"link_close": "L",
|
|
||||||
"strong_open": "s",
|
|
||||||
"strong_close": "S",
|
|
||||||
"text": "T"
|
|
||||||
};
|
|
||||||
|
|
||||||
// eslint-disable-next-line jsdoc/valid-types
|
// eslint-disable-next-line jsdoc/valid-types
|
||||||
/** @type import("./markdownlint").Rule */
|
/** @type import("./markdownlint").Rule */
|
||||||
|
|
@ -28,7 +17,7 @@ module.exports = {
|
||||||
"names": [ "MD013", "line-length" ],
|
"names": [ "MD013", "line-length" ],
|
||||||
"description": "Line length",
|
"description": "Line length",
|
||||||
"tags": [ "line_length" ],
|
"tags": [ "line_length" ],
|
||||||
"parser": "markdownit",
|
"parser": "micromark",
|
||||||
"function": function MD013(params, onError) {
|
"function": function MD013(params, onError) {
|
||||||
const lineLength = Number(params.config.line_length || 80);
|
const lineLength = Number(params.config.line_length || 80);
|
||||||
const headingLineLength =
|
const headingLineLength =
|
||||||
|
|
@ -51,26 +40,42 @@ module.exports = {
|
||||||
const includeTables = (tables === undefined) ? true : !!tables;
|
const includeTables = (tables === undefined) ? true : !!tables;
|
||||||
const headings = params.config.headings;
|
const headings = params.config.headings;
|
||||||
const includeHeadings = (headings === undefined) ? true : !!headings;
|
const includeHeadings = (headings === undefined) ? true : !!headings;
|
||||||
const headingLineNumbers = [];
|
const { tokens } = params.parsers.micromark;
|
||||||
forEachHeading(params, (heading) => {
|
const headingLineNumbers = new Set();
|
||||||
headingLineNumbers.push(heading.lineNumber);
|
for (const heading of filterByTypes(tokens, [ "atxHeading", "setextHeading" ])) {
|
||||||
});
|
addRangeToSet(headingLineNumbers, heading.startLine, heading.endLine);
|
||||||
const linkOnlyLineNumbers = [];
|
}
|
||||||
filterTokens(params, "inline", (token) => {
|
const codeBlockLineNumbers = new Set();
|
||||||
let childTokenTypes = "";
|
for (const codeBlock of filterByTypes(tokens, [ "codeFenced", "codeIndented" ])) {
|
||||||
for (const child of token.children) {
|
addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
|
||||||
if (child.type !== "text" || child.content !== "") {
|
}
|
||||||
childTokenTypes += tokenTypeMap[child.type] || "x";
|
const tableLineNumbers = new Set();
|
||||||
}
|
for (const table of filterByTypes(tokens, [ "table" ])) {
|
||||||
|
addRangeToSet(tableLineNumbers, table.startLine, table.endLine);
|
||||||
|
}
|
||||||
|
const linkLineNumbers = new Set();
|
||||||
|
for (const link of filterByTypes(tokens, [ "autolink", "image", "link", "literalAutolink" ])) {
|
||||||
|
addRangeToSet(linkLineNumbers, link.startLine, link.endLine);
|
||||||
|
}
|
||||||
|
const paragraphDataLineNumbers = new Set();
|
||||||
|
for (const paragraph of filterByTypes(tokens, [ "paragraph" ])) {
|
||||||
|
for (const data of getDescendantsByType(paragraph, [ "data" ])) {
|
||||||
|
addRangeToSet(paragraphDataLineNumbers, data.startLine, data.endLine);
|
||||||
}
|
}
|
||||||
if (linkOrImageOnlyLineRe.test(childTokenTypes)) {
|
}
|
||||||
linkOnlyLineNumbers.push(token.lineNumber);
|
const linkOnlyLineNumbers = new Set();
|
||||||
|
for (const lineNumber of linkLineNumbers) {
|
||||||
|
if (!paragraphDataLineNumbers.has(lineNumber)) {
|
||||||
|
linkOnlyLineNumbers.add(lineNumber);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
const { definitionLineIndices } = referenceLinkImageData();
|
const definitionLineIndices = new Set(referenceLinkImageData().definitionLineIndices);
|
||||||
forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence, inTable) => {
|
for (let lineIndex = 0; lineIndex < params.lines.length; lineIndex++) {
|
||||||
|
const line = params.lines[lineIndex];
|
||||||
const lineNumber = lineIndex + 1;
|
const lineNumber = lineIndex + 1;
|
||||||
const isHeading = includesSorted(headingLineNumbers, lineNumber);
|
const isHeading = headingLineNumbers.has(lineNumber);
|
||||||
|
const inCode = codeBlockLineNumbers.has(lineNumber);
|
||||||
|
const inTable = tableLineNumbers.has(lineNumber);
|
||||||
const length = inCode ?
|
const length = inCode ?
|
||||||
codeLineLength :
|
codeLineLength :
|
||||||
(isHeading ? headingLineLength : lineLength);
|
(isHeading ? headingLineLength : lineLength);
|
||||||
|
|
@ -80,10 +85,10 @@ module.exports = {
|
||||||
if ((includeCodeBlocks || !inCode) &&
|
if ((includeCodeBlocks || !inCode) &&
|
||||||
(includeTables || !inTable) &&
|
(includeTables || !inTable) &&
|
||||||
(includeHeadings || !isHeading) &&
|
(includeHeadings || !isHeading) &&
|
||||||
!includesSorted(definitionLineIndices, lineIndex) &&
|
!definitionLineIndices.has(lineIndex) &&
|
||||||
(strict ||
|
(strict ||
|
||||||
(!(stern && sternModeRe.test(line)) &&
|
(!(stern && sternModeRe.test(line)) &&
|
||||||
!includesSorted(linkOnlyLineNumbers, lineNumber))) &&
|
!linkOnlyLineNumbers.has(lineNumber))) &&
|
||||||
lengthRe.test(line)) {
|
lengthRe.test(line)) {
|
||||||
addErrorDetailIf(
|
addErrorDetailIf(
|
||||||
onError,
|
onError,
|
||||||
|
|
@ -92,8 +97,9 @@ module.exports = {
|
||||||
line.length,
|
line.length,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
[ length + 1, line.length - length ]);
|
[ length + 1, line.length - length ]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -72,3 +72,15 @@ Long lines inside HTML comments should also produce a violation of the line-leng
|
||||||
<!-- Long lines inside HTML comments should also produce a violation of the line-length rule. {MD013} -->
|
<!-- Long lines inside HTML comments should also produce a violation of the line-length rule. {MD013} -->
|
||||||
|
|
||||||
Long lines inside HTML comments should also <!-- produce a violation of the line-length rule. {MD013} -->
|
Long lines inside HTML comments should also <!-- produce a violation of the line-length rule. {MD013} -->
|
||||||
|
|
||||||
|
<https://example.com/long-line-comprised-entirely-of-an-autolink-long-line-comprised-entirely-of-an-autolink>
|
||||||
|
|
||||||
|
https://example.com/long-line-comprised-entirely-of-a-bare-link-long-line-comprised-entirely-of-a-bare-link
|
||||||
|
|
||||||
|
Long <https://example.com/line-comprised-mostly-of-an-autolink-long-line-comprised-mostly-of-an-autolink> {MD013}
|
||||||
|
|
||||||
|
Long https://example.com/long-line-comprised-mostly-of-a-bare-link-long-line-comprised-mostly-of-a-bare-link {MD013}
|
||||||
|
|
||||||
|
<!-- markdownlint-configure-file {
|
||||||
|
"no-bare-urls": false
|
||||||
|
} -->
|
||||||
|
|
|
||||||
|
|
@ -214,24 +214,6 @@ test("isBlankLine", (t) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("includesSorted", (t) => {
|
|
||||||
t.plan(154);
|
|
||||||
const inputs = [
|
|
||||||
[ ],
|
|
||||||
[ 8 ],
|
|
||||||
[ 7, 11 ],
|
|
||||||
[ 0, 1, 2, 3, 5, 8, 13 ],
|
|
||||||
[ 2, 3, 5, 7, 11, 13, 17, 19 ],
|
|
||||||
[ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 ],
|
|
||||||
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]
|
|
||||||
];
|
|
||||||
for (const input of inputs) {
|
|
||||||
for (let i = 0; i <= 21; i++) {
|
|
||||||
t.is(helpers.includesSorted(input, i), input.includes(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("forEachInlineCodeSpan", (t) => {
|
test("forEachInlineCodeSpan", (t) => {
|
||||||
t.plan(99);
|
t.plan(99);
|
||||||
const testCases =
|
const testCases =
|
||||||
|
|
|
||||||
|
|
@ -945,7 +945,7 @@ test("readme", async(t) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("validateJsonUsingConfigSchemaStrict", async(t) => {
|
test("validateJsonUsingConfigSchemaStrict", async(t) => {
|
||||||
t.plan(178);
|
t.plan(179);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const ajv = new Ajv(ajvOptions);
|
const ajv = new Ajv(ajvOptions);
|
||||||
const validateSchemaStrict = ajv.compile(configSchemaStrict);
|
const validateSchemaStrict = ajv.compile(configSchemaStrict);
|
||||||
|
|
|
||||||
|
|
@ -37472,6 +37472,38 @@ Generated by [AVA](https://avajs.dev).
|
||||||
'line-length',
|
'line-length',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
errorContext: null,
|
||||||
|
errorDetail: 'Expected: 80; Actual: 113',
|
||||||
|
errorRange: [
|
||||||
|
81,
|
||||||
|
33,
|
||||||
|
],
|
||||||
|
fixInfo: null,
|
||||||
|
lineNumber: 80,
|
||||||
|
ruleDescription: 'Line length',
|
||||||
|
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md013.md',
|
||||||
|
ruleNames: [
|
||||||
|
'MD013',
|
||||||
|
'line-length',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
errorContext: null,
|
||||||
|
errorDetail: 'Expected: 80; Actual: 116',
|
||||||
|
errorRange: [
|
||||||
|
81,
|
||||||
|
36,
|
||||||
|
],
|
||||||
|
fixInfo: null,
|
||||||
|
lineNumber: 82,
|
||||||
|
ruleDescription: 'Line length',
|
||||||
|
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md013.md',
|
||||||
|
ruleNames: [
|
||||||
|
'MD013',
|
||||||
|
'line-length',
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
errorContext: null,
|
errorContext: null,
|
||||||
errorDetail: 'Expected: indented; Actual: fenced',
|
errorDetail: 'Expected: indented; Actual: fenced',
|
||||||
|
|
@ -37736,6 +37768,18 @@ Generated by [AVA](https://avajs.dev).
|
||||||
<!-- Long lines inside HTML comments should also produce a violation of the line-length rule. {MD013} -->␊
|
<!-- Long lines inside HTML comments should also produce a violation of the line-length rule. {MD013} -->␊
|
||||||
␊
|
␊
|
||||||
Long lines inside HTML comments should also <!-- produce a violation of the line-length rule. {MD013} -->␊
|
Long lines inside HTML comments should also <!-- produce a violation of the line-length rule. {MD013} -->␊
|
||||||
|
␊
|
||||||
|
<https://example.com/long-line-comprised-entirely-of-an-autolink-long-line-comprised-entirely-of-an-autolink>␊
|
||||||
|
␊
|
||||||
|
https://example.com/long-line-comprised-entirely-of-a-bare-link-long-line-comprised-entirely-of-a-bare-link␊
|
||||||
|
␊
|
||||||
|
Long <https://example.com/line-comprised-mostly-of-an-autolink-long-line-comprised-mostly-of-an-autolink> {MD013}␊
|
||||||
|
␊
|
||||||
|
Long https://example.com/long-line-comprised-mostly-of-a-bare-link-long-line-comprised-mostly-of-a-bare-link {MD013}␊
|
||||||
|
␊
|
||||||
|
<!-- markdownlint-configure-file {␊
|
||||||
|
"no-bare-urls": false␊
|
||||||
|
} -->␊
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue