Skip to content

Analyzers

Codefang ships two families of analyzers that extract quantitative insights from your codebase.

Static analyzers operate on source code via UAST (Universal Abstract Syntax Tree) and evaluate structural properties of the code as it exists right now. History analyzers walk Git commit history and track how the codebase evolves over time.


Static Analyzers

Static analyzers parse source files into a UAST and compute metrics in a single pass. They require no repository history and can run on individual files or entire directory trees.

Analyzer ID Description
Complexity complexity Cyclomatic complexity, cognitive complexity, nesting depth
Cohesion cohesion LCOM4 class cohesion, method-field usage graphs
Halstead halstead Program length, vocabulary, volume, difficulty, effort
Comments comments Documentation coverage, comment placement quality
Imports imports Import and dependency analysis

Running Static Analyzers

Pipe a UAST through codefang analyze:

# Single file, single analyzer
uast parse main.go | codefang analyze -a complexity

# Single file, all static analyzers
uast parse main.go | codefang analyze

# Entire directory tree
codefang analyze -a complexity ./src/

History Analyzers

History analyzers iterate over Git commits (oldest to newest) and accumulate statistics about how files, developers, and code structure change over time. They require a Git repository.

Analyzer ID Description
Burndown history/burndown Code survival over time, line ownership tracking
Developers history/devs Developer activity, language breakdown, bus factor
Couples history/couples File coupling, co-change patterns
File History history/file-history Per-file lifecycle and modification tracking
Quality history/quality Complexity, Halstead, comment, and cohesion metrics over time
Sentiment history/sentiment Comment sentiment analysis over time
Shotness history/shotness Structural hotspots (function-level change tracking)
Typos history/typos Typo detection dataset builder
Anomaly history/anomaly Z-score temporal anomaly detection

Running History Analyzers

Use codefang run with the -a flag:

# Single analyzer
codefang run -a history/burndown .

# Multiple analyzers
codefang run -a history/devs -a history/couples .

# All history analyzers
codefang run -a 'history/*' .

Glob Patterns

You can select analyzers using glob patterns with the -a flag:

# All static analyzers
codefang analyze -a 'static/*' ./src/

# All history analyzers
codefang run -a 'history/*' .

# All analyzers (both static and history)
codefang run -a '*' .

Output Formats

All analyzers support multiple output formats via the -f flag:

codefang run -a history/devs -f json .
codefang run -a history/devs -f yaml .
codefang run -a history/burndown -f plot .
codefang run -a history/burndown -f binary .

Combining analyzers

When running multiple history analyzers together, they share the same commit walk, making combined runs significantly faster than running each analyzer separately.