-
-
Notifications
You must be signed in to change notification settings - Fork 730
/
md004.js
76 lines (72 loc) · 2.14 KB
/
md004.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// @ts-check
"use strict";
const { addErrorDetailIf, listItemMarkerRe, unorderedListStyleFor } =
require("../helpers");
const { flattenedLists } = require("./cache");
const expectedStyleToMarker = {
"dash": "-",
"plus": "+",
"asterisk": "*"
};
const differentItemStyle = {
"dash": "plus",
"plus": "asterisk",
"asterisk": "dash"
};
const validStyles = Object.keys(expectedStyleToMarker);
module.exports = {
"names": [ "MD004", "ul-style" ],
"description": "Unordered list style",
"tags": [ "bullet", "ul" ],
"function": function MD004(params, onError) {
const style = String(params.config.style || "consistent");
let expectedStyle = style;
const nestingStyles = [];
for (const list of flattenedLists()) {
if (list.unordered) {
if (expectedStyle === "consistent") {
expectedStyle = unorderedListStyleFor(list.items[0]);
}
for (const item of list.items) {
const itemStyle = unorderedListStyleFor(item);
if (style === "sublist") {
const nesting = list.nesting;
if (!nestingStyles[nesting]) {
nestingStyles[nesting] =
(itemStyle === nestingStyles[nesting - 1]) ?
differentItemStyle[itemStyle] :
itemStyle;
}
expectedStyle = nestingStyles[nesting];
}
if (!validStyles.includes(expectedStyle)) {
expectedStyle = validStyles[0];
}
let range = null;
let fixInfo = null;
const match = item.line.match(listItemMarkerRe);
if (match) {
const column = match.index + 1;
const length = match[0].length;
range = [ column, length ];
fixInfo = {
"editColumn": match[1].length + 1,
"deleteCount": 1,
"insertText": expectedStyleToMarker[expectedStyle]
};
}
addErrorDetailIf(
onError,
item.lineNumber,
expectedStyle,
itemStyle,
null,
null,
range,
fixInfo
);
}
}
}
}
};