mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-22 17:23:00 +02:00
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:
@@ -3,6 +3,7 @@ import { toNative } from "./toNative";
|
||||
import libarg from "arg";
|
||||
import { NetscriptContext } from "../Netscript/APIWrapper";
|
||||
|
||||
export type Schema = [string, string | number | boolean | string[]][];
|
||||
type FlagType = StringConstructor | NumberConstructor | BooleanConstructor | StringConstructor[];
|
||||
type FlagsRet = Record<string, ScriptArg | string[]>;
|
||||
export function Flags(ctx: NetscriptContext | string[]): (data: unknown) => FlagsRet {
|
||||
@@ -12,7 +13,7 @@ export function Flags(ctx: NetscriptContext | string[]): (data: unknown) => Flag
|
||||
if (!Array.isArray(schema)) throw new Error("flags schema passed in is invalid.");
|
||||
const args: Record<string, FlagType> = {};
|
||||
|
||||
for (const d of schema) {
|
||||
for (const d of schema as Schema) {
|
||||
let t: FlagType = String;
|
||||
if (typeof d[1] === "number") {
|
||||
t = Number;
|
||||
@@ -24,13 +25,15 @@ export function Flags(ctx: NetscriptContext | string[]): (data: unknown) => Flag
|
||||
const numDashes = d[0].length > 1 ? 2 : 1;
|
||||
args["-".repeat(numDashes) + d[0]] = t;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
|
||||
const ret: FlagsRet = libarg(args, { argv: vargs });
|
||||
for (const d of schema) {
|
||||
for (const d of schema as Schema) {
|
||||
if (!Object.hasOwn(ret, "--" + d[0]) || !Object.hasOwn(ret, "-" + d[0])) ret[d[0]] = d[1];
|
||||
}
|
||||
for (const key of Object.keys(ret)) {
|
||||
if (!key.startsWith("-")) continue;
|
||||
const value = ret[key];
|
||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||
delete ret[key];
|
||||
const numDashes = key.length === 2 ? 1 : 2;
|
||||
ret[key.slice(numDashes)] = value;
|
||||
|
||||
Reference in New Issue
Block a user