Disallow duplicate definitions.
In Markdown, it's possible to define the same definition identifier multiple times. However, this is usually a mistake, as it can lead to unintended or incorrect link, image, and footnote references.
Please note that this rule does not report definition-style comments. For example:
[//]: # (This is a comment 1)
[//]: <> (This is a comment 2)Important
The footnotes are only supported when using language mode markdown/gfm.
This rule warns when Definition and FootnoteDefinition type identifiers are defined multiple times. Please note that this rule is case-insensitive, meaning earth and Earth are treated as the same identifier.
Examples of incorrect code:
<!-- eslint markdown/no-duplicate-definitions: "error" -->
<!-- definition -->
[mercury]: https://example.com/mercury/
[mercury]: https://example.com/venus/
[earth]: https://example.com/earth/
[Earth]: https://example.com/mars/
<!-- footnote definition -->
[^mercury]: Hello, Mercury!
[^mercury]: Hello, Venus!
[^earth]: Hello, Earth!
[^Earth]: Hello, Mars!Examples of correct code:
<!-- eslint markdown/no-duplicate-definitions: "error" -->
<!-- definition -->
[mercury]: https://example.com/mercury/
[venus]: https://example.com/venus/
<!-- footnote definition -->
[^mercury]: Hello, Mercury!
[^venus]: Hello, Venus!
<!-- definition-style comment -->
[//]: # (This is a comment 1)
[//]: <> (This is a comment 2)The following options are available on this rule:
-
allowDefinitions: Array<string>- when specified, duplicate definitions are allowed if they match one of the identifiers in this array. This is useful for ignoring definitions that are intentionally duplicated. (default:["//"])Examples of correct code when configured as
"no-duplicate-definitions": ["error", { allowDefinitions: ["mercury"] }]:<!-- eslint markdown/no-duplicate-definitions: ["error", { allowDefinitions: ["mercury"] }] --> [mercury]: https://example.com/mercury/ [mercury]: https://example.com/venus/
-
allowFootnoteDefinitions: Array<string>- when specified, duplicate footnote definitions are allowed if they match one of the identifiers in this array. This is useful for ignoring footnote definitions that are intentionally duplicated. (default:[])Examples of correct code when configured as
"no-duplicate-definitions": ["error", { allowFootnoteDefinitions: ["mercury"] }]:<!-- eslint markdown/no-duplicate-definitions: ["error", { allowFootnoteDefinitions: ["mercury"] }] --> [^mercury]: Hello, Mercury! [^mercury]: Hello, Venus!
-
checkFootnoteDefinitions: boolean- When set tofalse, the rule will not report duplicate footnote definitions. (default:true)Examples of correct code when configured as
"no-duplicate-definitions": ["error", { checkFootnoteDefinitions: false }]:<!-- eslint markdown/no-duplicate-definitions: ["error", { checkFootnoteDefinitions: false }] --> [^mercury]: Hello, Mercury! [^mercury]: Hello, Venus!
If you are using a different style of definition comments, or not concerned with duplicate definitions, you can safely disable this rule.