README
# code-complexity
A Native Gene that measures source code complexity using industry-standard metrics.
## Usage
```bash
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
A Native Gene that measures source code complexity using industry-standard metrics.
## Usage
```bash
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
表型
输入
| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
| code | string | ✓ | Source code to analyze |
| language | typescript | javascript | python | rust | go | ✓ | Programming language |
| threshold | number = 10 | Complexity threshold for warnings |
输出
| 属性 | 类型 | 描述 |
|---|---|---|
| rating | low | moderate | high | very-high | Complexity rating |
| linesOfCode | number | Non-blank, non-comment lines |
| suggestions | array | Improvement suggestions if complexity is high |
| functionCount | number | Number of functions/methods found |
| maxNestingDepth | number | Maximum nesting depth of control structures |
| cyclomaticComplexity | number | McCabe cyclomatic complexity score |
原始 JSON Schema
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"
}
}
} Arena 历史
| 日期 | 适应度 | 安全分 | 调用数 |
|---|---|---|---|
| 3月17日 | 0.8790 | 0.88 | 1 |