Update MD034/no-bare-urls to ignore "[link]" scenario that conflicts with MD011/no-reversed-links (fixes #268).

This commit is contained in:
David Anson 2020-04-01 20:21:36 -07:00
parent 29f16bf402
commit dd66a33d75
8 changed files with 60 additions and 27 deletions

View file

@ -21,25 +21,34 @@ module.exports = {
} else if ((type === "text") && !inLink) {
while ((match = bareUrlRe.exec(content)) !== null) {
const [ bareUrl ] = match;
const index = line.indexOf(content);
const range = (index === -1) ? null : [
line.indexOf(content) + match.index + 1,
bareUrl.length
];
const fixInfo = range ? {
"editColumn": range[0],
"deleteCount": range[1],
"insertText": `<${bareUrl}>`
} : null;
addErrorContext(
onError,
lineNumber,
bareUrl,
null,
null,
range,
fixInfo
);
const matchIndex = match.index;
const bareUrlLength = bareUrl.length;
// Allow "[https://example.com]" to avoid conflicts with
// MD011/no-reversed-links
if (
(content[matchIndex - 1] !== "[") ||
(content[matchIndex + bareUrlLength] !== "]")
) {
const index = line.indexOf(content);
const range = (index === -1) ? null : [
index + matchIndex + 1,
bareUrlLength
];
const fixInfo = range ? {
"editColumn": range[0],
"deleteCount": range[1],
"insertText": `<${bareUrl}>`
} : null;
addErrorContext(
onError,
lineNumber,
bareUrl,
null,
null,
range,
fixInfo
);
}
}
}
});