markdown/no-unused-definitions
Disallow unused definitions
A definition that no link or image uses is invisible in the rendered document. It's either left over from text that was removed, or the link that should use it has a typo. 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-unused-definitions": "error" },
},
];It also works with markdown/gfm.
Examples#
example.md1 problem
Read the guide.
[guide]: https://example.com/guideUnexpected unused definition guide (label: guide) found.example.md1 problem
It is fast.
[^1]: On Linux.Unexpected unused footnote definition 1 (label: 1) found.example.mdNo problems
Read the [guide].
[guide]: https://example.com/guideOptions#
| Option | Default | What it does |
|---|---|---|
allowDefinitions | ["//"] | Labels that don't have to be used. |
allowFootnoteDefinitions | [] | Footnote labels that don't have to be used. |
checkFootnoteDefinitions | true | Check footnote definitions too. |
[//]: # (text) is a common way to write a comment, which is why // is allowed:
example.mdNo problems
[//]: # (This is a comment)example.mdwith
{ "allowDefinitions": ["guide"] }No problems[guide]: https://example.com/guide