mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-01-07 08:28:49 +01:00
Update MD022/MD031/MD032 to report fixInfo for violations, normalize input to fixErrors.
This commit is contained in:
parent
2cd27c58f2
commit
a062e7c6bd
6 changed files with 357 additions and 38 deletions
29
lib/md022.js
29
lib/md022.js
|
|
@ -22,16 +22,33 @@ module.exports = {
|
|||
const [ topIndex, nextIndex ] = token.map;
|
||||
for (let i = 0; i < linesAbove; i++) {
|
||||
if (!isBlankLine(lines[topIndex - i - 1])) {
|
||||
addErrorDetailIf(onError, topIndex + 1, linesAbove, i, "Above",
|
||||
lines[topIndex].trim());
|
||||
return;
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
topIndex + 1,
|
||||
linesAbove,
|
||||
i,
|
||||
"Above",
|
||||
lines[topIndex].trim(),
|
||||
null,
|
||||
{
|
||||
"insertText": "\n"
|
||||
});
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < linesBelow; i++) {
|
||||
if (!isBlankLine(lines[nextIndex + i])) {
|
||||
addErrorDetailIf(onError, topIndex + 1, linesBelow, i, "Below",
|
||||
lines[topIndex].trim());
|
||||
return;
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
topIndex + 1,
|
||||
linesBelow,
|
||||
i,
|
||||
"Below",
|
||||
lines[topIndex].trim(),
|
||||
null,
|
||||
{
|
||||
"lineNumber": nextIndex + 1,
|
||||
"insertText": "\n"
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
20
lib/md031.js
20
lib/md031.js
|
|
@ -14,10 +14,22 @@ module.exports = {
|
|||
const includeListItems = (listItems === undefined) ? true : !!listItems;
|
||||
const { lines } = params;
|
||||
forEachLine(lineMetadata(), (line, i, inCode, onFence, inTable, inItem) => {
|
||||
if ((((onFence > 0) && !isBlankLine(lines[i - 1])) ||
|
||||
((onFence < 0) && !isBlankLine(lines[i + 1]))) &&
|
||||
(includeListItems || !inItem)) {
|
||||
addErrorContext(onError, i + 1, lines[i].trim());
|
||||
const onTopFence = (onFence > 0);
|
||||
const onBottomFence = (onFence < 0);
|
||||
if ((includeListItems || !inItem) &&
|
||||
((onTopFence && !isBlankLine(lines[i - 1])) ||
|
||||
(onBottomFence && !isBlankLine(lines[i + 1])))) {
|
||||
addErrorContext(
|
||||
onError,
|
||||
i + 1,
|
||||
lines[i].trim(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
{
|
||||
"lineNumber": i + (onTopFence ? 1 : 2),
|
||||
"insertText": "\n"
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
29
lib/md032.js
29
lib/md032.js
|
|
@ -5,6 +5,8 @@
|
|||
const { addErrorContext, isBlankLine } = require("../helpers");
|
||||
const { flattenedLists } = require("./cache");
|
||||
|
||||
const quotePrefixRe = /^[>\s]*/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD032", "blanks-around-lists" ],
|
||||
"description": "Lists should be surrounded by blank lines",
|
||||
|
|
@ -14,11 +16,34 @@ module.exports = {
|
|||
flattenedLists().filter((list) => !list.nesting).forEach((list) => {
|
||||
const firstIndex = list.open.map[0];
|
||||
if (!isBlankLine(lines[firstIndex - 1])) {
|
||||
addErrorContext(onError, firstIndex + 1, lines[firstIndex].trim());
|
||||
const line = lines[firstIndex];
|
||||
const quotePrefix = line.match(quotePrefixRe)[0].trimEnd();
|
||||
addErrorContext(
|
||||
onError,
|
||||
firstIndex + 1,
|
||||
line.trim(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
{
|
||||
"insertText": `${quotePrefix}\n`
|
||||
});
|
||||
}
|
||||
const lastIndex = list.lastLineIndex - 1;
|
||||
if (!isBlankLine(lines[lastIndex + 1])) {
|
||||
addErrorContext(onError, lastIndex + 1, lines[lastIndex].trim());
|
||||
const line = lines[lastIndex];
|
||||
const quotePrefix = line.match(quotePrefixRe)[0].trimEnd();
|
||||
addErrorContext(
|
||||
onError,
|
||||
lastIndex + 1,
|
||||
line.trim(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
{
|
||||
"lineNumber": lastIndex + 2,
|
||||
"insertText": `${quotePrefix}\n`
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue