Bỏ qua

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 debugger statements
  • 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 any types (use unknown if 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 (except warn/error)
  • No debugger statements
  • Prefer const over let
  • No var declarations
  • 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: true
  • noImplicitAny: true
  • strictNullChecks: true
  • noUnusedLocals: true
  • noUnusedParameters: true
  • noImplicitReturns: 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-service
  • shared, database, messaging, cache, observability
  • docker, 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:

  1. Update .eslintrc.json or .prettierrc
  2. Run npm run format and npm run lint:fix
  3. Commit changes
  4. Notify team in PR

Questions?

Contact the team lead or create a discussion on GitHub.