Socket
Socket
Sign inDemoInstall

eslint-plugin-json-schema-validator

Package Overview
Dependencies
Maintainers
1
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 0.0.6 to 0.0.7

lib/utils/http-client/cli.d.ts

24

lib/rules/no-invalid.js

@@ -19,2 +19,6 @@ "use strict";

verbose: true,
validateSchema: false,
missingRefs: "ignore",
extendRefs: "ignore",
logger: false,
});

@@ -144,12 +148,2 @@ ajv.addMetaSchema(require("ajv/lib/refs/json-schema-draft-04.json"));

}
function loadSchema(schemaPath, getCwd) {
if (schemaPath.startsWith("http://") || schemaPath.startsWith("https://")) {
const jsonPath = schema_1.urlToSchemastoreFilePath(schemaPath);
if (!jsonPath) {
return null;
}
return require(`../../schemastore/${jsonPath}`);
}
return require(path_1.default.resolve(getCwd(), schemaPath));
}
function parseOption(option, context) {

@@ -163,3 +157,3 @@ const filename = context.getFilename();

const schema = typeof schemaData.schema === "string"
? loadSchema(schemaData.schema, getCwd)
? schema_1.loadSchema(schemaData.schema, context)
: schemaData.schema;

@@ -187,3 +181,3 @@ if (!schema) {

}
const schema = loadSchema(schemaData.url, getCwd);
const schema = schema_1.loadSchema(schemaData.url, context);
if (!schema) {

@@ -206,8 +200,2 @@ continue;

};
function getCwd() {
if (context.getCwd) {
return context.getCwd();
}
return path_1.default.resolve("");
}
}

@@ -214,0 +202,0 @@ exports.default = utils_1.createRule("no-invalid", {

@@ -0,1 +1,5 @@

import type { RuleContext } from "../types";
declare type Schema = object;
export declare function urlToSchemastoreFilePath(url: string): string | null;
export declare function loadSchema(schemaPath: string, context: RuleContext): null | Schema;
export {};
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.urlToSchemastoreFilePath = void 0;
exports.loadSchema = exports.urlToSchemastoreFilePath = void 0;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const http_client_1 = require("./http-client");
function urlToSchemastoreFilePath(url) {
if (/^https?:\/\/json\.schemastore\.org\//u.test(url) ||
url.startsWith("https://raw.githubusercontent.com/angular/angular-cli") ||
url.startsWith("https://yarnpkg.com/")) {
if (/^https?:\/\/json\.schemastore\.org\//u.test(url)) {
const jsonPath = url.replace(/^https?:\/\//u, "");

@@ -17,1 +21,67 @@ if (jsonPath.endsWith(".json")) {

exports.urlToSchemastoreFilePath = urlToSchemastoreFilePath;
function loadSchema(schemaPath, context) {
if (schemaPath.startsWith("http://") || schemaPath.startsWith("https://")) {
const jsonPath = urlToSchemastoreFilePath(schemaPath);
if (!jsonPath) {
return loadSchemaFromURL(schemaPath, context);
}
return require(`../../schemastore/${jsonPath}`);
}
return require(path_1.default.resolve(getCwd(), schemaPath));
function getCwd() {
if (context.getCwd) {
return context.getCwd();
}
return path_1.default.resolve("");
}
}
exports.loadSchema = loadSchema;
function loadSchemaFromURL(schemaUrl, context) {
let jsonPath = schemaUrl.replace(/^https?:\/\//u, "");
if (!jsonPath.endsWith(".json")) {
jsonPath = `${jsonPath}.json`;
}
const jsonFilePath = path_1.default.join(__dirname, `../../.cached_schemastore/${jsonPath}`);
makeDirs(path_1.default.dirname(jsonFilePath));
if (fs_1.default.existsSync(jsonFilePath)) {
return require(jsonFilePath);
}
let json;
try {
json = http_client_1.syncGet(schemaUrl);
}
catch (e) {
return null;
}
let schema;
try {
schema = JSON.parse(json);
}
catch (_a) {
context.report({
loc: { line: 1, column: 0 },
message: `Could not be parsed JSON: "${schemaUrl}"`,
});
return null;
}
fs_1.default.writeFileSync(jsonFilePath, schemaStringify(schema));
return schema;
}
function makeDirs(dir) {
const dirs = [dir];
while (!fs_1.default.existsSync(dirs[0])) {
dirs.unshift(path_1.default.dirname(dirs[0]));
}
dirs.shift();
for (const dir of dirs) {
fs_1.default.mkdirSync(dir);
}
}
function schemaStringify(schema) {
return JSON.stringify(schema, (key, value) => {
if (key === "description" && typeof value === "string") {
return undefined;
}
return value;
});
}
{
"name": "eslint-plugin-json-schema-validator",
"version": "0.0.6",
"version": "0.0.7",
"description": "ESLint plugin that validates data using JSON Schema Validator.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -156,3 +156,3 @@ # Introduction

The JSON Schema included in this plugin release is copy from projects such as [SchemaStore]. Check [here](./schemastore/README.md) for licenses and details.
The JSON Schema included in this plugin release is copy from [SchemaStore]. Check [here](./schemastore/README.md) for licenses and details.

@@ -159,0 +159,0 @@ [SchemaStore]: https://github.com/SchemaStore/schemastore

@@ -1,5 +0,5 @@

The files included here are from the following projects. For the license, check the license of each project.
The files included here are from [SchemaStore]. Check the license of [SchemaStore].
- [SchemaStore](https://github.com/SchemaStore/schemastore) ... [Apache License 2.0](https://github.com/SchemaStore/schemastore/blob/master/LICENSE.md)
- [Angular CLI](https://github.com/angular/angular-cli) ... [MIT](https://github.com/angular/angular-cli/blob/master/LICENSE)
- [Yarn](https://yarnpkg.com/) ... [BSD 2-Clause "Simplified" License](https://github.com/yarnpkg/berry/blob/master/LICENSE.md)
- [SchemaStore] ... [Apache License 2.0](https://github.com/SchemaStore/schemastore/blob/master/LICENSE.md)
[SchemaStore]: https://github.com/SchemaStore/schemastore
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