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

View file

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

View file

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