Repository navigation
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe declaration exclusion regex now accepts optional TypeScript annotations before declaration delimiters. Regression tests and fixtures cover identifier extraction from annotated declarations and destructuring. ChangesAnnotated declaration matching
Priority: ⚪ Not assessed Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to Annotated declarations retain correct local-variable detection, and later hook references remain eligible for auto-import. No actionable risk remains. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. 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 |
Problem
The regex scanner that collects locally declared names (
RE_EXCLUDE[3]) only ends a declaration at=,;,\n,oforin. With a TypeScript annotation between the pattern and the=, the destructuring branch can't end at its own bracket. Because of thesflag, the lazy\{.*?\}/\[.*?\]then keeps going across lines until some later}/]happens to come right before=,;or a newline.Every identifier in that span is treated as a local declaration, so it is never auto-imported:
On
mainthis injects nothing:{ value }: Props = props … const config = { value }is captured as one pattern, anduseState/useEffectare counted as locals. Array patterns do the same (const [first]: [number] = f()stretches to the next]followed by=or a newline). A plain annotation likeconst count: number = 1also yieldscount: numberrather thancount.This looks like a different trigger for the same widening described in #525. It is not a fix for the
for-loop case there, which #522 already handled.Fix
Match an optional same-line annotation (
:[^=;\n]*) outside the captured group, before the terminator. Destructuring patterns now close at their own bracket, and the annotation text is no longer part of the collected names. The annotation can't cross=,;or a newline, so it can't extend the match.Tests
test/existing-scanning.test.ts: annotated simple, object and array declarations, plus two multi-line cases that check the scan stops at the annotated pattern. These 5 cases fail onmain.test/cases/positive/ts-annotated-destructuring.tswith its snapshot: the end-to-end repro above. It now getsimport { useState, useEffect } from 'react'. Onmainit fails because nothing is injected.vitest run: 28 files, 260 tests pass.eslint src testandvue-tsc --noEmitare clean.Summary by CodeRabbit