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": [ "MD030", "list-marker-space" ],
|
|
|
|
|
"description": "Spaces after list markers",
|
|
|
|
|
"tags": [ "ol", "ul", "whitespace" ],
|
|
|
|
|
"function": function MD030(params, onError) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const ulSingle = params.config.ul_single || 1;
|
|
|
|
|
const olSingle = params.config.ol_single || 1;
|
|
|
|
|
const ulMulti = params.config.ul_multi || 1;
|
|
|
|
|
const olMulti = params.config.ol_multi || 1;
|
2018-03-04 23:06:31 -08:00
|
|
|
shared.flattenLists().forEach(function forList(list) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const lineCount = list.lastLineIndex - list.open.map[0];
|
|
|
|
|
const allSingle = lineCount === list.items.length;
|
|
|
|
|
const expectedSpaces = list.unordered ?
|
2018-01-21 21:44:25 -08:00
|
|
|
(allSingle ? ulSingle : ulMulti) :
|
|
|
|
|
(allSingle ? olSingle : olMulti);
|
|
|
|
|
list.items.forEach(function forItem(item) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const match = /^[\s>]*\S+(\s+)/.exec(item.line);
|
2018-01-21 21:44:25 -08:00
|
|
|
shared.addErrorDetailIf(onError, item.lineNumber,
|
|
|
|
|
expectedSpaces, (match ? match[1].length : 0), null,
|
|
|
|
|
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|