code-complexity-scanner

代码复杂度扫描器 — 测量代码库的圈复杂度、认知复杂度和函数长度,以识别维护热点。用于回答有关复杂度、函数长度分析、可维护性指标或定位代码库最复杂部分的查询。触发词示例:复杂度、圈复杂度、认知复杂度、长函数、热点、可维护性指数、代码指标。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "code-complexity-scanner":https://skillpi.com/zh/skills/deepskill-cda6d83314e914804b28a5cd53939e5838668792e534e3635e512c407c5f136b。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

代码复杂度扫描器 — 测量代码库的圈复杂度、认知复杂度和函数长度,以识别维护热点。用于回答有关复杂度、函数长度分析、可维护性指标或定位代码库最复杂部分的查询。触发词示例:复杂度、圈复杂度、认知复杂度、长函数、热点、可维护性指数、代码指标。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

输入和输出
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: code-complexity-scanner
description: >-
  Measures cyclomatic complexity, cognitive complexity, and function length
  across codebases to identify maintenance hotspots. Use when someone asks
  about code complexity, function length analysis, maintainability metrics,
  or needs to find the most complex parts of their codebase. Trigger words:
  complexity, cyclomatic, cognitive complexity, long functions, hotspots,
  maintainability index, code metrics.
license: Apache-2.0
compatibility: "Works with any language; best results with JS/TS, Python, Go, Java"
metadata:
  author: terminal-skills
  version: "1.0.0"
  category: development
  tags: ["code-quality", "complexity", "metrics", "static-analysis"]

Code Complexity Scanner

Overview

This skill analyzes source code to measure cyclomatic complexity, cognitive complexity, and function length. It identifies the most complex functions and files in a codebase, helping teams focus refactoring efforts on the code that's hardest to maintain and most likely to harbor bugs.

Instructions

Step 1: Identify Target Language and Files

Detect the primary language from file extensions and package files. Filter to source code only (exclude node_modules, vendor, dist, build, pycache, .git).

Step 2: Measure Cyclomatic Complexity

For each function/method, count:

  • if, elif/else if → +1 each
  • for, while, do-while → +1 each
  • case in switch (each case) → +1 each
  • catch → +1
  • &&, || in conditions → +1 each
  • Ternary ?: → +1
  • Base complexity starts at 1

Step 3: Measure Cognitive Complexity

More nuanced than cyclomatic — penalizes nesting:

  • Each control flow break: +1
  • Each nesting level: +1 additional per level
  • Recursion: +1
  • Boolean operator sequences that switch: +1

Step 4: Identify Hotspot Files

Rank files by:

  1. Maximum function complexity in the file
  2. Average complexity across all functions
  3. Number of functions above threshold (default: 15)
  4. Total lines of code

Step 5: Output Report

Present findings in three tiers:

  • 🔴 Critical (complexity > 25): Must refactor — these functions are untestable
  • 🟡 Warning (complexity 15-25): Should refactor when next modifying
  • 🟢 OK (complexity < 15): Acceptable maintainability

Examples

Example 1: TypeScript Project Scan

User prompt:

Scan src/ for the most complex functions

Agent output:

Complexity Report — src/ (89 files scanned)

🔴 CRITICAL (complexity > 25)
  src/billing/calculator.ts
    calculateInvoiceTotal()     Cyclomatic: 34  Cognitive: 48  Lines: 180
    applyDiscountRules()        Cyclomatic: 26  Cognitive: 31  Lines: 95

  src/api/middleware/auth.ts
    validateAndRefreshToken()   Cyclomatic: 28  Cognitive: 35  Lines: 120

🟡 WARNING (complexity 15-25)
  src/workers/sync.ts
    reconcileRecords()          Cyclomatic: 19  Cognitive: 24  Lines: 88
  src/utils/validators.ts
    validateAddress()           Cyclomatic: 16  Cognitive: 18  Lines: 65

Summary:
  Files scanned: 89 | Functions analyzed: 412
  Average complexity: 6.8 | Median: 4
  Functions above threshold: 14 (3.4%)
  Recommended target: reduce critical functions below 15

Example 2: Python Project with Trend

User prompt:

What are the complexity hotspots in our Django app?

Agent output:

Complexity Hotspots — myapp/ (67 files)

Top 10 by Cyclomatic Complexity:
  Rank  Function                              CC   Lines  File
  1     process_order()                       38   340    views/checkout.py
  2     generate_report()                     27   210    reports/builder.py
  3     sync_inventory()                      24   180    tasks/inventory.py
  4     parse_import_file()                   22   150    importers/csv.py
  5     calculate_shipping()                  19   95     shipping/rates.py

Nesting depth violations (>4 levels):
  views/checkout.py:142    — 6 levels deep in process_order()
  reports/builder.py:89    — 5 levels deep in generate_report()

Recommended refactoring order: process_order() first (highest complexity,
most changed file per git history, 340 lines is 3x recommended max).

Guidelines

  • Thresholds are configurable — default 15 works for most teams, but ask the user if they have a team standard
  • Cognitive > cyclomatic for human readability — cognitive complexity better captures how hard code is to understand
  • Context matters — a parser with complexity 20 might be acceptable; a controller with complexity 20 needs splitting
  • Combine with change frequency — complex code that never changes is less urgent than complex code edited weekly
  • Don't count generated code — exclude auto-generated files, migrations, and schema definitions
  • Suggest specific refactorings — "Extract method" for long functions, "Replace conditional with polymorphism" for deep switch statements, "Introduce parameter object" for functions with 5+ parameters

当前收录版本

1.0.0

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

  • 面向开发者提供代码复杂度分析,解决可维护性痛点
  • 支持多语言(JS/TS/Python/Go/Java),适用性广
  • 提供具体阈值分级和重构建议,实用性强
触发精准95/100

亮点

  • 触发词覆盖完整(复杂度、圈复杂度、认知复杂度等)
  • 边界清晰,能准确匹配用户查询意图
结构规范95/100

亮点

  • 文档结构清晰,包含完整的使用步骤和示例
  • frontmatter 完整,单文件未超限
执行可靠90/100

亮点

  • 提供具体的复杂度计算规则和阈值分级
  • 输出格式示例完整,逻辑清晰
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。