From 005e3bbd2ae6d58ca5c3cac377da0deb56d3c34a Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 23 Sep 2021 12:31:31 +0200 Subject: [PATCH] remark-lint-table-cell-padding: fix almost empty cells Previously, for cells with just one character, which were properly aligned considering that the delimiter row also holds up space, there was an incorrect suggestion to remove spacing. --- packages/remark-lint-table-cell-padding/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/remark-lint-table-cell-padding/index.js b/packages/remark-lint-table-cell-padding/index.js index 02e625ab..4e903d8a 100644 --- a/packages/remark-lint-table-cell-padding/index.js +++ b/packages/remark-lint-table-cell-padding/index.js @@ -213,11 +213,20 @@ const remarkLintTableCellPadding = lintRule( /* c8 ignore next */ const align = node.align || [] /** @type {number[]} */ - const sizes = Array.from({length: align.length}) + const sizes = [] /** @type {Entry[]} */ const entries = [] let index = -1 + // Check align row. + // Because there’s zero to two `:`, and there must be one `-`. + while (++index < align.length) { + const alignment = align[index] + sizes[index] = alignment === 'center' ? 3 : alignment ? 2 : 1 + } + + index = -1 + // Check rows. while (++index < rows.length) { const row = rows[index] @@ -253,6 +262,8 @@ const remarkLintTableCellPadding = lintRule( // Detect max space per column. sizes[column] = Math.max( + // More cells could exist than the align row for generated tables. + /* c8 ignore next */ sizes[column] || 0, contentEnd - contentStart )