Metrics Overview
tsmetrics computes 25+ metrics across five categories.
Function-level metrics
| Metric | Key | Description | Default thresholds |
|---|---|---|---|
| Cyclomatic Complexity | CC | Number of independent execution paths | warn: 10, err: 25 |
| Halstead Volume | V | Size of implementation based on operator/operand counts | informational |
| Maintainability Index | MI | Composite score 0–100; higher = more maintainable | informational |
| LOC / SLOC | — | Total / source lines of code | warn: 50, err: 100 |
| Max Nesting | — | Maximum block nesting depth | warn: 3, err: 5 |
| Param Count | — | Number of formal parameters | warn: 4, err: 7 |
| Closure Depth | — | Maximum function nesting depth (detects callback hell) | informational |
| Long Parameter List | — | Flags functions with more than 4 parameters | threshold: 4 |
Class-level metrics
| Metric | Key | Description | Default thresholds |
|---|---|---|---|
| Weighted Methods per Class | WMC | Sum of cyclomatic complexity across all methods | warn: 20, err: 50 |
| Depth of Inheritance Tree | DIT | Edges from class to root of inheritance hierarchy | informational |
| Number of Methods | NOM/NOAM/NOOM | Total, added, and overriding methods | informational |
| Weight of Class | WOC | Ratio of public attributes to total public interface | informational |
| Tight Class Cohesion | TCC | Fraction of method pairs sharing a field access | informational |
| Coupling Between Objects | CBO | Count of distinct external types referenced structurally | informational |
| Response For Class | RFC | NOM + number of unique callees in method bodies | informational |
| Number of Implemented Interfaces | NOI | Count of interfaces in the implements clause | warn: 3, err: 5 |
React / FP metrics
| Metric | Description |
|---|---|
| Number of Used Components | Distinct PascalCase JSX component references in render output |
| JSX Nesting Level | Maximum depth of nested JSX elements |
| Hook Complexity | Total hook call count and number of distinct hook types per component |
| Custom Hook Cohesion | Fraction of return value pairs sharing internal state — low score suggests splitting the hook |
| Effect Density | Ratio of useEffect calls to component SLOC |
| Component Responsibility Score | Weighted score of props, state, effects, and JSX — detects "God Components" |
| Prop Drilling Depth | Maximum JSX nesting depth at which props are passed down |
| Render Complexity | Cyclomatic-style count of &&, ternaries, and .map() in JSX |
Module-level metrics
| Metric | Description |
|---|---|
| Module Cohesion | Fraction of exported function pairs that share an import dependency (FP analogue of TCC) |
| Function Coupling | Fan-out: number of distinct import sources (relative + package) |
| Pure Function Ratio | Fraction of functions with no detected side effects |
File-level metrics
| Metric | Description |
|---|---|
| Technical Debt | Per-function debt aggregated to file level |