remark-lint-maximum-heading-length

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

remark-lint rule to warn when headings are too long. Current stable version is 4.1.1 (ESM-only, requires Node.js 16+). Part of the unified/remark ecosystem, this rule enforces a maximum heading length (default 60 characters) and is included in some presets like remark-preset-lint-markdown-style-guide. Provides an optional stringLength function for custom text measurement (e.g., to count display width). Active development with regular releases coordinated across the remark-lint monorepo.

error Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported.
cause Package is ESM-only since v4, but used with require().
fix
Change require() to import or use dynamic import().
error TypeError: Cannot read properties of undefined (reading 'length')
cause Passing a number directly instead of options object in v4+.
fix
Use .use(remarkLintMaximumHeadingLength, { size: 60 }) instead of .use(remarkLintMaximumHeadingLength, 60).
breaking ESM-only since v4; CommonJS require() will throw.
fix Use import or dynamic import(). For Node.js <16, upgrade or stay on v3.
breaking Options structure changed: previously passed as number (max length), now must be an object with `size` property.
fix Change `.use(remarkLintMaximumHeadingLength, 60)` to `.use(remarkLintMaximumHeadingLength, { size: 60 })`.
deprecated Plugin no longer exports `remarkLintMaximumHeadingLength` as a named export; only default export.
fix Use default import: `import remarkLintMaximumHeadingLength from 'remark-lint-maximum-heading-length'`.
gotcha If using with a preset that overrides options, ensure your options object is merged correctly.
fix Explicitly pass options after the preset.
npm install remark-lint-maximum-heading-length
yarn add remark-lint-maximum-heading-length
pnpm add remark-lint-maximum-heading-length

Shows how to use the rule with unified, specifying a custom max heading length of 80 characters.

import remarkLint from 'remark-lint'
import remarkLintMaximumHeadingLength from 'remark-lint-maximum-heading-length'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import { read } from 'to-vfile'
import { unified } from 'unified'
import { reporter } from 'vfile-reporter'

const file = await read('example.md')

await unified()
  .use(remarkParse)
  .use(remarkLint)
  .use(remarkLintMaximumHeadingLength, { size: 80 })
  .use(remarkStringify)
  .process(file)

console.error(reporter(file))