Code metrics analyzer

Paste one source file or snippet and measure physical lines, code/comment/blank split, detected functions, approximate cyclomatic and cognitive complexity, maintainability grade, and over-threshold hotspots. Runs locally; no repository upload needed.

Try:
Metrics

About this tool

Code metrics are a quick way to spot source files that need a closer review before you wire them into a larger refactor. Paste one source file or snippet and this tool reports the physical line counts, code/comment/blank split, function-like declarations, approximate cyclomatic complexity, cognitive complexity, parameter counts, nesting depth, Halstead volume, and a maintainability grade.

Everything runs locally in WebAssembly. The analyzer is intentionally heuristic: it strips comments, looks for common declaration patterns, and counts branch/loop/boolean decision points without sending your code to a server or requiring a repository checkout.

Worked example

Input:

function grade(score) {
  if (score >= 90) return 'A';
  if (score >= 80) return 'B';
  return 'C';
}

With Language = JavaScript and Complexity warning threshold = 2, the summary includes:

Language: javascript
Lines: total 5, code 5, comment 0, blank 0
Functions: 1
Cyclomatic complexity: total 3, average 3.0, max 3
Over threshold (>2): 1

Functions:
- grade (line 1, 5 LOC): CCN 3, cognitive 4, params 1, nesting 1, risk low

What the metrics mean

Output formats

Limits and edge cases

FAQ

Is this accurate enough to replace lizard, scc, cloc, or a compiler plugin?

No. It is a local, paste-and-go triage tool for one snippet or file. Use it to spot obvious hotspots and to compare versions of the same code. For CI gates over a whole repository, use a language-aware AST tool or repository scanner.

Why does a line with code and a trailing comment count as code?

That convention avoids double-counting a physical line. A line such as return value; // done is still an executable code line, while a line containing only // done is a comment line. The comments are stripped before branch and function heuristics run.

What threshold should I use for cyclomatic complexity?

The default is 10, a common "look closer" threshold. For small pasted snippets, lower values such as 3 or 5 are useful when you want the function table to flag every branch-heavy example. The number is configurable because teams vary in how strictly they gate complexity.

Why did it miss a function in my code?

The analyzer does not build a full AST. It detects common function forms across many languages, but exotic declarations, macro-generated functions, and deeply chained anonymous callbacks can fall outside those patterns. The file-level line counts and complexity still reflect the pasted text.

Developer & Automation Access

Run it from the terminal

Same engine as this page, headless — via the gizza CLI:

gizza tool code-metrics-analyzer "function grade(score) {
  if (score >= 90) return 'A';
  if (score >= 80) return 'B';
  return 'C';
}"

New to the CLI? Get gizza →

Open it by URL

Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:

https://gizza.ai/tools/code-metrics-analyzer/?source=function%20grade%28score%29%20%7B%0A%20%20if%20%28score%20%3E%3D%2090%29%20return%20%27A%27%3B%0A%20%20if%20%28score%20%3E%3D%2080%29%20return%20%27B%27%3B%0A%20%20return%20%27C%27%3B%0A%7D&language=auto&output=summary&complexity_threshold=10&max_functions=50&sort=line

Machine-readable descriptor: tool.json — title + parameters JSON Schema for agents.