MD007 shouldn't apply to sublists of ordered lists, test and document MD006 behavior (fixes #20).

This commit is contained in:
David Anson 2016-06-26 11:56:48 -07:00
parent 83639b8ef8
commit efe9c9e73c
3 changed files with 97 additions and 8 deletions

View file

@ -121,7 +121,9 @@ function flattenLists(params) {
// Save current context and start a new one
stack.push(current);
current = {
"ordered": (token.type === "ordered_list_open"),
"unordered": (token.type === "bullet_list_open"),
"parentsUnordered": !current ||
(current.unordered && current.parentsUnordered),
"open": token,
"items": [],
"nesting": stack.length - 1,
@ -223,7 +225,7 @@ module.exports = [
"func": function MD004(params, errors) {
var style = params.options.style || "consistent";
flattenLists(params).forEach(function forList(list) {
if (!list.ordered) {
if (list.unordered) {
if (style === "consistent") {
style = unorderedListStyleFor(list.items[0]);
}
@ -261,7 +263,7 @@ module.exports = [
"aliases": [ "ul-start-left" ],
"func": function MD006(params, errors) {
flattenLists(params).forEach(function forList(list) {
if (!list.ordered && !list.nesting && indentFor(list.open)) {
if (list.unordered && !list.nesting && indentFor(list.open)) {
errors.push(list.open.lineNumber);
}
});
@ -277,7 +279,7 @@ module.exports = [
var optionsIndent = params.options.indent || 2;
var prevIndent = 0;
flattenLists(params).forEach(function forList(list) {
if (!list.ordered) {
if (list.unordered && list.parentsUnordered) {
var indent = indentFor(list.open);
if ((indent > prevIndent) &&
((indent - prevIndent) !== optionsIndent)) {
@ -602,7 +604,7 @@ module.exports = [
"func": function MD029(params, errors) {
var style = params.options.style || "one";
flattenLists(params).forEach(function forList(list) {
if (list.ordered) {
if (!list.unordered) {
var number = 1;
list.items.forEach(function forItem(item) {
var re = new RegExp("^\\s*" + String(number) + "\\.");
@ -631,9 +633,9 @@ module.exports = [
flattenLists(params).forEach(function forList(list) {
var lineCount = list.lastLineIndex - list.open.map[0];
var allSingle = lineCount === list.items.length;
var expectedSpaces = list.ordered ?
(allSingle ? olSingle : olMulti) :
(allSingle ? ulSingle : ulMulti);
var expectedSpaces = list.unordered ?
(allSingle ? ulSingle : ulMulti) :
(allSingle ? olSingle : olMulti);
list.items.forEach(function forItem(item) {
var match = /^\s*\S+(\s+)/.exec(item.line);
if (!match || (match[1].length !== expectedSpaces)) {