summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/ajv/lib/dotjs/validate.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/node_modules/ajv/lib/dotjs/validate.js')
-rw-r--r--tools/node_modules/eslint/node_modules/ajv/lib/dotjs/validate.js67
1 files changed, 48 insertions, 19 deletions
diff --git a/tools/node_modules/eslint/node_modules/ajv/lib/dotjs/validate.js b/tools/node_modules/eslint/node_modules/ajv/lib/dotjs/validate.js
index 1402b6a15a..cd0efc8101 100644
--- a/tools/node_modules/eslint/node_modules/ajv/lib/dotjs/validate.js
+++ b/tools/node_modules/eslint/node_modules/ajv/lib/dotjs/validate.js
@@ -4,6 +4,14 @@ module.exports = function generate_validate(it, $keyword, $ruleType) {
var $async = it.schema.$async === true,
$refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref'),
$id = it.self._getId(it.schema);
+ if (it.opts.strictKeywords) {
+ var $unknownKwd = it.util.schemaUnknownRules(it.schema, it.RULES.keywords);
+ if ($unknownKwd) {
+ var $keywordsMsg = 'unknown keyword: ' + $unknownKwd;
+ if (it.opts.strictKeywords === 'log') it.logger.warn($keywordsMsg);
+ else throw new Error($keywordsMsg);
+ }
+ }
if (it.isTop) {
out += ' var validate = ';
if ($async) {
@@ -84,6 +92,11 @@ module.exports = function generate_validate(it, $keyword, $ruleType) {
it.baseId = it.baseId || it.rootId;
delete it.isTop;
it.dataPathArr = [undefined];
+ if (it.schema.default !== undefined && it.opts.useDefaults && it.opts.strictDefaults) {
+ var $defaultMsg = 'default is ignored in the schema root';
+ if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
+ else throw new Error($defaultMsg);
+ }
out += ' var vErrors = null; ';
out += ' var errors = 0; ';
out += ' if (rootData === undefined) rootData = data; ';
@@ -291,7 +304,7 @@ module.exports = function generate_validate(it, $keyword, $ruleType) {
if ($rulesGroup.type) {
out += ' if (' + (it.util.checkDataType($rulesGroup.type, $data)) + ') { ';
}
- if (it.opts.useDefaults && !it.compositeRule) {
+ if (it.opts.useDefaults) {
if ($rulesGroup.type == 'object' && it.schema.properties) {
var $schema = it.schema.properties,
$schemaKeys = Object.keys($schema);
@@ -304,17 +317,25 @@ module.exports = function generate_validate(it, $keyword, $ruleType) {
var $sch = $schema[$propertyKey];
if ($sch.default !== undefined) {
var $passData = $data + it.util.getProperty($propertyKey);
- out += ' if (' + ($passData) + ' === undefined ';
- if (it.opts.useDefaults == 'empty') {
- out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' ';
- }
- out += ' ) ' + ($passData) + ' = ';
- if (it.opts.useDefaults == 'shared') {
- out += ' ' + (it.useDefault($sch.default)) + ' ';
+ if (it.compositeRule) {
+ if (it.opts.strictDefaults) {
+ var $defaultMsg = 'default is ignored for: ' + $passData;
+ if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
+ else throw new Error($defaultMsg);
+ }
} else {
- out += ' ' + (JSON.stringify($sch.default)) + ' ';
+ out += ' if (' + ($passData) + ' === undefined ';
+ if (it.opts.useDefaults == 'empty') {
+ out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' ';
+ }
+ out += ' ) ' + ($passData) + ' = ';
+ if (it.opts.useDefaults == 'shared') {
+ out += ' ' + (it.useDefault($sch.default)) + ' ';
+ } else {
+ out += ' ' + (JSON.stringify($sch.default)) + ' ';
+ }
+ out += '; ';
}
- out += '; ';
}
}
}
@@ -327,17 +348,25 @@ module.exports = function generate_validate(it, $keyword, $ruleType) {
$sch = arr4[$i += 1];
if ($sch.default !== undefined) {
var $passData = $data + '[' + $i + ']';
- out += ' if (' + ($passData) + ' === undefined ';
- if (it.opts.useDefaults == 'empty') {
- out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' ';
- }
- out += ' ) ' + ($passData) + ' = ';
- if (it.opts.useDefaults == 'shared') {
- out += ' ' + (it.useDefault($sch.default)) + ' ';
+ if (it.compositeRule) {
+ if (it.opts.strictDefaults) {
+ var $defaultMsg = 'default is ignored for: ' + $passData;
+ if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
+ else throw new Error($defaultMsg);
+ }
} else {
- out += ' ' + (JSON.stringify($sch.default)) + ' ';
+ out += ' if (' + ($passData) + ' === undefined ';
+ if (it.opts.useDefaults == 'empty') {
+ out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' ';
+ }
+ out += ' ) ' + ($passData) + ' = ';
+ if (it.opts.useDefaults == 'shared') {
+ out += ' ' + (it.useDefault($sch.default)) + ' ';
+ } else {
+ out += ' ' + (JSON.stringify($sch.default)) + ' ';
+ }
+ out += '; ';
}
- out += '; ';
}
}
}