mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 05:50:13 +01: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 actualEnd = -1;
|
||||||
let endMatching = false;
|
let endMatching = false;
|
||||||
list.items.forEach((item) => {
|
list.items.forEach((item) => {
|
||||||
|
const { line, lineNumber } = item;
|
||||||
const actualIndent = indentFor(item);
|
const actualIndent = indentFor(item);
|
||||||
if (list.unordered) {
|
if (list.unordered) {
|
||||||
addErrorDetailIf(onError, item.lineNumber,
|
addErrorDetailIf(
|
||||||
expectedIndent, actualIndent, null, null,
|
onError,
|
||||||
rangeFromRegExp(item.line, listItemMarkerRe));
|
lineNumber,
|
||||||
|
expectedIndent,
|
||||||
|
actualIndent,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
rangeFromRegExp(line, listItemMarkerRe)
|
||||||
|
// No fixInfo; MD007 handles this scenario better
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
const match = orderedListItemMarkerRe.exec(item.line);
|
const match = orderedListItemMarkerRe.exec(line);
|
||||||
actualEnd = match && match[0].length;
|
actualEnd = match[0].length;
|
||||||
expectedEnd = expectedEnd || actualEnd;
|
expectedEnd = expectedEnd || actualEnd;
|
||||||
|
const markerLength = match[1].length + 1;
|
||||||
if ((expectedIndent !== actualIndent) || endMatching) {
|
if ((expectedIndent !== actualIndent) || endMatching) {
|
||||||
if (expectedEnd === actualEnd) {
|
if (expectedEnd === actualEnd) {
|
||||||
endMatching = true;
|
endMatching = true;
|
||||||
|
|
@ -33,8 +42,24 @@ module.exports = {
|
||||||
const detail = endMatching ?
|
const detail = endMatching ?
|
||||||
`Expected: (${expectedEnd}); Actual: (${actualEnd})` :
|
`Expected: (${expectedEnd}); Actual: (${actualEnd})` :
|
||||||
`Expected: ${expectedIndent}; Actual: ${actualIndent}`;
|
`Expected: ${expectedIndent}; Actual: ${actualIndent}`;
|
||||||
addError(onError, item.lineNumber, detail, null,
|
const expected = endMatching ?
|
||||||
rangeFromRegExp(item.line, listItemMarkerRe));
|
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
|
2. Two
|
||||||
3. Three
|
3. Three
|
||||||
4. Four
|
4. Four
|
||||||
5. Five
|
5. Five
|
||||||
6. Six
|
6. Six
|
||||||
7. Seven
|
7. Seven
|
||||||
8. Eight
|
8. Eight
|
||||||
9. Nine
|
9. Nine
|
||||||
10. Ten
|
10. Ten
|
||||||
11. Eleven
|
11. Eleven
|
||||||
12. Twelve
|
12. Twelve
|
||||||
|
|
|
||||||
|
|
@ -94,3 +94,36 @@
|
||||||
12. Twelve
|
12. Twelve
|
||||||
13. Thirteen {MD005}
|
13. Thirteen {MD005}
|
||||||
14. Fourteen
|
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