diff options
Diffstat (limited to 'tools/node_modules/eslint/node_modules/ajv/dist/ajv.bundle.js')
-rw-r--r-- | tools/node_modules/eslint/node_modules/ajv/dist/ajv.bundle.js | 85 |
1 files changed, 60 insertions, 25 deletions
diff --git a/tools/node_modules/eslint/node_modules/ajv/dist/ajv.bundle.js b/tools/node_modules/eslint/node_modules/ajv/dist/ajv.bundle.js index 6b810ae26a..d76a8c5101 100644 --- a/tools/node_modules/eslint/node_modules/ajv/dist/ajv.bundle.js +++ b/tools/node_modules/eslint/node_modules/ajv/dist/ajv.bundle.js @@ -563,13 +563,21 @@ function compile(schema, root, localRefs, baseId) { } function useCustomRule(rule, schema, parentSchema, it) { - var validateSchema = rule.definition.validateSchema; - if (validateSchema && self._opts.validateSchema !== false) { - var valid = validateSchema(schema); - if (!valid) { - var message = 'keyword schema is invalid: ' + self.errorsText(validateSchema.errors); - if (self._opts.validateSchema == 'log') self.logger.error(message); - else throw new Error(message); + if (self._opts.validateSchema !== false) { + var deps = rule.definition.dependencies; + if (deps && !deps.every(function(keyword) { + return Object.prototype.hasOwnProperty.call(parentSchema, keyword); + })) + throw new Error('parent schema must have all required keywords: ' + deps.join(',')); + + var validateSchema = rule.definition.validateSchema; + if (validateSchema) { + var valid = validateSchema(schema); + if (!valid) { + var message = 'keyword schema is invalid: ' + self.errorsText(validateSchema.errors); + if (self._opts.validateSchema == 'log') self.logger.error(message); + else throw new Error(message); + } } } @@ -4654,6 +4662,7 @@ module.exports = function generate_validate(it, $keyword, $ruleType) { var IDENTIFIER = /^[a-z_$][a-z0-9_$-]*$/i; var customRuleCode = require('./dotjs/custom'); +var metaSchema = require('./refs/json-schema-draft-07.json'); module.exports = { add: addKeyword, @@ -4661,6 +4670,41 @@ module.exports = { remove: removeKeyword }; +var definitionSchema = { + definitions: { + simpleTypes: metaSchema.definitions.simpleTypes + }, + type: 'object', + dependencies: { + schema: ['validate'], + $data: ['validate'], + statements: ['inline'], + valid: {not: {required: ['macro']}} + }, + properties: { + type: metaSchema.properties.type, + schema: {type: 'boolean'}, + statements: {type: 'boolean'}, + dependencies: { + type: 'array', + items: {type: 'string'} + }, + metaSchema: {type: 'object'}, + modifying: {type: 'boolean'}, + valid: {type: 'boolean'}, + $data: {type: 'boolean'}, + async: {type: 'boolean'}, + errors: { + anyOf: [ + {type: 'boolean'}, + {const: 'full'} + ] + } + } +}; + +var validateDefinition; + /** * Define custom keyword * @this Ajv @@ -4680,26 +4724,22 @@ function addKeyword(keyword, definition) { throw new Error('Keyword ' + keyword + ' is not a valid identifier'); if (definition) { - if (definition.macro && definition.valid !== undefined) - throw new Error('"valid" option cannot be used with macro keywords'); + validateDefinition = validateDefinition || this.compile(definitionSchema); + + if (!validateDefinition(definition)) + throw new Error('custom keyword definition is invalid: ' + this.errorsText(validateDefinition.errors)); var dataType = definition.type; if (Array.isArray(dataType)) { - var i, len = dataType.length; - for (i=0; i<len; i++) checkDataType(dataType[i]); - for (i=0; i<len; i++) _addRule(keyword, dataType[i], definition); + for (var i=0; i<dataType.length; i++) + _addRule(keyword, dataType[i], definition); } else { - if (dataType) checkDataType(dataType); _addRule(keyword, dataType, definition); } - var $data = definition.$data === true && this._opts.$data; - if ($data && !definition.validate) - throw new Error('$data support: "validate" function is not defined'); - var metaSchema = definition.metaSchema; if (metaSchema) { - if ($data) { + if (definition.$data && this._opts.$data) { metaSchema = { anyOf: [ metaSchema, @@ -4740,11 +4780,6 @@ function addKeyword(keyword, definition) { RULES.custom[keyword] = rule; } - - function checkDataType(dataType) { - if (!RULES.types[dataType]) throw new Error('Unknown type ' + dataType); - } - return this; } @@ -4786,7 +4821,7 @@ function removeKeyword(keyword) { return this; } -},{"./dotjs/custom":21}],39:[function(require,module,exports){ +},{"./dotjs/custom":21,"./refs/json-schema-draft-07.json":40}],39:[function(require,module,exports){ module.exports={ "$schema": "http://json-schema.org/draft-07/schema#", "$id": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/data.json#", @@ -6648,7 +6683,7 @@ function Ajv(opts) { if (opts.formats) addInitialFormats(this); addDefaultMetaSchema(this); if (typeof opts.meta == 'object') this.addMetaSchema(opts.meta); - if (opts.nullable) this.addKeyword('nullable', {metaSchema: {const: true}}); + if (opts.nullable) this.addKeyword('nullable', {metaSchema: {type: 'boolean'}}); addInitialSchemas(this); } |