MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / findErrorCodeAssertions

Function findErrorCodeAssertions

scripts/lint-error-codes.cjs:54–79  ·  view source on GitHub ↗
(node, trail)

Source from the content-addressed store, hash-verified

52}
53
54function* findErrorCodeAssertions(node, trail) {
55 if (Array.isArray(node)) {
56 for (let i = 0; i < node.length; i++) {
57 yield* findErrorCodeAssertions(node[i], [...trail, i]);
58 }
59 return;
60 }
61 if (node && typeof node === 'object') {
62 if (node.check === 'error_code') {
63 if (typeof node.value === 'string') {
64 yield { code: node.value, trail: [...trail, 'value'] };
65 }
66 if (Array.isArray(node.allowed_values)) {
67 for (let i = 0; i < node.allowed_values.length; i++) {
68 const v = node.allowed_values[i];
69 if (typeof v === 'string') {
70 yield { code: v, trail: [...trail, 'allowed_values', i] };
71 }
72 }
73 }
74 }
75 for (const key of Object.keys(node)) {
76 yield* findErrorCodeAssertions(node[key], [...trail, key]);
77 }
78 }
79}
80
81function lintFile(filePath, { canonical, aliases }) {
82 const violations = [];

Callers 1

lintFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected