markdown/no-duplicate-definitions
Disallow duplicate definitions
When two definitions have the same label, the first one wins and the others are silently ignored. Links then don't go where the latest edit intended. Labels are compared the way Markdown compares them: case and the amount of whitespace don't matter.
In markdown/gfm the same goes for footnote definitions.
Configure#
Off by default. It needs an ESLint config that says which files are in the language:
eslint.config.js
import markdown from "@eslint/markdown";
export default [
{
files: ["**/*.md"],
plugins: { markdown },
language: "markdown/commonmark",
rules: { "markdown/no-duplicate-definitions": "error" },
},
];It also works with markdown/gfm.
Examples#
example.md1 problem
Read the [guide].
[guide]: https://example.com/v1
[Guide]: https://example.com/v2Unexpected duplicate definition guide (label: Guide) found. First defined at line 3 (label: guide).example.md1 problem
It is fast.[^1]
[^1]: On Linux.
[^1]: On macOS.Unexpected duplicate footnote definition 1 (label: 1) found. First defined at line 3 (label: 1).example.mdNo problems
Read the [guide] and the [reference].
[guide]: https://example.com/guide
[reference]: https://example.com/referenceOptions#
| Option | Default | What it does |
|---|---|---|
allowDefinitions | ["//"] | Labels that may be defined more than once. |
allowFootnoteDefinitions | [] | Footnote labels that may be defined more than once. |
checkFootnoteDefinitions | true | Check footnote definitions too. |
[//]: # (text) is a common way to write a comment, which is why // is allowed:
example.mdNo problems
[//]: # (First comment)
[//]: # (Second comment)example.mdwith
{ "checkFootnoteDefinitions": false }No problemsIt is fast.[^1]
[^1]: On Linux.
[^1]: On macOS.