From 57e72b01ae2a86a3bcf55d897af754bd90fcdddb Mon Sep 17 00:00:00 2001 From: Ralph Sennhauser Date: Sat, 14 Jun 2025 12:27:36 +0200 Subject: [PATCH] Enable eslint rule 'no-case-declarations' Enable recommended rule 'no-case-declarations' [1] and manually fix violations. [1] https://eslint.org/docs/latest/rules/no-case-declarations Ref: #8068 Signed-off-by: Ralph Sennhauser --- .../mods/public/autostart/autostart_host.js | 2 ++ .../public/gui/common/functions_utility.js | 2 ++ .../data/mods/public/gui/session/input.js | 23 +++++++++++++------ .../simulation/ai/petra/garrisonManager.js | 2 ++ .../components/PopulationCapManager.js | 3 ++- .../mods/public/simulation/helpers/Cheat.js | 5 +++- eslint.config.mjs | 1 + 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/binaries/data/mods/public/autostart/autostart_host.js b/binaries/data/mods/public/autostart/autostart_host.js index ff38fd62de..1374badaac 100644 --- a/binaries/data/mods/public/autostart/autostart_host.js +++ b/binaries/data/mods/public/autostart/autostart_host.js @@ -38,6 +38,7 @@ class AutoStartHost switch (message.type) { case "players": + { this.playerAssignments = message.newAssignments; Engine.SendNetworkReady(2); let max = 0; @@ -48,6 +49,7 @@ class AutoStartHost Engine.AssignNetworkPlayer(++max, uid); } break; + } case "ready": this.playerAssignments[message.guid].status = message.status; break; diff --git a/binaries/data/mods/public/gui/common/functions_utility.js b/binaries/data/mods/public/gui/common/functions_utility.js index 3f6474fdd7..fd2d417360 100644 --- a/binaries/data/mods/public/gui/common/functions_utility.js +++ b/binaries/data/mods/public/gui/common/functions_utility.js @@ -251,11 +251,13 @@ function resizeGUIObjectToCaption(object, align, margin = {}) objectSize.left = object.size.right - width; break; case "center": + { const oldWidth = object.size.right - object.size.left; const widthDiff = width - oldWidth; objectSize.right = object.size.right + (widthDiff / 2); objectSize.left = object.size.left - (widthDiff / 2); break; + } default: } } diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js index abf6c86497..b59ed42158 100644 --- a/binaries/data/mods/public/gui/session/input.js +++ b/binaries/data/mods/public/gui/session/input.js @@ -523,6 +523,7 @@ function handleInputBeforeGui(ev, hoveredObject) switch (inputState) { case INPUT_BANDBOXING: + { const bandbox = Engine.GetGUIObjectByName("bandbox"); switch (ev.type) { @@ -570,6 +571,7 @@ function handleInputBeforeGui(ev, hoveredObject) default: return false; } + } case INPUT_UNIT_POSITION: switch (ev.type) @@ -662,6 +664,7 @@ function handleInputBeforeGui(ev, hoveredObject) switch (ev.type) { case "mousemotion": + { placementSupport.wallEndPosition = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); // Update the structure placement preview, and by extension, the list of snapping candidate entities for both (!) @@ -686,7 +689,7 @@ function handleInputBeforeGui(ev, hoveredObject) } return false; - + } case "mousebuttondown": if (ev.button == SDL_BUTTON_LEFT) { @@ -730,6 +733,7 @@ function handleInputBeforeGui(ev, hoveredObject) switch (ev.type) { case "mousemotion": + { if (g_DragStart.distanceTo(ev) >= Math.square(getMaxDragDelta())) // Rotate in the direction of the cursor. placementSupport.angle = placementSupport.position.horizAngleTo(Engine.GetTerrainAtScreenPoint(ev.x, ev.y)); @@ -754,7 +758,7 @@ function handleInputBeforeGui(ev, hoveredObject) updateBuildingPlacementPreview(); return false; - + } case "mousebuttonup": if (ev.button == SDL_BUTTON_LEFT) { @@ -828,6 +832,7 @@ function handleInputAfterGui(ev) switch (ev.type) { case "mousemotion": + { const ent = Engine.PickEntityAtPoint(ev.x, ev.y); if (ent != INVALID_ENTITY) g_Selection.setHighlightList([ent]); @@ -835,7 +840,7 @@ function handleInputAfterGui(ev) g_Selection.setHighlightList([]); return false; - + } case "mousebuttondown": if (Engine.HotkeyIsPressed("session.flare") && !g_IsReplay) { @@ -891,6 +896,7 @@ function handleInputAfterGui(ev) switch (ev.type) { case "mousemotion": + { const ent = Engine.PickEntityAtPoint(ev.x, ev.y); if (ent != INVALID_ENTITY) g_Selection.setHighlightList([ent]); @@ -898,7 +904,7 @@ function handleInputAfterGui(ev) g_Selection.setHighlightList([]); return false; - + } case "mousebuttondown": if (ev.button == SDL_BUTTON_LEFT && preSelectedAction != ACTION_NONE) { @@ -932,6 +938,7 @@ function handleInputAfterGui(ev) switch (ev.type) { case "mousemotion": + { if (g_DragStart.distanceTo(ev) >= getMaxDragDelta()) { inputState = INPUT_BANDBOXING; @@ -944,7 +951,7 @@ function handleInputAfterGui(ev) else g_Selection.setHighlightList([]); return false; - + } case "mousebuttonup": if (ev.button == SDL_BUTTON_LEFT) { @@ -1124,7 +1131,7 @@ function handleInputAfterGui(ev) return false; case "hotkeydown": - + { const rotation_step = Math.PI / 12; // 24 clicks make a full rotation switch (ev.hotkey) @@ -1140,7 +1147,7 @@ function handleInputAfterGui(ev) default: return false; } - + } default: return false; } @@ -1629,6 +1636,7 @@ function performGroup(action, groupId) case "snap": case "select": case "add": + { const toSelect = []; g_Groups.update(); for (const ent in g_Groups.groups[groupId].ents) @@ -1647,6 +1655,7 @@ function performGroup(action, groupId) Engine.CameraMoveTo(position.x, position.z); } break; + } case "save": case "breakUp": g_Groups.groups[groupId].reset(); diff --git a/binaries/data/mods/public/simulation/ai/petra/garrisonManager.js b/binaries/data/mods/public/simulation/ai/petra/garrisonManager.js index c39ef121ab..5dffb8bcd4 100644 --- a/binaries/data/mods/public/simulation/ai/petra/garrisonManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/garrisonManager.js @@ -295,6 +295,7 @@ PETRA.GarrisonManager.prototype.keepGarrisoned = function(ent, holder, around) case PETRA.GarrisonManager.TYPE_TRADE: // trader garrisoned in ship return true; case PETRA.GarrisonManager.TYPE_PROTECTION: // hurt unit for healing or infantry for defense + { if (holder.buffHeal() && ent.isHealable() && ent.healthLevel() < this.Config.garrisonHealthLevel.high) return true; const capture = ent.capturePoints(); @@ -315,6 +316,7 @@ PETRA.GarrisonManager.prototype.keepGarrisoned = function(ent, holder, around) if (PETRA.isSiegeUnit(ent)) return around.meleeSiege; return holder.buffHeal() && ent.needsHeal(); + } case PETRA.GarrisonManager.TYPE_DECAY: return ent.captureStrength() && this.decayingStructures.has(holder.id()); case PETRA.GarrisonManager.TYPE_EMERGENCY: // f.e. hero in regicide mode diff --git a/binaries/data/mods/public/simulation/components/PopulationCapManager.js b/binaries/data/mods/public/simulation/components/PopulationCapManager.js index 139a1fdb29..ae8d64ff2b 100644 --- a/binaries/data/mods/public/simulation/components/PopulationCapManager.js +++ b/binaries/data/mods/public/simulation/components/PopulationCapManager.js @@ -152,11 +152,12 @@ PopulationCapManager.prototype.OnGlobalPlayerDefeated = function(msg) switch(this.popCapType) { case CAPTYPE_TEAM_POPULATION: + { const team = QueryPlayerIDInterface(msg.playerId, IID_Diplomacy).GetTeam(); if (team != -1) this.RedistributeTeamPopCap(team); break; - + } case CAPTYPE_WORLD_POPULATION: this.RedistributeWorldPopCap(); break; diff --git a/binaries/data/mods/public/simulation/helpers/Cheat.js b/binaries/data/mods/public/simulation/helpers/Cheat.js index 9eddfa733a..357b10d137 100644 --- a/binaries/data/mods/public/simulation/helpers/Cheat.js +++ b/binaries/data/mods/public/simulation/helpers/Cheat.js @@ -35,12 +35,14 @@ function Cheat(input) return; } case "convertunit": + { if (isNaN(input.parameter)) return; const playerID = (input.parameter > -1 && QueryPlayerIDInterface(input.parameter) || cmpPlayer).GetPlayerID(); for (const ent of input.selected) Engine.QueryInterface(ent, IID_Ownership)?.SetOwner(playerID); return; + } case "killunits": for (const ent of input.selected) { @@ -188,6 +190,7 @@ function Cheat(input) Cheat({ "player": input.player, "action": "changephase", "selected": input.selected }); return; case "playRetro": + { const play = input.parameter.toLowerCase() != "off"; cmpGuiInterface.PushNotification({ "type": "play-tracks", @@ -196,7 +199,7 @@ function Cheat(input) "players": [input.player] }); return; - + } default: warn("Cheat '" + input.action + "' is not implemented"); return; diff --git a/eslint.config.mjs b/eslint.config.mjs index c7cd7a099c..43067314d2 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -28,6 +28,7 @@ const configEslintRecommended = { "for-direction": "warn", "getter-return": "warn", "no-async-promise-executor": "warn", + "no-case-declarations": "warn", "no-class-assign": "warn", "no-compare-neg-zero": "warn", "no-cond-assign": "warn",