mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Update MD042/no-empty-links to improve range reporting, remove helpers.emptyLinkRe.
This commit is contained in:
parent
7c1550cbe9
commit
861443c740
4 changed files with 24 additions and 15 deletions
|
|
@ -52,9 +52,6 @@ var emphasisMarkersRe = /[_*]/g;
|
|||
// Regular expression for inline links and shortcut reference links
|
||||
var linkRe = /(\[(?:[^[\]]?(?:\[[^[\]]*\])?)*\])(\([^)]*\)|\[[^\]]*\])?/g;
|
||||
module.exports.linkRe = linkRe;
|
||||
// Regular expression for empty inline links
|
||||
module.exports.emptyLinkRe =
|
||||
/\[(?:[^[\]]?(?:\[[^[\]]*\])?)*\]\((?:|#|<>)\)/;
|
||||
// Regular expression for link reference definition lines
|
||||
module.exports.linkReferenceRe = /^ {0,3}\[[^\]]+]:\s.*$/;
|
||||
// All punctuation characters (normal and full-width)
|
||||
|
|
@ -3917,7 +3914,7 @@ module.exports = {
|
|||
"use strict";
|
||||
// @ts-check
|
||||
|
||||
var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, emptyLinkRe = _a.emptyLinkRe, filterTokens = _a.filterTokens, rangeFromRegExp = _a.rangeFromRegExp;
|
||||
var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, escapeForRegExp = _a.escapeForRegExp, filterTokens = _a.filterTokens;
|
||||
module.exports = {
|
||||
"names": ["MD042", "no-empty-links"],
|
||||
"description": "No empty links",
|
||||
|
|
@ -3940,7 +3937,14 @@ module.exports = {
|
|||
else if (child.type === "link_close") {
|
||||
inLink = false;
|
||||
if (emptyLink) {
|
||||
addErrorContext(onError, child.lineNumber, "[" + linkText + "]()", null, null, rangeFromRegExp(child.line, emptyLinkRe));
|
||||
var context = "[".concat(linkText, "]");
|
||||
var range = null;
|
||||
var match = child.line.match(new RegExp("".concat(escapeForRegExp(context), "\\((?:|#|<>)\\)")));
|
||||
if (match) {
|
||||
context = match[0];
|
||||
range = [match.index + 1, match[0].length];
|
||||
}
|
||||
addErrorContext(onError, child.lineNumber, context, null, null, range);
|
||||
emptyLink = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,10 +31,6 @@ const linkRe =
|
|||
/(\[(?:[^[\]]?(?:\[[^[\]]*\])?)*\])(\([^)]*\)|\[[^\]]*\])?/g;
|
||||
module.exports.linkRe = linkRe;
|
||||
|
||||
// Regular expression for empty inline links
|
||||
module.exports.emptyLinkRe =
|
||||
/\[(?:[^[\]]?(?:\[[^[\]]*\])?)*\]\((?:|#|<>)\)/;
|
||||
|
||||
// Regular expression for link reference definition lines
|
||||
module.exports.linkReferenceRe = /^ {0,3}\[[^\]]+]:\s.*$/;
|
||||
|
||||
|
|
|
|||
17
lib/md042.js
17
lib/md042.js
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
"ruleDescription": "No empty links",
|
||||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md042",
|
||||
"errorDetail": null,
|
||||
"errorContext": "[empty]()",
|
||||
"errorContext": "[empty](#)",
|
||||
"errorRange": [
|
||||
4,
|
||||
10
|
||||
|
|
@ -54,7 +54,7 @@
|
|||
"ruleDescription": "No empty links",
|
||||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md042",
|
||||
"errorDetail": null,
|
||||
"errorContext": "[empty]()",
|
||||
"errorContext": "[empty](<>)",
|
||||
"errorRange": [
|
||||
4,
|
||||
11
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue