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 { 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 {
|
2023-11-09 20:05:30 -08:00
|
|
|
"names": [ "MD023", "heading-start-left" ],
|
2018-03-19 23:39:42 +01:00
|
|
|
"description": "Headings must start at the beginning of the line",
|
2023-11-09 20:05:30 -08:00
|
|
|
"tags": [ "headings", "spaces" ],
|
2024-06-17 22:18:58 -07:00
|
|
|
"parser": "micromark",
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD023(params, onError) {
|
2024-08-24 22:05:16 -07:00
|
|
|
const headings = filterByTypesCached([ "atxHeading", "linePrefix", "setextHeading" ]);
|
2024-06-17 22:18:58 -07:00
|
|
|
for (let i = 0; i < headings.length - 1; i++) {
|
|
|
|
if (
|
|
|
|
(headings[i].type === "linePrefix") &&
|
|
|
|
(headings[i + 1].type !== "linePrefix") &&
|
|
|
|
(headings[i].startLine === headings[i + 1].startLine)
|
|
|
|
) {
|
|
|
|
const { endColumn, startColumn, startLine } = headings[i];
|
|
|
|
const length = endColumn - startColumn;
|
2019-09-02 15:35:43 -07:00
|
|
|
addErrorContext(
|
|
|
|
onError,
|
2024-06-17 22:18:58 -07:00
|
|
|
startLine,
|
|
|
|
params.lines[startLine - 1],
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
[ startColumn, length ],
|
2019-09-02 15:35:43 -07:00
|
|
|
{
|
2024-06-17 22:18:58 -07:00
|
|
|
"editColumn": startColumn,
|
|
|
|
"deleteCount": length
|
|
|
|
}
|
|
|
|
);
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
2024-06-17 22:18:58 -07:00
|
|
|
}
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
};
|