lint-md

raw JSON →
0.2.0 verified Fri May 01 auth: no javascript

lint-md is a core library for linting Chinese markdown files using AST-based rules. Version 0.2.0 is currently the latest and only version on npm. It provides lint, fix, and getDescription APIs, supporting over 17 rules covering spacing around Chinese/English, number formatting, empty content checks, and more. Rules can be configured with severity levels (ignore/warning/error) and options. Differentiator: focuses specifically on Chinese writing conventions, unlike generic markdown linting tools.

error Cannot find module 'lint-md'
cause Package not installed or import path incorrect.
fix
Run 'npm install lint-md' and ensure import is from 'lint-md' (no subpath).
error TypeError: lint is not a function
cause Using default import instead of named import.
fix
Use 'import { lint } from "lint-md"' instead of 'import lint from "lint-md"'.
error Uncaught TypeError: fix is not a function
cause Using destructured require incorrectly in ESM context.
fix
Use 'import { fix } from "lint-md"' if using ESM.
gotcha All rules default to error level; must explicitly set rules object to ignore.
fix Pass a rules object with rule names mapped to 0, 1, or 2.
gotcha Rule options for no-long-code are only accepted when severity is an array, not a number.
fix Use [2, { length: 100, exclude: [] }] instead of { 2: {...} }.
gotcha getDescription second parameter is a language string (e.g., 'zh_CN'), not a locale object.
fix Pass string 'en_US' or 'zh_CN'.
gotcha Lint and fix work on raw markdown strings, not file paths.
fix Read file content first with fs.readFileSync().
npm install lint-md
yarn add lint-md
pnpm add lint-md

Demonstrates lint, fix, and getDescription APIs with a simple markdown example.

import { lint, fix, getDescription } from 'lint-md';

const markdown = '# Hello 中文';
const rules = { 'space-round-alphabet': 2 };
const errors = lint(markdown, rules);
console.log('Errors:', errors);
// Fix the markdown
const fixed = fix(markdown);
console.log('Fixed:', fixed);
// Get description for a rule
const desc = getDescription('space-round-alphabet', 'zh_CN');
console.log('Description:', desc);