From 38642d588874843c8e26bf907e2ce6f0a9a9a192 Mon Sep 17 00:00:00 2001 From: chuga-git <98280110+chuga-git@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:35:02 -0600 Subject: [PATCH] CI lint for UID() misuse (#28465) * Adds CI check for UID() being passed parameters. * Fixes cases of UID() being passed parameters. --- code/_onclick/hud/action_button.dm | 2 +- code/datums/ai/ai_controller.dm | 6 +++--- code/datums/components/scope.dm | 4 ++-- code/game/objects/items/weapons/melee/melee_misc.dm | 4 ++-- code/modules/clothing/suits/wiz_robe.dm | 8 ++++---- code/modules/mod/mod_actions.dm | 2 +- code/modules/mod/mod_types.dm | 4 ++-- code/modules/mod/mod_ui.dm | 2 +- code/modules/mod/modules/_modules.dm | 2 +- code/modules/mod/modules/modules_antag.dm | 4 ++-- code/modules/projectiles/guns/energy/special_eguns.dm | 4 ++-- tools/ci/check_grep2.py | 6 ++++++ 12 files changed, 27 insertions(+), 21 deletions(-) diff --git a/code/_onclick/hud/action_button.dm b/code/_onclick/hud/action_button.dm index bca40a80af7..abc5ba05aac 100644 --- a/code/_onclick/hud/action_button.dm +++ b/code/_onclick/hud/action_button.dm @@ -67,7 +67,7 @@ if(last_hovered) last_hovered.MouseExited(over_location, over_control, params) closeToolTip(usr) - last_hovered_ref = UID(over_object) + last_hovered_ref = over_object?.UID() if(!isnull(over_object)) over_object.MouseEntered(over_location, over_control, params) diff --git a/code/datums/ai/ai_controller.dm b/code/datums/ai/ai_controller.dm index 38cc060c312..3ef36676574 100644 --- a/code/datums/ai/ai_controller.dm +++ b/code/datums/ai/ai_controller.dm @@ -468,9 +468,9 @@ RESTRICT_TYPE(/datum/ai_controller) #define TRACK_AI_DATUM_TARGET(tracked_datum, key) do { \ if(isdatum(tracked_datum)) { \ var/datum/_tracked_datum = tracked_datum; \ - if(!HAS_TRAIT_FROM(_tracked_datum, TRAIT_AI_TRACKING, "[UID(src)]_[key]")) { \ + if(!HAS_TRAIT_FROM(_tracked_datum, TRAIT_AI_TRACKING, "[UID()]_[key]")) { \ RegisterSignal(_tracked_datum, COMSIG_PARENT_QDELETING, PROC_REF(sig_remove_from_blackboard), override = TRUE); \ - ADD_TRAIT(_tracked_datum, TRAIT_AI_TRACKING, "[UID(src)]_[key]"); \ + ADD_TRAIT(_tracked_datum, TRAIT_AI_TRACKING, "[UID()]_[key]"); \ }; \ }; \ } while(FALSE) @@ -484,7 +484,7 @@ RESTRICT_TYPE(/datum/ai_controller) #define CLEAR_AI_DATUM_TARGET(tracked_datum, key) do { \ if(isdatum(tracked_datum)) { \ var/datum/_tracked_datum = tracked_datum; \ - REMOVE_TRAIT(_tracked_datum, TRAIT_AI_TRACKING, "[UID(src)]_[key]"); \ + REMOVE_TRAIT(_tracked_datum, TRAIT_AI_TRACKING, "[UID()]_[key]"); \ if(!HAS_TRAIT(_tracked_datum, TRAIT_AI_TRACKING)) { \ UnregisterSignal(_tracked_datum, COMSIG_PARENT_QDELETING); \ }; \ diff --git a/code/datums/components/scope.dm b/code/datums/components/scope.dm index 59e32cfedd7..324896538d9 100644 --- a/code/datums/components/scope.dm +++ b/code/datums/components/scope.dm @@ -183,7 +183,7 @@ ) RegisterSignals(user, capacity_signals, PROC_REF(on_incapacitated)) START_PROCESSING(SSprojectiles, src) - ADD_TRAIT(user, TRAIT_SCOPED, "[UID(src)]") + ADD_TRAIT(user, TRAIT_SCOPED, "[UID()]") if(istype(parent, /obj/item/gun)) var/obj/item/gun/G = parent G.on_scope_success(user) @@ -218,7 +218,7 @@ COMSIG_CARBON_SWAP_HANDS, COMSIG_PARENT_QDELETING, )) - REMOVE_TRAIT(user, TRAIT_SCOPED, "[UID(src)]") + REMOVE_TRAIT(user, TRAIT_SCOPED, "[UID()]") user.playsound_local(parent, 'sound/weapons/scope.ogg', 75, TRUE, frequency = -1) user.clear_fullscreen("scope") diff --git a/code/game/objects/items/weapons/melee/melee_misc.dm b/code/game/objects/items/weapons/melee/melee_misc.dm index 94f09cd1a0a..e6a55251358 100644 --- a/code/game/objects/items/weapons/melee/melee_misc.dm +++ b/code/game/objects/items/weapons/melee/melee_misc.dm @@ -425,7 +425,7 @@ zap(target, user, list(user), power) /datum/enchantment/lightning/toggle_traits(obj/item/I, mob/living/user) - var/enchant_ID = UID(src) // so it only removes the traits applied by this specific enchant. + var/enchant_ID = UID() // so it only removes the traits applied by this specific enchant. if(applied_traits) REMOVE_TRAIT(user, TRAIT_SHOCKIMMUNE, "[enchant_ID]") else @@ -462,7 +462,7 @@ toggle_traits(S, user) /datum/enchantment/fire/toggle_traits(obj/item/I, mob/living/user) - var/enchant_ID = UID(src) // so it only removes the traits applied by this specific enchant. + var/enchant_ID = UID() // so it only removes the traits applied by this specific enchant. if(applied_traits) REMOVE_TRAIT(user, TRAIT_NOFIRE, "[enchant_ID]") REMOVE_TRAIT(user, TRAIT_RESISTHEAT, "[enchant_ID]") diff --git a/code/modules/clothing/suits/wiz_robe.dm b/code/modules/clothing/suits/wiz_robe.dm index 7314f898497..c34addf3d7c 100644 --- a/code/modules/clothing/suits/wiz_robe.dm +++ b/code/modules/clothing/suits/wiz_robe.dm @@ -202,13 +202,13 @@ /obj/item/clothing/suit/space/hardsuit/wizard/equipped(mob/user, slot) . = ..() - ADD_TRAIT(user, TRAIT_ANTIMAGIC, "[UID(src)]") - ADD_TRAIT(user, TRAIT_ANTIMAGIC_NO_SELFBLOCK, "[UID(src)]") + ADD_TRAIT(user, TRAIT_ANTIMAGIC, "[UID()]") + ADD_TRAIT(user, TRAIT_ANTIMAGIC_NO_SELFBLOCK, "[UID()]") /obj/item/clothing/suit/space/hardsuit/wizard/dropped(mob/user) . = ..() - REMOVE_TRAIT(user, TRAIT_ANTIMAGIC, "[UID(src)]") - REMOVE_TRAIT(user, TRAIT_ANTIMAGIC_NO_SELFBLOCK, "[UID(src)]") + REMOVE_TRAIT(user, TRAIT_ANTIMAGIC, "[UID()]") + REMOVE_TRAIT(user, TRAIT_ANTIMAGIC_NO_SELFBLOCK, "[UID()]") /obj/item/clothing/suit/space/hardsuit/wizard/arch diff --git a/code/modules/mod/mod_actions.dm b/code/modules/mod/mod_actions.dm index 9fbf636001c..fef9ee1a901 100644 --- a/code/modules/mod/mod_actions.dm +++ b/code/modules/mod/mod_actions.dm @@ -116,7 +116,7 @@ return ..() /datum/action/item_action/mod/pinned_module/Grant(mob/user) - var/user_uid = UID(user) + var/user_uid = user.UID() if(!pinner_uid) pinner_uid = user_uid module.pinned_to[pinner_uid] = src diff --git a/code/modules/mod/mod_types.dm b/code/modules/mod/mod_types.dm index af6292a6284..ec6b4ac8a1a 100644 --- a/code/modules/mod/mod_types.dm +++ b/code/modules/mod/mod_types.dm @@ -28,9 +28,9 @@ for(var/obj/item/mod/module/module as anything in modules) if(!default_pins[module.type]) //this module isnt meant to be pinned by default continue - if(UID(wearer) in default_pins[module.type]) //if we already had pinned once to this user, don care anymore + if(wearer.UID() in default_pins[module.type]) //if we already had pinned once to this user, don care anymore continue - default_pins[module.type] += UID(wearer) + default_pins[module.type] += wearer.UID() module.pin(wearer) /obj/item/mod/control/pre_equipped/uninstall(obj/item/mod/module/old_module, deleting) diff --git a/code/modules/mod/mod_ui.dm b/code/modules/mod/mod_ui.dm index 6daf62d55a3..f0ad81d4bf0 100644 --- a/code/modules/mod/mod_ui.dm +++ b/code/modules/mod/mod_ui.dm @@ -27,7 +27,7 @@ "description" = module.desc, "module_type" = module.module_type, "module_active" = module.active, - "pinned" = module.pinned_to[UID(user)], //might just want user here + "pinned" = module.pinned_to[user.UID()], //might just want user here "idle_power" = module.idle_power_cost, "active_power" = module.active_power_cost, "use_power" = module.use_power_cost, diff --git a/code/modules/mod/modules/_modules.dm b/code/modules/mod/modules/_modules.dm index 7c2e568591c..6312dcaa4e0 100644 --- a/code/modules/mod/modules/_modules.dm +++ b/code/modules/mod/modules/_modules.dm @@ -59,7 +59,7 @@ /obj/item/mod/module/Initialize(mapload) . = ..() - module_UID = UID(src) + module_UID = UID() if(module_type != MODULE_ACTIVE) return if(ispath(device)) diff --git a/code/modules/mod/modules/modules_antag.dm b/code/modules/mod/modules/modules_antag.dm index 002de3f3b30..0fa7fd5ba74 100644 --- a/code/modules/mod/modules/modules_antag.dm +++ b/code/modules/mod/modules/modules_antag.dm @@ -540,10 +540,10 @@ incompatible_modules = list(/obj/item/mod/module/anti_magic) /obj/item/mod/module/anti_magic/on_suit_activation() - ADD_TRAIT(mod.wearer, TRAIT_ANTIMAGIC, "[UID(src)]") + ADD_TRAIT(mod.wearer, TRAIT_ANTIMAGIC, "[UID()]") /obj/item/mod/module/anti_magic/on_suit_deactivation(deleting = FALSE) - REMOVE_TRAIT(mod.wearer, TRAIT_ANTIMAGIC, "[UID(src)]") + REMOVE_TRAIT(mod.wearer, TRAIT_ANTIMAGIC, "[UID()]") /obj/item/mod/module/anomaly_locked/teslawall name = "MOD arc-shield module" // temp diff --git a/code/modules/projectiles/guns/energy/special_eguns.dm b/code/modules/projectiles/guns/energy/special_eguns.dm index ab0268275a1..16142f07ae6 100644 --- a/code/modules/projectiles/guns/energy/special_eguns.dm +++ b/code/modules/projectiles/guns/energy/special_eguns.dm @@ -686,11 +686,11 @@ /obj/item/gun/energy/bsg/equipped(mob/user, slot, initial) . = ..() - ADD_TRAIT(user, TRAIT_BSG_IMMUNE, "[UID(src)]") + ADD_TRAIT(user, TRAIT_BSG_IMMUNE, "[UID()]") /obj/item/gun/energy/bsg/dropped(mob/user, silent) . = ..() - REMOVE_TRAIT(user, TRAIT_BSG_IMMUNE, "[UID(src)]") + REMOVE_TRAIT(user, TRAIT_BSG_IMMUNE, "[UID()]") /obj/item/gun/energy/bsg/process_fire(atom/target, mob/living/user, message = TRUE, params, zone_override, bonus_spread = 0) if(!has_bluespace_crystal) diff --git a/tools/ci/check_grep2.py b/tools/ci/check_grep2.py index 2ed127bae2b..c643d1e4f59 100644 --- a/tools/ci/check_grep2.py +++ b/tools/ci/check_grep2.py @@ -187,6 +187,11 @@ def check_camel_case_type_names(idx, line): type_result = result.group(0) return [(idx + 1, f"name of type {type_result} is not in snake_case format.")] +UID_WITH_PARAMETER = re.compile(r"\bUID\(\w+\)") +def check_uid_parameters(idx, line): + if result := UID_WITH_PARAMETER.search(line): + return [(idx + 1, "UID() does not take arguments. Use UID() instead of UID(src) and datum.UID() instead of UID(datum).")] + CODE_CHECKS = [ check_space_indentation, check_mixed_indentation, @@ -204,6 +209,7 @@ CODE_CHECKS = [ check_empty_list_whitespace, check_istype_src, check_camel_case_type_names, + check_uid_parameters, ]