remark-lint-definition-sort
raw JSON → 1.0.1 verified Fri May 01 auth: no javascript
A remark-lint rule that warns when markdown definitions (including footnote definitions) are not sorted alphabetically. Version 1.0.1 is current, released as part of the remark-lint monorepo. It requires remark-lint and unified, and is ESM-only since Node 16+. Unlike general linters, it enforces a consistent order for 'definition' nodes (e.g., [label]: url), helping maintain readability in long lists. Definitions and footnotes are sorted separately, and 'groups' separated by non-definition content are sorted independently.
Common errors
error Cannot find module 'remark-lint-definition-sort' Require stack: - /path/to/project/... ↓
cause Using CommonJS require() on an ESM-only package.
fix
Use import syntax or set "type": "module" in package.json.
error TypeError: remarkLintDefinitionSort is not a function ↓
cause Using named import instead of default import.
fix
Change to 'import remarkLintDefinitionSort from 'remark-lint-definition-sort'' (default import).
Warnings
breaking ESM-only: Package does not support CommonJS require(); must use import syntax. ↓
fix Switch to ESM (import) or downgrade to a hypothetical CJS version (none exists).
deprecated This rule is not part of any preset; may be superseded by a combined rule in the future. ↓
fix No action needed; monitor remark-lint releases for combined definitions linting.
gotcha Footnotes and definitions are sorted separately: mixing them may produce unexpected 'unsorted' warnings. ↓
fix Ensure footnotes are in a separate block from regular definitions.
gotcha Groups of definitions separated by non-definition content are sorted independently; sorting is not global across the entire file. ↓
fix If you need strict global sorting, avoid separating definitions with paragraphs.
Install
npm install remark-lint-definition-sort yarn add remark-lint-definition-sort pnpm add remark-lint-definition-sort Imports
- remarkLintDefinitionSort wrong
const remarkLintDefinitionSort = require('remark-lint-definition-sort')correctimport remarkLintDefinitionSort from 'remark-lint-definition-sort' - default export wrong
import { remarkLintDefinitionSort } from 'remark-lint-definition-sort'correctimport remarkLintDefinitionSort from 'remark-lint-definition-sort' - types wrong
import { Plugin } from 'remark-lint-definition-sort'correctimport type { Plugin } from 'unified' // no types exported from this package
Quickstart
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
import remarkLint from 'remark-lint';
import remarkLintDefinitionSort from 'remark-lint-definition-sort';
import { read } from 'to-vfile';
import { reporter } from 'vfile-reporter';
const file = await read('example.md');
await unified()
.use(remarkParse)
.use(remarkLint)
.use(remarkLintDefinitionSort)
.use(remarkStringify)
.process(file);
console.error(reporter(file));