Remove state from shared.js, move to cache.js.

This commit is contained in:
David Anson 2019-04-10 21:26:59 -07:00
parent 827e1acb56
commit f614f3e1ce
17 changed files with 124 additions and 98 deletions

View file

@ -2,26 +2,28 @@
"use strict";
const shared = require("./shared");
const { addError, addErrorDetailIf, indentFor, listItemMarkerRe,
orderedListItemMarkerRe, rangeFromRegExp } = require("./shared");
const { flattenedLists } = require("./cache");
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) {
shared.flattenLists().forEach(function forList(list) {
flattenedLists().forEach((list) => {
const expectedIndent = list.indent;
let expectedEnd = 0;
let actualEnd = -1;
let endMatching = false;
list.items.forEach(function forItem(item) {
const actualIndent = shared.indentFor(item);
list.items.forEach((item) => {
const actualIndent = indentFor(item);
if (list.unordered) {
shared.addErrorDetailIf(onError, item.lineNumber,
addErrorDetailIf(onError, item.lineNumber,
expectedIndent, actualIndent, null, null,
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
rangeFromRegExp(item.line, listItemMarkerRe));
} else {
const match = shared.orderedListItemMarkerRe.exec(item.line);
const match = orderedListItemMarkerRe.exec(item.line);
actualEnd = match && match[0].length;
expectedEnd = expectedEnd || actualEnd;
if ((expectedIndent !== actualIndent) || endMatching) {
@ -31,8 +33,8 @@ module.exports = {
const detail = endMatching ?
`Expected: (${expectedEnd}); Actual: (${actualEnd})` :
`Expected: ${expectedIndent}; Actual: ${actualIndent}`;
shared.addError(onError, item.lineNumber, detail, null,
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
addError(onError, item.lineNumber, detail, null,
rangeFromRegExp(item.line, listItemMarkerRe));
}
}
}