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

Method findDeadCode

src/graph/queries.ts:271–295  ·  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

269 * @returns Array of unreferenced nodes
270 */
271 findDeadCode(kinds?: Node['kind'][]): Node[] {
272 const targetKinds = kinds || ['function', 'method', 'class'];
273 const deadCode: Node[] = [];
274
275 for (const kind of targetKinds) {
276 const nodes = this.queries.getNodesByKind(kind);
277 for (const node of nodes) {
278 // Skip exported symbols (they may be used externally)
279 if (node.isExported) {
280 continue;
281 }
282
283 const incomingEdges = this.queries.getIncomingEdges(node.id);
284
285 // Filter out containment edges
286 const references = incomingEdges.filter((e) => e.kind !== 'contains');
287
288 if (references.length === 0) {
289 deadCode.push(node);
290 }
291 }
292 }
293
294 return deadCode;
295 }
296
297 /**
298 * 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