Commit 150c1e1
feat: Implement lcom4 cohesion metrics (#16)
* 機能追加: IndexStore-DBを使用したLCOM4クラスコヒージョンメトリクス実装
SourceKit-LSPからIndexStore-DBへ移行し、より直接的で効率的なLCOM4(Lack of Cohesion of Methods)実装を実現。IndexStore-DBの低レベルAPIを使用することで、LSPプロトコルのオーバーヘッドを削減し、高精度(90-95%)な暗黙的self検出を可能にした。
主な変更:
- IndexStore-DB統合による高精度LCOM4計算エンジン実装
- CLI に --lcom4 と --project-root オプション追加
- 全出力フォーマット(Text/JSON/XML/Xcode)でLCOM4サポート
- Nominal Type(class/struct/actor)検出機能実装
- Union-Findアルゴリズムによる連結成分計算
技術詳細:
- Package.swift: indexstore-db依存関係に変更
- SemanticLCOMCalculator: IndexStoreDB APIを使用
- 構文解析フォールバック実装(IndexStore未生成時)
- Swift 6 Actor並行性準拠
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* 設定: VSCode Swift拡張機能デバッグ設定の更新
Swift拡張機能により、デバッグ設定にtargetとconfigurationフィールドを追加。
より明示的なビルドターゲットとコンフィグレーション指定を可能にする。
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* ドキュメント: LCOM4機能をREADMEに追加
IndexStore-DB統合によるLCOM4クラスコヒージョンメトリクスの機能説明を追加。
主な変更:
- Features セクションに LCOM4 機能を追加
- Supported Complexity Metrics セクションをFunction-levelとClass-levelに分類
- LCOM4 の使用例と要件を追加
- CLI 出力例に LCOM4 テーブルを追加
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* 修正: ComplexityAnalyzerのLCOM4コメントを更新
古い設計(SourceKit-LSP、将来的な実装)を示すコメントを、
現在の実装(IndexStore-DB、高精度セマンティック解析)に合わせて更新。
変更内容:
- "将来的にSourceKit-LSP統合で有効化予定" → "IndexStore-DB統合による高精度(90-95%)セマンティック解析"
- "基本的な構文解析のみ実装" → "IndexStoreが見つからない場合は構文解析ベースのフォールバック"
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* 修正: IndexStoreパスとlibIndexStore.dylibの動的検出
IndexStore-DBの初期化エラーを修正し、LCOM4機能を動作可能に。
主な変更:
- IndexStoreパスを.build/index/storeから.build/debug/index/storeに修正
(アーキテクチャ固有ディレクトリへのシンボリックリンクを使用)
- libIndexStore.dylibのパスを動的に検出する機能を追加
- xcrunを使用してXcodeツールチェーンからライブラリパスを取得
- エラーメッセージを正しいパスに更新
動作確認:
- ComplexityAnalyzer.swift: LCOM4=1 (高凝集度) ✓
- SwiftComplexityCore全体で正常に動作 ✓
TODO: Linux対応が必要(findLibIndexStore関数)
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* chore: upgrade to Swift 6.2 toolchain
- Update swift-tools-version from 6.1 to 6.2 in Package.swift
- Update Xcode version from 16.4 to 26.1 in CI/release workflows
(Xcode 26.1 includes Swift 6.2.x, while 16.4 only has Swift 6.1)
- Update swiftly install version from 6.1 to 6.2 for Linux runners
* chore: Separate build/test step of macos and linux so as to consider libdispatch linking on linux platform.
* fix(ci): use correct Swiftly toolchain path for libdispatch headers on Linux
The previous approach using `which swift` returned the Swiftly wrapper
path (~/.local/share/swiftly/bin/swift) instead of the actual toolchain
path. This caused the libdispatch headers to not be found during
IndexStoreDB compilation.
Now directly references the toolchain directory at
~/.local/share/swiftly/toolchains/<version>/usr to correctly locate
dispatch/dispatch.h headers.
* refactor: reduce high-complexity functions below threshold 15
- extractMembersFromSyntax(): Cognitive 27→3 (extract helper functions)
- formatAsText(): Cognitive 21→3 (separate sections)
- run(): Cognitive 18→4 (extract validation/logging functions)
- formatAsXcodeDiagnostics(): Cognitive 15→0 (use flatMap)
- extractMemberCounts(): refactor using extensions
All tests pass, no functions exceed threshold 15
* docs: translate all Japanese comments to English
Translate all Japanese documentation comments and inline comments
across the codebase to English for better accessibility:
- ComplexityCommand.swift: Helper function doc comments
- OutputFormatter.swift: Formatting section doc comments
- SemanticLCOMCalculator.swift: Union-Find, LCOM4 calculation,
IndexStore-DB integration, and syntax visitor comments
- ClassCohesion.swift: Cohesion model property doc comments
- ComplexityAnalyzer.swift: Analysis flow inline comments
- NominalTypeDetector.swift: Nominal type detection doc comments
No functional changes; only comment translations.
* docs: update Swift version to 6.2 and clarify LCOM4 platform support
- Update Swift version requirements from 6.1+ to 6.2+ in README
- Clarify that LCOM4 feature is macOS-only due to IndexStore-DB dependency
- Translate remaining Japanese comments in Package.swift to English
* refactor(lcom4): require explicit indexStorePath instead of projectRoot
- Change API from `projectRoot` to `indexStorePath` parameter
- Remove automatic IndexStore path inference from project root
- User must now explicitly specify IndexStore location (e.g., .build/debug/index/store)
- Add documentation explaining why enum is excluded from LCOM4 analysis
This change addresses PR review feedback requesting explicit IndexStore path
specification, as projectRoot cannot reliably identify IndexStore location
across different build configurations and project types.
* fix(cli): require --index-store-path when using --lcom4
Previously, using --lcom4 without --index-store-path would silently
disable LCOM4 analysis while printing a misleading warning about
"using basic syntax analysis". Now it correctly exits with an error
and provides a usage example.
* chore: remove outdated fallback comment
The comment mentioned fallback to syntax-based analysis, but this
behavior no longer exists - LCOM4 is either enabled with IndexStore-DB
or completely disabled.
* feat(lcom4): add Linux support with --toolchain-path option
- Add --toolchain-path CLI option for specifying Swift toolchain
- macOS: Auto-detect Xcode toolchain if not specified
- Linux: Require --toolchain-path for LCOM4 analysis
- Add platform-specific libIndexStore discovery (dylib/so)
- Add LCOM4 test steps to CI for both macOS and Linux
- Update README with Linux usage example
* Add debug scripts for build on linux
* chore: fix file type of Block
* fix(ci): use compiled binary directly to avoid rebuild on Linux
swift run may trigger a rebuild without -Xcxx flags, causing
dispatch/dispatch.h not found error. Using .build/debug/SwiftComplexityCLI
directly avoids this issue.
* fix(release): add libdispatch headers path for Linux build
IndexStoreDB requires libdispatch headers on Linux. Add -Xcxx -I flags
to include the Swift toolchain's lib/swift directory.
* fix(ci): update Xcode version to 26.1 for Swift 6.2 support
Package requires swift-tools-version: 6.2 but Xcode 16.4 only has
Swift 6.1.0. Update to Xcode 26.1 which includes Swift 6.2.
* docs: fix Linux example to include required build flags
Linux builds require -Xcxx -I flags for libdispatch headers.
Also use compiled binary directly instead of swift run.
---------
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 3c3c207 commit 150c1e1
File tree
16 files changed
+1425
-113
lines changed- .github/workflows
- .vscode
- Sources
- SwiftComplexityCLI
- SwiftComplexityCore
- Analysis
- Models
- Output
- Processing
- Tests/SwiftComplexityCoreTests
16 files changed
+1425
-113
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
68 | 89 | | |
69 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
70 | 128 | | |
71 | 129 | | |
72 | 130 | | |
| |||
78 | 136 | | |
79 | 137 | | |
80 | 138 | | |
81 | | - | |
| 139 | + | |
82 | 140 | | |
83 | 141 | | |
84 | 142 | | |
| |||
125 | 183 | | |
126 | 184 | | |
127 | 185 | | |
128 | | - | |
| 186 | + | |
129 | 187 | | |
130 | 188 | | |
131 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
| 128 | + | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
147 | 150 | | |
148 | 151 | | |
149 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
150 | 155 | | |
151 | 156 | | |
152 | 157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | | - | |
55 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
49 | 54 | | |
50 | 55 | | |
51 | 56 | | |
| |||
65 | 70 | | |
66 | 71 | | |
67 | 72 | | |
| 73 | + | |
| 74 | + | |
68 | 75 | | |
69 | 76 | | |
70 | 77 | | |
71 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
72 | 85 | | |
73 | 86 | | |
74 | 87 | | |
| |||
100 | 113 | | |
101 | 114 | | |
102 | 115 | | |
103 | | - | |
| 116 | + | |
104 | 117 | | |
105 | 118 | | |
106 | 119 | | |
107 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
108 | 125 | | |
109 | 126 | | |
110 | 127 | | |
| |||
114 | 131 | | |
115 | 132 | | |
116 | 133 | | |
117 | | - | |
| 134 | + | |
118 | 135 | | |
119 | 136 | | |
120 | 137 | | |
| |||
173 | 190 | | |
174 | 191 | | |
175 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
176 | 201 | | |
177 | 202 | | |
178 | 203 | | |
| |||
186 | 211 | | |
187 | 212 | | |
188 | 213 | | |
189 | | - | |
| 214 | + | |
190 | 215 | | |
191 | 216 | | |
192 | 217 | | |
193 | 218 | | |
194 | | - | |
| 219 | + | |
195 | 220 | | |
196 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
197 | 242 | | |
198 | 243 | | |
199 | 244 | | |
0 commit comments