From f3ac9e966962b7d0f7361092130281a9636a6887 Mon Sep 17 00:00:00 2001 From: Ralph Sennhauser Date: Mon, 12 May 2025 21:26:08 +0200 Subject: [PATCH] Fix eslint rule 'default-case' Manual fixes needed for: eslint --no-config-lookup --rule '"default-case": 1' Ref: #7812 Signed-off-by: Ralph Sennhauser --- .../data/mods/mod/gui/common/utilities.js | 2 + .../mods/public/autostart/cmd_line_args.js | 2 + .../mods/public/globalscripts/Technologies.js | 5 +- .../mods/public/gui/loadgame/SavegameList.js | 2 + .../public/gui/replaymenu/replay_filters.js | 2 + .../data/mods/public/gui/session/input.js | 98 +++++++++++-------- .../public/gui/session/selection_panels.js | 6 ++ .../mods/public/gui/session/unit_actions.js | 2 + .../components/BuildRestrictions.js | 3 +- .../components/TechnologyManager.js | 10 +- 10 files changed, 84 insertions(+), 48 deletions(-) diff --git a/binaries/data/mods/mod/gui/common/utilities.js b/binaries/data/mods/mod/gui/common/utilities.js index 1bd887ef88..d32771c244 100644 --- a/binaries/data/mods/mod/gui/common/utilities.js +++ b/binaries/data/mods/mod/gui/common/utilities.js @@ -16,6 +16,8 @@ function distributeButtonsHorizontally(button, captions) button[1].size = "33%+5 " + y1 + " 66%-5 " + y2; button[2].size = "66%+5 " + y1 + " 100%-18 " + y2; break; + default: + error("distributeButtonsHorizontally does not yet support more than 3 buttons, attempting to use " + captions.length); } } diff --git a/binaries/data/mods/public/autostart/cmd_line_args.js b/binaries/data/mods/public/autostart/cmd_line_args.js index f4512d86b1..5c07834500 100644 --- a/binaries/data/mods/public/autostart/cmd_line_args.js +++ b/binaries/data/mods/public/autostart/cmd_line_args.js @@ -105,6 +105,8 @@ function parseCmdLineArgs(settings, cmdLineArgs) settings.mapExploration.setExplored(true); settings.mapExploration.setRevealed(false); break; + default: + warn("Unknown argument for option 'autostart-visibility': " + cmdLineArgs['autostart-visibility']); } } diff --git a/binaries/data/mods/public/globalscripts/Technologies.js b/binaries/data/mods/public/globalscripts/Technologies.js index b420a5c797..dd12859e69 100644 --- a/binaries/data/mods/public/globalscripts/Technologies.js +++ b/binaries/data/mods/public/globalscripts/Technologies.js @@ -294,7 +294,8 @@ function InterpretTechRequirements(civ, operator, value) } break; } - + default: + warn("Unknown requirement operator in 'all': " + newOper); } } if (civPermitted === false) // if and only if false @@ -347,6 +348,8 @@ function InterpretTechRequirements(civ, operator, value) requirements.push(res); break; + default: + warn("Unknown requirement operator in 'any': " + newOper); } } if (!civPermitted && !requirements.length) diff --git a/binaries/data/mods/public/gui/loadgame/SavegameList.js b/binaries/data/mods/public/gui/loadgame/SavegameList.js index 786fec1912..3684c75e5e 100644 --- a/binaries/data/mods/public/gui/loadgame/SavegameList.js +++ b/binaries/data/mods/public/gui/loadgame/SavegameList.js @@ -116,6 +116,8 @@ class SavegameList cmpA = a.description; cmpB = b.description; break; + default: + error("Unknown sortKey in updateSavegameList: " + sortKey); } if (cmpA < cmpB) diff --git a/binaries/data/mods/public/gui/replaymenu/replay_filters.js b/binaries/data/mods/public/gui/replaymenu/replay_filters.js index 85ba489ef9..7505df280f 100644 --- a/binaries/data/mods/public/gui/replaymenu/replay_filters.js +++ b/binaries/data/mods/public/gui/replaymenu/replay_filters.js @@ -231,6 +231,8 @@ function filterReplays() cmpA_secondary = g_PopulationCapacities.Name.indexOf(a.attribs.settings.PopulationCapType); cmpB_secondary = g_PopulationCapacities.Name.indexOf(b.attribs.settings.PopulationCapType); break; + default: + error("Unknown sortKey in filterReplays: " + sortKey); } if (cmpA < cmpB) diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js index ee8eb49b4d..abf6c86497 100644 --- a/binaries/data/mods/public/gui/session/input.js +++ b/binaries/data/mods/public/gui/session/input.js @@ -500,6 +500,8 @@ function handleInputBeforeGui(ev, hoveredObject) mouseX = ev.x; mouseY = ev.y; break; + default: + break; } mouseIsOverObject = (hoveredObject != null); @@ -564,9 +566,10 @@ function handleInputBeforeGui(ev, hoveredObject) inputState = INPUT_NORMAL; return true; } - break; + return false; + default: + return false; } - break; case INPUT_UNIT_POSITION: switch (ev.type) @@ -575,8 +578,9 @@ function handleInputBeforeGui(ev, hoveredObject) return positionUnitsFreehandSelectionMouseMove(ev); case "mousebuttonup": return positionUnitsFreehandSelectionMouseUp(ev); + default: + return false; } - break; case INPUT_BUILDING_CLICK: switch (ev.type) @@ -589,7 +593,7 @@ function handleInputBeforeGui(ev, hoveredObject) inputState = INPUT_BUILDING_DRAG; return false; } - break; + return false; case "mousebuttonup": if (ev.button == SDL_BUTTON_LEFT) @@ -607,7 +611,7 @@ function handleInputBeforeGui(ev, hoveredObject) inputState = INPUT_BUILDING_PLACEMENT; return true; } - break; + return false; case "mousebuttondown": if (ev.button == SDL_BUTTON_RIGHT) @@ -617,9 +621,10 @@ function handleInputBeforeGui(ev, hoveredObject) inputState = INPUT_NORMAL; return true; } - break; + return false; + default: + return false; } - break; case INPUT_BUILDING_WALL_CLICK: // User is mid-click in choosing a starting point for building a wall. The build process can still be cancelled at this point @@ -632,7 +637,7 @@ function handleInputBeforeGui(ev, hoveredObject) inputState = INPUT_BUILDING_WALL_PATHING; return true; } - break; + return false; case "mousebuttondown": if (ev.button == SDL_BUTTON_RIGHT) @@ -644,9 +649,10 @@ function handleInputBeforeGui(ev, hoveredObject) inputState = INPUT_NORMAL; return true; } - break; + return false; + default: + return false; } - break; case INPUT_BUILDING_WALL_PATHING: // User has chosen a starting point for constructing the wall, and is now looking to set the endpoint. @@ -679,7 +685,7 @@ function handleInputBeforeGui(ev, hoveredObject) ].filter(tip => tip).join("\n"); } - break; + return false; case "mousebuttondown": if (ev.button == SDL_BUTTON_LEFT) @@ -715,9 +721,10 @@ function handleInputBeforeGui(ev, hoveredObject) inputState = INPUT_NORMAL; return true; } - break; + return false; + default: + return false; } - break; case INPUT_BUILDING_DRAG: switch (ev.type) @@ -746,7 +753,7 @@ function handleInputBeforeGui(ev, hoveredObject) } updateBuildingPlacementPreview(); - break; + return false; case "mousebuttonup": if (ev.button == SDL_BUTTON_LEFT) @@ -764,7 +771,7 @@ function handleInputBeforeGui(ev, hoveredObject) inputState = INPUT_BUILDING_PLACEMENT; return true; } - break; + return false; case "mousebuttondown": if (ev.button == SDL_BUTTON_RIGHT) @@ -774,9 +781,10 @@ function handleInputBeforeGui(ev, hoveredObject) inputState = INPUT_NORMAL; return true; } - break; + return false; + default: + return false; } - break; case INPUT_BATCHTRAINING: if (ev.type == "hotkeyup" && ev.hotkey == "session.batchtrain") @@ -784,10 +792,10 @@ function handleInputBeforeGui(ev, hoveredObject) flushTrainingBatch(); inputState = INPUT_NORMAL; } - break; + return false; + default: + return false; } - - return false; } function handleInputAfterGui(ev) @@ -847,11 +855,11 @@ function handleInputAfterGui(ev) else if (ev.button == SDL_BUTTON_RIGHT) { if (!controlsPlayer(g_ViewedPlayer)) - break; + return false; g_DragStart = new Vector2D(ev.x, ev.y); inputState = INPUT_UNIT_POSITION_START; } - break; + return false; case "hotkeypress": if (ev.hotkey.indexOf("selection.group.") == 0) @@ -874,9 +882,10 @@ function handleInputAfterGui(ev) prevHotkey = ev.hotkey; } } - break; + return false; + default: + return false; } - break; case INPUT_PRESELECTEDACTION: switch (ev.type) @@ -895,7 +904,7 @@ function handleInputAfterGui(ev) { const action = determineAction(ev.x, ev.y); if (!action) - break; + return false; if (!Engine.HotkeyIsPressed("session.queue") && !Engine.HotkeyIsPressed("session.orderone")) { preSelectedAction = ACTION_NONE; @@ -907,18 +916,17 @@ function handleInputAfterGui(ev) { preSelectedAction = ACTION_NONE; inputState = INPUT_NORMAL; - break; } + return false; default: // Slight hack: If selection is empty, reset the input state. if (!g_Selection.size()) { preSelectedAction = ACTION_NONE; inputState = INPUT_NORMAL; - break; } + return false; } - break; case INPUT_SELECTING: switch (ev.type) @@ -999,20 +1007,18 @@ function handleInputAfterGui(ev) inputState = INPUT_NORMAL; return true; } - break; + return false; + default: + return false; } - break; case INPUT_UNIT_POSITION_START: switch (ev.type) { case "mousemotion": if (g_DragStart.distanceToSquared(ev) >= Math.square(getMaxDragDelta())) - { inputState = INPUT_UNIT_POSITION; - return false; - } - break; + return false; case "mousebuttonup": inputState = INPUT_NORMAL; if (ev.button == SDL_BUTTON_RIGHT) @@ -1021,9 +1027,10 @@ function handleInputAfterGui(ev) if (action) return doAction(action, ev); } - break; + return false; + default: + return false; } - break; case INPUT_BUILDING_PLACEMENT: switch (ev.type) @@ -1114,7 +1121,7 @@ function handleInputAfterGui(ev) inputState = INPUT_NORMAL; return true; } - break; + return false; case "hotkeydown": @@ -1125,16 +1132,19 @@ function handleInputAfterGui(ev) case "session.rotate.cw": placementSupport.angle += rotation_step; updateBuildingPlacementPreview(); - break; + return false; case "session.rotate.ccw": placementSupport.angle -= rotation_step; updateBuildingPlacementPreview(); - break; + return false; + default: + return false; } - break; + default: + return false; } - break; + case INPUT_FLARE: if (ev.type == "mousebuttondown") { @@ -1150,8 +1160,10 @@ function handleInputAfterGui(ev) return true; } } + return false; + default: + return false; } - return false; } function doAction(action, ev) @@ -1644,6 +1656,8 @@ function performGroup(action, groupId) updateGroups(); break; + default: + warn("Unknow action in performGroup: " + action); } } diff --git a/binaries/data/mods/public/gui/session/selection_panels.js b/binaries/data/mods/public/gui/session/selection_panels.js index 2e25691a51..c9cfdec429 100644 --- a/binaries/data/mods/public/gui/session/selection_panels.js +++ b/binaries/data/mods/public/gui/session/selection_panels.js @@ -55,6 +55,8 @@ g_SelectionPanels.Alert = { case "end": endOfAlert(); return; + default: + error("Unknown value for alert action: " + data.item); } }; @@ -80,6 +82,8 @@ g_SelectionPanels.Alert = { else data.button.tooltip += "\n" + bodyFont(translate("Unload nearby vulnerable units.")); break; + default: + error("Unknown value for alert action: " + data.item); } data.button.enabled = controlsPlayer(data.player); @@ -789,6 +793,8 @@ g_SelectionPanels.Research = { current = playerState.typeCountsByClass[entity.class] ? Object.keys(playerState.typeCountsByClass[entity.class]).length : 0; break; + default: + error("Unknow value in entity requirement check: " + entity.check); } const remaining = entity.number - current; diff --git a/binaries/data/mods/public/gui/session/unit_actions.js b/binaries/data/mods/public/gui/session/unit_actions.js index 9a269c642e..9f0a6e224c 100644 --- a/binaries/data/mods/public/gui/session/unit_actions.js +++ b/binaries/data/mods/public/gui/session/unit_actions.js @@ -713,6 +713,8 @@ var g_UnitActions = "gain": getTradingTooltip(tradingDetails.gain) }); break; + default: + error("Unknown type for tradingDetails: " + tradingDetails.type); } return { diff --git a/binaries/data/mods/public/simulation/components/BuildRestrictions.js b/binaries/data/mods/public/simulation/components/BuildRestrictions.js index 19b697ac2a..377aed21e1 100644 --- a/binaries/data/mods/public/simulation/components/BuildRestrictions.js +++ b/binaries/data/mods/public/simulation/components/BuildRestrictions.js @@ -165,8 +165,9 @@ BuildRestrictions.prototype.CheckPlacement = function() case "fail_terrain_class": // TODO: be more specific and/or list valid terrain? result.message = markForTranslation("%(name)s cannot be built on invalid terrain"); + default: + return result; // Fail } - return result; // Fail } // Check territory restrictions diff --git a/binaries/data/mods/public/simulation/components/TechnologyManager.js b/binaries/data/mods/public/simulation/components/TechnologyManager.js index bbd5066bec..2331140a56 100644 --- a/binaries/data/mods/public/simulation/components/TechnologyManager.js +++ b/binaries/data/mods/public/simulation/components/TechnologyManager.js @@ -348,8 +348,9 @@ TechnologyManager.prototype.CheckTechnologyRequirements = function(reqs, civonly case "entities": return req[type].every(this.DoesEntitySpecPass, this); + default: + return false; } - return false; }); }); }; @@ -361,14 +362,15 @@ TechnologyManager.prototype.DoesEntitySpecPass = function(entity) case "count": if (!this.classCounts[entity.class] || this.classCounts[entity.class] < entity.number) return false; - break; + return true; case "variants": if (!this.typeCountsByClass[entity.class] || Object.keys(this.typeCountsByClass[entity.class]).length < entity.number) return false; - break; + return true; + default: + return true; } - return true; }; TechnologyManager.prototype.OnGlobalOwnershipChanged = function(msg)