← 返回
未分类 中文

Code Complexity Analyzer

Measure cyclomatic complexity, cognitive complexity, and structural metrics for Python, JavaScript/TypeScript, and Go code. Use when analyzing code quality,...
测量 Python、JavaScript/TypeScript和 Go 代码的圈复杂度、认知复杂度及结构指标,用于代码质量分析。
charlie-morrison
未分类 clawhub v1.0.1 1 版本 100000 Key: 无需
★ 0
Stars
📥 425
下载
💾 1
安装
1
版本
#latest

概述

Code Complexity Analyzer

Measure cyclomatic, cognitive, and structural complexity per function. Pure Python, no dependencies.

Quick Start

# Analyze a directory
python3 scripts/analyze_complexity.py src/

# Analyze specific files
python3 scripts/analyze_complexity.py app.py utils.py

# Show all functions (not just violations)
python3 scripts/analyze_complexity.py src/ --verbose

# Custom thresholds
python3 scripts/analyze_complexity.py src/ --cc 15 --cog 20 --max-lines 80

Output Formats

python3 scripts/analyze_complexity.py src/ --format text      # human-readable (default)
python3 scripts/analyze_complexity.py src/ --format json       # CI/tooling
python3 scripts/analyze_complexity.py src/ --format markdown   # reports

Supported Languages

  • Python (.py)
  • JavaScript (.js, .jsx, .mjs, .cjs)
  • TypeScript (.ts, .tsx)
  • Go (.go)

Metrics

MetricDescriptionDefault Threshold
----------------------------------------
Cyclomatic (CC)Independent execution paths≤10
Cognitive (COG)Perceived difficulty to understand (nesting-weighted)≤15
LinesFunction length≤50
ParamsParameter count≤5
NestingMax nesting depth≤4

Risk Levels

  • 🟢 Simple — CC≤5, COG≤8
  • 🟡 Low — CC≤10, COG≤15
  • 🟠 Moderate — CC≤20, COG≤25
  • 🔴 High — CC>20 or COG>25

Options

--cc N           Cyclomatic threshold (default: 10)
--cog N          Cognitive threshold (default: 15)
--max-lines N    Function length threshold (default: 50)
--max-params N   Parameter count threshold (default: 5)
--max-nesting N  Nesting depth threshold (default: 4)
--exclude DIR    Additional directories to exclude
--verbose, -v    Show all functions, not just violations

Auto-excluded: node_modules, .git, __pycache__, venv, dist, build.

Exit Codes

  • 0 — no violations
  • 1 — violations found (functions exceed CC or COG thresholds)
  • 2 — no analyzable files found

版本历史

共 1 个版本

  • v1.0.1 当前
    2026-05-03 10:25 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

Pyproject Toml Validator

charlie-morrison
依据 PEP 517/621 规则校验 pyproject.toml 文件,验证项目元数据、构建系统和工具配置,并提供详细报告。
★ 0 📥 463

Env Config Validator

charlie-morrison
校验 .env 文件,匹配 schema,比较环境(dev 与 prod),检测尾部空格、占位符、无效端口、缺失 protoc 等常见错误
★ 0 📥 452

Stylelint Config Validator

charlie-morrison
校验 Stylelint 配置文件,检查错误、已弃用规则、配置结构、插件、extends 和 overrides,并输出文本或 JSON 结果。
★ 0 📥 451