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.7 to 0.0.8

lib/utils/http-client/get-module.d.ts

9

lib/types.d.ts

@@ -54,5 +54,14 @@ import type { JSONSchema4 } from "json-schema";

}
export declare type JsonSchemaValidatorSettings = {
http?: {
requestOptions?: any;
getModulePath?: string;
};
};
export interface RuleContext {
id: string;
options: any[];
settings: {
"json-schema-validator"?: JsonSchemaValidatorSettings;
};
parserPath: string;

@@ -59,0 +68,0 @@ parserServices: {

5

lib/utils/http-client/cli.js

@@ -17,6 +17,7 @@ "use strict";

try {
const args = process.argv.slice(-2);
const args = process.argv.slice(-3);
const url = args[0];
const options = JSON.parse(args[1]);
const result = yield http_1.get(url, options);
const { httpModulePath } = JSON.parse(args[2]);
const result = yield http_1.get(url, options, httpModulePath);
console.log(result);

@@ -23,0 +24,0 @@ }

2

lib/utils/http-client/http.d.ts
/// <reference types="node" />
import type { RequestOptions } from "https";
export declare function get(url: string, options?: RequestOptions): Promise<string>;
export declare function get(url: string, options?: RequestOptions, httpModulePath?: string): Promise<string>;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.get = void 0;
const https_1 = __importDefault(require("https"));
const https_2 = __importDefault(require("https"));
const url_1 = require("url");
const TIMEOUT = 30000;
function get(url, options) {
const client = url.startsWith("https") ? https_1.default : https_2.default;
return new Promise((resolve, reject) => {
let result = "";
const req = client.get(Object.assign(Object.assign({}, options), urlToOptions(url)), (res) => {
res.on("data", (chunk) => {
result += chunk;
});
res.on("end", () => {
resolve(result);
});
});
req.on("error", (e) => {
reject(e);
});
req.setTimeout(TIMEOUT, function handleRequestTimeout() {
if (req.destroy) {
req.destroy();
}
else {
req.abort();
}
reject(new Error(`Timeout of ${TIMEOUT}ms exceeded`));
});
});
function get(url, options, httpModulePath) {
const client = httpModulePath
?
require(httpModulePath)
:
require("./get-modules/http");
return client.default ? client.default(url, options) : client(url, options);
}
exports.get = get;
function urlToOptions(urlStr) {
const url = new url_1.URL(urlStr);
const options = {
protocol: url.protocol,
hostname: typeof url.hostname === "string" && url.hostname.startsWith("[")
? url.hostname.slice(1, -1)
: url.hostname,
path: `${url.pathname || ""}${url.search || ""}`,
};
if (url.port !== "") {
options.port = Number(url.port);
}
if (url.username || url.password) {
options.auth = `${url.username}:${url.password}`;
}
return options;
}
/// <reference types="node" />
import type { RequestOptions } from "https";
export declare function syncGet(url: string, options?: RequestOptions): string;
export declare function syncGet(url: string, options?: RequestOptions, httpModulePath?: string): string;

@@ -9,7 +9,12 @@ "use strict";

const path_1 = __importDefault(require("path"));
function syncGet(url, options) {
function syncGet(url, options, httpModulePath) {
const httpScriptPath = require.resolve("./cli");
const execPath = process.execPath;
const argument = JSON.stringify(options || {});
const cliArgs = [httpScriptPath, url, argument];
const optionsJSON = JSON.stringify(options !== null && options !== void 0 ? options : {});
const cliArgs = [
httpScriptPath,
url,
optionsJSON,
JSON.stringify({ httpModulePath }),
];
if (path_1.default.extname(httpScriptPath) === ".ts") {

@@ -16,0 +21,0 @@ cliArgs.unshift("--require", "ts-node/register/transpile-only");

@@ -10,2 +10,4 @@ "use strict";

const http_client_1 = require("./http-client");
const debug_1 = __importDefault(require("debug"));
const debug = debug_1.default("eslint-plugin-json-schema-validator:utils-schema");
function urlToSchemastoreFilePath(url) {

@@ -30,12 +32,7 @@ if (/^https?:\/\/json\.schemastore\.org\//u.test(url)) {

}
return require(path_1.default.resolve(getCwd(), schemaPath));
function getCwd() {
if (context.getCwd) {
return context.getCwd();
}
return path_1.default.resolve("");
}
return require(path_1.default.resolve(getCwd(context), schemaPath));
}
exports.loadSchema = loadSchema;
function loadSchemaFromURL(schemaUrl, context) {
var _a, _b, _c;
let jsonPath = schemaUrl.replace(/^https?:\/\//u, "");

@@ -50,7 +47,11 @@ if (!jsonPath.endsWith(".json")) {

}
const options = (_b = (_a = context.settings) === null || _a === void 0 ? void 0 : _a["json-schema-validator"]) === null || _b === void 0 ? void 0 : _b.http;
const httpRequestOptions = (_c = options === null || options === void 0 ? void 0 : options.requestOptions) !== null && _c !== void 0 ? _c : {};
const httpGetModulePath = resolvePath(options === null || options === void 0 ? void 0 : options.getModulePath, context);
let json;
try {
json = http_client_1.syncGet(schemaUrl);
json = http_client_1.syncGet(schemaUrl, httpRequestOptions, httpGetModulePath);
}
catch (e) {
debug(e.message);
return null;

@@ -62,3 +63,3 @@ }

}
catch (_a) {
catch (_d) {
context.report({

@@ -91,1 +92,16 @@ loc: { line: 1, column: 0 },

}
function resolvePath(modulePath, context) {
if (!modulePath) {
return undefined;
}
if (modulePath.startsWith(".")) {
return path_1.default.join(getCwd(context), modulePath);
}
return modulePath;
}
function getCwd(context) {
if (context.getCwd) {
return context.getCwd();
}
return path_1.default.resolve("");
}
{
"name": "eslint-plugin-json-schema-validator",
"version": "0.0.7",
"version": "0.0.8",
"description": "ESLint plugin that validates data using JSON Schema Validator.",

@@ -17,7 +17,6 @@ "main": "lib/index.js",

"eslint-fix": "eslint \"tests\" \"src\" \"docs\" --ext .js,.vue,.ts,.json,.md,.toml,.yaml,.yml --fix",
"pretest:base": "cross-env DEBUG=eslint-plugin-json-schema-validator*",
"test:base": "mocha --require ts-node/register \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
"test:base": "env-cmd -e test mocha --require ts-node/register \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
"test": "npm run test:base",
"cover": "nyc --reporter=lcov npm run test:base",
"test:debug": "mocha --require ts-node/register/transpile-only \"tests/src/**/*.ts\" --reporter dot",
"test:debug": "env-cmd -e test mocha --require ts-node/register/transpile-only \"tests/src/**/*.ts\" --reporter dot",
"update": "node --require ts-node/register/transpile-only ./tools/update.ts && npm run eslint-fix",

@@ -58,2 +57,3 @@ "new": "ts-node ./tools/new-rule.ts",

"ajv": "^6.12.6",
"debug": "^4.3.1",
"jsonc-eslint-parser": "^0.6.2",

@@ -63,2 +63,3 @@ "lodash": "^4.17.19",

"toml-eslint-parser": "^0.2.1",
"tunnel-agent": "^0.6.0",
"yaml-eslint-parser": "^0.3.2"

@@ -76,6 +77,7 @@ },

"@types/node": "^14.0.13",
"@types/request": "^2.48.5",
"@types/semver": "^7.3.1",
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.4.1",
"cross-env": "^7.0.2",
"env-cmd": "^10.1.0",
"eslint": "^7.3.0",

@@ -100,2 +102,3 @@ "eslint-config-prettier": "^7.0.0",

"raw-loader": "^4.0.1",
"request": "^2.88.2",
"semver": "^7.3.2",

@@ -102,0 +105,0 @@ "stylelint": "^13.6.1",

@@ -126,2 +126,76 @@ # Introduction

<!--ADVANCED_USAGE_GUIDE_START-->
## :trollface: Advanced Usage
### Settings
Use `.eslintrc.*` file to configure `settings`. See also: [https://eslint.org/docs/user-guide/configuring/configuration-files#adding-shared-settings](https://eslint.org/docs/user-guide/configuring/configuration-files#adding-shared-settings).
Example **.eslintrc.js**:
```js
module.exports = {
settings: {
"json-schema-validator": {
http: {
getModulePath: "",
requestOptions: {},
}
}
}
}
```
- `http` ... Settings to resolve schema URLs.
- `getModulePath` ... Module path to `GET` the URL. The default implementation is [./src/utils/http-client/get-modules/http.ts](https://github.com/ota-meshi/eslint-plugin-json-schema-validator/blob/main/src/utils/http-client/get-modules/http.ts).
- `requestOptions` ... Options used in the module.
#### Example of `http`
Example of using the `request` module for HTTP requests.
**`./path/to/request-get.js`**:
```js
const request = require("request")
/**
* GET Method using request module.
*/
module.exports = function get(url, options) {
return new Promise((resolve, reject) => {
request.get(url, options, (error, _res, body) => {
if (error) {
reject(error)
return
}
resolve(body)
})
})
}
```
**.eslintrc.js**:
<!-- eslint-skip -->
```js
module.exports = {
settings: {
"json-schema-validator": {
http: {
getModulePath: require.resolve("./path/to/request-get.js"),
requestOptions: {
// Example of proxy settings.
proxy: "http://my.proxy.com:8080/"
},
}
}
}
}
```
<!--ADVANCED_USAGE_GUIDE_END-->
## :beers: Contributing

@@ -128,0 +202,0 @@

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