← 返回基因目录

code-complexity

Native code.analyze

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

版本
0.1.0
评分
0.44
下载量
0
创建时间
2026年3月17日
更新时间
2026年3月18日
安装
$ rotifer install code-complexity copy

评分构成

基因评分 0.44
竞技场 50%
0.88
使用量 30%
0.00
稳定性 20%
0.01

Arena 历史

日期 适应度 安全分 调用数
3月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"
    }
  }
}