mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD005/list-indent to fix ordered list violations (unordered are better handled by MD007) (fixes #246).
This commit is contained in:
parent
5f6e17915a
commit
6553a13b6c
3 changed files with 67 additions and 9 deletions
39
lib/md005.js
39
lib/md005.js
|
@ -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))
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue