2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-09-08 16:51:00 -07:00
|
|
|
const { addErrorContext, filterTokens, headingStyleFor } =
|
|
|
|
require("../helpers");
|
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",
|
|
|
|
"tags": [ "headings", "headers", "atx", "spaces" ],
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD019(params, onError) {
|
2019-09-08 16:51:00 -07:00
|
|
|
filterTokens(params, "heading_open", (token) => {
|
|
|
|
if (headingStyleFor(token) === "atx") {
|
|
|
|
const { line, lineNumber } = token;
|
2022-12-19 21:36:24 -08:00
|
|
|
const match = /^(#+)([ \t]{2,})\S/.exec(line);
|
2019-09-08 16:51:00 -07:00
|
|
|
if (match) {
|
|
|
|
const [
|
|
|
|
,
|
|
|
|
{ "length": hashLength },
|
|
|
|
{ "length": spacesLength }
|
|
|
|
] = match;
|
|
|
|
addErrorContext(
|
|
|
|
onError,
|
|
|
|
lineNumber,
|
|
|
|
line.trim(),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
[ 1, hashLength + spacesLength + 1 ],
|
|
|
|
{
|
|
|
|
"editColumn": hashLength + 1,
|
|
|
|
"deleteCount": spacesLength - 1
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|