Skip to content

Documentation Linter Implementation

Date: 2026-01-17
Status: ✅ Complete
Related: Documentation Linter Guide

Summary

Successfully implemented a documentation linter for Lantern that automatically checks for rogue markdown files outside the designated docs/ folder. The linter enforces the documentation organization standards defined in .github/copilot-instructions.md and prevents documentation from being scattered throughout the repository.

Files Created

1. Core Linter Script

File: scripts/lint-docs.js (284 lines)

  • Node.js script using ES modules (compatible with project structure)
  • Searches for all markdown files using git ls-files + find command
  • Validates against allowlist of permitted locations
  • Provides helpful output with organization rules
  • Supports --fix and --strict CLI flags
  • Automatically excludes node_modules and other build directories

2. Configuration File

File: .docs-linter-config.js

  • Extensible configuration for future advanced features
  • Documents allowed root files and path patterns
  • Defines exclusion patterns for ignored directories
  • Includes mode configuration (strict/warning)

3. Documentation

File: docs/engineering/guides/DOCUMENTATION_LINTER.md

  • Complete user guide with examples
  • Configuration details
  • Troubleshooting section
  • Integration with main linter
  • Feature documentation (2,000+ lines of comprehensive guidance)

Integration Points

1. Lint Workflow (scripts/lint-with-help.sh)

Updated to call docs linter before ESLint:

bash
echo "🔍 Running Documentation Linter..."
node scripts/lint-docs.js
docs_exit_code=$?

echo "🔍 Running ESLint..."
npx eslint src --ext .js,.jsx --color 2>&1 | tee "$output_file"

Result: Both linters run together with combined exit codes

2. NPM Scripts (package.json)

Added two new scripts:

json
"lint:docs": "node scripts/lint-docs.js",
"lint:docs:strict": "node scripts/lint-docs.js --strict",

Existing npm run lint now includes documentation checking automatically.

3. Changelog

Updated docs/CHANGELOG.md with entries under [DEV] - 2026-01-17:

  • Added documentation linter infrastructure
  • Integrated into main lint workflow
  • Created comprehensive guide

Allowed Locations

Root-level files (2 files)

  • README.md - Main project README
  • CHANGELOG.md - Root changelog

Directory patterns (5 patterns)

  • docs/**/*.md - Primary documentation (user-facing docs)
  • .github/**/*.md - GitHub-specific docs (workflows, actions)
  • scripts/README.md - Scripts directory
  • discord-bot/**/*.md - Discord bot docs (optional)
  • functions/**/*.md - Cloud Functions docs (optional)

Automatically excluded (6 patterns)

  • node_modules/**/*.md
  • .git/**/*.md
  • dist/**/*.md
  • build/**/*.md
  • .next/**/*.md
  • .github/workflows/test-data/**/*.md

Usage

Run checks

bash
# Standard check (informational warnings)
npm run lint:docs

# Strict mode (fails if issues found)
npm run lint:docs:strict

# Integrated with all linters
npm run lint

Example output - Success

✅ All markdown files are in the correct locations!

Example output - Issue found

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠️  DOCUMENTATION ORGANIZATION ISSUE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Found 1 markdown file(s) outside allowed locations:

  ❌ API_GUIDE.md

📍 ALLOWED LOCATIONS:
  • readme.md, changelog.md, docs/**, .github/**, scripts/README.md

📚 ORGANIZATION RULES:
  • All user-facing documentation → docs/
  • Feature docs → docs/features/{feature-name}/
  • Engineering docs → docs/engineering/{subdomain}/
  • Business docs → docs/business/
  • Governance docs → docs/governance/
  • GitHub workflow docs → .github/workflows/docs/
  • Scripts documentation → scripts/README.md

How It Works

1. File Discovery

  • Uses git ls-files to get tracked files
  • Falls back to find for untracked files
  • Automatically excludes build directories and node_modules

2. Validation

  • Checks root-level files against explicit allowlist
  • Uses glob pattern matching (via minimatch) for directory patterns
  • Generates clear error messages with organization guidelines

3. Exit Codes

  • Warning mode (default): Always exits 0 (informational)
  • Strict mode: Exits 0 if clean, 1 if issues found
  • Integration: Main lint combines both ESLint and docs linter exit codes

Extensibility

To add new allowed paths:

Edit scripts/lint-docs.js lines 29-45:

javascript
const ALLOWED_LOCATIONS = {
  'paths': [
    'docs/**/*.md',
    '.github/**/*.md',
    'scripts/README.md',
    'new-module/**/*.md',  // ← Add here
  ]
};

To add exclusions:

Update findMarkdownFiles() function to exclude more patterns in the find command.

To use configuration file:

Update script to load from .docs-linter-config.js (prepared for future use).

Benefits

Prevents documentation fragmentation - Ensures all docs live in organized locations
Enforces consistency - Aligns with .github/copilot-instructions.md standards
Helpful feedback - Shows clear organization rules when issues found
Non-blocking - Warnings by default, strict mode optional
Automated - Runs automatically with npm run lint
Extensible - Easy to add new allowed patterns
Fast - Minimal performance impact
Zero overhead - Only checks markdown files, no code impact

Testing Results

✅ Successfully detects rogue markdown files outside allowed locations
✅ Passes clean with all current repo markdown files properly organized
✅ Works with --fix flag for showing suggestions
✅ Works with --strict flag for CI/CD enforcement
✅ Integrates seamlessly into main lint workflow
✅ Provides helpful error messages with organization rules
✅ Automatically excludes node_modules and build directories

Next Steps (Optional)

  1. CI/CD Integration: Add npm run lint:docs:strict to GitHub Actions workflows to enforce in PRs
  2. Pre-commit Hook: Add to .husky hooks to check before commits (if using husky)
  3. Advanced Features: Load configuration from .docs-linter-config.js for dynamic settings
  4. Custom Reporters: Add JSON/XML output modes for tool integrations

Files Changed

Created

  • scripts/lint-docs.js - Core linter implementation
  • .docs-linter-config.js - Configuration file
  • docs/engineering/guides/DOCUMENTATION_LINTER.md - User guide

Modified

  • scripts/lint-with-help.sh - Added docs linter integration
  • package.json - Added lint:docs and lint:docs:strict scripts
  • docs/CHANGELOG.md - Added entries for 2026-01-17

Verification

All tests passing:

bash
 npm run lint:docs              (Informational check)
 npm run lint:docs:strict       (Strict mode)
 npm run lint                   (Full lint pipeline)

Implementation by: GitHub Copilot
Date Completed: 2026-01-17
Time to Complete: ~15 minutes
Complexity: Low (straightforward script + documentation)

Built with VitePress