3.9 KiB
Code Quality Setup - Team Documentation
Overview
This project uses automated code quality tools to maintain consistent code style and catch errors early:
- ESLint - Identifies code quality issues and potential bugs
- Prettier - Automatically formats code to consistent style
- Husky - Runs quality checks before commits via git hooks
- lint-staged - Only checks files you're committing (fast!)
- GitHub Actions - Verifies code quality in CI
For New Team Members
First Time Setup
After cloning the repository, run:
npm install
This automatically sets up Husky git hooks via the prepare script.
Daily Workflow
When you make changes and commit:
- Stage your files:
git add . - Commit:
git commit -m "your message" - Pre-commit hook automatically runs and checks your staged files
- If checks pass, commit succeeds
- If checks fail, fix the issues and try again
Manual Quality Checks
Run these commands any time:
# Check for linting errors
npm run lint
# Auto-fix linting issues
npm run lint:fix
# Format all files
npm run format
# Check formatting (doesn't modify files)
npm run format:check
IDE Integration
Recommended: Install ESLint and Prettier extensions in your editor:
- VS Code: Install "ESLint" and "Prettier - Code formatter" extensions
- WebStorm/IntelliJ: Enable ESLint and Prettier in Settings > Languages & Frameworks
Configure format on save in your editor for the best experience.
Common Scenarios
Pre-commit Hook Fails
Linting errors: Review the errors shown. Run npm run lint:fix to auto-fix many issues.
Formatting issues: Run npm run format to format all files, then try committing again.
Type errors: Fix TypeScript errors shown in the output. The hook prevents commits with type errors.
Bypassing Hooks (Emergency Only)
In rare cases where you need to commit despite failing checks:
git commit --no-verify -m "your message"
Warning: Only use this for emergencies. The CI will still fail if code quality checks don't pass.
Updating ESLint Rules
If you encounter a rule that doesn't make sense for your use case:
- Discuss with the team first
- Update
eslint.config.mjswith the agreed change - Run
npm run lintto verify the change works - Commit the configuration change
Troubleshooting
Hooks Not Running
If pre-commit hooks don't run when you commit:
# Reinstall Husky
rm -rf .husky
npm run prepare
Verify .husky/pre-commit exists and is executable.
ESLint Configuration Errors
If ESLint fails to run with configuration errors:
# Check your Node version (should be 18+)
node --version
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
Conflicts Between Tools
If ESLint and Prettier report conflicting issues:
- Prettier should always win for formatting issues
- Check that
eslint-config-prettieris installed - Verify it's last in the config chain to disable conflicting ESLint rules
CI Passing Locally But Failing in GitHub Actions
- Ensure you've committed all configuration files
- Verify Node.js version matches between local and CI
- Check that all devDependencies are in package.json
- Run
npm run lintandnpm run format:checklocally before pushing
Configuration Files
eslint.config.mjs- ESLint rules and configuration.prettierrc- Prettier formatting rules.prettierignore- Files Prettier should skip.husky/pre-commit- Pre-commit hook that runs lint-stagedpackage.json- Contains lint-staged configuration and scripts.github/workflows/lint.yml- CI workflow for automated checks