Commit 4c043884 authored by David Sveningsson's avatar David Sveningsson
Browse files

fix(deps): update dependency ajv to v7


Signed-off-by: HTML-validate's avatarHTML-validate <gitlab@html-validate.org>
parent 8d9a144f
Pipeline #234641682 passed with stages
in 10 minutes and 20 seconds
......@@ -1764,6 +1764,18 @@
"strip-json-comments": "^3.1.1"
},
"dependencies": {
"ajv": {
"version": "6.12.6",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
"integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
"dev": true,
"requires": {
"fast-deep-equal": "^3.1.1",
"fast-json-stable-stringify": "^2.0.0",
"json-schema-traverse": "^0.4.1",
"uri-js": "^4.2.2"
}
},
"debug": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
......@@ -1792,6 +1804,12 @@
"resolve-from": "^4.0.0"
}
},
"json-schema-traverse": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
"dev": true
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
......@@ -3905,13 +3923,13 @@
}
},
"ajv": {
"version": "6.12.6",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
"integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-7.0.2.tgz",
"integrity": "sha512-qIaxO9RXjaXyO21tJr0EvwPcZa49m64GcXCU8ZrLjCAlFyMuOcPpI560So4A11M1WsKslJYIXn6jSyG5P0xIeg==",
"requires": {
"fast-deep-equal": "^3.1.1",
"fast-json-stable-stringify": "^2.0.0",
"json-schema-traverse": "^0.4.1",
"json-schema-traverse": "^1.0.0",
"require-from-string": "^2.0.2",
"uri-js": "^4.2.2"
}
},
......@@ -7675,6 +7693,18 @@
"integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==",
"dev": true
},
"ajv": {
"version": "6.12.6",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
"integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
"dev": true,
"requires": {
"fast-deep-equal": "^3.1.1",
"fast-json-stable-stringify": "^2.0.0",
"json-schema-traverse": "^0.4.1",
"uri-js": "^4.2.2"
}
},
"cross-spawn": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
......@@ -7748,6 +7778,12 @@
"resolve-from": "^4.0.0"
}
},
"json-schema-traverse": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
"dev": true
},
"levn": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz",
......@@ -8553,7 +8589,8 @@
"fast-json-stable-stringify": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz",
"integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I="
"integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=",
"dev": true
},
"fast-levenshtein": {
"version": "2.0.6",
......@@ -9991,6 +10028,26 @@
"requires": {
"ajv": "^6.12.3",
"har-schema": "^2.0.0"
},
"dependencies": {
"ajv": {
"version": "6.12.6",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
"integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
"dev": true,
"requires": {
"fast-deep-equal": "^3.1.1",
"fast-json-stable-stringify": "^2.0.0",
"json-schema-traverse": "^0.4.1",
"uri-js": "^4.2.2"
}
},
"json-schema-traverse": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
"dev": true
}
}
},
"hard-rejection": {
......@@ -12071,9 +12128,9 @@
"dev": true
},
"json-schema-traverse": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="
},
"json-stable-stringify": {
"version": "0.0.1",
......@@ -20640,6 +20697,11 @@
"integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=",
"dev": true
},
"require-from-string": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
"integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw=="
},
"require-main-filename": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz",
......@@ -22566,6 +22628,26 @@
"lodash": "^4.17.20",
"slice-ansi": "^4.0.0",
"string-width": "^4.2.0"
},
"dependencies": {
"ajv": {
"version": "6.12.6",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
"integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
"dev": true,
"requires": {
"fast-deep-equal": "^3.1.1",
"fast-json-stable-stringify": "^2.0.0",
"json-schema-traverse": "^0.4.1",
"uri-js": "^4.2.2"
}
},
"json-schema-traverse": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
"dev": true
}
}
},
"tar": {
......@@ -23206,9 +23288,9 @@
}
},
"uri-js": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz",
"integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==",
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.0.tgz",
"integrity": "sha512-B0yRTzYdUCCn9n+F4+Gh4yIDtMQcaJsmYBDsTSG8g/OejKBodLQ2IHfN3bM7jUsRXndopT7OIXWdYqc1fjmV6g==",
"requires": {
"punycode": "^2.1.0"
},
......
......@@ -32,7 +32,7 @@ interface LoadedPlugin extends Plugin {
let rootDirCache: string = null;
const ajv = new Ajv({ jsonPointers: true });
const ajv = new Ajv({ strict: true, strictTuples: true, strictTypes: true });
ajv.addMetaSchema(require("ajv/lib/refs/json-schema-draft-06.json"));
const validator = ajv.compile(schema);
......
import betterAjvErrors from "@sidvind/better-ajv-errors";
import Ajv from "ajv";
import { ErrorObject } from "ajv";
import { UserError } from "./user-error";
function getSummary(schema: any, obj: any, errors: Ajv.ErrorObject[]): string {
function getSummary(schema: any, obj: any, errors: ErrorObject[]): string {
const output = betterAjvErrors(schema, obj, errors, {
format: "js",
}) as any;
......@@ -14,14 +14,14 @@ export class SchemaValidationError extends UserError {
public filename: string | null;
private obj: any;
private schema: any;
private errors: Ajv.ErrorObject[];
private errors: ErrorObject[];
public constructor(
filename: string | null,
message: string,
obj: any, // eslint-disable-line @typescript-eslint/explicit-module-boundary-types
schema: any, // eslint-disable-line @typescript-eslint/explicit-module-boundary-types
errors: Ajv.ErrorObject[]
errors: ErrorObject[]
) {
const summary = getSummary(schema, obj, errors);
super(`${message}: ${summary}`);
......
import Ajv from "ajv";
import Ajv, { KeywordDefinition, ValidateFunction } from "ajv";
import { DataValidateFunction, DataValidationCxt } from "ajv/dist/types";
import deepmerge from "deepmerge";
import jsonMergePatch from "json-merge-patch";
import { HtmlElement } from "../dom";
......@@ -45,12 +46,15 @@ function overwriteMerge<T>(a: T[], b: T[]): T[] {
* Injects errors with the "type" keyword to give the same output.
*/
/* istanbul ignore next: manual testing */
const ajvRegexpValidate: Ajv.ValidateFunction = function (data: any, dataPath: string): boolean {
const ajvRegexpValidate: DataValidateFunction = function (
data: any,
dataCxt: DataValidationCxt
): boolean {
const valid = data instanceof RegExp;
if (!valid) {
ajvRegexpValidate.errors = [
{
dataPath,
dataPath: dataCxt.dataPath,
schemaPath: undefined,
keyword: "type",
message: "should be regexp",
......@@ -62,7 +66,8 @@ const ajvRegexpValidate: Ajv.ValidateFunction = function (data: any, dataPath: s
}
return valid;
};
const ajvRegexpKeyword: Ajv.KeywordDefinition = {
const ajvRegexpKeyword: KeywordDefinition = {
keyword: "regexp",
schema: false,
errors: true,
validate: ajvRegexpValidate,
......@@ -91,7 +96,7 @@ export class MetaTable {
if (patch.properties) {
this.schema = jsonMergePatch.apply(this.schema, {
patternProperties: {
"^.*$": {
"^[^$].*$": {
properties: patch.properties,
},
},
......@@ -110,16 +115,15 @@ export class MetaTable {
* @param obj - Object with metadata to load
* @param filename - Optional filename used when presenting validation error
*/
public loadFromObject(obj: MetaDataTable, filename: string | null = null): void {
const validator = this.getSchemaValidator();
const valid = validator(obj);
if (!valid) {
public loadFromObject(obj: unknown, filename: string | null = null): void {
const validate = this.getSchemaValidator();
if (!validate(obj)) {
throw new SchemaValidationError(
filename,
`Element metadata is not valid`,
obj,
this.schema,
validator.errors
validate.errors
);
}
......@@ -206,11 +210,12 @@ export class MetaTable {
/**
* Construct a new AJV schema validator.
*/
private getSchemaValidator(): Ajv.ValidateFunction {
const ajv = new Ajv({ jsonPointers: true });
private getSchemaValidator(): ValidateFunction<MetaDataTable> {
const ajv = new Ajv({ strict: true, strictTuples: true, strictTypes: true });
ajv.addMetaSchema(require("ajv/lib/refs/json-schema-draft-06.json"));
ajv.addKeyword("regexp", ajvRegexpKeyword);
return ajv.compile(this.schema);
ajv.addKeyword(ajvRegexpKeyword);
ajv.addKeyword({ keyword: "copyable" });
return ajv.compile<MetaDataTable>(this.schema);
}
/**
......
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "https://html-validate.org/schemas/config.json",
"version": "1.0",
"type": "object",
"additionalProperties": false,
......@@ -33,7 +32,9 @@
},
"title": "Element metadata to load",
"description": "Array of modules, plugins or files to load element metadata from. Use <rootDir> to refer to the folder with the package.json file.",
"example": ["html-validate:recommended", "plugin:recommended", "module", "./local-file.json"]
"examples": [
["html-validate:recommended", "plugin:recommended", "module", "./local-file.json"]
]
},
"plugins": {
......@@ -43,7 +44,7 @@
},
"title": "Plugins to load",
"description": "Array of plugins load. Use <rootDir> to refer to the folder with the package.json file.",
"example": ["my-plugin", "./local-plugin"]
"examples": [["my-plugin", "./local-plugin"]]
},
"transform": {
......@@ -53,11 +54,13 @@
},
"title": "File transformations to use.",
"description": "Object where key is regular expression to match filename and value is name of transformer.",
"example": {
"^.*\\.foo$": "my-transformer",
"^.*\\.bar$": "my-plugin",
"^.*\\.baz$": "my-plugin:named"
}
"examples": [
{
"^.*\\.foo$": "my-transformer",
"^.*\\.bar$": "my-plugin",
"^.*\\.baz$": "my-plugin:named"
}
]
},
"rules": {
......@@ -68,18 +71,28 @@
{ "enum": [0, 1, 2, "off", "warn", "error"] },
{
"type": "array",
"minItems": 1,
"maxItems": 1,
"items": [{ "enum": [0, 1, 2, "off", "warn", "error"] }]
},
{
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": [{ "enum": [0, 1, 2, "off", "warn", "error"] }, {}]
}
]
}
},
"title": "Rule configuration.",
"description": "Enable/disable rules, set severity. Some rules have additional configuration like style or patterns to use.",
"example": {
"foo": "error",
"bar": "off",
"baz": ["error", { "style": "camelcase" }]
}
"examples": [
{
"foo": "error",
"bar": "off",
"baz": ["error", { "style": "camelcase" }]
}
]
}
}
}
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "https://html-validate.org/schemas/elements.json",
"version": "1.0",
"type": "object",
......@@ -12,7 +11,7 @@
},
"patternProperties": {
"^.*$": {
"^[^$].*$": {
"type": "object",
"properties": {
"inherit": {
......@@ -155,6 +154,8 @@
"expression": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": [
{
"type": "string",
......@@ -168,6 +169,8 @@
"operation": {
"type": "array",
"minItems": 3,
"maxItems": 3,
"items": [
{
"type": "string"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment