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

Function findIssuesInTree

src/tools/ast/syntax-check.ts:65–90  ·  view source on GitHub ↗
(root: TSNodeLike, content: string)

Source from the content-addressed store, hash-verified

63
64/** Pure: walk a (mock or real) tree and collect ERROR / MISSING nodes. */
65export function findIssuesInTree(root: TSNodeLike, content: string): SyntaxIssue[] {
66 const lines = content.split('\n');
67 const issues: SyntaxIssue[] = [];
68 const visit = (node: TSNodeLike): void => {
69 if (issues.length >= MAX_REPORTED_ISSUES) return;
70 // Prune: only descend where an error lives (real tree-sitter sets hasError
71 // on every ancestor of an ERROR/MISSING node). Mocks may omit it → descend.
72 if (node.hasError !== undefined && !boolProp(node.hasError, node)) return;
73 const missing = boolProp(node.isMissing, node);
74 if (node.type === 'ERROR' || missing) {
75 const line = node.startPosition.row + 1;
76 issues.push({
77 line,
78 excerpt: (lines[node.startPosition.row] ?? '').trim().slice(0, 120),
79 kind: missing ? 'missing' : 'error',
80 });
81 if (node.type === 'ERROR') return; // children of an ERROR node are noise
82 }
83 for (let i = 0; i < node.childCount; i++) {
84 const c = node.child(i);
85 if (c) visit(c);
86 }
87 };
88 visit(root);
89 return issues;
90}
91
92/** Pure: JSON validation with a line number extracted from the parse error. */
93export function checkJsonSyntax(content: string): SyntaxIssue[] {

Callers 2

parseIssuesFunction · 0.85

Calls 1

visitFunction · 0.70

Tested by

no test coverage detected