Skip to content

Commit 25210c2

Browse files
committed
Appease the incredibly picky deno linter
1 parent 9e34db6 commit 25210c2

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

typescript/packages/toolshed/lib/schema-match.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
import { Schema, Validator } from "jsonschema";
22

3+
function checkSubtrees(
4+
obj: unknown,
5+
validator: Validator,
6+
jsonSchema: Schema,
7+
): boolean {
8+
try {
9+
if (typeof obj !== "object" || obj === null) {
10+
return false;
11+
}
12+
13+
if (Array.isArray(obj)) {
14+
return obj.some((item) => checkSubtrees(item, validator, jsonSchema));
15+
}
16+
17+
const result = validator.validate(obj, jsonSchema);
18+
if (result.valid) {
19+
return true;
20+
}
21+
22+
return Object.values(obj).some((value) =>
23+
checkSubtrees(value, validator, jsonSchema)
24+
);
25+
} catch (err) {
26+
console.error("Error checking subtrees:", err);
27+
return false;
28+
}
29+
}
30+
331
export function checkSchemaMatch(
432
data: Record<string, unknown>,
533
schema: Schema,
@@ -38,29 +66,7 @@ export function checkSchemaMatch(
3866
return false;
3967
}
4068

41-
function checkSubtrees(obj: unknown): boolean {
42-
try {
43-
if (typeof obj !== "object" || obj === null) {
44-
return false;
45-
}
46-
47-
if (Array.isArray(obj)) {
48-
return obj.some((item) => checkSubtrees(item));
49-
}
50-
51-
const result = validator.validate(obj, jsonSchema as Schema);
52-
if (result.valid) {
53-
return true;
54-
}
55-
56-
return Object.values(obj).some((value) => checkSubtrees(value));
57-
} catch (err) {
58-
console.error("Error checking subtrees:", err);
59-
return false;
60-
}
61-
}
62-
63-
return checkSubtrees(data);
69+
return checkSubtrees(data, validator, jsonSchema as Schema);
6470
} catch (err) {
6571
console.error("Top level error in checkSchemaMatch:", err);
6672
return false;

0 commit comments

Comments
 (0)