7.10 Pure leaves depend on nothing impure

Rule: §7.10 in the code standards.

Why

A pure leaf is a script of static func over values: it does no engine lookup, no I/O and holds no state. Its tests pass plain values and check plain results, with no live object to build. The moment it preloads a script that looks things up on live objects, it gains that script’s dependencies, its tests need a live object again, and every caller of the rule pulls in the lookup’s preload closure too.

So dependencies point one way: code that looks things up on live objects may preload a pure leaf, and a pure leaf preloads only other pure leaves. When callers want one entry point that does both, the composing call goes on the lookup side, which already depends on the rule.

Good

BarePathCheck is the pure rule. It takes the declared type as a value and preloads nothing (addons/godot_mcp_toolkit/contract/bare_path_check.gd:24-26):

static func bare_path_message(
	property_name: String, raw_value: Variant, declared_type: int,
) -> String:

PropertySetCheck is another pure leaf (“preloads nothing”, its header says), and the lookup side depends on it, not the reverse: DeclaredTypeFitter walks a live object’s property list and preloads the check (addons/godot_mcp_toolkit/contract/declared_type_fitter.gd:20):

const PropertySetCheck := preload("res://addons/godot_mcp_toolkit/contract/property_set_check.gd")

The caller does the lookup and hands the rule a value (addons/godot_mcp_toolkit/commands/node_commands.gd:281-282):

var bare_path := BarePathCheck.bare_path_message(property_name, raw_value,
		DeclaredTypeFitter.declared_type(node, property_name))

Bad

The rule reaching out for its own data: it takes the live object, preloads the lookup, and can no longer be tested without one.

const DeclaredTypeFitter := preload("res://addons/godot_mcp_toolkit/contract/declared_type_fitter.gd")


static func bare_path_message(target: Object, property_name: String, raw_value: Variant) -> String:
	var declared_type := DeclaredTypeFitter.declared_type(target, property_name)

This shape is not in the tree; it is the one-entry-point design the rule turns down.

Source


This site uses Just the Docs, a documentation theme for Jekyll.