This commit is contained in:
Olivier Gagnon 2022-05-25 11:43:43 -04:00
parent 6fef46d5df
commit 76ccb0ba36
25 changed files with 38 additions and 41 deletions

@ -4,7 +4,11 @@ module.exports = {
commonjs: true, commonjs: true,
es6: false, 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", parser: "@typescript-eslint/parser",
parserOptions: { parserOptions: {
ecmaVersion: 8, ecmaVersion: 8,
@ -12,6 +16,7 @@ module.exports = {
ecmaFeatures: { ecmaFeatures: {
experimentalObjectRestSpread: true, experimentalObjectRestSpread: true,
}, },
project: ["./tsconfig.json", "./test/tsconfig.json", "./tools/tsconfig.json", "./test/cypress/tsconfig.json"],
}, },
plugins: ["@typescript-eslint"], plugins: ["@typescript-eslint"],
rules: { rules: {

@ -114,7 +114,7 @@
"start:container": "webpack-dev-server --progress --env.devServer --mode development --env.runInContainer", "start:container": "webpack-dev-server --progress --env.devServer --mode development --env.runInContainer",
"build": "webpack --mode production", "build": "webpack --mode production",
"build:dev": "webpack --mode development", "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": "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)", "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", "preinstall": "node ./tools/engines-check/engines-check.js",

@ -2029,12 +2029,12 @@ export class Bladeburner implements IBladeburner {
this.stamina = Math.min(this.maxStamina, this.stamina); this.stamina = Math.min(this.maxStamina, this.stamina);
// Count increase for contracts/operations // 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]; const growthF = Growths[contract.name];
if (growthF === undefined) throw new Error(`growth formula for action '${contract.name}' is undefined`); if (growthF === undefined) throw new Error(`growth formula for action '${contract.name}' is undefined`);
contract.count += (seconds * growthF()) / BladeburnerConstants.ActionCountGrowthPeriod; 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]; const growthF = Growths[op.name];
if (growthF === undefined) throw new Error(`growth formula for action '${op.name}' is undefined`); if (growthF === undefined) throw new Error(`growth formula for action '${op.name}' is undefined`);
if (growthF !== undefined) { if (growthF !== undefined) {

@ -74,7 +74,7 @@ export function GeneralActionElem(props: IProps): React.ReactElement {
<CopyableText value={props.action.name} /> <CopyableText value={props.action.name} />
<StartButton <StartButton
bladeburner={props.bladeburner} bladeburner={props.bladeburner}
type={ActionTypes[props.action.name as string]} type={ActionTypes[props.action.name ]}
name={props.action.name} name={props.action.name}
rerender={rerender} rerender={rerender}
/> />

@ -22,7 +22,7 @@ export function Augmentations(props: IProps): React.ReactElement {
const [augmentation, setAugmentation] = useState("Augmented Targeting I"); const [augmentation, setAugmentation] = useState("Augmented Targeting I");
function setAugmentationDropdown(event: SelectChangeEvent<string>): void { function setAugmentationDropdown(event: SelectChangeEvent<string>): void {
setAugmentation(event.target.value as string); setAugmentation(event.target.value );
} }
function queueAug(): void { function queueAug(): void {
props.player.queueAugmentation(augmentation); props.player.queueAugmentation(augmentation);

@ -15,7 +15,7 @@ import { CodingContractTypes } from "../../CodingContracts";
export function CodingContracts(): React.ReactElement { export function CodingContracts(): React.ReactElement {
const [codingcontract, setCodingcontract] = useState("Find Largest Prime Factor"); const [codingcontract, setCodingcontract] = useState("Find Largest Prime Factor");
function setCodingcontractDropdown(event: SelectChangeEvent<string>): void { function setCodingcontractDropdown(event: SelectChangeEvent<string>): void {
setCodingcontract(event.target.value as string); setCodingcontract(event.target.value );
} }
function specificContract(): void { function specificContract(): void {

@ -18,7 +18,7 @@ const bigNumber = 1e12;
export function Companies(): React.ReactElement { export function Companies(): React.ReactElement {
const [company, setCompany] = useState(FactionNames.ECorp as string); const [company, setCompany] = useState(FactionNames.ECorp as string);
function setCompanyDropdown(event: SelectChangeEvent<string>): void { function setCompanyDropdown(event: SelectChangeEvent<string>): void {
setCompany(event.target.value as string); setCompany(event.target.value );
} }
function resetCompanyRep(): void { function resetCompanyRep(): void {
AllCompanies[company].playerReputation = 0; AllCompanies[company].playerReputation = 0;

@ -29,7 +29,7 @@ export function Factions(props: IProps): React.ReactElement {
const [faction, setFaction] = useState(FactionNames.Illuminati as string); const [faction, setFaction] = useState(FactionNames.Illuminati as string);
function setFactionDropdown(event: SelectChangeEvent<string>): void { function setFactionDropdown(event: SelectChangeEvent<string>): void {
setFaction(event.target.value as string); setFaction(event.target.value );
} }
function receiveInvite(): void { function receiveInvite(): void {

@ -19,7 +19,7 @@ interface IProps {
export function Programs(props: IProps): React.ReactElement { export function Programs(props: IProps): React.ReactElement {
const [program, setProgram] = useState("NUKE.exe"); const [program, setProgram] = useState("NUKE.exe");
function setProgramDropdown(event: SelectChangeEvent<string>): void { function setProgramDropdown(event: SelectChangeEvent<string>): void {
setProgram(event.target.value as string); setProgram(event.target.value );
} }
function addProgram(): void { function addProgram(): void {
if (!props.player.hasProgram(program)) { if (!props.player.hasProgram(program)) {

@ -6,20 +6,13 @@ import AccordionDetails from "@mui/material/AccordionDetails";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { saveObject } from "../../SaveObject"; import { saveObject } from "../../SaveObject";
import { SnackbarEvents, ToastVariant } from "../../ui/React/Snackbar"; import { SnackbarEvents, ToastVariant } from "../../ui/React/Snackbar";
import { Upload } from "@mui/icons-material"; import { Upload } from "@mui/icons-material";
import { Button } from "@mui/material"; import { Button } from "@mui/material";
import { OptionSwitch } from "../../ui/React/OptionSwitch"; import { OptionSwitch } from "../../ui/React/OptionSwitch";
// Update as additional BitNodes get implemented export function SaveFile(): React.ReactElement {
interface IProps {
player: IPlayer;
}
export function SaveFile(props: IProps): React.ReactElement {
const importInput = useRef<HTMLInputElement>(null); const importInput = useRef<HTMLInputElement>(null);
const [saveFile, setSaveFile] = useState(""); const [saveFile, setSaveFile] = useState("");
const [restoreScripts, setRestoreScripts] = useState(true); const [restoreScripts, setRestoreScripts] = useState(true);

@ -15,7 +15,7 @@ import MenuItem from "@mui/material/MenuItem";
export function Servers(): React.ReactElement { export function Servers(): React.ReactElement {
const [server, setServer] = useState("home"); const [server, setServer] = useState("home");
function setServerDropdown(event: SelectChangeEvent<string>): void { function setServerDropdown(event: SelectChangeEvent<string>): void {
setServer(event.target.value as string); setServer(event.target.value );
} }
function rootServer(): void { function rootServer(): void {
const s = GetServer(server); const s = GetServer(server);

@ -8,8 +8,8 @@ export function Unclickable(): React.ReactElement {
function unclickable(event: React.MouseEvent<HTMLDivElement>): void { function unclickable(event: React.MouseEvent<HTMLDivElement>): void {
if (!event.target || !(event.target instanceof Element)) return; if (!event.target || !(event.target instanceof Element)) return;
const display = getComputedStyle(event.target as Element).display; const display = getComputedStyle(event.target ).display;
const visibility = getComputedStyle(event.target as Element).visibility; const visibility = getComputedStyle(event.target ).visibility;
if (display === "none" && visibility === "hidden" && event.isTrusted) player.giveExploit(Exploit.Unclickable); if (display === "none" && visibility === "hidden" && event.isTrusted) player.giveExploit(Exploit.Unclickable);
} }

@ -54,8 +54,8 @@ export const CurrentOptionsPage = (props: IProps): React.ReactElement => {
} }
function handleLocaleChange(event: SelectChangeEvent<string>): void { function handleLocaleChange(event: SelectChangeEvent<string>): void {
setLocale(event.target.value as string); setLocale(event.target.value );
Settings.Locale = event.target.value as string; Settings.Locale = event.target.value ;
} }
function handleTimestampFormatChange(event: React.ChangeEvent<HTMLInputElement>): void { function handleTimestampFormatChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -54,7 +54,7 @@ export function HacknetNodeElem(props: IProps): React.ReactElement {
multiplier = getMaxNumberLevelUpgrades(props.player, node, HacknetNodeConstants.MaxLevel); multiplier = getMaxNumberLevelUpgrades(props.player, node, HacknetNodeConstants.MaxLevel);
} else { } else {
const levelsToMax = HacknetNodeConstants.MaxLevel - node.level; const levelsToMax = HacknetNodeConstants.MaxLevel - node.level;
multiplier = Math.min(levelsToMax, purchaseMult as number); multiplier = Math.min(levelsToMax, purchaseMult );
} }
const increase = const increase =
@ -94,7 +94,7 @@ export function HacknetNodeElem(props: IProps): React.ReactElement {
multiplier = getMaxNumberRamUpgrades(props.player, node, HacknetNodeConstants.MaxRam); multiplier = getMaxNumberRamUpgrades(props.player, node, HacknetNodeConstants.MaxRam);
} else { } else {
const levelsToMax = Math.round(Math.log2(HacknetNodeConstants.MaxRam / node.ram)); const levelsToMax = Math.round(Math.log2(HacknetNodeConstants.MaxRam / node.ram));
multiplier = Math.min(levelsToMax, purchaseMult as number); multiplier = Math.min(levelsToMax, purchaseMult );
} }
const increase = const increase =
@ -144,7 +144,7 @@ export function HacknetNodeElem(props: IProps): React.ReactElement {
multiplier = getMaxNumberCoreUpgrades(props.player, node, HacknetNodeConstants.MaxCores); multiplier = getMaxNumberCoreUpgrades(props.player, node, HacknetNodeConstants.MaxCores);
} else { } else {
const levelsToMax = HacknetNodeConstants.MaxCores - node.cores; const levelsToMax = HacknetNodeConstants.MaxCores - node.cores;
multiplier = Math.min(levelsToMax, purchaseMult as number); multiplier = Math.min(levelsToMax, purchaseMult );
} }
const increase = const increase =

@ -257,7 +257,7 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
function getMaterial(divisionName: string, cityName: string, materialName: string): Material { function getMaterial(divisionName: string, cityName: string, materialName: string): Material {
const warehouse = getWarehouse(divisionName, cityName); const warehouse = getWarehouse(divisionName, cityName);
const matName = (materialName as string).replace(/ /g, ""); const matName = (materialName ).replace(/ /g, "");
const material = warehouse.materials[matName]; const material = warehouse.materials[matName];
if (material === undefined) throw new Error(`Invalid material name: '${materialName}'`); if (material === undefined) throw new Error(`Invalid material name: '${materialName}'`);
return material; return material;

@ -1,5 +1,4 @@
import { INetscriptHelper } from "./INetscriptHelper"; import { INetscriptHelper } from "./INetscriptHelper";
import { WorkerScript } from "../Netscript/WorkerScript";
import { IPlayer } from "../PersonObjects/IPlayer"; import { IPlayer } from "../PersonObjects/IPlayer";
import { calculateServerGrowth } from "../Server/formulas/grow"; import { calculateServerGrowth } from "../Server/formulas/grow";
import { import {

@ -606,7 +606,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
_ctx.log(() => "cannot backdoor this kind of server"); _ctx.log(() => "cannot backdoor this kind of server");
return Promise.resolve(); return Promise.resolve();
} }
const server = baseserver as Server; const server = baseserver ;
const installTime = (calculateHackingTime(server, player) / 4) * 1000; const installTime = (calculateHackingTime(server, player) / 4) * 1000;
// No root access or skill level too low // No root access or skill level too low

@ -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.`); 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); 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({ PromptEvent.emit({
txt: `Do you want to save changes to ${closingScript.fileName} on ${closingScript.hostname}?`, txt: `Do you want to save changes to ${closingScript.fileName} on ${closingScript.hostname}?`,
resolve: (result: boolean | string) => { resolve: (result: boolean | string) => {

@ -36,7 +36,7 @@ function toNumber(n: number | IMinMaxRange): number {
return n; return n;
} }
case "object": { case "object": {
const range = n as IMinMaxRange; const range = n ;
value = getRandomInt(range.min, range.max); value = getRandomInt(range.min, range.max);
break; break;
} }

@ -68,7 +68,7 @@ export function placeOrder(
// Process to see if it should be executed immediately // Process to see if it should be executed immediately
const processOrderRefs = { const processOrderRefs = {
stockMarket: StockMarket as IStockMarket, stockMarket: StockMarket ,
symbolToStockMap: SymbolToStockMap, symbolToStockMap: SymbolToStockMap,
}; };
processOrders(stock, order.type, order.pos, processOrderRefs); processOrders(stock, order.type, order.pos, processOrderRefs);

@ -84,7 +84,7 @@ export function mv(
script.filename = destPath; script.filename = destPath;
} else if (srcFile instanceof TextFile) { } else if (srcFile instanceof TextFile) {
const textFile = srcFile as TextFile; const textFile = srcFile ;
if (!dest.endsWith(".txt")) { if (!dest.endsWith(".txt")) {
terminal.error(`Source and destination files must have the same type`); terminal.error(`Source and destination files must have the same type`);
return; return;

@ -121,7 +121,7 @@ export function getTextFile(fn: string, server: BaseServer): TextFile | null {
filename = removeLeadingSlash(filename); filename = removeLeadingSlash(filename);
} }
for (const file of server.textFiles as TextFile[]) { for (const file of server.textFiles ) {
if (file.fn === filename) { if (file.fn === filename) {
return file; return file;
} }

@ -4,8 +4,5 @@ import { getRandomByte } from "./helpers/getRandomByte";
* Generate a random IP address * Generate a random IP address
* Does not check to see if the IP already exists in the game * Does not check to see if the IP already exists in the game
*/ */
export function createRandomIp(): string { export const createRandomIp = (): string =>
const ip: string = getRandomByte(99) + "." + getRandomByte(9) + "." + getRandomByte(9) + "." + getRandomByte(9); `${getRandomByte(99)}.${getRandomByte(9)}.${getRandomByte(9)}.${getRandomByte(9)}`;
return ip;
}

@ -6,7 +6,6 @@ import { Company } from "../../src/Company/Company";
import { Server } from "../../src/Server/Server"; import { Server } from "../../src/Server/Server";
import { buyStock, sellStock, shortStock, sellShort } from "../../src/StockMarket/BuyingAndSelling"; import { buyStock, sellStock, shortStock, sellShort } from "../../src/StockMarket/BuyingAndSelling";
import { IStockMarket } from "../../src/StockMarket/IStockMarket";
import { Order } from "../../src/StockMarket/Order"; import { Order } from "../../src/StockMarket/Order";
import { import {
forecastForecastChangeFromCompanyWork, forecastForecastChangeFromCompanyWork,
@ -1149,7 +1148,7 @@ describe("Stock Market Tests", function () {
Player.setMoney(100e9); Player.setMoney(100e9);
processOrdersRefs = { processOrdersRefs = {
stockMarket: StockMarket as IStockMarket, stockMarket: StockMarket,
symbolToStockMap: SymbolToStockMap, symbolToStockMap: SymbolToStockMap,
}; };
}); });

4
tools/tsconfig.json Normal file

@ -0,0 +1,4 @@
{
"extends": "../tsconfig.json",
"include": ["**/*.js"]
}