remark-lint-heading-word-length

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

A remark-lint rule that warns when headings contain too many or too few words. Version 3.0.0 is current; breaking change drops Node <20.18.0. Words are split on whitespace. Unlike the archived remark-lint-heading-length, this rule supports configurable min/max word counts. ESM-only. Part of the unified-utils monorepo with semantic-release.

error Error [ERR_REQUIRE_ESM]: require() of ES Module
cause Attempting to use CommonJS require() on ESM-only package.
fix
Replace 'const ... = require(...)' with 'import ... from ...'
error TypeError: plugin is not a function
cause Using the full npm package name as plugin key in remark config.
fix
Use 'lint-heading-word-length' instead of 'remark-lint-heading-word-length'.
breaking Minimum Node version now 20.18.0
fix Upgrade Node to 20.18.0 or later.
breaking Package is now ESM-only
fix Switch from require() to import. If you must use CommonJS, consider dynamic import() or stick with v2.x.
deprecated The old 'remark-lint-heading-length' package is archived and no longer maintained
fix Migrate to remark-lint-heading-word-length for active development and new features.
gotcha Plugin short name 'lint-heading-word-length' must be used in config (not full package name)
fix Use 'lint-heading-word-length' in .remarkrc or package.json plugins array.
npm install remark-lint-heading-word-length
yarn add remark-lint-heading-word-length
pnpm add remark-lint-heading-word-length

Loads a markdown file, lints headings for word count, and prints errors using vfile-reporter.

import { read } from 'to-vfile';
import { reporter } from 'vfile-reporter';
import { remark } from 'remark';
import remarkLint from 'remark-lint';
import lintHeadingWordLength from 'remark-lint-heading-word-length';

const file = await remark()
  .use(remarkLint)
  .use(lintHeadingWordLength, { minimumWords: 3, maximumWords: 12 })
  .process(await read('example.md'));

console.log(reporter(file));