diff --git a/lib/config/validation.spec.ts b/lib/config/validation.spec.ts index f850f7f291e1881fb449386deda75b0815490fbf..0bf7c5a9069f81695796bec1f0d547a7917bda43 100644 --- a/lib/config/validation.spec.ts +++ b/lib/config/validation.spec.ts @@ -292,6 +292,29 @@ describe('config/validation', () => { expect(errors).toMatchSnapshot(); }); it('errors if no regexManager matchStrings', async () => { + const config = { + regexManagers: [ + { + fileMatch: [], + }, + ], + }; + const { warnings, errors } = await configValidation.validateConfig( + config as any, + true + ); + expect(warnings).toHaveLength(0); + expect(errors).toHaveLength(1); + expect(errors).toMatchInlineSnapshot(` + Array [ + Object { + "message": "Each Regex Manager must contain a fileMatch array", + "topic": "Configuration Error", + }, + ] + `); + }); + it('errors if empty regexManager matchStrings', async () => { const config = { regexManagers: [ { @@ -306,6 +329,14 @@ describe('config/validation', () => { ); expect(warnings).toHaveLength(0); expect(errors).toHaveLength(1); + expect(errors).toMatchInlineSnapshot(` + Array [ + Object { + "message": "Each Regex Manager must contain a fileMatch array", + "topic": "Configuration Error", + }, + ] + `); }); it('errors if no regexManager fileMatch', async () => { const config = { diff --git a/lib/config/validation.ts b/lib/config/validation.ts index fb99cc6f3d02fbf35f69597476c381b359fa8324..69aaca7ac947717608eef55475ce1bf2be09cefb 100644 --- a/lib/config/validation.ts +++ b/lib/config/validation.ts @@ -408,39 +408,41 @@ export async function validateConfig( )}`, }); } else if (is.nonEmptyArray(regexManager.fileMatch)) { - let validRegex = false; - for (const matchString of regexManager.matchStrings) { - try { - regEx(matchString); - validRegex = true; - } catch (e) { - errors.push({ - topic: 'Configuration Error', - message: `Invalid regExp for ${currentPath}: \`${String( - matchString - )}\``, - }); - } - } - if (validRegex) { - const mandatoryFields = [ - 'depName', - 'currentValue', - 'datasource', - ]; - for (const field of mandatoryFields) { - if ( - !regexManager[`${field}Template`] && - !regexManager.matchStrings.some((matchString) => - matchString.includes(`(?<${field}>`) - ) - ) { + if (is.nonEmptyArray(regexManager.matchStrings)) { + let validRegex = false; + for (const matchString of regexManager.matchStrings) { + try { + regEx(matchString); + validRegex = true; + } catch (e) { errors.push({ topic: 'Configuration Error', - message: `Regex Managers must contain ${field}Template configuration or regex group named ${field}`, + message: `Invalid regExp for ${currentPath}: \`${String( + matchString + )}\``, }); } } + if (validRegex) { + const mandatoryFields = [ + 'depName', + 'currentValue', + 'datasource', + ]; + for (const field of mandatoryFields) { + if ( + !regexManager[`${field}Template`] && + !regexManager.matchStrings.some((matchString) => + matchString.includes(`(?<${field}>`) + ) + ) { + errors.push({ + topic: 'Configuration Error', + message: `Regex Managers must contain ${field}Template configuration or regex group named ${field}`, + }); + } + } + } } } else { errors.push({