forked from DavidAnson/markdownlint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmd022.js
More file actions
56 lines (53 loc) · 1.59 KB
/
Copy pathmd022.js
File metadata and controls
56 lines (53 loc) · 1.59 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
// @ts-check
"use strict";
const { addErrorDetailIf, filterTokens, isBlankLine } = require("../helpers");
module.exports = {
"names": [ "MD022", "blanks-around-headings", "blanks-around-headers" ],
"description": "Headings should be surrounded by blank lines",
"tags": [ "headings", "headers", "blank_lines" ],
"function": function MD022(params, onError) {
let linesAbove = params.config.lines_above;
linesAbove = Number((linesAbove === undefined) ? 1 : linesAbove);
let linesBelow = params.config.lines_below;
linesBelow = Number((linesBelow === undefined) ? 1 : linesBelow);
const { lines } = params;
filterTokens(params, "heading_open", (token) => {
const [ topIndex, nextIndex ] = token.map;
let actualAbove = 0;
for (let i = 0; i < linesAbove; i++) {
if (isBlankLine(lines[topIndex - i - 1])) {
actualAbove++;
}
}
addErrorDetailIf(
onError,
topIndex + 1,
linesAbove,
actualAbove,
"Above",
lines[topIndex].trim(),
null,
{
"insertText": "".padEnd(linesAbove - actualAbove, "\n")
});
let actualBelow = 0;
for (let i = 0; i < linesBelow; i++) {
if (isBlankLine(lines[nextIndex + i])) {
actualBelow++;
}
}
addErrorDetailIf(
onError,
topIndex + 1,
linesBelow,
actualBelow,
"Below",
lines[topIndex].trim(),
null,
{
"lineNumber": nextIndex + 1,
"insertText": "".padEnd(linesBelow - actualBelow, "\n")
});
});
}
};