2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
2024-06-11 21:37:09 -07:00
|
|
|
const { addErrorContext } = require("../helpers");
|
|
|
|
|
const { filterByTypes, getHeadingStyle } = require("../helpers/micromark.cjs");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2024-02-27 20:42:09 -08:00
|
|
|
// eslint-disable-next-line jsdoc/valid-types
|
|
|
|
|
/** @type import("./markdownlint").Rule */
|
2018-01-21 21:44:25 -08:00
|
|
|
module.exports = {
|
|
|
|
|
"names": [ "MD019", "no-multiple-space-atx" ],
|
2018-03-19 23:39:42 +01:00
|
|
|
"description": "Multiple spaces after hash on atx style heading",
|
2023-11-09 20:05:30 -08:00
|
|
|
"tags": [ "headings", "atx", "spaces" ],
|
2024-06-11 21:37:09 -07:00
|
|
|
"parser": "micromark",
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD019(params, onError) {
|
2024-06-11 21:37:09 -07:00
|
|
|
const atxHeadings = filterByTypes(
|
|
|
|
|
params.parsers.micromark.tokens,
|
|
|
|
|
[ "atxHeading" ]
|
|
|
|
|
).filter((heading) => getHeadingStyle(heading) === "atx");
|
|
|
|
|
for (const atxHeading of atxHeadings) {
|
|
|
|
|
const [ atxHeadingSequence, whitespace ] = atxHeading.children;
|
|
|
|
|
if (
|
|
|
|
|
(atxHeadingSequence?.type === "atxHeadingSequence") &&
|
|
|
|
|
(whitespace?.type === "whitespace") &&
|
|
|
|
|
(whitespace.text.length > 1)
|
|
|
|
|
) {
|
|
|
|
|
const column = whitespace.startColumn + 1;
|
|
|
|
|
const length = whitespace.endColumn - column;
|
|
|
|
|
addErrorContext(
|
|
|
|
|
onError,
|
|
|
|
|
atxHeading.startLine,
|
|
|
|
|
atxHeading.text.trim(),
|
|
|
|
|
undefined,
|
|
|
|
|
undefined,
|
|
|
|
|
[ column, length ],
|
|
|
|
|
{
|
|
|
|
|
"editColumn": column,
|
|
|
|
|
"deleteCount": length
|
|
|
|
|
}
|
|
|
|
|
);
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
2024-06-11 21:37:09 -07:00
|
|
|
}
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
|
};
|