Adds CI checks forbidding certain kinds of world loops (#24454)

* Updates checkgrep to report unnecessary loops

* improved message

* global lists are better too

* much better

* Apply suggestions from code review

Co-authored-by: GDN <96800819+GDNgit@users.noreply.github.com>

* update to modern check_grep format

---------

Co-authored-by: GDN <96800819+GDNgit@users.noreply.github.com>
Co-authored-by: S34N <12197162+S34NW@users.noreply.github.com>
This commit is contained in:
Luc
2024-03-20 16:17:45 -04:00
committed by GitHub
parent d1c77ea8fb
commit 9efffccd71
7 changed files with 27 additions and 4 deletions
+8
View File
@@ -20,6 +20,14 @@
fire_damage = 3
var/mob/camera/blob/overmind = null
/mob/living/simple_animal/hostile/blob/Initialize(mapload)
. = ..()
GLOB.blob_minions |= src
/mob/living/simple_animal/hostile/blob/Destroy()
GLOB.blob_minions -= src
return ..()
/mob/living/simple_animal/hostile/blob/proc/adjustcolors(a_color)
if(a_color)
color = a_color
+1 -1
View File
@@ -469,7 +469,7 @@
for(var/obj/structure/blob/BL in GLOB.blobs)
BL.adjustcolors(blob_reagent_datum.color)
for(var/mob/living/simple_animal/hostile/blob/BLO)
for(var/mob/living/simple_animal/hostile/blob/BLO in GLOB.blob_minions)
BLO.adjustcolors(blob_reagent_datum.complementary_color)
to_chat(src, "Your reagent is now: <b><font color=\"[blob_reagent_datum.color]\">[blob_reagent_datum.name]</b></font> - [blob_reagent_datum.description]")
+1
View File
@@ -2,6 +2,7 @@
GLOBAL_LIST_EMPTY(blobs)
GLOBAL_LIST_EMPTY(blob_nodes)
GLOBAL_LIST_EMPTY(blob_minions)
/obj/structure/blob
name = "blob"
+1 -1
View File
@@ -8,7 +8,7 @@
RS.lightsoutAmount = pick(2,2,3)
RS.start()
RS.kill()
for(var/area/A)
for(var/area/A in GLOB.all_areas)
if(!is_station_level(A.z)) continue //Spook on main station only.
if(A.luminosity) continue
// if(A.lighting_space) continue
@@ -118,7 +118,7 @@
var/atom/movable/screen/text/blurb/location_blurb = new()
if(antag_check.antag_datums)
for(var/datum/antagonist/role)
for(var/datum/antagonist/role in antag_check.antag_datums)
if(role.custom_blurb())
location_blurb.blurb_text = uppertext(role.custom_blurb())
location_blurb.text_color = role.blurb_text_color
+1 -1
View File
@@ -22,7 +22,7 @@
/datum/station_goal/bluespace_cannon/check_completion()
if(..())
return TRUE
for(var/obj/machinery/bsa/full/B)
for(var/obj/machinery/bsa/full/B in GLOB.machines)
if(B && !B.stat && is_station_contact(B.z))
return TRUE
return FALSE
+14
View File
@@ -133,6 +133,19 @@ def check_tgui_ui_new_argument(idx, line):
if "\tui = new" in line and not TGUI_UI_NEW.search(line):
return [(idx + 1, "Invalid argument within constructor, please make sure window sizing is in corresponding JavaScript file.")]
# checks for any (for var/type/x) loops that are not looping over bare datums: enforcing that the only case we will see this is if you genuinely want to loop over all datums in memory
FOR_ALL_DATUMS = re.compile(r"for\s*\(\s*var\/((\w+)(?:(?:\/\w+){2,})?)\)")
# double-checks that we don't have any attempts at looping like for(var/atom/a)
FOR_ALL_NOT_DATUMS = re.compile(r"for\s*\(\s*var\/((?:atom|area|turf|obj|mob)(?:\/\w+))\)")
def check_datum_loops(idx, line):
if FOR_ALL_DATUMS.search(line) or FOR_ALL_NOT_DATUMS.search(line):
return Failure(
idx + 1,
# yes this will concatenate the strings, don't look too hard
"Found a for loop without explicit contents. If you're trying to loop over everything in the world, first double check that you truly need to, and if so specify \'in world\'.\n"
"If you're trying to check bare datums, please ensure that your value is only cast to /datum, and please make sure you use \'as anything\', or use a global list instead."
)
CODE_CHECKS = [
check_space_indentation,
check_mixed_indentation,
@@ -144,6 +157,7 @@ CODE_CHECKS = [
check_conditional_spacing,
check_global_list_empty,
check_tgui_ui_new_argument,
check_datum_loops,
]