Skip to content

Commit

Permalink
Merge pull request #334 from chris48s/dependabot/npm_and_yarn/prettie…
Browse files Browse the repository at this point in the history
…r-3.0.0

Bump prettier from 2.8.8 to 3.0.0
  • Loading branch information
chris48s authored Jul 14, 2023
2 parents b955c6b + e831405 commit d235d9e
Show file tree
Hide file tree
Showing 14 changed files with 956 additions and 144 deletions.
866 changes: 839 additions & 27 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-mocha": "^10.0.3",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-prettier": "^5.0.0",
"mocha": "^10.0.0",
"mock-cwd": "^1.0.0",
"nock": "^13.0.4",
"prettier": "^2.1.2"
"prettier": "^3.0.0"
},
"engines": {
"node": ">=16"
Expand Down
4 changes: 2 additions & 2 deletions src/ajv.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function _ajvFactory(
schema,
strictMode,
cache,
resolver = (url) => cache.fetch(url)
resolver = (url) => cache.fetch(url),
) {
const opts = { allErrors: true, loadSchema: resolver, strict: strictMode };

Expand All @@ -27,7 +27,7 @@ function _ajvFactory(
} else if (schema["$schema"].includes("json-schema.org/draft-06/schema")) {
const ajvDraft06 = new Ajv(opts);
ajvDraft06.addMetaSchema(
require("ajv/lib/refs/json-schema-draft-06.json")
require("ajv/lib/refs/json-schema-draft-06.json"),
);
return ajvDraft06;
} else if (schema["$schema"].includes("json-schema.org/draft-07/schema")) {
Expand Down
32 changes: 16 additions & 16 deletions src/ajv.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,84 +15,84 @@ describe("_ajvFactory", function () {
const ajv = _ajvFactory(
{ $schema: "http://json-schema.org/draft-04/schema#" },
false,
testCache
testCache,
);
expect(ajv.schemas).to.have.own.property(
"http://json-schema.org/draft-04/schema"
"http://json-schema.org/draft-04/schema",
);
});

it("should support draft-06", function () {
const ajv = _ajvFactory(
{ $schema: "http://json-schema.org/draft-06/schema#" },
false,
testCache
testCache,
);
expect(ajv.schemas).to.have.own.property(
"http://json-schema.org/draft-06/schema"
"http://json-schema.org/draft-06/schema",
);
});

it("should support draft-07", function () {
const ajv = _ajvFactory(
{ $schema: "http://json-schema.org/draft-07/schema#" },
false,
testCache
testCache,
);
expect(ajv.schemas).to.have.own.property(
"http://json-schema.org/draft-07/schema"
"http://json-schema.org/draft-07/schema",
);
});

it("should support draft-2019-09", function () {
const ajv = _ajvFactory(
{ $schema: "https://json-schema.org/draft/2019-09/schema" },
false,
testCache
testCache,
);
expect(ajv.schemas).to.have.own.property(
"https://json-schema.org/draft/2019-09/schema"
"https://json-schema.org/draft/2019-09/schema",
);
});

it("should support draft-2020-12", function () {
const ajv = _ajvFactory(
{ $schema: "https://json-schema.org/draft/2020-12/schema" },
false,
testCache
testCache,
);
expect(ajv.schemas).to.have.own.property(
"https://json-schema.org/draft/2020-12/schema"
"https://json-schema.org/draft/2020-12/schema",
);
});

it("should fall back to draft-06/draft-07 mode if $schema key is missing", function () {
const ajv = _ajvFactory({}, false, testCache);
expect(ajv.schemas).to.have.own.property(
"http://json-schema.org/draft-06/schema"
"http://json-schema.org/draft-06/schema",
);
expect(ajv.schemas).to.have.own.property(
"http://json-schema.org/draft-07/schema"
"http://json-schema.org/draft-07/schema",
);
});

it("should fall back to draft-06/draft-07 mode if $schema key is invalid (str)", function () {
const ajv = _ajvFactory({ $schema: "foobar" }, false, testCache);
expect(ajv.schemas).to.have.own.property(
"http://json-schema.org/draft-06/schema"
"http://json-schema.org/draft-06/schema",
);
expect(ajv.schemas).to.have.own.property(
"http://json-schema.org/draft-07/schema"
"http://json-schema.org/draft-07/schema",
);
});

it("should fall back to draft-06/draft-07 mode if $schema key is invalid (not str)", function () {
const ajv = _ajvFactory({ $schema: true }, false, testCache);
expect(ajv.schemas).to.have.own.property(
"http://json-schema.org/draft-06/schema"
"http://json-schema.org/draft-06/schema",
);
expect(ajv.schemas).to.have.own.property(
"http://json-schema.org/draft-07/schema"
"http://json-schema.org/draft-07/schema",
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Cache {
this.cache.removeKey(url);
}
this.cache.save(true);
}.bind(this)
}.bind(this),
);
}

Expand All @@ -39,7 +39,7 @@ class Cache {
}
if (this.callCounter[url] > this.callLimit) {
throw new Error(
`Called ${url} >${this.callLimit} times. Possible circular reference.`
`Called ${url} >${this.callLimit} times. Possible circular reference.`,
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cache.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ describe("Cache", function () {

//..and then the third one should fail
await expect(
testCache.fetch("https://www.foobar.com/baz")
testCache.fetch("https://www.foobar.com/baz"),
).to.be.rejectedWith(
Error,
"Called https://www.foobar.com/baz >2 times. Possible circular reference."
"Called https://www.foobar.com/baz >2 times. Possible circular reference.",
);
mock.done();
});
Expand Down
10 changes: 5 additions & 5 deletions src/catalogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function getCatalogs(config) {
catalogs = catalogs.concat(
config.catalogs.map(function (loc) {
return { location: loc };
})
}),
);
}
catalogs.push({ location: SCHEMASTORE_CATALOG_URL });
Expand Down Expand Up @@ -83,7 +83,7 @@ async function getMatchForFilename(catalogs, filename, cache) {
if (!rec.catalog) {
const catalogSchema = await getFromUrlOrFile(
SCHEMASTORE_CATALOG_SCHEMA_URL,
cache
cache,
);

// Validate the catalog
Expand All @@ -92,7 +92,7 @@ async function getMatchForFilename(catalogs, filename, cache) {
catalog,
catalogSchema,
strictMode,
cache
cache,
);
if (!valid || catalog.schemas === undefined) {
throw new Error(`Malformed catalog at ${catalogLocation}`);
Expand Down Expand Up @@ -123,10 +123,10 @@ async function getMatchForFilename(catalogs, filename, cache) {
// We found >1 matches in the same catalog. This is always a hard error.
const matchesLog = getMultipleMatchesLogMessage(matches);
logger.info(
`Found multiple possible matches for ${filename}. Possible matches:\n\n${matchesLog}`
`Found multiple possible matches for ${filename}. Possible matches:\n\n${matchesLog}`,
);
throw new Error(
`Found multiple possible schemas to validate ${filename}`
`Found multiple possible schemas to validate ${filename}`,
);
}

Expand Down
22 changes: 11 additions & 11 deletions src/catalogs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ describe("getSchemaMatchesForFilename", function () {

it("returns [] when no matches found", function () {
expect(
getSchemaMatchesForFilename(schemas, "doesnt-match-anything.json")
getSchemaMatchesForFilename(schemas, "doesnt-match-anything.json"),
).to.deep.equal([]);
});

it("returns a match using globstar pattern", function () {
expect(
getSchemaMatchesForFilename(schemas, "subdir/one/two/three/file.json")
getSchemaMatchesForFilename(schemas, "subdir/one/two/three/file.json"),
).to.deep.equal([
{
url: "https://example.com/subdir-schema.json",
Expand Down Expand Up @@ -76,7 +76,7 @@ describe("getSchemaMatchesForFilename", function () {

it("returns a match if filename starts with a dot", function () {
expect(
getSchemaMatchesForFilename(schemas, ".starts-with-a-dot.json")
getSchemaMatchesForFilename(schemas, ".starts-with-a-dot.json"),
).to.deep.equal([
{
url: "https://example.com/starts-with-a-dot-schema.json",
Expand Down Expand Up @@ -124,7 +124,7 @@ describe("getMatchForFilename", function () {

it("returns a schema when one match found", async function () {
expect(
await getMatchForFilename(catalogs, "file1.json", testCache)
await getMatchForFilename(catalogs, "file1.json", testCache),
).to.deep.equal({
location: "https://example.com/files-schema-schema.json",
fileMatch: ["file1.json", "file2.json"],
Expand All @@ -133,7 +133,7 @@ describe("getMatchForFilename", function () {

it("returns a schema when match has only one version", async function () {
expect(
await getMatchForFilename(catalogs, "one-version.json", testCache)
await getMatchForFilename(catalogs, "one-version.json", testCache),
).to.deep.equal({
location: "https://example.com/v1.json",
fileMatch: ["one-version.json"],
Expand All @@ -145,22 +145,22 @@ describe("getMatchForFilename", function () {

it("throws an exception when no matches found", async function () {
await expect(
getMatchForFilename(catalogs, "doesnt-match-anything.json", testCache)
getMatchForFilename(catalogs, "doesnt-match-anything.json", testCache),
).to.be.rejectedWith(
Error,
"Could not find a schema to validate doesnt-match-anything.json"
"Could not find a schema to validate doesnt-match-anything.json",
);
});

it("throws an exception when multiple matches found", async function () {
await expect(getMatchForFilename(catalogs, "file2.json", testCache))
.to.be.rejectedWith(
Error,
"Found multiple possible schemas to validate file2.json"
"Found multiple possible schemas to validate file2.json",
)
.then(() => {
assert(
logContainsInfo("Found multiple possible matches for file2.json")
logContainsInfo("Found multiple possible matches for file2.json"),
);
assert(logContainsInfo("https://example.com/files-schema-schema.json"));
assert(logContainsInfo("https://example.com/duplicate.json"));
Expand All @@ -171,11 +171,11 @@ describe("getMatchForFilename", function () {
await expect(getMatchForFilename(catalogs, "versions.json", testCache))
.to.be.rejectedWith(
Error,
"Found multiple possible schemas to validate versions.json"
"Found multiple possible schemas to validate versions.json",
)
.then(() => {
assert(
logContainsInfo("Found multiple possible matches for versions.json")
logContainsInfo("Found multiple possible matches for versions.json"),
);
assert(logContainsInfo("https://example.com/versions-v1.json"));
assert(logContainsInfo("https://example.com/versions-v2.json"));
Expand Down
6 changes: 3 additions & 3 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ async function validateFile(filename, config, cache) {
result.schemaLocation = schemaLocation;
const schema = await getFromUrlOrFile(schemaLocation, cache);
logger.info(
`Validating ${filename} against schema from ${schemaLocation} ...`
`Validating ${filename} against schema from ${schemaLocation} ...`,
);

const data = parseFile(
await fs.promises.readFile(filename, "utf8"),
catalogMatch.parser ? `.${catalogMatch.parser}` : path.extname(filename)
catalogMatch.parser ? `.${catalogMatch.parser}` : path.extname(filename),
);

const strictMode = config.verbose >= 2 ? "log" : false;
Expand All @@ -70,7 +70,7 @@ async function validateFile(filename, config, cache) {
schema,
strictMode,
cache,
resolver
resolver,
);
result.valid = valid;
result.errors = errors;
Expand Down
Loading

0 comments on commit d235d9e

Please sign in to comment.