From 33e3bf7ce2ee27dec94bf1e56a540bb96d1ba4fb Mon Sep 17 00:00:00 2001 From: Michael Kriese <michael.kriese@visualon.de> Date: Tue, 23 Aug 2022 21:38:24 +0200 Subject: [PATCH] refactor: move nested function to module scope (#17361) Co-authored-by: Rhys Arkins <rhys@arkins.net> --- lib/modules/manager/regex/utils.ts | 42 ++++++++++++++++-------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/lib/modules/manager/regex/utils.ts b/lib/modules/manager/regex/utils.ts index 3158298f3b..fab60f86ec 100644 --- a/lib/modules/manager/regex/utils.ts +++ b/lib/modules/manager/regex/utils.ts @@ -20,6 +20,27 @@ export const validMatchFields = [ type ValidMatchFields = typeof validMatchFields[number]; +function updateDependency( + dependency: PackageDependency, + field: ValidMatchFields, + value: string +): void { + switch (field) { + case 'registryUrl': + // check if URL is valid and pack inside an array + try { + const url = new URL(value).toString(); + dependency.registryUrls = [url]; + } catch (err) { + logger.warn({ value }, 'Invalid regex manager registryUrl'); + } + break; + default: + dependency[field] = value; + break; + } +} + export function createDependency( extractionTemplate: ExtractionTemplate, config: CustomExtractConfig, @@ -28,30 +49,13 @@ export function createDependency( const dependency = dep ?? {}; const { groups, replaceString } = extractionTemplate; - function updateDependency(field: ValidMatchFields, value: string): void { - switch (field) { - case 'registryUrl': - // check if URL is valid and pack inside an array - try { - const url = new URL(value).toString(); - dependency.registryUrls = [url]; - } catch (err) { - logger.warn({ value }, 'Invalid regex manager registryUrl'); - } - break; - default: - dependency[field] = value; - break; - } - } - for (const field of validMatchFields) { const fieldTemplate = `${field}Template` as keyof RegexManagerTemplates; const tmpl = config[fieldTemplate]; if (tmpl) { try { const compiled = template.compile(tmpl, groups, false); - updateDependency(field, compiled); + updateDependency(dependency, field, compiled); } catch (err) { logger.warn( { template: tmpl }, @@ -60,7 +64,7 @@ export function createDependency( return null; } } else if (groups[field]) { - updateDependency(field, groups[field]); + updateDependency(dependency, field, groups[field]); } } dependency.replaceString = replaceString; -- GitLab