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

@ -167,6 +167,16 @@ or the tab key is used to indent. Starting a list 1 space in means that the
indent of the first nested list is less than the indent of the second level (3 indent of the first nested list is less than the indent of the second level (3
characters if you use 4 space tabs, or 1 character if you use 2 space tabs). characters if you use 4 space tabs, or 1 character if you use 2 space tabs).
Note: This rule is triggered for the following scenario because the unordered
sublist is not recognized as such by the parser. Not being nested 3 characters
as required by the outer ordered list, it creates a top-level unordered list
instead.
1. List item
- List item
- List item
1. List item
## MD007 - Unordered list indentation ## MD007 - Unordered list indentation
Tags: bullet, ul, indentation Tags: bullet, ul, indentation
@ -202,6 +212,10 @@ require a 4 space indents. See
<http://support.markedapp.com/discussions/problems/21-sub-lists-not-indenting> <http://support.markedapp.com/discussions/problems/21-sub-lists-not-indenting>
for a description of the problem. for a description of the problem.
Note: This rule applies to a sublist only if its parent lists are all also
unordered (otherwise, extra indentation of ordered lists interferes with the
rule).
## MD009 - Trailing spaces ## MD009 - Trailing spaces
Tags: whitespace Tags: whitespace

View file

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

View file

@ -0,0 +1,73 @@
# Heading
## Excessive nesting
- one
1. two
1. three
- four
1. one
- two
- three
1. four
## Insufficient nesting
- one
1. two
1. three
- four
1. one
- two {MD006}
- three
1. four
## Correct nesting, same type
- one
- two
- three
- four
1. one
1. two
1. three
1. four
## Correct nesting, different types
- one
1. two
1. three
- four
1. one
- two
- three
1. four
1. one
- two
- three
- one
1. two
- three
- one
- two
1. three
1. one
1. two
- three
1. one
- two
1. three
- one
1. two
1. three