Add MD006, MD009, MD010 with tests.

This commit is contained in:
David Anson 2015-03-03 09:29:13 -08:00
parent e366ee071c
commit 812f5bdfff
3 changed files with 70 additions and 3 deletions

View file

@ -125,6 +125,30 @@ module.exports = [
}
},
{
"name": "MD006",
"desc": "Consider starting bulleted lists at the beginning of the line",
"func": function MD006(params, errors) {
var inList = 0;
params.tokens.filter(function filterToken(token) {
switch (token.type) {
case "bullet_list_open":
inList++;
return inList === 1;
case "bullet_list_close":
inList--;
return false;
default:
return false;
}
}).forEach(function forToken(token) {
if (indentFrom(token) !== 0) {
errors.push(token.lineNumber);
}
});
}
},
{
"name": "MD007",
"desc": "Unordered list indentation",
@ -144,6 +168,32 @@ module.exports = [
}
},
// MD008 does not exist
{
"name": "MD009",
"desc": "Trailing spaces",
"func": function MD009(params, errors) {
params.lines.forEach(function forLine(line, lineIndex) {
if (line.match(/\s$/)) {
errors.push(lineIndex + 1);
}
});
}
},
{
"name": "MD010",
"desc": "Hard tabs",
"func": function MD010(params, errors) {
params.lines.forEach(function forLine(line, lineIndex) {
if (line.match(/\t/)) {
errors.push(lineIndex + 1);
}
});
}
},
{
"name": "MD031",
"desc": "Fenced code blocks should be surrounded by blank lines",
@ -173,13 +223,13 @@ module.exports = [
var inList = false;
var inCode = false;
var prevLine = "";
params.lines.forEach(function forLine(line, lineNumber) {
params.lines.forEach(function forLine(line, lineIndex) {
if (!inCode) {
var listMarker = line.trim().match(/^([\*\+\-]|(\d+\.))\s/);
if (listMarker && !inList && !prevLine.match(/^($|\s)/)) {
errors.push(lineNumber + 1);
errors.push(lineIndex + 1);
} else if (!listMarker && inList && !line.match(/^($|\s)/)) {
errors.push(lineNumber);
errors.push(lineIndex);
}
inList = listMarker;
}

View file

@ -0,0 +1,14 @@
Some text
* Item {MD006}
* Item
* Item
* Item
* Item
* Item
* Item
Some more text
* Item {MD006}
* Item

View file

@ -0,0 +1,3 @@
Some text {MD009}
Some more text {MD010}
Some more text