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