Skip to content

Commit 0c2cea3

Browse files
committed
Break out of loop to allow result object to be updated after failing fast
1 parent 3f1e4da commit 0c2cea3

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

lib/entry-points.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/json/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,16 @@ export function checkSchema<S extends Schema>(
264264
path: string = "",
265265
): CheckSchemaResult {
266266
const result: CheckSchemaResult = successfulCheckSchema();
267+
268+
// Track the set of input keys. We remove keys from this set as we recognise them
269+
// during validation.
267270
const inputKeys = new Set(Object.keys(obj));
271+
272+
// Track keys that have failed validation, starting with the empty set.
268273
const invalidKeys = new Set();
269274

275+
// Loop through all keys in the object schema and validate that the given object
276+
// satisfies the schema key.
270277
for (const [key, validator] of Object.entries(schema)) {
271278
const hasKey = key in obj;
272279

@@ -282,7 +289,7 @@ export function checkSchema<S extends Schema>(
282289
result.valid = false;
283290

284291
if (options.failFast) {
285-
return result;
292+
break;
286293
}
287294
continue;
288295
}
@@ -292,7 +299,7 @@ export function checkSchema<S extends Schema>(
292299
result.valid = false;
293300

294301
if (options.failFast) {
295-
return result;
302+
break;
296303
}
297304
continue;
298305
}
@@ -314,7 +321,7 @@ export function checkSchema<S extends Schema>(
314321
result.valid = false;
315322

316323
if (options.failFast) {
317-
return result;
324+
break;
318325
}
319326
continue;
320327
}

0 commit comments

Comments
 (0)