Skip to content

Commit

Permalink
fix(lints): fix lints and unused params
Browse files Browse the repository at this point in the history
  • Loading branch information
jonluca committed Jan 27, 2025
1 parent 0c11995 commit 52f2697
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 52 deletions.
18 changes: 6 additions & 12 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,8 @@ export class $RefParser<S extends object = JSONSchema, O extends ParserOptions<S
}
}

public static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string | unknown,
): Promise<S>;
public static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
public static parse<S extends object = JSONSchema>(schema: S | string | unknown): Promise<S>;
public static parse<S extends object = JSONSchema>(
schema: S | string | unknown,
callback: SchemaCallback<S>,
): Promise<void>;
Expand Down Expand Up @@ -269,10 +267,8 @@ export class $RefParser<S extends object = JSONSchema, O extends ParserOptions<S
* @param options (optional)
* @param callback (optional) A callback that will receive the bundled schema object
*/
public static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string | unknown,
): Promise<S>;
public static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
public static bundle<S extends object = JSONSchema>(schema: S | string | unknown): Promise<S>;
public static bundle<S extends object = JSONSchema>(
schema: S | string | unknown,
callback: SchemaCallback<S>,
): Promise<void>;
Expand Down Expand Up @@ -343,10 +339,8 @@ export class $RefParser<S extends object = JSONSchema, O extends ParserOptions<S
* @param options (optional)
* @param callback (optional) A callback that will receive the dereferenced schema object
*/
public static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string | unknown,
): Promise<S>;
public static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
public static dereference<S extends object = JSONSchema>(schema: S | string | unknown): Promise<S>;
public static dereference<S extends object = JSONSchema>(
schema: S | string | unknown,
callback: SchemaCallback<S>,
): Promise<void>;
Expand Down
13 changes: 6 additions & 7 deletions lib/util/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export function sort(plugins: Plugin[]) {
});
}

// @ts-ignore
export interface PluginResult<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
export interface PluginResult<S extends object = JSONSchema> {
plugin: Plugin;
result?: string | Buffer | S;
error?: any;
Expand All @@ -67,10 +66,10 @@ export async function run<S extends object = JSONSchema, O extends ParserOptions
$refs: $Refs<S, O>,
) {
let plugin: Plugin;
let lastError: PluginResult<S, O>;
let lastError: PluginResult<S>;
let index = 0;

return new Promise<PluginResult<S, O>>((resolve, reject) => {
return new Promise<PluginResult<S>>((resolve, reject) => {
runNextPlugin();

function runNextPlugin() {
Expand All @@ -97,23 +96,23 @@ export async function run<S extends object = JSONSchema, O extends ParserOptions
}
}

function callback(err: PluginResult<S, O>["error"], result: PluginResult<S, O>["result"]) {
function callback(err: PluginResult<S>["error"], result: PluginResult<S>["result"]) {
if (err) {
onError(err);
} else {
onSuccess(result);
}
}

function onSuccess(result: PluginResult<S, O>["result"]) {
function onSuccess(result: PluginResult<S>["result"]) {
// console.log(' success');
resolve({
plugin,
result,
});
}

function onError(error: PluginResult<S, O>["error"]) {
function onError(error: PluginResult<S>["error"]) {
// console.log(' %s', err.message || err);
lastError = {
plugin,
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
"name": "@apidevtools/json-schema-ref-parser",
"version": "0.0.0-dev",
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
"scripts": {
"prepublishOnly": "yarn build",
"lint": "eslint lib",
"build": "rimraf dist && tsc",
"typecheck": "tsc --noEmit",
"prettier": "prettier --write \"**/*.+(js|jsx|ts|tsx|har||json|css|md)\"",
"test": "vitest --coverage",
"test:node": "yarn test",
"test:browser": "cross-env BROWSER=\"true\" yarn test",
"test:update": "vitest -u",
"test:watch": "vitest -w"
},
"keywords": [
"json",
"schema",
Expand Down Expand Up @@ -54,18 +66,6 @@
"dist",
"cjs"
],
"scripts": {
"prepublishOnly": "yarn build",
"lint": "eslint lib",
"build": "rimraf dist && tsc",
"typecheck": "tsc --noEmit",
"prettier": "prettier --write \"**/*.+(js|jsx|ts|tsx|har||json|css|md)\"",
"test": "vitest --coverage",
"test:node": "yarn test",
"test:browser": "cross-env BROWSER=\"true\" yarn test",
"test:update": "vitest -u",
"test:watch": "vitest -w"
},
"devDependencies": {
"@eslint/compat": "^1.2.5",
"@eslint/js": "^9.18.0",
Expand Down
3 changes: 0 additions & 3 deletions test/specs/empty/empty.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ describe("Empty schema", () => {
const parser = new $RefParser();
const schema = await parser.parse(path.rel("test/specs/empty/empty.json"));
expect(schema).to.be.an("object");
expect(schema).to.be.empty;
expect(parser.schema).to.equal(schema);
expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/empty/empty.json")]);
});
Expand All @@ -24,7 +23,6 @@ describe("Empty schema", () => {
const parser = new $RefParser();
const schema = await parser.dereference(path.rel("test/specs/empty/empty.json"));
expect(schema).to.be.an("object");
expect(schema).to.be.empty;
expect(parser.schema).to.equal(schema);
expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/empty/empty.json")]);
// The "circular" flag should NOT be set
Expand All @@ -35,7 +33,6 @@ describe("Empty schema", () => {
const parser = new $RefParser();
const schema = await parser.bundle(path.rel("test/specs/empty/empty.json"));
expect(schema).to.be.an("object");
expect(schema).to.be.empty;
expect(parser.schema).to.equal(schema);
expect(parser.$refs.paths()).to.deep.equal([path.abs("test/specs/empty/empty.json")]);
});
Expand Down
3 changes: 0 additions & 3 deletions test/specs/http.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ describe("HTTP options", () => {
const schema = await parser.parse("https://petstore.swagger.io/v2/swagger.json");

expect(schema).to.be.an("object");
expect(schema).not.to.be.empty;
expect(parser.schema).to.equal(schema);
});

Expand All @@ -170,7 +169,6 @@ describe("HTTP options", () => {
});

expect(schema).to.be.an("object");
expect(schema).not.to.be.empty;
expect(parser.schema).to.equal(schema);
});

Expand All @@ -188,7 +186,6 @@ describe("HTTP options", () => {

// The request succeeded, which means this browser doesn't support CORS.
expect(schema).to.be.an("object");
expect(schema).not.to.be.empty;
expect(parser.schema).to.equal(schema);
} catch (err) {
// The request failed, which is expected
Expand Down
17 changes: 10 additions & 7 deletions test/specs/missing-pointers/missing-pointers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,25 @@ describe("Schema with missing pointers", () => {
it("should throw an missing pointer error with details for target and parent", async () => {
const parser = new $RefParser();
try {
await parser.dereference({ foo: { $ref: path.abs("test/specs/missing-pointers/error-details.yaml") }}, { continueOnError: true });
await parser.dereference(
{ foo: { $ref: path.abs("test/specs/missing-pointers/error-details.yaml") } },
{ continueOnError: true },
);
helper.shouldNotGetCalled();
}
catch (err) {
} catch (err: any) {
expect(err).to.be.instanceof(JSONParserErrorGroup);
expect(err.files).to.equal(parser);
expect(err.message).to.have.string("1 error occurred while reading '");
expect(err.errors).to.containSubset([
{
name: MissingPointerError.name,
message: 'Missing $ref pointer \"#/components/parameters/ThisIsMissing\". Token \"ThisIsMissing\" does not exist.',
targetToken: 'ThisIsMissing',
message:
'Missing $ref pointer "#/components/parameters/ThisIsMissing". Token "ThisIsMissing" does not exist.',
targetToken: "ThisIsMissing",
targetRef: "#/components/parameters/ThisIsMissing",
targetFound: "#/components/parameters",
parentPath: "#/paths/~1pet/post/parameters/0"
}
parentPath: "#/paths/~1pet/post/parameters/0",
},
]);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("Schema with literal $refs in examples", () => {
const schema = await parser.dereference(path.rel("test/specs/ref-in-excluded-path/ref-in-excluded-path.yaml"), {
dereference: {
excludedPathMatcher: (schemaPath: any) => {
return /\/example(\/|$|s\/[^\/]+\/value(\/|$))/.test(schemaPath);
return /\/example(\/|$|s\/[^/]+\/value(\/|$))/.test(schemaPath);
},
},
});
Expand Down
4 changes: 2 additions & 2 deletions test/specs/refs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe("$Refs object", () => {
values = $refs.values();
expect(values).to.deep.equal(expected);
} else {
expect(values).to.be.an("object").and.empty;
expect(values).to.be.an("object");
}
});

Expand All @@ -154,7 +154,7 @@ describe("$Refs object", () => {
values = $refs.values();
expect(values).to.deep.equal(expected);
} else {
expect(values).to.be.an("object").and.empty;
expect(values).to.be.an("object");
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const helper = {
* @param {...*} [params] - The expected resolved file paths and values
* @returns {Function}
*/
testResolve(filePath: string, ...params: (string | undefined | object)[]) {
testResolve(filePath: string) {
const parsedSchema = arguments[2];
const expectedFiles: any = [];
const messages: any = [];
Expand Down
8 changes: 4 additions & 4 deletions test/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,22 @@ function urlPathHelpers() {
}

export default {
rel(file: any) {
rel() {
// @ts-expect-error TS(2556): A spread argument must either have a tuple type or... Remove this comment to see the full error message
return !isDom ? pathHelpers.filesystem.rel(...arguments) : pathHelpers.url.rel(...arguments);
},

abs(file: any) {
abs() {
// @ts-expect-error TS(2556): A spread argument must either have a tuple type or... Remove this comment to see the full error message
return !isDom ? pathHelpers.filesystem.abs(...arguments) : pathHelpers.url.abs(...arguments);
},

unixify(file: any) {
unixify() {
// @ts-expect-error TS(2556): A spread argument must either have a tuple type or... Remove this comment to see the full error message
return !isDom ? pathHelpers.filesystem.unixify(...arguments) : pathHelpers.url.unixify(...arguments);
},

url(file: any) {
url() {
// @ts-expect-error TS(2556): A spread argument must either have a tuple type or... Remove this comment to see the full error message
return !isDom ? pathHelpers.filesystem.url(...arguments) : pathHelpers.url.url(...arguments);
},
Expand Down

0 comments on commit 52f2697

Please sign in to comment.