MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / findDeadCode

Method findDeadCode

src/graph/queries.ts:270–294  ·  view source on GitHub ↗

* 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'][])

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

pushMethod · 0.80
getNodesByKindMethod · 0.65
getIncomingEdgesMethod · 0.65

Tested by

no test coverage detected