remark-lint-table-cell-padding

raw JSON →
5.1.1 verified Fri May 01 auth: no javascript

remark-lint rule to warn when GFM table cells are padded inconsistently. Version 5.1.1, part of the remark-lint ecosystem, maintained by the remark organization. It checks whether cells have compact (no spaces around content) or padded (at least one space) style. Supports 'consistent' mode to detect first style, and custom stringLength function for wide characters. ESM-only, requires Node 16+, and needs remark-gfm for GFM table parsing.

error Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported.
cause Package is ESM-only and cannot be required with CommonJS require().
fix
Change to import statement and ensure project is ESM or use dynamic import().
error Cannot find module 'remark-gfm'
cause Missing dependency remark-gfm required to parse GFM tables.
fix
Install remark-gfm: npm install remark-gfm and add .use(remarkGfm) to pipeline.
error Warning: ... Cell padding Cell should be padded ...
cause Table cells do not have spaces around content when style is 'padded'.
fix
Add spaces: | a | instead of |a|.
breaking Package is ESM-only since version 5.0.0. Requires Node.js 16+ and cannot be required with CommonJS.
fix Use import syntax or switch to dynamic import(). Ensure Node.js >=16.
gotcha The rule only works if remark-gfm is used to parse GFM tables. Without it, tables are not parsed and the rule does nothing.
fix Add remark-gfm to your unified pipeline: .use(remarkGfm).
gotcha The 'stringLength' option must be provided when using non-standard characters (e.g., emoji, CJK) to correctly measure cell width.
fix Pass a function like stringLength: s => [...s].length or use string-width package.
deprecated Passing a string like 'padded' directly as options is deprecated in favor of an object with style property.
fix Use { style: 'padded' } instead of just 'padded'.
gotcha The 'consistent' style uses the first cell's padding style. If the first cell is mis-padded, it may not warn correctly.
fix Explicitly set style to 'padded' or 'compact' when known.
npm install remark-lint-table-cell-padding
yarn add remark-lint-table-cell-padding
pnpm add remark-lint-table-cell-padding

Shows how to set up the lint rule with unified, enabling GFM tables and using 'padded' style.

import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
import remarkLint from 'remark-lint';
import remarkGfm from 'remark-gfm';
import remarkLintTableCellPadding from 'remark-lint-table-cell-padding';
import { reporter } from 'vfile-reporter';

const file = await unified()
  .use(remarkParse)
  .use(remarkGfm)
  .use(remarkLint)
  .use(remarkLintTableCellPadding, 'padded')
  .use(remarkStringify)
  .process('| a |\n| - |');

console.error(reporter(file));
// Logs: 1:3-1:6 warning Cell padding Cell should be padded remark-lint-table-cell-padding