mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-21 21:30:47 +02:00
Update MD011/MD034 to report fixInfo for violations.
This commit is contained in:
parent
5e73aa1d9d
commit
620853f200
3 changed files with 41 additions and 8 deletions
28
lib/md011.js
28
lib/md011.js
|
@ -2,20 +2,34 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addError, forEachInlineChild, rangeFromRegExp } = require("../helpers");
|
||||
const { addError, forEachInlineChild } = require("../helpers");
|
||||
|
||||
const reversedLinkRe = /\([^)]+\)\[[^\]^][^\]]*]/;
|
||||
const reversedLinkRe = /\(([^)]+)\)\[([^\]^][^\]]*)]/g;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD011", "no-reversed-links" ],
|
||||
"description": "Reversed link syntax",
|
||||
"tags": [ "links" ],
|
||||
"function": function MD011(params, onError) {
|
||||
forEachInlineChild(params, "text", function forToken(token) {
|
||||
const match = reversedLinkRe.exec(token.content);
|
||||
if (match) {
|
||||
addError(onError, token.lineNumber, match[0], null,
|
||||
rangeFromRegExp(token.line, reversedLinkRe));
|
||||
forEachInlineChild(params, "text", (token) => {
|
||||
const { lineNumber, content } = token;
|
||||
let match = null;
|
||||
while ((match = reversedLinkRe.exec(content)) !== null) {
|
||||
const [ reversedLink, linkText, linkDestination ] = match;
|
||||
const column = match.index + 1;
|
||||
const length = reversedLink.length;
|
||||
addError(
|
||||
onError,
|
||||
lineNumber,
|
||||
reversedLink,
|
||||
null,
|
||||
[ column, length ],
|
||||
{
|
||||
"editColumn": column,
|
||||
"deleteCount": length,
|
||||
"insertText": `[${linkText}](${linkDestination})`
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
15
lib/md034.js
15
lib/md034.js
|
@ -26,7 +26,20 @@ module.exports = {
|
|||
line.indexOf(content) + match.index + 1,
|
||||
bareUrl.length
|
||||
];
|
||||
addErrorContext(onError, lineNumber, bareUrl, null, null, range);
|
||||
const fixInfo = range ? {
|
||||
"editColumn": range[0],
|
||||
"deleteCount": range[1],
|
||||
"insertText": `<${bareUrl}>`
|
||||
} : null;
|
||||
addErrorContext(
|
||||
onError,
|
||||
lineNumber,
|
||||
bareUrl,
|
||||
null,
|
||||
null,
|
||||
range,
|
||||
fixInfo
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,3 +5,9 @@ However, this shouldn't trigger inside code blocks:
|
|||
myObj.getFiles("test")[0]
|
||||
|
||||
Nor inline code: `myobj.getFiles("test")[0]`
|
||||
|
||||
Two (issues)[https://www.example.com/one] in {MD011} {MD034}
|
||||
the (same text)[https://www.example.com/two]. {MD011} {MD034}
|
||||
|
||||
<!-- markdownlint-disable line-length -->
|
||||
Two (issues)[https://www.example.com/three] on the (same line)[https://www.example.com/four]. {MD011} {MD034}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue