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.
Common errors
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)
Warnings
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.
Install
npm install remark-lint-no-empty-sections yarn add remark-lint-no-empty-sections pnpm add remark-lint-no-empty-sections Imports
- default wrong
const { remarkLintNoEmptySections } = require('remark-lint-no-empty-sections')correctimport remarkLintNoEmptySections from 'remark-lint-no-empty-sections' - remark wrong
const remark = require('remark')correctimport { remark } from 'remark' - No empty sections wrong
import { noEmptySections } from 'remark-lint-no-empty-sections'correctimport remarkLintNoEmptySections from 'remark-lint-no-empty-sections'
Quickstart
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 ]