Output Formats
tsmetrics supports four output formats: table, json, csv, and html.
Output sections
Regardless of format, results are organized into three sections:
- Function Metrics — per-function: CC, LOC, SLOC, nesting depth, param count, Halstead Volume, Maintainability Index, closure depth
- React / FP Component Metrics — per-component: hook complexity, hook cohesion, effect density, component responsibility score, prop drilling depth, render complexity
- File Metrics — per-file: total LOC/SLOC, function count, technical debt, module cohesion, function coupling (fan-out), pure function ratio
Table (default)
UTF-8 box-drawing tables printed to stdout. Cyclomatic Complexity values are color-coded: green (<5), yellow (5–9), red (≥10).
Function Metrics
=== 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 │
└──────────────────┴───────────────┴──────┴─────┴──────┴────────────┴─────────┴────────┴─────┴──────┴──────┘
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 │
└──────────────────────────────┴───────────┴──────┴───────┴─────────┴────────────┴─────────────┴───────────┴──────┘
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 │
└──────────────────────────────┴─────┴──────┴─────┴─────────┴──────────┴────────────┴──────────┴────────┴─────────────┘
Analyzed 4 file(s) — 33 function(s) — 289 LOC total
JSON
Structured JSON with the full analysis result, including per-file metrics, per-function metrics, per-component metrics, and all threshold violations.
json
{
"total_files": 2,
"total_functions": 5,
"total_loc": 140,
"files": [
{
"path": "src/utils.ts",
"total_loc": 60,
"total_sloc": 50,
"function_count": 2,
"module_cohesion": 0.85,
"fan_out": 3,
"pure_function_ratio": 0.5,
"technical_debt": 12.4,
"functions": [
{
"name": "validateInput",
"file": "src/utils.ts",
"line": 24,
"loc": 32,
"sloc": 26,
"cyclomatic_complexity": 11,
"max_nesting": 4,
"param_count": 2,
"halstead_volume": 142.3,
"maintainability_index": 58.1,
"closure_depth": 1
}
],
"components": []
}
],
"violations": [
{
"file": "src/utils.ts",
"entity": "validateInput",
"line": 24,
"metric": "cyclomatic_complexity",
"value": 11,
"threshold": 10,
"severity": "warning"
}
]
}
CSV
RFC 4180-compliant CSV. One row per function — suitable for spreadsheet import or further processing.
file,function,line,loc,sloc,complexity,nesting,params,halstead_volume,maintainability_index,closure_depth
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
Violations are not included in CSV output. Use JSON for the full picture including component metrics.
HTML
A self-contained HTML report with inline CSS and JavaScript. Features:
- Sortable columns (click any header)
- Color-coded complexity badges (green / yellow / red)
- Separate tables for function, component, and file metrics
- Violations table (if any thresholds exceeded)
- No external dependencies — single file, works offline
bash
tsmetrics analyze ./src --format html > report.html open report.html