Skip to main content

is_stabby_lambda_body

Function is_stabby_lambda_body 

Source
pub fn is_stabby_lambda_body<'a>(
    node: &Node<'a>,
    ancestors: Ancestors<'a, '_>,
) -> bool
Expand description

Whether node — a Block / DoBlock — is the body of a stabby lambda (->(z) { … } / ->(z) do … end), which parses as a Lambda node that CONTAINS the block. The Lambda wrapper already counts as the closure (#465) and opens the function space (#1257), so classifying the body again would double-count one lambda as two closures, or open a phantom nested Function space. The keyword forms lambda { } / proc { } and iterator blocks ([1].each { |x| x }) parse as a Call carrying the block argument — the parent is not a Lambda — so they still classify exactly once.

One helper shared by [Checker::is_closure], [Checker::is_func_space_with_code], and the cognitive lambda-nesting arm (crate::metrics::cognitive’s Ruby impl), so the closure count, the space tree, and the nesting surcharge cannot drift apart (.claude/rules/grammar-dispatch.md §6).

The parent comes off the caller’s chain: all consumers run per node from a walk, and Node::parent costs O(depth) because tree_sitter resolves it by descending from the root (#1088).