Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 1x 1x 3x 3x 3x 2x 2x 2x 2x 2x 3x 3x 3x 6x 6x 2x 3x | import {getError} from "./get-error.js";
import {isNonEmptyString, isObject, isNil} from "./utils.js";
const VALIDATORS = {
commitlintFile: isNonEmptyString,
commitlintConfig: isObject,
};
export const verifyConfig = (pluginConfig) => {
const filtredPluginConfig = filterConfig(pluginConfig);
const errors = Object.entries(filtredPluginConfig).reduce(
reduceFunction,
[],
);
if (errors.length > 0) {
throw new AggregateError(errors, "Verifying config is fail");
}
};
function reduceFunction(errors, [option, value]) {
const isError = !isNil(value) && !VALIDATORS[option](value);
Iif (!isError) {
return errors;
}
const error = getError(`EINVALID${option.toUpperCase()}`, {
[option]: value,
});
return [...errors, error];
}
function filterConfig(pluginConfig) {
const validKeys = Object.keys(VALIDATORS);
const result = {};
for (const key of validKeys) {
const value = pluginConfig[key];
if (value) {
result[key] = value;
}
}
return result;
}
|