Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): validate packageRules matchUpdateTypes combos #9649

Merged
merged 6 commits into from Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 contain both matchUpdateTypes and matchRegistryUrls. 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