From 522413678a104578418f8e03c55362e1b9566908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mart=C3=ADnek?= <96337712+Michal-Martinek@users.noreply.github.com> Date: Tue, 14 Oct 2025 20:10:52 +0200 Subject: [PATCH] =?UTF-8?q?Enabled=20the=20`@typescript-eslint/no-unused-e?= =?UTF-8?q?xpressions`=C2=A0eslint=20rule=20(#2014)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description: - Fixes #1790 - Fixed the codebase: - expressions short-circuiting with `&&` changed to proper `if` statements - `A instanceof B;` expressions now emit warnings ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: michal7952 --------- Co-authored-by: Evan --- eslint.config.js | 1 - src/client/Main.ts | 53 ++++++++++++++----- src/client/graphics/layers/EventsDisplay.ts | 4 +- .../graphics/layers/StructureIconsLayer.ts | 4 +- src/core/execution/RailroadExecution.ts | 4 +- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index c707ee03e..3caf4b48d 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", }, }, diff --git a/src/client/Main.ts b/src/client/Main.ts index d5acbe4ab..07d36fbc9 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(); diff --git a/src/client/graphics/layers/EventsDisplay.ts b/src/client/graphics/layers/EventsDisplay.ts index a9b8c85e1..31ef319b2 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 df6634461..4f86c8070 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 55f88760d..97bc8d1d9 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(); } }