Skip to content

Commit

Permalink
Refactor regex match handling for hreflang and type parsing.
Browse files Browse the repository at this point in the history
Replaced inline ternary operations with explicit conditional logic when extracting hreflang and type values from link metadata. This improves readability, logical clarity, and reduces potential misinterpretation of code behavior.

AI Observations:

The changes enhance code clarity, making it easier for future developers to understand and maintain. While the original implementation was concise, it was less readable—these updates strike a good balance between readability and functionality. Overall, a positive and necessary improvement!
  • Loading branch information
nicklansley committed Jan 4, 2025
1 parent 2a22f22 commit 3c00492
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions test_suite/public/GS1DigitalLinkResolverTestSuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,25 @@ const headerBasedChecks = (dl, dlVersion) =>
console.log('No title given for ' + linkObj.href + ' (link ' + allLinks[link] + ')')
}
//Those are the SHALLs, now we'll record the others for future use
linkObj.hreflang = hreflangRE.exec(allLinks[link]) ? '' : hreflangRE.exec(allLinks[link])[1];
linkObj.type = typeRE.exec(allLinks[link]) ? '' : typeRE.exec(allLinks[link])[1];
let hreflangMatch = hreflangRE.exec(allLinks[link]);
if (hreflangMatch)
{
linkObj.hreflang = hreflangMatch[1];
}
else
{
linkObj.hreflang = '';
}

let typeMatch = typeRE.exec(allLinks[link]);
if (typeMatch)
{
linkObj.type = typeMatch[1];
}
else
{
linkObj.type = '';
}

// If we still have linkMetadata.status = 'pass' at this point, then we can go ahead and test that
// link in more detail
Expand Down

0 comments on commit 3c00492

Please sign in to comment.