fix(linter): skip useDestructuring for variables with type annotations#8975
fix(linter): skip useDestructuring for variables with type annotations#8975FrankFMY wants to merge 3 commits intobiomejs:mainfrom
Conversation
Fixes biomejs#8478. The `useDestructuring` rule now ignores variable declarations that have TypeScript type annotations, since destructuring would lose the explicit type information.
🦋 Changeset detectedLatest commit: 1d80f03 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
WalkthroughThe PR changes the nursery Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
Summary
Fixes #8478. The
useDestructuringrule incorrectly flagged variable declarations with TypeScript type annotations. For example,const foo: string = object.foowas suggested to be destructured toconst { foo } = object, which would lose the explicit: stringtype annotation.Added a check for
variable_annotation().is_some()in theJsVariableDeclaratorbranch, following the same pattern already used byuse_array_literals. Also added TypeScript-specific test cases (valid.tsandinvalid.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 issuesDocs
Updated the rule's doc comment with a TypeScript valid example demonstrating the skipped case.