remark-lint-no-empty-sections

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

A remark-lint rule that warns when a markdown section heading has no content before the next heading of the same or higher level. This package (v4.0.0) is part of the remark-lint ecosystem and is specifically designed for enforcing formatting guidelines in free-programming-books. It is released on demand, with no fixed cadence. Unlike generic lint rules, it targets empty sections, which can occur when headings are split incorrectly or content is missing. It integrates seamlessly with remark-cli.

error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/node_modules/remark-lint-no-empty-sections/index.js ... not supported.
cause Trying to use require() with an ESM-only package, which is not allowed in Node.js 12+.
fix
Change to import statement: import remarkLintNoEmptySections from 'remark-lint-no-empty-sections';
error TypeError: remark().use(...).use is not a function
cause Using .use() after processing has started or not properly chaining.
fix
Ensure you call .use() before .process(): remark().use(remarkLint).use(remarkLintNoEmptySections).process(markdown)
breaking ESM-only since v4.0.0. CommonJS require() will throw.
fix Switch to ESM imports or use dynamic import() if needed.
breaking No longer ships TypeScript definitions; must use @types/remark-lint or declare module.
fix Install @types/remark-lint and create a .d.ts file for this plugin.
gotcha Plugin will not warn if parent heading has content but child heading is empty — only same-level empty sections are flagged.
fix Use additional lint rules (e.g., remark-lint-no-heading-punctuation) to catch other empty issues.
npm install remark-lint-no-empty-sections
yarn add remark-lint-no-empty-sections
pnpm add remark-lint-no-empty-sections

Shows how to use the plugin programmatically with ESM imports, including an example that triggers a warning.

import { remark } from 'remark';
import remarkLint from 'remark-lint';
import remarkLintNoEmptySections from 'remark-lint-no-empty-sections';

const result = await remark()
  .use(remarkLint)
  .use(remarkLintNoEmptySections)
  .process('# Title\n\n## Subsection\n\nSome content.');

console.log(result.messages);
// []

const result2 = await remark()
  .use(remarkLint)
  .use(remarkLintNoEmptySections)
  .process('# Title\n\n## Subsection\n\n### Empty Sub-sub');

console.log(result2.messages);
// [ [1:1-31:1] Empty section ]