Validate documentation before preview/build. Catches YAML, MDX, broken links, and naming issues. Auto-fix available. Run this BEFORE preview or build to prevent cryptic webpack errors.
Validate documentation for Docusaurus compatibility before preview or build. Catches YAML, MDX, broken links, and naming issues that cause cryptic webpack errors. Use --fix for automatic repairs.
/plugin marketplace add anton-abyzov/specweave/plugin install sw-alternatives@specweaveValidate your documentation for Docusaurus compatibility BEFORE starting the preview server or building.
Docusaurus compilation errors are often cryptic:
Unexpected character → unquoted HTML attributeUnterminated JSX contents → unclosed tagCould not parse expression → bad YAML frontmatterThis validator catches these issues before you see webpack errors.
# Validate internal docs (default)
/sw-docs:validate
# Validate with auto-fix
/sw-docs:validate --fix
# Validate public docs
/sw-docs:validate public
# Validate specific path
/sw-docs:validate --path .specweave/docs/internal/specs
CRITICAL: Run validation BEFORE starting preview or build!
# Check which docs to validate
DOCS_TYPE="${1:-internal}" # internal or public
if [ "$DOCS_TYPE" = "public" ]; then
DOCS_PATH=".specweave/docs/public"
else
DOCS_PATH=".specweave/docs/internal"
fi
# Verify path exists
if [ ! -d "$DOCS_PATH" ]; then
echo "❌ Documentation path not found: $DOCS_PATH"
exit 1
fi
Execute the validation using the DocsValidator:
import { DocsValidator } from '../../../src/utils/docs-validator.js';
import * as path from 'path';
// Get options from command args
const autoFix = process.argv.includes('--fix');
const docsType = process.argv.find(a => a === 'public') ? 'public' : 'internal';
const docsPath = path.resolve(`.specweave/docs/${docsType}`);
// Create validator
const validator = new DocsValidator({
docsPath,
autoFix,
});
// Run validation
console.log(`\n📋 Validating ${docsType} documentation...`);
console.log(` Path: ${docsPath}\n`);
const result = await validator.validate();
// Display formatted result
console.log(DocsValidator.formatResult(result));
// Exit with error code if invalid (for CI integration)
if (!result.valid && !autoFix) {
console.log('💡 Tip: Run with --fix to auto-repair fixable issues\n');
process.exit(1);
}
Display a clear summary:
═══════════════════════════════════════════════════════════════
DOCUMENTATION VALIDATION REPORT
═══════════════════════════════════════════════════════════════
✅ Documentation is valid and ready for preview/build
Errors: 0
Warnings: 3
Info: 0
═══════════════════════════════════════════════════════════════
Or if issues found:
═══════════════════════════════════════════════════════════════
DOCUMENTATION VALIDATION REPORT
═══════════════════════════════════════════════════════════════
❌ Documentation has issues that need to be fixed
Errors: 2
Warnings: 5
Info: 0
ERRORS (must fix):
───────────────────────────────────────────────────────────────
📄 specs/FS-118E/FEATURE.md
❌ yaml_unquoted_colon:3: Unquoted colon in YAML value: title: Feature: External Sync [auto-fixable]
📄 architecture/diagrams/overview.md
❌ mdx_compatibility: Unquoted attribute: target=_blank [auto-fixable]
QUICK FIXES:
───────────────────────────────────────────────────────────────
1. Run validation with auto-fix:
/sw-docs:validate --fix
2. Or fix manually:
• YAML: Wrap values with colons in quotes
title: "Feature: Auth" (not title: Feature: Auth)
• MDX: Quote HTML attributes, close self-closing tags
target="_blank" (not target=_blank)
<br /> (not <br>)
═══════════════════════════════════════════════════════════════
--- without closing ---)title: Feature: Auth → error)target=_blank → needs quotes)<br> → needs <br />)With --fix, the validator automatically repairs:
| Issue Type | Auto-Fix Action |
|---|---|
yaml_unquoted_colon | Wraps value in quotes |
yaml_tabs | Converts tabs to spaces |
mdx_compatibility | Quotes attributes, closes tags |
Issues that cannot be auto-fixed:
Use in GitHub Actions to gate deployments:
name: Validate Docs
on:
push:
paths:
- '.specweave/docs/**'
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm install
- run: npx specweave docs:validate
# Wrong:
title: Feature: External Sync
# Correct:
title: "Feature: External Sync"
<!-- Wrong -->
<a href="..." target=_blank>Link</a>
<br>
<!-- Correct -->
<a href="..." target="_blank">Link</a>
<br />
If you see many warnings about links to CLAUDE.md, README.md, or _archive/:
Add to docusaurus.config.ts:
onBrokenLinks: 'warn', // Not 'throw'
onBrokenMarkdownLinks: 'warn',
/sw-docs:view - View docs (runs validation first)/sw-docs:build - Build docs (runs validation first)/sw-docs:health - Full documentation health report