remark-lint-no-duplicate-definitions

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

A remark-lint rule that warns when identifiers (footnotes, links, etc.) are defined multiple times in Markdown documents. Current stable version is 4.0.1 (ESM-only, requires Node.js 16+). Part of the remark-lint ecosystem, included in `remark-preset-lint-recommended`. It helps catch mistakes where the same identifier is used for different definitions, ensuring uniqueness. Unlike custom checks, this rule integrates seamlessly with remark's unified pipeline and provides clear, standardized error messages.

error Unexpected definition with an already defined identifier (`mercury`), expected unique identifiers
cause The same identifier is defined more than once in the Markdown document.
fix
Remove duplicate definitions or rename one of the identifiers to be unique.
error TypeError: remarkLintNoDuplicateDefinitions is not a function
cause Using named import instead of default import.
fix
Use import remarkLintNoDuplicateDefinitions from 'remark-lint-no-duplicate-definitions' (no curly braces).
error ERR_REQUIRE_ESM: require() of ES Module not supported
cause Trying to require() the package in a CommonJS context.
fix
Use dynamic import() or switch to ESM (e.g., set type: module in package.json).
breaking Package is now ESM-only. Requires Node.js 16+ and cannot be required with CommonJS require() directly.
fix Use import syntax or dynamic import(). If you must use require, set type: module in package.json or use .mjs extension.
deprecated The previous option allowDuplicates is removed in v4. The rule now always warns on duplicates.
fix If you need to allow duplicates, consider using a custom rule or ignore messages via remark-lint options.
gotcha The rule does not check cross-case duplicates. Identifiers are case-sensitive.
fix Ensure identifiers match exactly. If you need case-insensitive checking, use a custom rule or additional linting.
gotcha The rule only checks definitions, not references. Defining the same identifier multiple times will warn, but references are not validated.
fix Use remark-lint-no-undefined-references to catch missing definitions, and ensure uniqueness via this rule.
npm install remark-lint-no-duplicate-definitions
yarn add remark-lint-no-duplicate-definitions
pnpm add remark-lint-no-duplicate-definitions

Demonstrates how to use the rule to detect duplicate definitions. The input has two identical identifiers (mercury) and the output will show a warning.

import { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkLint from 'remark-lint'
import remarkLintNoDuplicateDefinitions from 'remark-lint-no-duplicate-definitions'
import remarkStringify from 'remark-stringify'
import { reporter } from 'vfile-reporter'

const file = await unified()
  .use(remarkParse)
  .use(remarkLint)
  .use(remarkLintNoDuplicateDefinitions)
  .use(remarkStringify)
  .process('[mercury]: https://example.com/mercury/\n[mercury]: https://example.com/venus/')

console.error(reporter(file))