diff --git a/src/game/__tests__/dominion-lib-undo-canUndoAction.spec.ts b/src/game/__tests__/dominion-lib-undo-canUndoAction.spec.ts index 455506c..04225b7 100644 --- a/src/game/__tests__/dominion-lib-undo-canUndoAction.spec.ts +++ b/src/game/__tests__/dominion-lib-undo-canUndoAction.spec.ts @@ -40,7 +40,9 @@ describe('canUndoAction', () => { beforeEach(() => { jest.clearAllMocks(); - consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => { + // do nothing + }); removeTargetAndLinkedActionsSpy = jest.spyOn(undoHelpers, 'removeTargetAndLinkedActions'); reconstructGameStateSpy = jest.spyOn(undoHelpers, 'reconstructGameState'); }); diff --git a/src/game/__tests__/dominion-lib-undoAction.spec.ts b/src/game/__tests__/dominion-lib-undoAction.spec.ts index 8dc8008..0c04912 100644 --- a/src/game/__tests__/dominion-lib-undoAction.spec.ts +++ b/src/game/__tests__/dominion-lib-undoAction.spec.ts @@ -33,7 +33,9 @@ describe('undoAction', () => { beforeEach(() => { jest.clearAllMocks(); - consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => { + // do nothing + }); removeTargetAndLinkedActionsSpy = undoHelpers.removeTargetAndLinkedActions as jest.Mock; reconstructGameStateSpy = undoHelpers.reconstructGameState as jest.Mock; diff --git a/src/game/dominion-lib-load-save.ts b/src/game/dominion-lib-load-save.ts index f965aa5..b2de473 100644 --- a/src/game/dominion-lib-load-save.ts +++ b/src/game/dominion-lib-load-save.ts @@ -322,64 +322,74 @@ export function safeParseSavedGameMetadata(jsonString: string): ISavedGameMetada * @param game - The game object to validate * @returns Whether the game object is valid */ -export function isValidGame(game: any): game is IGame { - const isValidPlayer = (player: any): player is IPlayer => { +export function isValidGame(game: unknown): game is IGame { + if (typeof game !== 'object' || game === null) { + return false; + } + + const g = game as Record; + + const isValidPlayer = (player: unknown): player is IPlayer => { + if (typeof player !== 'object' || player === null) return false; + const p = player as Record; return ( - typeof player.name === 'string' && - typeof player.mats === 'object' && - typeof player.turn === 'object' && - typeof player.newTurn === 'object' && - typeof player.victory === 'object' + typeof p.name === 'string' && + typeof p.mats === 'object' && + typeof p.turn === 'object' && + typeof p.newTurn === 'object' && + typeof p.victory === 'object' ); }; - const isValidSupply = (supply: any): supply is IGameSupply => { + const isValidSupply = (supply: unknown): supply is IGameSupply => { + if (typeof supply !== 'object' || supply === null) return false; + const s = supply as Record; return ( - typeof supply === 'object' && - typeof supply.estates === 'number' && - typeof supply.duchies === 'number' && - typeof supply.provinces === 'number' && - typeof supply.coppers === 'number' && - typeof supply.silvers === 'number' && - typeof supply.golds === 'number' && - typeof supply.curses === 'number' && - typeof supply.colonies === 'number' && - typeof supply.platinums === 'number' + typeof s.estates === 'number' && + typeof s.duchies === 'number' && + typeof s.provinces === 'number' && + typeof s.coppers === 'number' && + typeof s.silvers === 'number' && + typeof s.golds === 'number' && + typeof s.curses === 'number' && + typeof s.colonies === 'number' && + typeof s.platinums === 'number' ); }; - const isValidOptions = (options: any): options is IGameOptions => { + const isValidOptions = (options: unknown): options is IGameOptions => { + if (typeof options !== 'object' || options === null) return false; + const o = options as Record; return ( - typeof options === 'object' && - typeof options.curses === 'boolean' && - typeof options.expansions === 'object' && - typeof options.mats === 'object' + typeof o.curses === 'boolean' && + typeof o.expansions === 'object' && + typeof o.mats === 'object' ); }; - const isValidLogEntry = (logEntry: any): logEntry is ILogEntry => { + const isValidLogEntry = (logEntry: unknown): logEntry is ILogEntry => { + if (typeof logEntry !== 'object' || logEntry === null) return false; + const l = logEntry as Record; return ( - typeof logEntry.id === 'string' && - logEntry.timestamp instanceof Date && - typeof logEntry.playerIndex === 'number' && - typeof logEntry.action === 'string' + typeof l.id === 'string' && + l.timestamp instanceof Date && + typeof l.playerIndex === 'number' && + typeof l.action === 'string' ); }; return ( - game !== null && - game !== undefined && - Array.isArray(game.players) && - game.players.every(isValidPlayer) && - isValidSupply(game.supply) && - isValidOptions(game.options) && - Array.isArray(game.log) && - game.log.every(isValidLogEntry) && - typeof game.currentTurn === 'number' && - typeof game.currentPlayerIndex === 'number' && - typeof game.firstPlayerIndex === 'number' && - typeof game.selectedPlayerIndex === 'number' && - typeof game.currentStep === 'number' && - typeof game.setsRequired === 'number' + Array.isArray(g.players) && + g.players.every(isValidPlayer) && + isValidSupply(g.supply) && + isValidOptions(g.options) && + Array.isArray(g.log) && + g.log.every(isValidLogEntry) && + typeof g.currentTurn === 'number' && + typeof g.currentPlayerIndex === 'number' && + typeof g.firstPlayerIndex === 'number' && + typeof g.selectedPlayerIndex === 'number' && + typeof g.currentStep === 'number' && + typeof g.setsRequired === 'number' ); } diff --git a/src/main.tsx b/src/main.tsx index cb48943..100e48b 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,3 +1,4 @@ +import React from 'react'; import { StrictMode } from 'react'; import * as ReactDOM from 'react-dom/client'; diff --git a/src/types/fonts.d.ts b/src/types/fonts.d.ts index 0b6cf02..732c3f8 100644 --- a/src/types/fonts.d.ts +++ b/src/types/fonts.d.ts @@ -1,9 +1,9 @@ declare module '*.ttf' { - const content: any; + const content: string; export default content; } declare module '*.otf' { - const content: any; + const content: string; export default content; } diff --git a/webpack.config.js b/webpack.config.js index 24550b5..45ebb35 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-require-imports */ const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin'); const { NxReactWebpackPlugin } = require('@nx/react/webpack-plugin'); const { join } = require('path');