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/v2
example.md1 problem
It is fast.[^1]

[^1]: On Linux.
[^1]: On macOS.
example.mdNo problems
Read the [guide] and the [reference].

[guide]: https://example.com/guide
[reference]: https://example.com/reference

Options#

OptionDefaultWhat it does
allowDefinitions["//"]Labels that may be defined more than once.
allowFootnoteDefinitions[]Footnote labels that may be defined more than once.
checkFootnoteDefinitionstrueCheck 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 problems
It is fast.[^1]

[^1]: On Linux.
[^1]: On macOS.