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

test(language/lint): add unit tests for unused-variable pass#60
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

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
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