| 22 | const END_BRACKETS = ["}", "});", "})"]; |
| 23 | |
| 24 | function linesMatch(lineA: string, lineB: string, linesBetween = 0): boolean { |
| 25 | // Require a perfect (without padding) match for these lines |
| 26 | // Otherwise they are edit distance 1 from empty lines and other single char lines (e.g. each other) |
| 27 | if (["}", "*", "});", "})"].includes(lineA.trim())) { |
| 28 | return lineA.trim() === lineB.trim(); |
| 29 | } |
| 30 | |
| 31 | const d = distance(lineA, lineB); |
| 32 | |
| 33 | return ( |
| 34 | // Should be more unlikely for lines to fuzzy match if they are further away |
| 35 | (d / Math.max(lineA.length, lineB.length) <= |
| 36 | Math.max(0, 0.48 - linesBetween * 0.06) || |
| 37 | lineA.trim() === lineB.trim()) && |
| 38 | lineA.trim() !== "" |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Used to find a match for a new line in an array of old lines. |