mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Convert markdownlint library to an ECMAScript module, replace markdownlint-micromark with micromark, stop publishing (large) markdownlint-browser.js, see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c for guidance.
This commit is contained in:
parent
191226f070
commit
1e71f6f44e
140 changed files with 1087 additions and 10428 deletions
50
lib/md056.mjs
Normal file
50
lib/md056.mjs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// @ts-check
|
||||
|
||||
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
||||
import { getParentOfType } from "../helpers/micromark-helpers.cjs";
|
||||
import { filterByTypesCached } from "./cache.mjs";
|
||||
|
||||
const makeRange = (start, end) => [ start, end - start + 1 ];
|
||||
|
||||
/** @typedef {import("micromark-extension-gfm-table")} */
|
||||
|
||||
/** @type {import("./markdownlint.mjs").Rule} */
|
||||
export default {
|
||||
"names": [ "MD056", "table-column-count" ],
|
||||
"description": "Table column count",
|
||||
"tags": [ "table" ],
|
||||
"parser": "micromark",
|
||||
"function": function MD056(params, onError) {
|
||||
const rows = filterByTypesCached([ "tableDelimiterRow", "tableRow" ]);
|
||||
let expectedCount = 0;
|
||||
let currentTable = null;
|
||||
for (const row of rows) {
|
||||
const table = getParentOfType(row, [ "table" ]);
|
||||
if (currentTable !== table) {
|
||||
expectedCount = 0;
|
||||
currentTable = table;
|
||||
}
|
||||
const cells = row.children.filter((child) => [ "tableData", "tableDelimiter", "tableHeader" ].includes(child.type));
|
||||
const actualCount = cells.length;
|
||||
expectedCount ||= actualCount;
|
||||
let detail = undefined;
|
||||
let range = undefined;
|
||||
if (actualCount < expectedCount) {
|
||||
detail = "Too few cells, row will be missing data";
|
||||
range = [ row.endColumn - 1, 1 ];
|
||||
} else if (expectedCount < actualCount) {
|
||||
detail = "Too many cells, extra data will be missing";
|
||||
range = makeRange(cells[expectedCount].startColumn, row.endColumn - 1);
|
||||
}
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
row.endLine,
|
||||
expectedCount,
|
||||
actualCount,
|
||||
detail,
|
||||
undefined,
|
||||
range
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue