mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Update MD037/MD038/MD039 to report fixInfo for violations.
This commit is contained in:
parent
620853f200
commit
c8a74bd72c
3 changed files with 66 additions and 29 deletions
27
lib/md039.js
27
lib/md039.js
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addErrorContext, filterTokens, rangeFromRegExp } =
|
||||
require("../helpers");
|
||||
const { addErrorContext, filterTokens } = require("../helpers");
|
||||
|
||||
const spaceInLinkRe = /\[(?:\s+(?:[^\]]*?)\s*|(?:[^\]]*?)\s+)](?=\(\S*\))/;
|
||||
|
||||
|
|
@ -12,10 +11,11 @@ module.exports = {
|
|||
"description": "Spaces inside link text",
|
||||
"tags": [ "whitespace", "links" ],
|
||||
"function": function MD039(params, onError) {
|
||||
filterTokens(params, "inline", function forToken(token) {
|
||||
filterTokens(params, "inline", (token) => {
|
||||
const { line, lineNumber, children } = token;
|
||||
let inLink = false;
|
||||
let linkText = "";
|
||||
token.children.forEach(function forChild(child) {
|
||||
children.forEach((child) => {
|
||||
if (child.type === "link_open") {
|
||||
inLink = true;
|
||||
linkText = "";
|
||||
|
|
@ -24,9 +24,22 @@ module.exports = {
|
|||
const left = linkText.trimLeft().length !== linkText.length;
|
||||
const right = linkText.trimRight().length !== linkText.length;
|
||||
if (left || right) {
|
||||
addErrorContext(onError, token.lineNumber,
|
||||
"[" + linkText + "]", left, right,
|
||||
rangeFromRegExp(token.line, spaceInLinkRe));
|
||||
const match = line.match(spaceInLinkRe);
|
||||
const column = match.index + 1;
|
||||
const length = match[0].length;
|
||||
addErrorContext(
|
||||
onError,
|
||||
lineNumber,
|
||||
`[${linkText}]`,
|
||||
left,
|
||||
right,
|
||||
[ column, length ],
|
||||
{
|
||||
"editColumn": column + 1,
|
||||
"deleteCount": length - 2,
|
||||
"insertText": linkText.trim()
|
||||
}
|
||||
);
|
||||
}
|
||||
} else if (inLink) {
|
||||
linkText += child.content;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue