2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2024-08-17 17:58:16 -07:00
|
|
|
const { addErrorContext } = require("../helpers");
|
2024-08-24 22:05:16 -07:00
|
|
|
const { addRangeToSet } = require("../helpers/micromark.cjs");
|
|
|
|
const { filterByTypesCached } = require("./cache");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2024-02-27 20:42:09 -08:00
|
|
|
// eslint-disable-next-line jsdoc/valid-types
|
|
|
|
/** @type import("./markdownlint").Rule */
|
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" ],
|
2024-08-17 17:58:16 -07:00
|
|
|
"parser": "micromark",
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD018(params, onError) {
|
2024-08-24 22:05:16 -07:00
|
|
|
const { lines } = params;
|
2024-08-17 17:58:16 -07:00
|
|
|
const ignoreBlockLineNumbers = new Set();
|
2024-08-24 22:05:16 -07:00
|
|
|
for (const ignoreBlock of filterByTypesCached([ "codeFenced", "codeIndented", "htmlFlow" ])) {
|
2024-08-17 17:58:16 -07:00
|
|
|
addRangeToSet(ignoreBlockLineNumbers, ignoreBlock.startLine, ignoreBlock.endLine);
|
|
|
|
}
|
|
|
|
for (const [ lineIndex, line ] of lines.entries()) {
|
|
|
|
if (
|
|
|
|
!ignoreBlockLineNumbers.has(lineIndex + 1) &&
|
2021-02-03 22:05:07 -08:00
|
|
|
/^#+[^# \t]/.test(line) &&
|
2020-03-08 19:49:52 -07:00
|
|
|
!/#\s*$/.test(line) &&
|
2024-08-17 17:58:16 -07:00
|
|
|
!line.startsWith("#️⃣")
|
|
|
|
) {
|
2024-02-27 20:42:09 -08:00
|
|
|
// @ts-ignore
|
2019-09-08 16:51:00 -07:00
|
|
|
const hashCount = /^#+/.exec(line)[0].length;
|
|
|
|
addErrorContext(
|
|
|
|
onError,
|
|
|
|
lineIndex + 1,
|
|
|
|
line.trim(),
|
2024-08-17 17:58:16 -07:00
|
|
|
undefined,
|
|
|
|
undefined,
|
2019-09-08 16:51:00 -07:00
|
|
|
[ 1, hashCount + 1 ],
|
|
|
|
{
|
|
|
|
"editColumn": hashCount + 1,
|
|
|
|
"insertText": " "
|
|
|
|
}
|
|
|
|
);
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
2024-08-17 17:58:16 -07:00
|
|
|
}
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
};
|