Remove asserts the types already cover

The nil check burn down added guards which turned out redundant once
the surrounding annotations landed. `_has_handlers` is set to true when
the first handler registers, so it is a boolean rather than the literal
false it was inferred as.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
bbassie
2026-08-07 15:31:48 +00:00
co-authored by Claude Opus 5
parent f907007d14
commit 619ed4b39f
19 changed files with 68 additions and 55 deletions
+6 -3
View File
@@ -50,7 +50,8 @@ local servers = External.get_servers()
]]
function External.get_servers()
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
return (assert(ext.servers, "No server list was found, please ensure that the external service is running"))
local value = assert(ext.servers, "No server list was found, please ensure that the external service is running")
return value
end
--[[-- Gets a table of all the servers filtered by name, key is the server id, value is the server details
@@ -85,7 +86,8 @@ function External.get_current_server()
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
local server_id = assert(ext.current, "No current id was found, please ensure that the external service is running")
return (assert(servers[server_id], "No details found for server with id: " .. tostring(server_id)))
local value = assert(servers[server_id], "No details found for server with id: " .. tostring(server_id))
return value
end
--[[-- Gets the details of the given server
@@ -99,7 +101,8 @@ local server = External.get_server_details('eu-01')
function External.get_server_details(server_id)
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
return (assert(servers[server_id], "No details found for server with id: " .. tostring(server_id)))
local value = assert(servers[server_id], "No details found for server with id: " .. tostring(server_id))
return value
end
--[[-- Gets the status of the given server
+10 -9
View File
@@ -216,7 +216,7 @@ game.player.print(Roles.debug())
function Roles.debug()
local output = ""
for index, role_name in ipairs(Roles.config.order) do
local role = assert(Roles.config.roles[role_name])
local role = Roles.config.roles[role_name]
local color = (role.custom_color or Colours.white) --[[@as Color.struct]]
local color_str = string.format("[color=%d, %d, %d]", color.r, color.g, color.b)
output = output .. string.format("\n%s %s) %s[/color]", color_str, index, serpent.line(role))
@@ -369,14 +369,15 @@ local role = Roles.get_player_highest_role(game.player)
--- @return Roles.Role
function Roles.get_player_highest_role(player)
local roles = Roles.get_player_roles(player)
local highest
local highest --- @type Roles.Role?
for _, role in ipairs(roles) do
if not highest or role.index < highest.index then
highest = role
end
end
return (assert(highest, "Player has no roles"))
local value = assert(highest, "Player has no roles")
return value
end
--- Assignment.
@@ -415,7 +416,7 @@ function Roles.assign_player(player, roles, by_player_name, skip_checks, silent)
-- If the player has a role that needs to defer the role changes, save the roles that need to be assigned later into a table
if valid_player and Roles.player_has_flag(valid_player, "defer_role_changes") then
local assign_later = Roles.config.deferred_roles[assert(valid_player).name] or {}
local assign_later = Roles.config.deferred_roles[valid_player.name] or {}
for _, role in ipairs(role_objects) do
local role_change = assign_later[role.name]
if role_change then
@@ -431,7 +432,7 @@ function Roles.assign_player(player, roles, by_player_name, skip_checks, silent)
end
end
Roles.config.deferred_roles[assert(valid_player).name] = assign_later
Roles.config.deferred_roles[valid_player.name] = assign_later
return
end
@@ -477,8 +478,8 @@ function Roles.unassign_player(player, roles, by_player_name, skip_checks, silen
-- If the player has a role that needs to defer the role changes, save the roles that need to be unassigned later into a table
local defer_changes = Roles.player_has_flag(player, "defer_role_changes")
if defer_changes then
local assign_later = Roles.config.deferred_roles[assert(valid_player).name] or {}
if defer_changes and valid_player then
local assign_later = Roles.config.deferred_roles[valid_player.name] or {}
for _, role in ipairs(role_objects) do
local role_change = assign_later[role.name]
if role_change then
@@ -494,7 +495,7 @@ function Roles.unassign_player(player, roles, by_player_name, skip_checks, silen
end
end
Roles.config.deferred_roles[assert(valid_player).name] = assign_later
Roles.config.deferred_roles[valid_player.name] = assign_later
end
-- Remove the player from roles
@@ -674,7 +675,7 @@ function Roles.define_role_order(order)
-- Re-links roles to they parents as this is called at the end of the config
for index, role_name in pairs(Roles.config.order) do
local role = assert(Roles.config.roles[role_name])
local role = Roles.config.roles[role_name]
if not role then
error("Role with name " .. role_name .. " has not beed defined, either define it or remove it from the order list.", 2)
end
+1 -1
View File
@@ -291,7 +291,7 @@ function vlayer.remove_item(item_name, count)
if not config.unlimited_surface_area and item_properties.required_area and item_properties.required_area > 0 then
-- Remove from the unallocated storage first
remove_unallocated = math.min(count, assert(vlayer_data.storage.unallocated[item_name]))
remove_unallocated = math.min(count, vlayer_data.storage.unallocated[item_name])
if remove_unallocated > 0 then
vlayer_data.storage.items[item_name] = vlayer_data.storage.items[item_name] - count
+4 -5
View File
@@ -381,14 +381,13 @@ local vlayer_gui_control_see = Gui.define("vlayer_gui_control_see")
}:style{
width = 200,
}:on_click(function(def, player, element, event)
local target = assert(assert(element.parent)[vlayer_gui_control_type.name]).selected_index
local n = assert(assert(element.parent)[vlayer_gui_control_list.name]).selected_index
local target = assert(element.parent)[vlayer_gui_control_type.name].selected_index
local n = assert(element.parent)[vlayer_gui_control_list.name].selected_index
if target and vlayer_control_type_list[target] and n > 0 then
local i = vlayer.get_interfaces()
local entity = i[vlayer_control_type_list[target]][n]
if entity and entity.valid then
local player = Gui.get_player(event)
player.set_controller{ type = defines.controllers.remote, position = entity.position, surface = entity.surface }
player.print{ "vlayer.result-interface-location", { "vlayer.control-type-" .. vlayer_control_type_list[target]:gsub("_", "-") }, pos_to_gps_string(entity.position, entity.surface.name) }
end
@@ -425,8 +424,8 @@ local vlayer_gui_control_remove = Gui.define("vlayer_gui_control_remove")
}:style{
width = 200,
}:on_click(function(def, player, element)
local target = assert(assert(element.parent)[vlayer_gui_control_type.name]).selected_index
local n = assert(assert(element.parent)[vlayer_gui_control_list.name]).selected_index
local target = assert(element.parent)[vlayer_gui_control_type.name].selected_index
local n = assert(element.parent)[vlayer_gui_control_list.name].selected_index
if target and vlayer_control_type_list[target] and n > 0 then
local i = vlayer.get_interfaces()
+4 -4
View File
@@ -294,10 +294,10 @@ local confirm_edit_button = Gui.define("confirm_edit_button")
local parent = assert(element.parent)
local grandparent = assert(parent.parent)
local warp_id = parent.caption --[[@as string]]
local name_flow = assert(grandparent["name-" .. warp_id])
local icon_flow = assert(grandparent["icon-" .. warp_id])
local warp_name = assert(name_flow[warp_textfield.name]).text
local warp_icon = assert(icon_flow[warp_icon_editing.name]).elem_value --[[@as SignalID]]
local name_flow = grandparent["name-" .. warp_id]
local icon_flow = grandparent["icon-" .. warp_id]
local warp_name = name_flow[warp_textfield.name].text
local warp_icon = icon_flow[warp_icon_editing.name].elem_value --[[@as SignalID]]
if warp_icon.type == nil then warp_icon.type = "item" end
Warps.set_editing(warp_id, player.name)
Warps.update_warp(warp_id, warp_name, warp_icon, player.name)