Update MD005/list-indent to fix ordered list violations (unordered are better handled by MD007) (fixes #246).

This commit is contained in:
David Anson 2020-01-15 22:06:41 -08:00
parent 5f6e17915a
commit 6553a13b6c
3 changed files with 67 additions and 9 deletions

View file

@ -17,15 +17,24 @@ module.exports = {
let actualEnd = -1;
let endMatching = false;
list.items.forEach((item) => {
const { line, lineNumber } = item;
const actualIndent = indentFor(item);
if (list.unordered) {
addErrorDetailIf(onError, item.lineNumber,
expectedIndent, actualIndent, null, null,
rangeFromRegExp(item.line, listItemMarkerRe));
addErrorDetailIf(
onError,
lineNumber,
expectedIndent,
actualIndent,
null,
null,
rangeFromRegExp(line, listItemMarkerRe)
// No fixInfo; MD007 handles this scenario better
);
} else {
const match = orderedListItemMarkerRe.exec(item.line);
actualEnd = match && match[0].length;
const match = orderedListItemMarkerRe.exec(line);
actualEnd = match[0].length;
expectedEnd = expectedEnd || actualEnd;
const markerLength = match[1].length + 1;
if ((expectedIndent !== actualIndent) || endMatching) {
if (expectedEnd === actualEnd) {
endMatching = true;
@ -33,8 +42,24 @@ module.exports = {
const detail = endMatching ?
`Expected: (${expectedEnd}); Actual: (${actualEnd})` :
`Expected: ${expectedIndent}; Actual: ${actualIndent}`;
addError(onError, item.lineNumber, detail, null,
rangeFromRegExp(item.line, listItemMarkerRe));
const expected = endMatching ?
expectedEnd - markerLength :
expectedIndent;
const actual = endMatching ?
actualEnd - markerLength :
actualIndent;
addError(
onError,
lineNumber,
detail,
null,
rangeFromRegExp(line, listItemMarkerRe),
{
"editColumn": Math.min(actual, expected) + 1,
"deleteCount": Math.max(actual - expected, 0),
"insertText": "".padEnd(Math.max(expected - actual, 0))
}
);
}
}
}

View file

@ -20,11 +20,11 @@ Text text
2. Two
3. Three
4. Four
5. Five
5. Five
6. Six
7. Seven
8. Eight
9. Nine
10. Ten
11. Eleven
11. Eleven
12. Twelve

View file

@ -94,3 +94,36 @@
12. Twelve
13. Thirteen {MD005}
14. Fourteen
## Leading Spaces Errors with Nesting
1. One
2. Two {MD005}
3. Three
1. One
2. Two
3. Three
4. Four
5. Five {MD005}
6. Six
7. Seven
8. Eight {MD005}
9. Nine
10. Ten
4. Four
5. Five {MD005}
6. Six
1. One
2. Two
3. Three {MD005}
4. Four
5. Five
6. Six
7. Seven {MD005}
8. Eight
9. Nine
10. Ten
7. Seven
8. Eight {MD005}
9. Nine
10. Ten