This document explains the pre-commit hooks and recommended tools configured for this project.
Husky makes managing Git hooks easy. It runs scripts before commits, pushes, and other Git operations.
Instead of linting all files, lint-staged only runs linters on files you've staged for commit, making checks much faster.
Validates that your commit messages follow the Conventional Commits standard.
Runs before every commit:
- ✅ ESLint - Fixes and lints staged JavaScript/TypeScript files
- ✅ Prettier - Formats staged files
- ✅ Type Check - Runs TypeScript compiler to catch type errors
Runs after you write your commit message:
- ✅ Commitlint - Validates commit message format
Runs before pushing to remote:
- ✅ Tests - Runs the entire test suite
- ✅ Build - Ensures production build succeeds
Run the following command to install all dependencies:
npm installThe prepare script will automatically set up husky hooks after installation.
Just commit as usual. The hooks will run automatically:
git add .
git commit -m "feat: add new feature"Or use the Commitizen helper:
npm run commit- Pre-commit: Lints and formats staged files, then type-checks
- Commit-msg: Validates your commit message format
- If any check fails, the commit is aborted
If you absolutely need to bypass hooks:
git commit --no-verify -m "emergency fix"The .lintstagedrc.json file defines what runs on staged files:
{
"*.{js,jsx,ts,tsx}": [
"eslint --fix",
"prettier --write"
],
"*.{json,md,css}": [
"prettier --write"
]
}npm run lint- Lint all filesnpm run lint-staged- Lint only staged files (used by pre-commit hook)npm run type-check- Run TypeScript type checkingnpm run test- Run test suitenpm run build- Build production bundlenpm run commit- Use Commitizen for guided commit messages
Helps maintain consistent coding styles across different editors.
Create .editorconfig file:
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false-
npm-check-updates - Keep dependencies up to date
npx npm-check-updates -u
-
depcheck - Find unused dependencies
npx depcheck
- SonarQube/SonarCloud - Already configured! (
sonar-project.properties) - CodeQL - GitHub's semantic code analysis (add via GitHub Actions)
Consider adding to your CI pipeline:
- Lighthouse CI - Performance budgets
- Bundle analyzer - Track bundle size
- Percy or Chromatic - Visual regression testing for Storybook
-
TypeDoc - Generate TypeScript documentation
npm install --save-dev typedoc
-
npm audit - Already available, run with:
npm audit npm audit fix
-
Snyk - Already configured! (
.snykfile exists)
If the build check is too slow for pre-push, edit .husky/pre-push and comment out:
# npm run build || exit 1Edit .husky/pre-commit to add more checks. Keep it fast though!
Modify .lintstagedrc.json to change what runs on staged files.
-
Ensure husky is installed:
npm install
-
Check hook permissions:
chmod +x .husky/pre-commit .husky/commit-msg .husky/pre-push
If type checking is slow, you can temporarily disable it by editing .husky/pre-commit:
# npm run type-check || exit 1Only do this temporarily! Type checking catches important errors.
Make sure your CI pipeline runs the same checks:
npm run lintnpm run type-checknpm run testnpm run build
This ensures code that passes locally will pass in CI.
This project uses Conventional Commits:
<type>(<scope>): <subject>
<body>
<footer>
Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changes (formatting)refactor: Code refactoringtest: Adding or updating testschore: Maintenance tasksperf: Performance improvementsci: CI/CD changesbuild: Build system changesrevert: Reverting changes
Examples:
feat(api): add tide prediction endpoint
fix(forecast): handle missing wind data
docs: update API documentation
test(nbdc): add tests for data parsing
chore(deps): update dependencies
- Commit frequently - Small, focused commits are easier to review
- Write clear commit messages - Use the Conventional Commits format
- Fix hook failures - Don't bypass hooks without good reason
- Keep hooks fast - Pre-commit should take < 30 seconds
- Use pre-push for slow checks - Tests and builds go here
- Review before pushing - Pre-push is your last safety check
Install recommended extensions (add to .vscode/extensions.json):
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"Orta.vscode-jest",
"ms-vscode.vscode-typescript-next"
]
}