mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 14:30:12 +01:00
Update MD027/MD044 to report fixInfo for violations.
This commit is contained in:
parent
316bfeadaa
commit
00a7e765ec
3 changed files with 59 additions and 26 deletions
56
lib/md027.js
56
lib/md027.js
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { addErrorContext, newLineRe, rangeFromRegExp } = require("../helpers");
|
const { addErrorContext, newLineRe } = require("../helpers");
|
||||||
|
|
||||||
const spaceAfterBlockQuote = /^\s*(?:>\s+)+\S/;
|
const spaceAfterBlockQuoteRe = /^((?:\s*>)+)(\s{2,})\S/;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": [ "MD027", "no-multiple-space-blockquote" ],
|
"names": [ "MD027", "no-multiple-space-blockquote" ],
|
||||||
|
|
@ -13,31 +13,43 @@ module.exports = {
|
||||||
"function": function MD027(params, onError) {
|
"function": function MD027(params, onError) {
|
||||||
let blockquoteNesting = 0;
|
let blockquoteNesting = 0;
|
||||||
let listItemNesting = 0;
|
let listItemNesting = 0;
|
||||||
params.tokens.forEach(function forToken(token) {
|
params.tokens.forEach((token) => {
|
||||||
if (token.type === "blockquote_open") {
|
const { content, lineNumber, type } = token;
|
||||||
|
if (type === "blockquote_open") {
|
||||||
blockquoteNesting++;
|
blockquoteNesting++;
|
||||||
} else if (token.type === "blockquote_close") {
|
} else if (type === "blockquote_close") {
|
||||||
blockquoteNesting--;
|
blockquoteNesting--;
|
||||||
} else if (token.type === "list_item_open") {
|
} else if (type === "list_item_open") {
|
||||||
listItemNesting++;
|
listItemNesting++;
|
||||||
} else if (token.type === "list_item_close") {
|
} else if (type === "list_item_close") {
|
||||||
listItemNesting--;
|
listItemNesting--;
|
||||||
} else if ((token.type === "inline") && (blockquoteNesting > 0)) {
|
} else if ((type === "inline") && blockquoteNesting) {
|
||||||
const multipleSpaces = listItemNesting ?
|
const lineCount = content.split(newLineRe).length;
|
||||||
/^(\s*>)+\s\s+>/.test(token.line) :
|
for (let i = 0; i < lineCount; i++) {
|
||||||
/^(\s*>)+\s\s/.test(token.line);
|
const line = params.lines[lineNumber + i - 1];
|
||||||
if (multipleSpaces) {
|
const match = line.match(spaceAfterBlockQuoteRe);
|
||||||
addErrorContext(onError, token.lineNumber, token.line, null,
|
if (match) {
|
||||||
null, rangeFromRegExp(token.line, spaceAfterBlockQuote));
|
const [
|
||||||
}
|
fullMatch,
|
||||||
token.content.split(newLineRe)
|
{ "length": blockquoteLength },
|
||||||
.forEach(function forLine(line, offset) {
|
{ "length": spaceLength }
|
||||||
if (/^\s/.test(line)) {
|
] = match;
|
||||||
addErrorContext(onError, token.lineNumber + offset,
|
if (!listItemNesting || (fullMatch[fullMatch.length - 1] === ">")) {
|
||||||
"> " + line, null, null,
|
addErrorContext(
|
||||||
rangeFromRegExp(line, spaceAfterBlockQuote));
|
onError,
|
||||||
|
lineNumber + i,
|
||||||
|
line,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
[ 1, fullMatch.length ],
|
||||||
|
{
|
||||||
|
"editColumn": blockquoteLength + 1,
|
||||||
|
"deleteCount": spaceLength - 1
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
27
lib/md044.js
27
lib/md044.js
|
|
@ -29,9 +29,30 @@ module.exports = {
|
||||||
.replace(/^\W*/, "").replace(/\W*$/, "");
|
.replace(/^\W*/, "").replace(/\W*$/, "");
|
||||||
if (!names.includes(wordMatch)) {
|
if (!names.includes(wordMatch)) {
|
||||||
const lineNumber = token.lineNumber + index + fenceOffset;
|
const lineNumber = token.lineNumber + index + fenceOffset;
|
||||||
const range = [ match.index + 1, wordMatch.length ];
|
const fullLine = params.lines[lineNumber - 1];
|
||||||
addErrorDetailIf(onError, lineNumber,
|
let matchIndex = match.index;
|
||||||
name, match[1], null, null, range);
|
const matchLength = wordMatch.length;
|
||||||
|
const fullLineWord =
|
||||||
|
fullLine.slice(matchIndex, matchIndex + matchLength);
|
||||||
|
if (fullLineWord !== wordMatch) {
|
||||||
|
// Attempt to fix bad offset due to inline content
|
||||||
|
matchIndex = fullLine.indexOf(wordMatch);
|
||||||
|
}
|
||||||
|
const range = [ matchIndex + 1, matchLength ];
|
||||||
|
addErrorDetailIf(
|
||||||
|
onError,
|
||||||
|
lineNumber,
|
||||||
|
name,
|
||||||
|
match[1],
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
range,
|
||||||
|
{
|
||||||
|
"editColumn": matchIndex + 1,
|
||||||
|
"deleteCount": matchLength,
|
||||||
|
"insertText": name
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@
|
||||||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md027",
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md027",
|
||||||
"errorDetail": null,
|
"errorDetail": null,
|
||||||
"errorContext": "> > > Multiple spaces, multip...",
|
"errorContext": "> > > Multiple spaces, multip...",
|
||||||
"errorRange": [ 1, 8 ]
|
"errorRange": [ 1, 4 ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"lineNumber": 9,
|
"lineNumber": 9,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue