This project uses Git pre-commit hooks to automatically check for formatting and build errors before each commit.
Before every commit, the following checks run automatically:
- Code Formatting - Prettier checks all TypeScript, HTML, SCSS, and JSON files
- TypeScript Compilation - Ensures no TypeScript errors
- Auto-formatting - Staged files are automatically formatted
Run the setup script:
.\setup-git-hooks.ps1Or manually:
npm install
npm run prepareThis will:
- Install husky, lint-staged, and prettier
- Initialize Git hooks
- Create the pre-commit hook
git add .
git commit -m "Your commit message"The pre-commit hook will run automatically. If any checks fail:
- The commit will be blocked
- You'll see error messages
- Fix the errors and try again
Format all files:
npm run formatCheck formatting without fixing:
npm run format:checkOnly in emergency situations:
git commit --no-verify -m "Emergency fix".prettierrc- Prettier configuration.prettierignore- Files to ignore for formattingpackage.json- Husky and lint-staged configuration.husky/pre-commit- Pre-commit hook script
File types checked:
*.ts- TypeScript files*.js- JavaScript files*.html- HTML templates*.scss- SCSS stylesheets*.css- CSS stylesheets*.json- JSON files
Excluded:
node_modules/dist/anddist-test/*.logfiles- Build artifacts
- Third-party libraries
# Reinstall hooks
npx husky install# Auto-fix all formatting issues
npm run format
# Then commit again
git add .
git commit -m "Your message"# Check errors
npx tsc --noEmit
# Fix the errors in your code
# Then commit again# Install dependencies
npm install
# Run prepare script
npm run prepareIf pre-commit checks are too slow, you can:
- Commit smaller changes more frequently
- Edit
.husky/pre-committo remove the full build check - Use
--no-verifysparingly for work-in-progress commits
Current formatting rules (.prettierrc):
- Semicolons: Yes (
;) - Quotes: Double (
") - Print Width: 80 characters
- Tab Width: 2 spaces
- Trailing Commas: ES5 compatible
- End of Line: LF (Unix-style)
To change these, edit .prettierrc.
✅ Consistent Code Style - Everyone follows the same formatting ✅ Catch Errors Early - TypeScript errors found before commit ✅ Automated - No manual formatting needed ✅ Cleaner Git History - No "fix formatting" commits ✅ Better Code Reviews - Focus on logic, not style
To disable pre-commit hooks:
# Remove the hook
rm .husky/pre-commit
# Or bypass for one commit
git commit --no-verifyNote: Only disable in emergency situations. The checks help maintain code quality.
These same checks should run in your CI/CD pipeline:
# In GitHub Actions, GitLab CI, etc.
npm run format:check
npx tsc --noEmit
npm run buildThis ensures code quality even if someone bypasses local hooks.