tsmetrics
A fast, tree-sitter-powered TypeScript static analyzer written in Rust. Point it at your codebase and get 25+ actionable metrics in seconds.
Quick Start
npx tsmetrics analyze ./src
# Option B — cargo (from source)
git clone https://github.com/gabrielrf97/tsmetrics && cd tsmetrics && cargo install --path .
# Run an analysis
tsmetrics analyze ./src
# Export a self-contained HTML report
tsmetrics analyze ./src --format html > report.html
What is tsmetrics?
tsmetrics (TypeScript Static Analyzer) parses TypeScript and TSX files using tree-sitter and computes a comprehensive set of software quality metrics. It is written in Rust and designed for speed, correctness, and scriptability.
Metrics are grouped into five categories:
- Function-level — Cyclomatic Complexity, Halstead Volume, Maintainability Index, LOC, nesting depth, closure depth, parameter count
- Class-level — WMC, DIT, NOM/NOAM/NOOM, WOC, TCC, CBO, RFC, NOI
- React / FP — Hook Complexity, Custom Hook Cohesion, Effect Density, Component Responsibility, Prop Drilling Depth, Render Complexity, JSX Nesting, Used Components
- Module-level — Module Cohesion, Function Coupling (Fan-Out), Pure Function Ratio
- File-level — Technical Debt score
It also detects four object-oriented design smells inspired by Object-Oriented Metrics in Practice (Lanza & Marinescu): God Class, Brain Method, Feature Envy, and Refused Bequest.
Features
Fast
Files processed in parallel using Rayon. Handles large codebases without breaking a sweat.
Accurate
Built on tree-sitter's full AST — no regex heuristics. Handles generics, decorators, and TSX.
Configurable
Override warning/error thresholds per metric via tsmetrics.yaml. Exclude paths you don't care about.
Multiple Outputs
Table, JSON, CSV, and self-contained HTML report formats.