mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-01-28 01:46:09 +01:00
Add rule MD056/table-column-count (fixes #92).
This commit is contained in:
parent
f694a56254
commit
30d62f19ac
26 changed files with 1748 additions and 298 deletions
10
lib/configuration.d.ts
vendored
10
lib/configuration.d.ts
vendored
|
|
@ -1070,6 +1070,14 @@ export interface Configuration {
|
|||
*/
|
||||
style?: "consistent" | "leading_only" | "trailing_only" | "leading_and_trailing" | "no_leading_or_trailing";
|
||||
};
|
||||
/**
|
||||
* MD056/table-column-count : Table column count : https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md056.md
|
||||
*/
|
||||
MD056?: boolean;
|
||||
/**
|
||||
* MD056/table-column-count : Table column count : https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md056.md
|
||||
*/
|
||||
"table-column-count"?: boolean;
|
||||
/**
|
||||
* headings : MD001, MD003, MD018, MD019, MD020, MD021, MD022, MD023, MD024, MD025, MD026, MD036, MD041, MD043
|
||||
*/
|
||||
|
|
@ -1163,7 +1171,7 @@ export interface Configuration {
|
|||
*/
|
||||
images?: boolean;
|
||||
/**
|
||||
* table : MD055
|
||||
* table : MD055, MD056
|
||||
*/
|
||||
table?: boolean;
|
||||
[k: string]: unknown;
|
||||
|
|
|
|||
44
lib/md056.js
Normal file
44
lib/md056.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const { addErrorDetailIf } = require("../helpers");
|
||||
const { filterByTypes } = require("../helpers/micromark.cjs");
|
||||
|
||||
const makeRange = (start, end) => [ start, end - start + 1 ];
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD056", "table-column-count" ],
|
||||
"description": "Table column count",
|
||||
"tags": [ "table" ],
|
||||
"function": function MD056(params, onError) {
|
||||
const tables = filterByTypes(params.parsers.micromark.tokens, [ "table" ]);
|
||||
for (const table of tables) {
|
||||
const rows = filterByTypes(table.children, [ "tableDelimiterRow", "tableRow" ]);
|
||||
let expectedCount = 0;
|
||||
for (const row of rows) {
|
||||
const cells = filterByTypes(row.children, [ "tableData", "tableDelimiter", "tableHeader" ]);
|
||||
const actualCount = cells.length;
|
||||
expectedCount ||= actualCount;
|
||||
let detail = null;
|
||||
let range = null;
|
||||
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,
|
||||
null,
|
||||
range
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,9 +6,11 @@ const { homepage, version } = require("./constants");
|
|||
|
||||
const rules = [
|
||||
require("./md001"),
|
||||
// md002: Deprecated and removed
|
||||
require("./md003"),
|
||||
require("./md004"),
|
||||
require("./md005"),
|
||||
// md006: Deprecated and removed
|
||||
require("./md007"),
|
||||
require("./md009"),
|
||||
require("./md010"),
|
||||
|
|
@ -52,8 +54,8 @@ const rules = [
|
|||
require("./md052"),
|
||||
require("./md053"),
|
||||
require("./md054"),
|
||||
require("./md055")
|
||||
// md056: See https://github.com/markdownlint/markdownlint
|
||||
require("./md055"),
|
||||
require("./md056")
|
||||
// md057: See https://github.com/markdownlint/markdownlint
|
||||
];
|
||||
for (const rule of rules) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue