Fix MD039/no-space-in-links range for multiple issues on the same line.

This commit is contained in:
David Anson 2019-09-21 21:05:58 -07:00
parent 4843e277c0
commit a75f1ecf2a
4 changed files with 22 additions and 7 deletions

View file

@ -15,6 +15,7 @@ module.exports = {
const { line, lineNumber, children } = token;
let inLink = false;
let linkText = "";
let lineIndex = 0;
children.forEach((child) => {
if (child.type === "link_open") {
inLink = true;
@ -24,9 +25,10 @@ module.exports = {
const left = linkText.trimLeft().length !== linkText.length;
const right = linkText.trimRight().length !== linkText.length;
if (left || right) {
const match = line.match(spaceInLinkRe);
const column = match.index + 1;
const match = line.slice(lineIndex).match(spaceInLinkRe);
const column = match.index + lineIndex + 1;
const length = match[0].length;
lineIndex = column + length - 1;
addErrorContext(
onError,
lineNumber,

View file

@ -56,3 +56,5 @@ text text ```` code
span code
span```` text
text.
Text [ space](link) text [space ](link) text [ space ](link) text.

View file

@ -58,3 +58,5 @@ text text ````code
span code
span```` text
text.
Text [space](link) text [space](link) text [space](link) text.

View file

@ -224,6 +224,15 @@
"errorContext": "[ inside ]",
"errorRange": [ 7, 10 ]
},
{
"lineNumber": 60,
"ruleNames": [ "MD039", "no-space-in-links" ],
"ruleDescription": "Spaces inside link text",
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039",
"errorDetail": null,
"errorContext": "[ space]",
"errorRange": [ 6, 8 ]
},
{
"lineNumber": 21,
"ruleNames": [ "MD040", "fenced-code-language" ],