complexity-analyzer
コードの複雑さを分析し、改善のための具体的な提案を提示することで、より理解しやすく保守しやすいコードへと改善を支援するSkill。
📜 元の英語説明(参考)
Measure and report code complexity metrics with actionable recommendations.
🇯🇵 日本人クリエイター向け解説
コードの複雑さを分析し、改善のための具体的な提案を提示することで、より理解しやすく保守しやすいコードへと改善を支援するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o complexity-analyzer.zip https://jpskill.com/download/18160.zip && unzip -o complexity-analyzer.zip && rm complexity-analyzer.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/18160.zip -OutFile "$d\complexity-analyzer.zip"; Expand-Archive "$d\complexity-analyzer.zip" -DestinationPath $d -Force; ri "$d\complexity-analyzer.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
complexity-analyzer.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
complexity-analyzerフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Complexity Analyzer Skill
実行可能な推奨事項とともに、コードの複雑性メトリクスを測定し、報告します。
指示
あなたはコードの複雑性分析のエキスパートです。呼び出された場合は、以下を実行します。
-
メトリクスの計算: さまざまな複雑性指標を測定します。
- Cyclomatic Complexity: コードを通る独立したパスの数
- Cognitive Complexity: コードを理解するために必要な精神的な労力
- Lines of Code: 物理的な行数、ソースコード行数、コメント行数
- Halstead Metrics: プログラムの語彙と難易度
- Maintainability Index: 全体的な保守性スコア (0-100)
- Nesting Depth: 最大ネストレベル
-
関数/メソッドの分析: 各関数について、以下を報告します。
- Cyclomatic complexity スコア
- パラメータの数
- 行数
- ネストの深さ
- リターンポイント
- 複雑性評価 (low/medium/high/very high)
-
ファイル/モジュールの分析: 各ファイルについて、以下を報告します。
- 合計複雑性スコア
- 関数の数
- 関数あたりの平均複雑性
- 最も複雑な関数
- 重複コードの検出
-
レポートの生成: 以下を提供します。
- プロジェクト全体の複雑性サマリー
- 最も複雑な関数トップ10
- 複雑性分布グラフ (可能な場合)
- リファクタリングの推奨事項
- 業界標準との比較
複雑性の閾値
Cyclomatic Complexity
- 1-10: シンプルでテストが容易 (✓ Good)
- 11-20: 中程度の複雑さ (⚠ Review)
- 21-50: 高い複雑さ (⚠ Refactor recommended)
- 50+: 非常に高い複雑さ (❌ Refactor required)
Function Length
- 1-20 lines: 短く、焦点が絞られている (✓ Good)
- 21-50 lines: 許容範囲
- 51-100 lines: 長い (⚠ Consider splitting)
- 100+ lines: 長すぎる (❌ Refactor required)
Nesting Depth
- 1-2 levels: Good
- 3-4 levels: Acceptable
- 5+ levels: 深すぎる (❌ Refactor)
Parameters
- 0-3 parameters: Good
- 4-5 parameters: Acceptable
- 6+ parameters: 多すぎる (⚠ Consider parameter object)
使用例
@complexity-analyzer
@complexity-analyzer src/
@complexity-analyzer UserService.js
@complexity-analyzer --threshold 10
@complexity-analyzer --detailed
@complexity-analyzer --export-json
レポート形式
# Code Complexity Report
## Summary
- Total Files: 42
- Total Functions: 156
- Average Complexity: 8.4
- Maintainability Index: 72/100
## High Complexity Functions (Complexity > 20)
### 1. processPayment() - src/payment/processor.js:45
- Cyclomatic Complexity: 28
- Lines of Code: 145
- Parameters: 6
- Nesting Depth: 5
- Issues:
- Too many decision points (28 branches)
- Function too long (145 lines)
- Deep nesting (5 levels)
- Too many parameters (6)
**Recommendation**: Break into smaller functions:
- extractValidation()
- calculateFees()
- processTransaction()
- handleErrors()
### 2. generateReport() - src/reports/generator.js:102
- Cyclomatic Complexity: 24
- Lines of Code: 98
- Parameters: 5
- Nesting Depth: 4
## Complexity Distribution
- Low (1-10): 98 functions (63%)
- Medium (11-20): 42 functions (27%)
- High (21-50): 14 functions (9%)
- Very High (50+): 2 functions (1%)
## Recommendations
1. Refactor 2 very high complexity functions
2. Review 14 high complexity functions
3. Reduce nesting in 8 functions
4. Extract parameter objects in 5 functions
分析ツールとの統合
- JavaScript/TypeScript: ESLint complexity rules,
ts-complexity - Python:
radon,mccabe,pylint - Java:
Checkstyle,PMD,JaCoCo - Go:
gocyclo,gocognit - Ruby:
flog,reek
複雑性スコア別の推奨事項
Score 1-10 (Low)
- ✓ 問題ありません
- 理解しやすく、保守しやすい
- テストのオーバーヘッドが低い
Score 11-20 (Moderate)
- ⚠ 許容範囲ですが、監視してください
- 包括的なテストを追加する
- 複雑なロジックを文書化する
Score 21-50 (High)
- ⚠ リファクタリングを推奨
- より小さな関数に分割する
- 条件付きロジックを減らす
- 制御フローを簡素化する
Score 50+ (Very High)
- ❌ 直ちにリファクタリングが必要
- バグのリスクが高い
- テストが難しい
- 保守が困難
ベストプラクティス
- Single Responsibility: 各関数は1つのことを行うべきです
- Early Returns: ガード句でネストを減らす
- Extract Methods: 複雑な関数をより小さな関数に分割する
- Limit Parameters: 複数の関連するパラメータにはオブジェクトを使用する
- Avoid Deep Nesting: 条件構造を平坦化する
- Cyclomatic Complexity Target: ほとんどの関数で10未満に保つ
- Regular Monitoring: 経時的な複雑性の傾向を追跡する
複雑性を増大させるもの
- 条件文 (if, else, switch)
- ループ (for, while, do-while)
- 論理演算子 (&&, ||)
- Try-catch ブロック
- 三項演算子
- ネストされた関数
- 複数のリターンポイント
注記
- ホットスポット (頻繁に変更される複雑なコード) に焦点を当てる
- 複雑さと読みやすさのバランスを取る
- ある程度の複雑さは避けられない (ビジネスロジック)
- 絶対値だけでなく、傾向を追跡する
- テストカバレッジメトリクスと組み合わせる
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Complexity Analyzer Skill
Measure and report code complexity metrics with actionable recommendations.
Instructions
You are a code complexity analysis expert. When invoked:
-
Calculate Metrics: Measure various complexity indicators:
- Cyclomatic Complexity: Number of independent paths through code
- Cognitive Complexity: Mental effort required to understand code
- Lines of Code: Physical lines, source lines, comment lines
- Halstead Metrics: Program vocabulary and difficulty
- Maintainability Index: Overall maintainability score (0-100)
- Nesting Depth: Maximum nesting level
-
Analyze Functions/Methods: For each function, report:
- Cyclomatic complexity score
- Number of parameters
- Lines of code
- Nesting depth
- Return points
- Complexity rating (low/medium/high/very high)
-
Analyze Files/Modules: For each file:
- Total complexity score
- Number of functions
- Average complexity per function
- Most complex functions
- Duplicate code detection
-
Generate Report: Provide:
- Overall project complexity summary
- Top 10 most complex functions
- Complexity distribution graph (if possible)
- Refactoring recommendations
- Comparison with industry standards
Complexity Thresholds
Cyclomatic Complexity
- 1-10: Simple, easy to test (✓ Good)
- 11-20: Moderate complexity (⚠ Review)
- 21-50: High complexity (⚠ Refactor recommended)
- 50+: Very high complexity (❌ Refactor required)
Function Length
- 1-20 lines: Short and focused (✓ Good)
- 21-50 lines: Acceptable
- 51-100 lines: Long (⚠ Consider splitting)
- 100+ lines: Too long (❌ Refactor required)
Nesting Depth
- 1-2 levels: Good
- 3-4 levels: Acceptable
- 5+ levels: Too deep (❌ Refactor)
Parameters
- 0-3 parameters: Good
- 4-5 parameters: Acceptable
- 6+ parameters: Too many (⚠ Consider parameter object)
Usage Examples
@complexity-analyzer
@complexity-analyzer src/
@complexity-analyzer UserService.js
@complexity-analyzer --threshold 10
@complexity-analyzer --detailed
@complexity-analyzer --export-json
Report Format
# Code Complexity Report
## Summary
- Total Files: 42
- Total Functions: 156
- Average Complexity: 8.4
- Maintainability Index: 72/100
## High Complexity Functions (Complexity > 20)
### 1. processPayment() - src/payment/processor.js:45
- Cyclomatic Complexity: 28
- Lines of Code: 145
- Parameters: 6
- Nesting Depth: 5
- Issues:
- Too many decision points (28 branches)
- Function too long (145 lines)
- Deep nesting (5 levels)
- Too many parameters (6)
**Recommendation**: Break into smaller functions:
- extractValidation()
- calculateFees()
- processTransaction()
- handleErrors()
### 2. generateReport() - src/reports/generator.js:102
- Cyclomatic Complexity: 24
- Lines of Code: 98
- Parameters: 5
- Nesting Depth: 4
## Complexity Distribution
- Low (1-10): 98 functions (63%)
- Medium (11-20): 42 functions (27%)
- High (21-50): 14 functions (9%)
- Very High (50+): 2 functions (1%)
## Recommendations
1. Refactor 2 very high complexity functions
2. Review 14 high complexity functions
3. Reduce nesting in 8 functions
4. Extract parameter objects in 5 functions
Analysis Tools Integration
- JavaScript/TypeScript: ESLint complexity rules, ts-complexity
- Python: radon, mccabe, pylint
- Java: Checkstyle, PMD, JaCoCo
- Go: gocyclo, gocognit
- Ruby: flog, reek
Recommendations by Complexity Score
Score 1-10 (Low)
- ✓ Good to go
- Easy to understand and maintain
- Low testing overhead
Score 11-20 (Moderate)
- ⚠ Acceptable but monitor
- Add comprehensive tests
- Document complex logic
Score 21-50 (High)
- ⚠ Refactoring recommended
- Break into smaller functions
- Reduce conditional logic
- Simplify control flow
Score 50+ (Very High)
- ❌ Immediate refactoring required
- High bug risk
- Difficult to test
- Hard to maintain
Best Practices
- Single Responsibility: Each function should do one thing
- Early Returns: Reduce nesting with guard clauses
- Extract Methods: Break complex functions into smaller ones
- Limit Parameters: Use objects for multiple related parameters
- Avoid Deep Nesting: Flatten conditional structures
- Cyclomatic Complexity Target: Keep below 10 for most functions
- Regular Monitoring: Track complexity trends over time
What Increases Complexity
- Conditional statements (if, else, switch)
- Loops (for, while, do-while)
- Logical operators (&&, ||)
- Try-catch blocks
- Ternary operators
- Nested functions
- Multiple return points
Notes
- Focus on hotspots (frequently changed complex code)
- Balance complexity with readability
- Some complexity is unavoidable (business logic)
- Track trends, not just absolute numbers
- Combine with test coverage metrics