From 76ccb0ba36275d55fe22bc97875a911cfa85f6db Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Wed, 25 May 2022 11:43:43 -0400 Subject: [PATCH] lint --- .eslintrc.js | 7 ++++++- package.json | 2 +- src/Bladeburner/Bladeburner.tsx | 4 ++-- src/Bladeburner/ui/GeneralActionElem.tsx | 2 +- src/DevMenu/ui/Augmentations.tsx | 2 +- src/DevMenu/ui/CodingContracts.tsx | 2 +- src/DevMenu/ui/Companies.tsx | 2 +- src/DevMenu/ui/Factions.tsx | 2 +- src/DevMenu/ui/Programs.tsx | 2 +- src/DevMenu/ui/SaveFile.tsx | 9 +-------- src/DevMenu/ui/Servers.tsx | 2 +- src/Exploits/Unclickable.tsx | 4 ++-- src/GameOptions/ui/CurrentOptionsPage.tsx | 4 ++-- src/Hacknet/ui/HacknetNodeElem.tsx | 6 +++--- src/NetscriptFunctions/Corporation.ts | 2 +- src/NetscriptFunctions/Formulas.ts | 1 - src/NetscriptFunctions/Singularity.ts | 2 +- src/ScriptEditor/ui/ScriptEditorRoot.tsx | 2 +- src/StockMarket/Stock.ts | 2 +- src/StockMarket/StockMarket.tsx | 2 +- src/Terminal/commands/mv.ts | 2 +- src/TextFile.ts | 2 +- src/utils/IPAddress.ts | 7 ++----- test/jest/StockMarket.test.ts | 3 +-- tools/tsconfig.json | 4 ++++ 25 files changed, 38 insertions(+), 41 deletions(-) create mode 100644 tools/tsconfig.json diff --git a/.eslintrc.js b/.eslintrc.js index da124eaee..82b418fbb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -4,7 +4,11 @@ module.exports = { commonjs: true, es6: false, }, - extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"], + extends: [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + // "plugin:@typescript-eslint/recommended-requiring-type-checking", + ], parser: "@typescript-eslint/parser", parserOptions: { ecmaVersion: 8, @@ -12,6 +16,7 @@ module.exports = { ecmaFeatures: { experimentalObjectRestSpread: true, }, + project: ["./tsconfig.json", "./test/tsconfig.json", "./tools/tsconfig.json", "./test/cypress/tsconfig.json"], }, plugins: ["@typescript-eslint"], rules: { diff --git a/package.json b/package.json index 6c0867b15..d63b94fbb 100644 --- a/package.json +++ b/package.json @@ -114,7 +114,7 @@ "start:container": "webpack-dev-server --progress --env.devServer --mode development --env.runInContainer", "build": "webpack --mode production", "build:dev": "webpack --mode development", - "lint": "eslint --fix --ext js,jsx,ts,tsx --max-warnings 0 .", + "lint": "eslint --fix --ext js,jsx,ts,tsx --max-warnings 0 src test", "lint:report": "eslint --ext js,jsx,ts,tsx --max-warnings 0 .", "lint:report-diff": "eslint --max-warnings 0 $(git diff --name-only --diff-filter=ACMRTUXB origin/dev | grep -E \"(.js$|.jsx$|.ts$|.tsx$)\" | xargs)", "preinstall": "node ./tools/engines-check/engines-check.js", diff --git a/src/Bladeburner/Bladeburner.tsx b/src/Bladeburner/Bladeburner.tsx index 451d7e119..74ce942c0 100644 --- a/src/Bladeburner/Bladeburner.tsx +++ b/src/Bladeburner/Bladeburner.tsx @@ -2029,12 +2029,12 @@ export class Bladeburner implements IBladeburner { this.stamina = Math.min(this.maxStamina, this.stamina); // Count increase for contracts/operations - for (const contract of Object.values(this.contracts) as Contract[]) { + for (const contract of Object.values(this.contracts) ) { const growthF = Growths[contract.name]; if (growthF === undefined) throw new Error(`growth formula for action '${contract.name}' is undefined`); contract.count += (seconds * growthF()) / BladeburnerConstants.ActionCountGrowthPeriod; } - for (const op of Object.values(this.operations) as Operation[]) { + for (const op of Object.values(this.operations) ) { const growthF = Growths[op.name]; if (growthF === undefined) throw new Error(`growth formula for action '${op.name}' is undefined`); if (growthF !== undefined) { diff --git a/src/Bladeburner/ui/GeneralActionElem.tsx b/src/Bladeburner/ui/GeneralActionElem.tsx index c4809a61f..7cd4b1dcc 100644 --- a/src/Bladeburner/ui/GeneralActionElem.tsx +++ b/src/Bladeburner/ui/GeneralActionElem.tsx @@ -74,7 +74,7 @@ export function GeneralActionElem(props: IProps): React.ReactElement { diff --git a/src/DevMenu/ui/Augmentations.tsx b/src/DevMenu/ui/Augmentations.tsx index be569e1d3..4776264bf 100644 --- a/src/DevMenu/ui/Augmentations.tsx +++ b/src/DevMenu/ui/Augmentations.tsx @@ -22,7 +22,7 @@ export function Augmentations(props: IProps): React.ReactElement { const [augmentation, setAugmentation] = useState("Augmented Targeting I"); function setAugmentationDropdown(event: SelectChangeEvent): void { - setAugmentation(event.target.value as string); + setAugmentation(event.target.value ); } function queueAug(): void { props.player.queueAugmentation(augmentation); diff --git a/src/DevMenu/ui/CodingContracts.tsx b/src/DevMenu/ui/CodingContracts.tsx index b519737f2..7ddd96494 100644 --- a/src/DevMenu/ui/CodingContracts.tsx +++ b/src/DevMenu/ui/CodingContracts.tsx @@ -15,7 +15,7 @@ import { CodingContractTypes } from "../../CodingContracts"; export function CodingContracts(): React.ReactElement { const [codingcontract, setCodingcontract] = useState("Find Largest Prime Factor"); function setCodingcontractDropdown(event: SelectChangeEvent): void { - setCodingcontract(event.target.value as string); + setCodingcontract(event.target.value ); } function specificContract(): void { diff --git a/src/DevMenu/ui/Companies.tsx b/src/DevMenu/ui/Companies.tsx index 567f02af0..c1f98dc70 100644 --- a/src/DevMenu/ui/Companies.tsx +++ b/src/DevMenu/ui/Companies.tsx @@ -18,7 +18,7 @@ const bigNumber = 1e12; export function Companies(): React.ReactElement { const [company, setCompany] = useState(FactionNames.ECorp as string); function setCompanyDropdown(event: SelectChangeEvent): void { - setCompany(event.target.value as string); + setCompany(event.target.value ); } function resetCompanyRep(): void { AllCompanies[company].playerReputation = 0; diff --git a/src/DevMenu/ui/Factions.tsx b/src/DevMenu/ui/Factions.tsx index f8ea3b4e2..20322822e 100644 --- a/src/DevMenu/ui/Factions.tsx +++ b/src/DevMenu/ui/Factions.tsx @@ -29,7 +29,7 @@ export function Factions(props: IProps): React.ReactElement { const [faction, setFaction] = useState(FactionNames.Illuminati as string); function setFactionDropdown(event: SelectChangeEvent): void { - setFaction(event.target.value as string); + setFaction(event.target.value ); } function receiveInvite(): void { diff --git a/src/DevMenu/ui/Programs.tsx b/src/DevMenu/ui/Programs.tsx index af39aa8b4..7b300e81e 100644 --- a/src/DevMenu/ui/Programs.tsx +++ b/src/DevMenu/ui/Programs.tsx @@ -19,7 +19,7 @@ interface IProps { export function Programs(props: IProps): React.ReactElement { const [program, setProgram] = useState("NUKE.exe"); function setProgramDropdown(event: SelectChangeEvent): void { - setProgram(event.target.value as string); + setProgram(event.target.value ); } function addProgram(): void { if (!props.player.hasProgram(program)) { diff --git a/src/DevMenu/ui/SaveFile.tsx b/src/DevMenu/ui/SaveFile.tsx index 2f8bd392f..584b0138f 100644 --- a/src/DevMenu/ui/SaveFile.tsx +++ b/src/DevMenu/ui/SaveFile.tsx @@ -6,20 +6,13 @@ import AccordionDetails from "@mui/material/AccordionDetails"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import Typography from "@mui/material/Typography"; -import { IPlayer } from "../../PersonObjects/IPlayer"; import { saveObject } from "../../SaveObject"; import { SnackbarEvents, ToastVariant } from "../../ui/React/Snackbar"; import { Upload } from "@mui/icons-material"; import { Button } from "@mui/material"; import { OptionSwitch } from "../../ui/React/OptionSwitch"; -// Update as additional BitNodes get implemented - -interface IProps { - player: IPlayer; -} - -export function SaveFile(props: IProps): React.ReactElement { +export function SaveFile(): React.ReactElement { const importInput = useRef(null); const [saveFile, setSaveFile] = useState(""); const [restoreScripts, setRestoreScripts] = useState(true); diff --git a/src/DevMenu/ui/Servers.tsx b/src/DevMenu/ui/Servers.tsx index dec46880f..b73a935b4 100644 --- a/src/DevMenu/ui/Servers.tsx +++ b/src/DevMenu/ui/Servers.tsx @@ -15,7 +15,7 @@ import MenuItem from "@mui/material/MenuItem"; export function Servers(): React.ReactElement { const [server, setServer] = useState("home"); function setServerDropdown(event: SelectChangeEvent): void { - setServer(event.target.value as string); + setServer(event.target.value ); } function rootServer(): void { const s = GetServer(server); diff --git a/src/Exploits/Unclickable.tsx b/src/Exploits/Unclickable.tsx index 7fab8d376..fbcfb3c1b 100644 --- a/src/Exploits/Unclickable.tsx +++ b/src/Exploits/Unclickable.tsx @@ -8,8 +8,8 @@ export function Unclickable(): React.ReactElement { function unclickable(event: React.MouseEvent): void { if (!event.target || !(event.target instanceof Element)) return; - const display = getComputedStyle(event.target as Element).display; - const visibility = getComputedStyle(event.target as Element).visibility; + const display = getComputedStyle(event.target ).display; + const visibility = getComputedStyle(event.target ).visibility; if (display === "none" && visibility === "hidden" && event.isTrusted) player.giveExploit(Exploit.Unclickable); } diff --git a/src/GameOptions/ui/CurrentOptionsPage.tsx b/src/GameOptions/ui/CurrentOptionsPage.tsx index ad8db447d..b5fda7b73 100644 --- a/src/GameOptions/ui/CurrentOptionsPage.tsx +++ b/src/GameOptions/ui/CurrentOptionsPage.tsx @@ -54,8 +54,8 @@ export const CurrentOptionsPage = (props: IProps): React.ReactElement => { } function handleLocaleChange(event: SelectChangeEvent): void { - setLocale(event.target.value as string); - Settings.Locale = event.target.value as string; + setLocale(event.target.value ); + Settings.Locale = event.target.value ; } function handleTimestampFormatChange(event: React.ChangeEvent): void { diff --git a/src/Hacknet/ui/HacknetNodeElem.tsx b/src/Hacknet/ui/HacknetNodeElem.tsx index 3df102f3e..b5909027c 100644 --- a/src/Hacknet/ui/HacknetNodeElem.tsx +++ b/src/Hacknet/ui/HacknetNodeElem.tsx @@ -54,7 +54,7 @@ export function HacknetNodeElem(props: IProps): React.ReactElement { multiplier = getMaxNumberLevelUpgrades(props.player, node, HacknetNodeConstants.MaxLevel); } else { const levelsToMax = HacknetNodeConstants.MaxLevel - node.level; - multiplier = Math.min(levelsToMax, purchaseMult as number); + multiplier = Math.min(levelsToMax, purchaseMult ); } const increase = @@ -94,7 +94,7 @@ export function HacknetNodeElem(props: IProps): React.ReactElement { multiplier = getMaxNumberRamUpgrades(props.player, node, HacknetNodeConstants.MaxRam); } else { const levelsToMax = Math.round(Math.log2(HacknetNodeConstants.MaxRam / node.ram)); - multiplier = Math.min(levelsToMax, purchaseMult as number); + multiplier = Math.min(levelsToMax, purchaseMult ); } const increase = @@ -144,7 +144,7 @@ export function HacknetNodeElem(props: IProps): React.ReactElement { multiplier = getMaxNumberCoreUpgrades(props.player, node, HacknetNodeConstants.MaxCores); } else { const levelsToMax = HacknetNodeConstants.MaxCores - node.cores; - multiplier = Math.min(levelsToMax, purchaseMult as number); + multiplier = Math.min(levelsToMax, purchaseMult ); } const increase = diff --git a/src/NetscriptFunctions/Corporation.ts b/src/NetscriptFunctions/Corporation.ts index b1d134946..03ec45ed8 100644 --- a/src/NetscriptFunctions/Corporation.ts +++ b/src/NetscriptFunctions/Corporation.ts @@ -257,7 +257,7 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript function getMaterial(divisionName: string, cityName: string, materialName: string): Material { const warehouse = getWarehouse(divisionName, cityName); - const matName = (materialName as string).replace(/ /g, ""); + const matName = (materialName ).replace(/ /g, ""); const material = warehouse.materials[matName]; if (material === undefined) throw new Error(`Invalid material name: '${materialName}'`); return material; diff --git a/src/NetscriptFunctions/Formulas.ts b/src/NetscriptFunctions/Formulas.ts index 2c8124ca0..37d986b6b 100644 --- a/src/NetscriptFunctions/Formulas.ts +++ b/src/NetscriptFunctions/Formulas.ts @@ -1,5 +1,4 @@ import { INetscriptHelper } from "./INetscriptHelper"; -import { WorkerScript } from "../Netscript/WorkerScript"; import { IPlayer } from "../PersonObjects/IPlayer"; import { calculateServerGrowth } from "../Server/formulas/grow"; import { diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index 8cf3ffc5a..87d0892c8 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -606,7 +606,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript _ctx.log(() => "cannot backdoor this kind of server"); return Promise.resolve(); } - const server = baseserver as Server; + const server = baseserver ; const installTime = (calculateHackingTime(server, player) / 4) * 1000; // No root access or skill level too low diff --git a/src/ScriptEditor/ui/ScriptEditorRoot.tsx b/src/ScriptEditor/ui/ScriptEditorRoot.tsx index 1c7d5c363..24780072a 100644 --- a/src/ScriptEditor/ui/ScriptEditorRoot.tsx +++ b/src/ScriptEditor/ui/ScriptEditorRoot.tsx @@ -693,7 +693,7 @@ export function Root(props: IProps): React.ReactElement { if (server === null) throw new Error(`Server '${closingScript.hostname}' should not be null, but it is.`); const serverScriptIndex = server.scripts.findIndex((script) => script.filename === closingScript.fileName); - if (serverScriptIndex === -1 || savedScriptCode !== server.scripts[serverScriptIndex as number].code) { + if (serverScriptIndex === -1 || savedScriptCode !== server.scripts[serverScriptIndex ].code) { PromptEvent.emit({ txt: `Do you want to save changes to ${closingScript.fileName} on ${closingScript.hostname}?`, resolve: (result: boolean | string) => { diff --git a/src/StockMarket/Stock.ts b/src/StockMarket/Stock.ts index c5c891898..f6e27db31 100644 --- a/src/StockMarket/Stock.ts +++ b/src/StockMarket/Stock.ts @@ -36,7 +36,7 @@ function toNumber(n: number | IMinMaxRange): number { return n; } case "object": { - const range = n as IMinMaxRange; + const range = n ; value = getRandomInt(range.min, range.max); break; } diff --git a/src/StockMarket/StockMarket.tsx b/src/StockMarket/StockMarket.tsx index 7869b9f9d..208c6e765 100644 --- a/src/StockMarket/StockMarket.tsx +++ b/src/StockMarket/StockMarket.tsx @@ -68,7 +68,7 @@ export function placeOrder( // Process to see if it should be executed immediately const processOrderRefs = { - stockMarket: StockMarket as IStockMarket, + stockMarket: StockMarket , symbolToStockMap: SymbolToStockMap, }; processOrders(stock, order.type, order.pos, processOrderRefs); diff --git a/src/Terminal/commands/mv.ts b/src/Terminal/commands/mv.ts index 3d31894a5..2961aa891 100644 --- a/src/Terminal/commands/mv.ts +++ b/src/Terminal/commands/mv.ts @@ -84,7 +84,7 @@ export function mv( script.filename = destPath; } else if (srcFile instanceof TextFile) { - const textFile = srcFile as TextFile; + const textFile = srcFile ; if (!dest.endsWith(".txt")) { terminal.error(`Source and destination files must have the same type`); return; diff --git a/src/TextFile.ts b/src/TextFile.ts index d04d11281..8ee024795 100644 --- a/src/TextFile.ts +++ b/src/TextFile.ts @@ -121,7 +121,7 @@ export function getTextFile(fn: string, server: BaseServer): TextFile | null { filename = removeLeadingSlash(filename); } - for (const file of server.textFiles as TextFile[]) { + for (const file of server.textFiles ) { if (file.fn === filename) { return file; } diff --git a/src/utils/IPAddress.ts b/src/utils/IPAddress.ts index 5f85aa59d..325712bea 100644 --- a/src/utils/IPAddress.ts +++ b/src/utils/IPAddress.ts @@ -4,8 +4,5 @@ import { getRandomByte } from "./helpers/getRandomByte"; * Generate a random IP address * Does not check to see if the IP already exists in the game */ -export function createRandomIp(): string { - const ip: string = getRandomByte(99) + "." + getRandomByte(9) + "." + getRandomByte(9) + "." + getRandomByte(9); - - return ip; -} +export const createRandomIp = (): string => + `${getRandomByte(99)}.${getRandomByte(9)}.${getRandomByte(9)}.${getRandomByte(9)}`; diff --git a/test/jest/StockMarket.test.ts b/test/jest/StockMarket.test.ts index a989c68c5..f531d714f 100644 --- a/test/jest/StockMarket.test.ts +++ b/test/jest/StockMarket.test.ts @@ -6,7 +6,6 @@ import { Company } from "../../src/Company/Company"; import { Server } from "../../src/Server/Server"; import { buyStock, sellStock, shortStock, sellShort } from "../../src/StockMarket/BuyingAndSelling"; -import { IStockMarket } from "../../src/StockMarket/IStockMarket"; import { Order } from "../../src/StockMarket/Order"; import { forecastForecastChangeFromCompanyWork, @@ -1149,7 +1148,7 @@ describe("Stock Market Tests", function () { Player.setMoney(100e9); processOrdersRefs = { - stockMarket: StockMarket as IStockMarket, + stockMarket: StockMarket, symbolToStockMap: SymbolToStockMap, }; }); diff --git a/tools/tsconfig.json b/tools/tsconfig.json new file mode 100644 index 000000000..9b143e1d7 --- /dev/null +++ b/tools/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../tsconfig.json", + "include": ["**/*.js"] +}