From 3f46055b704a3475b022f46ab36665b53a816f8e Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Fri, 7 Aug 2026 11:00:47 +0000 Subject: [PATCH] Enable need-check-nil and start the burn down `Roles.new_role` returned the result of `error`, which made it nullable, and `set_permission_group` returned nil for an unknown group, which broke the config chain with an index error rather than saying so. Positions and bounding boxes read back from the game always use the named members, so they are narrowed once where they enter a function. Co-Authored-By: Claude Opus 5 (1M context) --- .emmyrc.json | 2 -- exp_legacy/module/expcore/roles.lua | 5 ++--- exp_scenario/module/control/mine_depletion.lua | 16 +++++++++------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.emmyrc.json b/.emmyrc.json index 62b2e74a..c103023e 100644 --- a/.emmyrc.json +++ b/.emmyrc.json @@ -18,7 +18,6 @@ }, "$comment-disable": "Carried over from the luals config, which had these as editor only rather than checked in ci", "$comment-unnecessary-if": "Disabled by the config fmtk generates for itself, the api union types make it unreliable", - "$comment-need-check-nil": "To be enabled once the backlog is cleared, a third of it is MapPosition and BoundingBox being aliased as struct|[double, double]", "diagnostics": { "globals": [ "__DebugAdapter", "__Profiler" ], "disable": [ @@ -27,7 +26,6 @@ "invert-if", "missing-parameter", "missing-return-value", - "need-check-nil", "param-type-mismatch", "preferred-local-alias", "redefined-local", diff --git a/exp_legacy/module/expcore/roles.lua b/exp_legacy/module/expcore/roles.lua index 529752d2..540c42ea 100644 --- a/exp_legacy/module/expcore/roles.lua +++ b/exp_legacy/module/expcore/roles.lua @@ -719,7 +719,7 @@ local role = Roles.new_role('Moderator', 'Mod') ]] function Roles.new_role(name, short_hand) ExpUtil.assert_not_runtime() - if Roles.config.roles[name] then return error("Role name is non unique") end + if Roles.config.roles[name] then error("Role name is non unique") end local role = setmetatable({ name = name, short_hand = short_hand or name, @@ -896,8 +896,7 @@ function Roles._prototype:set_permission_group(name, use_factorio_api) if use_factorio_api then self.permission_group = { true, name } --[[@as [boolean, string] ]] else - local group = Groups.get_group_by_name(name) - if not group then return end + assert(Groups.get_group_by_name(name), "Permission group not found: " .. name) self.permission_group = name end return self diff --git a/exp_scenario/module/control/mine_depletion.lua b/exp_scenario/module/control/mine_depletion.lua index 894c3dfb..996a6019 100644 --- a/exp_scenario/module/control/mine_depletion.lua +++ b/exp_scenario/module/control/mine_depletion.lua @@ -68,12 +68,13 @@ local function try_deconstruct_output_chest(entity) end -- Get all adjacent mining drills and inserters + local target_position = target.position --[[@as MapPosition.struct]] local entities = target.surface.find_entities_filtered{ type = { "mining-drill", "inserter" }, to_be_deconstructed = false, area = { - { target.position.x - 1, target.position.y - 1 }, - { target.position.x + 1, target.position.y + 1 } + { target_position.x - 1, target_position.y - 1 }, + { target_position.x + 1, target_position.y + 1 } }, } @@ -159,14 +160,14 @@ local function try_deconstruct_miner(entity) end -- Build pipes if the miner used fluid - local position = entity.position + local position = entity.position --[[@as MapPosition.struct]] local create_entity_position = { x = position.x, y = position.y } local create_entity_param = { name = "entity-ghost", inner_name = "pipe", force = entity.force, position = create_entity_position } local create_entity = surface.create_entity create_entity(create_entity_param) -- Find all the entities to connect to - local bounding_box = entity.bounding_box + local bounding_box = entity.bounding_box --[[@as ExpUtil_AABB.Box]] local search_area = { { bounding_box.left_top.x - 1, bounding_box.left_top.y - 1 }, { bounding_box.right_bottom.x + 1, bounding_box.right_bottom.y + 1 }, @@ -246,7 +247,7 @@ local function on_resource_depleted(event) end -- Find all mining drills within the area - local position = resource.position + local position = resource.position --[[@as MapPosition.struct]] local drills = resource.surface.find_entities_filtered{ type = "mining-drill", area = { @@ -258,8 +259,9 @@ local function on_resource_depleted(event) -- Check which could have reached this resource for _, drill in pairs(drills) do local radius = drill.prototype.mining_drill_radius - local dx = math.abs(drill.position.x - position.x) - local dy = math.abs(drill.position.y - position.y) + local drill_position = drill.position --[[@as MapPosition.struct]] + local dx = math.abs(drill_position.x - position.x) + local dy = math.abs(drill_position.y - position.y) if dx <= radius and dy <= radius then try_deconstruct_miner(drill) end