Skip to content

test(language/lint): add unit tests for unreachable-code pass#65

Open
dsorajisto wants to merge 1 commit into
salesforce:mainfrom
dsorajisto:test-unreachable-code-lint-pass
Open

test(language/lint): add unit tests for unreachable-code pass#65
dsorajisto wants to merge 1 commit into
salesforce:mainfrom
dsorajisto:test-unreachable-code-lint-pass

Conversation

@dsorajisto

Copy link
Copy Markdown
Contributor

What

Adds 5 unit tests for the unreachable-code lint pass in packages/language/src/lint/unreachable-code.ts. Brings the rule's test count from 0 to 5.

Why

The unreachable-code rule flags code that follows a terminal statement — either a bare transition or an if/else block where all branches transition. It had no tests pinning down its behavior. This closes the gap using the same pattern PRs #38 (required-fields.test.ts), #48 (empty-block.test.ts), and #60 (unused-variable.test.ts) established for single-rule lint tests.

How

New test file at packages/language/src/lint/unreachable-code.test.ts using vitest. Follows unsupported-conditionals.test.ts exactly: single describe block, flat it cases, shared getDiagnostics helper, and the same ProcBlock / ProcedureValue schema shape so the procedural fixtures parse correctly.

The 5 cases:

  1. Flags code after a transition
  2. Does not flag a procedure whose last statement is a transition
  3. Flags code after an if/else where both branches transition
  4. Does not flag code after an if/else where only one branch transitions
  5. Flags unreachable code inside a nested if body

Test Plan

pnpm --filter @agentscript/language test unreachable-code

Result:

✓ src/lint/unreachable-code.test.ts (5 tests) 7ms
Test Files  1 passed (1)
     Tests  5 passed (5)
  • pnpm --filter @agentscript/language test unreachable-code — 5/5 passing
  • npx eslint --config eslint.config.js packages/language/src/lint/unreachable-code.test.ts — exit 0
  • New/updated tests cover the change — N/A (this PR is the tests)

Checklist

  • My code follows the project's coding style
  • I have reviewed my own diff
  • I have added/updated documentation as needed
  • This change does not introduce new warnings

Adds 5 unit tests for the unreachable-code lint pass in
packages/language/src/lint/unreachable-code.ts, which detects code
that follows a terminal statement (transition, or an if/else where
all branches transition).

Coverage:
- Code after a transition → flagged
- Procedure ending in a transition → not flagged
- Code after a fully-transitioning if/else → flagged
- Code after a half-transitioning if/else → not flagged
- Unreachable code inside a nested if body → flagged

Follows the same test pattern as required-fields.test.ts (salesforce#38),
empty-block.test.ts (salesforce#48), and unused-variable.test.ts (salesforce#60).

All tests pass via:

    pnpm --filter @agentscript/language test unreachable-code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant