Skip to content

Commit

Permalink
feat(config): validate packageRules matchUpdateTypes combos (#9649)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Apr 22, 2021
1 parent 6232b65 commit 61abc03
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/config/__snapshots__/validation.spec.ts.snap
Expand Up @@ -164,6 +164,15 @@ Array [
]
`;

exports[`config/validation validateConfig(config) errors if invalid combinations in packageRules 1`] = `
Array [
Object {
"message": "packageRules[0]: packageRules cannot combine both matchUpdateTypes and registryUrls. Rule: {\\"matchUpdateTypes\\":[\\"major\\"],\\"registryUrls\\":[\\"https://registry.npmjs.org\\"]}",
"topic": "Configuration Error",
},
]
`;

exports[`config/validation validateConfig(config) errors if language or manager objects are nested 1`] = `
Array [
Object {
Expand Down
17 changes: 17 additions & 0 deletions lib/config/validation.spec.ts
Expand Up @@ -585,5 +585,22 @@ describe(getName(__filename), () => {
expect(warnings).toMatchSnapshot();
expect(errors).toHaveLength(0);
});
it('errors if invalid combinations in packageRules', async () => {
const config = {
packageRules: [
{
matchUpdateTypes: ['major'],
registryUrls: ['https://registry.npmjs.org'],
},
],
} as any;
const { warnings, errors } = await configValidation.validateConfig(
config,
true
);
expect(warnings).toHaveLength(0);
expect(errors).toHaveLength(1);
expect(errors).toMatchSnapshot();
});
});
});
28 changes: 28 additions & 0 deletions lib/config/validation.ts
Expand Up @@ -325,6 +325,34 @@ export async function validateConfig(
message,
});
}
// It's too late to apply any of these options once you already have updates determined
const preLookupOptions = [
'extractVersion',
'followTag',
'ignoreDeps',
'ignoreUnstable',
'rangeStrategy',
'registryUrls',
'respectLatest',
'rollbackPrs',
'separateMajorMinor',
'separateMinorPatch',
'separateMultipleMajor',
'versioning',
];
if (is.nonEmptyArray(resolvedRule.matchUpdateTypes)) {
for (const option of preLookupOptions) {
if (resolvedRule[option] !== undefined) {
const message = `${currentPath}[${subIndex}]: packageRules cannot combine both matchUpdateTypes and ${option}. Rule: ${JSON.stringify(
packageRule
)}`;
errors.push({
topic: 'Configuration Error',
message,
});
}
}
}
} else {
errors.push({
topic: 'Configuration Error',
Expand Down

0 comments on commit 61abc03

Please sign in to comment.