Add MD011 with tests, pass empty env to markdown-it.parse.

This commit is contained in:
David Anson 2015-03-03 18:28:59 -08:00
parent 812f5bdfff
commit f35d690fb1
3 changed files with 26 additions and 1 deletions

View file

@ -17,7 +17,7 @@ function lintFile(file, config, callback) {
if (err) {
callback(err);
} else {
var tokens = md.parse(contents);
var tokens = md.parse(contents, {});
var lines = contents.split(/\r\n|\r|\n/g);
tokens.forEach(function forToken(token) {
if (token.lines) {

View file

@ -194,6 +194,24 @@ module.exports = [
}
},
{
"name": "MD011",
"desc": "Reversed link syntax",
"func": function MD011(params, errors) {
params.tokens.filter(function filterToken(token) {
return (token.type === "inline");
}).forEach(function forToken(token) {
token.children.filter(function filterChild(child) {
return (child.type === "text");
}).forEach(function forChild(child) {
if (child.content.match(/\([^)]+\)\[[^\]]+\]/)) {
errors.push(token.lineNumber);
}
});
});
}
},
{
"name": "MD031",
"desc": "Fenced code blocks should be surrounded by blank lines",

7
test/reversed_link.md Normal file
View file

@ -0,0 +1,7 @@
Go to (this website)[http://www.example.com] {MD011}
However, this shouldn't trigger inside code blocks:
myObj.getFiles("test")[0]
Nor inline code: `myobj.getFiles("test")[0]`