Skip to content

Commit

Permalink
Upgrade ajv to v8
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Mar 26, 2021
1 parent b600501 commit 6480674
Show file tree
Hide file tree
Showing 78 changed files with 182 additions and 181 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"eslint": ">=6.0.0"
},
"dependencies": {
"ajv": "^7.0.0",
"ajv": "^8.0.0-0",
"debug": "^4.3.1",
"eslint-utils": "^2.1.0",
"json-schema-migrate": "^1.1.0",
Expand Down Expand Up @@ -98,7 +98,7 @@
"raw-loader": "^4.0.1",
"request": "^2.88.2",
"semver": "^7.3.2",
"stylelint": "^13.6.1",
"stylelint": "^13.12.0",
"stylelint-config-standard": "^21.0.0",
"stylelint-plugin-stylus": "^0.10.0",
"ts-node": "^9.0.0",
Expand Down
64 changes: 32 additions & 32 deletions src/utils/validator-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ function errorToValidateError(
): ValidateError {
const error: DefinedError = errorObject as DefinedError

const dataPath = error.dataPath.startsWith("/")
? error.dataPath.slice(1)
: error.dataPath
// console.log(dataPath)
const path: string[] = dataPath
? dataPath.split("/").map(unescapeFragment)
const instancePath = error.instancePath.startsWith("/")
? error.instancePath.slice(1)
: error.instancePath
// console.log(instancePath)
const path: string[] = instancePath
? instancePath.split("/").map(unescapeFragment)
: []

if (error.keyword === "additionalProperties") {
Expand All @@ -191,19 +191,19 @@ function errorToValidateError(
}
}
if (error.keyword === "uniqueItems") {
const baseMessage = `should NOT have duplicate items (items ## ${error.params.j} and ${error.params.i} are identical)`
const baseMessage = `must NOT have duplicate items (items ## ${error.params.j} and ${error.params.i} are identical)`
return {
message: `${joinPath(path)} ${baseMessage}.`,
path: [...path, String(error.params.i)],
}
}
let baseMessage: string
if (error.keyword === "enum") {
baseMessage = `should be equal to ${joinEnums(
baseMessage = `must be equal to ${joinEnums(
error.params.allowedValues,
)}`
} else if (error.keyword === "const") {
baseMessage = `should be equal to ${JSON.stringify(
baseMessage = `must be equal to ${JSON.stringify(
error.params.allowedValue,
)}`
} else if (error.keyword === "not") {
Expand All @@ -212,40 +212,40 @@ function errorToValidateError(
const schemaKeys = Object.keys(schema)
if (schemaKeys.length === 1 && schemaKeys[0] === "type") {
// { type: "foo" }
baseMessage = `should NOT be ${schema.type}`
baseMessage = `must NOT be ${schema.type}`
} else if (schemaKeys.length === 1 && schemaKeys[0] === "enum") {
// { enum: ["foo"] }
baseMessage = `should NOT be equal to ${joinEnums(schema.enum)}`
baseMessage = `must NOT be equal to ${joinEnums(schema.enum)}`
} else {
baseMessage = `should NOT be valid of define schema`
baseMessage = `must NOT be valid of define schema`
}
} else if (
error.keyword === "type" || // should be X
error.keyword === "oneOf" || // should match exactly one schema in oneOf
error.keyword === "anyOf" || // should match some schema in anyOf
error.keyword === "type" || // must be X
error.keyword === "oneOf" || // must match exactly one schema in oneOf
error.keyword === "anyOf" || // must match some schema in anyOf
// array
error.keyword === "minItems" || // should NOT have fewer than X items
error.keyword === "maxItems" || // should NOT have more than X items
error.keyword === "additionalItems" || // should NOT have more than X items
error.keyword === "contains" || // should contain at least 1 valid item(s)
error.keyword === "minItems" || // must NOT have fewer than X items
error.keyword === "maxItems" || // must NOT have more than X items
error.keyword === "additionalItems" || // must NOT have more than X items
error.keyword === "contains" || // must contain at least 1 valid item(s)
// object
error.keyword === "required" || // should have required property 'X'
error.keyword === "maxProperties" || // should NOT have more than X items
error.keyword === "minProperties" || // should NOT have fewer than X items
error.keyword === "dependencies" || // should have property X when property Y is present
error.keyword === "required" || // must have required property 'X'
error.keyword === "maxProperties" || // must NOT have more than X items
error.keyword === "minProperties" || // must NOT have fewer than X items
error.keyword === "dependencies" || // must have property X when property Y is present
// string
error.keyword === "pattern" || // should match pattern "X"
error.keyword === "maxLength" || // should NOT have more than X characters
error.keyword === "minLength" || // should NOT have fewer than X characters
error.keyword === "pattern" || // must match pattern "X"
error.keyword === "maxLength" || // must NOT have more than X characters
error.keyword === "minLength" || // must NOT have fewer than X characters
error.keyword === "format" ||
// number
error.keyword === "maximum" || // should be <= X
error.keyword === "minimum" || // should be >= X
error.keyword === "exclusiveMaximum" || // should be < X
error.keyword === "exclusiveMinimum" || // should be > X
error.keyword === "multipleOf" || // should be multiple of X
error.keyword === "maximum" || // must be <= X
error.keyword === "minimum" || // must be >= X
error.keyword === "exclusiveMaximum" || // must be < X
error.keyword === "exclusiveMinimum" || // must be > X
error.keyword === "multipleOf" || // must be multiple of X
// other
error.keyword === "if" // should match "X" schema
error.keyword === "if" // must match "X" schema
) {
// Use error.message
baseMessage = error.message!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"message": "\"additionalItemsTest\" should NOT have more than 2 items.",
"message": "\"additionalItemsTest\" must NOT have more than 2 items.",
"line": 3,
"column": 5,
"endLine": 3,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[
{
"message": "\"anyOfTest[2]\" should be string.",
"message": "\"anyOfTest[2]\" must be string.",
"line": 3,
"column": 31,
"endLine": 3,
"endColumn": 35
},
{
"message": "\"anyOfTest[2]\" should be number.",
"message": "\"anyOfTest[2]\" must be number.",
"line": 3,
"column": 31,
"endLine": 3,
"endColumn": 35
},
{
"message": "\"anyOfTest[2]\" should match some schema in anyOf.",
"message": "\"anyOfTest[2]\" must match a schema in anyOf.",
"line": 3,
"column": 31,
"endLine": 3,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[
{
"message": "\"containsTest\" should contain at least 1 valid item(s).",
"message": "\"containsTest\" must contain at least 1 valid item(s).",
"line": 3,
"column": 5,
"endLine": 3,
"endColumn": 19
},
{
"message": "\"containsTest[0]\" should be number.",
"message": "\"containsTest[0]\" must be number.",
"line": 3,
"column": 22,
"endLine": 3,
"endColumn": 27
},
{
"message": "\"containsTest[1]\" should be number.",
"message": "\"containsTest[1]\" must be number.",
"line": 3,
"column": 29,
"endLine": 3,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"message": "\"maxItemsTest\" should NOT have more than 2 items.",
"message": "\"maxItemsTest\" must NOT have more than 2 items.",
"line": 3,
"column": 5,
"endLine": 3,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"message": "\"uniqueItemsTest\" should NOT have duplicate items (items ## 1 and 3 are identical).",
"message": "\"uniqueItemsTest\" must NOT have duplicate items (items ## 1 and 3 are identical).",
"line": 3,
"column": 34,
"endLine": 3,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"message": "\"const\" should be equal to \"foo\".",
"message": "\"const\" must be equal to \"foo\".",
"line": 3,
"column": 5,
"endLine": 3,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[
{
"message": "\"extends[0]\" should be string.",
"message": "\"extends[0]\" must be string.",
"line": 3,
"column": 15,
"endLine": 3,
"endColumn": 17
},
{
"message": "\"plugins[1]\" should be string.",
"message": "\"plugins[1]\" must be string.",
"line": 4,
"column": 22,
"endLine": 4,
"endColumn": 26
},
{
"message": "\"plugins[2]\" should be string.",
"message": "\"plugins[2]\" must be string.",
"line": 4,
"column": 27,
"endLine": 4,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"message": "\"enum\" should be equal to 1, 2 or 3.",
"message": "\"enum\" must be equal to 1, 2 or 3.",
"line": 3,
"column": 5,
"endLine": 3,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[
{
"message": "\"extends[0]\" should be string.",
"message": "\"extends[0]\" must be string.",
"line": 3,
"column": 17,
"endLine": 3,
"endColumn": 19
},
{
"message": "\"plugins[1]\" should be string.",
"message": "\"plugins[1]\" must be string.",
"line": 4,
"column": 24,
"endLine": 4,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"message": "\"overrides[0]\" should have required property 'files'.",
"message": "\"overrides[0]\" must have required property 'files'.",
"line": 4,
"column": 9,
"endLine": 7,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[
{
"message": "\"extends[0]\" should be string.",
"message": "\"extends[0]\" must be string.",
"line": 3,
"column": 15,
"endLine": 3,
"endColumn": 17
},
{
"message": "\"plugins[1]\" should be string.",
"message": "\"plugins[1]\" must be string.",
"line": 4,
"column": 22,
"endLine": 4,
"endColumn": 26
},
{
"message": "\"plugins[2]\" should be string.",
"message": "\"plugins[2]\" must be string.",
"line": 4,
"column": 27,
"endLine": 4,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
[
{
"message": "\"extends[0]\" should be string.",
"message": "\"extends[0]\" must be string.",
"line": 3,
"column": 17,
"endLine": 3,
"endColumn": 17
},
{
"message": "\"plugins[1]\" should be string.",
"message": "\"plugins[1]\" must be string.",
"line": 4,
"column": 24,
"endLine": 4,
"endColumn": 25
},
{
"message": "\"plugins[2]\" should be string.",
"message": "\"plugins[2]\" must be string.",
"line": 4,
"column": 26,
"endLine": 4,
"endColumn": 27
},
{
"message": "\"overrides[0].files\" should be string.",
"message": "\"overrides[0].files\" must be string.",
"line": 7,
"column": 13,
"endLine": 7,
"endColumn": 20
},
{
"message": "\"overrides[0].files\" should NOT have fewer than 1 items.",
"message": "\"overrides[0].files\" must NOT have fewer than 1 items.",
"line": 7,
"column": 13,
"endLine": 7,
"endColumn": 20
},
{
"message": "\"overrides[0].files\" should match exactly one schema in oneOf.",
"message": "\"overrides[0].files\" must match exactly one schema in oneOf.",
"line": 7,
"column": 13,
"endLine": 7,
"endColumn": 20
},
{
"message": "\"overrides[0].extends[1]\" should be string.",
"message": "\"overrides[0].extends[1]\" must be string.",
"line": 8,
"column": 32,
"endLine": 8,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
[
{
"message": "\"plugins[1]\" should be string.",
"message": "\"plugins[1]\" must be string.",
"line": 5,
"column": 3,
"endLine": 5,
"endColumn": 5
},
{
"message": "\"overrides[0].files\" should be string.",
"message": "\"overrides[0].files\" must be string.",
"line": 10,
"column": 1,
"endLine": 10,
"endColumn": 6
},
{
"message": "\"overrides[0].files\" should NOT have fewer than 1 items.",
"message": "\"overrides[0].files\" must NOT have fewer than 1 items.",
"line": 10,
"column": 1,
"endLine": 10,
"endColumn": 6
},
{
"message": "\"overrides[0].files\" should match exactly one schema in oneOf.",
"message": "\"overrides[0].files\" must match exactly one schema in oneOf.",
"line": 10,
"column": 1,
"endLine": 10,
"endColumn": 6
},
{
"message": "\"overrides[0].extends[1]\" should be string.",
"message": "\"overrides[0].extends[1]\" must be string.",
"line": 13,
"column": 3,
"endLine": 13,
"endColumn": 5
},
{
"message": "\"overrides[0].extends[3]\" should be string.",
"message": "\"overrides[0].extends[3]\" must be string.",
"line": 15,
"column": 3,
"endLine": 15,
Expand Down

0 comments on commit 6480674

Please sign in to comment.