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.

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).
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.
npm install remark-lint-definition-sort
yarn add remark-lint-definition-sort
pnpm add remark-lint-definition-sort

Demonstrates how to programmatically lint markdown definitions sorting using unified pipeline with remark-lint.

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));