Summary
C#'s if / while / do condition slots read a fixed child index, so
a leading comment inside the parentheses shifts the read and the condition
scores zero.
$ # if (IsEven(x)) -> abc.conditions 1
$ # if (/*c*/ IsEven(x)) -> abc.conditions 0
This is the same class #1181
fixed for the ternary, and the same trap the when-guard slot added in
#1422
deliberately avoids: tree-sitter extras are named nodes, so a
first-named-child read hands the slot a comment. That arm iterates every
named child instead, and csharp_guard_keeps_its_condition_across_a_comment
pins it. The sibling slots were left to their own change rather than
widened into #1422.
Where
src/metrics/abc/csharp.rs, csharp_walk_for_conditions — the
IfStatement | WhileStatement and DoStatement arms, which use
csharp_inspect_child(node, idx, …) with a positional index. The guard arm
immediately below them shows the shape that survives extras.
Fix shape
Prefer child_by_field_name where the grammar exposes a field for the slot
(.claude/rules/grammar-dispatch.md §3). Where it does not, iterate named
children and pick by role, as the WhenClause | CatchFilterClause arm does.
Check the sibling languages in the same pass — java.rs, groovy.rs and
cpp.rs all carry positional inspect_child reads, and Groovy's
if / while (child(2)) and do-while (child(4)) are called out in
src/metrics/abc/groovy.rs as the last positional condition lookups after
#1181/#1276 migrated the rest.
Tests
A commented and an uncommented spelling of the same condition, asserted
against each other rather than against a literal, so the pair cannot
drift apart silently. Both block (/* */) and line (//) comments, since
they are separate extras.
Related
Summary
C#'s
if/while/docondition slots read a fixed child index, soa leading comment inside the parentheses shifts the read and the condition
scores zero.
This is the same class #1181
fixed for the ternary, and the same trap the
when-guard slot added in#1422
deliberately avoids: tree-sitter
extras are named nodes, so afirst-named-child read hands the slot a
comment. That arm iterates everynamed child instead, and
csharp_guard_keeps_its_condition_across_a_commentpins it. The sibling slots were left to their own change rather than
widened into #1422.
Where
src/metrics/abc/csharp.rs,csharp_walk_for_conditions— theIfStatement | WhileStatementandDoStatementarms, which usecsharp_inspect_child(node, idx, …)with a positional index. The guard armimmediately below them shows the shape that survives extras.
Fix shape
Prefer
child_by_field_namewhere the grammar exposes a field for the slot(
.claude/rules/grammar-dispatch.md§3). Where it does not, iterate namedchildren and pick by role, as the
WhenClause | CatchFilterClausearm does.Check the sibling languages in the same pass —
java.rs,groovy.rsandcpp.rsall carry positionalinspect_childreads, and Groovy'sif/while(child(2)) anddo-while(child(4)) are called out insrc/metrics/abc/groovy.rsas the last positional condition lookups after#1181/#1276 migrated the rest.
Tests
A commented and an uncommented spelling of the same condition, asserted
against each other rather than against a literal, so the pair cannot
drift apart silently. Both block (
/* */) and line (//) comments, sincethey are separate extras.
Related
whenguard on a switch arm is a branch neither metric counts #1422 — where the guard slot was written extras-safe and the siblingslots deliberately were not.