Add "sublist" style to MD004 (fixes #21).

This commit is contained in:
David Anson 2016-07-04 14:32:40 -07:00
parent c8ecec1953
commit 7a1773ea77
4 changed files with 91 additions and 7 deletions

View file

@ -224,13 +224,24 @@ module.exports = [
"aliases": [ "ul-style" ],
"func": function MD004(params, errors) {
var style = params.options.style || "consistent";
var expectedStyle = style;
var nestingStyles = [];
flattenLists(params).forEach(function forList(list) {
if (list.unordered) {
if (style === "consistent") {
style = unorderedListStyleFor(list.items[0]);
if (expectedStyle === "consistent") {
expectedStyle = unorderedListStyleFor(list.items[0]);
}
list.items.forEach(function forItem(item) {
if (unorderedListStyleFor(item) !== style) {
var itemStyle = unorderedListStyleFor(item);
if (style === "sublist") {
var nesting = list.nesting;
if (!nestingStyles[nesting] &&
(itemStyle !== nestingStyles[nesting - 1])) {
nestingStyles[nesting] = itemStyle;
} else if (itemStyle !== nestingStyles[nesting]) {
errors.push(item.lineNumber);
}
} else if (itemStyle !== expectedStyle) {
errors.push(item.lineNumber);
}
});