(documentURL: string, fixes: DynamicThemeFix[])
| 12 | * @returns A single fix constructed from the generic fix and a single most relevant other fix |
| 13 | */ |
| 14 | export function findRelevantFix(documentURL: string, fixes: DynamicThemeFix[]): number | null { |
| 15 | if (!Array.isArray(fixes) || fixes.length === 0 || fixes[0].url[0] !== '*') { |
| 16 | logWarn('selectRelevantFix() failed to construct a single fix', documentURL, fixes); |
| 17 | return null; |
| 18 | } |
| 19 | |
| 20 | let maxSpecificity = 0; |
| 21 | let maxSpecificityIndex: number | null = null; |
| 22 | for (let i = 1; i < fixes.length; i++) { |
| 23 | if (isURLInList(documentURL, fixes[i].url)) { |
| 24 | // Note: this is legacy logic, a bit odd |
| 25 | const specificity = fixes[i].url[0].length; |
| 26 | if (maxSpecificityIndex === null || maxSpecificity < specificity) { |
| 27 | maxSpecificity = specificity; |
| 28 | maxSpecificityIndex = i; |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | return maxSpecificityIndex; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Constructs a single fix out of multiple fixes, without modifying the original fixes |
no test coverage detected