mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02: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";
|
||||
|
||||
const { addErrorContext, newLineRe, rangeFromRegExp } = require("../helpers");
|
||||
const { addErrorContext, newLineRe } = require("../helpers");
|
||||
|
||||
const spaceAfterBlockQuote = /^\s*(?:>\s+)+\S/;
|
||||
const spaceAfterBlockQuoteRe = /^((?:\s*>)+)(\s{2,})\S/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD027", "no-multiple-space-blockquote" ],
|
||||
|
@ -13,31 +13,43 @@ module.exports = {
|
|||
"function": function MD027(params, onError) {
|
||||
let blockquoteNesting = 0;
|
||||
let listItemNesting = 0;
|
||||
params.tokens.forEach(function forToken(token) {
|
||||
if (token.type === "blockquote_open") {
|
||||
params.tokens.forEach((token) => {
|
||||
const { content, lineNumber, type } = token;
|
||||
if (type === "blockquote_open") {
|
||||
blockquoteNesting++;
|
||||
} else if (token.type === "blockquote_close") {
|
||||
} else if (type === "blockquote_close") {
|
||||
blockquoteNesting--;
|
||||
} else if (token.type === "list_item_open") {
|
||||
} else if (type === "list_item_open") {
|
||||
listItemNesting++;
|
||||
} else if (token.type === "list_item_close") {
|
||||
} else if (type === "list_item_close") {
|
||||
listItemNesting--;
|
||||
} else if ((token.type === "inline") && (blockquoteNesting > 0)) {
|
||||
const multipleSpaces = listItemNesting ?
|
||||
/^(\s*>)+\s\s+>/.test(token.line) :
|
||||
/^(\s*>)+\s\s/.test(token.line);
|
||||
if (multipleSpaces) {
|
||||
addErrorContext(onError, token.lineNumber, token.line, null,
|
||||
null, rangeFromRegExp(token.line, spaceAfterBlockQuote));
|
||||
}
|
||||
token.content.split(newLineRe)
|
||||
.forEach(function forLine(line, offset) {
|
||||
if (/^\s/.test(line)) {
|
||||
addErrorContext(onError, token.lineNumber + offset,
|
||||
"> " + line, null, null,
|
||||
rangeFromRegExp(line, spaceAfterBlockQuote));
|
||||
} else if ((type === "inline") && blockquoteNesting) {
|
||||
const lineCount = content.split(newLineRe).length;
|
||||
for (let i = 0; i < lineCount; i++) {
|
||||
const line = params.lines[lineNumber + i - 1];
|
||||
const match = line.match(spaceAfterBlockQuoteRe);
|
||||
if (match) {
|
||||
const [
|
||||
fullMatch,
|
||||
{ "length": blockquoteLength },
|
||||
{ "length": spaceLength }
|
||||
] = match;
|
||||
if (!listItemNesting || (fullMatch[fullMatch.length - 1] === ">")) {
|
||||
addErrorContext(
|
||||
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*$/, "");
|
||||
if (!names.includes(wordMatch)) {
|
||||
const lineNumber = token.lineNumber + index + fenceOffset;
|
||||
const range = [ match.index + 1, wordMatch.length ];
|
||||
addErrorDetailIf(onError, lineNumber,
|
||||
name, match[1], null, null, range);
|
||||
const fullLine = params.lines[lineNumber - 1];
|
||||
let matchIndex = match.index;
|
||||
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",
|
||||
"errorDetail": null,
|
||||
"errorContext": "> > > Multiple spaces, multip...",
|
||||
"errorRange": [ 1, 8 ]
|
||||
"errorRange": [ 1, 4 ]
|
||||
},
|
||||
{
|
||||
"lineNumber": 9,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue