mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
31 lines
929 B
JavaScript
31 lines
929 B
JavaScript
// @ts-check
|
|
|
|
"use strict";
|
|
|
|
const { addErrorDetailIf } = require("../helpers");
|
|
const { getHeadingLevel } = require("../helpers/micromark-helpers.cjs");
|
|
const { filterByTypesCached } = require("./cache");
|
|
|
|
// eslint-disable-next-line jsdoc/valid-types
|
|
/** @type import("./markdownlint").Rule */
|
|
module.exports = {
|
|
"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;
|
|
}
|
|
}
|
|
};
|