mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-26 18:48:48 +01:00
Add new rule MD058/blanks-around-tables (fixes #132).
This commit is contained in:
parent
5ecdb045a5
commit
26466108e9
27 changed files with 914 additions and 76 deletions
33
lib/md032.js
33
lib/md032.js
|
|
@ -2,28 +2,12 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addErrorContext, blockquotePrefixRe, isBlankLine } = require("../helpers");
|
||||
const { addErrorContextForLine, isBlankLine } = require("../helpers");
|
||||
const { filterByPredicate, nonContentTokens } = require("../helpers/micromark.cjs");
|
||||
|
||||
const isList = (token) => (
|
||||
(token.type === "listOrdered") || (token.type === "listUnordered")
|
||||
);
|
||||
const addBlankLineError = (onError, lines, lineIndex, lineNumber) => {
|
||||
const line = lines[lineIndex];
|
||||
const quotePrefix = line.match(blockquotePrefixRe)[0].trimEnd();
|
||||
addErrorContext(
|
||||
onError,
|
||||
lineIndex + 1,
|
||||
line.trim(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
{
|
||||
lineNumber,
|
||||
"insertText": `${quotePrefix}\n`
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("./markdownlint").Rule */
|
||||
|
|
@ -53,7 +37,12 @@ module.exports = {
|
|||
// Look for a blank line above the list
|
||||
const firstIndex = list.startLine - 1;
|
||||
if (!isBlankLine(lines[firstIndex - 1])) {
|
||||
addBlankLineError(onError, lines, firstIndex);
|
||||
addErrorContextForLine(
|
||||
onError,
|
||||
// @ts-ignore
|
||||
lines,
|
||||
firstIndex
|
||||
);
|
||||
}
|
||||
|
||||
// Find the "visual" end of the list
|
||||
|
|
@ -69,7 +58,13 @@ module.exports = {
|
|||
// Look for a blank line below the list
|
||||
const lastIndex = endLine - 1;
|
||||
if (!isBlankLine(lines[lastIndex + 1])) {
|
||||
addBlankLineError(onError, lines, lastIndex, lastIndex + 2);
|
||||
addErrorContextForLine(
|
||||
onError,
|
||||
// @ts-ignore
|
||||
lines,
|
||||
lastIndex,
|
||||
lastIndex + 2
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue