@alexlit/lint-kit 117.2.1 → 117.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packages/config-eslint/index.js +7 -374
- package/packages/config-eslint/legacy.js +3 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/LICENSE +19 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/README.md +126 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/conf/config-schema.js +79 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/conf/environments.js +215 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs +1143 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs.map +1 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/dist/eslintrc.cjs +4371 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/dist/eslintrc.cjs.map +1 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js +532 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/config-array.js +510 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/config-dependency.js +124 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/extracted-config.js +145 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/ignore-pattern.js +238 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/index.js +19 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/override-tester.js +225 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array-factory.js +1155 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/flat-compat.js +318 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/index-universal.js +29 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/index.js +58 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/ajv.js +191 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/config-ops.js +135 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/config-validator.js +370 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/deprecation-warnings.js +63 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/naming.js +96 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js +42 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/types.js +149 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/package.json +82 -0
- package/packages/config-eslint/node_modules/@eslint/eslintrc/universal.js +9 -0
- package/packages/config-eslint/node_modules/ajv/.tonic_example.js +20 -0
- package/packages/config-eslint/node_modules/ajv/LICENSE +22 -0
- package/packages/config-eslint/node_modules/ajv/README.md +1497 -0
- package/packages/config-eslint/node_modules/ajv/dist/ajv.bundle.js +7189 -0
- package/packages/config-eslint/node_modules/ajv/dist/ajv.min.js +3 -0
- package/packages/config-eslint/node_modules/ajv/dist/ajv.min.js.map +1 -0
- package/packages/config-eslint/node_modules/ajv/lib/ajv.d.ts +397 -0
- package/packages/config-eslint/node_modules/ajv/lib/ajv.js +506 -0
- package/packages/config-eslint/node_modules/ajv/lib/cache.js +26 -0
- package/packages/config-eslint/node_modules/ajv/lib/compile/async.js +90 -0
- package/packages/config-eslint/node_modules/ajv/lib/compile/equal.js +5 -0
- package/packages/config-eslint/node_modules/ajv/lib/compile/error_classes.js +34 -0
- package/packages/config-eslint/node_modules/ajv/lib/compile/formats.js +142 -0
- package/packages/config-eslint/node_modules/ajv/lib/compile/index.js +387 -0
- package/packages/config-eslint/node_modules/ajv/lib/compile/resolve.js +270 -0
- package/packages/config-eslint/node_modules/ajv/lib/compile/rules.js +66 -0
- package/packages/config-eslint/node_modules/ajv/lib/compile/schema_obj.js +9 -0
- package/packages/config-eslint/node_modules/ajv/lib/compile/ucs2length.js +20 -0
- package/packages/config-eslint/node_modules/ajv/lib/compile/util.js +239 -0
- package/packages/config-eslint/node_modules/ajv/lib/data.js +49 -0
- package/packages/config-eslint/node_modules/ajv/lib/definition_schema.js +37 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/_limit.jst +113 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/_limitItems.jst +12 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/_limitLength.jst +12 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/_limitProperties.jst +12 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/allOf.jst +32 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/anyOf.jst +46 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/coerce.def +51 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/comment.jst +9 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/const.jst +11 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/contains.jst +55 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/custom.jst +191 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/defaults.def +47 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/definitions.def +203 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/dependencies.jst +79 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/enum.jst +30 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/errors.def +194 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/format.jst +106 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/if.jst +73 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/items.jst +98 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/missing.def +39 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/multipleOf.jst +22 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/not.jst +43 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/oneOf.jst +54 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/pattern.jst +14 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/properties.jst +245 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/propertyNames.jst +52 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/ref.jst +85 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/required.jst +108 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/uniqueItems.jst +62 -0
- package/packages/config-eslint/node_modules/ajv/lib/dot/validate.jst +276 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/README.md +3 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limit.js +163 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limitItems.js +80 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limitLength.js +85 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limitProperties.js +80 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/allOf.js +42 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/anyOf.js +73 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/comment.js +14 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/const.js +56 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/contains.js +81 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/custom.js +228 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/dependencies.js +168 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/enum.js +66 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/format.js +150 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/if.js +103 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/index.js +33 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/items.js +140 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/multipleOf.js +80 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/not.js +84 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/oneOf.js +73 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/pattern.js +75 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/properties.js +335 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/propertyNames.js +81 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/ref.js +124 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/required.js +270 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/uniqueItems.js +86 -0
- package/packages/config-eslint/node_modules/ajv/lib/dotjs/validate.js +482 -0
- package/packages/config-eslint/node_modules/ajv/lib/keyword.js +146 -0
- package/packages/config-eslint/node_modules/ajv/lib/refs/data.json +17 -0
- package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-draft-04.json +149 -0
- package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-draft-06.json +154 -0
- package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-draft-07.json +168 -0
- package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-secure.json +94 -0
- package/packages/config-eslint/node_modules/ajv/package.json +106 -0
- package/packages/config-eslint/node_modules/ajv/scripts/.eslintrc.yml +3 -0
- package/packages/config-eslint/node_modules/ajv/scripts/bundle.js +61 -0
- package/packages/config-eslint/node_modules/ajv/scripts/compile-dots.js +73 -0
- package/packages/config-eslint/node_modules/ajv/scripts/info +10 -0
- package/packages/config-eslint/node_modules/ajv/scripts/prepare-tests +12 -0
- package/packages/config-eslint/node_modules/ajv/scripts/publish-built-version +32 -0
- package/packages/config-eslint/node_modules/ajv/scripts/travis-gh-pages +23 -0
- package/packages/config-eslint/node_modules/eslint-visitor-keys/LICENSE +201 -0
- package/packages/config-eslint/node_modules/eslint-visitor-keys/README.md +105 -0
- package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/eslint-visitor-keys.cjs +384 -0
- package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/eslint-visitor-keys.d.cts +27 -0
- package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/index.d.ts +16 -0
- package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/visitor-keys.d.ts +12 -0
- package/packages/config-eslint/node_modules/eslint-visitor-keys/lib/index.js +65 -0
- package/packages/config-eslint/node_modules/eslint-visitor-keys/lib/visitor-keys.js +315 -0
- package/packages/config-eslint/node_modules/eslint-visitor-keys/package.json +74 -0
- package/packages/config-eslint/node_modules/espree/LICENSE +25 -0
- package/packages/config-eslint/node_modules/espree/README.md +244 -0
- package/packages/config-eslint/node_modules/espree/dist/espree.cjs +883 -0
- package/packages/config-eslint/node_modules/espree/espree.js +177 -0
- package/packages/config-eslint/node_modules/espree/lib/espree.js +349 -0
- package/packages/config-eslint/node_modules/espree/lib/features.js +27 -0
- package/packages/config-eslint/node_modules/espree/lib/options.js +123 -0
- package/packages/config-eslint/node_modules/espree/lib/token-translator.js +263 -0
- package/packages/config-eslint/node_modules/espree/lib/version.js +3 -0
- package/packages/config-eslint/node_modules/espree/package.json +86 -0
- package/packages/config-eslint/node_modules/globals/globals.json +1998 -0
- package/packages/config-eslint/node_modules/globals/index.d.ts +2077 -0
- package/packages/config-eslint/node_modules/globals/index.js +2 -0
- package/packages/config-eslint/node_modules/globals/license +9 -0
- package/packages/config-eslint/node_modules/globals/package.json +58 -0
- package/packages/config-eslint/node_modules/globals/readme.md +44 -0
- package/packages/config-eslint/node_modules/json-schema-traverse/.eslintrc.yml +27 -0
- package/packages/config-eslint/node_modules/json-schema-traverse/.travis.yml +8 -0
- package/packages/config-eslint/node_modules/json-schema-traverse/LICENSE +21 -0
- package/packages/config-eslint/node_modules/json-schema-traverse/README.md +83 -0
- package/packages/config-eslint/node_modules/json-schema-traverse/index.js +89 -0
- package/packages/config-eslint/node_modules/json-schema-traverse/package.json +43 -0
- package/packages/config-eslint/node_modules/json-schema-traverse/spec/.eslintrc.yml +6 -0
- package/packages/config-eslint/node_modules/json-schema-traverse/spec/fixtures/schema.js +125 -0
- package/packages/config-eslint/node_modules/json-schema-traverse/spec/index.spec.js +171 -0
- package/packages/config-eslint/package.json +5 -3
- package/packages/config-eslint/plugins/no-await-in-promise.js +2 -2
- package/packages/config-eslint/utils/create-config.js +377 -0
- package/scripts/lint.eslint.sh +1 -1
- package/.eslintrc.cjs +0 -16
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
module.exports = function generate_propertyNames(it, $keyword, $ruleType) {
|
|
3
|
+
var out = ' ';
|
|
4
|
+
var $lvl = it.level;
|
|
5
|
+
var $dataLvl = it.dataLevel;
|
|
6
|
+
var $schema = it.schema[$keyword];
|
|
7
|
+
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
|
8
|
+
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
|
9
|
+
var $breakOnError = !it.opts.allErrors;
|
|
10
|
+
var $data = 'data' + ($dataLvl || '');
|
|
11
|
+
var $errs = 'errs__' + $lvl;
|
|
12
|
+
var $it = it.util.copy(it);
|
|
13
|
+
var $closingBraces = '';
|
|
14
|
+
$it.level++;
|
|
15
|
+
var $nextValid = 'valid' + $it.level;
|
|
16
|
+
out += 'var ' + ($errs) + ' = errors;';
|
|
17
|
+
if ((it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all))) {
|
|
18
|
+
$it.schema = $schema;
|
|
19
|
+
$it.schemaPath = $schemaPath;
|
|
20
|
+
$it.errSchemaPath = $errSchemaPath;
|
|
21
|
+
var $key = 'key' + $lvl,
|
|
22
|
+
$idx = 'idx' + $lvl,
|
|
23
|
+
$i = 'i' + $lvl,
|
|
24
|
+
$invalidName = '\' + ' + $key + ' + \'',
|
|
25
|
+
$dataNxt = $it.dataLevel = it.dataLevel + 1,
|
|
26
|
+
$nextData = 'data' + $dataNxt,
|
|
27
|
+
$dataProperties = 'dataProperties' + $lvl,
|
|
28
|
+
$ownProperties = it.opts.ownProperties,
|
|
29
|
+
$currentBaseId = it.baseId;
|
|
30
|
+
if ($ownProperties) {
|
|
31
|
+
out += ' var ' + ($dataProperties) + ' = undefined; ';
|
|
32
|
+
}
|
|
33
|
+
if ($ownProperties) {
|
|
34
|
+
out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
|
|
35
|
+
} else {
|
|
36
|
+
out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
|
|
37
|
+
}
|
|
38
|
+
out += ' var startErrs' + ($lvl) + ' = errors; ';
|
|
39
|
+
var $passData = $key;
|
|
40
|
+
var $wasComposite = it.compositeRule;
|
|
41
|
+
it.compositeRule = $it.compositeRule = true;
|
|
42
|
+
var $code = it.validate($it);
|
|
43
|
+
$it.baseId = $currentBaseId;
|
|
44
|
+
if (it.util.varOccurences($code, $nextData) < 2) {
|
|
45
|
+
out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
|
|
46
|
+
} else {
|
|
47
|
+
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
|
|
48
|
+
}
|
|
49
|
+
it.compositeRule = $it.compositeRule = $wasComposite;
|
|
50
|
+
out += ' if (!' + ($nextValid) + ') { for (var ' + ($i) + '=startErrs' + ($lvl) + '; ' + ($i) + '<errors; ' + ($i) + '++) { vErrors[' + ($i) + '].propertyName = ' + ($key) + '; } var err = '; /* istanbul ignore else */
|
|
51
|
+
if (it.createErrors !== false) {
|
|
52
|
+
out += ' { keyword: \'' + ('propertyNames') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { propertyName: \'' + ($invalidName) + '\' } ';
|
|
53
|
+
if (it.opts.messages !== false) {
|
|
54
|
+
out += ' , message: \'property name \\\'' + ($invalidName) + '\\\' is invalid\' ';
|
|
55
|
+
}
|
|
56
|
+
if (it.opts.verbose) {
|
|
57
|
+
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
|
58
|
+
}
|
|
59
|
+
out += ' } ';
|
|
60
|
+
} else {
|
|
61
|
+
out += ' {} ';
|
|
62
|
+
}
|
|
63
|
+
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
|
64
|
+
if (!it.compositeRule && $breakOnError) {
|
|
65
|
+
/* istanbul ignore if */
|
|
66
|
+
if (it.async) {
|
|
67
|
+
out += ' throw new ValidationError(vErrors); ';
|
|
68
|
+
} else {
|
|
69
|
+
out += ' validate.errors = vErrors; return false; ';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if ($breakOnError) {
|
|
73
|
+
out += ' break; ';
|
|
74
|
+
}
|
|
75
|
+
out += ' } }';
|
|
76
|
+
}
|
|
77
|
+
if ($breakOnError) {
|
|
78
|
+
out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
module.exports = function generate_ref(it, $keyword, $ruleType) {
|
|
3
|
+
var out = ' ';
|
|
4
|
+
var $lvl = it.level;
|
|
5
|
+
var $dataLvl = it.dataLevel;
|
|
6
|
+
var $schema = it.schema[$keyword];
|
|
7
|
+
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
|
8
|
+
var $breakOnError = !it.opts.allErrors;
|
|
9
|
+
var $data = 'data' + ($dataLvl || '');
|
|
10
|
+
var $valid = 'valid' + $lvl;
|
|
11
|
+
var $async, $refCode;
|
|
12
|
+
if ($schema == '#' || $schema == '#/') {
|
|
13
|
+
if (it.isRoot) {
|
|
14
|
+
$async = it.async;
|
|
15
|
+
$refCode = 'validate';
|
|
16
|
+
} else {
|
|
17
|
+
$async = it.root.schema.$async === true;
|
|
18
|
+
$refCode = 'root.refVal[0]';
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot);
|
|
22
|
+
if ($refVal === undefined) {
|
|
23
|
+
var $message = it.MissingRefError.message(it.baseId, $schema);
|
|
24
|
+
if (it.opts.missingRefs == 'fail') {
|
|
25
|
+
it.logger.error($message);
|
|
26
|
+
var $$outStack = $$outStack || [];
|
|
27
|
+
$$outStack.push(out);
|
|
28
|
+
out = ''; /* istanbul ignore else */
|
|
29
|
+
if (it.createErrors !== false) {
|
|
30
|
+
out += ' { keyword: \'' + ('$ref') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { ref: \'' + (it.util.escapeQuotes($schema)) + '\' } ';
|
|
31
|
+
if (it.opts.messages !== false) {
|
|
32
|
+
out += ' , message: \'can\\\'t resolve reference ' + (it.util.escapeQuotes($schema)) + '\' ';
|
|
33
|
+
}
|
|
34
|
+
if (it.opts.verbose) {
|
|
35
|
+
out += ' , schema: ' + (it.util.toQuotedString($schema)) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
|
36
|
+
}
|
|
37
|
+
out += ' } ';
|
|
38
|
+
} else {
|
|
39
|
+
out += ' {} ';
|
|
40
|
+
}
|
|
41
|
+
var __err = out;
|
|
42
|
+
out = $$outStack.pop();
|
|
43
|
+
if (!it.compositeRule && $breakOnError) {
|
|
44
|
+
/* istanbul ignore if */
|
|
45
|
+
if (it.async) {
|
|
46
|
+
out += ' throw new ValidationError([' + (__err) + ']); ';
|
|
47
|
+
} else {
|
|
48
|
+
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
|
52
|
+
}
|
|
53
|
+
if ($breakOnError) {
|
|
54
|
+
out += ' if (false) { ';
|
|
55
|
+
}
|
|
56
|
+
} else if (it.opts.missingRefs == 'ignore') {
|
|
57
|
+
it.logger.warn($message);
|
|
58
|
+
if ($breakOnError) {
|
|
59
|
+
out += ' if (true) { ';
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
throw new it.MissingRefError(it.baseId, $schema, $message);
|
|
63
|
+
}
|
|
64
|
+
} else if ($refVal.inline) {
|
|
65
|
+
var $it = it.util.copy(it);
|
|
66
|
+
$it.level++;
|
|
67
|
+
var $nextValid = 'valid' + $it.level;
|
|
68
|
+
$it.schema = $refVal.schema;
|
|
69
|
+
$it.schemaPath = '';
|
|
70
|
+
$it.errSchemaPath = $schema;
|
|
71
|
+
var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code);
|
|
72
|
+
out += ' ' + ($code) + ' ';
|
|
73
|
+
if ($breakOnError) {
|
|
74
|
+
out += ' if (' + ($nextValid) + ') { ';
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
$async = $refVal.$async === true || (it.async && $refVal.$async !== false);
|
|
78
|
+
$refCode = $refVal.code;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if ($refCode) {
|
|
82
|
+
var $$outStack = $$outStack || [];
|
|
83
|
+
$$outStack.push(out);
|
|
84
|
+
out = '';
|
|
85
|
+
if (it.opts.passContext) {
|
|
86
|
+
out += ' ' + ($refCode) + '.call(this, ';
|
|
87
|
+
} else {
|
|
88
|
+
out += ' ' + ($refCode) + '( ';
|
|
89
|
+
}
|
|
90
|
+
out += ' ' + ($data) + ', (dataPath || \'\')';
|
|
91
|
+
if (it.errorPath != '""') {
|
|
92
|
+
out += ' + ' + (it.errorPath);
|
|
93
|
+
}
|
|
94
|
+
var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
|
|
95
|
+
$parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
|
|
96
|
+
out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ', rootData) ';
|
|
97
|
+
var __callValidate = out;
|
|
98
|
+
out = $$outStack.pop();
|
|
99
|
+
if ($async) {
|
|
100
|
+
if (!it.async) throw new Error('async schema referenced by sync schema');
|
|
101
|
+
if ($breakOnError) {
|
|
102
|
+
out += ' var ' + ($valid) + '; ';
|
|
103
|
+
}
|
|
104
|
+
out += ' try { await ' + (__callValidate) + '; ';
|
|
105
|
+
if ($breakOnError) {
|
|
106
|
+
out += ' ' + ($valid) + ' = true; ';
|
|
107
|
+
}
|
|
108
|
+
out += ' } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; ';
|
|
109
|
+
if ($breakOnError) {
|
|
110
|
+
out += ' ' + ($valid) + ' = false; ';
|
|
111
|
+
}
|
|
112
|
+
out += ' } ';
|
|
113
|
+
if ($breakOnError) {
|
|
114
|
+
out += ' if (' + ($valid) + ') { ';
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
out += ' if (!' + (__callValidate) + ') { if (vErrors === null) vErrors = ' + ($refCode) + '.errors; else vErrors = vErrors.concat(' + ($refCode) + '.errors); errors = vErrors.length; } ';
|
|
118
|
+
if ($breakOnError) {
|
|
119
|
+
out += ' else { ';
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
module.exports = function generate_required(it, $keyword, $ruleType) {
|
|
3
|
+
var out = ' ';
|
|
4
|
+
var $lvl = it.level;
|
|
5
|
+
var $dataLvl = it.dataLevel;
|
|
6
|
+
var $schema = it.schema[$keyword];
|
|
7
|
+
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
|
8
|
+
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
|
9
|
+
var $breakOnError = !it.opts.allErrors;
|
|
10
|
+
var $data = 'data' + ($dataLvl || '');
|
|
11
|
+
var $valid = 'valid' + $lvl;
|
|
12
|
+
var $isData = it.opts.$data && $schema && $schema.$data,
|
|
13
|
+
$schemaValue;
|
|
14
|
+
if ($isData) {
|
|
15
|
+
out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
|
|
16
|
+
$schemaValue = 'schema' + $lvl;
|
|
17
|
+
} else {
|
|
18
|
+
$schemaValue = $schema;
|
|
19
|
+
}
|
|
20
|
+
var $vSchema = 'schema' + $lvl;
|
|
21
|
+
if (!$isData) {
|
|
22
|
+
if ($schema.length < it.opts.loopRequired && it.schema.properties && Object.keys(it.schema.properties).length) {
|
|
23
|
+
var $required = [];
|
|
24
|
+
var arr1 = $schema;
|
|
25
|
+
if (arr1) {
|
|
26
|
+
var $property, i1 = -1,
|
|
27
|
+
l1 = arr1.length - 1;
|
|
28
|
+
while (i1 < l1) {
|
|
29
|
+
$property = arr1[i1 += 1];
|
|
30
|
+
var $propertySch = it.schema.properties[$property];
|
|
31
|
+
if (!($propertySch && (it.opts.strictKeywords ? (typeof $propertySch == 'object' && Object.keys($propertySch).length > 0) || $propertySch === false : it.util.schemaHasRules($propertySch, it.RULES.all)))) {
|
|
32
|
+
$required[$required.length] = $property;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
var $required = $schema;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if ($isData || $required.length) {
|
|
41
|
+
var $currentErrorPath = it.errorPath,
|
|
42
|
+
$loopRequired = $isData || $required.length >= it.opts.loopRequired,
|
|
43
|
+
$ownProperties = it.opts.ownProperties;
|
|
44
|
+
if ($breakOnError) {
|
|
45
|
+
out += ' var missing' + ($lvl) + '; ';
|
|
46
|
+
if ($loopRequired) {
|
|
47
|
+
if (!$isData) {
|
|
48
|
+
out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; ';
|
|
49
|
+
}
|
|
50
|
+
var $i = 'i' + $lvl,
|
|
51
|
+
$propertyPath = 'schema' + $lvl + '[' + $i + ']',
|
|
52
|
+
$missingProperty = '\' + ' + $propertyPath + ' + \'';
|
|
53
|
+
if (it.opts._errorDataPathProperty) {
|
|
54
|
+
it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
|
|
55
|
+
}
|
|
56
|
+
out += ' var ' + ($valid) + ' = true; ';
|
|
57
|
+
if ($isData) {
|
|
58
|
+
out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
|
|
59
|
+
}
|
|
60
|
+
out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { ' + ($valid) + ' = ' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] !== undefined ';
|
|
61
|
+
if ($ownProperties) {
|
|
62
|
+
out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + ']) ';
|
|
63
|
+
}
|
|
64
|
+
out += '; if (!' + ($valid) + ') break; } ';
|
|
65
|
+
if ($isData) {
|
|
66
|
+
out += ' } ';
|
|
67
|
+
}
|
|
68
|
+
out += ' if (!' + ($valid) + ') { ';
|
|
69
|
+
var $$outStack = $$outStack || [];
|
|
70
|
+
$$outStack.push(out);
|
|
71
|
+
out = ''; /* istanbul ignore else */
|
|
72
|
+
if (it.createErrors !== false) {
|
|
73
|
+
out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
|
|
74
|
+
if (it.opts.messages !== false) {
|
|
75
|
+
out += ' , message: \'';
|
|
76
|
+
if (it.opts._errorDataPathProperty) {
|
|
77
|
+
out += 'is a required property';
|
|
78
|
+
} else {
|
|
79
|
+
out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
|
|
80
|
+
}
|
|
81
|
+
out += '\' ';
|
|
82
|
+
}
|
|
83
|
+
if (it.opts.verbose) {
|
|
84
|
+
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
|
85
|
+
}
|
|
86
|
+
out += ' } ';
|
|
87
|
+
} else {
|
|
88
|
+
out += ' {} ';
|
|
89
|
+
}
|
|
90
|
+
var __err = out;
|
|
91
|
+
out = $$outStack.pop();
|
|
92
|
+
if (!it.compositeRule && $breakOnError) {
|
|
93
|
+
/* istanbul ignore if */
|
|
94
|
+
if (it.async) {
|
|
95
|
+
out += ' throw new ValidationError([' + (__err) + ']); ';
|
|
96
|
+
} else {
|
|
97
|
+
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
|
101
|
+
}
|
|
102
|
+
out += ' } else { ';
|
|
103
|
+
} else {
|
|
104
|
+
out += ' if ( ';
|
|
105
|
+
var arr2 = $required;
|
|
106
|
+
if (arr2) {
|
|
107
|
+
var $propertyKey, $i = -1,
|
|
108
|
+
l2 = arr2.length - 1;
|
|
109
|
+
while ($i < l2) {
|
|
110
|
+
$propertyKey = arr2[$i += 1];
|
|
111
|
+
if ($i) {
|
|
112
|
+
out += ' || ';
|
|
113
|
+
}
|
|
114
|
+
var $prop = it.util.getProperty($propertyKey),
|
|
115
|
+
$useData = $data + $prop;
|
|
116
|
+
out += ' ( ( ' + ($useData) + ' === undefined ';
|
|
117
|
+
if ($ownProperties) {
|
|
118
|
+
out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
|
|
119
|
+
}
|
|
120
|
+
out += ') && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop)) + ') ) ';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
out += ') { ';
|
|
124
|
+
var $propertyPath = 'missing' + $lvl,
|
|
125
|
+
$missingProperty = '\' + ' + $propertyPath + ' + \'';
|
|
126
|
+
if (it.opts._errorDataPathProperty) {
|
|
127
|
+
it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
|
|
128
|
+
}
|
|
129
|
+
var $$outStack = $$outStack || [];
|
|
130
|
+
$$outStack.push(out);
|
|
131
|
+
out = ''; /* istanbul ignore else */
|
|
132
|
+
if (it.createErrors !== false) {
|
|
133
|
+
out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
|
|
134
|
+
if (it.opts.messages !== false) {
|
|
135
|
+
out += ' , message: \'';
|
|
136
|
+
if (it.opts._errorDataPathProperty) {
|
|
137
|
+
out += 'is a required property';
|
|
138
|
+
} else {
|
|
139
|
+
out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
|
|
140
|
+
}
|
|
141
|
+
out += '\' ';
|
|
142
|
+
}
|
|
143
|
+
if (it.opts.verbose) {
|
|
144
|
+
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
|
145
|
+
}
|
|
146
|
+
out += ' } ';
|
|
147
|
+
} else {
|
|
148
|
+
out += ' {} ';
|
|
149
|
+
}
|
|
150
|
+
var __err = out;
|
|
151
|
+
out = $$outStack.pop();
|
|
152
|
+
if (!it.compositeRule && $breakOnError) {
|
|
153
|
+
/* istanbul ignore if */
|
|
154
|
+
if (it.async) {
|
|
155
|
+
out += ' throw new ValidationError([' + (__err) + ']); ';
|
|
156
|
+
} else {
|
|
157
|
+
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
|
161
|
+
}
|
|
162
|
+
out += ' } else { ';
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
if ($loopRequired) {
|
|
166
|
+
if (!$isData) {
|
|
167
|
+
out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; ';
|
|
168
|
+
}
|
|
169
|
+
var $i = 'i' + $lvl,
|
|
170
|
+
$propertyPath = 'schema' + $lvl + '[' + $i + ']',
|
|
171
|
+
$missingProperty = '\' + ' + $propertyPath + ' + \'';
|
|
172
|
+
if (it.opts._errorDataPathProperty) {
|
|
173
|
+
it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
|
|
174
|
+
}
|
|
175
|
+
if ($isData) {
|
|
176
|
+
out += ' if (' + ($vSchema) + ' && !Array.isArray(' + ($vSchema) + ')) { var err = '; /* istanbul ignore else */
|
|
177
|
+
if (it.createErrors !== false) {
|
|
178
|
+
out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
|
|
179
|
+
if (it.opts.messages !== false) {
|
|
180
|
+
out += ' , message: \'';
|
|
181
|
+
if (it.opts._errorDataPathProperty) {
|
|
182
|
+
out += 'is a required property';
|
|
183
|
+
} else {
|
|
184
|
+
out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
|
|
185
|
+
}
|
|
186
|
+
out += '\' ';
|
|
187
|
+
}
|
|
188
|
+
if (it.opts.verbose) {
|
|
189
|
+
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
|
190
|
+
}
|
|
191
|
+
out += ' } ';
|
|
192
|
+
} else {
|
|
193
|
+
out += ' {} ';
|
|
194
|
+
}
|
|
195
|
+
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else if (' + ($vSchema) + ' !== undefined) { ';
|
|
196
|
+
}
|
|
197
|
+
out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { if (' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] === undefined ';
|
|
198
|
+
if ($ownProperties) {
|
|
199
|
+
out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + ']) ';
|
|
200
|
+
}
|
|
201
|
+
out += ') { var err = '; /* istanbul ignore else */
|
|
202
|
+
if (it.createErrors !== false) {
|
|
203
|
+
out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
|
|
204
|
+
if (it.opts.messages !== false) {
|
|
205
|
+
out += ' , message: \'';
|
|
206
|
+
if (it.opts._errorDataPathProperty) {
|
|
207
|
+
out += 'is a required property';
|
|
208
|
+
} else {
|
|
209
|
+
out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
|
|
210
|
+
}
|
|
211
|
+
out += '\' ';
|
|
212
|
+
}
|
|
213
|
+
if (it.opts.verbose) {
|
|
214
|
+
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
|
215
|
+
}
|
|
216
|
+
out += ' } ';
|
|
217
|
+
} else {
|
|
218
|
+
out += ' {} ';
|
|
219
|
+
}
|
|
220
|
+
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } ';
|
|
221
|
+
if ($isData) {
|
|
222
|
+
out += ' } ';
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
var arr3 = $required;
|
|
226
|
+
if (arr3) {
|
|
227
|
+
var $propertyKey, i3 = -1,
|
|
228
|
+
l3 = arr3.length - 1;
|
|
229
|
+
while (i3 < l3) {
|
|
230
|
+
$propertyKey = arr3[i3 += 1];
|
|
231
|
+
var $prop = it.util.getProperty($propertyKey),
|
|
232
|
+
$missingProperty = it.util.escapeQuotes($propertyKey),
|
|
233
|
+
$useData = $data + $prop;
|
|
234
|
+
if (it.opts._errorDataPathProperty) {
|
|
235
|
+
it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
|
|
236
|
+
}
|
|
237
|
+
out += ' if ( ' + ($useData) + ' === undefined ';
|
|
238
|
+
if ($ownProperties) {
|
|
239
|
+
out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
|
|
240
|
+
}
|
|
241
|
+
out += ') { var err = '; /* istanbul ignore else */
|
|
242
|
+
if (it.createErrors !== false) {
|
|
243
|
+
out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
|
|
244
|
+
if (it.opts.messages !== false) {
|
|
245
|
+
out += ' , message: \'';
|
|
246
|
+
if (it.opts._errorDataPathProperty) {
|
|
247
|
+
out += 'is a required property';
|
|
248
|
+
} else {
|
|
249
|
+
out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
|
|
250
|
+
}
|
|
251
|
+
out += '\' ';
|
|
252
|
+
}
|
|
253
|
+
if (it.opts.verbose) {
|
|
254
|
+
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
|
255
|
+
}
|
|
256
|
+
out += ' } ';
|
|
257
|
+
} else {
|
|
258
|
+
out += ' {} ';
|
|
259
|
+
}
|
|
260
|
+
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
it.errorPath = $currentErrorPath;
|
|
266
|
+
} else if ($breakOnError) {
|
|
267
|
+
out += ' if (true) {';
|
|
268
|
+
}
|
|
269
|
+
return out;
|
|
270
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
module.exports = function generate_uniqueItems(it, $keyword, $ruleType) {
|
|
3
|
+
var out = ' ';
|
|
4
|
+
var $lvl = it.level;
|
|
5
|
+
var $dataLvl = it.dataLevel;
|
|
6
|
+
var $schema = it.schema[$keyword];
|
|
7
|
+
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
|
8
|
+
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
|
9
|
+
var $breakOnError = !it.opts.allErrors;
|
|
10
|
+
var $data = 'data' + ($dataLvl || '');
|
|
11
|
+
var $valid = 'valid' + $lvl;
|
|
12
|
+
var $isData = it.opts.$data && $schema && $schema.$data,
|
|
13
|
+
$schemaValue;
|
|
14
|
+
if ($isData) {
|
|
15
|
+
out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
|
|
16
|
+
$schemaValue = 'schema' + $lvl;
|
|
17
|
+
} else {
|
|
18
|
+
$schemaValue = $schema;
|
|
19
|
+
}
|
|
20
|
+
if (($schema || $isData) && it.opts.uniqueItems !== false) {
|
|
21
|
+
if ($isData) {
|
|
22
|
+
out += ' var ' + ($valid) + '; if (' + ($schemaValue) + ' === false || ' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'boolean\') ' + ($valid) + ' = false; else { ';
|
|
23
|
+
}
|
|
24
|
+
out += ' var i = ' + ($data) + '.length , ' + ($valid) + ' = true , j; if (i > 1) { ';
|
|
25
|
+
var $itemType = it.schema.items && it.schema.items.type,
|
|
26
|
+
$typeIsArray = Array.isArray($itemType);
|
|
27
|
+
if (!$itemType || $itemType == 'object' || $itemType == 'array' || ($typeIsArray && ($itemType.indexOf('object') >= 0 || $itemType.indexOf('array') >= 0))) {
|
|
28
|
+
out += ' outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } ';
|
|
29
|
+
} else {
|
|
30
|
+
out += ' var itemIndices = {}, item; for (;i--;) { var item = ' + ($data) + '[i]; ';
|
|
31
|
+
var $method = 'checkDataType' + ($typeIsArray ? 's' : '');
|
|
32
|
+
out += ' if (' + (it.util[$method]($itemType, 'item', it.opts.strictNumbers, true)) + ') continue; ';
|
|
33
|
+
if ($typeIsArray) {
|
|
34
|
+
out += ' if (typeof item == \'string\') item = \'"\' + item; ';
|
|
35
|
+
}
|
|
36
|
+
out += ' if (typeof itemIndices[item] == \'number\') { ' + ($valid) + ' = false; j = itemIndices[item]; break; } itemIndices[item] = i; } ';
|
|
37
|
+
}
|
|
38
|
+
out += ' } ';
|
|
39
|
+
if ($isData) {
|
|
40
|
+
out += ' } ';
|
|
41
|
+
}
|
|
42
|
+
out += ' if (!' + ($valid) + ') { ';
|
|
43
|
+
var $$outStack = $$outStack || [];
|
|
44
|
+
$$outStack.push(out);
|
|
45
|
+
out = ''; /* istanbul ignore else */
|
|
46
|
+
if (it.createErrors !== false) {
|
|
47
|
+
out += ' { keyword: \'' + ('uniqueItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { i: i, j: j } ';
|
|
48
|
+
if (it.opts.messages !== false) {
|
|
49
|
+
out += ' , message: \'should NOT have duplicate items (items ## \' + j + \' and \' + i + \' are identical)\' ';
|
|
50
|
+
}
|
|
51
|
+
if (it.opts.verbose) {
|
|
52
|
+
out += ' , schema: ';
|
|
53
|
+
if ($isData) {
|
|
54
|
+
out += 'validate.schema' + ($schemaPath);
|
|
55
|
+
} else {
|
|
56
|
+
out += '' + ($schema);
|
|
57
|
+
}
|
|
58
|
+
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
|
59
|
+
}
|
|
60
|
+
out += ' } ';
|
|
61
|
+
} else {
|
|
62
|
+
out += ' {} ';
|
|
63
|
+
}
|
|
64
|
+
var __err = out;
|
|
65
|
+
out = $$outStack.pop();
|
|
66
|
+
if (!it.compositeRule && $breakOnError) {
|
|
67
|
+
/* istanbul ignore if */
|
|
68
|
+
if (it.async) {
|
|
69
|
+
out += ' throw new ValidationError([' + (__err) + ']); ';
|
|
70
|
+
} else {
|
|
71
|
+
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
|
75
|
+
}
|
|
76
|
+
out += ' } ';
|
|
77
|
+
if ($breakOnError) {
|
|
78
|
+
out += ' else { ';
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
if ($breakOnError) {
|
|
82
|
+
out += ' if (true) { ';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|