-
-
Notifications
You must be signed in to change notification settings - Fork 733
/
md012.js
43 lines (40 loc) · 1.29 KB
/
md012.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
34
35
36
37
38
39
40
41
42
43
// @ts-check
"use strict";
const { addErrorDetailIf } = require("../helpers");
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD012", "no-multiple-blanks" ],
"description": "Multiple consecutive blank lines",
"tags": [ "whitespace", "blank_lines" ],
"parser": "micromark",
"function": function MD012(params, onError) {
const maximum = Number(params.config.maximum || 1);
const { lines } = params;
const codeBlockLineNumbers = new Set();
for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
}
let count = 0;
for (const [ lineIndex, line ] of lines.entries()) {
const inCode = codeBlockLineNumbers.has(lineIndex + 1);
count = (inCode || (line.trim().length > 0)) ? 0 : count + 1;
if (maximum < count) {
addErrorDetailIf(
onError,
lineIndex + 1,
maximum,
count,
undefined,
undefined,
undefined,
{
"deleteCount": -1
}
);
}
}
}
};