Something went wrong. Try again.
code complexity & repetition analysis tool
Something went wrong. Try again.
Todo #
Roadmap #
A. Test Coverage Ingestion #
- Ingest LCOV/JSON from
cargo llvm-covorcargo test -- --coverage. - Render to terminal, HTML, Markdown, and JSONL.
- Support path normalization:
--root,--strip-prefix,--ignore-regex. - Support Git diff coverage.
B. AST-Based Clone Detection #
- Compare abstract syntax trees or subtrees.
- Identify clones resilient to renamed variables or formatting changes.
- Require per-language AST adapters.
C. Cognitive Complexity #
- Score human comprehension cost.
- Reward flattened control flow and penalize deep nesting.
- Require AST-level traversal.
D. Halstead Complexity #
- Count distinct and total operators and operands.
- Compute vocabulary, length, volume, difficulty, and effort.
- Complement Cyclomatic Complexity with lexical complexity.
E. Maintainability Index #
- Combine Cyclomatic, Halstead, and LOC into a single number.
- Useful for dashboards and longitudinal tracking.
F. Semantic Clone Detection #
- Go beyond syntax to identify logically equivalent code.
- Require control/data-flow analysis.
G. Dependency Metrics #
- Coupling, fan-in/fan-out, and depth of inheritance.
- Require language-specific type resolution or symbol graph extraction.
H. Hotspot Analysis #
- Combine Git history and complexity metrics.
- Identify files that change often and are complex.
I. Incremental Mode #
- Cache hashes and graphs.
- Analyze only changed files and touched boundaries.
J. Rich Reports #
- HTML dashboards.
- SVG graphs for CFG visualization.
- JSON with stable schema for CI systems.
Coverage Completion #
Tasks #
HTML #
Filtering Features #
Agentic Enhancements #
Build System Integration #
Definition of Done #
Clone Detection Improvements #
Direction #
Keep the clone detector language-agnostic and rolling-hash based for the near term. Improve the quality of the existing mccabre clones output before adding AST-level or language-specific clone detection.
Tasks #
Configuration #
CLI Shape #
-
--min-lines/--min-ln <n>--min-occurrences/--min-occ <n>--fail-over-duplicates <percent>--ignore-pattern <glob>repeatable--top <n>
Token Pipeline #
-
- collect significant tokens
- normalize tokens
- hash windows
- verify matched windows
- merge matched ranges
- build report
-
- identifiers can hash as
<identifier> - literals can hash as
<literal> - operators and punctuation remain exact
- identifiers can hash as
Clone Group Quality #
Reporting #
-
- files with clones
- duplicate line count
- duplicate token count
- duplicate line percentage
- clone instance count
Tests & Benchmarks #
Later #
Definition of Done #
AST Foundation & Language Adapters #
Tasks #
-
nesting_constructs()for cognitive complexity.function_definition()/call_expression()for call graphs.import_statement()for coupling metrics.identifier_kinds()/literal_kinds()for clone normalization.
Definition of Done #
Cognitive Complexity #
Tasks #
-
- +1 base for nesting constructs, language-specific via adapter.
- +nesting level for nested structures.
- +1 for logical operators via
adapter.logical_operators(). - +1 for labeled breaks/continues.
- +1 for recursion.
Dependencies #
- Requires: AST Foundation & Language Adapters.
Definition of Done #
Halstead Complexity #
Direction #
Add Halstead as a token-based metric before Maintainability Index. Keep the first implementation simple and deterministic: use the existing tokenizer where possible, classify tokens into operators and operands, and report file-level values before adding per-function breakdowns.
Metrics #
Halstead is based on counts of operators and operands:
n1: distinct operatorsn2: distinct operandsN1: total operatorsN2: total operands- Vocabulary:
n = n1 + n2 - Length:
N = N1 + N2 - Volume:
V = N * log2(n) - Difficulty:
D = (n1 / 2) * (N2 / n2) - Effort:
E = D * V
Tasks #
Tests #
Dependencies #
- Uses existing: tokenizer and file loader.
- Feeds future: Maintainability Index.
Definition of Done #
References #
- https://www.researchgate.net/publication/317317114_Software_Complexity_Analysis_Using_Halstead_Metrics
- https://nvlpubs.nist.gov/nistpubs/TechnicalNotes/NIST.TN.1990.pdf
Maintainability Index #
Tasks #
-
MI = max(0, (171 - 5.2*ln(HV) - 0.23*CC - 16.2*ln(LOC)) * 100/171)
Dependencies #
- Requires: Halstead Complexity.
- Uses existing: Cyclomatic, LOC.
Definition of Done #
AST-Based Clone Detection #
Tasks #
Dependencies #
- Requires: AST Foundation & Language Adapters.
Definition of Done #
Coupling Metrics #
Tasks #
Dependencies #
- Requires: AST Foundation & Language Adapters,
petgraph.
Definition of Done #
Call Graphs & Data-Flow Graphs #
Tasks #
Dependencies #
- Requires: AST Foundation & Language Adapters,
petgraph.
Definition of Done #
Summary #
MVP #
- LOC
- Cyclomatic Complexity
- Rabin-Karp Clone Detection
- Halstead Complexity
v1 #
- Call graphs and data-flow graphs
- AST-based clones
- Cognitive Complexity
- Maintainability Index
- Coupling metrics
v2 #
- Hotspot analysis
- Incremental scanning