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 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) {
|
2018-03-04 23:06:31 -08:00
|
|
|
shared.forEachLine(function forLine(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) {
|
|
|
|
shared.addErrorContext(onError, lineIndex + 1, line.trim(), left,
|
2018-03-19 23:39:42 +01:00
|
|
|
right, shared.rangeFromRegExp(line, atxClosedHeadingNoSpaceRe));
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|