Implement rule MD046/code-block-style from Ruby version.

This commit is contained in:
David Anson 2019-04-17 14:42:17 -07:00
parent c45eead5d7
commit 0af999e218
24 changed files with 236 additions and 19 deletions

32
lib/md046.js Normal file
View file

@ -0,0 +1,32 @@
// @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) {
let expectedStyle = params.config.style || "consistent";
params.tokens
.filter((token) => token.type === "code_block" || token.type === "fence")
.forEach((token) => {
const { lineNumber, type } = token;
if (expectedStyle === "consistent") {
expectedStyle = tokenTypeToStyle[type];
}
addErrorDetailIf(
onError,
lineNumber,
expectedStyle,
tokenTypeToStyle[type]);
});
}
};