mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-27 19:37:07 +02:00
lint fixes
This commit is contained in:
@@ -5,11 +5,12 @@
|
||||
* @param obj the object to clear all properties
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
export function clearObject(obj: any): void {
|
||||
for (const key in obj) {
|
||||
export function clearObject(obj: unknown): void {
|
||||
if (typeof obj !== "object" || obj === null || obj === undefined) return;
|
||||
for (const key of Object.getOwnPropertyNames(obj)) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
// tslint:disable-next-line:no-dynamic-delete
|
||||
delete obj[key];
|
||||
delete (obj as any)[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,18 +9,18 @@ export function compareArrays<T>(a1: T[], a2: T[]): boolean {
|
||||
}
|
||||
|
||||
for (let i = 0; i < a1.length; ++i) {
|
||||
if (Array.isArray(a1[i])) {
|
||||
const v1 = a1[i];
|
||||
const v2 = a2[i];
|
||||
if (Array.isArray(v1)) {
|
||||
// If the other element is not an array, then these cannot be equal
|
||||
if (!Array.isArray(a2[i])) {
|
||||
if (!Array.isArray(v2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const elem1 = a1[i] as any;
|
||||
const elem2 = a2[i] as any;
|
||||
if (!compareArrays(elem1, elem2)) {
|
||||
if (!compareArrays(v1, v2)) {
|
||||
return false;
|
||||
}
|
||||
} else if (a1[i] !== a2[i] && !(Number.isNaN(a1[i]) && Number.isNaN(a2[i]))) {
|
||||
} else if (v1 !== v2 && !(Number.isNaN(v1) && Number.isNaN(v2))) {
|
||||
// strict (in)equality considers NaN not equal to itself
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7,15 +7,25 @@ interface IError {
|
||||
|
||||
export function exceptionAlert(e: IError | string): void {
|
||||
console.error(e);
|
||||
let msg = "";
|
||||
let file = "UNKNOWN FILE NAME";
|
||||
let line = "UNKNOWN LINE NUMBER";
|
||||
const isError = (e: IError | string): e is IError => e.hasOwnProperty("fileName");
|
||||
if (isError(e)) {
|
||||
file = e.fileName ?? file;
|
||||
line = e.lineNumber?.toString() ?? line;
|
||||
} else {
|
||||
msg = e;
|
||||
}
|
||||
dialogBoxCreate(
|
||||
"Caught an exception: " +
|
||||
e +
|
||||
msg +
|
||||
"<br><br>" +
|
||||
"Filename: " +
|
||||
((e as any).fileName || "UNKNOWN FILE NAME") +
|
||||
file +
|
||||
"<br><br>" +
|
||||
"Line Number: " +
|
||||
((e as any).lineNumber || "UNKNOWN LINE NUMBER") +
|
||||
line +
|
||||
"<br><br>" +
|
||||
"This is a bug, please report to game developer with this " +
|
||||
"message as well as details about how to reproduce the bug.<br><br>" +
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
export function isArray(arr: unknown): arr is unknown[] {
|
||||
return Array.isArray(arr);
|
||||
}
|
||||
|
||||
// Checks whether an array is a 2D array.
|
||||
// For this, a 2D array is an array which contains only other arrays.
|
||||
// If one element in the array is a number or string, it is NOT a 2D array
|
||||
export function is2DArray(arr: any[]): boolean {
|
||||
if (arr.constructor !== Array) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return arr.every((e) => {
|
||||
return e.constructor === Array;
|
||||
});
|
||||
export function is2DArray(arr: unknown): arr is unknown[][] {
|
||||
return isArray(arr) && arr.every((u) => isArray(u));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user