Add MD004 with tests, support disabling rules.

This commit is contained in:
David Anson 2015-03-01 22:56:52 -08:00
parent d2e38c1646
commit 2da9462e45
13 changed files with 201 additions and 7 deletions

View file

@ -14,6 +14,19 @@ function headingStyleFrom(token, lines) {
return "setext";
}
function unorderedListStyleFrom(token, lines) {
switch (lines[token.lines[0]].trim().substr(0, 1)) {
case "*":
return "asterisk";
case "-":
return "dash";
case "+":
return "plus";
default:
return null;
}
}
function padAndTrim(lines) {
return [].concat(
"",
@ -75,6 +88,25 @@ module.exports = [
}
},
{
"name": "MD004",
"desc": "Unordered list style",
"func": function MD004(params, errors) {
var style = params.options.style || "consistent";
var listItems = params.tokens.filter(function filterToken(token) {
return (token.type === "list_item_open");
});
if ((style === "consistent") && listItems.length) {
style = unorderedListStyleFrom(listItems[0], params.lines);
}
listItems.forEach(function forToken(token) {
if (unorderedListStyleFrom(token, params.lines) !== style) {
errors.push(lineNumberFrom(token));
}
});
}
},
{
"name": "MD031",
"desc": "Fenced code blocks should be surrounded by blank lines",