Repository navigation
test(language/lint): add unit tests for unused-variable pass - #60
dsorajisto wants to merge 1 commit into
Conversation
|
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. |
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
573b748 to
6484a8d
Compare
BichengWang
left a comment
There was a problem hiding this comment.
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.
What
Adds 5 unit tests for the
unused-variablelint pass inpackages/language/src/lint/unused-variable.ts. Brings the rule's test count from 0 to 5.Why
The
unused-variablerule flags variables declared in thevariables: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.tsusing vitest. Followsempty-block.test.tsexactly: singledescribeblock, flatitcases, sharedgetDiagnosticshelper. The test schema combinesVariablesBlock(for variable declarations) with a small customValueBlockwhoseexpr: ExpressionValuefield provides somewhere for expressions to reference those variables.The 5 cases:
variables:block is declaredTest Plan
Result:
pnpm --filter @agentscript/language test unused-variable— 5/5 passingnpx eslint --config eslint.config.js packages/language/src/lint/unused-variable.test.ts— exit 0Checklist