refactor: move nested function to module scope (#17361)

Co-authored-by: Rhys Arkins <rhys@arkins.net>
This commit is contained in:
Michael Kriese 2022-08-23 21:38:24 +02:00 committed by GitHub
parent 57ade2b33e
commit 33e3bf7ce2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,15 +20,11 @@ export const validMatchFields = [
type ValidMatchFields = typeof validMatchFields[number]; type ValidMatchFields = typeof validMatchFields[number];
export function createDependency( function updateDependency(
extractionTemplate: ExtractionTemplate, dependency: PackageDependency,
config: CustomExtractConfig, field: ValidMatchFields,
dep?: PackageDependency value: string
): PackageDependency | null { ): void {
const dependency = dep ?? {};
const { groups, replaceString } = extractionTemplate;
function updateDependency(field: ValidMatchFields, value: string): void {
switch (field) { switch (field) {
case 'registryUrl': case 'registryUrl':
// check if URL is valid and pack inside an array // check if URL is valid and pack inside an array
@ -43,7 +39,15 @@ export function createDependency(
dependency[field] = value; dependency[field] = value;
break; break;
} }
} }
export function createDependency(
extractionTemplate: ExtractionTemplate,
config: CustomExtractConfig,
dep?: PackageDependency
): PackageDependency | null {
const dependency = dep ?? {};
const { groups, replaceString } = extractionTemplate;
for (const field of validMatchFields) { for (const field of validMatchFields) {
const fieldTemplate = `${field}Template` as keyof RegexManagerTemplates; const fieldTemplate = `${field}Template` as keyof RegexManagerTemplates;
@ -51,7 +55,7 @@ export function createDependency(
if (tmpl) { if (tmpl) {
try { try {
const compiled = template.compile(tmpl, groups, false); const compiled = template.compile(tmpl, groups, false);
updateDependency(field, compiled); updateDependency(dependency, field, compiled);
} catch (err) { } catch (err) {
logger.warn( logger.warn(
{ template: tmpl }, { template: tmpl },
@ -60,7 +64,7 @@ export function createDependency(
return null; return null;
} }
} else if (groups[field]) { } else if (groups[field]) {
updateDependency(field, groups[field]); updateDependency(dependency, field, groups[field]);
} }
} }
dependency.replaceString = replaceString; dependency.replaceString = replaceString;