forked from DavidAnson/markdownlint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmd001.js
More file actions
22 lines (19 loc) · 690 Bytes
/
md001.js
File metadata and controls
22 lines (19 loc) · 690 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// @ts-check
"use strict";
const { addErrorDetailIf, filterTokens } = require("../helpers");
module.exports = {
"names": [ "MD001", "heading-increment", "header-increment" ],
"description": "Heading levels should only increment by one level at a time",
"tags": [ "headings", "headers" ],
"function": function MD001(params, onError) {
let prevLevel = 0;
filterTokens(params, "heading_open", function forToken(token) {
const level = Number.parseInt(token.tag.slice(1), 10);
if (prevLevel && (level > prevLevel)) {
addErrorDetailIf(onError, token.lineNumber,
"h" + (prevLevel + 1), "h" + level);
}
prevLevel = level;
});
}
};