Skip to content

Commit

Permalink
remark-lint-table-cell-padding: fix almost empty cells
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wooorm committed Sep 23, 2021
1 parent 1555c25 commit 005e3bb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/remark-lint-table-cell-padding/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit 005e3bb

Please sign in to comment.