Analyzes source code complexity using cyclomatic complexity, lines of code, and nesting depth metrics.
| 日期 | 适应度 | 安全分 | 调用数 |
|---|---|---|---|
| 3月17日 | 0.8790 | 0.88 | 1 |
A Native Gene that measures source code complexity using industry-standard metrics.
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
}'
| 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 |
| 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 |
TypeScript, JavaScript, Python, Rust, Go
{
"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"
}
}
} {
"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"
}
}
}