Skip to content
Snippets Groups Projects
Unverified Commit 61abc03a authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

feat(config): validate packageRules matchUpdateTypes combos (#9649)

parent 6232b654
No related branches found
No related tags found
No related merge requests found
...@@ -164,6 +164,15 @@ Array [ ...@@ -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`] = ` exports[`config/validation validateConfig(config) errors if language or manager objects are nested 1`] = `
Array [ Array [
Object { Object {
......
...@@ -585,5 +585,22 @@ describe(getName(__filename), () => { ...@@ -585,5 +585,22 @@ describe(getName(__filename), () => {
expect(warnings).toMatchSnapshot(); expect(warnings).toMatchSnapshot();
expect(errors).toHaveLength(0); 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();
});
}); });
}); });
...@@ -325,6 +325,34 @@ export async function validateConfig( ...@@ -325,6 +325,34 @@ export async function validateConfig(
message, 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 { } else {
errors.push({ errors.push({
topic: 'Configuration Error', topic: 'Configuration Error',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment