remark-lint-no-duplicate-headings-in-section

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

A remark-lint rule that warns when the same heading text appears multiple times within a single section. Version 4.0.1 is the current stable release. This package is part of the remark-lint ecosystem, which provides a variety of linting rules for markdown. It helps ensure heading uniqueness per section, catching potential duplication mistakes. Unlike other lint rules that check overall duplicate headings, this rule scopes duplicates to sections, allowing the same heading text in different sections. It supports MDX and is ESM-only from version 4+. Install via npm, use with unified processor or CLI.

error Error [ERR_REQUIRE_ESM]: require() of ES Module
cause Using require() on an ESM-only package.
fix
Import using import syntax or use dynamic import().
error TypeError: remarkLintNoDuplicateHeadingsInSection is not a function
cause Using named import instead of default import.
fix
Use default import: import remarkLintNoDuplicateHeadingsInSection from 'remark-lint-no-duplicate-headings-in-section'
error Cannot find module 'remark-lint-no-duplicate-headings-in-section'
cause Package not installed in node_modules.
fix
Run npm install remark-lint-no-duplicate-headings-in-section
breaking Package is ESM-only since version 4.0.0. CommonJS require() will fail.
fix Switch to import syntax. Use dynamic import() if necessary.
gotcha The rule does not check for duplicate headings across different sections; only within the same section, respecting heading hierarchy.
fix Understand that duplicate headings in different sections are allowed. Use remark-lint-no-duplicate-headings if you want global uniqueness.
deprecated No deprecation warnings as of version 4.0.1.
fix N/A
npm install remark-lint-no-duplicate-headings-in-section
yarn add remark-lint-no-duplicate-headings-in-section
pnpm add remark-lint-no-duplicate-headings-in-section

Shows how to use the rule with unified to detect duplicate headings in a section.

import { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import remarkLint from 'remark-lint'
import remarkLintNoDuplicateHeadingsInSection from 'remark-lint-no-duplicate-headings-in-section'
import { reporter } from 'vfile-reporter'

const file = await unified()
  .use(remarkParse)
  .use(remarkLint)
  .use(remarkLintNoDuplicateHeadingsInSection)
  .use(remarkStringify)
  .process('# Planets\n\n## Mars\n\n### Discovery\n\n### Discovery')

console.error(reporter(file))