2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-04-13 11:18:57 -07:00
|
|
|
const { addErrorContext, forEachLine, rangeFromRegExp } = require("../helpers");
|
2019-04-10 21:26:59 -07:00
|
|
|
const { lineMetadata } = require("./cache");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const atxClosedHeadingNoSpaceRe = /(?:^#+[^#\s])|(?:[^#\s]#+\s*$)/;
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD020", "no-missing-space-closed-atx" ],
|
2018-03-19 23:39:42 +01:00
|
|
|
"description": "No space inside hashes on closed atx style heading",
|
|
|
|
"tags": [ "headings", "headers", "atx_closed", "spaces" ],
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD020(params, onError) {
|
2019-04-10 21:26:59 -07:00
|
|
|
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
|
2018-01-21 21:44:25 -08:00
|
|
|
if (!inCode && /^#+[^#]*[^\\]#+$/.test(line)) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const left = /^#+[^#\s]/.test(line);
|
|
|
|
const right = /[^#\s]#+$/.test(line);
|
2018-01-21 21:44:25 -08:00
|
|
|
if (left || right) {
|
2019-04-10 21:26:59 -07:00
|
|
|
addErrorContext(onError, lineIndex + 1, line.trim(), left,
|
|
|
|
right, rangeFromRegExp(line, atxClosedHeadingNoSpaceRe));
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|