Code Quality Setup Guide¤
This document outlines the comprehensive code quality tools and processes implemented in this project.
Overview¤
The project now includes:
- Linting: ESLint with TypeScript support
- Formatting: Prettier for consistent code style
- Testing: Jest with comprehensive coverage reporting
- Pre-commit hooks: Husky + lint-staged
- CI/CD: GitHub Actions for automated quality checks
- Security: Vulnerability scanning with Trivy
Tools Configuration¤
ESLint¤
- Backend: TypeScript-specific rules with Prettier integration
- Frontend: React Native + TypeScript rules with Prettier integration
- Rules: Strict typing, consistent styling, React best practices
Prettier¤
- Consistent code formatting across all file types
- Integration with ESLint to prevent conflicts
- Pre-commit hook ensures all code is formatted
Jest Testing¤
- Backend Coverage Thresholds: 80% (85% for agents, 75% for routes)
- Frontend Coverage Thresholds: 70% (75% for components, 80% for hooks)
- Multiple coverage formats: HTML, LCOV, JSON, Cobertura
- Separate unit and integration test configurations
Husky Pre-commit Hooks¤
- Automatic linting and formatting before commits
- TypeScript type checking
- Prevents broken code from being committed
Available Scripts¤
Root Level Commands¤
Backend Commands¤
Frontend Commands¤
Coverage Thresholds¤
Backend¤
- Global: 80% across all metrics
- Agents Module: 85% (critical business logic)
- Routes Module: 75% (API endpoints)
Frontend¤
- Global: 70% across all metrics
- Components: 75% (UI components)
- Hooks: 80% (custom React hooks)
CI/CD Integration¤
Quality Checks Workflow¤
The GitHub Actions workflow runs on every push and PR:
- Multi-Node Testing: Tests on Node.js 18.x and 20.x
- Code Formatting: Prettier format checking
- Linting: ESLint checks for all code
- Type Checking: TypeScript compilation
- Testing: Full test suite with coverage
- Security Scanning: Trivy vulnerability scan
- Dependency Audit: npm audit for security issues
- Coverage Upload: Codecov integration
Security Features¤
- Trivy Scanner: Identifies vulnerabilities in dependencies
- Dependency Audit: High-level security issue detection
- SARIF Upload: Security results integrated with GitHub
Pre-commit Process¤
When you commit code, the following happens automatically:
- lint-staged runs on changed files:
- ESLint fixes issues
- Prettier formats code
- TypeScript type checking
- Success: Commit proceeds if all checks pass
- Failure: Commit blocked with error details
Configuration Files¤
Core Configuration¤
.prettierrc
- Prettier formatting rules.prettierignore
- Files to skip formattingcodecov.yml
- Coverage reporting config.husky/pre-commit
- Pre-commit hook script
Backend Configuration¤
backend/.eslintrc.js
- ESLint rulesbackend/jest.config.js
- Jest testing config
Frontend Configuration¤
frontend/eslint.config.js
- ESLint rulesfrontend/jest.config.js
- Jest testing configfrontend/jest.setup.js
- Test environment setup
Getting Started¤
-
Install Dependencies:
-
Setup Git Hooks:
-
Run Quality Checks:
-
Fix Issues:
Best Practices¤
Writing Tests¤
- Aim for high coverage but focus on quality
- Test critical business logic thoroughly
- Use descriptive test names
- Mock external dependencies
- Test both happy and error paths
Code Style¤
- Let Prettier handle formatting
- Follow ESLint rules for best practices
- Use TypeScript strictly (avoid
any
) - Keep functions small and focused
- Write self-documenting code
Git Workflow¤
- Commit frequently with descriptive messages
- Let pre-commit hooks catch issues early
- Review coverage reports in PRs
- Address security vulnerabilities promptly
Troubleshooting¤
Common Issues¤
-
Pre-commit Hook Fails:
- Run
npm run lint:fix
andnpm run format
- Check TypeScript errors with
npm run type-check
- Run
-
Coverage Below Threshold:
- Add tests for uncovered code paths
- Review coverage reports in
coverage/
directory
-
ESLint Conflicts:
- Rules are configured to work with Prettier
- Run
npm run lint:fix
to auto-fix issues
-
Type Errors:
- Fix TypeScript issues before committing
- Use
npm run type-check
to identify problems
For more details, see the individual configuration files and CI/CD workflow definitions.