mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-21 16:30:12 +01:00
Remove state from shared.js, move to cache.js.
This commit is contained in:
parent
827e1acb56
commit
f614f3e1ce
17 changed files with 124 additions and 98 deletions
20
lib/md005.js
20
lib/md005.js
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue