| name | fix-once-auto-inject |
| description | One-time fixes get repeated manually: |
| lastReviewed | 2026-04-30T00:00:00.000Z |
Fix-Once + Auto-Inject-Future
The Problem
One-time fixes get repeated manually:
- "Add the missing import to every new file"
- "Remember to set the flag when creating services"
- Relies on human memory → fails over time
The Solution
Pair an idempotent one-time fix with a build-time auto-inject fallback.
Prong 1: One-Time Fix Script
const fs = require('fs');
const glob = require('glob');
const header = '// Copyright 2026 Company\n\n';
glob.sync('src/**/*.ts').forEach(file => {
const content = fs.readFileSync(file, 'utf8');
if (!content.startsWith('// Copyright')) {
fs.writeFileSync(file, header + content);
console.log(`Fixed: ${file}`);
}
});
Run once to fix existing files.
Prong 2: Auto-Inject at Build
const files = getChangedFiles();
files.filter(f => f.endsWith('.ts')).forEach(file => {
const content = fs.readFileSync(file, 'utf8');
if (!content.startsWith('// Copyright')) {
console.error(`Missing header: ${file}`);
process.exit(1);
}
});
Git Hook Version
#!/bin/bash
for file in $(git diff --cached --name-only | grep '\.ts$'); do
if ! head -1 "$file" | grep -q "Copyright"; then
echo "Missing copyright header: $file"
exit 1
fi
done
Pattern
┌─────────────────────────────────────┐
│ Fix existing files (one-time) │
│ node scripts/fix-all.cjs │
└─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Enforce on new files (ongoing) │
│ build hook / pre-commit / CI │
└─────────────────────────────────────┘
Verification
- Running fix script on already-fixed files is idempotent
- Creating a new file without the fix fails the hook
- No manual enforcement needed after setup
When to Apply
- License headers
- Required imports
- Configuration defaults
- Any "every file must have X" rule
Tags
build automation enforcement hooks