Update MD007/ul-indent to report/fix for all unordered list item groupings.

This commit is contained in:
David Anson 2019-12-01 17:30:47 -08:00
parent 3981bc7897
commit 3e91da338c
9 changed files with 143 additions and 37 deletions

View file

@ -22,7 +22,7 @@ module.exports.inlineCommentRe = inlineCommentRe;
// Regular expressions for range matching // Regular expressions for range matching
module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s]*/ig; module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s]*/ig;
module.exports.listItemMarkerRe = /^[\s>]*(?:[*+-]|\d+[.)])\s+/; module.exports.listItemMarkerRe = /^([\s>]*)(?:[*+-]|\d+[.)])\s+/;
module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/; module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/;
// readFile options for reading with the UTF-8 encoding // readFile options for reading with the UTF-8 encoding

View file

@ -2,7 +2,7 @@
"use strict"; "use strict";
const { addErrorDetailIf, listItemMarkerRe, rangeFromRegExp } = const { addErrorDetailIf, indentFor, listItemMarkerRe } =
require("../helpers"); require("../helpers");
const { flattenedLists } = require("./cache"); const { flattenedLists } = require("./cache");
@ -13,10 +13,32 @@ module.exports = {
"function": function MD007(params, onError) { "function": function MD007(params, onError) {
const optionsIndent = params.config.indent || 2; const optionsIndent = params.config.indent || 2;
flattenedLists().forEach((list) => { flattenedLists().forEach((list) => {
if (list.unordered && list.parentsUnordered && list.indent) { if (list.unordered && list.parentsUnordered) {
addErrorDetailIf(onError, list.open.lineNumber, list.items.forEach((item) => {
list.parentIndent + optionsIndent, list.indent, null, null, const { lineNumber, line } = item;
rangeFromRegExp(list.open.line, listItemMarkerRe)); const expectedIndent = list.nesting * optionsIndent;
const actualIndent = indentFor(item);
let range = null;
let editColumn = 1;
const match = line.match(listItemMarkerRe);
if (match) {
range = [ 1, match[0].length ];
editColumn += match[1].length - actualIndent;
}
addErrorDetailIf(
onError,
lineNumber,
expectedIndent,
actualIndent,
null,
null,
range,
{
editColumn,
"deleteCount": actualIndent,
"insertText": "".padEnd(expectedIndent)
});
});
} }
}); });
} }

View file

@ -1,30 +1,59 @@
# Bulleted List Not at Beginning of Line # Bulleted List Not at Beginning of Line
Some text Text
* Item {MD006}
* Item * Item
* Item * Item
* Item * Item
* Item * Item
* Item {MD006} * Item
* Item {MD006} * Item
Some more text
* Item {MD006}
* Item * Item
Text Text
* Item {MD006} {MD007} * Item {MD006} {MD007}
* Item {MD006} * Item {MD007}
* Item {MD006} * Item {MD007}
* Item {MD007}
* Item {MD007}
* Item {MD006} {MD007}
* Item {MD006} {MD007}
Text Text
* Item {MD006} * Item
* Item
* Item {MD006} Text
* Item {MD006} * Item {MD006} {MD007}
* Item {MD007}
Text
* Item
* Item
* Item
Text
* Item {MD006} {MD007}
* Item {MD006} {MD007}
* Item {MD006} {MD007}
Text
* Item
* Item
* Item
Text
* Item {MD006} {MD007}
* Item {MD006} {MD007}
* Item {MD006} {MD007}

View file

@ -80,12 +80,30 @@
"errorContext": null, "errorContext": null,
"errorRange": [1, 3] "errorRange": [1, 3]
}, },
{
"lineNumber": 8,
"ruleNames": [ "MD007", "ul-indent" ],
"ruleDescription": "Unordered list indentation",
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md007",
"errorDetail": "Expected: 0; Actual: 1",
"errorContext": null,
"errorRange": [1, 3]
},
{ {
"lineNumber": 12, "lineNumber": 12,
"ruleNames": [ "MD007", "ul-indent" ], "ruleNames": [ "MD007", "ul-indent" ],
"ruleDescription": "Unordered list indentation", "ruleDescription": "Unordered list indentation",
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md007", "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md007",
"errorDetail": "Expected: 2; Actual: 1", "errorDetail": "Expected: 0; Actual: 1",
"errorContext": null,
"errorRange": [1, 3]
},
{
"lineNumber": 13,
"ruleNames": [ "MD007", "ul-indent" ],
"ruleDescription": "Unordered list indentation",
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md007",
"errorDetail": "Expected: 0; Actual: 1",
"errorContext": null, "errorContext": null,
"errorRange": [1, 3] "errorRange": [1, 3]
}, },

View file

@ -1,4 +1,6 @@
# Inconsistent Bullet Indent Same Level
* Item * Item
* Item {MD007} * Item {MD007}
* Item {MD005} * Item {MD005}
* Item {MD007} * Item

View file

@ -1,4 +1,4 @@
# list-indentation # List Indentation
Text Text
@ -25,22 +25,22 @@ Text
- Item - Item
- Item - Item
- Item {MD005} - Item {MD005} {MD007}
- Item - Item
- Item {MD005} - Item {MD005} {MD007}
- Item {MD005} - Item {MD005} {MD007}
- Item - Item
- Item - Item
- Item - Item
- Item {MD005} - Item {MD005} {MD007}
- Item - Item
- Item - Item
- Item {MD007} - Item {MD007}
- Item - Item {MD007}
- Item
- Item
- Item {MD007} - Item {MD007}
- Item - Item
- Item {MD007}
- Item {MD007}
- Item {MD005} - Item {MD005}
Text Text

View file

@ -1,4 +1,4 @@
# Lists in blockquote # Lists in Blockquote
> 1. The simplest ordered list in blockquote > 1. The simplest ordered list in blockquote
@ -64,8 +64,19 @@ Text
> * Item {MD004} > * Item {MD004}
> * Item {MD004} > * Item {MD004}
> * Item {MD004} {MD030} > * Item {MD004} {MD030}
> * Item {MD004} {MD005} > * Item {MD004} {MD005} {MD007}
> * Item {MD004} {MD005} > * Item {MD004} {MD005} {MD007}
> * Item {MD004}
> * Item {MD004}
> * Item {MD004}
> * Item {MD004} {MD005} {MD007}
Text
> > * Item {MD004}
> > * Item {MD004}
> > * Item {MD004} {MD030}
> > * Item {MD004} {MD005} {MD007}
Text Text

View file

@ -1,4 +1,4 @@
# Heading # Lists with Nesting
## Excessive nesting ## Excessive nesting
@ -19,7 +19,7 @@
- three {MD032} - three {MD032}
1. one {MD032} 1. one {MD032}
- two {MD006} {MD032} - two {MD006} {MD007} {MD032}
1. three {MD032} 1. three {MD032}
## Correct nesting, same type ## Correct nesting, same type
@ -28,11 +28,17 @@
- two - two
- three - three
- four - four
- five
- six
- seven
1. one 1. one
1. two 1. two
1. three 1. three
1. four 1. four
1. five
1. six
1. seven
## Correct nesting, different types ## Correct nesting, different types
@ -69,3 +75,21 @@
- one - one
1. two 1. two
1. three 1. three
- one
1. two
- three
1. four
- five
1. six
- seven
1. eight
1. one
- two
1. three
- four
1. five
- six
1. seven
- eight