eslint-plugin-json-schema-validator
Advanced tools
Comparing version 0.0.0 to 0.0.1
@@ -14,5 +14,17 @@ "use strict"; | ||
const ast_1 = require("../utils/ast"); | ||
const ajv = new ajv_1.default({ schemaId: "auto", allErrors: true }); | ||
const ajv = new ajv_1.default({ | ||
schemaId: "auto", | ||
allErrors: true, | ||
verbose: true, | ||
}); | ||
ajv.addMetaSchema(require("ajv/lib/refs/json-schema-draft-04.json")); | ||
ajv.addMetaSchema(require("ajv/lib/refs/json-schema-draft-06.json")); | ||
function escapeQuotes(str) { | ||
return str | ||
.replace(/'|\\/g, "\\$&") | ||
.replace(/\n/g, "\\n") | ||
.replace(/\r/g, "\\r") | ||
.replace(/\f/g, "\\f") | ||
.replace(/\t/g, "\\t"); | ||
} | ||
function parseDataPath(error) { | ||
@@ -28,12 +40,41 @@ const dataPath = error.dataPath.startsWith(".") | ||
index++; | ||
const startIndex = index; | ||
let endIndex = dataPath.length; | ||
for (; index < dataPath.length; index++) { | ||
if (dataPath[index] === "]") { | ||
endIndex = index; | ||
index++; | ||
break; | ||
let prop = ""; | ||
if (dataPath[index] === "'") { | ||
index++; | ||
for (; index < dataPath.length; index++) { | ||
const c = dataPath[index]; | ||
if (c === "\\") { | ||
index++; | ||
const k = dataPath[index]; | ||
prop += | ||
k === "n" | ||
? "\n" | ||
: k === "r" | ||
? "\r" | ||
: k === "f" | ||
? "\f" | ||
: k === "t" | ||
? "\t" | ||
: k; | ||
continue; | ||
} | ||
if (c === "'") { | ||
index++; | ||
index++; | ||
break; | ||
} | ||
prop += c; | ||
} | ||
} | ||
paths.push(dataPath.slice(startIndex, endIndex)); | ||
else { | ||
for (; index < dataPath.length; index++) { | ||
const c = dataPath[index]; | ||
if (c === "]") { | ||
index++; | ||
break; | ||
} | ||
prop += c; | ||
} | ||
} | ||
paths.push(prop); | ||
} | ||
@@ -44,20 +85,21 @@ else if (c === ".") { | ||
else { | ||
const startIndex = index; | ||
let endIndex = dataPath.length; | ||
let prop = ""; | ||
for (; index < dataPath.length; index++) { | ||
if (dataPath[index] === ".") { | ||
endIndex = index; | ||
const c = dataPath[index]; | ||
if (c === ".") { | ||
index++; | ||
break; | ||
} | ||
if (dataPath[index] === "[") { | ||
endIndex = index; | ||
if (c === "[") { | ||
break; | ||
} | ||
prop += c; | ||
} | ||
paths.push(dataPath.slice(startIndex, endIndex)); | ||
paths.push(prop); | ||
} | ||
} | ||
if (error.keyword === "additionalProperties") { | ||
paths.push(error.params.additionalProperty); | ||
const additionalProperty = error.params | ||
.additionalProperty; | ||
paths.push(additionalProperty); | ||
} | ||
@@ -71,7 +113,13 @@ return paths; | ||
if (error.keyword === "additionalProperties") { | ||
const additionalProperty = error.params | ||
const property = error.params | ||
.additionalProperty; | ||
return `Unexpected property "${dataPath.length | ||
? `${dataPath}.${additionalProperty}` | ||
: additionalProperty}"`; | ||
const escaped = escapeQuotes(property); | ||
let errorPath = dataPath; | ||
if (property === escaped) { | ||
errorPath = errorPath ? `${errorPath}.${property}` : property; | ||
} | ||
else { | ||
errorPath += `['${escaped}']`; | ||
} | ||
return `Unexpected property "${errorPath}"`; | ||
} | ||
@@ -101,4 +149,4 @@ return `"${dataPath}" ${error.message}.`; | ||
let jsonPath; | ||
if (schemaPath.startsWith("https://json.schemastore.org/")) { | ||
jsonPath = schemaPath.replace(/^https:\/\/json\.schemastore\.org\//u, ""); | ||
if (/^https?:\/\/json\.schemastore\.org\//u.test(schemaPath)) { | ||
jsonPath = schemaPath.replace(/^https?:\/\/json\.schemastore\.org\//u, ""); | ||
} | ||
@@ -137,3 +185,3 @@ else { | ||
} | ||
if (!schemaData.url.startsWith("https://json.schemastore.org/")) { | ||
if (!/^https?:\/\/json\.schemastore\.org\//u.test(schemaData.url)) { | ||
continue; | ||
@@ -140,0 +188,0 @@ } |
@@ -31,3 +31,3 @@ "use strict"; | ||
} | ||
throw new Error("Unexpected state"); | ||
throw new Error(`${"Unexpected state: ["}${[path, ...paths].join(", ")}]`); | ||
}, | ||
@@ -66,3 +66,3 @@ JSONArrayExpression(node, paths) { | ||
} | ||
throw new Error("Unexpected state"); | ||
throw new Error(`${"Unexpected state: ["}${[path, ...paths].join(", ")}]`); | ||
}, | ||
@@ -69,0 +69,0 @@ }; |
@@ -19,3 +19,3 @@ "use strict"; | ||
} | ||
throw new Error("Unexpected state"); | ||
throw new Error(`${"Unexpected state: ["}${[path, ...paths].join(", ")}]`); | ||
}, | ||
@@ -41,3 +41,3 @@ TOMLInlineTable(node, paths) { | ||
} | ||
throw new Error("Unexpected state"); | ||
throw new Error(`${"Unexpected state: ["}${paths.join(", ")}]`); | ||
}, | ||
@@ -73,3 +73,3 @@ }; | ||
} | ||
throw new Error("Unexpected state"); | ||
throw new Error(`${"Unexpected state: ["}${paths.join(", ")}]`); | ||
} | ||
@@ -76,0 +76,0 @@ exports.getTOMLNodeFromPath = getTOMLNodeFromPath; |
@@ -25,3 +25,3 @@ "use strict"; | ||
} | ||
throw new Error("Unexpected state"); | ||
throw new Error(`${"Unexpected state: ["}${[path, ...paths].join(", ")}]`); | ||
}, | ||
@@ -61,3 +61,3 @@ YAMLDocument(node, _paths) { | ||
} | ||
throw new Error("Unexpected state"); | ||
throw new Error(`${"Unexpected state: ["}${[path, ...paths].join(", ")}]`); | ||
}, | ||
@@ -96,3 +96,3 @@ YAMLSequence(node, paths) { | ||
} | ||
throw new Error("Unexpected state"); | ||
throw new Error(`${"Unexpected state: ["}${[path, ...paths].join(", ")}]`); | ||
}, | ||
@@ -103,7 +103,7 @@ YAMLAlias(node, paths) { | ||
}, | ||
YAMLWithMeta(node, _paths) { | ||
YAMLWithMeta(node, paths) { | ||
if (node.value) { | ||
return { value: node.value }; | ||
} | ||
throw new Error("Unexpected state"); | ||
throw new Error(`${"Unexpected state: ["}${paths.join(", ")}]`); | ||
}, | ||
@@ -110,0 +110,0 @@ }; |
{ | ||
"name": "eslint-plugin-json-schema-validator", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "ESLint plugin that validates data using JSON Schema Validator.", | ||
@@ -8,4 +8,3 @@ "main": "lib/index.js", | ||
"lib", | ||
"schemastore", | ||
"update" | ||
"schemastore" | ||
], | ||
@@ -76,3 +75,2 @@ "scripts": { | ||
"@typescript-eslint/parser": "^4.4.1", | ||
"babel-eslint": "^10.1.0", | ||
"cross-env": "^7.0.2", | ||
@@ -79,0 +77,0 @@ "eslint": "^7.3.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
41
2
0
3868608
269
3788