Skip to content

feat(docs): lint npm-run script references in docs against package.json#616

Merged
BigSimmo merged 1 commit into
mainfrom
claude/docs-script-linter
Jul 13, 2026
Merged

feat(docs): lint npm-run script references in docs against package.json#616
BigSimmo merged 1 commit into
mainfrom
claude/docs-script-linter

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 13, 2026

Copy link
Copy Markdown
Owner

What

Tier D. check-docs-links.mjs validates file paths in docs, but nothing checks the hundreds of npm run <script> references — so a renamed/removed script leaves stale instructions the agents (Codex/Claude/Cursor) then follow.

  • scripts/check-docs-script-refs.mjs — scans inline code spans + fenced blocks in README/AGENTS/docs (excluding archive/audit/dated) for npm run <script> and validates each against package.json scripts. Prose is ignored (code-only scan); placeholders and an allowlist are skipped. Pure parsePackageScripts/extractScriptRefs/findStaleRefs exported and tested.
  • docs:check-scripts npm script — advisory, like docs:check-links (not in CI, so historical docs can't block unrelated PRs).
  • tests/docs-script-refs.test.ts — 7 tests.

It caught real drift on the first run

docs/branch-review-ledger.md referenced npm run test:e2e:advisory, which main renamed to test:e2e:regression. Since that's a historical "Checks" record, I allowlisted the old name (with a note) rather than falsify the record. 262 live references now resolve.

Verification

7/7 vitest, real-docs run passes, eslint, tsc (own files clean), prettier.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a documentation validation command that checks referenced npm, pnpm, and Yarn scripts against available project scripts.
    • Reports stale script references and returns a failure status when issues are found.
  • Tests

    • Added coverage for script parsing, reference extraction, placeholders, flags, and stale-reference detection.

Tier D. check-docs-links.mjs validates file PATHS in docs but nothing checks the
hundreds of `npm run <script>` references, so a renamed/removed script leaves stale
instructions the agents then follow.

- scripts/check-docs-script-refs.mjs: scans inline code spans + fenced blocks in
  README/AGENTS/docs (excluding archive/audit/dated) for `npm run <script>` and
  validates each against package.json's scripts. Prose is ignored (code-only scan);
  placeholders and an allowlist are skipped. Pure parse/extract/validate exported.
- docs:check-scripts npm script (advisory, like docs:check-links — not in CI so
  historical docs cannot block unrelated PRs).
- tests/docs-script-refs.test.ts: 7 tests.

On first run it caught a real stale ref (`test:e2e:advisory`, renamed to
test:e2e:regression) in the branch-review-ledger; allowlisted with a note since it
is a historical "Checks" record. 262 live references now resolve.

Verified: 7/7 vitest, real-docs run passes, eslint, tsc (own files clean), prettier.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@BigSimmo
BigSimmo enabled auto-merge (squash) July 13, 2026 17:51
@supabase

supabase Bot commented Jul 13, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a docs:check-scripts npm command and a Node.js validator that scans documentation for stale package-script references. It also adds exported parsing helpers and Vitest coverage for parsing, extraction, and stale-reference filtering.

Changes

Documentation script validation

Layer / File(s) Summary
Checker configuration and parsing helpers
scripts/check-docs-script-refs.mjs
Defines scan rules and helpers for parsing package scripts, extracting references from code blocks, and filtering placeholders, allowlisted, and valid scripts.
Documentation scan and npm entry point
scripts/check-docs-script-refs.mjs, package.json
Recursively scans selected Markdown files, reports stale references, sets exit code 1 on failures, and exposes the docs:check-scripts command.
Helper behavior tests
tests/docs-script-refs.test.ts
Tests script parsing, code-only extraction, flag handling, stale references, placeholders, and allowlisted tokens.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Developer
  participant NpmScript
  participant DocumentationChecker
  participant PackageJson
  participant MarkdownFiles
  Developer->>NpmScript: run docs:check-scripts
  NpmScript->>DocumentationChecker: invoke checker
  DocumentationChecker->>PackageJson: load package scripts
  DocumentationChecker->>MarkdownFiles: scan selected Markdown files
  MarkdownFiles-->>DocumentationChecker: return script references
  DocumentationChecker-->>Developer: report stale references and exit status
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: linting npm run script references in docs against package.json.
Description check ✅ Passed The description covers the summary and verification, though it does not follow the template headings exactly or include the checkbox checklist.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/docs-script-linter

Comment @coderabbitai help to get the list of available commands.

@BigSimmo
BigSimmo merged commit ee43ecf into main Jul 13, 2026
18 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/check-docs-script-refs.mjs`:
- Around line 34-39: Update the ALLOWLIST handling in the documentation
reference checker so test:e2e:advisory is ignored only when scanning
docs/branch-review-ledger.md, while placeholder tokens remain globally allowed.
Add a regression test proving active-document references to the retired script
still fail validation outside that historical ledger.
- Around line 59-60: Update the script-name pattern in the region reference
scanning loop to include dots in matched npm, pnpm, and yarn script names,
preserving the existing allowed characters. Add a regression test covering a
dotted script name such as lint.fix and verify it is detected in documentation
references.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 80cf961e-fa4f-4cac-b736-ed4ba83a0f91

📥 Commits

Reviewing files that changed from the base of the PR and between e5bcba8 and 9f31fc5.

📒 Files selected for processing (3)
  • package.json
  • scripts/check-docs-script-refs.mjs
  • tests/docs-script-refs.test.ts

Comment on lines +34 to +39
const ALLOWLIST = new Set([
"<script>",
"<name>",
"your-script",
"test:e2e:advisory", // renamed to test:e2e:regression (2026-07); kept for historical ledger accuracy
]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Scope the retired-script exception to its historical record.

Line 38 suppresses test:e2e:advisory in every scanned file, so a newly added active-doc reference to that removed script passes validation. Keep placeholder tokens global, but apply this exception only to docs/branch-review-ledger.md (or exclude that record separately) and add a regression test.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/check-docs-script-refs.mjs` around lines 34 - 39, Update the
ALLOWLIST handling in the documentation reference checker so test:e2e:advisory
is ignored only when scanning docs/branch-review-ledger.md, while placeholder
tokens remain globally allowed. Add a regression test proving active-document
references to the retired script still fail validation outside that historical
ledger.

Comment on lines +59 to +60
for (const m of region.matchAll(/\b(?:npm|pnpm|yarn)\s+run\s+([A-Za-z0-9][A-Za-z0-9:_-]*)/g)) {
names.add(m[1]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '## scripts/check-docs-script-refs.mjs\n'
ast-grep outline scripts/check-docs-script-refs.mjs --view expanded || true
printf '\n## relevant lines\n'
nl -ba scripts/check-docs-script-refs.mjs | sed -n '1,180p'
printf '\n## search for parsePackageScripts and related tests\n'
rg -n "parsePackageScripts|check-docs-script-refs|lint\.fix|npm\\s+run|pnpm\\s+run|yarn\\s+run" -S .

Repository: BigSimmo/Database

Length of output: 898


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '## scripts/check-docs-script-refs.mjs (relevant section)\n'
sed -n '40,80p' scripts/check-docs-script-refs.mjs

printf '\n## tests and references\n'
rg -n "extractScriptRefs|parsePackageScripts|findStaleRefs|lint\\.fix|npm\\s+run|pnpm\\s+run|yarn\\s+run" -S . --glob '!**/node_modules/**'

Repository: BigSimmo/Database

Length of output: 50376


Allow dotted npm script names in docs refs. scripts/check-docs-script-refs.mjs:59-60 skips names like lint.fix, so stale references to valid package scripts are missed. Add . to the token class and cover it with a regression test.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/check-docs-script-refs.mjs` around lines 59 - 60, Update the
script-name pattern in the region reference scanning loop to include dots in
matched npm, pnpm, and yarn script names, preserving the existing allowed
characters. Add a regression test covering a dotted script name such as lint.fix
and verify it is detected in documentation references.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant