Prerequisites

Installation

npm / npx (no Rust required)

bash
# Run directly without installing
npx tsmetrics analyze ./src

# Or install globally
npm install -g tsmetrics

Cargo (from source)

bash
git clone https://github.com/gabrielrf97/tsmetrics.git
cd tsmetrics
cargo install --path .
# Or build without installing: cargo build --release
# Binary at target/release/tsmetrics

GitHub Releases

Pre-built binaries for Linux, macOS, and Windows are available on the GitHub releases page.

First Analysis

Point tsmetrics at a TypeScript file or directory:

bash
# Analyze a single file
tsmetrics analyze src/utils.ts

# Analyze an entire directory (recursive)
tsmetrics analyze src/

# Analyze multiple paths
tsmetrics analyze src/ lib/ types/

Example output (table format)

Output is organized into three sections. The tables below are scrollable on narrow screens.

Section 1 — Function Metrics

Analyzed 4 file(s) — 33 function(s) — 289 LOC total === Function Metrics === ┌──────────────────────────────┬───────────────┬──────┬─────┬──────┬────────────┬─────────┬────────┬─────┬──────┬──────┐ │ File ┆ Function ┆ Line ┆ LOC ┆ SLOC ┆ Complexity ┆ Nesting ┆ Params ┆ HV ┆ MI ┆ CDep │ ╞══════════════════════════════╪═══════════════╪══════╪═════╪══════╪════════════╪═════════╪════════╪═════╪══════╪══════╡ │ src/utils.ts ┆ parseConfig ┆ 4 ┆ 12 ┆ 12 ┆ 5 ┆ 2 ┆ 1 ┆ 220 ┆ 59.4 ┆ 1 │ │ src/utils.ts ┆ validateInput ┆ 17 ┆ 12 ┆ 12 ┆ 12 ┆ 2 ┆ 2 ┆ 375 ┆ 56.8 ┆ 1 │ │ src/processor.ts ┆ processData ┆ 8 ┆ 19 ┆ 19 ┆ 6 ┆ 3 ┆ 3 ┆ 291 ┆ 54.0 ┆ 1 │ └──────────────────────────────┴───────────────┴──────┴─────┴──────┴────────────┴─────────┴────────┴─────┴──────┴──────┘

Section 2 — React / FP Component Metrics

=== React / FP Component Metrics === ┌──────────────────────────────┬───────────┬──────┬───────┬─────────┬────────────┬─────────────┬───────────┬──────┐ │ File ┆ Component ┆ Line ┆ Hooks ┆ Effects ┆ EffDensity ┆ RenderCmplx ┆ PropDrill ┆ CRS │ ╞══════════════════════════════╪═══════════╪══════╪═══════╪═════════╪════════════╪═════════════╪═══════════╪══════╡ │ src/components/UserCard.tsx ┆ UserCard ┆ 51 ┆ 4 ┆ 1 ┆ 0.059 ┆ 0 ┆ 0 ┆ 8.0 │ │ src/components/Dashboard.tsx ┆ Dashboard ┆ 72 ┆ 8 ┆ 2 ┆ 0.062 ┆ 0 ┆ 0 ┆ 19.0 │ └──────────────────────────────┴───────────┴──────┴───────┴─────────┴────────────┴─────────────┴───────────┴──────┘

Section 3 — File Metrics

=== File Metrics === ┌──────────────────────────────┬─────┬──────┬─────┬─────────┬──────────┬────────────┬──────────┬────────┬─────────────┐ │ File ┆ LOC ┆ SLOC ┆ Fns ┆ Classes ┆ TechDebt ┆ TD/100SLOC ┆ Cohesion ┆ FanOut ┆ PureFnRatio │ ╞══════════════════════════════╪═════╪══════╪═════╪═════════╪══════════╪════════════╪══════════╪════════╪═════════════╡ │ src/utils.ts ┆ 60 ┆ 50 ┆ 2 ┆ 0 ┆ 12.40 ┆ 24.80 ┆ 0.85 ┆ 2 ┆ 0.50 │ │ src/processor.ts ┆ 107 ┆ 93 ┆ 19 ┆ 0 ┆ 53.78 ┆ 57.83 ┆ 0.10 ┆ 1 ┆ 0.63 │ │ src/components/UserCard.tsx ┆ 42 ┆ 37 ┆ 4 ┆ 0 ┆ 15.30 ┆ 41.35 ┆ 0.50 ┆ 1 ┆ 0.25 │ │ src/components/Dashboard.tsx ┆ 80 ┆ 68 ┆ 8 ┆ 0 ┆ 38.92 ┆ 57.24 ┆ 0.20 ┆ 2 ┆ 0.25 │ └──────────────────────────────┴─────┴──────┴─────┴─────────┴──────────┴────────────┴──────────┴────────┴─────────────┘

Understanding the output

Function Metrics

ColumnDescription
FilePath to the TypeScript source file
FunctionFunction or method name (<anonymous> for unnamed)
Line1-based line number where the function is declared
LOCLines of Code (including blank and comment lines)
SLOCSource Lines of Code (blank and comment lines excluded)
ComplexityCyclomatic Complexity — color-coded green (<5) / yellow (5–9) / red (≥10)
NestingMaximum nesting depth
ParamsNumber of formal parameters
HVHalstead Volume — token-based size estimate
MIMaintainability Index (0–100, higher is better)
CDepClosure Depth — maximum callback/closure nesting level

React / FP Component Metrics

ColumnDescription
ComponentReact component or FP function name
HooksTotal hook calls (useState, useEffect, custom hooks, etc.)
EffectsNumber of useEffect / useLayoutEffect calls
EffDensityEffects per SLOC — how effect-heavy the component is
RenderCmplxRender complexity — conditional branches in JSX
PropDrillProp drilling depth — levels of prop passing through intermediaries
CRSComponent Responsibility Score — composite size/complexity signal

File Metrics

ColumnDescription
LOC / SLOCTotal lines / source lines in the file
FnsNumber of functions (including anonymous)
ClassesNumber of class declarations
TechDebtAggregate technical debt score
TD/100SLOCTechnical debt normalized per 100 source lines
CohesionModule cohesion (0–1, higher is better)
FanOutNumber of distinct external modules imported
PureFnRatioFraction of functions with no side effects (0–1)

Filtering results

bash
# Only show functions with CC ≥ 10
tsmetrics analyze src/ --min-complexity 10

# Only show functions with ≥ 50 LOC
tsmetrics analyze src/ --min-loc 50

# Show verbose output (skipped files reported to stderr)
tsmetrics analyze src/ --verbose

# Show timing information
tsmetrics analyze src/ --timing

Next steps

Edit on GitHub