Improve highlighting for MD042/no-empty-links, add more tests.

This commit is contained in:
David Anson 2017-11-15 21:44:21 -08:00
parent 3b42e00c60
commit 0fd322a380
3 changed files with 30 additions and 8 deletions

View file

@ -8,7 +8,7 @@ var atxClosedHeaderSpaceRe = /(?:^#+\s\s+?\S)|(?:\S\s\s+?#+\s*$)/;
var atxHeaderSpaceRe = /^#+\s*\S/;
var bareUrlRe = /(?:http|ftp)s?:\/\/[^\s]*/i;
var dollarCommandRe = /^(\s*)(\$\s)/;
var emptyLinkRe = /\[[^\]]*](?:\((?:#?|(?:<>))\))|(?:\[[^\]]*])/;
var emptyLinkRe = /\[[^\]]*](?:\((?:#?|(?:<>))\))/;
var htmlRe = /<[^>]*>/;
var listItemMarkerRe = /^[\s>]*(?:[*+-]|\d+\.)\s+/;
var listItemMarkerInterruptsRe = /^[\s>]*(?:[*+-]|1\.)\s+/;
@ -1113,7 +1113,7 @@ module.exports = [
} else if (child.type === "link_close") {
inLink = false;
if (emptyLink) {
errors.addContext(child.lineNumber, "[" + linkText + "]");
errors.addContext(child.lineNumber, "[" + linkText + "]()");
}
} else if (inLink) {
linkText += child.content;

View file

@ -4,6 +4,8 @@ An [empty]() link
An [empty](#) link with fragment
An [empty](<>) link with angle brackets
This is a test file for the MARKDOWNLINT package.
This is a paragraph
@ -11,3 +13,5 @@ about Markdownlint
that capitalizes the
name wrong twice:
MarkDownLint.
A [normal](link) and an [empty one]() and a [fragment](#one).

View file

@ -14,7 +14,7 @@
"ruleAlias": "no-empty-links",
"ruleDescription": "No empty links",
"errorDetail": null,
"errorContext": "[empty]",
"errorContext": "[empty]()",
"errorRange": [4, 9]
},
{
@ -23,11 +23,29 @@
"ruleAlias": "no-empty-links",
"ruleDescription": "No empty links",
"errorDetail": null,
"errorContext": "[empty]",
"errorContext": "[empty]()",
"errorRange": [4, 10]
},
{
"lineNumber": 14,
"lineNumber": 7,
"ruleName": "MD042",
"ruleAlias": "no-empty-links",
"ruleDescription": "No empty links",
"errorDetail": null,
"errorContext": "[empty]()",
"errorRange": [4, 11]
},
{
"lineNumber": 17,
"ruleName": "MD042",
"ruleAlias": "no-empty-links",
"ruleDescription": "No empty links",
"errorDetail": null,
"errorContext": "[empty one]()",
"errorRange": [25, 13]
},
{
"lineNumber": 18,
"ruleName": "MD043",
"ruleAlias": "required-headers",
"ruleDescription": "Required header structure",
@ -36,7 +54,7 @@
"errorRange": null
},
{
"lineNumber": 7,
"lineNumber": 9,
"ruleName": "MD044",
"ruleAlias": "proper-names",
"ruleDescription": "Proper names should have the correct capitalization",
@ -45,7 +63,7 @@
"errorRange": [29, 12]
},
{
"lineNumber": 10,
"lineNumber": 12,
"ruleName": "MD044",
"ruleAlias": "proper-names",
"ruleDescription": "Proper names should have the correct capitalization",
@ -54,7 +72,7 @@
"errorRange": [7, 12]
},
{
"lineNumber": 13,
"lineNumber": 15,
"ruleName": "MD044",
"ruleAlias": "proper-names",
"ruleDescription": "Proper names should have the correct capitalization",