Code Quality Standards
This document outlines the code quality tools and standards used in this project.
Tools Overview
Code Quality Stack:
├── ESLint → Linting & code patterns
├── Prettier → Code formatting
├── TypeScript (strict) → Type safety
├── Husky → Git hooks
├── lint-staged → Pre-commit checks
├── commitlint → Commit message format
├── cspell → Spell checking
└── dependency-cruiser → Architecture rules
Automated Checks
Pre-Commit (runs on git commit)
- Prettier: Formats staged files
- ESLint: Fixes linting issues in staged files
- Custom checks:
- No
console.log()statements - No
debuggerstatements - No merge conflict markers
Commit Message (runs on git commit)
- Validates commit message format
- Enforces Conventional Commits standard
- Checks type, scope, and subject
Pre-Push (runs on git push)
- Type checking: Ensures no TypeScript errors
- Tests: Runs tests on affected projects
- Build: Builds affected projects
CI Pipeline (runs on PR/push to main)
- Formatting check: Ensures all files are formatted
- Linting: Checks all code for linting errors
- Type checking: Validates TypeScript types
- Spell checking: Checks for spelling errors
- Tests: Runs full test suite with coverage
- Build: Builds all projects
- Dependency review: Checks for security issues
Manual Commands
# Format all files
npm run format
# Check formatting (without changing files)
npm run format:check
# Lint all files
npm run lint
# Lint and fix issues
npm run lint:fix
# Type check
npm run typecheck
# Run all checks
npm run check:all
# Spell check
npm run spell:check
# Check naming conventions
npm run check:naming
# Check dependency rules
npm run dep:check
ESLint Rules
Enabled Rules
TypeScript:
- No
anytypes (useunknownif needed) - Explicit function return types
- No unused variables
- No floating promises
- Consistent naming conventions
Import:
- Organized import order
- No circular dependencies
- No unresolved imports
- No duplicate imports
Security:
- Basic security checks
- No dangerous patterns
Code Quality:
- No
console.log(exceptwarn/error) - No
debuggerstatements - Prefer
constoverlet - No
vardeclarations - Always use strict equality (
===)
Disabled Rules (in tests)
@typescript-eslint/no-explicit-any@typescript-eslint/no-unsafe-*
Prettier Configuration
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"tabWidth": 2,
"semi": true
}
TypeScript Strict Mode
All strict mode options are enabled:
strict: truenoImplicitAny: truestrictNullChecks: truenoUnusedLocals: truenoUnusedParameters: truenoImplicitReturns: true
Commit Message Format
<type>(<scope>): <subject>
<body>
<footer>
Types:
feat,fix,docs,style,refactor,perf,test,chore,ci,build,revert
Scopes:
api-gateway,user-service,field-service,booking-service,payment-service,notification-serviceshared,database,messaging,cache,observabilitydocker,ci,deps,config
Examples:
feat(booking): add conflict detection
fix(payment): handle webhook timeout
docs(readme): update setup instructions
chore(deps): update nestjs to v10
Architecture Rules
Enforced by dependency-cruiser:
- No circular dependencies
- No orphan modules (unused files)
- Services cannot import controllers (layering violation)
- Libs cannot import from apps (dependency direction)
VS Code Integration
Install recommended extensions:
- Prettier
- ESLint
- EditorConfig
- Code Spell Checker
- Error Lens
Settings are automatically applied from .vscode/settings.json.
Bypassing Checks (Emergency Only)
Skip Pre-Commit
git commit --no-verify -m "emergency fix"
Skip Pre-Push
git push --no-verify
⚠️ Warning: Only use --no-verify in emergencies. All PRs will still be checked by CI.
Troubleshooting
"Prettier formatting failed"
npm run format
git add .
git commit
"ESLint errors found"
npm run lint:fix
# Fix remaining errors manually
git add .
git commit
"Type check failed"
npm run typecheck
# Fix TypeScript errors
git add .
git commit
"Pre-push checks failed"
# Run locally to see details
npm run check:all
Updating Rules
To update linting/formatting rules:
- Update
.eslintrc.jsonor.prettierrc - Run
npm run formatandnpm run lint:fix - Commit changes
- Notify team in PR
Questions?
Contact the team lead or create a discussion on GitHub.