Skip to content

docs(ast-grep): propagate counter-total-suffix syntax findings - #12

Merged
bborbe merged 1 commit into
masterfrom
feat/astgrep-guide-context-selector
Jun 2, 2026
Merged

docs(ast-grep): propagate counter-total-suffix syntax findings#12
bborbe merged 1 commit into
masterfrom
feat/astgrep-guide-context-selector

Conversation

@bborbe

Copy link
Copy Markdown
Owner

Summary

Folds the ast-grep 0.43.0 syntax recipe from PR #11 into `docs/ast-grep-rule-writing-guide.md` so the next bootstrap PR doesn't re-learn the traps.

153 → 193 lines (+40).

What's added

New section: 'Struct-literal field matching' — covers the 3-piece recipe:

  1. `pattern.context + selector` — required because bare `'Name: $X'` parses as a Go `labeled_statement` (Name = goto label), not as a struct `keyed_element`.
  2. `inside.pattern + stopBy: end` — re-anchors on the enclosing literal type so siblings (`GaugeOpts` / `HistogramOpts` / `SummaryOpts`) don't false-flag through the selector.
  3. `constraints` at rule-top-level (sibling of `rule:`, NOT under `rule.pattern.constraints`) with `not.regex` inside the metavariable spec.

Three new entries in 'Pitfalls Learned':

  • `'Name: $X'` parses as labeled_statement
  • `pattern.context` alone leaks to sibling types
  • `constraints` placement: top-level sibling, not nested

Canonical example entry for `rules/go/counter-total-suffix.yml` (the rule that landed in PR #11).

Why

PR #4 burned cycles on factory-pattern YAMLs (returned to field-based `has` clauses after invalid `regex` at rule-top-level). PR #8 deferred `counter-total-suffix` entirely after early YAML attempts produced zero matches. PR #11 cracked the recipe. The guide is the right home for the discovery — bootstrap authors check it before writing the YAML, not during the debug loop.

Test plan

  • `make precommit` clean
  • No personal vault paths
  • No trading-domain terms
  • Cross-reference to `rules/go/counter-total-suffix.yml` resolves

PR #11 cracked the ast-grep 0.43.0 recipe for struct-literal field
matching after PR #4 and PR #8 both burned cycles iterating on
zero-match patterns. Folding the discoveries into the guide so the
next bootstrap PR doesn't re-learn them.
New section 'Struct-literal field matching' covers the 3-piece recipe:
1. pattern.context + selector for sub-node targeting (bare 'Name: $X'
parses as labeled_statement, not keyed_element — must wrap in context)
2. inside.pattern with stopBy: end for type anchoring (prevents
GaugeOpts / HistogramOpts / SummaryOpts false-flags through the
selector)
3. constraints at rule-top-level (NOT under rule.pattern.constraints),
with not.regex inside the metavariable spec
Pitfalls Learned grew by 3 entries documenting the specific traps:
- 'Name: $X' parses as labeled_statement
- pattern.context alone leaks to sibling types
- constraints placement: top-level sibling of rule, not nested
Canonical example entry added pointing to rules/go/counter-total-suffix.yml
(landed in PR #11). 153 → 193 lines.
No personal vault paths, no trading-domain terms — pre-emptive grep clean.

@ben-s-pull-request-reviewerben-s-pull-request-reviewerBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed by ben-s-pull-request-reviewer[bot] — no concerns flagged.

@bborbe
bborbe merged commit c07b809 into masterJun 2, 2026
1 check passed
@bborbe
bborbe deleted the feat/astgrep-guide-context-selector branch June 2, 2026 09:31
bborbe added a commit that referenced this pull request Jun 2, 2026
Bot review on b75eb2f: COMMENTED state with body 'no concerns flagged' — effective approval. Same pattern as PR #3 + PR #12 (bot's no-findings code path returns terse COMMENT rather than APPROVE verdict). Doc-only PR; CI green; previous CHANGES_REQUESTED review's 8 MAJOR + 1 NIT all addressed in b75eb2f.
bborbe added a commit that referenced this pull request Jun 2, 2026
Bot review on cd0f4fa: COMMENTED state with body 'no concerns flagged' — effective approval. Same pattern as PRs #3 / #12 / #17 (bot's no-findings code path returns terse COMMENT rather than APPROVE verdict JSON). Doc-only PR; CI green. This PR closes the schema-doc gap exposed by PR #19.
bborbe added a commit that referenced this pull request Jun 2, 2026
Bot review timed out at 30-min activeDeadlineSeconds ceiling — the dispatcher refactor + 5-phase scaffolding produced a diff larger than the reviewer's per-PR budget. Admin-merge per PR #3 / #12 / #17 / #20 precedent. Differs from prior admin-merges in that this changes the actual /coding:pr-review contract (not doc-only), but: (1) make precommit clean including new check-coverage; (2) validate-citations.sh smoke-tested valid + invalid cases; (3) check-coverage.sh against current state: '124 rules, 15 mechanical YAMLs, no drift'; (4) the 3 simplified agents (go-error, go-time, go-context) are forward-compatible with the legacy 'scan + judge' shape — the dispatcher tolerates both during the per-agent migration follow-ups.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@bborbe