( invalidWord: string, validWords: string[] )
| 28 | if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) |
| 29 | v = Math.min(v, prevPrev[j - 2] + 1); // transposition |
| 30 | curr[j] = v; |
| 31 | if (v < rowMin) rowMin = v; |
| 32 | } |
| 33 | if (rowMin > max) return max + 1; |
| 34 | [prevPrev, prev, curr] = [prev, curr, prevPrev]; |
| 35 | } |
| 36 | return prev[lb]; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Given an invalid word, return the best match amongst validWords. |
| 41 | * |
| 42 | * Permissive by design (distance up to 7): callers use it to *decorate* an |
| 43 | * error that has already been raised, where a mediocre suggestion is |
| 44 | * harmless. For a matcher whose result decides whether a warning fires at |
| 45 | * all, use the conservative `suggestOperatorName` (engine-declarations.ts), |
| 46 | * which layers stricter policy over the same `osaDistance` kernel. |
| 47 | */ |
| 48 | export function fuzzyStringMatch( |
| 49 | invalidWord: string, |
| 50 | validWords: string[] |
| 51 | ): string | null { |
| 52 | const threshold = 7; |
| 53 | let bestMatch: string | null = null; |
| 54 | let minDistance = Infinity; |
| 55 | |
| 56 | for (const word of validWords) { |
no test coverage detected