2019-07-17 08:14:56 +00:00
|
|
|
import is from '@sindresorhus/is';
|
2020-10-18 05:56:16 +00:00
|
|
|
import { getManagerList } from '../manager';
|
2020-11-10 09:12:03 +00:00
|
|
|
import { configRegexPredicate, isConfigRegex, regEx } from '../util/regex';
|
2020-04-05 08:09:55 +00:00
|
|
|
import * as template from '../util/template';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { hasValidSchedule, hasValidTimezone } from '../workers/branch/schedule';
|
2021-03-02 20:44:55 +00:00
|
|
|
import { getOptions } from './definitions';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { resolveConfigPresets } from './presets';
|
2021-03-02 20:44:55 +00:00
|
|
|
import type {
|
|
|
|
RenovateConfig,
|
|
|
|
RenovateOptions,
|
|
|
|
ValidationMessage,
|
|
|
|
} from './types';
|
2020-05-01 16:03:48 +00:00
|
|
|
import * as managerValidator from './validation-helpers/managers';
|
2019-07-17 08:14:56 +00:00
|
|
|
|
2019-08-23 13:46:31 +00:00
|
|
|
const options = getOptions();
|
2017-07-28 19:15:27 +00:00
|
|
|
|
2019-08-23 13:46:31 +00:00
|
|
|
let optionTypes: Record<string, RenovateOptions['type']>;
|
2017-07-28 19:15:27 +00:00
|
|
|
|
2019-08-23 13:46:31 +00:00
|
|
|
export interface ValidationResult {
|
|
|
|
errors: ValidationMessage[];
|
|
|
|
warnings: ValidationMessage[];
|
|
|
|
}
|
|
|
|
|
2020-10-18 05:56:16 +00:00
|
|
|
const managerList = getManagerList();
|
|
|
|
|
|
|
|
function isManagerPath(parentPath: string): boolean {
|
|
|
|
return (
|
|
|
|
/^regexManagers\[[0-9]+]$/.test(parentPath) ||
|
|
|
|
managerList.includes(parentPath)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-23 13:46:31 +00:00
|
|
|
export async function validateConfig(
|
|
|
|
config: RenovateConfig,
|
|
|
|
isPreset?: boolean,
|
|
|
|
parentPath?: string
|
|
|
|
): Promise<ValidationResult> {
|
2017-11-03 06:43:26 +00:00
|
|
|
if (!optionTypes) {
|
|
|
|
optionTypes = {};
|
2020-04-12 16:09:36 +00:00
|
|
|
options.forEach((option) => {
|
2017-11-03 06:43:26 +00:00
|
|
|
optionTypes[option.name] = option.type;
|
|
|
|
});
|
|
|
|
}
|
2019-08-23 13:46:31 +00:00
|
|
|
let errors: ValidationMessage[] = [];
|
|
|
|
let warnings: ValidationMessage[] = [];
|
2017-07-28 19:15:27 +00:00
|
|
|
|
2019-08-23 13:46:31 +00:00
|
|
|
function getDeprecationMessage(option: string): string {
|
2018-04-17 06:39:26 +00:00
|
|
|
const deprecatedOptions = {
|
2020-09-01 12:28:18 +00:00
|
|
|
branchName: `Direct editing of branchName is now deprecated. Please edit branchPrefix, additionalBranchPrefix, or branchTopic instead`,
|
2018-04-17 06:39:26 +00:00
|
|
|
commitMessage: `Direct editing of commitMessage is now deprecated. Please edit commitMessage's subcomponents instead.`,
|
|
|
|
prTitle: `Direct editing of prTitle is now deprecated. Please edit commitMessage subcomponents instead as they will be passed through to prTitle.`,
|
2021-03-20 19:35:15 +00:00
|
|
|
yarnrc:
|
|
|
|
'Use of `yarnrc` in config is deprecated. Please commit it to your repository instead.',
|
2018-04-17 06:39:26 +00:00
|
|
|
};
|
|
|
|
return deprecatedOptions[option];
|
|
|
|
}
|
|
|
|
|
2019-08-23 13:46:31 +00:00
|
|
|
function isIgnored(key: string): boolean {
|
2018-01-16 07:02:08 +00:00
|
|
|
const ignoredNodes = [
|
2018-07-18 07:31:55 +00:00
|
|
|
'$schema',
|
2018-01-16 07:02:08 +00:00
|
|
|
'depType',
|
|
|
|
'npmToken',
|
|
|
|
'packageFile',
|
|
|
|
'forkToken',
|
|
|
|
'repository',
|
2018-07-29 06:43:53 +00:00
|
|
|
'vulnerabilityAlertsOnly',
|
2019-10-06 08:53:51 +00:00
|
|
|
'vulnerabilityAlert',
|
2021-02-24 14:13:41 +00:00
|
|
|
'isVulnerabilityAlert',
|
2019-04-23 14:07:27 +00:00
|
|
|
'copyLocalLibs', // deprecated - functionality is now enabled by default
|
2018-09-21 03:43:51 +00:00
|
|
|
'prBody', // deprecated
|
2018-01-16 07:02:08 +00:00
|
|
|
];
|
2018-06-04 18:44:32 +00:00
|
|
|
return ignoredNodes.includes(key);
|
2017-07-28 19:15:27 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 12:59:50 +00:00
|
|
|
function validateAliasObject(
|
|
|
|
key: string,
|
|
|
|
val: Record<string, unknown>
|
|
|
|
): boolean {
|
2020-06-04 13:47:56 +00:00
|
|
|
if (key === 'aliases') {
|
|
|
|
for (const value of Object.values(val)) {
|
|
|
|
if (!is.urlString(value)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-10 12:46:16 +00:00
|
|
|
for (const [key, val] of Object.entries(config)) {
|
2018-04-11 19:38:31 +00:00
|
|
|
const currentPath = parentPath ? `${parentPath}.${key}` : key;
|
2020-10-16 08:23:50 +00:00
|
|
|
// istanbul ignore if
|
|
|
|
if (key === '__proto__') {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Config security error',
|
2020-10-16 08:23:50 +00:00
|
|
|
message: '__proto__',
|
|
|
|
});
|
|
|
|
continue; // eslint-disable-line
|
|
|
|
}
|
2020-10-18 05:56:16 +00:00
|
|
|
if (key === 'fileMatch') {
|
|
|
|
if (parentPath === undefined) {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Config error',
|
2020-10-18 05:56:16 +00:00
|
|
|
message: `"fileMatch" may not be defined at the top level of a config and must instead be within a manager block`,
|
|
|
|
});
|
|
|
|
} else if (!isManagerPath(parentPath)) {
|
|
|
|
warnings.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Config warning',
|
2020-10-18 05:56:16 +00:00
|
|
|
message: `"fileMatch" must be configured in a manager block and not here: ${parentPath}`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-08-02 06:54:42 +00:00
|
|
|
if (
|
2017-07-28 19:15:27 +00:00
|
|
|
!isIgnored(key) && // We need to ignore some reserved keys
|
2019-08-28 04:46:48 +00:00
|
|
|
!(is as any).function(val) // Ignore all functions
|
2017-07-28 19:15:27 +00:00
|
|
|
) {
|
2018-04-17 06:39:26 +00:00
|
|
|
if (getDeprecationMessage(key)) {
|
|
|
|
warnings.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Deprecation Warning',
|
2018-04-17 06:39:26 +00:00
|
|
|
message: getDeprecationMessage(key),
|
|
|
|
});
|
|
|
|
}
|
2020-01-27 11:48:08 +00:00
|
|
|
const templateKeys = [
|
|
|
|
'branchName',
|
|
|
|
'commitBody',
|
|
|
|
'commitMessage',
|
|
|
|
'prTitle',
|
|
|
|
'semanticCommitScope',
|
|
|
|
];
|
2020-03-06 08:07:55 +00:00
|
|
|
if ((key.endsWith('Template') || templateKeys.includes(key)) && val) {
|
2020-01-27 11:48:08 +00:00
|
|
|
try {
|
2021-02-03 15:33:28 +00:00
|
|
|
let res = template.compile(val.toString(), config, false);
|
|
|
|
res = template.compile(res, config, false);
|
|
|
|
template.compile(res, config, false);
|
2020-01-27 11:48:08 +00:00
|
|
|
} catch (err) {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2020-04-05 08:09:55 +00:00
|
|
|
message: `Invalid template in config path: ${currentPath}`,
|
2020-01-27 11:48:08 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 19:15:27 +00:00
|
|
|
if (!optionTypes[key]) {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2019-03-17 06:21:25 +00:00
|
|
|
message: `Invalid configuration option: ${currentPath}`,
|
2017-07-28 19:15:27 +00:00
|
|
|
});
|
2017-08-14 09:09:14 +00:00
|
|
|
} else if (key === 'schedule') {
|
2020-03-02 11:06:16 +00:00
|
|
|
const [validSchedule, errorMessage] = hasValidSchedule(val as string[]);
|
2017-08-14 09:09:14 +00:00
|
|
|
if (!validSchedule) {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2018-04-11 19:38:31 +00:00
|
|
|
message: `Invalid ${currentPath}: \`${errorMessage}\``,
|
2017-08-14 09:09:14 +00:00
|
|
|
});
|
|
|
|
}
|
2020-11-12 07:21:05 +00:00
|
|
|
} else if (
|
|
|
|
['allowedVersions', 'matchCurrentVersion'].includes(key) &&
|
|
|
|
isConfigRegex(val)
|
|
|
|
) {
|
2020-11-10 09:12:03 +00:00
|
|
|
if (!configRegexPredicate(val)) {
|
2020-04-15 20:07:53 +00:00
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2020-04-15 20:07:53 +00:00
|
|
|
message: `Invalid regExp for ${currentPath}: \`${val}\``,
|
|
|
|
});
|
|
|
|
}
|
2018-03-12 03:24:45 +00:00
|
|
|
} else if (key === 'timezone' && val !== null) {
|
2020-03-02 11:06:16 +00:00
|
|
|
const [validTimezone, errorMessage] = hasValidTimezone(val as string);
|
2018-03-12 03:24:45 +00:00
|
|
|
if (!validTimezone) {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2018-04-11 19:38:31 +00:00
|
|
|
message: `${currentPath}: ${errorMessage}`,
|
2018-03-12 03:24:45 +00:00
|
|
|
});
|
|
|
|
}
|
2017-07-29 20:12:19 +00:00
|
|
|
} else if (val != null) {
|
2017-08-14 05:49:33 +00:00
|
|
|
const type = optionTypes[key];
|
2017-07-28 19:15:27 +00:00
|
|
|
if (type === 'boolean') {
|
|
|
|
if (val !== true && val !== false) {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2018-04-11 19:38:31 +00:00
|
|
|
message: `Configuration option \`${currentPath}\` should be boolean. Found: ${JSON.stringify(
|
2017-08-22 06:12:42 +00:00
|
|
|
val
|
|
|
|
)} (${typeof val})`,
|
2017-07-28 19:15:27 +00:00
|
|
|
});
|
|
|
|
}
|
2019-03-31 06:01:06 +00:00
|
|
|
} else if (type === 'array' && val) {
|
2021-03-04 05:21:55 +00:00
|
|
|
if (is.array(val)) {
|
2018-04-11 19:38:31 +00:00
|
|
|
for (const [subIndex, subval] of val.entries()) {
|
2018-06-04 18:07:22 +00:00
|
|
|
if (is.object(subval)) {
|
2018-03-28 08:04:07 +00:00
|
|
|
const subValidation = await module.exports.validateConfig(
|
2018-04-11 19:38:31 +00:00
|
|
|
subval,
|
2018-04-12 10:13:39 +00:00
|
|
|
isPreset,
|
2018-04-11 19:38:31 +00:00
|
|
|
`${currentPath}[${subIndex}]`
|
2018-03-28 08:04:07 +00:00
|
|
|
);
|
2018-03-06 14:54:27 +00:00
|
|
|
warnings = warnings.concat(subValidation.warnings);
|
|
|
|
errors = errors.concat(subValidation.errors);
|
2017-08-02 05:52:28 +00:00
|
|
|
}
|
2018-03-28 07:37:19 +00:00
|
|
|
}
|
|
|
|
if (key === 'extends') {
|
2020-02-05 18:17:20 +00:00
|
|
|
const tzRe = /^:timezone\((.+)\)$/;
|
2018-03-28 07:37:19 +00:00
|
|
|
for (const subval of val) {
|
2020-10-27 15:39:11 +00:00
|
|
|
if (is.string(subval)) {
|
|
|
|
if (tzRe.test(subval)) {
|
|
|
|
const [, timezone] = tzRe.exec(subval);
|
|
|
|
const [validTimezone, errorMessage] = hasValidTimezone(
|
|
|
|
timezone
|
|
|
|
);
|
|
|
|
if (!validTimezone) {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2020-10-27 15:39:11 +00:00
|
|
|
message: `${currentPath}: ${errorMessage}`,
|
|
|
|
});
|
|
|
|
}
|
2018-03-28 07:37:19 +00:00
|
|
|
}
|
2020-10-27 15:39:11 +00:00
|
|
|
} else {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Warning',
|
2020-10-27 15:39:11 +00:00
|
|
|
message: `${currentPath}: preset value is not a string`,
|
|
|
|
});
|
2018-03-28 07:37:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-12 10:13:39 +00:00
|
|
|
|
|
|
|
const selectors = [
|
2021-03-11 14:40:31 +00:00
|
|
|
'matchFiles',
|
2021-01-29 10:43:42 +00:00
|
|
|
'matchPaths',
|
|
|
|
'matchLanguages',
|
|
|
|
'matchBaseBranches',
|
|
|
|
'matchManagers',
|
|
|
|
'matchDatasources',
|
|
|
|
'matchDepTypes',
|
|
|
|
'matchPackageNames',
|
|
|
|
'matchPackagePatterns',
|
2021-04-03 05:18:25 +00:00
|
|
|
'matchPackagePrefixes',
|
2018-04-12 10:13:39 +00:00
|
|
|
'excludePackageNames',
|
|
|
|
'excludePackagePatterns',
|
2021-04-03 05:18:25 +00:00
|
|
|
'excludePackagePrefixes',
|
2020-07-22 06:32:01 +00:00
|
|
|
'matchCurrentVersion',
|
2021-01-29 10:43:42 +00:00
|
|
|
'matchSourceUrlPrefixes',
|
|
|
|
'matchUpdateTypes',
|
2018-04-12 10:13:39 +00:00
|
|
|
];
|
2018-03-28 08:04:07 +00:00
|
|
|
if (key === 'packageRules') {
|
|
|
|
for (const packageRule of val) {
|
|
|
|
let hasSelector = false;
|
2018-06-04 18:07:22 +00:00
|
|
|
if (is.object(packageRule)) {
|
2020-03-02 11:06:16 +00:00
|
|
|
const resolvedRule = await resolveConfigPresets(
|
2020-04-14 05:05:30 +00:00
|
|
|
packageRule as RenovateConfig,
|
|
|
|
config
|
2020-03-02 11:06:16 +00:00
|
|
|
);
|
2019-02-20 21:29:38 +00:00
|
|
|
errors.push(
|
|
|
|
...managerValidator.check({ resolvedRule, currentPath })
|
|
|
|
);
|
2018-03-28 08:04:07 +00:00
|
|
|
for (const pKey of Object.keys(resolvedRule)) {
|
|
|
|
if (selectors.includes(pKey)) {
|
|
|
|
hasSelector = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!hasSelector) {
|
2018-04-11 19:38:31 +00:00
|
|
|
const message = `${currentPath}: Each packageRule must contain at least one selector (${selectors.join(
|
2018-03-28 13:13:32 +00:00
|
|
|
', '
|
|
|
|
)}). If you wish for configuration to apply to all packages, it is not necessary to place it inside a packageRule at all.`;
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2018-03-28 08:04:07 +00:00
|
|
|
message,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2018-04-11 19:38:31 +00:00
|
|
|
message: `${currentPath} must contain JSON objects`,
|
2018-03-28 08:04:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-06 08:07:55 +00:00
|
|
|
if (key === 'regexManagers') {
|
|
|
|
const allowedKeys = [
|
2021-02-01 06:03:38 +00:00
|
|
|
'description',
|
2020-03-06 08:07:55 +00:00
|
|
|
'fileMatch',
|
|
|
|
'matchStrings',
|
2020-11-27 05:55:57 +00:00
|
|
|
'matchStringsStrategy',
|
2020-03-06 08:07:55 +00:00
|
|
|
'depNameTemplate',
|
|
|
|
'lookupNameTemplate',
|
|
|
|
'datasourceTemplate',
|
|
|
|
'versioningTemplate',
|
2021-03-22 06:18:34 +00:00
|
|
|
'registryUrlTemplate',
|
2020-03-06 08:07:55 +00:00
|
|
|
];
|
2020-07-30 04:54:20 +00:00
|
|
|
// TODO: fix types
|
|
|
|
for (const regexManager of val as any[]) {
|
2020-03-06 08:07:55 +00:00
|
|
|
if (
|
2020-04-12 16:09:36 +00:00
|
|
|
Object.keys(regexManager).some(
|
|
|
|
(k) => !allowedKeys.includes(k)
|
|
|
|
)
|
2020-03-06 08:07:55 +00:00
|
|
|
) {
|
|
|
|
const disallowedKeys = Object.keys(regexManager).filter(
|
2020-04-12 16:09:36 +00:00
|
|
|
(k) => !allowedKeys.includes(k)
|
2020-03-06 08:07:55 +00:00
|
|
|
);
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2020-03-06 08:07:55 +00:00
|
|
|
message: `Regex Manager contains disallowed fields: ${disallowedKeys.join(
|
|
|
|
', '
|
|
|
|
)}`,
|
|
|
|
});
|
2021-03-04 05:21:55 +00:00
|
|
|
} else if (is.nonEmptyArray(regexManager.fileMatch)) {
|
2020-03-06 08:07:55 +00:00
|
|
|
let validRegex = false;
|
|
|
|
for (const matchString of regexManager.matchStrings) {
|
|
|
|
try {
|
|
|
|
regEx(matchString);
|
|
|
|
validRegex = true;
|
|
|
|
} catch (e) {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2020-08-26 12:59:50 +00:00
|
|
|
message: `Invalid regExp for ${currentPath}: \`${String(
|
|
|
|
matchString
|
|
|
|
)}\``,
|
2020-03-06 08:07:55 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (validRegex) {
|
|
|
|
const mandatoryFields = [
|
|
|
|
'depName',
|
|
|
|
'currentValue',
|
|
|
|
'datasource',
|
|
|
|
];
|
|
|
|
for (const field of mandatoryFields) {
|
|
|
|
if (
|
|
|
|
!regexManager[`${field}Template`] &&
|
2020-04-12 16:09:36 +00:00
|
|
|
!regexManager.matchStrings.some((matchString) =>
|
2020-03-06 08:07:55 +00:00
|
|
|
matchString.includes(`(?<${field}>`)
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2020-03-06 08:07:55 +00:00
|
|
|
message: `Regex Managers must contain ${field}Template configuration or regex group named ${field}`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-04 05:21:55 +00:00
|
|
|
} else {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2021-03-04 05:21:55 +00:00
|
|
|
message: `Each Regex Manager must contain a fileMatch array`,
|
|
|
|
});
|
2020-03-06 08:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-29 10:43:42 +00:00
|
|
|
if (
|
|
|
|
key === 'matchPackagePatterns' ||
|
|
|
|
key === 'excludePackagePatterns'
|
|
|
|
) {
|
2020-07-30 04:54:20 +00:00
|
|
|
for (const pattern of val as string[]) {
|
2019-10-22 06:48:40 +00:00
|
|
|
if (pattern !== '*') {
|
|
|
|
try {
|
|
|
|
regEx(pattern);
|
|
|
|
} catch (e) {
|
2019-10-15 08:14:49 +00:00
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2019-10-22 06:48:40 +00:00
|
|
|
message: `Invalid regExp for ${currentPath}: \`${pattern}\``,
|
2019-10-15 08:14:49 +00:00
|
|
|
});
|
|
|
|
}
|
2018-04-30 11:18:51 +00:00
|
|
|
}
|
2019-10-22 06:48:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (key === 'fileMatch') {
|
2020-07-30 04:54:20 +00:00
|
|
|
for (const fileMatch of val as string[]) {
|
2019-10-22 06:48:40 +00:00
|
|
|
try {
|
|
|
|
regEx(fileMatch);
|
|
|
|
} catch (e) {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2019-10-22 06:48:40 +00:00
|
|
|
message: `Invalid regExp for ${currentPath}: \`${fileMatch}\``,
|
|
|
|
});
|
|
|
|
}
|
2018-04-30 11:18:51 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-12 10:13:39 +00:00
|
|
|
if (
|
2018-04-27 03:45:22 +00:00
|
|
|
(selectors.includes(key) || key === 'matchCurrentVersion') &&
|
2020-02-05 18:17:20 +00:00
|
|
|
!/p.*Rules\[\d+\]$/.test(parentPath) && // Inside a packageRule
|
2018-04-12 10:13:39 +00:00
|
|
|
(parentPath || !isPreset) // top level in a preset
|
|
|
|
) {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2018-04-12 10:13:39 +00:00
|
|
|
message: `${currentPath}: ${key} should be inside a \`packageRule\` only`,
|
|
|
|
});
|
|
|
|
}
|
2021-03-04 05:21:55 +00:00
|
|
|
} else {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2021-03-04 05:21:55 +00:00
|
|
|
message: `Configuration option \`${currentPath}\` should be a list (Array)`,
|
|
|
|
});
|
2017-07-28 19:15:27 +00:00
|
|
|
}
|
|
|
|
} else if (type === 'string') {
|
2018-06-04 18:07:22 +00:00
|
|
|
if (!is.string(val)) {
|
2017-07-28 19:15:27 +00:00
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2018-04-11 19:38:31 +00:00
|
|
|
message: `Configuration option \`${currentPath}\` should be a string`,
|
2017-07-28 19:15:27 +00:00
|
|
|
});
|
|
|
|
}
|
2020-09-30 09:02:25 +00:00
|
|
|
} else if (
|
|
|
|
type === 'object' &&
|
|
|
|
currentPath !== 'compatibility' &&
|
2020-10-27 07:13:23 +00:00
|
|
|
currentPath !== 'constraints' &&
|
|
|
|
currentPath !== 'force.constraints'
|
2020-09-30 09:02:25 +00:00
|
|
|
) {
|
2020-08-26 12:59:50 +00:00
|
|
|
if (is.plainObject(val)) {
|
2020-06-04 13:47:56 +00:00
|
|
|
if (key === 'aliases') {
|
|
|
|
if (!validateAliasObject(key, val)) {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2020-06-04 13:47:56 +00:00
|
|
|
message: `Invalid alias object configuration`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const ignoredObjects = options
|
|
|
|
.filter((option) => option.freeChoice)
|
|
|
|
.map((option) => option.name);
|
|
|
|
if (!ignoredObjects.includes(key)) {
|
|
|
|
const subValidation = await module.exports.validateConfig(
|
|
|
|
val,
|
|
|
|
isPreset,
|
|
|
|
currentPath
|
|
|
|
);
|
|
|
|
warnings = warnings.concat(subValidation.warnings);
|
|
|
|
errors = errors.concat(subValidation.errors);
|
|
|
|
}
|
2019-03-31 07:16:29 +00:00
|
|
|
}
|
2017-07-28 19:15:27 +00:00
|
|
|
} else {
|
|
|
|
errors.push({
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2018-04-11 19:38:31 +00:00
|
|
|
message: `Configuration option \`${currentPath}\` should be a json object`,
|
2017-07-28 19:15:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-23 13:46:31 +00:00
|
|
|
function sortAll(a: ValidationMessage, b: ValidationMessage): number {
|
2020-03-07 10:27:10 +00:00
|
|
|
// istanbul ignore else: currently never happen
|
2021-04-01 13:50:17 +00:00
|
|
|
if (a.topic === b.topic) {
|
2019-04-16 14:03:37 +00:00
|
|
|
return a.message > b.message ? 1 : -1;
|
2018-04-28 06:48:12 +00:00
|
|
|
}
|
2020-03-07 10:27:10 +00:00
|
|
|
// istanbul ignore next: currently never happen
|
2021-04-01 13:50:17 +00:00
|
|
|
return a.topic > b.topic ? 1 : -1;
|
2018-04-28 06:48:12 +00:00
|
|
|
}
|
|
|
|
errors.sort(sortAll);
|
|
|
|
warnings.sort(sortAll);
|
2017-07-31 12:50:44 +00:00
|
|
|
return { errors, warnings };
|
2017-07-28 19:15:27 +00:00
|
|
|
}
|