2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const shared = require("./shared");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD005", "list-indent" ],
|
|
|
|
"description": "Inconsistent indentation for list items at the same level",
|
|
|
|
"tags": [ "bullet", "ul", "indentation" ],
|
|
|
|
"function": function MD005(params, onError) {
|
2018-03-04 23:06:31 -08:00
|
|
|
shared.flattenLists().forEach(function forList(list) {
|
2018-06-15 22:37:12 -07:00
|
|
|
const expectedIndent = list.indent;
|
|
|
|
let expectedEnd = 0;
|
|
|
|
let actualEnd = -1;
|
|
|
|
let endMatching = false;
|
2018-01-21 21:44:25 -08:00
|
|
|
list.items.forEach(function forItem(item) {
|
2018-06-15 22:37:12 -07:00
|
|
|
const actualIndent = shared.indentFor(item);
|
|
|
|
if (list.unordered) {
|
|
|
|
shared.addErrorDetailIf(onError, item.lineNumber,
|
|
|
|
expectedIndent, actualIndent, null,
|
|
|
|
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
|
|
|
|
} else {
|
|
|
|
const match = shared.orderedListItemMarkerRe.exec(item.line);
|
|
|
|
actualEnd = match && match[0].length;
|
|
|
|
expectedEnd = expectedEnd || actualEnd;
|
|
|
|
if ((expectedIndent !== actualIndent) || endMatching) {
|
|
|
|
if (expectedEnd === actualEnd) {
|
|
|
|
endMatching = true;
|
|
|
|
} else {
|
|
|
|
const detail = endMatching ?
|
|
|
|
`Expected: (${expectedEnd}); Actual: (${actualEnd})` :
|
|
|
|
`Expected: ${expectedIndent}; Actual: ${actualIndent}`;
|
|
|
|
shared.addError(onError, item.lineNumber, detail, null,
|
|
|
|
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-21 21:44:25 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|