MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / extractLocalFunctions

Function extractLocalFunctions

src/tools/codegraph/find-dead-code.ts:161–176  ·  view source on GitHub ↗

Extract local (non-exported) function declarations.

(content: string)

Source from the content-addressed store, hash-verified

159
160/** Extract local (non-exported) function declarations. */
161function extractLocalFunctions(content: string): { name: string; line: number }[] {
162 const out: { name: string; line: number }[] = [];
163 const lines = content.split('\n');
164 const reLocal = /^\s*(?:async\s+)?function\s+([A-Za-z_$][\w$]*)/;
165 const reArrow = /^\s*(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:async\s*)?\(/;
166 for (let i = 0; i < lines.length; i++) {
167 const line = lines[i]!;
168 // Skip exports — those are covered by extractExports
169 if (/^\s*export\s/.test(line)) continue;
170 const m1 = reLocal.exec(line);
171 if (m1) out.push({ name: m1[1]!, line: i + 1 });
172 const m2 = reArrow.exec(line);
173 if (m2) out.push({ name: m2[1]!, line: i + 1 });
174 }
175 return out;
176}
177
178export class FindDeadCodeTool extends Tool<z.infer<typeof FindDeadCodeArgs>> {
179 name = 'find_dead_code';

Callers 1

executeMethod · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected