CODEBASE: Fix lint errors 3 (#1758)

This is a really big refactor because it actually *fixes* a lot of the lint errors instead of disabling them.
This commit is contained in:
catloversg
2024-11-14 23:18:57 +07:00
committed by GitHub
parent 97ca8c5f5e
commit 75cf9c88b5
31 changed files with 187 additions and 51 deletions
+12 -1
View File
@@ -1,3 +1,4 @@
import { arrayAssert } from "../utils/helpers/typeAssertion";
import type { IReviverValue } from "../utils/JSONReviver";
// Versions of js builtin classes that can be converted to and from JSON for use in save files
@@ -6,6 +7,7 @@ export class JSONSet<T> extends Set<T> {
return { ctor: "JSONSet", data: Array.from(this) };
}
static fromJSON(value: IReviverValue): JSONSet<any> {
arrayAssert(value.data);
return new JSONSet(value.data);
}
}
@@ -16,6 +18,15 @@ export class JSONMap<K, __V> extends Map<K, __V> {
}
static fromJSON(value: IReviverValue): JSONMap<any, any> {
return new JSONMap(value.data);
arrayAssert(value.data);
for (const item of value.data) {
arrayAssert(item);
if (item.length !== 2) {
console.error("Invalid data passed to JSONMap.fromJSON(). Value:", value);
throw new Error(`An item is not an array with exactly 2 items. Its length is ${item.length}.`);
}
}
// We validated the data above, so it's safe to typecast here.
return new JSONMap(value.data as [unknown, unknown][]);
}
}