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+findcommand - Validates against allowlist of permitted locations
- Provides helpful output with organization rules
- Supports
--fixand--strictCLI flags - Automatically excludes
node_modulesand 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:
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:
"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 READMECHANGELOG.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 directorydiscord-bot/**/*.md- Discord bot docs (optional)functions/**/*.md- Cloud Functions docs (optional)
Automatically excluded (6 patterns) โ
node_modules/**/*.md.git/**/*.mddist/**/*.mdbuild/**/*.md.next/**/*.md.github/workflows/test-data/**/*.md
Usage โ
Run checks โ
# 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 lintExample 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.mdHow It Works โ
1. File Discovery โ
- Uses
git ls-filesto get tracked files - Falls back to
findfor 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:
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) โ
- CI/CD Integration: Add
npm run lint:docs:strictto GitHub Actions workflows to enforce in PRs - Pre-commit Hook: Add to
.huskyhooks to check before commits (if using husky) - Advanced Features: Load configuration from
.docs-linter-config.jsfor dynamic settings - Custom Reporters: Add JSON/XML output modes for tool integrations
Related Documentation โ
- Documentation Linter Guide - Complete user guide
- Documentation Guidelines - Standards being enforced
- DOCS_INDEX - Documentation index
- Changelog Workflow - How to maintain CHANGELOG.md
- CONTRIBUTING.md - Contribution guidelines
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- Addedlint:docsandlint:docs:strictscripts - โ
docs/CHANGELOG.md- Added entries for 2026-01-17
Verification โ
All tests passing:
โ 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)