From 3eee163aae1d35bed6af10aa1b82c8b779336696 Mon Sep 17 00:00:00 2001 From: TheSparta Date: Tue, 31 Oct 2023 17:46:14 +0000 Subject: [PATCH] fixed lint/complexity/noForEach --- .../src/controllers/InsuranceController.ts | 32 +++++++++++-------- project/src/generators/LocationGenerator.ts | 5 ++- project/src/generators/LootGenerator.ts | 10 +++--- project/src/helpers/AssortHelper.ts | 8 ++++- project/src/helpers/InRaidHelper.ts | 10 +++--- project/src/loaders/PreAkiModLoader.ts | 9 ++++-- project/src/models/external/HttpFramework.ts | 4 +-- project/src/routers/HttpRouter.ts | 4 +-- .../src/services/BotGenerationCacheService.ts | 8 ++--- project/src/services/ProfileFixerService.ts | 8 ++--- project/src/services/RagfairOfferService.ts | 7 ++-- project/src/utils/RagfairOfferHolder.ts | 10 ++++-- project/src/utils/collections/queue/Queue.ts | 5 ++- 13 files changed, 74 insertions(+), 46 deletions(-) diff --git a/project/src/controllers/InsuranceController.ts b/project/src/controllers/InsuranceController.ts index 7f85703f..6393f9db 100644 --- a/project/src/controllers/InsuranceController.ts +++ b/project/src/controllers/InsuranceController.ts @@ -120,7 +120,7 @@ export class InsuranceController this.logger.debug(`Processing ${insuranceDetails.length} insurance packages, which includes a total of ${this.countAllInsuranceItems(insuranceDetails)} items, in profile ${sessionID}`); // Iterate over each of the insurance packages. - insuranceDetails.forEach(insured => + for (const insured of insuranceDetails) { // Find items that should be deleted from the insured items. const itemsToDelete = this.findItemsToDelete(insured); @@ -136,7 +136,7 @@ export class InsuranceController // Remove the fully processed insurance package from the profile. this.removeInsurancePackageFromProfile(sessionID, insured.messageContent.systemData); - }); + } } /** @@ -216,7 +216,10 @@ export class InsuranceController protected populateItemsMap(insured: Insurance): Map { const itemsMap = new Map(); - insured.items.forEach(item => itemsMap.set(item._id, item)); + for (const item of insured.items) + { + itemsMap.set(item._id, item); + } return itemsMap; } @@ -311,7 +314,10 @@ export class InsuranceController const allChildrenAreAttachments = directChildren.every(child => this.itemHelper.isAttachmentAttached(child)); if (allChildrenAreAttachments) { - itemAndChildren.forEach(item => toDelete.add(item._id)); + for (const item of itemAndChildren) + { + toDelete.add(item._id); + } } } } @@ -327,7 +333,7 @@ export class InsuranceController */ protected processAttachments(mainParentToAttachmentsMap: Map, itemsMap: Map, traderId: string, toDelete: Set): void { - mainParentToAttachmentsMap.forEach((attachmentItems, parentId) => + for (const [ parentId, attachmentItems ] of mainParentToAttachmentsMap) { // Log the parent item's name. const parentItem = itemsMap.get(parentId); @@ -336,7 +342,7 @@ export class InsuranceController // Process the attachments for this individual parent item. this.processAttachmentByParent(attachmentItems, traderId, toDelete); - }); + } } /** @@ -383,10 +389,10 @@ export class InsuranceController */ protected logAttachmentsDetails(attachments: EnrichedItem[]): void { - attachments.forEach(({ name, maxPrice }) => + for ( const attachment of attachments) { - this.logger.debug(`Child Item - Name: ${name}, Max Price: ${maxPrice}`); - }); + this.logger.debug(`Child Item - Name: ${attachment.name}, Max Price: ${attachment.maxPrice}`); + } } /** @@ -413,7 +419,7 @@ export class InsuranceController { const valuableToDelete = attachments.slice(0, successfulRolls).map(({ _id }) => _id); - valuableToDelete.forEach(attachmentsId => + for (const attachmentsId of valuableToDelete) { const valuableChild = attachments.find(({ _id }) => _id === attachmentsId); if (valuableChild) @@ -422,7 +428,7 @@ export class InsuranceController this.logger.debug(`Marked for removal - Child Item: ${name}, Max Price: ${maxPrice}`); toDelete.add(attachmentsId); } - }); + } } /** @@ -448,7 +454,7 @@ export class InsuranceController { const hideoutParentId = this.fetchHideoutItemParent(insured.items); - insured.items.forEach(item => + for (const item of insured.items) { // Check if the item's parent exists in the insured items list. const parentExists = insured.items.some(parentItem => parentItem._id === item.parentId); @@ -460,7 +466,7 @@ export class InsuranceController item.slotId = "hideout"; delete item.location; } - }); + } } /** diff --git a/project/src/generators/LocationGenerator.ts b/project/src/generators/LocationGenerator.ts index e8f6e9b3..5f185851 100644 --- a/project/src/generators/LocationGenerator.ts +++ b/project/src/generators/LocationGenerator.ts @@ -237,7 +237,10 @@ export class LocationGenerator // Create probability array with all possible container ids in this group and their relataive probability of spawning const containerDistribution = new ProbabilityObjectArray(this.mathUtil, this.jsonUtil); - containerIds.forEach(x => containerDistribution.push(new ProbabilityObject(x, containerData.containerIdsWithProbability[x]))); + for (const containerId of containerIds) + { + containerDistribution.push(new ProbabilityObject(containerId, containerData.containerIdsWithProbability[containerId])); + } chosenContainerIds.push(...containerDistribution.draw(containerData.chosenCount)); diff --git a/project/src/generators/LootGenerator.ts b/project/src/generators/LootGenerator.ts index f013c7d9..fe0a3b9f 100644 --- a/project/src/generators/LootGenerator.ts +++ b/project/src/generators/LootGenerator.ts @@ -54,13 +54,13 @@ export class LootGenerator const itemTypeCounts = this.initItemLimitCounter(options.itemLimits); const tables = this.databaseServer.getTables(); - const itemBlacklist = new Set(this.itemFilterService.getBlacklistedItems()); - - options.itemBlacklist.forEach(itemBlacklist.add, itemBlacklist); - + const itemBlacklist = new Set([...this.itemFilterService.getBlacklistedItems(), ...options.itemBlacklist]); if (!options.allowBossItems) { - this.itemFilterService.getBossItems().forEach(itemBlacklist.add, itemBlacklist); + for (const bossItem of this.itemFilterService.getBossItems()) + { + itemBlacklist.add(bossItem); + } } // Handle sealed weapon containers diff --git a/project/src/helpers/AssortHelper.ts b/project/src/helpers/AssortHelper.ts index 8026ab7b..43ac41bb 100644 --- a/project/src/helpers/AssortHelper.ts +++ b/project/src/helpers/AssortHelper.ts @@ -127,7 +127,13 @@ export class AssortHelper if (assort.barter_scheme[itemID] && flea) { - assort.barter_scheme[itemID].forEach(b => b.forEach(br => br.sptQuestLocked = true)); + for (const barterSchemes of assort.barter_scheme[itemID]) + { + for (const barterScheme of barterSchemes) + { + barterScheme.sptQuestLocked = true; + } + } return assort; } delete assort.barter_scheme[itemID]; diff --git a/project/src/helpers/InRaidHelper.ts b/project/src/helpers/InRaidHelper.ts index c2d7a707..a286c137 100644 --- a/project/src/helpers/InRaidHelper.ts +++ b/project/src/helpers/InRaidHelper.ts @@ -364,10 +364,10 @@ export class InRaidHelper && !(this.inRaidConfig.keepFiRSecureContainerOnDeath && this.itemHelper.itemIsInsideContainer(x, "SecuredContainer", postRaidProfile.Inventory.items)); }); - itemsToRemovePropertyFrom.forEach(item => + for (const item of itemsToRemovePropertyFrom) { delete item.upd.SpawnedInSession; - }); + } return postRaidProfile; } @@ -410,10 +410,10 @@ export class InRaidHelper { // Get inventory item ids to remove from players profile const itemIdsToDeleteFromProfile = this.getInventoryItemsLostOnDeath(pmcData).map(x => x._id); - itemIdsToDeleteFromProfile.forEach(x => + for (const itemId of itemIdsToDeleteFromProfile) { - this.inventoryHelper.removeItem(pmcData, x, sessionID); - }); + this.inventoryHelper.removeItem(pmcData, itemId, sessionID); + } // Remove contents of fast panel pmcData.Inventory.fastPanel = {}; diff --git a/project/src/loaders/PreAkiModLoader.ts b/project/src/loaders/PreAkiModLoader.ts index 8db771d1..630305c4 100644 --- a/project/src/loaders/PreAkiModLoader.ts +++ b/project/src/loaders/PreAkiModLoader.ts @@ -146,10 +146,10 @@ export class PreAkiModLoader implements IModLoader const modOrder = this.vfs.readFile(this.modOrderPath, { encoding: "utf8" }); try { - this.jsonUtil.deserialize(modOrder).order.forEach((mod: string, index: number) => + for (const [index, mod] of (this.jsonUtil.deserialize(modOrder).order as string[]).entries()) { this.order[mod] = index; - }); + } } catch (error) { @@ -210,7 +210,10 @@ export class PreAkiModLoader implements IModLoader validMods.sort((prev, next) => this.sortMods(prev, next, missingFromOrderJSON)); // log the missing mods from order.json - Object.keys(missingFromOrderJSON).forEach((missingMod) => (this.logger.debug(this.localisationService.getText("modloader-mod_order_missing_from_json", missingMod)))); + for (const missingMod of Object.keys(missingFromOrderJSON)) + { + this.logger.debug(this.localisationService.getText("modloader-mod_order_missing_from_json", missingMod)); + } // add mods for (const mod of validMods) diff --git a/project/src/models/external/HttpFramework.ts b/project/src/models/external/HttpFramework.ts index 8fabeac2..42a4c3d1 100644 --- a/project/src/models/external/HttpFramework.ts +++ b/project/src/models/external/HttpFramework.ts @@ -32,7 +32,7 @@ export const Listen = (basePath: string) => if (!handlersArray) return; // Add each flagged handler to the Record - handlersArray.forEach(({ handlerName, path, httpMethod }) => + for (const { handlerName, path, httpMethod } of handlersArray) { if (!this.handlers[httpMethod]) this.handlers[httpMethod] = {}; @@ -41,7 +41,7 @@ export const Listen = (basePath: string) => if (!path || path === "") this.handlers[httpMethod][`/${basePath}`] = this[handlerName]; this.handlers[httpMethod][`/${basePath}/${path}`] = this[handlerName]; } - }); + } // Cleanup the handlers list Base.prototype["handlers"] = []; diff --git a/project/src/routers/HttpRouter.ts b/project/src/routers/HttpRouter.ts index 407f2d7a..9267b590 100644 --- a/project/src/routers/HttpRouter.ts +++ b/project/src/routers/HttpRouter.ts @@ -15,7 +15,7 @@ export class HttpRouter protected groupBy(list: T[], keyGetter: (t:T) => string): Map { const map: Map = new Map(); - list.forEach((item) => + for (const item of list) { const key = keyGetter(item); const collection = map.get(key); @@ -27,7 +27,7 @@ export class HttpRouter { collection.push(item); } - }); + } return map; } diff --git a/project/src/services/BotGenerationCacheService.ts b/project/src/services/BotGenerationCacheService.ts index 2742a9bc..f77e64be 100644 --- a/project/src/services/BotGenerationCacheService.ts +++ b/project/src/services/BotGenerationCacheService.ts @@ -27,17 +27,17 @@ export class BotGenerationCacheService */ public storeBots(key: string, botsToStore: IBotBase[]): void { - botsToStore.forEach(e => + for (const bot of botsToStore) { if (this.storedBots.has(key)) { - this.storedBots.get(key).unshift(e); + this.storedBots.get(key).unshift(bot); } else { - this.storedBots.set(key, [e]); + this.storedBots.set(key, [bot]); } - }); + } } /** diff --git a/project/src/services/ProfileFixerService.ts b/project/src/services/ProfileFixerService.ts index 0a819231..de0a45d7 100644 --- a/project/src/services/ProfileFixerService.ts +++ b/project/src/services/ProfileFixerService.ts @@ -383,14 +383,14 @@ export class ProfileFixerService protected getActiveRepeatableQuests(repeatableQuests: IPmcDataRepeatableQuest[]): IRepeatableQuest[] { let activeQuests = []; - repeatableQuests?.forEach(x => + for (const repeatableQuest of repeatableQuests) { - if (x.activeQuests.length > 0) + if (repeatableQuest.activeQuests.length > 0) { // daily/weekly collection has active quests in them, add to array and return - activeQuests = activeQuests.concat(x.activeQuests); + activeQuests = activeQuests.concat(repeatableQuest.activeQuests); } - }); + } return activeQuests; } diff --git a/project/src/services/RagfairOfferService.ts b/project/src/services/RagfairOfferService.ts index 07feab5b..e67b659f 100644 --- a/project/src/services/RagfairOfferService.ts +++ b/project/src/services/RagfairOfferService.ts @@ -187,9 +187,10 @@ export class RagfairOfferService public expireStaleOffers(): void { const time = this.timeUtil.getTimestamp(); - this.ragfairOfferHandler - .getStaleOffers(time) - .forEach(o => this.processStaleOffer(o)); + for (const staleOffer of this.ragfairOfferHandler.getStaleOffers(time)) + { + this.processStaleOffer(staleOffer); + } } /** diff --git a/project/src/utils/RagfairOfferHolder.ts b/project/src/utils/RagfairOfferHolder.ts index 86861ded..75491e5f 100644 --- a/project/src/utils/RagfairOfferHolder.ts +++ b/project/src/utils/RagfairOfferHolder.ts @@ -51,7 +51,10 @@ export class RagfairOfferHolder public addOffers(offers: Array): void { - offers.forEach(o => this.addOffer(o)); + for (const offer of offers) + { + this.addOffer(offer); + } } public addOffer(offer: IRagfairOffer): void @@ -76,7 +79,10 @@ export class RagfairOfferHolder public removeOffers(offers: Array): void { - offers.forEach(o => this.removeOffer(o)); + for (const offer of offers) + { + this.removeOffer(offer); + } } public removeOfferByTrader(traderId: string): void diff --git a/project/src/utils/collections/queue/Queue.ts b/project/src/utils/collections/queue/Queue.ts index 607c08c5..4d632372 100644 --- a/project/src/utils/collections/queue/Queue.ts +++ b/project/src/utils/collections/queue/Queue.ts @@ -19,7 +19,10 @@ export class Queue public enqueueAll(elements: T[]): void { - elements.forEach(e => this.enqueue(e)); + for (const element of elements) + { + this.enqueue(element); + } } public dequeue(): T