mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
37 lines
997 B
JavaScript
37 lines
997 B
JavaScript
// @ts-check
|
|
|
|
"use strict";
|
|
|
|
const { addErrorContext, forEachLine } = require("../helpers");
|
|
const { lineMetadata } = require("./cache");
|
|
|
|
// eslint-disable-next-line jsdoc/valid-types
|
|
/** @type import("./markdownlint").Rule */
|
|
module.exports = {
|
|
"names": [ "MD018", "no-missing-space-atx" ],
|
|
"description": "No space after hash on atx style heading",
|
|
"tags": [ "headings", "atx", "spaces" ],
|
|
"function": function MD018(params, onError) {
|
|
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
|
|
if (!inCode &&
|
|
/^#+[^# \t]/.test(line) &&
|
|
!/#\s*$/.test(line) &&
|
|
!line.startsWith("#️⃣")) {
|
|
// @ts-ignore
|
|
const hashCount = /^#+/.exec(line)[0].length;
|
|
addErrorContext(
|
|
onError,
|
|
lineIndex + 1,
|
|
line.trim(),
|
|
null,
|
|
null,
|
|
[ 1, hashCount + 1 ],
|
|
{
|
|
"editColumn": hashCount + 1,
|
|
"insertText": " "
|
|
}
|
|
);
|
|
}
|
|
});
|
|
}
|
|
};
|