(diff: string)
| 6 | * 2. Contains valid diff content lines (starting with +, -, or space) which are not header lines |
| 7 | */ |
| 8 | export function isUnifiedDiffFormat(diff: string): boolean { |
| 9 | const lines = diff.trim().split("\n"); |
| 10 | |
| 11 | if (lines.length < 3) { |
| 12 | return false; |
| 13 | } |
| 14 | |
| 15 | let hasHunkHeader = false; |
| 16 | let hasValidContent = false; |
| 17 | |
| 18 | for (const line of lines) { |
| 19 | if (line.startsWith("---") || line.startsWith("+++")) { |
| 20 | // ignore file headers - they are not required or useful |
| 21 | } else if (line.match(/^@@ -\d+,?\d* \+\d+,?\d* @@/)) { |
| 22 | hasHunkHeader = true; |
| 23 | } else if (line.match(/^[+ -]/) || line === "") { |
| 24 | hasValidContent = true; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | return hasHunkHeader && hasValidContent; |
| 29 | } |
| 30 | |
| 31 | function extractBeforeLines(hunkLines: string[]): string[] { |
| 32 | return hunkLines |
no outgoing calls
no test coverage detected