mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-03 06:17:04 +02:00
CODEBASE: Expand lint rules, and Aliases are stored as maps (#501)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { Truthy } from "lodash";
|
||||
|
||||
/**
|
||||
* Returns the input array as a comma separated string.
|
||||
*
|
||||
@@ -19,3 +21,7 @@ export function arrayToString(a: unknown[]): string {
|
||||
|
||||
return `[${vals.join(", ")}]`;
|
||||
}
|
||||
|
||||
export function FilterTruthy<T>(input: T[]): Truthy<T>[] {
|
||||
return input.filter(Boolean) as Truthy<T>[];
|
||||
}
|
||||
@@ -18,6 +18,5 @@ export function addOffset(midpoint: number, percentage: number): number {
|
||||
const offset: number = midpoint * (percentage / maxPercent);
|
||||
|
||||
// Double the range to account for both sides of the midpoint.
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
return midpoint + (Math.random() * (offset * 2) - offset);
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Clears defined properties from an object.
|
||||
* Does not delete up the prototype chain.
|
||||
* @deprecated Look into using `Map` or `Set` rather than manipulating properties on an Object.
|
||||
* @param obj the object to clear all properties
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
export function clearObject(obj: unknown): void {
|
||||
if (typeof obj !== "object" || obj === null || obj === undefined) return;
|
||||
const o = obj as Record<string, unknown>;
|
||||
for (const key of Object.getOwnPropertyNames(o)) {
|
||||
if (o.hasOwnProperty(key)) {
|
||||
delete o[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ export function createProgressBarText(params: IProgressBarConfiguration): string
|
||||
totalTicks: 20,
|
||||
};
|
||||
|
||||
// tslint:disable-next-line:prefer-object-spread
|
||||
const derived: IProgressBarConfigurationMaterialized = Object.assign({}, defaultParams, params);
|
||||
// Ensure it is 0..1
|
||||
derived.progress = Math.max(Math.min(derived.progress, 1), 0);
|
||||
|
||||
@@ -7,7 +7,7 @@ interface IError {
|
||||
|
||||
export const isIError = (v: unknown): v is IError => {
|
||||
if (typeof v !== "object" || v == null) return false;
|
||||
return v.hasOwnProperty("fileName") && v.hasOwnProperty("lineNumber");
|
||||
return Object.hasOwn(v, "fileName") && Object.hasOwn(v, "lineNumber");
|
||||
};
|
||||
|
||||
export function exceptionAlert(e: unknown): void {
|
||||
|
||||
@@ -12,6 +12,5 @@ export function isPowerOfTwo(n: number): boolean {
|
||||
}
|
||||
|
||||
// Disabling the bitwise rule because it's honestly the most efficient way to check for this.
|
||||
// tslint:disable-next-line:no-bitwise
|
||||
return (n & (n - 1)) === 0;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { ScriptFilePath } from "../../Paths/ScriptFilePath";
|
||||
// This needs to be high in the dependency graph, with few/no dependencies of
|
||||
// its own, since many key modules depend on it.
|
||||
|
||||
export type ScriptKey = string /*& { __type: "ScriptKey" }*/;
|
||||
export type ScriptKey = string & { __type: "ScriptKey" };
|
||||
|
||||
// The key used to lookup worker scripts in their map.
|
||||
export function scriptKey(path: ScriptFilePath, args: ScriptArg[]): ScriptKey {
|
||||
|
||||
@@ -11,9 +11,9 @@ export function assert<T>(
|
||||
): asserts v is T {
|
||||
try {
|
||||
assertFn(v);
|
||||
} catch (type: unknown) {
|
||||
if (typeof type !== "string") type = "unknown";
|
||||
throw msgFn(type as string);
|
||||
} catch (e) {
|
||||
const type = typeof e === "string" ? e : "unknown";
|
||||
throw msgFn(type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user