Clear the last of the nil checks

Guards now cover the statements that follow them, and a couple of reads
are restructured so the narrowing survives.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
bbassie
2026-08-07 15:31:43 +00:00
co-authored by Claude Opus 5
parent 76ecc37d3f
commit f5656025ee
9 changed files with 31 additions and 22 deletions
+1 -1
View File
@@ -71,7 +71,7 @@ Commands.new("commands", { "exp-commands_help.description" })
page = as_number page = as_number
end end
keyword = assert(keyword):lower() keyword = tostring(keyword):lower()
local pages, found local pages, found
if cache and cache.keyword == keyword then if cache and cache.keyword == keyword then
-- Cached value found, no search is needed -- Cached value found, no search is needed
+7 -5
View File
@@ -14,7 +14,8 @@ end
]] ]]
local ext, var local ext --- @type table<string, any>
local var --- @type table<string, any>
local concat = table.concat local concat = table.concat
local External = {} local External = {}
@@ -29,12 +30,13 @@ end
]] ]]
function External.valid() function External.valid()
if storage.ext == nil then return false end local stored = storage.ext
if ext == storage.ext and var == ext.var then if stored == nil then return false end
if ext == stored and var == ext.var then
return var ~= nil return var ~= nil
else else
ext = storage.ext ext = stored
var = ext.var var = stored.var
return var ~= nil return var ~= nil
end end
end end
@@ -34,7 +34,7 @@ for _, config_key in ipairs{ "always_protected_names", "always_protected_types",
end end
-- Require roles if a permission is assigned in the config -- Require roles if a permission is assigned in the config
local Roles local Roles --- @type table<string, any>
if config.ignore_permission then if config.ignore_permission then
Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
end end
@@ -4,7 +4,7 @@ local Gui = require("modules/exp_gui")
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
----- Locals ----- ----- Locals -----
local follow_label -- Gui constructor local follow_label --- @type ExpElement Gui constructor
local following = {} local following = {}
local spectating = {} local spectating = {}
local Public = {} local Public = {}
+2 -2
View File
@@ -673,7 +673,7 @@ warp_list_container = Gui.define("warp_list_container")
-- Draw the scroll table for the warps -- Draw the scroll table for the warps
local scroll_table = Gui.elements.scroll_table(container, 250, 3, "scroll") local scroll_table = Gui.elements.scroll_table(container, 250, 3, "scroll")
-- Set the scroll panel to always show the scrollbar (not doing this will result in a changing gui size) -- Set the scroll panel to always show the scrollbar (not doing this will result in a changing gui size)
scroll_table.parent.vertical_scroll_policy = "always" assert(scroll_table.parent).vertical_scroll_policy = "always"
-- Change the style of the scroll table -- Change the style of the scroll table
local scroll_table_style = scroll_table.style local scroll_table_style = scroll_table.style
@@ -874,7 +874,7 @@ local function role_update_event(event)
-- Check if user has permission to add warps -- Check if user has permission to add warps
local allow_add_warp = check_player_permissions(player, "allow_add_warp") local allow_add_warp = check_player_permissions(player, "allow_add_warp")
-- Update container size depending on whether the player is allowed to add warps -- Update container size depending on whether the player is allowed to add warps
frame.parent.style.width = allow_add_warp and 268 or 220 assert(frame.parent).style.width = allow_add_warp and 268 or 220
-- Update the warps, in case the user can now edit them -- Update the warps, in case the user can now edit them
local scroll_table = frame.scroll.table local scroll_table = frame.scroll.table
+8 -5
View File
@@ -149,11 +149,13 @@ local function create_entities(surface, offset)
local pos = apply_offset({ entity_details[2], entity_details[3] }, offset) local pos = apply_offset({ entity_details[2], entity_details[3] }, offset)
local entity = surface.create_entity{ name = entity_details[1], position = pos, force = "neutral" } local entity = surface.create_entity{ name = entity_details[1], position = pos, force = "neutral" }
if entity and config.entities.protected then if entity then
protect_entity(entity) if config.entities.protected then
end protect_entity(entity)
end
entity.operable = config.entities.operable entity.operable = config.entities.operable
end
end end
end end
@@ -276,7 +278,8 @@ local function on_player_created(event)
if config.resource_patches.enabled then create_resource_patches(surface, offset) end if config.resource_patches.enabled then create_resource_patches(surface, offset) end
if config.turrets.enabled then update_turrets() end if config.turrets.enabled then update_turrets() end
(player.force --[[@as LuaForce]]).set_spawn_position(offset, surface) local force = player.force --[[@as LuaForce]]
force.set_spawn_position(offset, surface)
player.teleport(offset, surface) player.teleport(offset, surface)
end end
+1 -1
View File
@@ -106,7 +106,7 @@ Elements.reason_confirm = Gui.define("player_list/reason_confirm")
if reason == nil or not reason:find("%S") then reason = "no reason given" end if reason == nil or not reason:find("%S") then reason = "no reason given" end
button_data.reason_callback(player, reason) button_data.reason_callback(player, reason)
end end
element.parent.entry.text = "" assert(assert(element.parent).entry).text = ""
Elements.container.set_selected_player(player, nil) Elements.container.set_selected_player(player, nil)
Elements.player_table.refresh_player(player) Elements.player_table.refresh_player(player)
end) --[[@as any]] end) --[[@as any]]
@@ -193,7 +193,8 @@ Elements.science_table = Gui.define("science_production/science_table")
local science_table = Gui.elements.scroll_table(parent, 190, 4) local science_table = Gui.elements.scroll_table(parent, 190, 4)
local no_production_label = Elements.no_production_label(science_table) local no_production_label = Elements.no_production_label(science_table)
Elements.no_production_label.refresh(no_production_label) Elements.no_production_label.refresh(no_production_label)
(science_table.style --[[@as LuaStyle]]).column_alignments[3] = "right" local science_table_style = science_table.style --[[@as LuaStyle]]
science_table_style.column_alignments[3] = "right"
return science_table return science_table
end) end)
:element_data{} --[[@as any]] :element_data{} --[[@as any]]
@@ -280,7 +281,8 @@ function Elements.science_table.add_row(science_table, row_data)
column_count = 2, column_count = 2,
} }
delta_table.style.padding = 0 delta_table.style.padding = 0
(delta_table.style --[[@as LuaStyle]]).column_alignments[1] = "right" local delta_table_style = delta_table.style --[[@as LuaStyle]]
delta_table_style.column_alignments[1] = "right"
-- Draw the net production label -- Draw the net production label
local net = Elements.production_label(science_table, row_data.net) local net = Elements.production_label(science_table, row_data.net)
@@ -429,8 +431,10 @@ do local _display_data = {} --- @type table<string, Elements.eta_label.display_d
-- Update the eta labels -- Update the eta labels
for player, eta_label in Elements.eta_label:online_elements() do for player, eta_label in Elements.eta_label:online_elements() do
local display_data = _display_data[player.force.name] local display_data = _display_data[player.force.name]
eta_label.caption = display_data.caption if display_data then
eta_label.tooltip = display_data.tooltip eta_label.caption = display_data.caption
eta_label.tooltip = display_data.tooltip
end
end end
end end
end end
+2 -2
View File
@@ -551,7 +551,7 @@ function ExpUtil.move_items_to_surface(options)
options.item = item options.item = item
entity = ExpUtil.get_storage_for_stack(options) entity = ExpUtil.get_storage_for_stack(options)
entity.insert(options.item) entity.insert(options.item)
local item_stack = options.item --[[@as LuaItemStack]] local item_stack = options.item --[[@as LuaItemStack]]
item_stack.clear() item_stack.clear()
end end
end end
@@ -604,7 +604,7 @@ end
--- @param n number --- @param n number
--- @return string --- @return string
function ExpUtil.comma_value(n) -- credit http://richard.warburton.it function ExpUtil.comma_value(n) -- credit http://richard.warburton.it
local left, num, right = string.match(n, "^([^%d]*%d)(%d*)(.-)$") local left, num, right = string.match(n, "^([^%d]*%d)(%d*)(.-)$")
assert(left and num and right) assert(left and num and right)
return left .. (num:reverse():gsub("(%d%d%d)", "%1, "):reverse()) .. right return left .. (num:reverse():gsub("(%d%d%d)", "%1, "):reverse()) .. right
end end