MCPcopy Create free account
hub / github.com/openai/plugins / detectFunctions

Function detectFunctions

plugins/plugin-eval/src/evaluators/python.js:20–69  ·  view source on GitHub ↗
(lines)

Source from the content-addressed store, hash-verified

18}
19
20function detectFunctions(lines) {
21 const functions = [];
22 for (let index = 0; index < lines.length; index += 1) {
23 const line = lines[index];
24 const match = /^(\s*)(?:async\s+def|def)\s+([A-Za-z0-9_]+)\s*\(([^)]*)\)\s*:/.exec(line);
25 if (!match) {
26 continue;
27 }
28
29 const indent = match[1].length;
30 let endIndex = index;
31 for (let cursor = index + 1; cursor < lines.length; cursor += 1) {
32 const cursorLine = lines[cursor];
33 const trimmed = cursorLine.trim();
34 if (!trimmed) {
35 continue;
36 }
37 const cursorIndent = cursorLine.length - cursorLine.trimStart().length;
38 if (cursorIndent <= indent && !trimmed.startsWith("#")) {
39 break;
40 }
41 endIndex = cursor;
42 }
43
44 const slice = lines.slice(index, endIndex + 1);
45 const source = slice.join("\n");
46 const maxIndent = slice.reduce((max, sliceLine) => {
47 if (!sliceLine.trim()) {
48 return max;
49 }
50 const currentIndent = sliceLine.length - sliceLine.trimStart().length;
51 return Math.max(max, currentIndent);
52 }, indent);
53 const params = match[3]
54 .split(",")
55 .map((item) => item.trim())
56 .filter(Boolean).length;
57
58 functions.push({
59 name: match[2],
60 startLine: index + 1,
61 endLine: endIndex + 1,
62 length: slice.length,
63 params,
64 complexity: 1 + countDecisionPoints(source),
65 nesting: Math.max(0, Math.round((maxIndent - indent) / 4)),
66 });
67 }
68 return functions;
69}
70
71export async function analyzePythonFiles(filePaths, rootPath) {
72 const checks = [];

Callers 1

analyzePythonFilesFunction · 0.70

Calls 3

filterMethod · 0.80
mapMethod · 0.80
countDecisionPointsFunction · 0.70

Tested by

no test coverage detected