|
| 1 | +--- |
| 2 | +name: markdown-lint |
| 3 | +description: 'Lint and format Markdown files using markdownlint-cli2 and markdown-table-formatter. Use when checking or fixing Markdown formatting, table alignment, or markdownlint rule violations after editing .md files.' |
| 4 | +argument-hint: 'Optional: the path(s) or glob of Markdown files to lint — or leave blank to lint files you changed' |
| 5 | +user-invocable: true |
| 6 | +--- |
| 7 | + |
| 8 | +# Lint Markdown |
| 9 | + |
| 10 | +Check and fix Markdown formatting using the repository's two Markdown tools, driven by `pnpm`. |
| 11 | + |
| 12 | +## Overview |
| 13 | + |
| 14 | +Markdown quality is enforced by two tools, both installed as dev dependencies in the root `package.json`: |
| 15 | + |
| 16 | +- **`markdownlint-cli2`** — applies the markdownlint rules in [`.github/linters/.markdownlint-cli2.yaml`](../../linters/.markdownlint-cli2.yaml), which extends [`.github/linters/.markdownlint.yml`](../../linters/.markdownlint.yml). It honors the `ignores`/`gitignore` settings in that config (so `node_modules`, `.git`, etc. are skipped automatically). |
| 17 | +- **`markdown-table-formatter`** — normalizes Markdown table alignment and padding. It has no config file and only accepts CLI flags (`--check`, `--columnpadding`, `--verbose`). It does **not** read `.gitignore`, so scope it to specific files or directories rather than the whole tree. |
| 18 | + |
| 19 | +## Prerequisites |
| 20 | + |
| 21 | +1. **Node.js + pnpm**: pnpm is pinned via the `packageManager` field in `package.json`. If pnpm is missing, run `corepack enable pnpm`. |
| 22 | +2. **Install dependencies**: run `pnpm install --frozen-lockfile` from the repository root so the tool binaries are available. |
| 23 | + |
| 24 | +## Procedure |
| 25 | + |
| 26 | +### Step 1: Determine the scope |
| 27 | + |
| 28 | +Prefer linting only the files you changed instead of the entire repository. |
| 29 | + |
| 30 | +- For changed files: `git diff --name-only --diff-filter=d HEAD '*.md'` |
| 31 | +- For a directory: use a glob such as `"docs/**/*.md"`. |
| 32 | +- Avoid passing `"./**/*.md"` to `markdown-table-formatter` — it will traverse `node_modules` because it does not respect `.gitignore`. |
| 33 | + |
| 34 | +### Step 2: Check (read-only) |
| 35 | + |
| 36 | +Run both tools in check mode. Replace `<glob-or-paths>` with the scope from Step 1. |
| 37 | + |
| 38 | +```bash |
| 39 | +# Check table formatting (exits non-zero if any table needs reformatting) |
| 40 | +pnpm exec markdown-table-formatter "<glob-or-paths>" --check |
| 41 | + |
| 42 | +# Check markdownlint rules |
| 43 | +pnpm exec markdownlint-cli2 "<glob-or-paths>" --config "./.github/linters/.markdownlint-cli2.yaml" |
| 44 | +``` |
| 45 | + |
| 46 | +### Step 3: Fix |
| 47 | + |
| 48 | +Apply automatic fixes, then re-run the checks in Step 2 to confirm a clean result. |
| 49 | + |
| 50 | +```bash |
| 51 | +# Reformat tables in place |
| 52 | +pnpm exec markdown-table-formatter "<glob-or-paths>" |
| 53 | + |
| 54 | +# Auto-fix markdownlint violations where possible |
| 55 | +pnpm exec markdownlint-cli2 "<glob-or-paths>" --config "./.github/linters/.markdownlint-cli2.yaml" --fix |
| 56 | +``` |
| 57 | + |
| 58 | +### Step 4: Resolve remaining issues |
| 59 | + |
| 60 | +Not every markdownlint rule is auto-fixable. For violations that remain after Step 3, edit the Markdown manually following the rule messages. Do not hard-wrap prose to satisfy line length — the MD013 line-length rule is intentionally disabled (see the Markdown authoring guidelines in `.github/instructions/markdown.instructions.md`). |
| 61 | + |
| 62 | +### Step 5: Report result |
| 63 | + |
| 64 | +Summarize what was checked, what was fixed automatically, and any violations that require manual attention. |
| 65 | + |
| 66 | +## Quick Reference |
| 67 | + |
| 68 | +| Goal | Command | |
| 69 | +|-----------------------------|---------------------------------------------------------------------------------------------------| |
| 70 | +| Check table formatting | `pnpm exec markdown-table-formatter "<glob>" --check` | |
| 71 | +| Fix table formatting | `pnpm exec markdown-table-formatter "<glob>"` | |
| 72 | +| Check markdownlint rules | `pnpm exec markdownlint-cli2 "<glob>" --config "./.github/linters/.markdownlint-cli2.yaml"` | |
| 73 | +| Fix markdownlint rules | `pnpm exec markdownlint-cli2 "<glob>" --config "./.github/linters/.markdownlint-cli2.yaml" --fix` | |
| 74 | +| List changed Markdown files | `git diff --name-only --diff-filter=d HEAD '*.md'` | |
0 commit comments