mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 22:38:34 +02:00
CODEBASE: Fix lint errors 1 (#1732)
This commit is contained in:
@@ -99,13 +99,13 @@ export function handleUnknownError(e: unknown, ws: WorkerScript | null = null, i
|
||||
Error has been logged to the console.\n\nType of error: ${typeof e}\nValue of error: ${e}`;
|
||||
e = ws ? basicErrorMessage(ws, msg, "UNKNOWN") : msg;
|
||||
}
|
||||
dialogBoxCreate(initialText + e);
|
||||
dialogBoxCreate(initialText + String(e));
|
||||
}
|
||||
|
||||
/** Use this handler to handle the error when we call getSaveData function */
|
||||
export function handleGetSaveDataError(error: unknown) {
|
||||
/** Use this handler to handle the error when we call getSaveData function or getSaveInfo function */
|
||||
export function handleGetSaveDataInfoError(error: unknown, fromGetSaveInfo = false) {
|
||||
console.error(error);
|
||||
let errorMessage = `Cannot get save data. Error: ${error}.`;
|
||||
let errorMessage = `Cannot get save ${fromGetSaveInfo ? "info" : "data"}. Error: ${error}.`;
|
||||
if (error instanceof RangeError) {
|
||||
errorMessage += " This may be because the save data is too large.";
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ function spawnOptions(ctx: NetscriptContext, threadOrOption: unknown): CompleteS
|
||||
function mapToString(map: Map<unknown, unknown>): string {
|
||||
const formattedMap = [...map]
|
||||
.map((m) => {
|
||||
return `${m[0]} => ${m[1]}`;
|
||||
return `${String(m[0])} => ${String(m[1])}`;
|
||||
})
|
||||
.join("; ");
|
||||
return `< Map: ${formattedMap} >`;
|
||||
@@ -245,7 +245,7 @@ function setToString(set: Set<unknown>): string {
|
||||
/** Convert multiple arguments for tprint or print into a single string. */
|
||||
function argsToString(args: unknown[]): string {
|
||||
// Reduce array of args into a single output string
|
||||
return args.reduce((out, arg) => {
|
||||
return args.reduce((out: string, arg) => {
|
||||
if (arg === null) {
|
||||
return (out += "null");
|
||||
}
|
||||
@@ -264,12 +264,13 @@ function argsToString(args: unknown[]): string {
|
||||
return (out += setToString(nativeArg));
|
||||
}
|
||||
if (typeof nativeArg === "object") {
|
||||
return (out += JSON.stringify(nativeArg, (_, value) => {
|
||||
return (out += JSON.stringify(nativeArg, (_, value: unknown) => {
|
||||
/**
|
||||
* If the property is a promise, we will return a string that clearly states that it's a promise object, not a
|
||||
* normal object. If we don't do that, all promises will be serialized into "{}".
|
||||
*/
|
||||
if (value instanceof Promise) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-base-to-string -- "[object Promise]" is exactly the string that we want.
|
||||
return value.toString();
|
||||
}
|
||||
if (value instanceof Map) {
|
||||
@@ -282,8 +283,8 @@ function argsToString(args: unknown[]): string {
|
||||
}));
|
||||
}
|
||||
|
||||
return (out += `${nativeArg}`);
|
||||
}, "") as string;
|
||||
return (out += String(nativeArg));
|
||||
}, "");
|
||||
}
|
||||
|
||||
function validateHGWOptions(ctx: NetscriptContext, opts: unknown): CompleteHGWOptions {
|
||||
@@ -296,6 +297,7 @@ function validateHGWOptions(ctx: NetscriptContext, opts: unknown): CompleteHGWOp
|
||||
return result;
|
||||
}
|
||||
if (typeof opts !== "object") {
|
||||
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
||||
throw errorMessage(ctx, `BasicHGWOptions must be an object if specified, was ${opts}`);
|
||||
}
|
||||
// Safe assertion since threadOrOption type has been narrowed to a non-null object
|
||||
@@ -723,7 +725,7 @@ function createPublicRunningScript(runningScript: RunningScript, workerScript?:
|
||||
args: runningScript.args.slice(),
|
||||
dynamicRamUsage: workerScript && roundToTwo(workerScript.dynamicRamUsage),
|
||||
filename: runningScript.filename,
|
||||
logs: runningScript.logs.map((x) => "" + x),
|
||||
logs: runningScript.logs.map((x) => String(x)),
|
||||
offlineExpGained: runningScript.offlineExpGained,
|
||||
offlineMoneyMade: runningScript.offlineMoneyMade,
|
||||
offlineRunningTime: runningScript.offlineRunningTime,
|
||||
@@ -782,13 +784,21 @@ function validateBitNodeOptions(ctx: NetscriptContext, bitNodeOptions: unknown):
|
||||
return result;
|
||||
}
|
||||
if (typeof bitNodeOptions !== "object") {
|
||||
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
||||
throw errorMessage(ctx, `bitNodeOptions must be an object if it's specified. It was ${bitNodeOptions}.`);
|
||||
}
|
||||
const options = bitNodeOptions as Unknownify<BitNodeOptions>;
|
||||
if (!(options.sourceFileOverrides instanceof Map)) {
|
||||
throw errorMessage(ctx, `sourceFileOverrides must be a Map.`);
|
||||
}
|
||||
const validationResultForSourceFileOverrides = validateSourceFileOverrides(options.sourceFileOverrides, true);
|
||||
const validationResultForSourceFileOverrides = validateSourceFileOverrides(
|
||||
/**
|
||||
* Cast the type from Map<any, any> to Map<number, number> to satisfy the lint rule. The validation logic in
|
||||
* validateSourceFileOverrides will check the data.
|
||||
*/
|
||||
options.sourceFileOverrides as Map<number, number>,
|
||||
true,
|
||||
);
|
||||
if (!validationResultForSourceFileOverrides.valid) {
|
||||
throw errorMessage(
|
||||
ctx,
|
||||
|
||||
Reference in New Issue
Block a user