本文へ移動
cccskills
無料GitHub で公開

code-quality-metrics

This skill should be used when the user asks about "code complexity", "cyclomatic complexity", "cognitive complexity", "code metrics", "maintainability index", "code coverage", or when measuring code quality quantitatively. Provides metrics thresholds and measurement techniques.

インストール方法を見る

含まれるファイル(3)

  • SKILL.md5.1 KB
  • .skillfish.json263 B
  • references/measurement-tools.md6.0 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Code Quality Metrics Guide

Overview

Code quality metrics provide quantitative measures of code characteristics. This skill covers complexity metrics, maintainability indices, and their practical thresholds across different languages.

Complexity Metrics

Cyclomatic Complexity (CC)

Measures the number of linearly independent paths through code.

Calculation: CC = E - N + 2P

  • E = edges in control flow graph
  • N = nodes in control flow graph
  • P = connected components (usually 1)

Simplified: Count decision points + 1

  • Each if, elif, else, for, while, case, catch, &&, ||, ?: adds 1

Thresholds:

RangeRiskAction
1-10LowSimple, well-structured
11-20ModerateMore complex, consider refactoring
21-50HighComplex, difficult to test
>50Very HighUntestable, must refactor

Cognitive Complexity

Measures how difficult code is to understand (introduced by SonarQube).

Key differences from CC:

  • Penalizes nested structures more heavily
  • Doesn't count all decision points equally
  • Focuses on human comprehension

Calculation rules:

  1. +1 for each break in linear flow (if, for, while, switch, catch, ?:)
  2. +1 for each nesting level inside these structures
  3. +1 for binary logical operators (&&, ||)
  4. Recursion adds +1

Thresholds:

RangeAssessment
0-7Easy to understand
8-15Moderate complexity
16-24High complexity, refactor
25+Very high, immediate refactoring

Example:

def process(items):           # 0
    for item in items:        # +1 (loop)
        if item.active:       # +1 (if) +1 (nesting=1)
            if item.valid:    # +1 (if) +2 (nesting=2)
                handle(item)
    return items              # Total: 6

Halstead Metrics

Based on counting operators and operands:

MetricFormulaMeaning
Vocabularyn = n1 + n2Unique operators + operands
LengthN = N1 + N2Total operators + operands
VolumeV = N × log2(n)Size of implementation
DifficultyD = (n1/2) × (N2/n2)Error-proneness
EffortE = D × VMental effort to understand

Maintainability Metrics

Maintainability Index (MI)

Composite metric combining complexity, size, and comments.

Formula: MI = 171 - 5.2 × ln(V) - 0.23 × CC - 16.2 × ln(LOC)

Thresholds:

RangeMaintainability
85-100High maintainability
65-84Moderate maintainability
0-64Low maintainability

Lines of Code (LOC)

MetricDescriptionThreshold
Physical LOCAll lines including blanks/commentsMethod: <100, Class: <500
Logical LOCExecutable statementsMethod: <30, Class: <200
Comment RatioComments / Total10-30% typical

Coupling Metrics

Afferent Coupling (Ca)

Number of classes that depend on this class.

  • High Ca = Many dependents, changes are risky

Efferent Coupling (Ce)

Number of classes this class depends on.

  • High Ce = Many dependencies, class is fragile

Instability (I)

I = Ce / (Ca + Ce)

  • 0 = Stable (many dependents, few dependencies)
  • 1 = Unstable (few dependents, many dependencies)

Cohesion Metrics

Lack of Cohesion of Methods (LCOM)

Measures how related methods are within a class.

LCOM1: Number of method pairs without shared instance variables

  • 0 = Perfect cohesion
  • High = Low cohesion, consider splitting

LCOM4: Number of connected components in method-field graph

  • 1 = Cohesive class
  • 1 = Multiple responsibilities

Quick Reference Table

MetricToolGoodWarningCritical
CyclomaticESLint, SonarQube≤1011-20>20
CognitiveSonarQube≤1516-24>24
Method LOC-≤3031-50>50
Class LOC-≤300301-500>500
ParametersESLint≤34-5>5
Nesting DepthESLint≤34>4
LCOM4-12>2

Measurement Commands

ESLint Complexity

npx eslint --rule 'complexity: ["error", 10]' src/

SonarQube Analysis

sonar-scanner -Dsonar.projectKey=myproject

Python Radon

radon cc src/ -a -s  # Cyclomatic complexity
radon mi src/ -s     # Maintainability index

Additional Resources

Reference Files

For detailed measurement techniques:

  • references/measurement-tools.md - Tool configurations and usage
  • references/thresholds-by-language.md - Language-specific thresholds

Integration with Other Skills

Combine with:

  • solid-principles for structural analysis
  • refactoring-patterns for improvement strategies

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Browser automation CLI for AI agents. Use when needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. TRIGGER when user requests to "open a website", "fill out a form", "click a button", "take a screenshot", "debug this in browser", "scrape data from a page", "test this web app", "login to a site", "frontend UI/UX aesthetics", "automate browser actions", or any task requiring programmatic web interaction.

日本語の概要は準備中です。原文の説明を表示しています。

archibate/dotfiles-opencode1082026年4月29日 更新

Review common AI slops of defensive programming patterns, avoid silent errors. TRIGGER when reviewing code for defensive anti-patterns, writing fail-fast code, or auditing error handling quality.

日本語の概要は準備中です。原文の説明を表示しています。

archibate/dotfiles-opencode1082026年4月29日 更新

ast-grep

無料

Guide for writing ast-grep rules to perform structural code search and analysis. This skill should be used when users need to search codebases using Abstract Syntax Tree (AST) patterns, find specific code structures, or perform complex code queries that go beyond simple text search, or when a simple grep/glob search is insufficient for structural code pattern matching.

日本語の概要は準備中です。原文の説明を表示しています。

archibate/dotfiles-opencode1082026年4月29日 更新

Best practices for AI-driven English-to-Chinese translation. This skill should be used when the user asks to "translate to Chinese", "update the Chinese translation", "improve Chinese translation", "fix translation quality", "review Chinese translation", or when translating any English text into Chinese. Also applies when polishing an existing Chinese translation of English content.

日本語の概要は準備中です。原文の説明を表示しています。

archibate/dotfiles-opencode1082026年4月29日 更新

This skill should be used when the user asks to "use bilibili API", "download bilibili video", "get bilibili user info", "list bilibili favorites", "send bilibili danmaku", "upload video to bilibili", "monitor bilibili live room", "search bilibili", "get bilibili comments", or needs guidance on the bilibili_api Python library usage, authentication, API endpoints, or workflow patterns.

日本語の概要は準備中です。原文の説明を表示しています。

archibate/dotfiles-opencode1082026年4月29日 更新

This skill should be used when sending images, files, or notifications back to the user via messaging platforms (Discord, Feishu, Telegram, etc.) through cc-connect. TRIGGER when agent generates a plot/chart/screenshot and wants to show the user; agent creates a report/PDF/file the user should receive; agent needs to proactively notify the user (e.g. task completed, alert, reminder); user asks to "send image", "show me the chart", "notify me", "send the file", "send to Telegram", "show plot in Discord".

日本語の概要は準備中です。原文の説明を表示しています。

archibate/dotfiles-opencode1082026年4月29日 更新

archibate のスキルをすべて見る

このスキルの問題を報告する