Add rule MD055/table-missing-border (fixes #93, refs #1039, no generated files).

This commit is contained in:
Gabriel Kuznik 2023-12-01 12:33:48 +01:00 committed by David Anson
parent 4a52864b39
commit a563c082a5
11 changed files with 228 additions and 12 deletions

27
lib/md055.js Normal file
View file

@ -0,0 +1,27 @@
// @ts-check
"use strict";
const { addErrorContext } = require("../helpers");
const { filterByTypes } = require("../helpers/micromark.cjs");
module.exports = {
"names": [ "MD055", "table-missing-border" ],
"description": "Table is missing leading or trailing pipe character",
"tags": [ "table" ],
"function": function MD055(params, onError) {
const tables = filterByTypes(params.parsers.micromark.tokens, [ "table" ]);
for (const table of tables) {
const rows = filterByTypes(table.children, [ "tableRow", "tableDelimiterRow" ]);
for (const row of rows) {
const { startLine, text } = row;
if (!text.startsWith("|")) {
addErrorContext(onError, startLine, text, true);
}
if (!text.endsWith("|")) {
addErrorContext(onError, startLine, text, false, true);
}
}
}
}
}