From f2c07c013708ab5eb41dbeeafa74b970c19c9748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mart=C3=ADnek?= <96337712+Michal-Martinek@users.noreply.github.com> Date: Fri, 5 Sep 2025 22:55:13 +0200 Subject: [PATCH 1/3] Enabled `@typescript-eslint/no-unused-expressions` eslint rule --- eslint.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/eslint.config.js b/eslint.config.js index c707ee03e5..3caf4b48d0 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -40,7 +40,6 @@ export default [ rules: { // Disable rules that would fail. The failures should be fixed, and the entries here removed. "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-unused-expressions": "off", "no-unused-vars": "off", }, }, From 420e1eed9e2d1d4aaafae01b10a81887c52c0d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mart=C3=ADnek?= <96337712+Michal-Martinek@users.noreply.github.com> Date: Fri, 5 Sep 2025 22:59:17 +0200 Subject: [PATCH 2/3] Replace shortcircuiting && expressions with explicit if statements --- src/client/graphics/layers/EventsDisplay.ts | 4 ++-- src/client/graphics/layers/StructureIconsLayer.ts | 4 +++- src/core/execution/RailroadExecution.ts | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/client/graphics/layers/EventsDisplay.ts b/src/client/graphics/layers/EventsDisplay.ts index a9b8c85e1d..31ef319b2c 100644 --- a/src/client/graphics/layers/EventsDisplay.ts +++ b/src/client/graphics/layers/EventsDisplay.ts @@ -1051,7 +1051,7 @@ export class EventsDisplay extends LitElement implements Layer { ? this.renderButton({ content: this.getEventDescription(event), onClick: () => { - event.focusID && + if (event.focusID) this.emitGoToPlayerEvent(event.focusID); }, className: "text-left", @@ -1060,7 +1060,7 @@ export class EventsDisplay extends LitElement implements Layer { ? this.renderButton({ content: this.getEventDescription(event), onClick: () => { - event.unitView && + if (event.unitView) this.emitGoToUnitEvent( event.unitView, ); diff --git a/src/client/graphics/layers/StructureIconsLayer.ts b/src/client/graphics/layers/StructureIconsLayer.ts index df66344616..4f86c80703 100644 --- a/src/client/graphics/layers/StructureIconsLayer.ts +++ b/src/client/graphics/layers/StructureIconsLayer.ts @@ -255,7 +255,9 @@ export class StructureIconsLayer implements Layer { this.potentialUpgrade.iconContainer.filters = []; this.potentialUpgrade.dotContainer.filters = []; } - this.ghostUnit?.container && (this.ghostUnit.container.filters = []); + if (this.ghostUnit?.container) { + this.ghostUnit.container.filters = []; + } if (!this.ghostUnit) return; diff --git a/src/core/execution/RailroadExecution.ts b/src/core/execution/RailroadExecution.ts index 55f88760d4..97bc8d1d97 100644 --- a/src/core/execution/RailroadExecution.ts +++ b/src/core/execution/RailroadExecution.ts @@ -164,7 +164,7 @@ export class RailroadExecution implements Execution { } private redrawBuildings() { - this.railRoad.from.unit.isActive() && this.railRoad.from.unit.touch(); - this.railRoad.to.unit.isActive() && this.railRoad.to.unit.touch(); + if (this.railRoad.from.unit.isActive()) this.railRoad.from.unit.touch(); + if (this.railRoad.to.unit.isActive()) this.railRoad.to.unit.touch(); } } From 086a58ffb079051358e7722ca6f47aaf83ccfe68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mart=C3=ADnek?= <96337712+Michal-Martinek@users.noreply.github.com> Date: Fri, 5 Sep 2025 23:16:50 +0200 Subject: [PATCH 3/3] Using results of 'instanceof' check expressions Currently raising `console.warn` on fauilure --- src/client/Main.ts | 53 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/src/client/Main.ts b/src/client/Main.ts index d5acbe4ab3..07d36fbc90 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -106,10 +106,9 @@ class Client { gameVersion.innerText = version; const newsModal = document.querySelector("news-modal") as NewsModal; - if (!newsModal) { + if (!newsModal || !(newsModal instanceof NewsModal)) { console.warn("News modal element not found"); } - newsModal instanceof NewsModal; const newsButton = document.querySelector("news-button") as NewsButton; if (!newsButton) { console.warn("News button element not found"); @@ -168,7 +167,9 @@ class Client { const spModal = document.querySelector( "single-player-modal", ) as SinglePlayerModal; - spModal instanceof SinglePlayerModal; + if (!spModal || !(spModal instanceof SinglePlayerModal)) { + console.warn("Singleplayer modal element not found"); + } const singlePlayer = document.getElementById("single-player"); if (singlePlayer === null) throw new Error("Missing single-player"); @@ -185,7 +186,9 @@ class Client { // }); const hlpModal = document.querySelector("help-modal") as HelpModal; - hlpModal instanceof HelpModal; + if (!hlpModal || !(hlpModal instanceof HelpModal)) { + console.warn("Help modal element not found"); + } const helpButton = document.getElementById("help-button"); if (helpButton === null) throw new Error("Missing help-button"); helpButton.addEventListener("click", () => { @@ -195,7 +198,10 @@ class Client { const flagInputModal = document.querySelector( "flag-input-modal", ) as FlagInputModal; - flagInputModal instanceof FlagInputModal; + if (!flagInputModal || !(flagInputModal instanceof FlagInputModal)) { + console.warn("Flag input modal element not found"); + } + const flgInput = document.getElementById("flag-input_"); if (flgInput === null) throw new Error("Missing flag-input_"); flgInput.addEventListener("click", () => { @@ -205,6 +211,12 @@ class Client { this.patternsModal = document.querySelector( "territory-patterns-modal", ) as TerritoryPatternsModal; + if ( + !this.patternsModal || + !(this.patternsModal instanceof TerritoryPatternsModal) + ) { + console.warn("Territory patterns modal element not found"); + } const patternButton = document.getElementById( "territory-patterns-input-preview-button", ); @@ -212,7 +224,12 @@ class Client { patternButton.style.display = "none"; } - this.patternsModal instanceof TerritoryPatternsModal; + if ( + !this.patternsModal || + !(this.patternsModal instanceof TerritoryPatternsModal) + ) { + console.warn("Territory patterns modal element not found"); + } if (patternButton === null) throw new Error("territory-patterns-input-preview-button"); this.patternsModal.previewButton = patternButton; @@ -224,7 +241,12 @@ class Client { this.tokenLoginModal = document.querySelector( "token-login", ) as TokenLoginModal; - this.tokenLoginModal instanceof TokenLoginModal; + if ( + !this.tokenLoginModal || + !(this.tokenLoginModal instanceof TokenLoginModal) + ) { + console.warn("Token login modal element not found"); + } const onUserMe = async (userMeResponse: UserMeResponse | false) => { document.dispatchEvent( @@ -335,7 +357,9 @@ class Client { const settingsModal = document.querySelector( "user-setting", ) as UserSettingModal; - settingsModal instanceof UserSettingModal; + if (!settingsModal || !(settingsModal instanceof UserSettingModal)) { + console.warn("User settings modal element not found"); + } document .getElementById("settings-button") ?.addEventListener("click", () => { @@ -345,7 +369,9 @@ class Client { const hostModal = document.querySelector( "host-lobby-modal", ) as HostPrivateLobbyModal; - hostModal instanceof HostPrivateLobbyModal; + if (!hostModal || !(hostModal instanceof HostPrivateLobbyModal)) { + console.warn("Host private lobby modal element not found"); + } const hostLobbyButton = document.getElementById("host-lobby-button"); if (hostLobbyButton === null) throw new Error("Missing host-lobby-button"); hostLobbyButton.addEventListener("click", () => { @@ -358,7 +384,9 @@ class Client { this.joinModal = document.querySelector( "join-private-lobby-modal", ) as JoinPrivateLobbyModal; - this.joinModal instanceof JoinPrivateLobbyModal; + if (!this.joinModal || !(this.joinModal instanceof JoinPrivateLobbyModal)) { + console.warn("Join private lobby modal element not found"); + } const joinPrivateLobbyButton = document.getElementById( "join-private-lobby-button", ); @@ -573,8 +601,9 @@ class Client { const startingModal = document.querySelector( "game-starting-modal", ) as GameStartingModal; - startingModal instanceof GameStartingModal; - startingModal.show(); + if (startingModal && startingModal instanceof GameStartingModal) { + startingModal.show(); + } }, () => { this.joinModal.close();