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": [ "MD029", "ol-prefix" ],
|
|
|
|
"description": "Ordered list item prefix",
|
|
|
|
"tags": [ "ol" ],
|
|
|
|
"function": function MD029(params, onError) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const style = params.config.style || "one_or_ordered";
|
2018-03-04 23:06:31 -08:00
|
|
|
shared.flattenLists().forEach(function forList(list) {
|
2018-01-21 21:44:25 -08:00
|
|
|
if (!list.unordered) {
|
2018-04-27 22:05:34 -07:00
|
|
|
let listStyle = style;
|
2018-01-21 21:44:25 -08:00
|
|
|
if (listStyle === "one_or_ordered") {
|
2018-04-27 22:05:34 -07:00
|
|
|
const second = (list.items.length > 1) &&
|
2018-06-15 22:37:12 -07:00
|
|
|
shared.orderedListItemMarkerRe.exec(list.items[1].line);
|
2018-01-21 21:44:25 -08:00
|
|
|
listStyle = (second && (second[1] !== "1")) ? "ordered" : "one";
|
|
|
|
}
|
2018-04-27 22:05:34 -07:00
|
|
|
let number = 1;
|
2018-01-21 21:44:25 -08:00
|
|
|
list.items.forEach(function forItem(item) {
|
2018-06-15 22:37:12 -07:00
|
|
|
const match = shared.orderedListItemMarkerRe.exec(item.line);
|
2018-01-21 21:44:25 -08:00
|
|
|
shared.addErrorDetailIf(onError, item.lineNumber,
|
|
|
|
String(number), !match || match[1],
|
|
|
|
"Style: " + (listStyle === "one" ? "1/1/1" : "1/2/3"),
|
|
|
|
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
|
|
|
|
if (listStyle === "ordered") {
|
|
|
|
number++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|