You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.4 KiB
42 lines
1.4 KiB
|
2 years ago
|
"use strict";
|
||
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||
|
|
};
|
||
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
|
exports.validateConfig = void 0;
|
||
|
|
const ajv_1 = __importDefault(require("ajv"));
|
||
|
|
const commitlint_schema_json_1 = __importDefault(require("./commitlint.schema.json"));
|
||
|
|
const formatErrors_1 = require("./formatErrors");
|
||
|
|
const TYPE_OF = [
|
||
|
|
'undefined',
|
||
|
|
'string',
|
||
|
|
'number',
|
||
|
|
'object',
|
||
|
|
'function',
|
||
|
|
'boolean',
|
||
|
|
'symbol',
|
||
|
|
];
|
||
|
|
function validateConfig(source, config) {
|
||
|
|
const ajv = new ajv_1.default({
|
||
|
|
meta: false,
|
||
|
|
strict: false,
|
||
|
|
useDefaults: true,
|
||
|
|
validateSchema: false,
|
||
|
|
verbose: true,
|
||
|
|
});
|
||
|
|
ajv.addKeyword({
|
||
|
|
keyword: 'typeof',
|
||
|
|
validate: function typeOfFunc(schema, data) {
|
||
|
|
return typeof data === schema;
|
||
|
|
},
|
||
|
|
metaSchema: { type: 'string', enum: TYPE_OF },
|
||
|
|
schema: true,
|
||
|
|
});
|
||
|
|
const validate = ajv.compile(commitlint_schema_json_1.default);
|
||
|
|
const isValid = validate(config);
|
||
|
|
if (!isValid && validate.errors && validate.errors.length) {
|
||
|
|
throw new Error(`Commitlint configuration in ${source} is invalid:\n${(0, formatErrors_1.formatErrors)(validate.errors)}`);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
exports.validateConfig = validateConfig;
|
||
|
|
//# sourceMappingURL=validate.js.map
|