remark-lint-no-duplicate-defined-urls

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

A remark-lint rule that warns when the same URL is defined multiple times in Markdown definitions. Current stable version is 3.0.1. It is part of the remark-lint ecosystem, focusing on detecting duplicate URLs to prevent mistakes. Unlike other lint rules that check for unused definitions, this targets duplicate URLs. It is ESM-only and requires Node.js 16+. Released as part of the remark-lint monorepo with regular updates.

error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/remark-lint-no-duplicate-defined-urls/index.js not supported.
cause Using CommonJS require() to load an ESM-only package.
fix
Change to import statement or use dynamic import().
error Unexpected definition with an already defined URL (as `mercury`), expected unique URLs
cause Two definitions in the Markdown file point to the same URL.
fix
Remove or rename one of the duplicate definitions.
error TypeError: remarkLintNoDuplicateDefinedUrls is not a function
cause Using named import { remarkLintNoDuplicateDefinedUrls } instead of default import.
fix
Remove curly braces: import remarkLintNoDuplicateDefinedUrls from ...
breaking Package is ESM-only since v3. CommonJS require will fail.
fix Use import syntax instead of require().
deprecated Support for Node.js versions below 16 is dropped as of v3.
fix Upgrade Node.js to v16 or later.
gotcha The package is a default export, not a named export. Using named import will result in undefined.
fix Use default import: import remarkLintNoDuplicateDefinedUrls from 'remark-lint-no-duplicate-defined-urls'
gotcha This rule must be used with remark-lint; it will not work if remark-lint is not in the plugin chain.
fix Ensure .use(remarkLint) is called before this rule.
npm install remark-lint-no-duplicate-defined-urls
yarn add remark-lint-no-duplicate-defined-urls
pnpm add remark-lint-no-duplicate-defined-urls

Set up remark-lint with the no-duplicate-defined-urls rule, parse a Markdown file, and report any lint messages.

import remarkLint from 'remark-lint'
import remarkLintNoDuplicateDefinedUrls from 'remark-lint-no-duplicate-defined-urls'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import { read } from 'to-vfile'
import { unified } from 'unified'
import { reporter } from 'vfile-reporter'

const file = await read('example.md')

await unified()
  .use(remarkParse)
  .use(remarkLint)
  .use(remarkLintNoDuplicateDefinedUrls)
  .use(remarkStringify)
  .process(file)

console.error(reporter(file))