-
-
Notifications
You must be signed in to change notification settings - Fork 752
/
Copy pathmd001.mjs
28 lines (26 loc) · 867 Bytes
/
md001.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// @ts-check
import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { getHeadingLevel } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD001", "heading-increment" ],
"description": "Heading levels should only increment by one level at a time",
"tags": [ "headings" ],
"parser": "micromark",
"function": function MD001(params, onError) {
let prevLevel = Number.MAX_SAFE_INTEGER;
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
const level = getHeadingLevel(heading);
if (level > prevLevel) {
addErrorDetailIf(
onError,
heading.startLine,
`h${prevLevel + 1}`,
`h${level}`
);
}
prevLevel = level;
}
}
};