Add basic infrastructure, MD031, and test.

This commit is contained in:
David Anson 2015-02-23 23:39:20 -08:00
parent cdec362dc0
commit d16e1cafc1
5 changed files with 136 additions and 1 deletions

30
lib/rules.js Normal file
View file

@ -0,0 +1,30 @@
"use strict";
function padAndTrim(lines) {
return [].concat(
"",
lines.map(function(line) {
return line.trim();
}),
"");
}
module.exports = {
MD031: function(lines) {
// Some parsers have trouble detecting fenced code blocks without
// surrounding whitespace, so examine the lines directly.
lines = padAndTrim(lines);
var errors = [];
var inCode = false;
lines.forEach(function(line, lineNum) {
if (line.match(/^(```|~~~)/)) {
inCode = !inCode;
if ((inCode && lines[lineNum - 1].length) ||
(!inCode && lines[lineNum + 1].length)) {
errors.push(lineNum);
}
}
});
return errors;
}
};