mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-21 21:30:47 +02:00
Update MD007/ul-indent to report/fix for all unordered list item groupings.
This commit is contained in:
parent
3981bc7897
commit
3e91da338c
9 changed files with 143 additions and 37 deletions
|
@ -22,7 +22,7 @@ module.exports.inlineCommentRe = inlineCommentRe;
|
|||
|
||||
// Regular expressions for range matching
|
||||
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+)[.)]/;
|
||||
|
||||
// readFile options for reading with the UTF-8 encoding
|
||||
|
|
32
lib/md007.js
32
lib/md007.js
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addErrorDetailIf, listItemMarkerRe, rangeFromRegExp } =
|
||||
const { addErrorDetailIf, indentFor, listItemMarkerRe } =
|
||||
require("../helpers");
|
||||
const { flattenedLists } = require("./cache");
|
||||
|
||||
|
@ -13,10 +13,32 @@ module.exports = {
|
|||
"function": function MD007(params, onError) {
|
||||
const optionsIndent = params.config.indent || 2;
|
||||
flattenedLists().forEach((list) => {
|
||||
if (list.unordered && list.parentsUnordered && list.indent) {
|
||||
addErrorDetailIf(onError, list.open.lineNumber,
|
||||
list.parentIndent + optionsIndent, list.indent, null, null,
|
||||
rangeFromRegExp(list.open.line, listItemMarkerRe));
|
||||
if (list.unordered && list.parentsUnordered) {
|
||||
list.items.forEach((item) => {
|
||||
const { lineNumber, line } = item;
|
||||
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)
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,30 +1,59 @@
|
|||
# Bulleted List Not at Beginning of Line
|
||||
|
||||
Some text
|
||||
Text
|
||||
|
||||
* Item {MD006}
|
||||
* Item
|
||||
* Item
|
||||
* Item
|
||||
* Item
|
||||
* Item
|
||||
* Item
|
||||
* Item
|
||||
* Item {MD006}
|
||||
* Item {MD006}
|
||||
* Item
|
||||
* Item
|
||||
* Item
|
||||
|
||||
Some more text
|
||||
Text
|
||||
|
||||
* Item {MD006}
|
||||
* Item
|
||||
* Item {MD006} {MD007}
|
||||
* Item {MD007}
|
||||
* Item {MD007}
|
||||
* Item {MD007}
|
||||
* Item {MD007}
|
||||
* Item {MD006} {MD007}
|
||||
* Item {MD006} {MD007}
|
||||
|
||||
Text
|
||||
|
||||
* Item
|
||||
* Item
|
||||
|
||||
Text
|
||||
|
||||
* Item {MD006} {MD007}
|
||||
* Item {MD007}
|
||||
|
||||
Text
|
||||
|
||||
* Item
|
||||
* Item
|
||||
* Item
|
||||
|
||||
Text
|
||||
|
||||
* Item {MD006} {MD007}
|
||||
* Item {MD006}
|
||||
* Item {MD006}
|
||||
* Item {MD006} {MD007}
|
||||
* Item {MD006} {MD007}
|
||||
|
||||
Text
|
||||
|
||||
* Item {MD006}
|
||||
* Item
|
||||
|
||||
* Item {MD006}
|
||||
* Item
|
||||
|
||||
* Item {MD006}
|
||||
* Item
|
||||
|
||||
Text
|
||||
|
||||
* Item {MD006} {MD007}
|
||||
|
||||
* Item {MD006} {MD007}
|
||||
|
||||
* Item {MD006} {MD007}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
### Three ###
|
||||
|
||||
* Alpha
|
||||
* Bravo
|
||||
* Bravo
|
||||
|
||||
- Charlie
|
||||
|
||||
|
|
|
@ -80,12 +80,30 @@
|
|||
"errorContext": null,
|
||||
"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,
|
||||
"ruleNames": [ "MD007", "ul-indent" ],
|
||||
"ruleDescription": "Unordered list indentation",
|
||||
"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,
|
||||
"errorRange": [1, 3]
|
||||
},
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
# Inconsistent Bullet Indent Same Level
|
||||
|
||||
* Item
|
||||
* Item {MD007}
|
||||
* Item {MD005}
|
||||
* Item {MD007}
|
||||
* Item
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# list-indentation
|
||||
# List Indentation
|
||||
|
||||
Text
|
||||
|
||||
|
@ -25,22 +25,22 @@ Text
|
|||
|
||||
- Item
|
||||
- Item
|
||||
- Item {MD005}
|
||||
- Item {MD005} {MD007}
|
||||
- Item
|
||||
- Item {MD005}
|
||||
- Item {MD005}
|
||||
- Item {MD005} {MD007}
|
||||
- Item {MD005} {MD007}
|
||||
- Item
|
||||
- Item
|
||||
- Item
|
||||
- Item {MD005}
|
||||
- Item {MD005} {MD007}
|
||||
- Item
|
||||
- Item
|
||||
- Item {MD007}
|
||||
- Item
|
||||
- Item
|
||||
- Item {MD007}
|
||||
- Item {MD007}
|
||||
- Item
|
||||
- Item {MD007}
|
||||
- Item
|
||||
- Item {MD007}
|
||||
- Item {MD005}
|
||||
|
||||
Text
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Lists in blockquote
|
||||
# Lists in Blockquote
|
||||
|
||||
> 1. The simplest ordered list in blockquote
|
||||
|
||||
|
@ -64,8 +64,19 @@ Text
|
|||
> * Item {MD004}
|
||||
> * Item {MD004}
|
||||
> * Item {MD004} {MD030}
|
||||
> * Item {MD004} {MD005}
|
||||
> * Item {MD004} {MD005}
|
||||
> * Item {MD004} {MD005} {MD007}
|
||||
> * 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
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Heading
|
||||
# Lists with Nesting
|
||||
|
||||
## Excessive nesting
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
|||
- three {MD032}
|
||||
|
||||
1. one {MD032}
|
||||
- two {MD006} {MD032}
|
||||
- two {MD006} {MD007} {MD032}
|
||||
1. three {MD032}
|
||||
|
||||
## Correct nesting, same type
|
||||
|
@ -28,11 +28,17 @@
|
|||
- two
|
||||
- three
|
||||
- four
|
||||
- five
|
||||
- six
|
||||
- seven
|
||||
|
||||
1. one
|
||||
1. two
|
||||
1. three
|
||||
1. four
|
||||
1. five
|
||||
1. six
|
||||
1. seven
|
||||
|
||||
## Correct nesting, different types
|
||||
|
||||
|
@ -69,3 +75,21 @@
|
|||
- one
|
||||
1. two
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue