360 Secure SkillHub
360 安全技能中心

Code Metrics

核心功能包括:统计各语言代码/注释行数、注释比、函数类数量;分析Python函数圈复杂度并分级告警;识别行数最多的大文件。典型场景:代码质量评估、行数统计、项目概览、代码审计。支持指定目录分析,可输出JSON格式,支持跳过复杂度分析、排除指定目录。依赖Python3.8+,无需额外第三方包。

johnnywang2001
johnnywang2001
热度 43.99
最近更新 2026-05-11 17:35:58
分类:开发依赖:代码执行 / 读写文件应用场景:代码审查 / 数据处理 / 报告撰写

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add code-metrics
Metadata
name
code-metrics
description
Analyze code quality metrics including lines of code by language, cyclomatic complexity (Python), function/class counts, comment ratios, and largest file rankings. Use when asked to analyze code quality, count lines of code, measure complexity, find the biggest files, get a project overview, or audit code metrics across a codebase. Supports Python, JavaScript, TypeScript, Go, Rust, Ruby, Java, C/C++, C#, Swift, Kotlin, PHP, Shell, Lua, R, and Scala.

Code Metrics

Analyze code quality and complexity metrics across your project. Supports 17+ languages.

Quick Start

# Analyze current project
python3 scripts/code_metrics.py

# Analyze specific directory
python3 scripts/code_metrics.py /path/to/project

# JSON output
python3 scripts/code_metrics.py --json

# Skip complexity analysis (faster)
python3 scripts/code_metrics.py --no-complexity

# Exclude additional directories
python3 scripts/code_metrics.py --exclude migrations fixtures

Metrics Provided

  • Lines of Code — total, code, comments, blank lines per language
  • Comment-to-code ratio — overall documentation density
  • Function & class counts — per language
  • Cyclomatic complexity — per-function for Python files (AST-based)
  • Largest files — top N files ranked by code lines
  • High complexity warnings — flags functions with complexity ≥5

Complexity Scale (Python)

Range Risk Meaning
1-4 🟢 Low Simple, well-structured
5-9 🟢 Moderate Acceptable
10-14 🟡 High Consider refactoring
15+ 🔴 Very High Refactor strongly recommended

Dependencies

  • Python 3.8+ (stdlib only, no pip packages needed)