From f35d690fb1a017bda6467403d56c930d77a9c035 Mon Sep 17 00:00:00 2001 From: David Anson Date: Tue, 3 Mar 2015 18:28:59 -0800 Subject: [PATCH] Add MD011 with tests, pass empty env to markdown-it.parse. --- lib/markdownlint.js | 2 +- lib/rules.js | 18 ++++++++++++++++++ test/reversed_link.md | 7 +++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/reversed_link.md diff --git a/lib/markdownlint.js b/lib/markdownlint.js index 6f9878d4..5d71909b 100644 --- a/lib/markdownlint.js +++ b/lib/markdownlint.js @@ -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) { diff --git a/lib/rules.js b/lib/rules.js index a65617be..ce6c3378 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -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", diff --git a/test/reversed_link.md b/test/reversed_link.md new file mode 100644 index 00000000..1e8ef326 --- /dev/null +++ b/test/reversed_link.md @@ -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]`