MCPcopy
hub / github.com/google-labs-code/design.md / forEachLeaf

Function forEachLeaf

packages/cli/src/linter/model/handler.ts:412–441  ·  view source on GitHub ↗

* Recursively iterate over an object and call a function for each leaf node. * Leaf node paths are dot-separated (e.g. "background.light").

(
  obj: Record<string, any>,
  fn: (path: string, value: any) => void,
  prefix = '',
  depth = 0,
  findings?: Finding[],
  rootPath?: string
)

Source from the content-addressed store, hash-verified

410 * Leaf node paths are dot-separated (e.g. "background.light").
411 */
412function forEachLeaf(
413 obj: Record<string, any>,
414 fn: (path: string, value: any) => void,
415 prefix = '',
416 depth = 0,
417 findings?: Finding[],
418 rootPath?: string
419) {
420 if (depth > MAX_TOKEN_NESTING_DEPTH) {
421 if (findings && rootPath) {
422 // Check if we've already reported this rootPath to avoid spamming
423 if (!findings.some((f) => f.path === rootPath && f.message.includes('nesting depth'))) {
424 findings.push({
425 severity: 'error',
426 path: rootPath,
427 message: `Token nesting depth exceeds maximum allowed depth of ${MAX_TOKEN_NESTING_DEPTH}.`,
428 });
429 }
430 }
431 return;
432 }
433 for (const [key, value] of Object.entries(obj)) {
434 const fullPath = prefix ? `${prefix}.${key}` : key;
435 if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
436 forEachLeaf(value, fn, fullPath, depth + 1, findings, rootPath);
437 } else {
438 fn(fullPath, value);
439 }
440 }
441}

Callers 1

executeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…