2024-06-01 21:32:10 -07:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const { addErrorContextForLine, isBlankLine } = require("../helpers");
|
2024-08-24 22:05:16 -07:00
|
|
|
const { filterByTypesCached } = require("./cache");
|
2024-06-01 21:32:10 -07:00
|
|
|
|
|
|
|
// eslint-disable-next-line jsdoc/valid-types
|
|
|
|
/** @type import("./markdownlint").Rule */
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD058", "blanks-around-tables" ],
|
|
|
|
"description": "Tables should be surrounded by blank lines",
|
|
|
|
"tags": [ "table" ],
|
|
|
|
"parser": "micromark",
|
|
|
|
"function": function MD058(params, onError) {
|
2024-08-24 22:05:16 -07:00
|
|
|
const { lines } = params;
|
2024-06-01 21:32:10 -07:00
|
|
|
// For every table...
|
2024-08-24 22:05:16 -07:00
|
|
|
const tables = filterByTypesCached([ "table" ]);
|
2024-06-01 21:32:10 -07:00
|
|
|
for (const table of tables) {
|
|
|
|
// Look for a blank line above the table
|
|
|
|
const firstIndex = table.startLine - 1;
|
|
|
|
if (!isBlankLine(lines[firstIndex - 1])) {
|
|
|
|
addErrorContextForLine(
|
|
|
|
onError,
|
|
|
|
// @ts-ignore
|
|
|
|
lines,
|
|
|
|
firstIndex
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// Look for a blank line below the table
|
|
|
|
const lastIndex = table.endLine - 1;
|
|
|
|
if (!isBlankLine(lines[lastIndex + 1])) {
|
|
|
|
addErrorContextForLine(
|
|
|
|
onError,
|
|
|
|
// @ts-ignore
|
|
|
|
lines,
|
|
|
|
lastIndex,
|
|
|
|
lastIndex + 2
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|