2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
2024-11-28 20:36:44 -08:00
|
|
|
import { addErrorContext } from "../helpers/helpers.cjs";
|
|
|
|
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
|
|
|
|
import { filterByTypesCached } from "./cache.mjs";
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2024-12-03 19:58:28 -08:00
|
|
|
/** @type {import("markdownlint").Rule} */
|
2024-11-28 20:36:44 -08:00
|
|
|
export default {
|
2018-01-21 21:44:25 -08:00
|
|
|
"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
|
|
|
}
|
|
|
|
};
|