Skip to content

test(language/lint): add unit tests for unused-variable pass - #60

Open
dsorajisto wants to merge 1 commit into
salesforce:mainfrom
dsorajisto:test-unused-variable-lint-pass
Open

dsorajisto wants to merge 1 commit into
salesforce:mainfrom
dsorajisto:test-unused-variable-lint-pass

Conversation

@dsorajisto

Copy link
Copy Markdown
Contributor

What

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

Why

The unused-variable rule flags variables declared in the variables: block that are never referenced via @variables.<name> expressions, but had no tests pinning down its behavior. This closes the gap using the same pattern PRs #38 (required-fields.test.ts) and #48 (empty-block.test.ts) established for single-rule lint tests.

How

New test file at packages/language/src/lint/unused-variable.test.ts using vitest. Follows empty-block.test.ts exactly: single describe block, flat it cases, shared getDiagnostics helper. The test schema combines VariablesBlock (for variable declarations) with a small custom ValueBlock whose expr: ExpressionValue field provides somewhere for expressions to reference those variables.

The 5 cases:

  1. Flags a variable that is declared but never referenced
  2. Does not flag a variable that is referenced in an expression
  3. Flags only the unused variables when multiple are declared
  4. Reports one diagnostic per unused variable
  5. Does not flag variables when no variables: block is declared

Test Plan

pnpm --filter @agentscript/language test unused-variable

Result:

✓ src/lint/unused-variable.test.ts (5 tests) 6ms
Test Files  1 passed (1)
     Tests  5 passed (5)
  • pnpm --filter @agentscript/language test unused-variable — 5/5 passing
  • npx eslint --config eslint.config.js packages/language/src/lint/unused-variable.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

@dsorajisto

Copy link
Copy Markdown
Contributor Author

Hi, ust checking if there's anything blocking review here. Happy to update if the pattern needs to change, or close if the project isn't looking for more single-rule test PRs right now. No rush; wanted to check the temperature.

setu4993 pushed a commit that referenced this pull request Sep 3, 2026
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 (#38),
empty-block.test.ts (#48), and unused-variable.test.ts (#60).

All tests pass via:

    pnpm --filter @agentscript/language test unreachable-code
Adds 5 unit tests for the unused-variable lint pass in
packages/language/src/lint/unused-variable.ts, which flags variables
declared in the `variables:` block that are never referenced via
`@variables.<name>` expressions elsewhere.

Coverage:
- Declared-but-unreferenced variable → flagged
- Variable referenced in an expression → not flagged
- Mixed used/unused → only the unused ones flagged
- One diagnostic per unused variable when multiple are unused
- No `variables:` block → no diagnostics

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

All tests pass via:

    pnpm --filter @agentscript/language test unused-variable
@dsorajisto
dsorajisto force-pushed the test-unused-variable-lint-pass branch from 573b748 to 6484a8d Compare October 18, 2026 03:31
@dsorajisto

Copy link
Copy Markdown
Contributor Author

Rebased onto the latest main; no conflicts and the language suite passes (370 tests). This follows the same pattern as #65 and #90, which have since been merged. Happy to adjust anything if needed.

@BichengWang BichengWang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed 6484a8d34066cb10eaa2199adbff00c249fe2dc2 against ace15eb2dc75564fd9e214385ac045c539056770. No blocking findings.

The five cases exercise the actual parser → dialect → lint path and distinguish unused declarations from referenced ones, including a mixed declaration block. I checked that they detect both sides of the rule: temporarily ignoring expression references made the referenced-variable and mixed-variable tests fail (2/5 failures), while suppressing diagnostic emission made the three unused-variable cases fail (3/5 failures). Both mutations were reverted, and all 370 language tests then passed, including the five added here.

Offline validation used Node 22.20.0 and pnpm 10.34.6. The language package build/typecheck and ESLint/Prettier checks for the new file passed. The normal Turbo dependency build was blocked by the missing tree-sitter CLI; I built the types, JavaScript parser, parser interface, and language packages separately. The full monorepo suite and native parser suite were not run.

This branch has not been deployed

No deployments
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.

2 participants