← Back to Gene Catalog

code-complexity

Native code.analyze

Analyzes source code complexity using cyclomatic complexity, lines of code, and nesting depth metrics.

Version
0.1.0
Score
0.44
Downloads
0
Created
Mar 17, 2026
Updated
Mar 18, 2026
Install
$ rotifer install code-complexity copy

Score Breakdown

Gene Score 0.44
Arena 50%
0.88
Usage 30%
0.00
Stability 20%
0.01

Arena History

Date Fitness Safety Calls
Mar 17 0.8790 0.88 1

README

code-complexity

A Native Gene that measures source code complexity using industry-standard metrics.

Usage

rotifer test code-complexity --input '{
  "code": "function example(x) {\n  if (x > 0) {\n    for (let i = 0; i < x; i++) {\n      if (i % 2 === 0) console.log(i);\n    }\n  }\n}",
  "language": "javascript",
  "threshold": 10
}'

Metrics

Metric Description
Cyclomatic Complexity McCabe's complexity — number of independent paths through code
Lines of Code Non-blank, non-comment lines
Max Nesting Depth Deepest level of nested control structures
Function Count Number of functions/methods

Rating Scale

Score Rating Meaning
1-5 Low Simple, easy to maintain
6-10 Moderate Manageable complexity
11-20 High Consider refactoring
21+ Very High Refactoring strongly recommended

Supported Languages

TypeScript, JavaScript, Python, Rust, Go

Phenotype

inputSchema

{
  "type": "object",
  "required": [
    "code",
    "language"
  ],
  "properties": {
    "code": {
      "type": "string",
      "description": "Source code to analyze"
    },
    "language": {
      "enum": [
        "typescript",
        "javascript",
        "python",
        "rust",
        "go"
      ],
      "type": "string",
      "description": "Programming language"
    },
    "threshold": {
      "type": "number",
      "default": 10,
      "description": "Complexity threshold for warnings"
    }
  }
}

outputSchema

{
  "type": "object",
  "properties": {
    "rating": {
      "enum": [
        "low",
        "moderate",
        "high",
        "very-high"
      ],
      "type": "string",
      "description": "Complexity rating"
    },
    "linesOfCode": {
      "type": "number",
      "description": "Non-blank, non-comment lines"
    },
    "suggestions": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Improvement suggestions if complexity is high"
    },
    "functionCount": {
      "type": "number",
      "description": "Number of functions/methods found"
    },
    "maxNestingDepth": {
      "type": "number",
      "description": "Maximum nesting depth of control structures"
    },
    "cyclomaticComplexity": {
      "type": "number",
      "description": "McCabe cyclomatic complexity score"
    }
  }
}