diff --git a/.eslintrc.js b/.eslintrc.js index 0f285e40e..c88ebcfeb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -137,7 +137,7 @@ module.exports = { "no-ex-assign": ["off"], "no-extra-boolean-cast": ["error"], "no-extra-parens": ["off"], - "no-extra-semi": ["off"], + "no-extra-semi": ["error"], "no-eval": ["off"], "no-extend-native": ["off"], "no-extra-bind": ["error"], @@ -166,12 +166,12 @@ module.exports = { "no-label-var": ["error"], "no-labels": ["off"], "no-lone-blocks": ["error"], - "no-lonely-if": ["off"], + "no-lonely-if": ["error"], "no-loop-func": ["off"], "no-magic-numbers": ["off"], "no-mixed-operators": ["off"], "no-mixed-requires": ["error"], - "no-mixed-spaces-and-tabs": ["off"], + "no-mixed-spaces-and-tabs": ["error"], "no-multi-assign": ["off"], "no-multi-spaces": ["off"], "no-multi-str": ["error"], diff --git a/electron/storage.js b/electron/storage.js index 076200d3f..03ebdcc16 100644 --- a/electron/storage.js +++ b/electron/storage.js @@ -337,23 +337,21 @@ async function restoreIfNewerExists(window) { let bestMatch; if (!steam.data && !disk.data) { log.info("No data to import"); - } else { + } else if (!steam.data) { // We'll just compare using the lastSave field for now. - if (!steam.data) { - log.debug('Best potential save match: Disk'); - bestMatch = disk; - } else if (!disk.data) { - log.debug('Best potential save match: Steam Cloud'); - bestMatch = steam; - } else if ((steam.data.lastSave >= disk.data.lastSave) - || (steam.data.playtime + lowPlaytime > disk.data.playtime)) { - // We want to prioritze steam data if the playtime is very close - log.debug('Best potential save match: Steam Cloud'); - bestMatch = steam; - } else { - log.debug('Best potential save match: disk'); - bestMatch = disk; - } + log.debug('Best potential save match: Disk'); + bestMatch = disk; + } else if (!disk.data) { + log.debug('Best potential save match: Steam Cloud'); + bestMatch = steam; + } else if ((steam.data.lastSave >= disk.data.lastSave) + || (steam.data.playtime + lowPlaytime > disk.data.playtime)) { + // We want to prioritze steam data if the playtime is very close + log.debug('Best potential save match: Steam Cloud'); + bestMatch = steam; + } else { + log.debug('Best potential save match: disk'); + bestMatch = disk; } if (bestMatch) { if (bestMatch.data.lastSave > currentData.lastSave + 5000) { diff --git a/src/Corporation/Actions.ts b/src/Corporation/Actions.ts index ab217d843..53148f26e 100644 --- a/src/Corporation/Actions.ts +++ b/src/Corporation/Actions.ts @@ -218,8 +218,7 @@ export function SellProduct(product: Product, city: string, amt: string, price: product.sllman[city][0] = false; product.sllman[city][1] = ""; } - } else { - if (all) { + } else if (all) { for (let i = 0; i < cities.length; ++i) { const tempCity = cities[i]; product.sllman[tempCity][0] = true; @@ -229,7 +228,6 @@ export function SellProduct(product: Product, city: string, amt: string, price: product.sllman[city][0] = true; product.sllman[city][1] = qty; } - } } } diff --git a/src/Corporation/ui/ThrowPartyModal.tsx b/src/Corporation/ui/ThrowPartyModal.tsx index 9c156f76a..8b89c4506 100644 --- a/src/Corporation/ui/ThrowPartyModal.tsx +++ b/src/Corporation/ui/ThrowPartyModal.tsx @@ -33,8 +33,7 @@ export function ThrowPartyModal(props: IProps): React.ReactElement { function throwParty(): void { if (cost === null || isNaN(cost) || cost < 0) { dialogBoxCreate("Invalid value entered"); - } else { - if (!canParty) { + } else if (!canParty) { dialogBoxCreate("You don't have enough company funds to throw a party!"); } else { const mult = ThrowParty(corp, props.office, cost); @@ -46,7 +45,6 @@ export function ThrowPartyModal(props: IProps): React.ReactElement { props.rerender(); props.onClose(); } - } } function EffectText(): React.ReactElement { diff --git a/src/Faction/FactionHelpers.tsx b/src/Faction/FactionHelpers.tsx index 8e9754c61..33011af70 100644 --- a/src/Faction/FactionHelpers.tsx +++ b/src/Faction/FactionHelpers.tsx @@ -166,8 +166,7 @@ export function purchaseAugmentation(aug: Augmentation, fac: Faction, sing = fal if (sing) { return "You purchased " + aug.name; - } else { - if (!Settings.SuppressBuyAugmentationConfirmation) { + } else if (!Settings.SuppressBuyAugmentationConfirmation) { dialogBoxCreate( "You purchased " + aug.name + @@ -177,7 +176,6 @@ export function purchaseAugmentation(aug: Augmentation, fac: Faction, sing = fal "augmentations will now be more expensive.", ); } - } } else { dialogBoxCreate( "Hmm, something went wrong when trying to purchase an Augmentation. " + diff --git a/src/Locations/ui/SpecialLocation.tsx b/src/Locations/ui/SpecialLocation.tsx index bcd21acb5..23d7c8ef1 100644 --- a/src/Locations/ui/SpecialLocation.tsx +++ b/src/Locations/ui/SpecialLocation.tsx @@ -51,21 +51,19 @@ export function SpecialLocation(props: IProps): React.ReactElement { if (p.inBladeburner()) { // Enter Bladeburner division router.toBladeburner(); - } else { + } else if (p.strength >= 100 && p.defense >= 100 && p.dexterity >= 100 && p.agility >= 100) { // Apply for Bladeburner division - if (p.strength >= 100 && p.defense >= 100 && p.dexterity >= 100 && p.agility >= 100) { - p.startBladeburner({ new: true }); - dialogBoxCreate("You have been accepted into the Bladeburner division!"); - setRerender((old) => !old); + p.startBladeburner({new: true}); + dialogBoxCreate("You have been accepted into the Bladeburner division!"); + setRerender((old) => !old); - const worldHeader = document.getElementById("world-menu-header"); - if (worldHeader instanceof HTMLElement) { - worldHeader.click(); - worldHeader.click(); - } - } else { - dialogBoxCreate("Rejected! Please apply again when you have 100 of each combat stat (str, def, dex, agi)"); + const worldHeader = document.getElementById("world-menu-header"); + if (worldHeader instanceof HTMLElement) { + worldHeader.click(); + worldHeader.click(); } + } else { + dialogBoxCreate("Rejected! Please apply again when you have 100 of each combat stat (str, def, dex, agi)"); } } diff --git a/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx b/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx index 9cbcf2010..08ce271fc 100644 --- a/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx +++ b/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx @@ -608,11 +608,9 @@ export function process(this: IPlayer, router: IRouter, numCycles = 1): void { if (this.workPartTime(numCycles)) { router.toCity(); } - } else { - if (this.work(numCycles)) { + } else if (this.work(numCycles)) { router.toCity(); } - } } } @@ -2244,8 +2242,7 @@ export function checkForFactionInvitations(this: IPlayer): Faction[] { if (!(fulcrumSecretServer instanceof Server)) throw new Error("Fulcrum Secret Technologies should be normal server"); if (fulcrumSecretServer == null) { console.error("Could not find Fulcrum Secret Technologies Server"); - } else { - if ( + } else if ( !fulcrumsecrettechonologiesFac.isBanned && !fulcrumsecrettechonologiesFac.isMember && !fulcrumsecrettechonologiesFac.alreadyInvited && @@ -2254,7 +2251,6 @@ export function checkForFactionInvitations(this: IPlayer): Faction[] { ) { invitedFactions.push(fulcrumsecrettechonologiesFac); } - } //BitRunners const bitrunnersFac = Factions["BitRunners"]; diff --git a/src/RedPill.tsx b/src/RedPill.tsx index 2c2edf99d..ffaa77fa4 100644 --- a/src/RedPill.tsx +++ b/src/RedPill.tsx @@ -75,12 +75,10 @@ function giveSourceFile(bitNodeNumber: number): void { export function enterBitNode(router: IRouter, flume: boolean, destroyedBitNode: number, newBitNode: number): void { if (!flume) { giveSourceFile(destroyedBitNode); - } else { - if (SourceFileFlags[5] === 0 && newBitNode !== 5) { + } else if (SourceFileFlags[5] === 0 && newBitNode !== 5) { Player.intelligence = 0; Player.intelligence_exp = 0; } - } if (newBitNode === 5 && Player.intelligence === 0) { Player.intelligence = 1; } diff --git a/src/StockMarket/OrderProcessing.tsx b/src/StockMarket/OrderProcessing.tsx index 81f5c7b05..9ba62c2f0 100644 --- a/src/StockMarket/OrderProcessing.tsx +++ b/src/StockMarket/OrderProcessing.tsx @@ -165,8 +165,7 @@ function executeOrder(order: Order, refs: IProcessOrderRefs): void { console.error("Could not find the following Order in Order Book: "); console.error(order); - } else { - if (isBuy) { + } else if (isBuy) { dialogBoxCreate( <> Failed to execute {order.type} for {stock.symbol} @ ({pos}). This is most likely @@ -174,5 +173,4 @@ function executeOrder(order: Order, refs: IProcessOrderRefs): void { , ); } - } } diff --git a/src/StockMarket/Stock.ts b/src/StockMarket/Stock.ts index 47461ded9..c5c891898 100644 --- a/src/StockMarket/Stock.ts +++ b/src/StockMarket/Stock.ts @@ -213,13 +213,11 @@ export class Stock { } else { this.otlkMag -= changeAmt; } - } else { + } else if (this.b) { // Forecast decreases - if (this.b) { - this.otlkMag -= changeAmt; - } else { - this.otlkMag += changeAmt; - } + this.otlkMag -= changeAmt; + } else { + this.otlkMag += changeAmt; } this.otlkMag = Math.min(this.otlkMag, 50); diff --git a/src/StockMarket/ui/StockTicker.tsx b/src/StockMarket/ui/StockTicker.tsx index eb138de0c..148f879d0 100644 --- a/src/StockMarket/ui/StockTicker.tsx +++ b/src/StockMarket/ui/StockTicker.tsx @@ -113,11 +113,9 @@ export function StockTicker(props: IProps): React.ReactElement { if (qty > stock.playerShares) { return <>You do not have this many shares in the Long position; } - } else { - if (qty > stock.playerShortShares) { + } else if (qty > stock.playerShortShares) { return <>You do not have this many shares in the Short position; } - } const cost = getSellTransactionGain(stock, qty, position); if (cost == null) { diff --git a/src/Terminal/Parser.ts b/src/Terminal/Parser.ts index e6b11dbe4..80c3654b4 100644 --- a/src/Terminal/Parser.ts +++ b/src/Terminal/Parser.ts @@ -68,13 +68,11 @@ export function ParseCommand(command: string): (string | number | boolean)[] { } continue; } - } else { - if (inQuote === ``) { + } else if (inQuote === ``) { inQuote = `"`; } else if (inQuote === `"`) { inQuote = ``; } - } } else if (c === "'") { // Single quotes, same thing as above if (!escaped && prevChar === " ") { @@ -88,13 +86,11 @@ export function ParseCommand(command: string): (string | number | boolean)[] { } continue; } - } else { - if (inQuote === ``) { + } else if (inQuote === ``) { inQuote = `'`; } else if (inQuote === `'`) { inQuote = ``; } - } } else if (c === " " && inQuote === ``) { const arg = command.substr(start, i - start); diff --git a/src/Terminal/commands/ls.tsx b/src/Terminal/commands/ls.tsx index 738f23f00..6ef2cc48c 100644 --- a/src/Terminal/commands/ls.tsx +++ b/src/Terminal/commands/ls.tsx @@ -179,13 +179,11 @@ export function ls( i--; if (!style) { terminal.print(row); - } else { - if (linked) { + } else if (linked) { terminal.printRaw(); } else { terminal.printRaw({row}); } - } } } diff --git a/src/Terminal/commands/unalias.ts b/src/Terminal/commands/unalias.ts index 216b55fb1..b9d47b3bc 100644 --- a/src/Terminal/commands/unalias.ts +++ b/src/Terminal/commands/unalias.ts @@ -14,11 +14,9 @@ export function unalias( if (args.length !== 1) { terminal.error("Incorrect usage of unalias name. Usage: unalias [alias]"); return; - } else { - if (removeAlias(args[0] + "")) { + } else if (removeAlias(args[0] + "")) { terminal.print(`Removed alias ${args[0]}`); } else { terminal.error(`No such alias exists: ${args[0]}`); } - } } diff --git a/src/Terminal/tabCompletion.ts b/src/Terminal/tabCompletion.ts index 288503f21..6a7e20b9c 100644 --- a/src/Terminal/tabCompletion.ts +++ b/src/Terminal/tabCompletion.ts @@ -66,28 +66,22 @@ export function tabCompletion( if (arg === "") { if (longestStartSubstr === command) { return allPossibilities; - } else { - if (semiColonIndex === -1) { + } else if (semiColonIndex === -1) { // No semicolon, so replace the whole command return longestStartSubstr; } else { // Replace only after the last semicolon return `${oldValue.slice(0, semiColonIndex + 1)} ${longestStartSubstr}`; } - } - } else { - if (longestStartSubstr === arg) { + } else if (longestStartSubstr === arg) { // List all possible options return allPossibilities; - } else { - if (semiColonIndex == -1) { + } else if (semiColonIndex == -1) { // No semicolon, so replace the whole command return `${command} ${longestStartSubstr}`; } else { // Replace only after the last semicolon return `${oldValue.slice(0, semiColonIndex + 1)} ${command} ${longestStartSubstr}`; } - } - } } } diff --git a/src/utils/Validator.ts b/src/utils/Validator.ts index ab62d653e..bfd026d8f 100644 --- a/src/utils/Validator.ts +++ b/src/utils/Validator.ts @@ -17,8 +17,7 @@ export function validateObject, Key extends if (paramValidator !== undefined) { if (typeof paramValidator === 'function') { paramValidator(obj, key); - } else { - if (paramValidator.func !== undefined) { + } else if (paramValidator.func !== undefined) { paramValidator.func(obj, validator, key); } else { if ((typeof obj[key]) !== (typeof paramValidator.default)) { @@ -31,7 +30,6 @@ export function validateObject, Key extends if (obj[key] > paramValidator.max) obj[key] = paramValidator.max as Type[Key]; } } - } } } }