2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-09-08 16:51:00 -07:00
|
|
|
const { addErrorContext, forEachLine } = require("../helpers");
|
2019-04-10 21:26:59 -07:00
|
|
|
const { lineMetadata } = require("./cache");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD018", "no-missing-space-atx" ],
|
2018-03-19 23:39:42 +01:00
|
|
|
"description": "No space after hash on atx style heading",
|
2023-11-09 20:05:30 -08:00
|
|
|
"tags": [ "headings", "atx", "spaces" ],
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD018(params, onError) {
|
2019-04-10 21:26:59 -07:00
|
|
|
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
|
2020-03-08 19:49:52 -07:00
|
|
|
if (!inCode &&
|
2021-02-03 22:05:07 -08:00
|
|
|
/^#+[^# \t]/.test(line) &&
|
2020-03-08 19:49:52 -07:00
|
|
|
!/#\s*$/.test(line) &&
|
|
|
|
!line.startsWith("#️⃣")) {
|
2019-09-08 16:51:00 -07:00
|
|
|
const hashCount = /^#+/.exec(line)[0].length;
|
|
|
|
addErrorContext(
|
|
|
|
onError,
|
|
|
|
lineIndex + 1,
|
|
|
|
line.trim(),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
[ 1, hashCount + 1 ],
|
|
|
|
{
|
|
|
|
"editColumn": hashCount + 1,
|
|
|
|
"insertText": " "
|
|
|
|
}
|
|
|
|
);
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|