Skip to content

jhuliangr/codemetrics

Repository files navigation

🧮 CodeMetrics

CodeMetrics Banner License

A CLI tool for analyzing code metrics, complexity, and unused code in JavaScript and TypeScript projects.


🚀 Overview

CodeMetrics is a command-line utility that analyzes your codebase and generates detailed metrics about code quality and structure.

It helps developers understand and improve their code by reporting on:

  • Total, comment, and blank lines
  • Code complexity estimation
  • Number of functions and classes
  • Code duplication ratio
  • 🔍 Unused variables and imports
  • ⚠️ Unsafe TypeScript types (any, unknown)

📦 Installation

1️⃣ Clone the repository

git clone https://github.com/jhuliangr/codemetrics.git
cd codemetrics

2️⃣ Install dependencies

pnpm install

3️⃣ (Optional) Build the project

pnpm build

🧰 Usage

pnpm analyze <path> [options]

📊 Analyze your codebase

Analyze code metrics for a directory or a single file.

pnpm analyze ./src -f table

Options

Option Description Default
-f, --format <type> Output format (table, json) table
-e, --exclude <patterns...> Glob-like patterns to exclude files
--max-complexity <number> Maximum allowed complexity 10

Example

pnpm analyze ./src -f json -e "node_modules" "dist"

🧠 Metrics Collected

Metric Description
lines.total Total number of lines
lines.code Lines containing actual code
lines.comment Lines containing comments
lines.blank Blank or empty lines
complexity Estimated cyclomatic complexity
functions Number of functions detected
classes Number of classes detected
duplication.percentage Percentage of duplicated lines
unusedVariables Declared variables never used
unusedImports Imported modules not used
typeIssues Use of any or unknown types (TypeScript only)

📈 Example Output

📊 Code Metrics Summary
──────────────────────────────────────────────
File: src/utils/helpers.ts
──────────────────────────────────────────────
Lines: total=120, code=90, comment=20, blank=10
Complexity: 8
Functions: 5
Classes: 1
Duplication: 12.5%
Unused Variables: tempVar
Unused Imports: lodash
Type Issues: Use of type "any" detected
──────────────────────────────────────────────

About

A command-line tool for analyzing code metrics, complexity, and dead code in JavaScript/TypeScript projects using AST analysis. Project made for an assignment at Harbour Space Institute of Technology

Topics

Resources

Stars

Watchers

Forks

Contributors