Socket
Socket
Sign inDemoInstall

eslint-plugin-json-schema-validator

Package Overview
Dependencies
Maintainers
2
Versions
317
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-json-schema-validator - npm Package Compare versions

Comparing version 3.2.8 to 4.0.0

7

lib/rules/no-invalid.js

@@ -15,3 +15,4 @@ "use strict";

const validator_factory_1 = require("../utils/validator-factory");
const node_fs_1 = __importDefault(require("node:fs"));
const fs_1 = __importDefault(require("fs"));
const CATALOG_URL = "https://www.schemastore.org/api/json/catalog.json";
function matchFile(filename, fileMatch) {

@@ -51,3 +52,3 @@ return (fileMatch.includes(path_1.default.basename(filename)) ||

if (option.useSchemastoreCatalog !== false) {
const catalog = require("../../schemastore/www.schemastore.org/api/json/catalog.json");
const catalog = (0, schema_1.loadJson)(CATALOG_URL, context);
const schemas = catalog.schemas;

@@ -346,3 +347,3 @@ for (const schemaData of schemas) {

try {
if (node_fs_1.default.statSync(filename).isDirectory()) {
if (fs_1.default.statSync(filename).isDirectory()) {
return child || filename;

@@ -349,0 +350,0 @@ }

import type { RuleContext } from "../types";
import type { SchemaObject } from "./types";
export declare function urlToSchemastoreFilePath(url: string): string | null;
export declare function loadSchema(schemaPath: string, context: RuleContext): null | SchemaObject;
export declare function loadJson<T = any>(jsonPath: string, context: RuleContext): null | T;

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.loadSchema = exports.urlToSchemastoreFilePath = void 0;
exports.loadJson = exports.loadSchema = void 0;
const path_1 = __importDefault(require("path"));

@@ -16,39 +16,28 @@ const fs_1 = __importDefault(require("fs"));

const RELOADING = new Set();
function urlToSchemastoreFilePath(url) {
if (/^https?:\/\/json\.schemastore\.org\//u.test(url)) {
const jsonPath = url.replace(/^https?:\/\//u, "");
if (jsonPath.endsWith(".json")) {
return jsonPath;
}
return `${jsonPath}.json`;
}
return null;
function loadSchema(schemaPath, context) {
return loadJsonInternal(schemaPath, context, (schema) => {
(0, json_schema_migrate_1.draft7)(schema);
return schema;
});
}
exports.urlToSchemastoreFilePath = urlToSchemastoreFilePath;
function loadSchema(schemaPath, context) {
if (schemaPath.startsWith("http://") || schemaPath.startsWith("https://")) {
const jsonPath = urlToSchemastoreFilePath(schemaPath);
if (!jsonPath) {
return loadSchemaFromURL(schemaPath, context);
}
try {
return require(`../../schemastore/${jsonPath}`);
}
catch (_a) {
}
return loadSchemaFromURL(schemaPath, context);
exports.loadSchema = loadSchema;
function loadJson(jsonPath, context) {
return loadJsonInternal(jsonPath, context);
}
exports.loadJson = loadJson;
function loadJsonInternal(jsonPath, context, edit) {
if (jsonPath.startsWith("http://") || jsonPath.startsWith("https://")) {
return loadJsonFromURL(jsonPath, context, edit);
}
const json = fs_1.default.readFileSync(path_1.default.resolve(getCwd(context), schemaPath), "utf-8");
const schema = JSON.parse(json);
(0, json_schema_migrate_1.draft7)(schema);
return schema;
const json = fs_1.default.readFileSync(path_1.default.resolve(getCwd(context), jsonPath), "utf-8");
const data = JSON.parse(json);
return edit ? edit(data) : data;
}
exports.loadSchema = loadSchema;
function loadSchemaFromURL(schemaUrl, context) {
function loadJsonFromURL(jsonPath, context, edit) {
var _a, _b, _c;
let jsonPath = schemaUrl.replace(/^https?:\/\//u, "");
if (!jsonPath.endsWith(".json")) {
jsonPath = `${jsonPath}.json`;
let jsonFileName = jsonPath.replace(/^https?:\/\//u, "");
if (!jsonFileName.endsWith(".json")) {
jsonFileName = `${jsonFileName}.json`;
}
const jsonFilePath = path_1.default.join(__dirname, `../../.cached_schemastore/${jsonPath}`);
const jsonFilePath = path_1.default.join(__dirname, `../../.cached_schemastore/${jsonFileName}`);
const options = (_b = (_a = context.settings) === null || _a === void 0 ? void 0 : _a["json-schema-validator"]) === null || _b === void 0 ? void 0 : _b.http;

@@ -58,20 +47,25 @@ const httpRequestOptions = (_c = options === null || options === void 0 ? void 0 : options.requestOptions) !== null && _c !== void 0 ? _c : {};

makeDirs(path_1.default.dirname(jsonFilePath));
if (fs_1.default.existsSync(jsonFilePath)) {
const { schema, timestamp } = require(jsonFilePath);
if (schema != null && typeof timestamp === "number") {
if (timestamp + TTL < Date.now()) {
if (!RELOADING.has(schemaUrl)) {
RELOADING.add(schemaUrl);
(0, http_client_1.get)(schemaUrl, httpRequestOptions, httpGetModulePath).then((json) => {
postProcess(schemaUrl, jsonFilePath, json, context);
RELOADING.delete(schemaUrl);
});
}
let data, timestamp;
try {
;
({ data, timestamp } =
require(`../../.cached_schemastore/${jsonFileName}`));
}
catch (_d) {
}
if (data != null && typeof timestamp === "number") {
if (timestamp + TTL < Date.now()) {
if (!RELOADING.has(jsonFilePath)) {
RELOADING.add(jsonFilePath);
(0, http_client_1.get)(jsonPath, httpRequestOptions, httpGetModulePath).then((json) => {
postProcess(jsonPath, jsonFilePath, json, context, edit);
RELOADING.delete(jsonFilePath);
});
}
return schema;
}
return data;
}
let json;
try {
json = (0, http_client_1.syncGet)(schemaUrl, httpRequestOptions, httpGetModulePath);
json = (0, http_client_1.syncGet)(jsonPath, httpRequestOptions, httpGetModulePath);
}

@@ -82,8 +76,8 @@ catch (e) {

}
return postProcess(schemaUrl, jsonFilePath, json, context);
return postProcess(jsonPath, jsonFilePath, json, context, edit);
}
function postProcess(schemaUrl, jsonFilePath, json, context) {
let schema;
function postProcess(schemaUrl, jsonFilePath, json, context, edit) {
let data;
try {
schema = JSON.parse(json);
data = JSON.parse(json);
}

@@ -97,5 +91,7 @@ catch (_a) {

}
(0, json_schema_migrate_1.draft7)(schema);
if (edit) {
data = edit(data);
}
fs_1.default.writeFileSync(jsonFilePath, schemaStringify({
schema,
data,
timestamp: Date.now(),

@@ -105,3 +101,3 @@ v: require("../../package.json").version,

delete require.cache[jsonFilePath];
return schema;
return data;
}

@@ -108,0 +104,0 @@ function makeDirs(dir) {

{
"name": "eslint-plugin-json-schema-validator",
"version": "3.2.8",
"version": "4.0.0",
"description": "ESLint plugin that validates data using JSON Schema Validator.",

@@ -11,8 +11,7 @@ "repository": "git+https://github.com/ota-meshi/eslint-plugin-json-schema-validator.git",

"engines": {
"node": "^14.17.0 || >=16.0.0"
"node": "^14.18.0 || >=16.0.0"
},
"main": "lib/index.js",
"files": [
"lib",
"schemastore"
"lib"
],

@@ -42,8 +41,5 @@ "keywords": [

"preversion": "yarn test && git add .",
"re-migrate": "yarn ts tools/update-schemastore/re-migrate",
"test": "env-cmd -e test yarn mocha \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
"ts": "node -r esbuild-register",
"update": "yarn ts ./tools/update && yarn lint-fix",
"update:schemastore": "yarn ts tools/update-schemastore",
"update:schemastore-only": "yarn ts tools/update-schemastore/only",
"version": "env-cmd -e version yarn update && git add ."

@@ -61,3 +57,3 @@ },

"minimatch": "^5.0.0",
"synckit": "^0.7.1",
"synckit": "^0.8.0",
"toml-eslint-parser": "^0.4.0",

@@ -97,3 +93,2 @@ "tunnel-agent": "^0.6.0",

"eslint-plugin-yml": "^1.0.0",
"eslint4b": "^7.3.1",
"espree": "^9.0.0",

@@ -116,4 +111,5 @@ "mocha": "^10.0.0",

"vue-eslint-parser": "^9.0.0",
"vuepress": "^1.5.2"
"vuepress": "^1.5.2",
"yaml": "^2.1.1"
}
}

@@ -233,4 +233,2 @@ # Introduction

The JSON Schema included in this plugin release is copy from [SchemaStore]. Check [here](https://github.com/ota-meshi/eslint-plugin-json-schema-validator/blob/main/schemastore/README.md) for licenses and details.
[SchemaStore]: https://github.com/SchemaStore/schemastore

@@ -237,0 +235,0 @@ [JSON]: https://json.org/

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc