mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Implement rule MD046/code-block-style from Ruby version.
This commit is contained in:
parent
c45eead5d7
commit
0af999e218
24 changed files with 236 additions and 19 deletions
32
lib/md046.js
Normal file
32
lib/md046.js
Normal 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]);
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue