(content: string)
| 91 | |
| 92 | /** Pure: JSON validation with a line number extracted from the parse error. */ |
| 93 | export 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. */ |
| 110 | export function shouldReject(beforeHadErrors: boolean | null, afterHasErrors: boolean): boolean { |
no outgoing calls
no test coverage detected