Update MD042/no-empty-links to improve range reporting, remove helpers.emptyLinkRe.

This commit is contained in:
David Anson 2022-02-13 17:41:31 -08:00
parent 7c1550cbe9
commit 861443c740
4 changed files with 24 additions and 15 deletions

View file

@ -2,7 +2,7 @@
"use strict";
const { addErrorContext, emptyLinkRe, filterTokens, rangeFromRegExp } =
const { addErrorContext, escapeForRegExp, filterTokens } =
require("../helpers");
module.exports = {
@ -26,9 +26,18 @@ module.exports = {
} else if (child.type === "link_close") {
inLink = false;
if (emptyLink) {
addErrorContext(onError, child.lineNumber,
"[" + linkText + "]()", null, null,
rangeFromRegExp(child.line, emptyLinkRe));
let context = `[${linkText}]`;
let range = null;
const match = child.line.match(
new RegExp(`${escapeForRegExp(context)}\\((?:|#|<>)\\)`)
);
if (match) {
context = match[0];
range = [ match.index + 1, match[0].length ];
}
addErrorContext(
onError, child.lineNumber, context, null, null, range
);
emptyLink = false;
}
} else if (inLink) {