Skip to content

fix(lint): require single to target on transition statement#62

Merged
monga-puneet merged 4 commits into
mainfrom
pm/lint-transition-target
Jun 15, 2026
Merged

fix(lint): require single to target on transition statement#62
monga-puneet merged 4 commits into
mainfrom
pm/lint-transition-target

Conversation

@monga-puneet

@monga-puneet monga-puneet commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a new lint pass transitionTargetPass enforcing SPEC §5.10: a transition statement must have exactly one to <target> clause.

Two silent acceptance bugs are fixed:

  • Bare transition with no target — currently parsed and compiled with zero diagnostics.
  • Multiple to clauses on a single transition (e.g. transition to @a, to @b) — silently accepted; only one target is meaningful.

Both now produce ERROR diagnostics with stable codes transition-missing-target and transition-multiple-targets and spec-referenced messages. The missing-target diagnostic range is narrowed to the transition keyword token so the squiggle points at the actual problem.

Test plan

  • New unit tests in packages/language/src/lint/transition-target.test.ts (5 cases: valid form, bare, two-target, three-target, valid to ... with k=v)
  • pnpm --filter @agentscript/language test → 192/192 passing
  • pnpm --filter @agentscript/compiler test — no new regressions (pre-existing failures on main are unrelated to this change)

Adds `transitionTargetPass` enforcing SPEC §5.10: a `transition` statement
must have exactly one `to <target>` clause.

- Bare `transition` (no target) was silently accepted.
- Multiple `to` clauses (`transition to @A, to @b`) were silently accepted.

Both now produce ERROR diagnostics with stable codes
`transition-missing-target` and `transition-multiple-targets` and
spec-referenced messages. Fixtures cover the bare form, `with`-only,
missing-`to` typo, and multi-target cases.
The four finding-*.agent fixtures were not referenced by any test —
inline source strings in transition-target.test.ts already cover all
cases, matching the pattern used by every other lint pass in the repo.
Match the existing convention — no other lint pass cites SPEC § in
its user-facing message.
attachDiagnostic expects AstNodeLike; TransitionStatement does not
widen automatically, so the guard is load-bearing for the type check
even though the runtime invariant is already established by enterNode.

@setu4993 setu4993 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice catch.

Comment on lines +20 to +25
const MISSING_TARGET_MESSAGE =
"'transition' requires a target. Use 'transition to <target>'.";

const MULTIPLE_TARGETS_MESSAGE =
"'transition' accepts a single 'to' target. " +
"Multiple 'to' clauses are not allowed.";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These just get used here, so weird to have them defined as constants.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

java habbit :)

@monga-puneet monga-puneet merged commit 6748f5a into main Jun 15, 2026
7 checks passed
Sign up for free to 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.

2 participants