-
-
Notifications
You must be signed in to change notification settings - Fork 757
/
Copy pathmd030.js
50 lines (47 loc) · 1.62 KB
/
md030.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
44
45
46
47
48
49
50
// @ts-check
"use strict";
const { addErrorDetailIf } = require("../helpers");
const { flattenedLists } = require("./cache");
module.exports = {
"names": [ "MD030", "list-marker-space" ],
"description": "Spaces after list markers",
"tags": [ "ol", "ul", "whitespace" ],
"function": function MD030(params, onError) {
const ulSingle = Number(params.config.ul_single || 1);
const olSingle = Number(params.config.ol_single || 1);
const ulMulti = Number(params.config.ul_multi || 1);
const olMulti = Number(params.config.ol_multi || 1);
for (const list of flattenedLists()) {
const lineCount = list.lastLineIndex - list.open.map[0];
const allSingle = lineCount === list.items.length;
const expectedSpaces = list.unordered ?
(allSingle ? ulSingle : ulMulti) :
(allSingle ? olSingle : olMulti);
for (const item of list.items) {
const { line, lineNumber } = item;
const match = /^[\s>]*\S+(\s*)/.exec(line);
const [ { "length": matchLength }, { "length": actualSpaces } ] = match;
if (matchLength < line.length) {
let fixInfo = null;
if (expectedSpaces !== actualSpaces) {
fixInfo = {
"editColumn": matchLength - actualSpaces + 1,
"deleteCount": actualSpaces,
"insertText": "".padEnd(expectedSpaces)
};
}
addErrorDetailIf(
onError,
lineNumber,
expectedSpaces,
actualSpaces,
null,
null,
[ 1, matchLength ],
fixInfo
);
}
}
}
}
};