CODEBASE: Expand lint rules, and Aliases are stored as maps (#501)

This commit is contained in:
Snarling
2023-05-05 03:55:59 -04:00
committed by GitHub
parent d25254caf1
commit ebae35b1fb
202 changed files with 905 additions and 1110 deletions
+1 -1
View File
@@ -186,7 +186,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
}
function hasResearched(division: Industry, researchName: CorpResearchName): boolean {
return division.researched[researchName] === undefined ? false : (division.researched[researchName] as boolean);
return division.researched[researchName] ?? false;
}
function bribe(factionName: string, amountCash: number): boolean {
+7 -5
View File
@@ -8,7 +8,7 @@ import { helpers } from "../Netscript/NetscriptHelpers";
import { Terminal } from "../Terminal";
import { RamCostConstants } from "../Netscript/RamCostGenerator";
export type INetscriptExtra = {
export interface INetscriptExtra {
heart: {
break(): number;
};
@@ -19,7 +19,7 @@ export type INetscriptExtra = {
rainbow(guess: string): void;
iKnowWhatImDoing(): void;
printRaw(value: React.ReactNode): void;
};
}
export function NetscriptExtra(): InternalAPI<INetscriptExtra> {
return {
@@ -30,7 +30,9 @@ export function NetscriptExtra(): InternalAPI<INetscriptExtra> {
exploit: () => () => Player.giveExploit(Exploit.UndocumentedFunctionCall),
bypass: (ctx) => (doc) => {
// reset both fields first
type temporary = { completely_unused_field: unknown };
interface temporary {
completely_unused_field: unknown;
}
const d = doc as temporary;
d.completely_unused_field = undefined;
const real_document = document as unknown as temporary;
@@ -53,7 +55,7 @@ export function NetscriptExtra(): InternalAPI<INetscriptExtra> {
};
recur(2);
console.warn("I am sure that this variable is false.");
if (x !== false) {
if (x) {
console.warn("Reality has been altered!");
Player.giveExploit(Exploit.RealityAlteration);
}
@@ -67,7 +69,7 @@ export function NetscriptExtra(): InternalAPI<INetscriptExtra> {
},
iKnowWhatImDoing: (ctx) => () => {
helpers.log(ctx, () => "Unlocking unsupported feature: window.tprintRaw");
// @ts-ignore window has no tprintRaw property defined
// @ts-expect-error window has no tprintRaw property defined
window.tprintRaw = Terminal.printRaw.bind(Terminal);
},
printRaw: (ctx) => (value) => {
+3 -5
View File
@@ -4,15 +4,13 @@ import { ScriptArg } from "../Netscript/ScriptArg";
import { NetscriptContext } from "../Netscript/APIWrapper";
type FlagType = StringConstructor | NumberConstructor | BooleanConstructor | StringConstructor[];
type FlagsRet = { [key: string]: ScriptArg | string[] };
type FlagsRet = Record<string, ScriptArg | string[]>;
export function Flags(ctx: NetscriptContext | string[]): (data: unknown) => FlagsRet {
const vargs = Array.isArray(ctx) ? ctx : ctx.workerScript.args;
return (schema: unknown): FlagsRet => {
schema = toNative(schema);
if (!Array.isArray(schema)) throw new Error("flags schema passed in is invalid.");
const args: {
[key: string]: FlagType;
} = {};
const args: Record<string, FlagType> = {};
for (const d of schema) {
let t: FlagType = String;
@@ -28,7 +26,7 @@ export function Flags(ctx: NetscriptContext | string[]): (data: unknown) => Flag
}
const ret: FlagsRet = libarg(args, { argv: vargs });
for (const d of schema) {
if (!ret.hasOwnProperty("--" + d[0]) || !ret.hasOwnProperty("-" + d[0])) ret[d[0]] = d[1];
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;
+4 -3
View File
@@ -10,6 +10,7 @@ import { Router } from "../ui/GameRoot";
import { Page } from "../ui/Router";
import { GraftingWork } from "../Work/GraftingWork";
import { helpers } from "../Netscript/NetscriptHelpers";
import { augmentationExists } from "../Augmentation/AugmentationHelpers";
export function NetscriptGrafting(): InternalAPI<IGrafting> {
const checkGraftingAPIAccess = (ctx: NetscriptContext): void => {
@@ -25,7 +26,7 @@ export function NetscriptGrafting(): InternalAPI<IGrafting> {
getAugmentationGraftPrice: (ctx) => (_augName) => {
const augName = helpers.string(ctx, "augName", _augName);
checkGraftingAPIAccess(ctx);
if (!getGraftingAvailableAugs().includes(augName) || !StaticAugmentations.hasOwnProperty(augName)) {
if (!getGraftingAvailableAugs().includes(augName) || augmentationExists(augName)) {
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid aug: ${augName}`);
}
const graftableAug = new GraftableAugmentation(StaticAugmentations[augName]);
@@ -35,7 +36,7 @@ export function NetscriptGrafting(): InternalAPI<IGrafting> {
getAugmentationGraftTime: (ctx) => (_augName) => {
const augName = helpers.string(ctx, "augName", _augName);
checkGraftingAPIAccess(ctx);
if (!getGraftingAvailableAugs().includes(augName) || !StaticAugmentations.hasOwnProperty(augName)) {
if (!getGraftingAvailableAugs().includes(augName) || !augmentationExists(augName)) {
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid aug: ${augName}`);
}
const graftableAug = new GraftableAugmentation(StaticAugmentations[augName]);
@@ -57,7 +58,7 @@ export function NetscriptGrafting(): InternalAPI<IGrafting> {
if (player.city !== CityName.NewTokyo) {
throw helpers.makeRuntimeErrorMsg(ctx, "You must be in New Tokyo to begin grafting an Augmentation.");
}
if (!getGraftingAvailableAugs().includes(augName) || !StaticAugmentations.hasOwnProperty(augName)) {
if (!getGraftingAvailableAugs().includes(augName) || !augmentationExists(augName)) {
helpers.log(ctx, () => `Invalid aug: ${augName}`);
return false;
}
+11 -7
View File
@@ -11,8 +11,9 @@ import { FactionNames } from "../Faction/data/FactionNames";
import { Factions } from "../Faction/Factions";
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
import { checkEnum } from "../utils/helpers/enum";
import { CityName, LocationName } from "../Enums";
import { LocationName } from "../Enums";
import { helpers } from "../Netscript/NetscriptHelpers";
import { FilterTruthy } from "../utils/helpers/ArrayHelpers";
export function NetscriptInfiltration(): InternalAPI<IInfiltration> {
const getLocationsWithInfiltrations = Object.values(Locations).filter(
@@ -41,12 +42,15 @@ export function NetscriptInfiltration(): InternalAPI<IInfiltration> {
};
return {
getPossibleLocations: () => () => {
return getLocationsWithInfiltrations
.filter((l) => l.city) //Guarantees no locations with a "null" entry, which should not be infiltratable anyway.
.map((l) => ({
city: l.city as CityName,
name: l.name,
}));
return FilterTruthy(
getLocationsWithInfiltrations.map((l) => {
if (!l.city) return false;
return {
city: l.city,
name: l.name,
};
}),
);
},
getInfiltration: (ctx) => (_location) => {
const location = helpers.string(ctx, "location", _location);
+1 -1
View File
@@ -693,7 +693,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
return Object.entries(CompanyPositions)
.filter((_position) => Companies[companyName].hasPosition(_position[0]))
.map((_position) => _position[1]["name"]);
.map((_position) => _position[1].name);
},
getCompanyPositionInfo: (ctx) => (_companyName, _positionName) => {
helpers.checkSingularityAccess(ctx);
+1 -1
View File
@@ -305,7 +305,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
const orders: StockOrder = {};
const stockMarketOrders = StockMarket["Orders"];
const stockMarketOrders = StockMarket.Orders;
for (const symbol of Object.keys(stockMarketOrders)) {
const orderBook = stockMarketOrders[symbol];
if (orderBook.constructor === Array && orderBook.length > 0) {
+1 -1
View File
@@ -86,7 +86,7 @@ export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
getGameInfo: () => () => {
const version = CONSTANTS.VersionString;
const commit = hash();
const platform = navigator.userAgent.toLowerCase().indexOf(" electron/") > -1 ? "Steam" : "Browser";
const platform = navigator.userAgent.toLowerCase().includes(" electron/") ? "Steam" : "Browser";
const gameInfo = {
version,
+5 -5
View File
@@ -10,10 +10,10 @@ interface PseudoObject {
const isPseudoObject = (v: unknown): v is PseudoObject =>
!!v &&
typeof v === "object" &&
v.hasOwnProperty("properties") &&
v.hasOwnProperty("getter") &&
v.hasOwnProperty("setter") &&
v.hasOwnProperty("proto");
Object.hasOwn(v, "properties") &&
Object.hasOwn(v, "getter") &&
Object.hasOwn(v, "setter") &&
Object.hasOwn(v, "proto");
// the acorn interpreter has a bug where it doesn't convert arrays correctly.
// so we have to more or less copy it here.
@@ -23,7 +23,7 @@ export function toNative(pseudoObj: unknown): unknown {
return pseudoObj; // it wasn't a pseudo object anyway.
}
if (pseudoObj.hasOwnProperty("class") && pseudoObj.class === "Array") {
if (Object.hasOwn(pseudoObj, "class") && pseudoObj.class === "Array") {
const arr: unknown[] = [];
const length = defaultInterpreter.getProperty(pseudoObj, "length");
if (typeof length === "number") {