Skip to content

Commit

Permalink
fix: eslint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion committed May 24, 2024
1 parent 7c6603e commit d276112
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 67 deletions.
30 changes: 16 additions & 14 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,29 @@
// remove this.
"files": ["lib/index.d.ts"],
"rules": {
// "@typescript-eslint/consistent-indexed-object-style": "off",
// "@typescript-eslint/consistent-type-imports": "off",
// "@typescript-eslint/no-explicit-any": "off",
// "@typescript-eslint/sort-type-constituents": "off",
// "eslint-comments/no-unused-disable": "off",
// "lines-between-class-members": "off",
// "max-classes-per-file": "off",
// "quotes": "off",
// "typescript-sort-keys/interface": "off"
"@typescript-eslint/array-type": "off",
"@typescript-eslint/consistent-indexed-object-style": "off",
"@typescript-eslint/consistent-type-imports": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/sort-type-constituents": "off",
"eslint-comments/no-unused-disable": "off",
"lines-between-class-members": "off",
"max-classes-per-file": "off",
"typescript-sort-keys/interface": "off",
"unicorn/custom-error-definition": "off"
}
},
{
// These can all get removed when the library is moved over to native TS.
"files": ["*.js"],
"rules": {
// "@typescript-eslint/no-this-alias": "off",
// "@typescript-eslint/no-unused-vars": "off",
// "@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-shadow": "off",
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "off",
// "eslint-comments/no-unused-disable": "off",
// "func-names": "off"
"func-names": "off",
"no-unused-expressions": "off"
}
}
],
Expand Down
8 changes: 4 additions & 4 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ JSON Schema $Ref Parser comes with built-in JSON, YAML, plain-text, and binary p
|`text.encoding`|`string` |The encoding to use when parsing text-based files. The default is "utf8".
<!-- prettier-ignore-end -->

`resolve` Options
-------------------
## `resolve` Options

The `resolve` options control how JSON Schema $Ref Parser will resolve file paths and URLs, and how those files will be read/downloaded.

JSON Schema $Ref Parser comes with built-in support for HTTP and HTTPS, as well as support for local files (when running in Node.js). You can configure or disable either of these built-in resolvers. You can also add [your own custom resolvers](plugins/resolvers.md) if you want.
Expand All @@ -67,8 +67,8 @@ JSON Schema $Ref Parser comes with built-in support for HTTP and HTTPS, as well
|`http.withCredentials`|`boolean`|Set this to `true` if you're downloading files from a CORS-enabled server that requires authentication
<!-- prettier-ignore-end -->

`dereference` Options
-------------------
## `dereference` Options

The `dereference` options control how JSON Schema $Ref Parser will dereference `$ref` pointers within the JSON schema.

<!-- prettier-ignore-start -->
Expand Down
1 change: 0 additions & 1 deletion lib/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ function crawl(parent, key, path, pathFromRoot, indirections, inventory, $refs,
return a.length - b.length;
});

// eslint-disable-next-line no-shadow
for (const key of keys) {
const keyPath = Pointer.join(path, key);
const keyPathFromRoot = Pointer.join(pathFromRoot, key);
Expand Down
1 change: 0 additions & 1 deletion lib/dereference.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ function dereference$Ref($ref, path, pathFromRoot, parents, processedObjects, de
// Check for circular references
const directCircular = pointer.circular;
let circular = directCircular || parents.has(pointer.value);
// eslint-disable-next-line chai-friendly/no-unused-expressions
circular && foundCircularReference(path, $refs, options);

// Dereference the JSON reference
Expand Down
1 change: 0 additions & 1 deletion lib/parsers/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ module.exports = {
* @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
* @returns {Promise}
*/
// eslint-disable-next-line require-await
async parse(file) {
let data = file.data;
if (Buffer.isBuffer(data)) {
Expand Down
1 change: 0 additions & 1 deletion lib/parsers/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ module.exports = {
* @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
* @returns {Promise}
*/
// eslint-disable-next-line require-await
async parse(file) {
let data = file.data;
if (Buffer.isBuffer(data)) {
Expand Down
13 changes: 2 additions & 11 deletions lib/util/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,10 @@ const jsonPointerSlash = /~1/g;
const jsonPointerTilde = /~0/g;

// RegExp patterns to URL-encode special characters in local filesystem paths
const urlEncodePatterns = [
/\?/g, '%3F',
/#/g, '%23',
];
const urlEncodePatterns = [/\?/g, '%3F', /#/g, '%23'];

// RegExp patterns to URL-decode special characters for local filesystem paths
const urlDecodePatterns = [
/%23/g, '#',
/%24/g, '$',
/%26/g, '&',
/%2C/g, ',',
/%40/g, '@',
];
const urlDecodePatterns = [/%23/g, '#', /%24/g, '$', /%26/g, '&', /%2C/g, ',', /%40/g, '@'];

exports.parse = require('url').parse;
exports.resolve = require('url').resolve;
Expand Down
2 changes: 1 addition & 1 deletion test/specs/deep-circular/deep-circular.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Schema with deeply-nested circular $refs', () => {
await parser.dereference(path.rel('specs/deep-circular/deep-circular.yaml'), {
dereference: { circular: false },
});
assert.fail()
assert.fail();
} catch (err) {
// A ReferenceError should have been thrown
expect(err).to.be.an.instanceOf(ReferenceError);
Expand Down
1 change: 1 addition & 0 deletions test/specs/empty/empty.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-unused-expressions */
import { describe, it, expect, assert } from 'vitest';

import $RefParser from '../../../lib';
Expand Down
37 changes: 20 additions & 17 deletions test/specs/error-source/error-source.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { host } from '@jsdevtools/host-environment';
import { describe, it, expect, assert } from 'vitest'
import { describe, it, expect, assert } from 'vitest';

import $RefParser from '../../..';
import { InvalidPointerError, ResolverError, MissingPointerError } from '../../../lib/util/errors';
Expand All @@ -26,22 +26,25 @@ describe('Report correct error source and path for', () => {
}
});

it.skipIf(shouldSkipWindows)('schema with a local reference pointing at property with broken external reference', async () => {
const parser = new $RefParser();
try {
await parser.dereference(path.abs('specs/error-source/broken-external.json'), { continueOnError: true });
assert.fail();
} catch (err) {
expect(err.errors).to.containSubset([
{
name: ResolverError.name,
source: path.unixify(path.abs('specs/error-source/broken-external.json')),
path: ['components', 'schemas', 'testSchema', 'properties', 'test'],
message: message => typeof message === 'string',
},
]);
}
});
it.skipIf(shouldSkipWindows)(
'schema with a local reference pointing at property with broken external reference',
async () => {
const parser = new $RefParser();
try {
await parser.dereference(path.abs('specs/error-source/broken-external.json'), { continueOnError: true });
assert.fail();
} catch (err) {
expect(err.errors).to.containSubset([
{
name: ResolverError.name,
source: path.unixify(path.abs('specs/error-source/broken-external.json')),
path: ['components', 'schemas', 'testSchema', 'properties', 'test'],
message: message => typeof message === 'string',
},
]);
}
},
);

it.skipIf(shouldSkipWindows)(
'schema with a missing local pointer and reference pointing at external file with broken external',
Expand Down
3 changes: 2 additions & 1 deletion test/specs/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ describe('HTTP options', () => {

// 2020-07-08 - The HTTPBin redirect endpoints are suddenly returning 404 errors. Not sure why 🤷‍♂️
// TODO: Re-enable these tests once HTTPBin is working again
describe.skip('http.redirect', { timeout: 30000}, () => {
// eslint-disable-next-line vitest/no-disabled-tests
describe.skip('http.redirect', { timeout: 30000 }, () => {
it('should follow 5 redirects by default', async () => {
const parser = new $RefParser();

Expand Down
2 changes: 1 addition & 1 deletion test/specs/invalid-pointers/invalid-pointers.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect, assert } from 'vitest';

import $RefParser from '../../../lib';
import { JSONParserErrorGroup, InvalidPointerError } from '../../../lib/util/errors';
import { InvalidPointerError } from '../../../lib/util/errors';
import path from '../../utils/path';

describe('Schema with invalid pointers', () => {
Expand Down
25 changes: 12 additions & 13 deletions test/specs/resolvers/resolvers.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { describe, it, expect, assert } from 'vitest';

import $RefParser from '../../..';
Expand Down Expand Up @@ -68,22 +69,20 @@ describe('options.resolve', function () {
expect(schema).to.deep.equal(dereferencedSchema);
});

if (typeof Promise === 'function') {
it('should use a custom resolver that returns a promise', async function () {
const schema = await $RefParser.dereference(path.abs('specs/resolvers/resolvers.yaml'), {
resolve: {
// A custom resolver for "foo://" URLs
foo: {
canRead: /^foo:\/\//i,
read(_file) {
return Promise.resolve({ bar: { baz: 'hello world' } });
},
it('should use a custom resolver that returns a promise', async function () {
const schema = await $RefParser.dereference(path.abs('specs/resolvers/resolvers.yaml'), {
resolve: {
// A custom resolver for "foo://" URLs
foo: {
canRead: /^foo:\/\//i,
read(_file) {
return Promise.resolve({ bar: { baz: 'hello world' } });
},
},
});
expect(schema).to.deep.equal(dereferencedSchema);
},
});
}
expect(schema).to.deep.equal(dereferencedSchema);
});

it('should continue resolving if a custom resolver fails', async function () {
const schema = await $RefParser.dereference(path.abs('specs/resolvers/resolvers.yaml'), {
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions test/utils/helper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
/* eslint-disable no-param-reassign */
import { host } from '@jsdevtools/host-environment';
import { expect } from 'chai';
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
'**/node_modules/**',

// Vitest doesn't support directories with special characters in them.
'**/__\\(\\{\\[\\ %\\ \\&\\ \\$\\ \\#\\ @\\ \\`\\ \\~\\ ,\\)\\}\\]__/**',
'**/special-characters/**',

// This test is better served by native TS typings. Ignoring until we have those.
'**/typescript-definition.spec.ts',
Expand Down

0 comments on commit d276112

Please sign in to comment.