Add Rule.parser property for custom rules to specify which Markdown parser output they use, honor it strictly, and add full type support.

This commit is contained in:
David Anson 2024-03-09 16:17:50 -08:00
parent d2acc168d2
commit d5994ae4de
68 changed files with 635 additions and 115 deletions

View file

@ -714,10 +714,10 @@ module.exports.frontMatterHasTitle =
/** /**
* Returns an object with information about reference links and images. * Returns an object with information about reference links and images.
* *
* @param {Object} params RuleParams instance. * @param {import("../helpers/micromark.cjs").Token[]} tokens Micromark tokens.
* @returns {Object} Reference link/image data. * @returns {Object} Reference link/image data.
*/ */
function getReferenceLinkImageData(params) { function getReferenceLinkImageData(tokens) {
const normalizeReference = (s) => s.toLowerCase().trim().replace(/\s+/g, " "); const normalizeReference = (s) => s.toLowerCase().trim().replace(/\s+/g, " ");
const definitions = new Map(); const definitions = new Map();
const definitionLineIndices = []; const definitionLineIndices = [];
@ -726,7 +726,7 @@ function getReferenceLinkImageData(params) {
const shortcuts = new Map(); const shortcuts = new Map();
const filteredTokens = const filteredTokens =
micromark.filterByTypes( micromark.filterByTypes(
params.parsers.micromark.tokens, tokens,
[ [
// definitionLineIndices // definitionLineIndices
"definition", "gfmFootnoteDefinition", "definition", "gfmFootnoteDefinition",
@ -1193,20 +1193,7 @@ const flatTokensSymbol = Symbol("flat-tokens");
/** @typedef {import("markdownlint-micromark").Event} Event */ /** @typedef {import("markdownlint-micromark").Event} Event */
/** @typedef {import("markdownlint-micromark").ParseOptions} ParseOptions */ /** @typedef {import("markdownlint-micromark").ParseOptions} ParseOptions */
/** @typedef {import("markdownlint-micromark").TokenType} TokenType */ /** @typedef {import("markdownlint-micromark").TokenType} TokenType */
/** @typedef {import("../lib/markdownlint.js").MicromarkToken} Token */
/**
* Markdown token.
*
* @typedef {Object} Token
* @property {TokenType} type Token type.
* @property {number} startLine Start line (1-based).
* @property {number} startColumn Start column (1-based).
* @property {number} endLine End line (1-based).
* @property {number} endColumn End column (1-based).
* @property {string} text Token text.
* @property {Token[]} children Child tokens.
* @property {Token | null} parent Parent token.
*/
/** /**
* Returns whether a token is an htmlFlow type containing an HTML comment. * Returns whether a token is an htmlFlow type containing an HTML comment.
@ -1712,17 +1699,16 @@ function validateRuleList(ruleList, synchronous) {
for (const [ index, rule ] of ruleList.entries()) { for (const [ index, rule ] of ruleList.entries()) {
const customIndex = index - rules.length; const customIndex = index - rules.length;
// eslint-disable-next-line no-inner-declarations, jsdoc/require-jsdoc // eslint-disable-next-line no-inner-declarations, jsdoc/require-jsdoc
function newError(property) { function newError(property, value) {
return new Error( return new Error(
"Property '" + property + "' of custom rule at index " + `Property '${property}' of custom rule at index ${customIndex} is incorrect: '${value}'.`);
customIndex + " is incorrect.");
} }
for (const property of [ "names", "tags" ]) { for (const property of [ "names", "tags" ]) {
const value = rule[property]; const value = rule[property];
if (!result && if (!result &&
(!value || !Array.isArray(value) || (value.length === 0) || (!value || !Array.isArray(value) || (value.length === 0) ||
!value.every(helpers.isString) || value.some(helpers.isEmptyString))) { !value.every(helpers.isString) || value.some(helpers.isEmptyString))) {
result = newError(property); result = newError(property, value);
} }
} }
for (const propertyInfo of [ for (const propertyInfo of [
@ -1732,22 +1718,31 @@ function validateRuleList(ruleList, synchronous) {
const property = propertyInfo[0]; const property = propertyInfo[0];
const value = rule[property]; const value = rule[property];
if (!result && (!value || (typeof value !== propertyInfo[1]))) { if (!result && (!value || (typeof value !== propertyInfo[1]))) {
result = newError(property); result = newError(property, value);
} }
} }
if (
!result &&
(rule.parser !== undefined) &&
(rule.parser !== "markdownit") &&
!((customIndex < 0) && (rule.parser === "micromark")) &&
(rule.parser !== "none")
) {
result = newError("parser", rule.parser);
}
if ( if (
!result && !result &&
rule.information && rule.information &&
!helpers.isUrl(rule.information) !helpers.isUrl(rule.information)
) { ) {
result = newError("information"); result = newError("information", rule.information);
} }
if ( if (
!result && !result &&
(rule.asynchronous !== undefined) && (rule.asynchronous !== undefined) &&
(typeof rule.asynchronous !== "boolean") (typeof rule.asynchronous !== "boolean")
) { ) {
result = newError("asynchronous"); result = newError("asynchronous", rule.asynchronous);
} }
if (!result && rule.asynchronous && synchronous) { if (!result && rule.asynchronous && synchronous) {
result = new Error( result = new Error(
@ -2242,18 +2237,26 @@ function lintContent(
const lines = content.split(helpers.newLineRe); const lines = content.split(helpers.newLineRe);
annotateAndFreezeTokens(markdownitTokens, lines); annotateAndFreezeTokens(markdownitTokens, lines);
// Create (frozen) parameters for rules // Create (frozen) parameters for rules
const parsers = Object.freeze({ /** @type {MarkdownParsers} */
// @ts-ignore
const parsersMarkdownIt = Object.freeze({
"markdownit": Object.freeze({ "markdownit": Object.freeze({
"tokens": markdownitTokens "tokens": markdownitTokens
}), })
});
/** @type {MarkdownParsers} */
// @ts-ignore
const parsersMicromark = Object.freeze({
"micromark": Object.freeze({ "micromark": Object.freeze({
"tokens": micromarkTokens "tokens": micromarkTokens
}) })
}); });
/** @type {MarkdownParsers} */
// @ts-ignore
const parsersNone = Object.freeze({});
const paramsBase = { const paramsBase = {
name, name,
parsers, "parsers": parsersMarkdownIt,
"tokens": markdownitTokens,
"lines": Object.freeze(lines), "lines": Object.freeze(lines),
"frontMatterLines": Object.freeze(frontMatterLines) "frontMatterLines": Object.freeze(frontMatterLines)
}; };
@ -2262,9 +2265,9 @@ function lintContent(
const codeBlockAndSpanRanges = const codeBlockAndSpanRanges =
helpers.codeBlockAndSpanRanges(paramsBase, lineMetadata); helpers.codeBlockAndSpanRanges(paramsBase, lineMetadata);
const flattenedLists = const flattenedLists =
helpers.flattenLists(paramsBase.parsers.markdownit.tokens); helpers.flattenLists(markdownitTokens);
const referenceLinkImageData = const referenceLinkImageData =
helpers.getReferenceLinkImageData(paramsBase); helpers.getReferenceLinkImageData(micromarkTokens);
cache.set({ cache.set({
codeBlockAndSpanRanges, codeBlockAndSpanRanges,
flattenedLists, flattenedLists,
@ -2273,12 +2276,27 @@ function lintContent(
}); });
// Function to run for each rule // Function to run for each rule
let results = []; let results = [];
// eslint-disable-next-line jsdoc/require-jsdoc /**
function forRule(rule) { * @param {Rule} rule Rule.
* @returns {Promise<void> | null} Promise.
*/
const forRule = (rule) => {
// Configure rule // Configure rule
const ruleName = rule.names[0].toUpperCase(); const ruleName = rule.names[0].toUpperCase();
const tokens = {};
let parsers = parsersNone;
if (rule.parser === undefined) {
tokens.tokens = markdownitTokens;
parsers = parsersMarkdownIt;
} else if (rule.parser === "markdownit") {
parsers = parsersMarkdownIt;
} else if (rule.parser === "micromark") {
parsers = parsersMicromark;
}
const params = { const params = {
...paramsBase, ...paramsBase,
...tokens,
parsers,
"config": effectiveConfig[ruleName] "config": effectiveConfig[ruleName]
}; };
// eslint-disable-next-line jsdoc/require-jsdoc // eslint-disable-next-line jsdoc/require-jsdoc
@ -2554,6 +2572,7 @@ function lintInput(options, synchronous, callback) {
"description": rule.description, "description": rule.description,
"information": helpers.cloneIfUrl(rule.information), "information": helpers.cloneIfUrl(rule.information),
"tags": helpers.cloneIfArray(rule.tags), "tags": helpers.cloneIfArray(rule.tags),
"parser": rule.parser,
"asynchronous": rule.asynchronous, "asynchronous": rule.asynchronous,
"function": rule.function "function": rule.function
})); }));
@ -2960,22 +2979,27 @@ module.exports = markdownlint;
* @returns {void} * @returns {void}
*/ */
/* eslint-disable jsdoc/valid-types */
/** /**
* Rule parameters. * Rule parameters.
* *
* @typedef {Object} RuleParams * @typedef {Object} RuleParams
* @property {string} name File/string name. * @property {string} name File/string name.
* @property {MarkdownParsers} parsers Markdown parser data. * @property {MarkdownParsers} parsers Markdown parser data.
* @property {string[]} lines File/string lines. * @property {readonly string[]} lines File/string lines.
* @property {string[]} frontMatterLines Front matter lines. * @property {readonly string[]} frontMatterLines Front matter lines.
* @property {RuleConfiguration} config Rule configuration. * @property {RuleConfiguration} config Rule configuration.
*/ */
/* eslint-enable jsdoc/valid-types */
/** /**
* Markdown parser data. * Markdown parser data.
* *
* @typedef {Object} MarkdownParsers * @typedef {Object} MarkdownParsers
* @property {ParserMarkdownIt} markdownit Markdown parser data from markdown-it. * @property {ParserMarkdownIt} markdownit Markdown parser data from markdown-it (only present when Rule.parser is "markdownit").
* @property {ParserMicromark} micromark Markdown parser data from micromark (only present when Rule.parser is "micromark").
*/ */
/** /**
@ -2985,6 +3009,13 @@ module.exports = markdownlint;
* @property {MarkdownItToken[]} tokens Token objects from markdown-it. * @property {MarkdownItToken[]} tokens Token objects from markdown-it.
*/ */
/**
* Markdown parser data from micromark.
*
* @typedef {Object} ParserMicromark
* @property {MicromarkToken[]} tokens Token objects from micromark.
*/
/** /**
* markdown-it token. * markdown-it token.
* *
@ -3006,6 +3037,22 @@ module.exports = markdownlint;
* @property {string} line Line content. * @property {string} line Line content.
*/ */
/** @typedef {import("markdownlint-micromark").TokenType} MicromarkTokenType */
/**
* micromark token.
*
* @typedef {Object} MicromarkToken
* @property {MicromarkTokenType} type Token type.
* @property {number} startLine Start line (1-based).
* @property {number} startColumn Start column (1-based).
* @property {number} endLine End line (1-based).
* @property {number} endColumn End column (1-based).
* @property {string} text Token text.
* @property {MicromarkToken[]} children Child tokens.
* @property {MicromarkToken | null} parent Parent token.
*/
/** /**
* Error-reporting callback. * Error-reporting callback.
* *
@ -3044,6 +3091,7 @@ module.exports = markdownlint;
* @property {string} description Rule description. * @property {string} description Rule description.
* @property {URL} [information] Link to more information. * @property {URL} [information] Link to more information.
* @property {string[]} tags Rule tag(s). * @property {string[]} tags Rule tag(s).
* @property {"markdownit" | "micromark" | "none"} parser Parser used.
* @property {boolean} [asynchronous] True if asynchronous. * @property {boolean} [asynchronous] True if asynchronous.
* @property {RuleFunction} function Rule implementation. * @property {RuleFunction} function Rule implementation.
*/ */
@ -3189,6 +3237,7 @@ module.exports = {
"names": [ "MD001", "heading-increment" ], "names": [ "MD001", "heading-increment" ],
"description": "Heading levels should only increment by one level at a time", "description": "Heading levels should only increment by one level at a time",
"tags": [ "headings" ], "tags": [ "headings" ],
"parser": "markdownit",
"function": function MD001(params, onError) { "function": function MD001(params, onError) {
let prevLevel = 0; let prevLevel = 0;
filterTokens(params, "heading_open", function forToken(token) { filterTokens(params, "heading_open", function forToken(token) {
@ -3225,6 +3274,7 @@ module.exports = {
"names": [ "MD003", "heading-style" ], "names": [ "MD003", "heading-style" ],
"description": "Heading style", "description": "Heading style",
"tags": [ "headings" ], "tags": [ "headings" ],
"parser": "markdownit",
"function": function MD003(params, onError) { "function": function MD003(params, onError) {
let style = String(params.config.style || "consistent"); let style = String(params.config.style || "consistent");
filterTokens(params, "heading_open", function forToken(token) { filterTokens(params, "heading_open", function forToken(token) {
@ -3293,6 +3343,7 @@ module.exports = {
"names": [ "MD004", "ul-style" ], "names": [ "MD004", "ul-style" ],
"description": "Unordered list style", "description": "Unordered list style",
"tags": [ "bullet", "ul" ], "tags": [ "bullet", "ul" ],
"parser": "none",
"function": function MD004(params, onError) { "function": function MD004(params, onError) {
const style = String(params.config.style || "consistent"); const style = String(params.config.style || "consistent");
let expectedStyle = style; let expectedStyle = style;
@ -3369,6 +3420,7 @@ module.exports = {
"names": [ "MD005", "list-indent" ], "names": [ "MD005", "list-indent" ],
"description": "Inconsistent indentation for list items at the same level", "description": "Inconsistent indentation for list items at the same level",
"tags": [ "bullet", "ul", "indentation" ], "tags": [ "bullet", "ul", "indentation" ],
"parser": "micromark",
"function": function MD005(params, onError) { "function": function MD005(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */
@ -3470,6 +3522,7 @@ module.exports = {
"names": [ "MD007", "ul-indent" ], "names": [ "MD007", "ul-indent" ],
"description": "Unordered list indentation", "description": "Unordered list indentation",
"tags": [ "bullet", "ul", "indentation" ], "tags": [ "bullet", "ul", "indentation" ],
"parser": "micromark",
"function": function MD007(params, onError) { "function": function MD007(params, onError) {
const indent = Number(params.config.indent || 2); const indent = Number(params.config.indent || 2);
const startIndented = !!params.config.start_indented; const startIndented = !!params.config.start_indented;
@ -3563,6 +3616,7 @@ module.exports = {
"names": [ "MD009", "no-trailing-spaces" ], "names": [ "MD009", "no-trailing-spaces" ],
"description": "Trailing spaces", "description": "Trailing spaces",
"tags": [ "whitespace" ], "tags": [ "whitespace" ],
"parser": "markdownit",
"function": function MD009(params, onError) { "function": function MD009(params, onError) {
let brSpaces = params.config.br_spaces; let brSpaces = params.config.br_spaces;
brSpaces = Number((brSpaces === undefined) ? 2 : brSpaces); brSpaces = Number((brSpaces === undefined) ? 2 : brSpaces);
@ -3664,6 +3718,7 @@ module.exports = {
"names": [ "MD010", "no-hard-tabs" ], "names": [ "MD010", "no-hard-tabs" ],
"description": "Hard tabs", "description": "Hard tabs",
"tags": [ "whitespace", "hard_tab" ], "tags": [ "whitespace", "hard_tab" ],
"parser": "markdownit",
"function": function MD010(params, onError) { "function": function MD010(params, onError) {
const codeBlocks = params.config.code_blocks; const codeBlocks = params.config.code_blocks;
const includeCode = (codeBlocks === undefined) ? true : !!codeBlocks; const includeCode = (codeBlocks === undefined) ? true : !!codeBlocks;
@ -3737,6 +3792,7 @@ module.exports = {
"names": [ "MD011", "no-reversed-links" ], "names": [ "MD011", "no-reversed-links" ],
"description": "Reversed link syntax", "description": "Reversed link syntax",
"tags": [ "links" ], "tags": [ "links" ],
"parser": "none",
"function": function MD011(params, onError) { "function": function MD011(params, onError) {
const exclusions = codeBlockAndSpanRanges(); const exclusions = codeBlockAndSpanRanges();
forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence) => { forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence) => {
@ -3793,6 +3849,7 @@ module.exports = {
"names": [ "MD012", "no-multiple-blanks" ], "names": [ "MD012", "no-multiple-blanks" ],
"description": "Multiple consecutive blank lines", "description": "Multiple consecutive blank lines",
"tags": [ "whitespace", "blank_lines" ], "tags": [ "whitespace", "blank_lines" ],
"parser": "none",
"function": function MD012(params, onError) { "function": function MD012(params, onError) {
const maximum = Number(params.config.maximum || 1); const maximum = Number(params.config.maximum || 1);
let count = 0; let count = 0;
@ -3855,6 +3912,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",
"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 =
@ -3948,6 +4006,7 @@ module.exports = {
"names": [ "MD014", "commands-show-output" ], "names": [ "MD014", "commands-show-output" ],
"description": "Dollar signs used before commands without showing output", "description": "Dollar signs used before commands without showing output",
"tags": [ "code" ], "tags": [ "code" ],
"parser": "markdownit",
"function": function MD014(params, onError) { "function": function MD014(params, onError) {
for (const type of [ "code_block", "fence" ]) { for (const type of [ "code_block", "fence" ]) {
filterTokens(params, type, (token) => { filterTokens(params, type, (token) => {
@ -4014,6 +4073,7 @@ module.exports = {
"names": [ "MD018", "no-missing-space-atx" ], "names": [ "MD018", "no-missing-space-atx" ],
"description": "No space after hash on atx style heading", "description": "No space after hash on atx style heading",
"tags": [ "headings", "atx", "spaces" ], "tags": [ "headings", "atx", "spaces" ],
"parser": "none",
"function": function MD018(params, onError) { "function": function MD018(params, onError) {
forEachLine(lineMetadata(), (line, lineIndex, inCode) => { forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
if (!inCode && if (!inCode &&
@ -4062,6 +4122,7 @@ module.exports = {
"names": [ "MD019", "no-multiple-space-atx" ], "names": [ "MD019", "no-multiple-space-atx" ],
"description": "Multiple spaces after hash on atx style heading", "description": "Multiple spaces after hash on atx style heading",
"tags": [ "headings", "atx", "spaces" ], "tags": [ "headings", "atx", "spaces" ],
"parser": "markdownit",
"function": function MD019(params, onError) { "function": function MD019(params, onError) {
filterTokens(params, "heading_open", (token) => { filterTokens(params, "heading_open", (token) => {
if (headingStyleFor(token) === "atx") { if (headingStyleFor(token) === "atx") {
@ -4114,6 +4175,7 @@ module.exports = {
"names": [ "MD020", "no-missing-space-closed-atx" ], "names": [ "MD020", "no-missing-space-closed-atx" ],
"description": "No space inside hashes on closed atx style heading", "description": "No space inside hashes on closed atx style heading",
"tags": [ "headings", "atx_closed", "spaces" ], "tags": [ "headings", "atx_closed", "spaces" ],
"parser": "none",
"function": function MD020(params, onError) { "function": function MD020(params, onError) {
forEachLine(lineMetadata(), (line, lineIndex, inCode) => { forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
if (!inCode) { if (!inCode) {
@ -4191,6 +4253,7 @@ module.exports = {
"names": [ "MD021", "no-multiple-space-closed-atx" ], "names": [ "MD021", "no-multiple-space-closed-atx" ],
"description": "Multiple spaces inside hashes on closed atx style heading", "description": "Multiple spaces inside hashes on closed atx style heading",
"tags": [ "headings", "atx_closed", "spaces" ], "tags": [ "headings", "atx_closed", "spaces" ],
"parser": "markdownit",
"function": function MD021(params, onError) { "function": function MD021(params, onError) {
filterTokens(params, "heading_open", (token) => { filterTokens(params, "heading_open", (token) => {
if (headingStyleFor(token) === "atx_closed") { if (headingStyleFor(token) === "atx_closed") {
@ -4290,6 +4353,7 @@ module.exports = {
"names": [ "MD022", "blanks-around-headings" ], "names": [ "MD022", "blanks-around-headings" ],
"description": "Headings should be surrounded by blank lines", "description": "Headings should be surrounded by blank lines",
"tags": [ "headings", "blank_lines" ], "tags": [ "headings", "blank_lines" ],
"parser": "micromark",
"function": function MD022(params, onError) { "function": function MD022(params, onError) {
const getLinesAbove = getLinesFunction(params.config.lines_above); const getLinesAbove = getLinesFunction(params.config.lines_above);
const getLinesBelow = getLinesFunction(params.config.lines_below); const getLinesBelow = getLinesFunction(params.config.lines_below);
@ -4391,6 +4455,7 @@ module.exports = {
"names": [ "MD023", "heading-start-left" ], "names": [ "MD023", "heading-start-left" ],
"description": "Headings must start at the beginning of the line", "description": "Headings must start at the beginning of the line",
"tags": [ "headings", "spaces" ], "tags": [ "headings", "spaces" ],
"parser": "markdownit",
"function": function MD023(params, onError) { "function": function MD023(params, onError) {
filterTokens(params, "heading_open", function forToken(token) { filterTokens(params, "heading_open", function forToken(token) {
const { lineNumber, line } = token; const { lineNumber, line } = token;
@ -4440,6 +4505,7 @@ module.exports = {
"names": [ "MD024", "no-duplicate-heading" ], "names": [ "MD024", "no-duplicate-heading" ],
"description": "Multiple headings with the same content", "description": "Multiple headings with the same content",
"tags": [ "headings" ], "tags": [ "headings" ],
"parser": "markdownit",
"function": function MD024(params, onError) { "function": function MD024(params, onError) {
const siblingsOnly = !!params.config.siblings_only || false; const siblingsOnly = !!params.config.siblings_only || false;
const knownContents = [ null, [] ]; const knownContents = [ null, [] ];
@ -4496,6 +4562,7 @@ module.exports = {
"names": [ "MD025", "single-title", "single-h1" ], "names": [ "MD025", "single-title", "single-h1" ],
"description": "Multiple top-level headings in the same document", "description": "Multiple top-level headings in the same document",
"tags": [ "headings" ], "tags": [ "headings" ],
"parser": "markdownit",
"function": function MD025(params, onError) { "function": function MD025(params, onError) {
const level = Number(params.config.level || 1); const level = Number(params.config.level || 1);
const tag = "h" + level; const tag = "h" + level;
@ -4542,6 +4609,7 @@ module.exports = {
"names": [ "MD026", "no-trailing-punctuation" ], "names": [ "MD026", "no-trailing-punctuation" ],
"description": "Trailing punctuation in heading", "description": "Trailing punctuation in heading",
"tags": [ "headings" ], "tags": [ "headings" ],
"parser": "micromark",
"function": function MD026(params, onError) { "function": function MD026(params, onError) {
let punctuation = params.config.punctuation; let punctuation = params.config.punctuation;
punctuation = String( punctuation = String(
@ -4605,6 +4673,7 @@ module.exports = {
"names": ["MD027", "no-multiple-space-blockquote"], "names": ["MD027", "no-multiple-space-blockquote"],
"description": "Multiple spaces after blockquote symbol", "description": "Multiple spaces after blockquote symbol",
"tags": ["blockquote", "whitespace", "indentation"], "tags": ["blockquote", "whitespace", "indentation"],
"parser": "micromark",
"function": function MD027(params, onError) { "function": function MD027(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */
@ -4659,6 +4728,7 @@ module.exports = {
"names": [ "MD028", "no-blanks-blockquote" ], "names": [ "MD028", "no-blanks-blockquote" ],
"description": "Blank line inside blockquote", "description": "Blank line inside blockquote",
"tags": [ "blockquote", "whitespace" ], "tags": [ "blockquote", "whitespace" ],
"parser": "micromark",
"function": function MD028(params, onError) { "function": function MD028(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */
@ -4721,6 +4791,7 @@ module.exports = {
"names": [ "MD029", "ol-prefix" ], "names": [ "MD029", "ol-prefix" ],
"description": "Ordered list item prefix", "description": "Ordered list item prefix",
"tags": [ "ol" ], "tags": [ "ol" ],
"parser": "none",
"function": function MD029(params, onError) { "function": function MD029(params, onError) {
const style = String(params.config.style || "one_or_ordered"); const style = String(params.config.style || "one_or_ordered");
const filteredLists = flattenedLists().filter((list) => !list.unordered); const filteredLists = flattenedLists().filter((list) => !list.unordered);
@ -4794,6 +4865,7 @@ module.exports = {
"names": [ "MD030", "list-marker-space" ], "names": [ "MD030", "list-marker-space" ],
"description": "Spaces after list markers", "description": "Spaces after list markers",
"tags": [ "ol", "ul", "whitespace" ], "tags": [ "ol", "ul", "whitespace" ],
"parser": "micromark",
"function": function MD030(params, onError) { "function": function MD030(params, onError) {
const ulSingle = Number(params.config.ul_single || 1); const ulSingle = Number(params.config.ul_single || 1);
const olSingle = Number(params.config.ol_single || 1); const olSingle = Number(params.config.ol_single || 1);
@ -4872,6 +4944,7 @@ module.exports = {
"names": [ "MD031", "blanks-around-fences" ], "names": [ "MD031", "blanks-around-fences" ],
"description": "Fenced code blocks should be surrounded by blank lines", "description": "Fenced code blocks should be surrounded by blank lines",
"tags": [ "code", "blank_lines" ], "tags": [ "code", "blank_lines" ],
"parser": "none",
"function": function MD031(params, onError) { "function": function MD031(params, onError) {
const listItems = params.config.list_items; const listItems = params.config.list_items;
const includeListItems = (listItems === undefined) ? true : !!listItems; const includeListItems = (listItems === undefined) ? true : !!listItems;
@ -4953,6 +5026,7 @@ module.exports = {
"names": [ "MD032", "blanks-around-lists" ], "names": [ "MD032", "blanks-around-lists" ],
"description": "Lists should be surrounded by blank lines", "description": "Lists should be surrounded by blank lines",
"tags": [ "bullet", "ul", "ol", "blank_lines" ], "tags": [ "bullet", "ul", "ol", "blank_lines" ],
"parser": "micromark",
"function": function MD032(params, onError) { "function": function MD032(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */
@ -5020,6 +5094,7 @@ module.exports = {
"names": [ "MD033", "no-inline-html" ], "names": [ "MD033", "no-inline-html" ],
"description": "Inline HTML", "description": "Inline HTML",
"tags": [ "html" ], "tags": [ "html" ],
"parser": "micromark",
"function": function MD033(params, onError) { "function": function MD033(params, onError) {
let allowedElements = params.config.allowed_elements; let allowedElements = params.config.allowed_elements;
allowedElements = Array.isArray(allowedElements) ? allowedElements : []; allowedElements = Array.isArray(allowedElements) ? allowedElements : [];
@ -5076,6 +5151,7 @@ module.exports = {
"names": [ "MD034", "no-bare-urls" ], "names": [ "MD034", "no-bare-urls" ],
"description": "Bare URL used", "description": "Bare URL used",
"tags": [ "links", "url" ], "tags": [ "links", "url" ],
"parser": "micromark",
"function": function MD034(params, onError) { "function": function MD034(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */
@ -5190,6 +5266,7 @@ module.exports = {
"names": [ "MD035", "hr-style" ], "names": [ "MD035", "hr-style" ],
"description": "Horizontal rule style", "description": "Horizontal rule style",
"tags": [ "hr" ], "tags": [ "hr" ],
"parser": "micromark",
"function": function MD035(params, onError) { "function": function MD035(params, onError) {
let style = String(params.config.style || "consistent").trim(); let style = String(params.config.style || "consistent").trim();
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
@ -5230,6 +5307,7 @@ module.exports = {
"names": [ "MD036", "no-emphasis-as-heading" ], "names": [ "MD036", "no-emphasis-as-heading" ],
"description": "Emphasis used instead of a heading", "description": "Emphasis used instead of a heading",
"tags": [ "headings", "emphasis" ], "tags": [ "headings", "emphasis" ],
"parser": "markdownit",
"function": function MD036(params, onError) { "function": function MD036(params, onError) {
let punctuation = params.config.punctuation; let punctuation = params.config.punctuation;
punctuation = punctuation =
@ -5300,6 +5378,7 @@ module.exports = {
"names": [ "MD037", "no-space-in-emphasis" ], "names": [ "MD037", "no-space-in-emphasis" ],
"description": "Spaces inside emphasis markers", "description": "Spaces inside emphasis markers",
"tags": [ "whitespace", "emphasis" ], "tags": [ "whitespace", "emphasis" ],
"parser": "micromark",
"function": function MD037(params, onError) { "function": function MD037(params, onError) {
// Initialize variables // Initialize variables
@ -5423,6 +5502,7 @@ module.exports = {
"names": [ "MD038", "no-space-in-code" ], "names": [ "MD038", "no-space-in-code" ],
"description": "Spaces inside code span elements", "description": "Spaces inside code span elements",
"tags": [ "whitespace", "code" ], "tags": [ "whitespace", "code" ],
"parser": "micromark",
"function": function MD038(params, onError) { "function": function MD038(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */
@ -5527,6 +5607,7 @@ module.exports = {
"names": [ "MD039", "no-space-in-links" ], "names": [ "MD039", "no-space-in-links" ],
"description": "Spaces inside link text", "description": "Spaces inside link text",
"tags": [ "whitespace", "links" ], "tags": [ "whitespace", "links" ],
"parser": "markdownit",
"function": function MD039(params, onError) { "function": function MD039(params, onError) {
filterTokens(params, "inline", (token) => { filterTokens(params, "inline", (token) => {
const { children } = token; const { children } = token;
@ -5607,6 +5688,7 @@ module.exports = {
"names": [ "MD040", "fenced-code-language" ], "names": [ "MD040", "fenced-code-language" ],
"description": "Fenced code blocks should have a language specified", "description": "Fenced code blocks should have a language specified",
"tags": [ "code", "language" ], "tags": [ "code", "language" ],
"parser": "micromark",
"function": function MD040(params, onError) { "function": function MD040(params, onError) {
let allowed = params.config.allowed_languages; let allowed = params.config.allowed_languages;
allowed = Array.isArray(allowed) ? allowed : []; allowed = Array.isArray(allowed) ? allowed : [];
@ -5657,6 +5739,7 @@ module.exports = {
"names": [ "MD041", "first-line-heading", "first-line-h1" ], "names": [ "MD041", "first-line-heading", "first-line-h1" ],
"description": "First line in a file should be a top-level heading", "description": "First line in a file should be a top-level heading",
"tags": [ "headings" ], "tags": [ "headings" ],
"parser": "markdownit",
"function": function MD041(params, onError) { "function": function MD041(params, onError) {
const level = Number(params.config.level || 1); const level = Number(params.config.level || 1);
const tag = "h" + level; const tag = "h" + level;
@ -5713,6 +5796,7 @@ module.exports = {
"names": [ "MD042", "no-empty-links" ], "names": [ "MD042", "no-empty-links" ],
"description": "No empty links", "description": "No empty links",
"tags": [ "links" ], "tags": [ "links" ],
"parser": "markdownit",
"function": function MD042(params, onError) { "function": function MD042(params, onError) {
filterTokens(params, "inline", function forToken(token) { filterTokens(params, "inline", function forToken(token) {
let inLink = false; let inLink = false;
@ -5776,6 +5860,7 @@ module.exports = {
"names": [ "MD043", "required-headings" ], "names": [ "MD043", "required-headings" ],
"description": "Required heading structure", "description": "Required heading structure",
"tags": [ "headings" ], "tags": [ "headings" ],
"parser": "markdownit",
"function": function MD043(params, onError) { "function": function MD043(params, onError) {
const requiredHeadings = params.config.headings; const requiredHeadings = params.config.headings;
if (!Array.isArray(requiredHeadings)) { if (!Array.isArray(requiredHeadings)) {
@ -5859,6 +5944,7 @@ module.exports = {
"names": [ "MD044", "proper-names" ], "names": [ "MD044", "proper-names" ],
"description": "Proper names should have the correct capitalization", "description": "Proper names should have the correct capitalization",
"tags": [ "spelling" ], "tags": [ "spelling" ],
"parser": "micromark",
"function": function MD044(params, onError) { "function": function MD044(params, onError) {
let names = params.config.names; let names = params.config.names;
names = Array.isArray(names) ? names : []; names = Array.isArray(names) ? names : [];
@ -5980,6 +6066,7 @@ module.exports = {
"names": [ "MD045", "no-alt-text" ], "names": [ "MD045", "no-alt-text" ],
"description": "Images should have alternate text (alt text)", "description": "Images should have alternate text (alt text)",
"tags": [ "accessibility", "images" ], "tags": [ "accessibility", "images" ],
"parser": "micromark",
"function": function MD045(params, onError) { "function": function MD045(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */
@ -6060,6 +6147,7 @@ module.exports = {
"names": [ "MD046", "code-block-style" ], "names": [ "MD046", "code-block-style" ],
"description": "Code block style", "description": "Code block style",
"tags": [ "code" ], "tags": [ "code" ],
"parser": "micromark",
"function": function MD046(params, onError) { "function": function MD046(params, onError) {
let expectedStyle = String(params.config.style || "consistent"); let expectedStyle = String(params.config.style || "consistent");
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
@ -6104,6 +6192,7 @@ module.exports = {
"names": [ "MD047", "single-trailing-newline" ], "names": [ "MD047", "single-trailing-newline" ],
"description": "Files should end with a single newline character", "description": "Files should end with a single newline character",
"tags": [ "blank_lines" ], "tags": [ "blank_lines" ],
"parser": "none",
"function": function MD047(params, onError) { "function": function MD047(params, onError) {
const lastLineNumber = params.lines.length; const lastLineNumber = params.lines.length;
const lastLine = params.lines[lastLineNumber - 1]; const lastLine = params.lines[lastLineNumber - 1];
@ -6146,6 +6235,7 @@ module.exports = {
"names": [ "MD048", "code-fence-style" ], "names": [ "MD048", "code-fence-style" ],
"description": "Code fence style", "description": "Code fence style",
"tags": [ "code" ], "tags": [ "code" ],
"parser": "micromark",
"function": function MD048(params, onError) { "function": function MD048(params, onError) {
const style = String(params.config.style || "consistent"); const style = String(params.config.style || "consistent");
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
@ -6263,6 +6353,7 @@ module.exports = [
"names": [ "MD049", "emphasis-style" ], "names": [ "MD049", "emphasis-style" ],
"description": "Emphasis style", "description": "Emphasis style",
"tags": [ "emphasis" ], "tags": [ "emphasis" ],
"parser": "micromark",
"function": function MD049(params, onError) { "function": function MD049(params, onError) {
return impl( return impl(
params, params,
@ -6279,6 +6370,7 @@ module.exports = [
"names": [ "MD050", "strong-style" ], "names": [ "MD050", "strong-style" ],
"description": "Strong style", "description": "Strong style",
"tags": [ "emphasis" ], "tags": [ "emphasis" ],
"parser": "micromark",
"function": function MD050(params, onError) { "function": function MD050(params, onError) {
return impl( return impl(
params, params,
@ -6372,6 +6464,7 @@ module.exports = {
"names": [ "MD051", "link-fragments" ], "names": [ "MD051", "link-fragments" ],
"description": "Link fragments should be valid", "description": "Link fragments should be valid",
"tags": [ "links" ], "tags": [ "links" ],
"parser": "micromark",
"function": function MD051(params, onError) { "function": function MD051(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */
@ -6503,6 +6596,7 @@ module.exports = {
"description": "description":
"Reference links and images should use a label that is defined", "Reference links and images should use a label that is defined",
"tags": [ "images", "links" ], "tags": [ "images", "links" ],
"parser": "none",
"function": function MD052(params, onError) { "function": function MD052(params, onError) {
const { config, lines } = params; const { config, lines } = params;
const shortcutSyntax = config.shortcut_syntax || false; const shortcutSyntax = config.shortcut_syntax || false;
@ -6555,6 +6649,7 @@ module.exports = {
"names": [ "MD053", "link-image-reference-definitions" ], "names": [ "MD053", "link-image-reference-definitions" ],
"description": "Link and image reference definitions should be needed", "description": "Link and image reference definitions should be needed",
"tags": [ "images", "links" ], "tags": [ "images", "links" ],
"parser": "none",
"function": function MD053(params, onError) { "function": function MD053(params, onError) {
const ignored = new Set(params.config.ignored_definitions || [ "//" ]); const ignored = new Set(params.config.ignored_definitions || [ "//" ]);
const lines = params.lines; const lines = params.lines;
@ -6642,6 +6737,7 @@ module.exports = {
"names": [ "MD054", "link-image-style" ], "names": [ "MD054", "link-image-style" ],
"description": "Link and image style", "description": "Link and image style",
"tags": [ "images", "links" ], "tags": [ "images", "links" ],
"parser": "micromark",
"function": (params, onError) => { "function": (params, onError) => {
const config = params.config; const config = params.config;
const autolink = (config.autolink === undefined) || !!config.autolink; const autolink = (config.autolink === undefined) || !!config.autolink;
@ -6774,6 +6870,7 @@ module.exports = {
"names": [ "MD055", "table-pipe-style" ], "names": [ "MD055", "table-pipe-style" ],
"description": "Table pipe style", "description": "Table pipe style",
"tags": [ "table" ], "tags": [ "table" ],
"parser": "micromark",
"function": function MD055(params, onError) { "function": function MD055(params, onError) {
const style = String(params.config.style || "consistent"); const style = String(params.config.style || "consistent");
let expectedStyle = style; let expectedStyle = style;
@ -6858,6 +6955,7 @@ module.exports = {
"names": [ "MD056", "table-column-count" ], "names": [ "MD056", "table-column-count" ],
"description": "Table column count", "description": "Table column count",
"tags": [ "table" ], "tags": [ "table" ],
"parser": "micromark",
"function": function MD056(params, onError) { "function": function MD056(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */

View file

@ -34,6 +34,7 @@ module.exports = {
"description": "Rule that reports an error for any blockquote", "description": "Rule that reports an error for any blockquote",
"information": new URL("https://example.com/rules/any-blockquote"), "information": new URL("https://example.com/rules/any-blockquote"),
"tags": [ "test" ], "tags": [ "test" ],
"parser": "markdownit",
"function": function rule(params, onError) { "function": function rule(params, onError) {
params.parsers.markdownit.tokens.filter(function filterToken(token) { params.parsers.markdownit.tokens.filter(function filterToken(token) {
return token.type === "blockquote_open"; return token.type === "blockquote_open";
@ -49,8 +50,7 @@ module.exports = {
}; };
``` ```
A rule is implemented as an `Object` with one optional and four required A rule is implemented as an `Object`:
properties:
- `names` is a required `Array` of `String` values that identify the rule in - `names` is a required `Array` of `String` values that identify the rule in
output messages and config. output messages and config.
@ -60,6 +60,9 @@ properties:
about the rule. about the rule.
- `tags` is a required `Array` of `String` values that groups related rules for - `tags` is a required `Array` of `String` values that groups related rules for
easier customization. easier customization.
- `parser` is a required `String` value `"markdownit" | "none"` that specifies
the parser data used via `params.parsers` (see below).
- Note: The value `"micromark"` is valid but is NOT currently supported.
- `asynchronous` is an optional `Boolean` value that indicates whether the rule - `asynchronous` is an optional `Boolean` value that indicates whether the rule
returns a `Promise` and runs asynchronously. returns a `Promise` and runs asynchronously.
- `function` is a required `Function` that implements the rule and is passed two - `function` is a required `Function` that implements the rule and is passed two
@ -67,8 +70,13 @@ properties:
- `params` is an `Object` with properties that describe the content being - `params` is an `Object` with properties that describe the content being
analyzed: analyzed:
- `name` is a `String` that identifies the input file/string. - `name` is a `String` that identifies the input file/string.
- `tokens` is an `Array` of [`markdown-it` `Token`s][markdown-it-token] with - `parsers` is an `Object` with properties corresponding to the value of
added `line` and `lineNumber` properties. `parser` in the rule definition (see above).
- `markdownit` is an `Object` that provides access to output from the
[`markdown-it`][markdown-it] parser.
- `tokens` is an `Array` of [`markdown-it` `Token`s][markdown-it-token]
with added `line` and `lineNumber` properties. (This property was
previously on the `params` object.)
- `lines` is an `Array` of `String` values corresponding to the lines of the - `lines` is an `Array` of `String` values corresponding to the lines of the
input file/string. input file/string.
- `frontMatterLines` is an `Array` of `String` values corresponding to any - `frontMatterLines` is an `Array` of `String` values corresponding to any
@ -145,7 +153,7 @@ Yields the `params` object:
```json ```json
{ {
"name": "doc/example.md", "name": "doc/example.md",
"tokens": [ "parsers.markdownit.tokens": [
{ {
"type": "heading_open", "type": "heading_open",
"tag": "h1", "tag": "h1",

View file

@ -114,6 +114,7 @@ const testRule: markdownlint.Rule = {
"description": "Test rule", "description": "Test rule",
"information": new URL("https://example.com/rule-information"), "information": new URL("https://example.com/rule-information"),
"tags": [ "test-tag" ], "tags": [ "test-tag" ],
"parser": "none",
"function": function rule(params: markdownlint.RuleParams, onError: markdownlint.RuleOnError) { "function": function rule(params: markdownlint.RuleParams, onError: markdownlint.RuleOnError) {
assert(!!params); assert(!!params);
assert(!!onError); assert(!!onError);
@ -123,6 +124,9 @@ const testRule: markdownlint.Rule = {
"parsers": { "parsers": {
"markdownit": { "markdownit": {
"tokens": [] "tokens": []
},
"micromark": {
"tokens": []
} }
}, },
"lines": [ "lines": [

View file

@ -29,6 +29,7 @@ module.exports = {
"names": [ "every-n-lines" ], "names": [ "every-n-lines" ],
"description": "Rule that reports an error every N lines", "description": "Rule that reports an error every N lines",
"tags": [ "test" ], "tags": [ "test" ],
"parser": "none",
"function": (params, onError) => { "function": (params, onError) => {
const n = params.config.n || 2; const n = params.config.n || 2;
forEachLine(getLineMetadata(params), (line, lineIndex) => { forEachLine(getLineMetadata(params), (line, lineIndex) => {

View file

@ -702,10 +702,10 @@ module.exports.frontMatterHasTitle =
/** /**
* Returns an object with information about reference links and images. * Returns an object with information about reference links and images.
* *
* @param {Object} params RuleParams instance. * @param {import("../helpers/micromark.cjs").Token[]} tokens Micromark tokens.
* @returns {Object} Reference link/image data. * @returns {Object} Reference link/image data.
*/ */
function getReferenceLinkImageData(params) { function getReferenceLinkImageData(tokens) {
const normalizeReference = (s) => s.toLowerCase().trim().replace(/\s+/g, " "); const normalizeReference = (s) => s.toLowerCase().trim().replace(/\s+/g, " ");
const definitions = new Map(); const definitions = new Map();
const definitionLineIndices = []; const definitionLineIndices = [];
@ -714,7 +714,7 @@ function getReferenceLinkImageData(params) {
const shortcuts = new Map(); const shortcuts = new Map();
const filteredTokens = const filteredTokens =
micromark.filterByTypes( micromark.filterByTypes(
params.parsers.micromark.tokens, tokens,
[ [
// definitionLineIndices // definitionLineIndices
"definition", "gfmFootnoteDefinition", "definition", "gfmFootnoteDefinition",

View file

@ -15,20 +15,7 @@ const flatTokensSymbol = Symbol("flat-tokens");
/** @typedef {import("markdownlint-micromark").Event} Event */ /** @typedef {import("markdownlint-micromark").Event} Event */
/** @typedef {import("markdownlint-micromark").ParseOptions} ParseOptions */ /** @typedef {import("markdownlint-micromark").ParseOptions} ParseOptions */
/** @typedef {import("markdownlint-micromark").TokenType} TokenType */ /** @typedef {import("markdownlint-micromark").TokenType} TokenType */
/** @typedef {import("../lib/markdownlint.js").MicromarkToken} Token */
/**
* Markdown token.
*
* @typedef {Object} Token
* @property {TokenType} type Token type.
* @property {number} startLine Start line (1-based).
* @property {number} startColumn Start column (1-based).
* @property {number} endLine End line (1-based).
* @property {number} endColumn End column (1-based).
* @property {string} text Token text.
* @property {Token[]} children Child tokens.
* @property {Token | null} parent Parent token.
*/
/** /**
* Returns whether a token is an htmlFlow type containing an HTML comment. * Returns whether a token is an htmlFlow type containing an HTML comment.

63
lib/markdownlint.d.ts vendored
View file

@ -8,7 +8,7 @@ export = markdownlint;
*/ */
declare function markdownlint(options: Options | null, callback: LintCallback): void; declare function markdownlint(options: Options | null, callback: LintCallback): void;
declare namespace markdownlint { declare namespace markdownlint {
export { markdownlintSync as sync, readConfig, readConfigSync, getVersion, promises, RuleFunction, RuleParams, MarkdownParsers, ParserMarkdownIt, MarkdownItToken, RuleOnError, RuleOnErrorInfo, RuleOnErrorFixInfo, Rule, Options, Plugin, ToStringCallback, LintResults, LintError, FixInfo, LintContentCallback, LintCallback, Configuration, RuleConfiguration, ConfigurationParser, ReadConfigCallback, ResolveConfigExtendsCallback }; export { markdownlintSync as sync, readConfig, readConfigSync, getVersion, promises, RuleFunction, RuleParams, MarkdownParsers, ParserMarkdownIt, ParserMicromark, MarkdownItToken, MicromarkTokenType, MicromarkToken, RuleOnError, RuleOnErrorInfo, RuleOnErrorFixInfo, Rule, Options, Plugin, ToStringCallback, LintResults, LintError, FixInfo, LintContentCallback, LintCallback, Configuration, RuleConfiguration, ConfigurationParser, ReadConfigCallback, ResolveConfigExtendsCallback };
} }
/** /**
* Configuration options. * Configuration options.
@ -123,11 +123,11 @@ type RuleParams = {
/** /**
* File/string lines. * File/string lines.
*/ */
lines: string[]; lines: readonly string[];
/** /**
* Front matter lines. * Front matter lines.
*/ */
frontMatterLines: string[]; frontMatterLines: readonly string[];
/** /**
* Rule configuration. * Rule configuration.
*/ */
@ -138,9 +138,13 @@ type RuleParams = {
*/ */
type MarkdownParsers = { type MarkdownParsers = {
/** /**
* Markdown parser data from markdown-it. * Markdown parser data from markdown-it (only present when Rule.parser is "markdownit").
*/ */
markdownit: ParserMarkdownIt; markdownit: ParserMarkdownIt;
/**
* Markdown parser data from micromark (only present when Rule.parser is "micromark").
*/
micromark: ParserMicromark;
}; };
/** /**
* Markdown parser data from markdown-it. * Markdown parser data from markdown-it.
@ -151,6 +155,15 @@ type ParserMarkdownIt = {
*/ */
tokens: MarkdownItToken[]; tokens: MarkdownItToken[];
}; };
/**
* Markdown parser data from micromark.
*/
type ParserMicromark = {
/**
* Token objects from micromark.
*/
tokens: MicromarkToken[];
};
/** /**
* markdown-it token. * markdown-it token.
*/ */
@ -216,6 +229,44 @@ type MarkdownItToken = {
*/ */
line: string; line: string;
}; };
type MicromarkTokenType = import("markdownlint-micromark").TokenType;
/**
* micromark token.
*/
type MicromarkToken = {
/**
* Token type.
*/
type: MicromarkTokenType;
/**
* Start line (1-based).
*/
startLine: number;
/**
* Start column (1-based).
*/
startColumn: number;
/**
* End line (1-based).
*/
endLine: number;
/**
* End column (1-based).
*/
endColumn: number;
/**
* Token text.
*/
text: string;
/**
* Child tokens.
*/
children: MicromarkToken[];
/**
* Parent token.
*/
parent: MicromarkToken | null;
};
/** /**
* Error-reporting callback. * Error-reporting callback.
*/ */
@ -290,6 +341,10 @@ type Rule = {
* Rule tag(s). * Rule tag(s).
*/ */
tags: string[]; tags: string[];
/**
* Parser used.
*/
parser: "markdownit" | "micromark" | "none";
/** /**
* True if asynchronous. * True if asynchronous.
*/ */

View file

@ -33,17 +33,16 @@ function validateRuleList(ruleList, synchronous) {
for (const [ index, rule ] of ruleList.entries()) { for (const [ index, rule ] of ruleList.entries()) {
const customIndex = index - rules.length; const customIndex = index - rules.length;
// eslint-disable-next-line no-inner-declarations, jsdoc/require-jsdoc // eslint-disable-next-line no-inner-declarations, jsdoc/require-jsdoc
function newError(property) { function newError(property, value) {
return new Error( return new Error(
"Property '" + property + "' of custom rule at index " + `Property '${property}' of custom rule at index ${customIndex} is incorrect: '${value}'.`);
customIndex + " is incorrect.");
} }
for (const property of [ "names", "tags" ]) { for (const property of [ "names", "tags" ]) {
const value = rule[property]; const value = rule[property];
if (!result && if (!result &&
(!value || !Array.isArray(value) || (value.length === 0) || (!value || !Array.isArray(value) || (value.length === 0) ||
!value.every(helpers.isString) || value.some(helpers.isEmptyString))) { !value.every(helpers.isString) || value.some(helpers.isEmptyString))) {
result = newError(property); result = newError(property, value);
} }
} }
for (const propertyInfo of [ for (const propertyInfo of [
@ -53,22 +52,31 @@ function validateRuleList(ruleList, synchronous) {
const property = propertyInfo[0]; const property = propertyInfo[0];
const value = rule[property]; const value = rule[property];
if (!result && (!value || (typeof value !== propertyInfo[1]))) { if (!result && (!value || (typeof value !== propertyInfo[1]))) {
result = newError(property); result = newError(property, value);
} }
} }
if (
!result &&
(rule.parser !== undefined) &&
(rule.parser !== "markdownit") &&
!((customIndex < 0) && (rule.parser === "micromark")) &&
(rule.parser !== "none")
) {
result = newError("parser", rule.parser);
}
if ( if (
!result && !result &&
rule.information && rule.information &&
!helpers.isUrl(rule.information) !helpers.isUrl(rule.information)
) { ) {
result = newError("information"); result = newError("information", rule.information);
} }
if ( if (
!result && !result &&
(rule.asynchronous !== undefined) && (rule.asynchronous !== undefined) &&
(typeof rule.asynchronous !== "boolean") (typeof rule.asynchronous !== "boolean")
) { ) {
result = newError("asynchronous"); result = newError("asynchronous", rule.asynchronous);
} }
if (!result && rule.asynchronous && synchronous) { if (!result && rule.asynchronous && synchronous) {
result = new Error( result = new Error(
@ -563,18 +571,26 @@ function lintContent(
const lines = content.split(helpers.newLineRe); const lines = content.split(helpers.newLineRe);
annotateAndFreezeTokens(markdownitTokens, lines); annotateAndFreezeTokens(markdownitTokens, lines);
// Create (frozen) parameters for rules // Create (frozen) parameters for rules
const parsers = Object.freeze({ /** @type {MarkdownParsers} */
// @ts-ignore
const parsersMarkdownIt = Object.freeze({
"markdownit": Object.freeze({ "markdownit": Object.freeze({
"tokens": markdownitTokens "tokens": markdownitTokens
}), })
});
/** @type {MarkdownParsers} */
// @ts-ignore
const parsersMicromark = Object.freeze({
"micromark": Object.freeze({ "micromark": Object.freeze({
"tokens": micromarkTokens "tokens": micromarkTokens
}) })
}); });
/** @type {MarkdownParsers} */
// @ts-ignore
const parsersNone = Object.freeze({});
const paramsBase = { const paramsBase = {
name, name,
parsers, "parsers": parsersMarkdownIt,
"tokens": markdownitTokens,
"lines": Object.freeze(lines), "lines": Object.freeze(lines),
"frontMatterLines": Object.freeze(frontMatterLines) "frontMatterLines": Object.freeze(frontMatterLines)
}; };
@ -583,9 +599,9 @@ function lintContent(
const codeBlockAndSpanRanges = const codeBlockAndSpanRanges =
helpers.codeBlockAndSpanRanges(paramsBase, lineMetadata); helpers.codeBlockAndSpanRanges(paramsBase, lineMetadata);
const flattenedLists = const flattenedLists =
helpers.flattenLists(paramsBase.parsers.markdownit.tokens); helpers.flattenLists(markdownitTokens);
const referenceLinkImageData = const referenceLinkImageData =
helpers.getReferenceLinkImageData(paramsBase); helpers.getReferenceLinkImageData(micromarkTokens);
cache.set({ cache.set({
codeBlockAndSpanRanges, codeBlockAndSpanRanges,
flattenedLists, flattenedLists,
@ -594,12 +610,27 @@ function lintContent(
}); });
// Function to run for each rule // Function to run for each rule
let results = []; let results = [];
// eslint-disable-next-line jsdoc/require-jsdoc /**
function forRule(rule) { * @param {Rule} rule Rule.
* @returns {Promise<void> | null} Promise.
*/
const forRule = (rule) => {
// Configure rule // Configure rule
const ruleName = rule.names[0].toUpperCase(); const ruleName = rule.names[0].toUpperCase();
const tokens = {};
let parsers = parsersNone;
if (rule.parser === undefined) {
tokens.tokens = markdownitTokens;
parsers = parsersMarkdownIt;
} else if (rule.parser === "markdownit") {
parsers = parsersMarkdownIt;
} else if (rule.parser === "micromark") {
parsers = parsersMicromark;
}
const params = { const params = {
...paramsBase, ...paramsBase,
...tokens,
parsers,
"config": effectiveConfig[ruleName] "config": effectiveConfig[ruleName]
}; };
// eslint-disable-next-line jsdoc/require-jsdoc // eslint-disable-next-line jsdoc/require-jsdoc
@ -875,6 +906,7 @@ function lintInput(options, synchronous, callback) {
"description": rule.description, "description": rule.description,
"information": helpers.cloneIfUrl(rule.information), "information": helpers.cloneIfUrl(rule.information),
"tags": helpers.cloneIfArray(rule.tags), "tags": helpers.cloneIfArray(rule.tags),
"parser": rule.parser,
"asynchronous": rule.asynchronous, "asynchronous": rule.asynchronous,
"function": rule.function "function": rule.function
})); }));
@ -1281,22 +1313,27 @@ module.exports = markdownlint;
* @returns {void} * @returns {void}
*/ */
/* eslint-disable jsdoc/valid-types */
/** /**
* Rule parameters. * Rule parameters.
* *
* @typedef {Object} RuleParams * @typedef {Object} RuleParams
* @property {string} name File/string name. * @property {string} name File/string name.
* @property {MarkdownParsers} parsers Markdown parser data. * @property {MarkdownParsers} parsers Markdown parser data.
* @property {string[]} lines File/string lines. * @property {readonly string[]} lines File/string lines.
* @property {string[]} frontMatterLines Front matter lines. * @property {readonly string[]} frontMatterLines Front matter lines.
* @property {RuleConfiguration} config Rule configuration. * @property {RuleConfiguration} config Rule configuration.
*/ */
/* eslint-enable jsdoc/valid-types */
/** /**
* Markdown parser data. * Markdown parser data.
* *
* @typedef {Object} MarkdownParsers * @typedef {Object} MarkdownParsers
* @property {ParserMarkdownIt} markdownit Markdown parser data from markdown-it. * @property {ParserMarkdownIt} markdownit Markdown parser data from markdown-it (only present when Rule.parser is "markdownit").
* @property {ParserMicromark} micromark Markdown parser data from micromark (only present when Rule.parser is "micromark").
*/ */
/** /**
@ -1306,6 +1343,13 @@ module.exports = markdownlint;
* @property {MarkdownItToken[]} tokens Token objects from markdown-it. * @property {MarkdownItToken[]} tokens Token objects from markdown-it.
*/ */
/**
* Markdown parser data from micromark.
*
* @typedef {Object} ParserMicromark
* @property {MicromarkToken[]} tokens Token objects from micromark.
*/
/** /**
* markdown-it token. * markdown-it token.
* *
@ -1327,6 +1371,22 @@ module.exports = markdownlint;
* @property {string} line Line content. * @property {string} line Line content.
*/ */
/** @typedef {import("markdownlint-micromark").TokenType} MicromarkTokenType */
/**
* micromark token.
*
* @typedef {Object} MicromarkToken
* @property {MicromarkTokenType} type Token type.
* @property {number} startLine Start line (1-based).
* @property {number} startColumn Start column (1-based).
* @property {number} endLine End line (1-based).
* @property {number} endColumn End column (1-based).
* @property {string} text Token text.
* @property {MicromarkToken[]} children Child tokens.
* @property {MicromarkToken | null} parent Parent token.
*/
/** /**
* Error-reporting callback. * Error-reporting callback.
* *
@ -1365,6 +1425,7 @@ module.exports = markdownlint;
* @property {string} description Rule description. * @property {string} description Rule description.
* @property {URL} [information] Link to more information. * @property {URL} [information] Link to more information.
* @property {string[]} tags Rule tag(s). * @property {string[]} tags Rule tag(s).
* @property {"markdownit" | "micromark" | "none"} parser Parser used.
* @property {boolean} [asynchronous] True if asynchronous. * @property {boolean} [asynchronous] True if asynchronous.
* @property {RuleFunction} function Rule implementation. * @property {RuleFunction} function Rule implementation.
*/ */

View file

@ -10,6 +10,7 @@ module.exports = {
"names": [ "MD001", "heading-increment" ], "names": [ "MD001", "heading-increment" ],
"description": "Heading levels should only increment by one level at a time", "description": "Heading levels should only increment by one level at a time",
"tags": [ "headings" ], "tags": [ "headings" ],
"parser": "markdownit",
"function": function MD001(params, onError) { "function": function MD001(params, onError) {
let prevLevel = 0; let prevLevel = 0;
filterTokens(params, "heading_open", function forToken(token) { filterTokens(params, "heading_open", function forToken(token) {

View file

@ -11,6 +11,7 @@ module.exports = {
"names": [ "MD003", "heading-style" ], "names": [ "MD003", "heading-style" ],
"description": "Heading style", "description": "Heading style",
"tags": [ "headings" ], "tags": [ "headings" ],
"parser": "markdownit",
"function": function MD003(params, onError) { "function": function MD003(params, onError) {
let style = String(params.config.style || "consistent"); let style = String(params.config.style || "consistent");
filterTokens(params, "heading_open", function forToken(token) { filterTokens(params, "heading_open", function forToken(token) {

View file

@ -24,6 +24,7 @@ module.exports = {
"names": [ "MD004", "ul-style" ], "names": [ "MD004", "ul-style" ],
"description": "Unordered list style", "description": "Unordered list style",
"tags": [ "bullet", "ul" ], "tags": [ "bullet", "ul" ],
"parser": "none",
"function": function MD004(params, onError) { "function": function MD004(params, onError) {
const style = String(params.config.style || "consistent"); const style = String(params.config.style || "consistent");
let expectedStyle = style; let expectedStyle = style;

View file

@ -11,6 +11,7 @@ module.exports = {
"names": [ "MD005", "list-indent" ], "names": [ "MD005", "list-indent" ],
"description": "Inconsistent indentation for list items at the same level", "description": "Inconsistent indentation for list items at the same level",
"tags": [ "bullet", "ul", "indentation" ], "tags": [ "bullet", "ul", "indentation" ],
"parser": "micromark",
"function": function MD005(params, onError) { "function": function MD005(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */

View file

@ -21,6 +21,7 @@ module.exports = {
"names": [ "MD007", "ul-indent" ], "names": [ "MD007", "ul-indent" ],
"description": "Unordered list indentation", "description": "Unordered list indentation",
"tags": [ "bullet", "ul", "indentation" ], "tags": [ "bullet", "ul", "indentation" ],
"parser": "micromark",
"function": function MD007(params, onError) { "function": function MD007(params, onError) {
const indent = Number(params.config.indent || 2); const indent = Number(params.config.indent || 2);
const startIndented = !!params.config.start_indented; const startIndented = !!params.config.start_indented;

View file

@ -12,6 +12,7 @@ module.exports = {
"names": [ "MD009", "no-trailing-spaces" ], "names": [ "MD009", "no-trailing-spaces" ],
"description": "Trailing spaces", "description": "Trailing spaces",
"tags": [ "whitespace" ], "tags": [ "whitespace" ],
"parser": "markdownit",
"function": function MD009(params, onError) { "function": function MD009(params, onError) {
let brSpaces = params.config.br_spaces; let brSpaces = params.config.br_spaces;
brSpaces = Number((brSpaces === undefined) ? 2 : brSpaces); brSpaces = Number((brSpaces === undefined) ? 2 : brSpaces);

View file

@ -14,6 +14,7 @@ module.exports = {
"names": [ "MD010", "no-hard-tabs" ], "names": [ "MD010", "no-hard-tabs" ],
"description": "Hard tabs", "description": "Hard tabs",
"tags": [ "whitespace", "hard_tab" ], "tags": [ "whitespace", "hard_tab" ],
"parser": "markdownit",
"function": function MD010(params, onError) { "function": function MD010(params, onError) {
const codeBlocks = params.config.code_blocks; const codeBlocks = params.config.code_blocks;
const includeCode = (codeBlocks === undefined) ? true : !!codeBlocks; const includeCode = (codeBlocks === undefined) ? true : !!codeBlocks;

View file

@ -14,6 +14,7 @@ module.exports = {
"names": [ "MD011", "no-reversed-links" ], "names": [ "MD011", "no-reversed-links" ],
"description": "Reversed link syntax", "description": "Reversed link syntax",
"tags": [ "links" ], "tags": [ "links" ],
"parser": "none",
"function": function MD011(params, onError) { "function": function MD011(params, onError) {
const exclusions = codeBlockAndSpanRanges(); const exclusions = codeBlockAndSpanRanges();
forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence) => { forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence) => {

View file

@ -11,6 +11,7 @@ module.exports = {
"names": [ "MD012", "no-multiple-blanks" ], "names": [ "MD012", "no-multiple-blanks" ],
"description": "Multiple consecutive blank lines", "description": "Multiple consecutive blank lines",
"tags": [ "whitespace", "blank_lines" ], "tags": [ "whitespace", "blank_lines" ],
"parser": "none",
"function": function MD012(params, onError) { "function": function MD012(params, onError) {
const maximum = Number(params.config.maximum || 1); const maximum = Number(params.config.maximum || 1);
let count = 0; let count = 0;

View file

@ -28,6 +28,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",
"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 =

View file

@ -12,6 +12,7 @@ module.exports = {
"names": [ "MD014", "commands-show-output" ], "names": [ "MD014", "commands-show-output" ],
"description": "Dollar signs used before commands without showing output", "description": "Dollar signs used before commands without showing output",
"tags": [ "code" ], "tags": [ "code" ],
"parser": "markdownit",
"function": function MD014(params, onError) { "function": function MD014(params, onError) {
for (const type of [ "code_block", "fence" ]) { for (const type of [ "code_block", "fence" ]) {
filterTokens(params, type, (token) => { filterTokens(params, type, (token) => {

View file

@ -11,6 +11,7 @@ module.exports = {
"names": [ "MD018", "no-missing-space-atx" ], "names": [ "MD018", "no-missing-space-atx" ],
"description": "No space after hash on atx style heading", "description": "No space after hash on atx style heading",
"tags": [ "headings", "atx", "spaces" ], "tags": [ "headings", "atx", "spaces" ],
"parser": "none",
"function": function MD018(params, onError) { "function": function MD018(params, onError) {
forEachLine(lineMetadata(), (line, lineIndex, inCode) => { forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
if (!inCode && if (!inCode &&

View file

@ -11,6 +11,7 @@ module.exports = {
"names": [ "MD019", "no-multiple-space-atx" ], "names": [ "MD019", "no-multiple-space-atx" ],
"description": "Multiple spaces after hash on atx style heading", "description": "Multiple spaces after hash on atx style heading",
"tags": [ "headings", "atx", "spaces" ], "tags": [ "headings", "atx", "spaces" ],
"parser": "markdownit",
"function": function MD019(params, onError) { "function": function MD019(params, onError) {
filterTokens(params, "heading_open", (token) => { filterTokens(params, "heading_open", (token) => {
if (headingStyleFor(token) === "atx") { if (headingStyleFor(token) === "atx") {

View file

@ -11,6 +11,7 @@ module.exports = {
"names": [ "MD020", "no-missing-space-closed-atx" ], "names": [ "MD020", "no-missing-space-closed-atx" ],
"description": "No space inside hashes on closed atx style heading", "description": "No space inside hashes on closed atx style heading",
"tags": [ "headings", "atx_closed", "spaces" ], "tags": [ "headings", "atx_closed", "spaces" ],
"parser": "none",
"function": function MD020(params, onError) { "function": function MD020(params, onError) {
forEachLine(lineMetadata(), (line, lineIndex, inCode) => { forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
if (!inCode) { if (!inCode) {

View file

@ -13,6 +13,7 @@ module.exports = {
"names": [ "MD021", "no-multiple-space-closed-atx" ], "names": [ "MD021", "no-multiple-space-closed-atx" ],
"description": "Multiple spaces inside hashes on closed atx style heading", "description": "Multiple spaces inside hashes on closed atx style heading",
"tags": [ "headings", "atx_closed", "spaces" ], "tags": [ "headings", "atx_closed", "spaces" ],
"parser": "markdownit",
"function": function MD021(params, onError) { "function": function MD021(params, onError) {
filterTokens(params, "heading_open", (token) => { filterTokens(params, "heading_open", (token) => {
if (headingStyleFor(token) === "atx_closed") { if (headingStyleFor(token) === "atx_closed") {

View file

@ -37,6 +37,7 @@ module.exports = {
"names": [ "MD022", "blanks-around-headings" ], "names": [ "MD022", "blanks-around-headings" ],
"description": "Headings should be surrounded by blank lines", "description": "Headings should be surrounded by blank lines",
"tags": [ "headings", "blank_lines" ], "tags": [ "headings", "blank_lines" ],
"parser": "micromark",
"function": function MD022(params, onError) { "function": function MD022(params, onError) {
const getLinesAbove = getLinesFunction(params.config.lines_above); const getLinesAbove = getLinesFunction(params.config.lines_above);
const getLinesBelow = getLinesFunction(params.config.lines_below); const getLinesBelow = getLinesFunction(params.config.lines_below);

View file

@ -12,6 +12,7 @@ module.exports = {
"names": [ "MD023", "heading-start-left" ], "names": [ "MD023", "heading-start-left" ],
"description": "Headings must start at the beginning of the line", "description": "Headings must start at the beginning of the line",
"tags": [ "headings", "spaces" ], "tags": [ "headings", "spaces" ],
"parser": "markdownit",
"function": function MD023(params, onError) { "function": function MD023(params, onError) {
filterTokens(params, "heading_open", function forToken(token) { filterTokens(params, "heading_open", function forToken(token) {
const { lineNumber, line } = token; const { lineNumber, line } = token;

View file

@ -10,6 +10,7 @@ module.exports = {
"names": [ "MD024", "no-duplicate-heading" ], "names": [ "MD024", "no-duplicate-heading" ],
"description": "Multiple headings with the same content", "description": "Multiple headings with the same content",
"tags": [ "headings" ], "tags": [ "headings" ],
"parser": "markdownit",
"function": function MD024(params, onError) { "function": function MD024(params, onError) {
const siblingsOnly = !!params.config.siblings_only || false; const siblingsOnly = !!params.config.siblings_only || false;
const knownContents = [ null, [] ]; const knownContents = [ null, [] ];

View file

@ -11,6 +11,7 @@ module.exports = {
"names": [ "MD025", "single-title", "single-h1" ], "names": [ "MD025", "single-title", "single-h1" ],
"description": "Multiple top-level headings in the same document", "description": "Multiple top-level headings in the same document",
"tags": [ "headings" ], "tags": [ "headings" ],
"parser": "markdownit",
"function": function MD025(params, onError) { "function": function MD025(params, onError) {
const level = Number(params.config.level || 1); const level = Number(params.config.level || 1);
const tag = "h" + level; const tag = "h" + level;

View file

@ -12,6 +12,7 @@ module.exports = {
"names": [ "MD026", "no-trailing-punctuation" ], "names": [ "MD026", "no-trailing-punctuation" ],
"description": "Trailing punctuation in heading", "description": "Trailing punctuation in heading",
"tags": [ "headings" ], "tags": [ "headings" ],
"parser": "micromark",
"function": function MD026(params, onError) { "function": function MD026(params, onError) {
let punctuation = params.config.punctuation; let punctuation = params.config.punctuation;
punctuation = String( punctuation = String(

View file

@ -11,6 +11,7 @@ module.exports = {
"names": ["MD027", "no-multiple-space-blockquote"], "names": ["MD027", "no-multiple-space-blockquote"],
"description": "Multiple spaces after blockquote symbol", "description": "Multiple spaces after blockquote symbol",
"tags": ["blockquote", "whitespace", "indentation"], "tags": ["blockquote", "whitespace", "indentation"],
"parser": "micromark",
"function": function MD027(params, onError) { "function": function MD027(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */

View file

@ -13,6 +13,7 @@ module.exports = {
"names": [ "MD028", "no-blanks-blockquote" ], "names": [ "MD028", "no-blanks-blockquote" ],
"description": "Blank line inside blockquote", "description": "Blank line inside blockquote",
"tags": [ "blockquote", "whitespace" ], "tags": [ "blockquote", "whitespace" ],
"parser": "micromark",
"function": function MD028(params, onError) { "function": function MD028(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */

View file

@ -18,6 +18,7 @@ module.exports = {
"names": [ "MD029", "ol-prefix" ], "names": [ "MD029", "ol-prefix" ],
"description": "Ordered list item prefix", "description": "Ordered list item prefix",
"tags": [ "ol" ], "tags": [ "ol" ],
"parser": "none",
"function": function MD029(params, onError) { "function": function MD029(params, onError) {
const style = String(params.config.style || "one_or_ordered"); const style = String(params.config.style || "one_or_ordered");
const filteredLists = flattenedLists().filter((list) => !list.unordered); const filteredLists = flattenedLists().filter((list) => !list.unordered);

View file

@ -11,6 +11,7 @@ module.exports = {
"names": [ "MD030", "list-marker-space" ], "names": [ "MD030", "list-marker-space" ],
"description": "Spaces after list markers", "description": "Spaces after list markers",
"tags": [ "ol", "ul", "whitespace" ], "tags": [ "ol", "ul", "whitespace" ],
"parser": "micromark",
"function": function MD030(params, onError) { "function": function MD030(params, onError) {
const ulSingle = Number(params.config.ul_single || 1); const ulSingle = Number(params.config.ul_single || 1);
const olSingle = Number(params.config.ol_single || 1); const olSingle = Number(params.config.ol_single || 1);

View file

@ -13,6 +13,7 @@ module.exports = {
"names": [ "MD031", "blanks-around-fences" ], "names": [ "MD031", "blanks-around-fences" ],
"description": "Fenced code blocks should be surrounded by blank lines", "description": "Fenced code blocks should be surrounded by blank lines",
"tags": [ "code", "blank_lines" ], "tags": [ "code", "blank_lines" ],
"parser": "none",
"function": function MD031(params, onError) { "function": function MD031(params, onError) {
const listItems = params.config.list_items; const listItems = params.config.list_items;
const includeListItems = (listItems === undefined) ? true : !!listItems; const includeListItems = (listItems === undefined) ? true : !!listItems;

View file

@ -41,6 +41,7 @@ module.exports = {
"names": [ "MD032", "blanks-around-lists" ], "names": [ "MD032", "blanks-around-lists" ],
"description": "Lists should be surrounded by blank lines", "description": "Lists should be surrounded by blank lines",
"tags": [ "bullet", "ul", "ol", "blank_lines" ], "tags": [ "bullet", "ul", "ol", "blank_lines" ],
"parser": "micromark",
"function": function MD032(params, onError) { "function": function MD032(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */

View file

@ -12,6 +12,7 @@ module.exports = {
"names": [ "MD033", "no-inline-html" ], "names": [ "MD033", "no-inline-html" ],
"description": "Inline HTML", "description": "Inline HTML",
"tags": [ "html" ], "tags": [ "html" ],
"parser": "micromark",
"function": function MD033(params, onError) { "function": function MD033(params, onError) {
let allowedElements = params.config.allowed_elements; let allowedElements = params.config.allowed_elements;
allowedElements = Array.isArray(allowedElements) ? allowedElements : []; allowedElements = Array.isArray(allowedElements) ? allowedElements : [];

View file

@ -12,6 +12,7 @@ module.exports = {
"names": [ "MD034", "no-bare-urls" ], "names": [ "MD034", "no-bare-urls" ],
"description": "Bare URL used", "description": "Bare URL used",
"tags": [ "links", "url" ], "tags": [ "links", "url" ],
"parser": "micromark",
"function": function MD034(params, onError) { "function": function MD034(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */

View file

@ -11,6 +11,7 @@ module.exports = {
"names": [ "MD035", "hr-style" ], "names": [ "MD035", "hr-style" ],
"description": "Horizontal rule style", "description": "Horizontal rule style",
"tags": [ "hr" ], "tags": [ "hr" ],
"parser": "micromark",
"function": function MD035(params, onError) { "function": function MD035(params, onError) {
let style = String(params.config.style || "consistent").trim(); let style = String(params.config.style || "consistent").trim();
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types

View file

@ -10,6 +10,7 @@ module.exports = {
"names": [ "MD036", "no-emphasis-as-heading" ], "names": [ "MD036", "no-emphasis-as-heading" ],
"description": "Emphasis used instead of a heading", "description": "Emphasis used instead of a heading",
"tags": [ "headings", "emphasis" ], "tags": [ "headings", "emphasis" ],
"parser": "markdownit",
"function": function MD036(params, onError) { "function": function MD036(params, onError) {
let punctuation = params.config.punctuation; let punctuation = params.config.punctuation;
punctuation = punctuation =

View file

@ -11,6 +11,7 @@ module.exports = {
"names": [ "MD037", "no-space-in-emphasis" ], "names": [ "MD037", "no-space-in-emphasis" ],
"description": "Spaces inside emphasis markers", "description": "Spaces inside emphasis markers",
"tags": [ "whitespace", "emphasis" ], "tags": [ "whitespace", "emphasis" ],
"parser": "micromark",
"function": function MD037(params, onError) { "function": function MD037(params, onError) {
// Initialize variables // Initialize variables

View file

@ -25,6 +25,7 @@ module.exports = {
"names": [ "MD038", "no-space-in-code" ], "names": [ "MD038", "no-space-in-code" ],
"description": "Spaces inside code span elements", "description": "Spaces inside code span elements",
"tags": [ "whitespace", "code" ], "tags": [ "whitespace", "code" ],
"parser": "micromark",
"function": function MD038(params, onError) { "function": function MD038(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */

View file

@ -13,6 +13,7 @@ module.exports = {
"names": [ "MD039", "no-space-in-links" ], "names": [ "MD039", "no-space-in-links" ],
"description": "Spaces inside link text", "description": "Spaces inside link text",
"tags": [ "whitespace", "links" ], "tags": [ "whitespace", "links" ],
"parser": "markdownit",
"function": function MD039(params, onError) { "function": function MD039(params, onError) {
filterTokens(params, "inline", (token) => { filterTokens(params, "inline", (token) => {
const { children } = token; const { children } = token;

View file

@ -12,6 +12,7 @@ module.exports = {
"names": [ "MD040", "fenced-code-language" ], "names": [ "MD040", "fenced-code-language" ],
"description": "Fenced code blocks should have a language specified", "description": "Fenced code blocks should have a language specified",
"tags": [ "code", "language" ], "tags": [ "code", "language" ],
"parser": "micromark",
"function": function MD040(params, onError) { "function": function MD040(params, onError) {
let allowed = params.config.allowed_languages; let allowed = params.config.allowed_languages;
allowed = Array.isArray(allowed) ? allowed : []; allowed = Array.isArray(allowed) ? allowed : [];

View file

@ -10,6 +10,7 @@ module.exports = {
"names": [ "MD041", "first-line-heading", "first-line-h1" ], "names": [ "MD041", "first-line-heading", "first-line-h1" ],
"description": "First line in a file should be a top-level heading", "description": "First line in a file should be a top-level heading",
"tags": [ "headings" ], "tags": [ "headings" ],
"parser": "markdownit",
"function": function MD041(params, onError) { "function": function MD041(params, onError) {
const level = Number(params.config.level || 1); const level = Number(params.config.level || 1);
const tag = "h" + level; const tag = "h" + level;

View file

@ -11,6 +11,7 @@ module.exports = {
"names": [ "MD042", "no-empty-links" ], "names": [ "MD042", "no-empty-links" ],
"description": "No empty links", "description": "No empty links",
"tags": [ "links" ], "tags": [ "links" ],
"parser": "markdownit",
"function": function MD042(params, onError) { "function": function MD042(params, onError) {
filterTokens(params, "inline", function forToken(token) { filterTokens(params, "inline", function forToken(token) {
let inLink = false; let inLink = false;

View file

@ -11,6 +11,7 @@ module.exports = {
"names": [ "MD043", "required-headings" ], "names": [ "MD043", "required-headings" ],
"description": "Required heading structure", "description": "Required heading structure",
"tags": [ "headings" ], "tags": [ "headings" ],
"parser": "markdownit",
"function": function MD043(params, onError) { "function": function MD043(params, onError) {
const requiredHeadings = params.config.headings; const requiredHeadings = params.config.headings;
if (!Array.isArray(requiredHeadings)) { if (!Array.isArray(requiredHeadings)) {

View file

@ -17,6 +17,7 @@ module.exports = {
"names": [ "MD044", "proper-names" ], "names": [ "MD044", "proper-names" ],
"description": "Proper names should have the correct capitalization", "description": "Proper names should have the correct capitalization",
"tags": [ "spelling" ], "tags": [ "spelling" ],
"parser": "micromark",
"function": function MD044(params, onError) { "function": function MD044(params, onError) {
let names = params.config.names; let names = params.config.names;
names = Array.isArray(names) ? names : []; names = Array.isArray(names) ? names : [];

View file

@ -13,6 +13,7 @@ module.exports = {
"names": [ "MD045", "no-alt-text" ], "names": [ "MD045", "no-alt-text" ],
"description": "Images should have alternate text (alt text)", "description": "Images should have alternate text (alt text)",
"tags": [ "accessibility", "images" ], "tags": [ "accessibility", "images" ],
"parser": "micromark",
"function": function MD045(params, onError) { "function": function MD045(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */

View file

@ -16,6 +16,7 @@ module.exports = {
"names": [ "MD046", "code-block-style" ], "names": [ "MD046", "code-block-style" ],
"description": "Code block style", "description": "Code block style",
"tags": [ "code" ], "tags": [ "code" ],
"parser": "micromark",
"function": function MD046(params, onError) { "function": function MD046(params, onError) {
let expectedStyle = String(params.config.style || "consistent"); let expectedStyle = String(params.config.style || "consistent");
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types

View file

@ -10,6 +10,7 @@ module.exports = {
"names": [ "MD047", "single-trailing-newline" ], "names": [ "MD047", "single-trailing-newline" ],
"description": "Files should end with a single newline character", "description": "Files should end with a single newline character",
"tags": [ "blank_lines" ], "tags": [ "blank_lines" ],
"parser": "none",
"function": function MD047(params, onError) { "function": function MD047(params, onError) {
const lastLineNumber = params.lines.length; const lastLineNumber = params.lines.length;
const lastLine = params.lines[lastLineNumber - 1]; const lastLine = params.lines[lastLineNumber - 1];

View file

@ -11,6 +11,7 @@ module.exports = {
"names": [ "MD048", "code-fence-style" ], "names": [ "MD048", "code-fence-style" ],
"description": "Code fence style", "description": "Code fence style",
"tags": [ "code" ], "tags": [ "code" ],
"parser": "micromark",
"function": function MD048(params, onError) { "function": function MD048(params, onError) {
const style = String(params.config.style || "consistent"); const style = String(params.config.style || "consistent");
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types

View file

@ -75,6 +75,7 @@ module.exports = [
"names": [ "MD049", "emphasis-style" ], "names": [ "MD049", "emphasis-style" ],
"description": "Emphasis style", "description": "Emphasis style",
"tags": [ "emphasis" ], "tags": [ "emphasis" ],
"parser": "micromark",
"function": function MD049(params, onError) { "function": function MD049(params, onError) {
return impl( return impl(
params, params,
@ -91,6 +92,7 @@ module.exports = [
"names": [ "MD050", "strong-style" ], "names": [ "MD050", "strong-style" ],
"description": "Strong style", "description": "Strong style",
"tags": [ "emphasis" ], "tags": [ "emphasis" ],
"parser": "micromark",
"function": function MD050(params, onError) { "function": function MD050(params, onError) {
return impl( return impl(
params, params,

View file

@ -67,6 +67,7 @@ module.exports = {
"names": [ "MD051", "link-fragments" ], "names": [ "MD051", "link-fragments" ],
"description": "Link fragments should be valid", "description": "Link fragments should be valid",
"tags": [ "links" ], "tags": [ "links" ],
"parser": "micromark",
"function": function MD051(params, onError) { "function": function MD051(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */

View file

@ -12,6 +12,7 @@ module.exports = {
"description": "description":
"Reference links and images should use a label that is defined", "Reference links and images should use a label that is defined",
"tags": [ "images", "links" ], "tags": [ "images", "links" ],
"parser": "none",
"function": function MD052(params, onError) { "function": function MD052(params, onError) {
const { config, lines } = params; const { config, lines } = params;
const shortcutSyntax = config.shortcut_syntax || false; const shortcutSyntax = config.shortcut_syntax || false;

View file

@ -12,6 +12,7 @@ module.exports = {
"names": [ "MD053", "link-image-reference-definitions" ], "names": [ "MD053", "link-image-reference-definitions" ],
"description": "Link and image reference definitions should be needed", "description": "Link and image reference definitions should be needed",
"tags": [ "images", "links" ], "tags": [ "images", "links" ],
"parser": "none",
"function": function MD053(params, onError) { "function": function MD053(params, onError) {
const ignored = new Set(params.config.ignored_definitions || [ "//" ]); const ignored = new Set(params.config.ignored_definitions || [ "//" ]);
const lines = params.lines; const lines = params.lines;

View file

@ -27,6 +27,7 @@ module.exports = {
"names": [ "MD054", "link-image-style" ], "names": [ "MD054", "link-image-style" ],
"description": "Link and image style", "description": "Link and image style",
"tags": [ "images", "links" ], "tags": [ "images", "links" ],
"parser": "micromark",
"function": (params, onError) => { "function": (params, onError) => {
const config = params.config; const config = params.config;
const autolink = (config.autolink === undefined) || !!config.autolink; const autolink = (config.autolink === undefined) || !!config.autolink;

View file

@ -19,6 +19,7 @@ module.exports = {
"names": [ "MD055", "table-pipe-style" ], "names": [ "MD055", "table-pipe-style" ],
"description": "Table pipe style", "description": "Table pipe style",
"tags": [ "table" ], "tags": [ "table" ],
"parser": "micromark",
"function": function MD055(params, onError) { "function": function MD055(params, onError) {
const style = String(params.config.style || "consistent"); const style = String(params.config.style || "consistent");
let expectedStyle = style; let expectedStyle = style;

View file

@ -13,6 +13,7 @@ module.exports = {
"names": [ "MD056", "table-column-count" ], "names": [ "MD056", "table-column-count" ],
"description": "Table column count", "description": "Table column count",
"tags": [ "table" ], "tags": [ "table" ],
"parser": "micromark",
"function": function MD056(params, onError) { "function": function MD056(params, onError) {
// eslint-disable-next-line jsdoc/valid-types // eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */ /** @type import("../helpers/micromark.cjs").Token[] */

View file

@ -86,7 +86,6 @@
"markdown-it-for-inline": "2.0.1", "markdown-it-for-inline": "2.0.1",
"markdown-it-sub": "2.0.0", "markdown-it-sub": "2.0.0",
"markdown-it-sup": "2.0.0", "markdown-it-sup": "2.0.0",
"markdownlint-rule-helpers": "0.24.0",
"npm-run-all": "4.1.5", "npm-run-all": "4.1.5",
"terser-webpack-plugin": "5.3.10", "terser-webpack-plugin": "5.3.10",
"toml": "3.0.0", "toml": "3.0.0",

View file

@ -11,6 +11,8 @@ const { homepage, version } = require("../package.json");
test("customRulesV0", (t) => new Promise((resolve) => { test("customRulesV0", (t) => new Promise((resolve) => {
t.plan(4); t.plan(4);
const customRulesMd = "./test/custom-rules.md"; const customRulesMd = "./test/custom-rules.md";
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": customRules.all, "customRules": customRules.all,
"files": [ customRulesMd ], "files": [ customRulesMd ],
@ -77,6 +79,8 @@ test("customRulesV0", (t) => new Promise((resolve) => {
test("customRulesV1", (t) => new Promise((resolve) => { test("customRulesV1", (t) => new Promise((resolve) => {
t.plan(3); t.plan(3);
const customRulesMd = "./test/custom-rules.md"; const customRulesMd = "./test/custom-rules.md";
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": customRules.all, "customRules": customRules.all,
"files": [ customRulesMd ], "files": [ customRulesMd ],
@ -195,6 +199,8 @@ test("customRulesV1", (t) => new Promise((resolve) => {
test("customRulesV2", (t) => new Promise((resolve) => { test("customRulesV2", (t) => new Promise((resolve) => {
t.plan(3); t.plan(3);
const customRulesMd = "./test/custom-rules.md"; const customRulesMd = "./test/custom-rules.md";
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": customRules.all, "customRules": customRules.all,
"files": [ customRulesMd ], "files": [ customRulesMd ],
@ -304,6 +310,8 @@ test("customRulesV2", (t) => new Promise((resolve) => {
test("customRulesConfig", (t) => new Promise((resolve) => { test("customRulesConfig", (t) => new Promise((resolve) => {
t.plan(2); t.plan(2);
const customRulesMd = "./test/custom-rules.md"; const customRulesMd = "./test/custom-rules.md";
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": customRules.all, "customRules": customRules.all,
"files": [ customRulesMd ], "files": [ customRulesMd ],
@ -332,6 +340,8 @@ test("customRulesConfig", (t) => new Promise((resolve) => {
test("customRulesNpmPackage", (t) => new Promise((resolve) => { test("customRulesNpmPackage", (t) => new Promise((resolve) => {
t.plan(2); t.plan(2);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ require("./rules/npm") ], "customRules": [ require("./rules/npm") ],
"strings": { "strings": {
@ -352,7 +362,7 @@ test("customRulesNpmPackage", (t) => new Promise((resolve) => {
})); }));
test("customRulesBadProperty", (t) => { test("customRulesBadProperty", (t) => {
t.plan(27); t.plan(30);
for (const testCase of [ for (const testCase of [
{ {
"propertyName": "names", "propertyName": "names",
@ -376,6 +386,11 @@ test("customRulesBadProperty", (t) => {
"propertyValues": "propertyValues":
[ null, "string", [], [ null ], [ "" ], [ "string", 10 ] ] [ null, "string", [], [ null ], [ "" ], [ "string", 10 ] ]
}, },
{
"propertyName": "parser",
"propertyValues":
[ 10, "string", [] ]
},
{ {
"propertyName": "function", "propertyName": "function",
"propertyValues": [ null, "string", [] ] "propertyValues": [ null, "string", [] ]
@ -385,6 +400,8 @@ test("customRulesBadProperty", (t) => {
for (const propertyValue of propertyValues) { for (const propertyValue of propertyValues) {
const badRule = { ...customRules.anyBlockquote }; const badRule = { ...customRules.anyBlockquote };
badRule[propertyName] = propertyValue; badRule[propertyName] = propertyValue;
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ badRule ] "customRules": [ badRule ]
}; };
@ -394,9 +411,9 @@ test("customRulesBadProperty", (t) => {
}, },
{ {
"message": "message":
`Property '${propertyName}' of custom rule at index 0 is incorrect.` `Property '${propertyName}' of custom rule at index 0 is incorrect: '${propertyValue}'.`
}, },
"Did not get correct exception for missing property." `Did not get correct exception for property '${propertyName}' value '${propertyValue}'.`
); );
} }
} }
@ -405,11 +422,14 @@ test("customRulesBadProperty", (t) => {
test("customRulesUsedNameName", (t) => new Promise((resolve) => { test("customRulesUsedNameName", (t) => new Promise((resolve) => {
t.plan(4); t.plan(4);
markdownlint({ markdownlint({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name", "NO-missing-SPACE-atx" ], "names": [ "name", "NO-missing-SPACE-atx" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function noop() {} "function": function noop() {}
} }
] ]
@ -429,11 +449,14 @@ test("customRulesUsedNameName", (t) => new Promise((resolve) => {
test("customRulesUsedNameTag", (t) => new Promise((resolve) => { test("customRulesUsedNameTag", (t) => new Promise((resolve) => {
t.plan(4); t.plan(4);
markdownlint({ markdownlint({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name", "HtMl" ], "names": [ "name", "HtMl" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function noop() {} "function": function noop() {}
} }
] ]
@ -452,17 +475,21 @@ test("customRulesUsedNameTag", (t) => new Promise((resolve) => {
test("customRulesUsedTagName", (t) => new Promise((resolve) => { test("customRulesUsedTagName", (t) => new Promise((resolve) => {
t.plan(4); t.plan(4);
markdownlint({ markdownlint({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "filler" ], "names": [ "filler" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function noop() {} "function": function noop() {}
}, },
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag", "NO-missing-SPACE-atx" ], "tags": [ "tag", "NO-missing-SPACE-atx" ],
"parser": "none",
"function": function noop() {} "function": function noop() {}
} }
] ]
@ -479,8 +506,147 @@ test("customRulesUsedTagName", (t) => new Promise((resolve) => {
}); });
})); }));
test("customRulesParserUndefined", (t) => {
t.plan(5);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = {
"customRules": [
// @ts-ignore
{
"names": [ "name" ],
"description": "description",
"tags": [ "tag" ],
"function":
(params) => {
t.true(Object.keys(params).includes("tokens"));
t.is(Object.keys(params.parsers).length, 1);
t.truthy(params.parsers.markdownit);
t.is(Object.keys(params.parsers.markdownit).length, 1);
t.truthy(params.parsers.markdownit.tokens);
}
}
],
"strings": {
"string": "# Heading\n"
}
};
return markdownlint.promises.markdownlint(options).then(() => null);
});
test("customRulesParserNone", (t) => {
t.plan(2);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = {
"customRules": [
{
"names": [ "name" ],
"description": "description",
"tags": [ "tag" ],
"parser": "none",
"function":
(params) => {
t.false(Object.keys(params).includes("tokens"));
t.is(Object.keys(params.parsers).length, 0);
}
}
],
"strings": {
"string": "# Heading\n"
}
};
return markdownlint.promises.markdownlint(options).then(() => null);
});
test("customRulesParserMarkdownIt", (t) => {
t.plan(5);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = {
"customRules": [
{
"names": [ "name" ],
"description": "description",
"tags": [ "tag" ],
"parser": "markdownit",
"function":
(params) => {
t.false(Object.keys(params).includes("tokens"));
t.is(Object.keys(params.parsers).length, 1);
t.truthy(params.parsers.markdownit);
t.is(Object.keys(params.parsers.markdownit).length, 1);
t.truthy(params.parsers.markdownit.tokens);
}
}
],
"strings": {
"string": "# Heading\n"
}
};
return markdownlint.promises.markdownlint(options).then(() => null);
});
test("customRulesParserMicromark", (t) => {
t.plan(1);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = {
"customRules": [
{
"names": [ "name" ],
"description": "description",
"tags": [ "tag" ],
"parser": "micromark",
"function":
() => {
// t.false(Object.keys(params).includes("tokens"));
// t.is(Object.keys(params.parsers).length, 1);
// t.truthy(params.parsers.micromark);
// t.is(Object.keys(params.parsers.micromark).length, 1);
// t.truthy(params.parsers.micromark.tokens);
}
}
],
"strings": {
"string": "# Heading\n"
}
};
return markdownlint.promises.markdownlint(options).catch((error) => {
// parser "micromark" currently unsupported for custom rules
t.is(error.message, "Property 'parser' of custom rule at index 0 is incorrect: 'micromark'.");
});
});
test("customRulesParamsTokensSameObject", (t) => {
t.plan(1);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = {
"customRules": [
// @ts-ignore
{
"names": [ "name" ],
"description": "description",
"tags": [ "tag" ],
"function":
(params) => {
// @ts-ignore
t.is(params.tokens, params.parsers.markdownit.tokens);
}
}
],
"strings": {
"string": "# Heading\n"
}
};
return markdownlint.promises.markdownlint(options).then(() => null);
});
test("customRulesDefinitionStatic", (t) => new Promise((resolve) => { test("customRulesDefinitionStatic", (t) => new Promise((resolve) => {
t.plan(2); t.plan(2);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
@ -488,7 +654,9 @@ test("customRulesDefinitionStatic", (t) => new Promise((resolve) => {
"description": "description", "description": "description",
"information": new URL("https://example.com/information"), "information": new URL("https://example.com/information"),
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": (params, onError) => { "function": (params, onError) => {
// @ts-ignore
const definition = options.customRules[0]; const definition = options.customRules[0];
definition.names[0] = "changed"; definition.names[0] = "changed";
definition.description = "changed"; definition.description = "changed";
@ -528,11 +696,14 @@ test("customRulesThrowForFile", (t) => new Promise((resolve) => {
t.plan(4); t.plan(4);
const exceptionMessage = "Test exception message"; const exceptionMessage = "Test exception message";
markdownlint({ markdownlint({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function throws() { "function": function throws() {
throw new Error(exceptionMessage); throw new Error(exceptionMessage);
} }
@ -556,11 +727,14 @@ test("customRulesThrowForFileSync", (t) => {
t.throws( t.throws(
function customRuleThrowsCall() { function customRuleThrowsCall() {
markdownlint.sync({ markdownlint.sync({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function throws() { "function": function throws() {
throw new Error(exceptionMessage); throw new Error(exceptionMessage);
} }
@ -580,11 +754,14 @@ test("customRulesThrowForString", (t) => new Promise((resolve) => {
t.plan(4); t.plan(4);
const exceptionMessage = "Test exception message"; const exceptionMessage = "Test exception message";
markdownlint({ markdownlint({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function throws() { "function": function throws() {
throw new Error(exceptionMessage); throw new Error(exceptionMessage);
} }
@ -610,11 +787,14 @@ test("customRulesThrowForStringSync", (t) => {
t.throws( t.throws(
function customRuleThrowsCall() { function customRuleThrowsCall() {
markdownlint.sync({ markdownlint.sync({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function throws() { "function": function throws() {
throw new Error(exceptionMessage); throw new Error(exceptionMessage);
} }
@ -635,11 +815,14 @@ test("customRulesThrowForStringSync", (t) => {
test("customRulesOnErrorNull", (t) => new Promise((resolve) => { test("customRulesOnErrorNull", (t) => new Promise((resolve) => {
t.plan(4); t.plan(4);
markdownlint({ markdownlint({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function onErrorNull(params, onError) { "function": function onErrorNull(params, onError) {
// @ts-ignore // @ts-ignore
onError(null); onError(null);
@ -666,13 +849,17 @@ test("customRulesOnErrorNull", (t) => new Promise((resolve) => {
test("customRulesOnErrorNullSync", (t) => { test("customRulesOnErrorNullSync", (t) => {
t.plan(1); t.plan(1);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function onErrorNull(params, onError) { "function": function onErrorNull(params, onError) {
// @ts-ignore
onError(null); onError(null);
} }
} }
@ -754,12 +941,15 @@ test("customRulesOnErrorBad", (t) => {
badObject[propertyName] = propertyValue; badObject[propertyName] = propertyValue;
propertyNames = propertyName; propertyNames = propertyName;
} }
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function onErrorBad(params, onError) { "function": function onErrorBad(params, onError) {
onError(badObject); onError(badObject);
} }
@ -824,12 +1014,15 @@ test("customRulesOnErrorInvalid", (t) => {
badObject[propertyName] = propertyValue; badObject[propertyName] = propertyValue;
propertyNames = propertyName; propertyNames = propertyName;
} }
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function onErrorInvalid(params, onError) { "function": function onErrorInvalid(params, onError) {
onError(badObject); onError(badObject);
} }
@ -897,12 +1090,15 @@ test("customRulesOnErrorValid", (t) => {
} else { } else {
goodObject[propertyName] = propertyValue; goodObject[propertyName] = propertyValue;
} }
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function onErrorValid(params, onError) { "function": function onErrorValid(params, onError) {
onError(goodObject); onError(goodObject);
} }
@ -920,12 +1116,15 @@ test("customRulesOnErrorValid", (t) => {
test("customRulesOnErrorLazy", (t) => new Promise((resolve) => { test("customRulesOnErrorLazy", (t) => new Promise((resolve) => {
t.plan(2); t.plan(2);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function onErrorLazy(params, onError) { "function": function onErrorLazy(params, onError) {
onError({ onError({
"lineNumber": 1, "lineNumber": 1,
@ -975,12 +1174,15 @@ test("customRulesOnErrorModified", (t) => new Promise((resolve) => {
"insertText": "text" "insertText": "text"
} }
}; };
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function onErrorModified(params, onError) { "function": function onErrorModified(params, onError) {
onError(errorObject); onError(errorObject);
errorObject.lineNumber = 2; errorObject.lineNumber = 2;
@ -1026,11 +1228,14 @@ test("customRulesOnErrorModified", (t) => new Promise((resolve) => {
test("customRulesOnErrorInvalidHandled", (t) => new Promise((resolve) => { test("customRulesOnErrorInvalidHandled", (t) => new Promise((resolve) => {
t.plan(2); t.plan(2);
markdownlint({ markdownlint({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function onErrorInvalid(params, onError) { "function": function onErrorInvalid(params, onError) {
onError({ onError({
"lineNumber": 13 "lineNumber": 13
@ -1067,11 +1272,14 @@ test("customRulesOnErrorInvalidHandled", (t) => new Promise((resolve) => {
test("customRulesOnErrorInvalidHandledSync", (t) => { test("customRulesOnErrorInvalidHandledSync", (t) => {
t.plan(1); t.plan(1);
const actualResult = markdownlint.sync({ const actualResult = markdownlint.sync({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function onErrorInvalid(params, onError) { "function": function onErrorInvalid(params, onError) {
onError({ onError({
"lineNumber": 13, "lineNumber": 13,
@ -1105,12 +1313,15 @@ test("customRulesOnErrorInvalidHandledSync", (t) => {
test("customRulesFileName", (t) => new Promise((resolve) => { test("customRulesFileName", (t) => new Promise((resolve) => {
t.plan(2); t.plan(2);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function stringName(params) { "function": function stringName(params) {
t.is(params.name, "doc/CustomRules.md", "Incorrect file name"); t.is(params.name, "doc/CustomRules.md", "Incorrect file name");
} }
@ -1126,12 +1337,15 @@ test("customRulesFileName", (t) => new Promise((resolve) => {
test("customRulesStringName", (t) => new Promise((resolve) => { test("customRulesStringName", (t) => new Promise((resolve) => {
t.plan(2); t.plan(2);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": function stringName(params) { "function": function stringName(params) {
t.is(params.name, "string", "Incorrect string name"); t.is(params.name, "string", "Incorrect string name");
} }
@ -1150,11 +1364,14 @@ test("customRulesStringName", (t) => new Promise((resolve) => {
test("customRulesOnErrorInformationNotRuleNotError", (t) => { test("customRulesOnErrorInformationNotRuleNotError", (t) => {
t.plan(1); t.plan(1);
const actualResult = markdownlint.sync({ const actualResult = markdownlint.sync({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": (params, onError) => { "function": (params, onError) => {
onError({ onError({
"lineNumber": 1 "lineNumber": 1
@ -1172,12 +1389,15 @@ test("customRulesOnErrorInformationNotRuleNotError", (t) => {
test("customRulesOnErrorInformationRuleNotError", (t) => { test("customRulesOnErrorInformationRuleNotError", (t) => {
t.plan(1); t.plan(1);
const actualResult = markdownlint.sync({ const actualResult = markdownlint.sync({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"information": new URL("https://example.com/rule"), "information": new URL("https://example.com/rule"),
"parser": "none",
"function": (params, onError) => { "function": (params, onError) => {
onError({ onError({
"lineNumber": 1 "lineNumber": 1
@ -1199,11 +1419,14 @@ test("customRulesOnErrorInformationRuleNotError", (t) => {
test("customRulesOnErrorInformationNotRuleError", (t) => { test("customRulesOnErrorInformationNotRuleError", (t) => {
t.plan(1); t.plan(1);
const actualResult = markdownlint.sync({ const actualResult = markdownlint.sync({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": (params, onError) => { "function": (params, onError) => {
onError({ onError({
"lineNumber": 1, "lineNumber": 1,
@ -1226,12 +1449,15 @@ test("customRulesOnErrorInformationNotRuleError", (t) => {
test("customRulesOnErrorInformationRuleError", (t) => { test("customRulesOnErrorInformationRuleError", (t) => {
t.plan(1); t.plan(1);
const actualResult = markdownlint.sync({ const actualResult = markdownlint.sync({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"information": new URL("https://example.com/rule"), "information": new URL("https://example.com/rule"),
"parser": "none",
"function": (params, onError) => { "function": (params, onError) => {
onError({ onError({
"lineNumber": 1, "lineNumber": 1,
@ -1254,12 +1480,15 @@ test("customRulesOnErrorInformationRuleError", (t) => {
test("customRulesOnErrorInformationRuleErrorUndefined", (t) => { test("customRulesOnErrorInformationRuleErrorUndefined", (t) => {
t.plan(1); t.plan(1);
const actualResult = markdownlint.sync({ const actualResult = markdownlint.sync({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"information": new URL("https://example.com/rule"), "information": new URL("https://example.com/rule"),
"parser": "none",
"function": (params, onError) => { "function": (params, onError) => {
onError({ onError({
"lineNumber": 1, "lineNumber": 1,
@ -1282,12 +1511,15 @@ test("customRulesOnErrorInformationRuleErrorUndefined", (t) => {
test("customRulesOnErrorInformationRuleErrorMultiple", (t) => { test("customRulesOnErrorInformationRuleErrorMultiple", (t) => {
t.plan(6); t.plan(6);
const actualResult = markdownlint.sync({ const actualResult = markdownlint.sync({
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"information": new URL("https://example.com/rule"), "information": new URL("https://example.com/rule"),
"parser": "none",
"function": (params, onError) => { "function": (params, onError) => {
onError({ onError({
"lineNumber": 1, "lineNumber": 1,
@ -1356,6 +1588,8 @@ test("customRulesDoc", (t) => new Promise((resolve) => {
test("customRulesLintJavaScript", (t) => new Promise((resolve) => { test("customRulesLintJavaScript", (t) => new Promise((resolve) => {
t.plan(2); t.plan(2);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": customRules.lintJavaScript, "customRules": customRules.lintJavaScript,
"files": "test/lint-javascript.md" "files": "test/lint-javascript.md"
@ -1393,6 +1627,8 @@ test("customRulesLintJavaScript", (t) => new Promise((resolve) => {
test("customRulesValidateJson", (t) => new Promise((resolve) => { test("customRulesValidateJson", (t) => new Promise((resolve) => {
t.plan(3); t.plan(3);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": customRules.validateJson, "customRules": customRules.validateJson,
"files": "test/validate-json.md" "files": "test/validate-json.md"
@ -1425,12 +1661,15 @@ test("customRulesValidateJson", (t) => new Promise((resolve) => {
test("customRulesAsyncThrowsInSyncContext", (t) => { test("customRulesAsyncThrowsInSyncContext", (t) => {
t.plan(1); t.plan(1);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
"names": [ "name1", "name2" ], "names": [ "name1", "name2" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"asynchronous": true, "asynchronous": true,
"function": () => {} "function": () => {}
} }
@ -1449,32 +1688,16 @@ test("customRulesAsyncThrowsInSyncContext", (t) => {
); );
}); });
test("customRulesParamsTokensSameObject", (t) => {
t.plan(1);
const options = {
"customRules": [
{
"names": [ "name" ],
"description": "description",
"tags": [ "tag" ],
"function":
(params) => {
t.is(params.tokens, params.parsers.markdownit.tokens);
}
}
],
"files": [ "README.md" ]
};
return markdownlint.promises.markdownlint(options).then(() => null);
});
test("customRulesParamsAreFrozen", (t) => { test("customRulesParamsAreFrozen", (t) => {
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"function": "function":
(params) => { (params) => {
const pending = [ params ]; const pending = [ params ];
@ -1504,6 +1727,8 @@ test("customRulesParamsAreStable", (t) => {
t.plan(4); t.plan(4);
const config1 = { "value1": 10 }; const config1 = { "value1": 10 };
const config2 = { "value2": 20 }; const config2 = { "value2": 20 };
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"config": { "config": {
"MD010": true, "MD010": true,
@ -1518,18 +1743,20 @@ test("customRulesParamsAreStable", (t) => {
"description": "description1", "description": "description1",
"tags": [ "tag" ], "tags": [ "tag" ],
"asynchronous": true, "asynchronous": true,
"parser": "none",
"function": "function":
(params) => { (params) => {
const { config } = params;
t.deepEqual( t.deepEqual(
params.config, config,
config1, config1,
`Unexpected config in sync path: ${params.config}.` `Unexpected config in sync path: ${config}.`
); );
return Promise.resolve().then(() => { return Promise.resolve().then(() => {
t.deepEqual( t.deepEqual(
params.config, config,
config1, config1,
`Unexpected config in async path: ${params.config}.` `Unexpected config in async path: ${config}.`
); );
}); });
} }
@ -1539,6 +1766,7 @@ test("customRulesParamsAreStable", (t) => {
"description": "description2", "description": "description2",
"tags": [ "tag" ], "tags": [ "tag" ],
"asynchronous": true, "asynchronous": true,
"parser": "none",
"function": "function":
(params) => { (params) => {
const { config } = params; const { config } = params;
@ -1566,6 +1794,8 @@ test("customRulesParamsAreStable", (t) => {
test("customRulesAsyncReadFiles", (t) => { test("customRulesAsyncReadFiles", (t) => {
t.plan(3); t.plan(3);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
@ -1574,6 +1804,7 @@ test("customRulesAsyncReadFiles", (t) => {
"information": new URL("https://example.com/asyncRule1"), "information": new URL("https://example.com/asyncRule1"),
"tags": [ "tag" ], "tags": [ "tag" ],
"asynchronous": true, "asynchronous": true,
"parser": "none",
"function": "function":
(params, onError) => fs.readFile(__filename, "utf8").then( (params, onError) => fs.readFile(__filename, "utf8").then(
(content) => { (content) => {
@ -1592,6 +1823,7 @@ test("customRulesAsyncReadFiles", (t) => {
"description": "description2", "description": "description2",
"tags": [ "tag" ], "tags": [ "tag" ],
"asynchronous": true, "asynchronous": true,
"parser": "none",
"function": "function":
async(params, onError) => { async(params, onError) => {
const content = await fs.readFile(__filename, "utf8"); const content = await fs.readFile(__filename, "utf8");
@ -1651,6 +1883,8 @@ test("customRulesAsyncReadFiles", (t) => {
test("customRulesAsyncIgnoresSyncReturn", (t) => { test("customRulesAsyncIgnoresSyncReturn", (t) => {
t.plan(1); t.plan(1);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
@ -1659,6 +1893,7 @@ test("customRulesAsyncIgnoresSyncReturn", (t) => {
"information": new URL("https://example.com/asyncRule"), "information": new URL("https://example.com/asyncRule"),
"tags": [ "tag" ], "tags": [ "tag" ],
"asynchronous": false, "asynchronous": false,
"parser": "none",
"function": () => new Promise(() => { "function": () => new Promise(() => {
// Never resolves // Never resolves
}) })
@ -1669,6 +1904,7 @@ test("customRulesAsyncIgnoresSyncReturn", (t) => {
"information": new URL("https://example.com/asyncRule"), "information": new URL("https://example.com/asyncRule"),
"tags": [ "tag" ], "tags": [ "tag" ],
"asynchronous": true, "asynchronous": true,
"parser": "none",
"function": (params, onError) => new Promise((resolve) => { "function": (params, onError) => new Promise((resolve) => {
onError({ "lineNumber": 1 }); onError({ "lineNumber": 1 });
resolve(null); resolve(null);
@ -1739,11 +1975,15 @@ for (const flavor of [
] ]
]) { ]) {
const [ name, func ] = flavor; const [ name, func ] = flavor;
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule[] */
const customRule = [ const customRule = [
{ {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
// @ts-ignore
"function": func "function": func
} }
]; ];
@ -1873,11 +2113,15 @@ for (const flavor of [
] ]
]) { ]) {
const [ name, func ] = flavor; const [ name, func ] = flavor;
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Rule */
const customRule = { const customRule = {
"names": [ "name" ], "names": [ "name" ],
"description": "description", "description": "description",
"tags": [ "tag" ], "tags": [ "tag" ],
"parser": "none",
"asynchronous": true, "asynchronous": true,
// @ts-ignore
"function": func "function": func
}; };
for (const inputs of stringScenarios) { for (const inputs of stringScenarios) {

View file

@ -928,16 +928,19 @@ test("expandTildePath", (t) => {
test("getReferenceLinkImageData().shortcuts", (t) => { test("getReferenceLinkImageData().shortcuts", (t) => {
t.plan(1); t.plan(1);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
"names": [ "no-shortcut-links" ], "names": [ "no-shortcut-links" ],
"description": "-", "description": "-",
"tags": [ "-" ], "tags": [ "-" ],
"parser": "none",
"function": "function":
(params) => { () => {
const { shortcuts } = const { referenceLinkImageData } = require("../lib/cache");
helpers.getReferenceLinkImageData(params); const { shortcuts } = referenceLinkImageData();
t.is(shortcuts.size, 0, [ ...shortcuts.keys() ].join(", ")); t.is(shortcuts.size, 0, [ ...shortcuts.keys() ].join(", "));
} }
} }

View file

@ -1059,12 +1059,12 @@ test("someCustomRulesHaveValidUrl", (t) => {
(Object.getPrototypeOf(rule.information) === URL.prototype)); (Object.getPrototypeOf(rule.information) === URL.prototype));
if (rule === customRules.anyBlockquote) { if (rule === customRules.anyBlockquote) {
t.is( t.is(
rule.information.href, rule.information?.href,
`${homepage}/blob/main/test/rules/any-blockquote.js` `${homepage}/blob/main/test/rules/any-blockquote.js`
); );
} else if (rule === customRules.lettersEX) { } else if (rule === customRules.lettersEX) {
t.is( t.is(
rule.information.href, rule.information?.href,
`${homepage}/blob/main/test/rules/letters-E-X.js` `${homepage}/blob/main/test/rules/letters-E-X.js`
); );
} }
@ -1142,12 +1142,15 @@ Text with: [^footnote]
test("token-map-spans", (t) => { test("token-map-spans", (t) => {
t.plan(38); t.plan(38);
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../lib/markdownlint").Options */
const options = { const options = {
"customRules": [ "customRules": [
{ {
"names": [ "token-map-spans" ], "names": [ "token-map-spans" ],
"description": "token-map-spans", "description": "token-map-spans",
"tags": [ "tms" ], "tags": [ "tms" ],
"parser": "markdownit",
"function": function tokenMapSpans(params) { "function": function tokenMapSpans(params) {
const tokenLines = []; const tokenLines = [];
let lastLineNumber = -1; let lastLineNumber = -1;

View file

@ -2,7 +2,7 @@
"use strict"; "use strict";
const { filterTokens } = require("markdownlint-rule-helpers"); const { filterTokens } = require("../../helpers");
/** @typedef {import("../../lib/markdownlint").MarkdownItToken} MarkdownItToken */ /** @typedef {import("../../lib/markdownlint").MarkdownItToken} MarkdownItToken */
/** @typedef {(MarkdownItToken) => void} FilterTokensCallback */ /** @typedef {(MarkdownItToken) => void} FilterTokensCallback */
@ -16,6 +16,7 @@ module.exports = {
"/blob/main/test/rules/any-blockquote.js" "/blob/main/test/rules/any-blockquote.js"
), ),
"tags": [ "test" ], "tags": [ "test" ],
"parser": "markdownit",
"function": (params, onError) => { "function": (params, onError) => {
filterTokens( filterTokens(
params, params,

View file

@ -2,13 +2,14 @@
"use strict"; "use strict";
const { forEachLine, getLineMetadata } = require("markdownlint-rule-helpers"); const { forEachLine, getLineMetadata } = require("../../helpers");
/** @type import("../../lib/markdownlint").Rule */ /** @type import("../../lib/markdownlint").Rule */
module.exports = { module.exports = {
"names": [ "every-n-lines" ], "names": [ "every-n-lines" ],
"description": "Rule that reports an error every N lines", "description": "Rule that reports an error every N lines",
"tags": [ "test" ], "tags": [ "test" ],
"parser": "markdownit",
"function": (params, onError) => { "function": (params, onError) => {
const n = params.config.n || 2; const n = params.config.n || 2;
forEachLine(getLineMetadata(params), (line, lineIndex) => { forEachLine(getLineMetadata(params), (line, lineIndex) => {

View file

@ -7,6 +7,7 @@ module.exports = {
"names": [ "first-line" ], "names": [ "first-line" ],
"description": "Rule that reports an error for the first line", "description": "Rule that reports an error for the first line",
"tags": [ "test" ], "tags": [ "test" ],
"parser": "none",
"function": function rule(params, onError) { "function": function rule(params, onError) {
// Unconditionally report an error for line 1 // Unconditionally report an error for line 1
onError({ onError({

View file

@ -11,6 +11,7 @@ module.exports = {
"/blob/main/test/rules/letters-E-X.js" "/blob/main/test/rules/letters-E-X.js"
), ),
"tags": [ "test" ], "tags": [ "test" ],
"parser": "markdownit",
"function": (params, onError) => { "function": (params, onError) => {
for (const inline of params.parsers.markdownit.tokens.filter( for (const inline of params.parsers.markdownit.tokens.filter(
(token) => token.type === "inline" (token) => token.type === "inline"

View file

@ -2,7 +2,7 @@
"use strict"; "use strict";
const { filterTokens } = require("markdownlint-rule-helpers"); const { filterTokens } = require("../../helpers");
const eslint = require("eslint"); const eslint = require("eslint");
const eslintInstance = new eslint.ESLint(); const eslintInstance = new eslint.ESLint();
const linter = new eslint.Linter(); const linter = new eslint.Linter();
@ -29,6 +29,7 @@ module.exports = {
"names": [ "lint-javascript" ], "names": [ "lint-javascript" ],
"description": "Rule that lints JavaScript code", "description": "Rule that lints JavaScript code",
"tags": [ "test", "lint", "javascript" ], "tags": [ "test", "lint", "javascript" ],
"parser": "markdownit",
"asynchronous": true, "asynchronous": true,
"function": (params, onError) => { "function": (params, onError) => {
filterTokens(params, "fence", (fence) => { filterTokens(params, "fence", (fence) => {

View file

@ -7,6 +7,7 @@ module.exports = {
"names": [ "sample-rule" ], "names": [ "sample-rule" ],
"description": "Sample rule", "description": "Sample rule",
"tags": [ "sample" ], "tags": [ "sample" ],
"parser": "markdownit",
"function": function rule(params, onError) { "function": function rule(params, onError) {
for (const token of params.parsers.markdownit.tokens) { for (const token of params.parsers.markdownit.tokens) {
if (token.type === "hr") { if (token.type === "hr") {

View file

@ -2,7 +2,7 @@
"use strict"; "use strict";
const { filterTokens } = require("markdownlint-rule-helpers"); const { filterTokens } = require("../../helpers");
const { parse, printParseErrorCode } = require("jsonc-parser"); const { parse, printParseErrorCode } = require("jsonc-parser");
/** @type import("../../lib/markdownlint").Rule */ /** @type import("../../lib/markdownlint").Rule */
@ -10,6 +10,7 @@ module.exports = {
"names": [ "validate-json" ], "names": [ "validate-json" ],
"description": "Rule that validates JSON code", "description": "Rule that validates JSON code",
"tags": [ "test", "validate", "json" ], "tags": [ "test", "validate", "json" ],
"parser": "markdownit",
"asynchronous": true, "asynchronous": true,
"function": (params, onError) => { "function": (params, onError) => {
filterTokens(params, "fence", (fence) => { filterTokens(params, "fence", (fence) => {