Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

fix(linter): skip useDestructuring for variables with type annotations#8975

Open
FrankFMY wants to merge 3 commits intobiomejs:mainfrom
FrankFMY:fix/use-destructuring-type-annotations
Open

fix(linter): skip useDestructuring for variables with type annotations#8975
FrankFMY wants to merge 3 commits intobiomejs:mainfrom
FrankFMY:fix/use-destructuring-type-annotations

Conversation

@FrankFMY
Copy link
Contributor

@FrankFMY FrankFMY commented Feb 5, 2026

AI disclosure: This PR was authored with the assistance of Claude (Anthropic). Claude helped explore the codebase, identify the fix location, implement the change, write tests, and prepare the PR.

Summary

Fixes #8478. The useDestructuring rule incorrectly flagged variable declarations with TypeScript type annotations. For example, const foo: string = object.foo was suggested to be destructured to const { foo } = object, which would lose the explicit : string type annotation.

Added a check for variable_annotation().is_some() in the JsVariableDeclarator branch, following the same pattern already used by use_array_literals. Also added TypeScript-specific test cases (valid.ts and invalid.ts) covering type annotations, definite assignments, and ensuring the rule still triggers for TS files without annotations.

Test Plan

  • cargo test -p biome_js_analyze -- use_destructuring — all 4 tests pass (2 existing JS + 2 new TS)
  • cargo fmt -- --check — no formatting issues

Docs

Updated the rule's doc comment with a TypeScript valid example demonstrating the skipped case.

Fixes biomejs#8478. The `useDestructuring` rule now ignores variable
declarations that have TypeScript type annotations, since destructuring
would lose the explicit type information.
@changeset-bot
Copy link

changeset-bot bot commented Feb 5, 2026

🦋 Changeset detected

Latest commit: 1d80f03

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Feb 5, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Walkthrough

The PR changes the nursery useDestructuring lint to skip suggestions when a JsVariableDeclarator includes an explicit TypeScript variable annotation (early return introduced). Adds TypeScript tests covering annotated (valid) and non‑annotated (invalid) cases and a patch changeset referencing issue #8478.

Possibly related PRs

Suggested reviewers

  • ematipico
  • dyc3
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main fix: skipping destructuring suggestions for variables with type annotations.
Description check ✅ Passed The description clearly explains the bug fix, implementation approach, test coverage, and includes helpful context about the assisted authorship.
Linked Issues check ✅ Passed All code changes directly address issue #8478: type annotation detection is implemented, destructuring is skipped for annotated variables, existing behaviour is preserved, and comprehensive tests cover both annotated and non-annotated cases.
Out of Scope Changes check ✅ Passed All changes remain focused on the useDestructuring rule fix: the logic change, test cases, documentation update, and changeset entry are all directly related to issue #8478.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 6, 2026

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 95 skipped benchmarks1


Comparing FrankFMY:fix/use-destructuring-type-annotations (1d80f03) with main (2cba2b3)2

Open in CodSpeed

Footnotes

  1. 95 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (5a341b2) during the generation of this report, so 2cba2b3 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 useDestructuring doesn't work with type annotations

1 participant