Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CODEBASE: Fix lint errors 1 #1732

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-explicit-any": "off",
"react/no-unescaped-entities": "off",
"@typescript-eslint/restrict-template-expressions": "off",
},
settings: {
react: {
Expand Down
17 changes: 17 additions & 0 deletions src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,21 @@ declare global {
};
};
}

/**
* "loader" is not exposed in the public API.
*/
module "monaco-editor" {
namespace languages {
interface ILanguageExtensionPoint {
loader: () => Promise<{
language: {
tokenizer: {
root: any[];
};
};
}>;
}
}
}
}
2 changes: 1 addition & 1 deletion src/CodingContractGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function sanitizeRewardType(rewardType: CodingContractRewardType): CodingContrac
try {
return Factions[fac].getInfo().offerHackingWork;
} catch (e) {
console.error(`Error when trying to filter Hacking Factions for Coding Contract Generation: ${e}`);
console.error("Error when trying to filter Hacking Factions for Coding Contract Generation", e);
return false;
}
});
Expand Down
25 changes: 14 additions & 11 deletions src/Corporation/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ export function sellMaterial(material: Material, amount: string, price: string):
try {
if (temp.includes("MP")) throw "Only one reference to MP is allowed in sell price.";
temp = eval?.(temp);
} catch (e) {
throw new Error("Invalid value or expression for sell price field: " + e);
} catch (error) {
throw new Error("Invalid value or expression for sell price field", { cause: error });
}

if (temp == null || isNaN(parseFloat(temp))) {
Expand All @@ -231,8 +231,8 @@ export function sellMaterial(material: Material, amount: string, price: string):
tempQty = tempQty.replace(/INV/g, material.productionAmount.toString());
try {
tempQty = eval?.(tempQty);
} catch (e) {
throw new Error("Invalid value or expression for sell quantity field: " + e);
} catch (error) {
throw new Error("Invalid value or expression for sell quantity field", { cause: error });
}

if (tempQty == null || isNaN(parseFloat(tempQty))) {
Expand Down Expand Up @@ -263,8 +263,8 @@ export function sellProduct(product: Product, city: CityName, amt: string, price
try {
if (temp.includes("MP")) throw "Only one reference to MP is allowed in sell price.";
temp = eval?.(temp);
} catch (e) {
throw new Error("Invalid value or expression for sell price field: " + e);
} catch (error) {
throw new Error("Invalid value or expression for sell price field.", { cause: error });
}
if (temp == null || isNaN(parseFloat(temp))) {
throw new Error("Invalid value or expression for sell price field.");
Expand All @@ -291,8 +291,8 @@ export function sellProduct(product: Product, city: CityName, amt: string, price
temp = temp.replace(/INV/g, product.cityData[city].stored.toString());
try {
temp = eval?.(temp);
} catch (e) {
throw new Error("Invalid value or expression for sell quantity field: " + e);
} catch (error) {
throw new Error("Invalid value or expression for sell quantity field", { cause: error });
}

if (temp == null || isNaN(parseFloat(temp))) {
Expand Down Expand Up @@ -585,13 +585,16 @@ Attempted export amount: ${amount}`);
}
if (!error && isNaN(evaluated)) error = "evaluated value is NaN";
if (error) {
throw new Error(`Error while trying to set the exported amount of ${material.name}.
throw new Error(
`Error while trying to set the exported amount of ${material.name}.
Error occurred while testing keyword replacement with ${testReplacement}.
Your input: ${amount}
Sanitized input: ${sanitizedAmt}
Input after replacement: ${replaced}
Evaluated value: ${evaluated}
Error encountered: ${error}`);
Evaluated value: ${evaluated}` +
// eslint-disable-next-line @typescript-eslint/no-base-to-string
`Error encountered: ${error}`,
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Corporation/ui/ExpandNewCity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export function ExpandNewCity(props: IProps): React.ReactElement {
function expand(): void {
try {
purchaseOffice(corp, division, city);
} catch (err) {
dialogBoxCreate(err + "");
} catch (error) {
dialogBoxCreate(String(error));
catloversg marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Corporation/ui/NewDivisionTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export function NewDivisionTab(props: IProps): React.ReactElement {
if (disabledText) return;
try {
createDivision(corp, industry, name);
} catch (err) {
dialogBoxCreate(err + "");
} catch (error) {
dialogBoxCreate(String(error));
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Corporation/ui/modals/BuybackSharesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export function BuybackSharesModal(props: IProps): React.ReactElement {
props.onClose();
props.rerender();
setShares(NaN);
} catch (err) {
dialogBoxCreate(`${err}`);
} catch (error) {
dialogBoxCreate(String(error));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Corporation/ui/modals/ExportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export function ExportModal(props: ExportModalProps): React.ReactElement {
try {
if (!targetDivision || !targetCity) return;
actions.exportMaterial(targetDivision, targetCity, props.mat, exportAmount);
} catch (err) {
dialogBoxCreate(err + "");
} catch (error) {
dialogBoxCreate(String(error));
}
props.onClose();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Corporation/ui/modals/FindInvestorsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export function FindInvestorsModal(props: IProps): React.ReactElement {
);
props.onClose();
props.rerender();
} catch (err) {
dialogBoxCreate(`${err}`);
} catch (error) {
dialogBoxCreate(String(error));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Corporation/ui/modals/GoPublicModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export function GoPublicModal(props: IProps): React.ReactElement {
props.onClose();
props.rerender();
setShares(NaN);
} catch (err) {
dialogBoxCreate(`${err}`);
} catch (error) {
dialogBoxCreate(String(error));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Corporation/ui/modals/IssueDividendsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export function IssueDividendsModal(props: IProps): React.ReactElement {
if (percent === null) return;
try {
actions.issueDividends(corp, percent / 100);
} catch (err) {
dialogBoxCreate(err + "");
} catch (error) {
dialogBoxCreate(String(error));
}

props.onClose();
Expand Down
4 changes: 2 additions & 2 deletions src/Corporation/ui/modals/IssueNewSharesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export function IssueNewSharesModal(props: IProps): React.ReactElement {
);
props.onClose();
props.rerender();
} catch (err) {
dialogBoxCreate(`${err}`);
} catch (error) {
dialogBoxCreate(String(error));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Corporation/ui/modals/MakeProductModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export function MakeProductModal(props: IProps): React.ReactElement {
if (isNaN(design) || isNaN(marketing)) return;
try {
actions.makeProduct(corp, division, city, name, design, marketing);
} catch (err) {
dialogBoxCreate(err + "");
} catch (error) {
dialogBoxCreate(String(error));
}
props.onClose();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Corporation/ui/modals/PurchaseMaterialModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ function BulkPurchaseSection(props: IBPProps): React.ReactElement {
function bulkPurchase(): void {
try {
actions.bulkPurchase(corp, division, props.warehouse, props.mat, parseFloat(buyAmt));
} catch (err) {
dialogBoxCreate(err + "");
} catch (error) {
dialogBoxCreate(String(error));
}
props.onClose();
}
Expand Down Expand Up @@ -119,8 +119,8 @@ export function PurchaseMaterialModal(props: IProps): React.ReactElement {
if (buyAmt === null) return;
try {
actions.buyMaterial(division, props.mat, buyAmt);
} catch (err) {
dialogBoxCreate(err + "");
} catch (error) {
dialogBoxCreate(String(error));
}

props.onClose();
Expand Down
4 changes: 2 additions & 2 deletions src/Corporation/ui/modals/ResearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ function Upgrade({ n, division }: INodeProps): React.ReactElement {
if (n === null || disabled) return;
try {
actions.research(division, n.researchName);
} catch (err) {
dialogBoxCreate(err + "");
} catch (error) {
dialogBoxCreate(String(error));
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Corporation/ui/modals/SellMaterialModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function SellMaterialModal(props: IProps): React.ReactElement {
function sellMaterial(): void {
try {
actions.sellMaterial(props.mat, amt, price);
} catch (err) {
dialogBoxCreate(err + "");
} catch (error) {
dialogBoxCreate(String(error));
}
props.onClose();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Corporation/ui/modals/SellProductModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export function SellProductModal(props: IProps): React.ReactElement {
function sellProduct(): void {
try {
actions.sellProduct(props.product, props.city, iQty, px, checked);
} catch (err) {
dialogBoxCreate(err + "");
} catch (error) {
dialogBoxCreate(String(error));
}

props.onClose();
Expand Down
10 changes: 6 additions & 4 deletions src/Corporation/ui/modals/SmartSupplyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ function SSoption(props: ISSoptionProps): React.ReactElement {
const matName = props.matName;
const material = props.warehouse.materials[matName];
setSmartSupplyOption(props.warehouse, material, newValue);
} catch (err) {
dialogBoxCreate(err + "");
} catch (error) {
dialogBoxCreate(String(error));
return;
}
setChecked(newValue);
}
Expand All @@ -40,8 +41,9 @@ function SSoption(props: ISSoptionProps): React.ReactElement {
const matName = props.matName;
const material = props.warehouse.materials[matName];
setSmartSupplyOption(props.warehouse, material, newValue);
} catch (err) {
dialogBoxCreate(err + "");
} catch (error) {
dialogBoxCreate(String(error));
return;
}
setChecked(newValue);
}
Expand Down
50 changes: 27 additions & 23 deletions src/Electron.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CONSTANTS } from "./Constants";
import { commitHash } from "./utils/helpers/commitHash";
import { resolveFilePath } from "./Paths/FilePath";
import { hasScriptExtension } from "./Paths/ScriptFilePath";
import { handleGetSaveDataError } from "./Netscript/ErrorMessages";
import { handleGetSaveDataInfoError } from "./Netscript/ErrorMessages";

interface IReturnWebStatus extends IReturnStatus {
data?: Record<string, unknown>;
Expand Down Expand Up @@ -103,14 +103,14 @@ function initAppNotifier(): void {
const funcs = {
terminal: (message: string, type?: string) => {
const typesFn: Record<string, (s: string) => void> = {
info: Terminal.info,
warn: Terminal.warn,
error: Terminal.error,
success: Terminal.success,
info: (s) => Terminal.info(s),
warn: (s) => Terminal.warn(s),
error: (s) => Terminal.error(s),
success: (s) => Terminal.success(s),
};
let fn;
if (type) fn = typesFn[type];
if (!fn) fn = Terminal.print;
if (!fn) fn = (s: string) => Terminal.print(s);
fn.bind(Terminal)(message);
},
toast: (message: string, type: ToastVariant, duration = 2000) => SnackbarEvents.emit(message, type, duration),
Expand All @@ -124,12 +124,10 @@ function initSaveFunctions(): void {
const funcs = {
triggerSave: (): Promise<void> => saveObject.saveGame(true),
triggerGameExport: (): void => {
try {
saveObject.exportGame();
} catch (error) {
saveObject.exportGame().catch((error) => {
console.error(error);
SnackbarEvents.emit("Could not export game.", ToastVariant.ERROR, 2000);
}
});
},
triggerScriptsExport: (): void => exportScripts("*", Player.getHomeComputer()),
getSaveData: async (): Promise<{ save: SaveData; fileName: string }> => {
Expand Down Expand Up @@ -159,30 +157,36 @@ function initElectronBridge(): void {
const bridge = window.electronBridge;
if (!bridge) return;

bridge.receive("get-save-data-request", async () => {
let saveData;
try {
saveData = await window.appSaveFns.getSaveData();
} catch (error) {
handleGetSaveDataError(error);
return;
}
bridge.send("get-save-data-response", saveData);
bridge.receive("get-save-data-request", () => {
window.appSaveFns
.getSaveData()
.then((saveData) => {
bridge.send("get-save-data-response", saveData);
})
.catch((error) => {
handleGetSaveDataInfoError(error);
});
});
bridge.receive("get-save-info-request", async (saveData: unknown) => {
bridge.receive("get-save-info-request", (saveData: unknown) => {
if (typeof saveData !== "string" && !(saveData instanceof Uint8Array)) {
throw new Error("Error while trying to get save info");
}
const saveInfo = await window.appSaveFns.getSaveInfo(saveData);
bridge.send("get-save-info-response", saveInfo);
window.appSaveFns
.getSaveInfo(saveData)
.then((saveInfo) => {
bridge.send("get-save-info-response", saveInfo);
})
.catch((error) => {
handleGetSaveDataInfoError(error, true);
});
});
bridge.receive("push-save-request", (params: unknown) => {
if (typeof params !== "object") throw new Error("Error trying to push save request");
const { save, automatic = false } = params as { save: string; automatic: boolean };
window.appSaveFns.pushSaveData(save, automatic);
});
bridge.receive("trigger-save", () => {
return window.appSaveFns
window.appSaveFns
.triggerSave()
.then(() => {
bridge.send("save-completed");
Expand Down
2 changes: 1 addition & 1 deletion src/Faction/ui/FactionRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function MainPage({ faction, rerender, onAugmentations }: IMainProps): React.Rea
startWork();
}

// We have a special flag for whether the player this faction is the player's
// We have a special flag for whether this faction is the player's
// gang faction because if the player has a gang, they cannot do any other action
const isPlayersGang = Player.gang && Player.getGangName() === faction.name;

Expand Down
1 change: 1 addition & 0 deletions src/GameOptions/ui/GameOptionsSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const GameOptionsSidebar = (props: IProps): React.ReactElement => {
try {
await saveObject.importGame(importData.saveData);
} catch (e: unknown) {
console.error(e);
SnackbarEvents.emit(String(e), ToastVariant.ERROR, 5000);
}

Expand Down
Loading