diff --git a/.eslintrc b/.eslintrc index e444bb9b..522aa135 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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" } } ], diff --git a/docs/options.md b/docs/options.md index 011f9d21..df7dc3e9 100644 --- a/docs/options.md +++ b/docs/options.md @@ -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". -`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. @@ -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 -`dereference` Options -------------------- +## `dereference` Options + The `dereference` options control how JSON Schema $Ref Parser will dereference `$ref` pointers within the JSON schema. diff --git a/lib/bundle.js b/lib/bundle.js index 65b993af..bf5093ea 100644 --- a/lib/bundle.js +++ b/lib/bundle.js @@ -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); diff --git a/lib/dereference.js b/lib/dereference.js index b80789c4..23c2eef3 100644 --- a/lib/dereference.js +++ b/lib/dereference.js @@ -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 diff --git a/lib/parsers/json.js b/lib/parsers/json.js index 05beeee2..db67a47b 100644 --- a/lib/parsers/json.js +++ b/lib/parsers/json.js @@ -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)) { diff --git a/lib/parsers/yaml.js b/lib/parsers/yaml.js index cd050f38..79a7e3ea 100644 --- a/lib/parsers/yaml.js +++ b/lib/parsers/yaml.js @@ -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)) { diff --git a/lib/util/url.js b/lib/util/url.js index ecc56e77..e9938d53 100644 --- a/lib/util/url.js +++ b/lib/util/url.js @@ -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; diff --git a/test/specs/deep-circular/deep-circular.test.ts b/test/specs/deep-circular/deep-circular.test.ts index 7d9326cb..e80277a5 100644 --- a/test/specs/deep-circular/deep-circular.test.ts +++ b/test/specs/deep-circular/deep-circular.test.ts @@ -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); diff --git a/test/specs/empty/empty.test.ts b/test/specs/empty/empty.test.ts index 3a4e83c8..3f5f94b2 100644 --- a/test/specs/empty/empty.test.ts +++ b/test/specs/empty/empty.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-unused-expressions */ import { describe, it, expect, assert } from 'vitest'; import $RefParser from '../../../lib'; diff --git a/test/specs/error-source/error-source.test.ts b/test/specs/error-source/error-source.test.ts index a7569ebe..24387444 100644 --- a/test/specs/error-source/error-source.test.ts +++ b/test/specs/error-source/error-source.test.ts @@ -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'; @@ -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', diff --git a/test/specs/http.test.ts b/test/specs/http.test.ts index 97db0e27..950818f3 100644 --- a/test/specs/http.test.ts +++ b/test/specs/http.test.ts @@ -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(); diff --git a/test/specs/invalid-pointers/invalid-pointers.test.ts b/test/specs/invalid-pointers/invalid-pointers.test.ts index 14dafef8..179a4459 100644 --- a/test/specs/invalid-pointers/invalid-pointers.test.ts +++ b/test/specs/invalid-pointers/invalid-pointers.test.ts @@ -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', () => { diff --git a/test/specs/resolvers/resolvers.test.ts b/test/specs/resolvers/resolvers.test.ts index 8d99bc10..84a3f42f 100644 --- a/test/specs/resolvers/resolvers.test.ts +++ b/test/specs/resolvers/resolvers.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { describe, it, expect, assert } from 'vitest'; import $RefParser from '../../..'; @@ -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'), { diff --git a/test/specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml b/test/specs/special-characters/__({[ % & $ # @ ` ~ ,)}]__.yaml similarity index 100% rename from test/specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.yaml rename to test/specs/special-characters/__({[ % & $ # @ ` ~ ,)}]__.yaml diff --git a/test/specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.json b/test/specs/special-characters/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.json similarity index 100% rename from test/specs/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.json rename to test/specs/special-characters/__({[ % & $ # @ ` ~ ,)}]__/__({[ % & $ # @ ` ~ ,)}]__.json diff --git a/test/specs/__({[ % & $ # @ ` ~ ,)}]__/dereferenced.js b/test/specs/special-characters/dereferenced.js similarity index 100% rename from test/specs/__({[ % & $ # @ ` ~ ,)}]__/dereferenced.js rename to test/specs/special-characters/dereferenced.js diff --git a/test/specs/__({[ % & $ # @ ` ~ ,)}]__/parsed.js b/test/specs/special-characters/parsed.js similarity index 100% rename from test/specs/__({[ % & $ # @ ` ~ ,)}]__/parsed.js rename to test/specs/special-characters/parsed.js diff --git a/test/specs/__({[ % & $ # @ ` ~ ,)}]__/special-characters.test.ts b/test/specs/special-characters/special-characters.test.ts similarity index 100% rename from test/specs/__({[ % & $ # @ ` ~ ,)}]__/special-characters.test.ts rename to test/specs/special-characters/special-characters.test.ts diff --git a/test/utils/helper.ts b/test/utils/helper.ts index 2a79c7b2..dfe5545c 100644 --- a/test/utils/helper.ts +++ b/test/utils/helper.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ /* eslint-disable no-param-reassign */ import { host } from '@jsdevtools/host-environment'; import { expect } from 'chai'; diff --git a/vitest.config.mts b/vitest.config.mts index 0d925f4f..660d8b9e 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -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',