remark-lint-no-unused-definitions
raw JSON → 4.0.2 verified Fri May 01 auth: no javascript
A remark-lint rule that warns when definitions are not referenced in the document. Current version 4.0.2, part of the remark-lint monorepo, released as ESM-only. Differentiators: catches dead code (unused link/image/footnote definitions) to keep Markdown clean. Works with remark-gfm for footnotes. No options. Part of the recommended preset.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported. ↓
cause CJS require() used with ESM-only package.
fix
Use import syntax or dynamic import().
error TypeError: plugin.use is not a function ↓
cause Calling unified().use() with the default imported function incorrectly (e.g., as object instead of function).
fix
Ensure you are passing the default export directly: .use(remarkLintNoUnusedDefinitions)
error Cannot find module 'remark-lint' ↓
cause Missing peer dependency 'remark-lint'.
fix
Install remark-lint: npm install remark-lint
Warnings
breaking Package is ESM-only starting from v4.0.0. Node.js 12 no longer supported. ↓
fix Use import syntax instead of require(); upgrade Node.js to 16+.
deprecated The 'remark-lint' package is required but may be deprecated in future in favor of '@mysticatea/remark-lint' or similar. ↓
fix Ensure remark-lint is still maintained; consider alternative lint integrations.
gotcha The rule does not check references before definitions; it only warns if a definition has zero references. ↓
fix Combine with remark-lint-no-undefined-references to catch both sides.
gotcha Footnotes (GFM) are checked case-insensitively for references; a footnote reference 'mercury' matches definition '[^Mercury]'. ↓
fix Be aware of case-insensitive matching when using GFM footnotes.
Install
npm install remark-lint-no-unused-definitions yarn add remark-lint-no-unused-definitions pnpm add remark-lint-no-unused-definitions Imports
- remarkLintNoUnusedDefinitions wrong
const remarkLintNoUnusedDefinitions = require('remark-lint-no-unused-definitions')correctimport remarkLintNoUnusedDefinitions from 'remark-lint-no-unused-definitions' - default wrong
import { remarkLintNoUnusedDefinitions } from 'remark-lint-no-unused-definitions'correctimport remarkLintNoUnusedDefinitions from 'remark-lint-no-unused-definitions' - remarkLintNoUnusedDefinitions as a unified plugin
.use(remarkLintNoUnusedDefinitions)
Quickstart
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
import remarkLint from 'remark-lint';
import remarkLintNoUnusedDefinitions from 'remark-lint-no-unused-definitions';
import { reporter } from 'vfile-reporter';
const file = await unified()
.use(remarkParse)
.use(remarkLint)
.use(remarkLintNoUnusedDefinitions)
.use(remarkStringify)
.process('[mercury]: https://example.com/mercury/');
console.error(reporter(file));
// 1:1-1:40: Unexpected unused definition, expected no definition or one or more references to `mercury`