2019-04-17 14:42:17 -07:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const { addErrorDetailIf } = require("../helpers");
|
|
|
|
|
|
|
|
const tokenTypeToStyle = {
|
|
|
|
"fence": "fenced",
|
|
|
|
"code_block": "indented"
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD046", "code-block-style" ],
|
|
|
|
"description": "Code block style",
|
|
|
|
"tags": [ "code" ],
|
|
|
|
"function": function MD046(params, onError) {
|
2020-01-25 18:40:39 -08:00
|
|
|
let expectedStyle = String(params.config.style || "consistent");
|
2023-02-18 21:41:07 -08:00
|
|
|
const codeBlocksAndFences = params.parsers.markdownit.tokens.filter(
|
2022-06-08 22:10:27 -07:00
|
|
|
(token) => (token.type === "code_block") || (token.type === "fence")
|
|
|
|
);
|
|
|
|
for (const token of codeBlocksAndFences) {
|
|
|
|
const { lineNumber, type } = token;
|
|
|
|
if (expectedStyle === "consistent") {
|
|
|
|
expectedStyle = tokenTypeToStyle[type];
|
|
|
|
}
|
|
|
|
addErrorDetailIf(
|
|
|
|
onError,
|
|
|
|
lineNumber,
|
|
|
|
expectedStyle,
|
|
|
|
tokenTypeToStyle[type]);
|
|
|
|
}
|
2019-04-17 14:42:17 -07:00
|
|
|
}
|
|
|
|
};
|