2019-04-17 14:42:17 -07:00
|
|
|
// @ts-check
|
|
|
|
|
2024-11-28 20:36:44 -08:00
|
|
|
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
|
|
|
import { filterByTypesCached } from "./cache.mjs";
|
2019-04-17 14:42:17 -07:00
|
|
|
|
|
|
|
const tokenTypeToStyle = {
|
2024-02-19 20:30:35 -08:00
|
|
|
"codeFenced": "fenced",
|
|
|
|
"codeIndented": "indented"
|
2019-04-17 14:42:17 -07:00
|
|
|
};
|
|
|
|
|
2024-12-03 19:58:28 -08:00
|
|
|
/** @type {import("markdownlint").Rule} */
|
2024-11-28 20:36:44 -08:00
|
|
|
export default {
|
2019-04-17 14:42:17 -07:00
|
|
|
"names": [ "MD046", "code-block-style" ],
|
|
|
|
"description": "Code block style",
|
|
|
|
"tags": [ "code" ],
|
2024-03-09 16:17:50 -08:00
|
|
|
"parser": "micromark",
|
2019-04-17 14:42:17 -07:00
|
|
|
"function": function MD046(params, onError) {
|
2020-01-25 18:40:39 -08:00
|
|
|
let expectedStyle = String(params.config.style || "consistent");
|
2024-08-24 22:05:16 -07:00
|
|
|
for (const token of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
|
2024-02-19 20:30:35 -08:00
|
|
|
const { startLine, type } = token;
|
2022-06-08 22:10:27 -07:00
|
|
|
if (expectedStyle === "consistent") {
|
|
|
|
expectedStyle = tokenTypeToStyle[type];
|
|
|
|
}
|
|
|
|
addErrorDetailIf(
|
|
|
|
onError,
|
2024-02-19 20:30:35 -08:00
|
|
|
startLine,
|
2022-06-08 22:10:27 -07:00
|
|
|
expectedStyle,
|
|
|
|
tokenTypeToStyle[type]);
|
|
|
|
}
|
2019-04-17 14:42:17 -07:00
|
|
|
}
|
|
|
|
};
|