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

Function checkJsonSyntax

src/tools/ast/syntax-check.ts:93–107  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

91
92/** Pure: JSON validation with a line number extracted from the parse error. */
93export function checkJsonSyntax(content: string): SyntaxIssue[] {
94 try {
95 JSON.parse(content);
96 return [];
97 } catch (e: any) {
98 const msg: string = e?.message ?? 'invalid JSON';
99 let line = 1;
100 const mPos = msg.match(/position (\d+)/i);
101 const mLine = msg.match(/line (\d+)/i);
102 if (mLine) line = parseInt(mLine[1], 10);
103 else if (mPos) line = content.slice(0, parseInt(mPos[1], 10)).split('\n').length;
104 const lines = content.split('\n');
105 return [{ line, excerpt: (lines[line - 1] ?? '').trim().slice(0, 120), kind: 'error' }];
106 }
107}
108
109/** Pure: the gate decision. Reject only if the EDIT introduced the breakage. */
110export function shouldReject(beforeHadErrors: boolean | null, afterHasErrors: boolean): boolean {

Callers 2

checkSyntaxForWriteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected