mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +01: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
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)
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue