Code Metrics Calculator
Understand code quality metrics, thresholds, and improvement strategies.
Key Metrics
Cyclomatic Complexity: Number of independent paths
Good: < 10Bad: > 20
Lines of Code (LOC): Source code size
Good: ModularBad: Monolithic
Code Coverage: Test coverage percentage
Good: > 80%Bad: < 50%
Maintainability Index: Ease of maintenance
Good: > 70Bad: < 20
Coupling: Dependency between modules
Good: LowBad: High
Cohesion: Relatedness in module
Good: HighBad: Low
Complexity Thresholds
Level 1-5: Simple, easy to test
No action needed
Level 6-10: Moderate, acceptable
Consider simplification
Level 11-20: Complex, needs attention
Refactor recommended
Level 21-50: Very complex, risky
Refactor required
Level >50: Untestable, dangerous
Rewrite module
Analysis Tools
SonarQube: Code quality platform
Enterprise
ESLint: JS/TS linting
Free
Prettier: Code formatting
Free
Complexity Report: JS complexity
CLI
Code Climate: Quality metrics
SaaS
Understand: C/C++ metrics
Commercial
Improvement Strategies
High complexity
Fix: Extract functions, reduce branches
Low coverage
Fix: Add unit tests, test edge cases
High coupling
Fix: Use interfaces, dependency injection
Low cohesion
Fix: Split unrelated functions
Large functions
Fix: Break into smaller functions
Deep nesting
Fix: Early returns, guard clauses
Metrics Best Practices
Measure regularly (CI/CD integration). Set thresholds for alerts. Track trends over time. Focus on high-impact areas. Don't optimize metrics blindly - balance with functionality. Good code = readable + maintainable + testable. Metrics help identify problems, not solve them. Human judgment still essential.