* Find dead code (nodes with no incoming references) * * @param kinds - Node kinds to check (default: functions, methods, classes) * @returns Array of unreferenced nodes
(kinds?: Node['kind'][])
| 268 | * @returns Array of unreferenced nodes |
| 269 | */ |
| 270 | findDeadCode(kinds?: Node['kind'][]): Node[] { |
| 271 | const targetKinds = kinds || ['function', 'method', 'class']; |
| 272 | const deadCode: Node[] = []; |
| 273 | |
| 274 | for (const kind of targetKinds) { |
| 275 | const nodes = this.queries.getNodesByKind(kind); |
| 276 | for (const node of nodes) { |
| 277 | // Skip exported symbols (they may be used externally) |
| 278 | if (node.isExported) { |
| 279 | continue; |
| 280 | } |
| 281 | |
| 282 | const incomingEdges = this.queries.getIncomingEdges(node.id); |
| 283 | |
| 284 | // Filter out containment edges |
| 285 | const references = incomingEdges.filter((e) => e.kind !== 'contains'); |
| 286 | |
| 287 | if (references.length === 0) { |
| 288 | deadCode.push(node); |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | return deadCode; |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Get subgraph containing nodes matching a filter |
nothing calls this directly
no test coverage detected