2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const shared = require("./shared");
|
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) {
|
|
|
|
shared.filterTokens(params, "heading_open", function forToken(token) {
|
|
|
|
if (shared.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) {
|
|
|
|
shared.addErrorContext(onError, token.lineNumber, token.line.trim(),
|
|
|
|
left, right,
|
2018-03-19 23:39:42 +01:00
|
|
|
shared.rangeFromRegExp(token.line, atxClosedHeadingSpaceRe));
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|