2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-04-13 11:18:57 -07:00
|
|
|
const { addErrorContext, filterTokens, headingStyleFor, rangeFromRegExp } =
|
|
|
|
require("../helpers");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const atxClosedHeadingSpaceRe = /(?:^#+\s\s+?\S)|(?:\S\s\s+?#+\s*$)/;
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD021", "no-multiple-space-closed-atx" ],
|
2018-03-19 23:39:42 +01:00
|
|
|
"description": "Multiple spaces inside hashes on closed atx style heading",
|
|
|
|
"tags": [ "headings", "headers", "atx_closed", "spaces" ],
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD021(params, onError) {
|
2019-04-13 11:18:57 -07:00
|
|
|
filterTokens(params, "heading_open", function forToken(token) {
|
|
|
|
if (headingStyleFor(token) === "atx_closed") {
|
2018-04-27 22:05:34 -07:00
|
|
|
const left = /^#+\s\s/.test(token.line);
|
|
|
|
const right = /\s\s#+$/.test(token.line);
|
2018-01-21 21:44:25 -08:00
|
|
|
if (left || right) {
|
2019-04-13 11:18:57 -07:00
|
|
|
addErrorContext(onError, token.lineNumber, token.line.trim(),
|
2018-01-21 21:44:25 -08:00
|
|
|
left, right,
|
2019-04-13 11:18:57 -07:00
|
|
|
rangeFromRegExp(token.line, atxClosedHeadingSpaceRe));
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|