| name | analyze-code-quality |
| description | Analyze code quality including ESLint, Prettier, tests, TypeScript, and NestJS best practices. Use when reviewing code quality, checking test coverage, or auditing for best practices. |
Perform comprehensive code quality analysis.
Module: $0 (if empty, analyze entire project)
Focus area: $1 (options: eslint, prettier, tests, typescript, nestjs, all - default: all)
Analysis Scope
The analysis will cover the specified focus area or complete code quality review if "all" is selected.
1. ESLint Analysis
A. Configuration Validation
- โ
Check
.eslintrc.js exists and is properly configured
- โ
Verify Airbnb style guide is enabled
- โ
Check TypeScript ESLint parser configuration
- โ
Validate custom rules alignment with project needs
- โ
Verify ignore patterns (.eslintignore)
B. Code Violations Detection
Run ESLint analysis and categorize issues:
npm run lint
Report violations by severity:
- ๐ด Errors (must fix)
- ๐ก Warnings (should fix)
- ๐ต Info (nice to fix)
Common violations to check:
- โ Unused variables and imports
- โ Console.log statements in production code
- โ Missing return types on functions
- โ Any type usage (should use specific types)
- โ Inconsistent naming conventions
- โ Unreachable code
- โ Debugger statements
- โ Empty functions/blocks
- โ Complexity violations (cyclomatic complexity > 10)
- โ Max line length violations (> 120 chars)
- โ Missing JSDoc for public APIs
2. Prettier Formatting Analysis
A. Configuration Check
- โ
Verify
.prettierrc exists
- โ
Check configuration settings
- โ
Verify
.prettierignore configuration
B. Formatting Issues Detection
Run Prettier check:
npm run format:check
npx prettier --check "src/**/*.ts"
Report:
- List all files with formatting issues
- Count total files needing formatting
- Show sample formatting differences
- Provide auto-fix command:
npm run format
3. Unit Test Coverage Analysis
A. Test Execution
Run tests and collect metrics:
npm run test:cov
B. Coverage Metrics Analysis
Overall Coverage:
- โ
Statements coverage (target: >80%)
- โ
Branches coverage (target: >75%)
- โ
Functions coverage (target: >80%)
- โ
Lines coverage (target: >80%)
C. Test Quality Checks
File Coverage:
- โ List files WITHOUT test files (.spec.ts)
- โ
Verify test file naming convention matches source files
- โ Find test files with low assertions
- โ Find skipped/disabled tests (describe.skip, it.skip)
- โ Find focused tests (fit, fdescribe) - should never be committed
Test Patterns:
- โ
Check use cases have corresponding tests
- โ
Verify domain entities have unit tests
- โ
Check value objects have validation tests
- โ
Verify event handlers have tests
- โ
Check repository adapters have integration tests
- โ Flag missing edge case tests
- โ Flag missing error case tests
D. Test Configuration
- โ
Verify jest.config.js configuration
- โ
Check test environment setup
- โ
Validate code coverage thresholds
- โ
Check SonarQube reporter configuration
- โ
Verify path aliases work in tests
4. TypeScript Analysis
A. Configuration Validation
Check tsconfig.json settings for strict mode and best practices
B. Type Safety Issues
Run TypeScript compiler check:
npx tsc --noEmit
Flag common issues:
- โ
any type usage (use specific types or unknown)
- โ
@ts-ignore comments (fix the issue instead)
- โ
as any type assertions (use proper typing)
- โ Non-null assertions (
!) without justification
- โ Implicit any types
- โ Missing return types on functions
- โ Unsafe type assertions
- โ Unused variables/imports
- โ Type vs Interface usage (prefer interface for object shapes)
C. TypeScript Best Practices
interface CreateOrderDTO {
customerId: string;
items: OrderItem[];
}
function createOrder(dto: CreateOrderDTO): Promise<Result<Order>> {
}
function createOrder(dto: any): Promise<any> {
}
5. NestJS Best Practices Analysis
A. Module Organization
Check module structure:
- โ
Each module has proper
@Module() decorator
- โ
Providers array contains all injectables
- โ
Imports/Exports are correctly configured
- โ
No circular dependencies between modules
- โ Flag modules importing themselves
- โ Flag overly large modules (>10 providers)
B. Dependency Injection
Proper DI patterns:
@Injectable()
export class OrderService {
constructor(
@Inject('IOrderRepository') private readonly orderRepo: IOrderRepository,
private readonly logger: Logger,
) {}
}
export class OrderService {
private orderRepo = new OrderRepository();
}
C. Decorator Usage
Controllers:
- โ
Proper
@Controller() with route prefix
- โ
HTTP method decorators (
@Get(), @Post(), etc.)
- โ
@Body(), @Param(), @Query() decorators
- โ
Proper DTO validation with class-validator
- โ Missing
@ApiTags() for Swagger documentation
- โ Missing response type decorators (
@ApiResponse())
Services:
- โ
@Injectable() on all services
- โ
Proper scope (singleton, request, transient)
- โ Missing
@Injectable() decorator
Event Handlers:
- โ
@OnEvent() decorator with proper event name
- โ
Async handlers return Promise
- โ Synchronous long-running handlers (should be async)
D. NestJS-Specific Patterns
Guards, Interceptors, Pipes, Filters:
- โ
Implement proper interfaces
- โ
Proper use of decorators
- โ
Appropriate placement (global vs route-specific)
E. Performance & Best Practices
- โ Synchronous operations blocking event loop
- โ Missing
@UseInterceptors() for logging/transformation
- โ Direct database queries in controllers (should use services)
- โ Business logic in controllers (should be in use cases/domain)
- โ Missing validation pipes on endpoints
- โ Improper exception handling
- โ Memory leaks (unsubscribed observables)
- โ N+1 query problems
6. Code Complexity Analysis
A. Cyclomatic Complexity
- โ
Functions with complexity score > 10 (refactor needed)
- โ
Classes with too many methods (> 20)
- โ Deep nesting levels (> 4)
B. Code Smells
- โ Long Methods - Methods > 50 lines
- โ Long Parameter Lists - Functions with > 4 parameters
- โ Large Classes - Classes > 300 lines
- โ Duplicate Code - Similar code blocks
- โ Dead Code - Unused exports/functions
- โ Magic Numbers - Hardcoded numbers without constants
- โ Long Conditional Chains - Multiple if-else if-else
C. Maintainability Metrics
- Comment density (target: 10-20%)
- File length distribution
- Import complexity (too many imports = high coupling)
7. Dependency & Security Analysis
A. Package.json Review
- โ
Check for outdated dependencies:
npm outdated
- โ
Check for security vulnerabilities:
npm audit
- โ
Verify no dev dependencies in production code
- โ Flag deprecated packages
- โ Flag packages with known vulnerabilities
B. Import Analysis
- โ
Verify path aliases work (@shared, @modules)
- โ Flag relative imports going up many levels (../../../)
- โ Flag barrel file anti-patterns (index.ts exporting everything)
- โ Flag circular dependencies
8. Git & Commit Quality
A. Pre-commit Hooks
- โ
Verify Lefthook is configured
- โ
Check pre-commit runs linting
- โ
Check pre-commit runs formatting
- โ
Verify tests run before push
B. Code Review Checklist
- โ Large commits (> 500 lines)
- โ Commits mixing multiple concerns
- โ Missing commit messages or poor messages
- โ Direct commits to main/master
Output Format
Provide a comprehensive report:
๐ Code Quality Score
- Overall Score: 0-100%
- ESLint: Errors, Warnings, Info counts
- Prettier: Files needing formatting
- Test Coverage: % by category
- TypeScript: Type safety score
- NestJS: Best practices compliance
โ
Strengths
- Well-tested modules
- Good type coverage
- Clean formatting
- Proper DI usage
โ ๏ธ Critical Issues (Fix Immediately)
For each issue:
- Category: ESLint / Testing / TypeScript / NestJS
- Severity: Critical / High / Medium / Low
- Location: File:Line
- Issue: Description
- Impact: Why it matters
- Fix: How to resolve
- Command: Auto-fix command if available
๐ง Warnings (Should Fix)
Non-critical but important issues
๐ก Recommendations
- Suggested improvements
- Refactoring opportunities
- Performance optimizations
๐ Metrics Summary
Code Quality Metrics:
โโโ ESLint Issues: 23 (12 errors, 11 warnings)
โโโ Prettier: 5 files need formatting
โโโ Test Coverage: 78% (target: 80%)
โโโ TypeScript Errors: 0
โโโ Unused Exports: 8
โโโ Code Complexity: 3 functions > 10
โโโ Security Vulnerabilities: 2 (1 high, 1 medium)
โโโ Outdated Packages: 5
๐ฏ Action Items (Prioritized)
- Critical: Fix ESLint errors preventing build
- High: Increase test coverage for user module (45% โ 80%)
- High: Fix security vulnerability in package X
- Medium: Remove 8 unused exports
- Medium: Format 5 files with Prettier
- Low: Update 5 outdated packages
๐ Quick Fixes
Auto-fixable issues with commands:
npm run lint:fix
npm run format
npm update
npm audit fix
Analysis Guidelines
- Run actual linting/testing commands to get real data
- Provide file paths and line numbers for all issues
- Include code snippets showing violations
- Suggest concrete fixes with examples
- Prioritize issues by impact and effort
- Consider project context (not all warnings are critical)
- Provide both quick wins and long-term improvements
- Include metrics and trends if analyzing over time