2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const shared = require("./shared");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2018-01-31 21:32:50 -08:00
|
|
|
// Returns the unordered list style for a list item token
|
|
|
|
function unorderedListStyleFor(token) {
|
|
|
|
switch (token.markup) {
|
|
|
|
case "-":
|
|
|
|
return "dash";
|
|
|
|
case "+":
|
|
|
|
return "plus";
|
|
|
|
// case "*":
|
|
|
|
default:
|
|
|
|
return "asterisk";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-21 21:44:25 -08:00
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD004", "ul-style" ],
|
|
|
|
"description": "Unordered list style",
|
|
|
|
"tags": [ "bullet", "ul" ],
|
|
|
|
"function": function MD004(params, onError) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const style = params.config.style || "consistent";
|
|
|
|
let expectedStyle = style;
|
|
|
|
const nestingStyles = [];
|
2018-03-04 23:06:31 -08:00
|
|
|
shared.flattenLists().forEach(function forList(list) {
|
2018-01-21 21:44:25 -08:00
|
|
|
if (list.unordered) {
|
|
|
|
if (expectedStyle === "consistent") {
|
2018-01-31 21:32:50 -08:00
|
|
|
expectedStyle = unorderedListStyleFor(list.items[0]);
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
list.items.forEach(function forItem(item) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const itemStyle = unorderedListStyleFor(item);
|
2018-01-21 21:44:25 -08:00
|
|
|
if (style === "sublist") {
|
2018-04-27 22:05:34 -07:00
|
|
|
const nesting = list.nesting;
|
2018-01-21 21:44:25 -08:00
|
|
|
if (!nestingStyles[nesting] &&
|
|
|
|
(itemStyle !== nestingStyles[nesting - 1])) {
|
|
|
|
nestingStyles[nesting] = itemStyle;
|
|
|
|
} else {
|
|
|
|
shared.addErrorDetailIf(onError, item.lineNumber,
|
2019-03-24 21:50:56 -07:00
|
|
|
nestingStyles[nesting], itemStyle, null, null,
|
2018-01-21 21:44:25 -08:00
|
|
|
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
shared.addErrorDetailIf(onError, item.lineNumber,
|
2019-03-24 21:50:56 -07:00
|
|
|
expectedStyle, itemStyle, null, null,
|
2018-01-21 21:44:25 -08:00
|
|
|
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|