markdownlint/lib/md018.js

35 lines
896 B
JavaScript
Raw Normal View History

// @ts-check
"use strict";
const { addErrorContext, forEachLine } = require("../helpers");
const { lineMetadata } = require("./cache");
module.exports = {
"names": [ "MD018", "no-missing-space-atx" ],
"description": "No space after hash on atx style heading",
"tags": [ "headings", "headers", "atx", "spaces" ],
"function": function MD018(params, onError) {
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
if (!inCode &&
/^#+[^#\s]/.test(line) &&
!/#\s*$/.test(line) &&
!line.startsWith("#️⃣")) {
const hashCount = /^#+/.exec(line)[0].length;
addErrorContext(
onError,
lineIndex + 1,
line.trim(),
null,
null,
[ 1, hashCount + 1 ],
{
"editColumn": hashCount + 1,
"insertText": " "
}
);
}
});
}
};