Skip to content

Commit

Permalink
fix(renovate-config-validator): add validate presets to the validator (
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipAbed authored Aug 5, 2022
1 parent f07dcfb commit 4b0b49e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
20 changes: 19 additions & 1 deletion lib/config/validation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as httpMock from '../../test/http-mock';
import type { RenovateConfig } from './types';
import * as configValidation from './validation';

Expand Down Expand Up @@ -629,7 +630,24 @@ describe('config/validation', () => {

it('validates preset values', async () => {
const config = {
extends: ['foo', 'bar', 42] as never,
extends: ['config:base', ':pinVersions', 42] as never,
};
const { warnings, errors } = await configValidation.validateConfig(
config,
true
);
expect(warnings).toHaveLength(0);
expect(errors).toHaveLength(1);
});

it('validates if presets exist', async () => {
httpMock
.scope('https://registry.npmjs.org')
.get('/renovate-config-doesntExist')
.reply(500);

const config = {
extends: ['config:base', 'doesntExist'] as never,
};
const { warnings, errors } = await configValidation.validateConfig(
config,
Expand Down
15 changes: 14 additions & 1 deletion lib/config/validation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import is from '@sindresorhus/is';
import { logger } from '../logger';
import { getLanguageList, getManagerList } from '../modules/manager';
import { configRegexPredicate, isConfigRegex, regEx } from '../util/regex';
import * as template from '../util/template';
Expand All @@ -8,7 +9,7 @@ import {
} from '../workers/repository/update/branch/schedule';
import { migrateConfig } from './migration';
import { getOptions } from './options';
import { resolveConfigPresets } from './presets';
import { getPreset, resolveConfigPresets } from './presets';
import type {
RenovateConfig,
RenovateOptions,
Expand Down Expand Up @@ -271,6 +272,18 @@ export async function validateConfig(
if (key === 'extends') {
for (const subval of val) {
if (is.string(subval)) {
try {
await getPreset(subval, config);
} catch (err) {
logger.debug(
{ err, preset: subval },
`Could not resolve preset during config validation`
);
errors.push({
topic: 'Configuration Warning',
message: `Invalid Preset ${subval}`,
});
}
if (
parentName === 'packageRules' &&
subval.startsWith('group:')
Expand Down

0 comments on commit 4b0b49e

Please sign in to comment.