mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 14:30:12 +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
|
// Regular expression for inline links and shortcut reference links
|
||||||
var linkRe = /(\[(?:[^[\]]?(?:\[[^[\]]*\])?)*\])(\([^)]*\)|\[[^\]]*\])?/g;
|
var linkRe = /(\[(?:[^[\]]?(?:\[[^[\]]*\])?)*\])(\([^)]*\)|\[[^\]]*\])?/g;
|
||||||
module.exports.linkRe = linkRe;
|
module.exports.linkRe = linkRe;
|
||||||
// Regular expression for empty inline links
|
|
||||||
module.exports.emptyLinkRe =
|
|
||||||
/\[(?:[^[\]]?(?:\[[^[\]]*\])?)*\]\((?:|#|<>)\)/;
|
|
||||||
// Regular expression for link reference definition lines
|
// Regular expression for link reference definition lines
|
||||||
module.exports.linkReferenceRe = /^ {0,3}\[[^\]]+]:\s.*$/;
|
module.exports.linkReferenceRe = /^ {0,3}\[[^\]]+]:\s.*$/;
|
||||||
// All punctuation characters (normal and full-width)
|
// All punctuation characters (normal and full-width)
|
||||||
|
|
@ -3917,7 +3914,7 @@ module.exports = {
|
||||||
"use strict";
|
"use strict";
|
||||||
// @ts-check
|
// @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 = {
|
module.exports = {
|
||||||
"names": ["MD042", "no-empty-links"],
|
"names": ["MD042", "no-empty-links"],
|
||||||
"description": "No empty links",
|
"description": "No empty links",
|
||||||
|
|
@ -3940,7 +3937,14 @@ module.exports = {
|
||||||
else if (child.type === "link_close") {
|
else if (child.type === "link_close") {
|
||||||
inLink = false;
|
inLink = false;
|
||||||
if (emptyLink) {
|
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;
|
emptyLink = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,6 @@ const linkRe =
|
||||||
/(\[(?:[^[\]]?(?:\[[^[\]]*\])?)*\])(\([^)]*\)|\[[^\]]*\])?/g;
|
/(\[(?:[^[\]]?(?:\[[^[\]]*\])?)*\])(\([^)]*\)|\[[^\]]*\])?/g;
|
||||||
module.exports.linkRe = linkRe;
|
module.exports.linkRe = linkRe;
|
||||||
|
|
||||||
// Regular expression for empty inline links
|
|
||||||
module.exports.emptyLinkRe =
|
|
||||||
/\[(?:[^[\]]?(?:\[[^[\]]*\])?)*\]\((?:|#|<>)\)/;
|
|
||||||
|
|
||||||
// Regular expression for link reference definition lines
|
// Regular expression for link reference definition lines
|
||||||
module.exports.linkReferenceRe = /^ {0,3}\[[^\]]+]:\s.*$/;
|
module.exports.linkReferenceRe = /^ {0,3}\[[^\]]+]:\s.*$/;
|
||||||
|
|
||||||
|
|
|
||||||
17
lib/md042.js
17
lib/md042.js
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { addErrorContext, emptyLinkRe, filterTokens, rangeFromRegExp } =
|
const { addErrorContext, escapeForRegExp, filterTokens } =
|
||||||
require("../helpers");
|
require("../helpers");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
@ -26,9 +26,18 @@ module.exports = {
|
||||||
} else if (child.type === "link_close") {
|
} else if (child.type === "link_close") {
|
||||||
inLink = false;
|
inLink = false;
|
||||||
if (emptyLink) {
|
if (emptyLink) {
|
||||||
addErrorContext(onError, child.lineNumber,
|
let context = `[${linkText}]`;
|
||||||
"[" + linkText + "]()", null, null,
|
let range = null;
|
||||||
rangeFromRegExp(child.line, emptyLinkRe));
|
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;
|
emptyLink = false;
|
||||||
}
|
}
|
||||||
} else if (inLink) {
|
} else if (inLink) {
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
"ruleDescription": "No empty links",
|
"ruleDescription": "No empty links",
|
||||||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md042",
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md042",
|
||||||
"errorDetail": null,
|
"errorDetail": null,
|
||||||
"errorContext": "[empty]()",
|
"errorContext": "[empty](#)",
|
||||||
"errorRange": [
|
"errorRange": [
|
||||||
4,
|
4,
|
||||||
10
|
10
|
||||||
|
|
@ -54,7 +54,7 @@
|
||||||
"ruleDescription": "No empty links",
|
"ruleDescription": "No empty links",
|
||||||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md042",
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md042",
|
||||||
"errorDetail": null,
|
"errorDetail": null,
|
||||||
"errorContext": "[empty]()",
|
"errorContext": "[empty](<>)",
|
||||||
"errorRange": [
|
"errorRange": [
|
||||||
4,
|
4,
|
||||||
11
|
11
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue