forked from DavidAnson/markdownlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd046.js
33 lines (29 loc) · 855 Bytes
/
md046.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// @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 = String(params.config.style || "consistent");
const codeBlocksAndFences = params.tokens.filter(
(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]);
}
}
};