Skip to content

Commit

Permalink
CI lint for UID() misuse (ParadiseSS13#28465)
Browse files Browse the repository at this point in the history
* Adds CI check for UID() being passed parameters.

* Fixes cases of UID() being passed parameters.
  • Loading branch information
chuga-git authored Feb 21, 2025
1 parent 746cf7e commit 38642d5
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion code/_onclick/hud/action_button.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions code/datums/ai/ai_controller.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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); \
}; \
Expand Down
4 changes: 2 additions & 2 deletions code/datums/components/scope.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/weapons/melee/melee_misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]")
Expand Down
8 changes: 4 additions & 4 deletions code/modules/clothing/suits/wiz_robe.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mod/mod_actions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions code/modules/mod/mod_types.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mod/mod_ui.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mod/modules/_modules.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions code/modules/mod/modules/modules_antag.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions code/modules/projectiles/guns/energy/special_eguns.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tools/ci/check_grep2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -204,6 +209,7 @@ def check_camel_case_type_names(idx, line):
check_empty_list_whitespace,
check_istype_src,
check_camel_case_type_names,
check_uid_parameters,
]


Expand Down

0 comments on commit 38642d5

Please sign in to comment.