feat(core): improve useImportTypes detection#8824
Conversation
|
WalkthroughThis change introduces an EmbeddedValueReferences service that collects identifier and static-member usages from non-source JS snippets (templates). The service is built from embedded snippets in the workspace server, stored on DocumentServices, and propagated into the JS analyzer services. The use_import_type lint rule is updated to consult these embedded value references when deciding whether an import is used only as a type. Tests for Astro, Svelte and Vue templates were added to validate behaviour. Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
8c52bc3 to
ccf1f0c
Compare
dyc3
left a comment
There was a problem hiding this comment.
Even though I get the feeling that this will result in false negatives, it seems reasonable to me. Better false negatives than false positives.
I'll test it on some codebases I have.
Do you think we should add a disclaimer in the lint rule? |
dyc3
left a comment
There was a problem hiding this comment.
I'm still getting a lot of false positives for snippets from shadcn-svelte. Example:
<script lang="ts">
import { Avatar as AvatarPrimitive } from "bits-ui"; // <-- false positive
import { cn } from "$lib/utils.js";
let {
ref = $bindable(null),
class: className,
}: AvatarPrimitive.FallbackProps = $props();
</script>
<!-- used as value here -->
<AvatarPrimitive.Fallback
bind:ref
class={cn("bg-muted flex h-full w-full items-center justify-center rounded-full", className)}
/>
(also got some parsing errors, will open a separate issue for that)
TBH I don't think it'll be a big enough problem to warrant that. We can wait for bug reports. |
|
The main issue of the snippet you shared is that we don't properly parse namespace components such as I can improve the parsing in another PR, but as for now I think we can merge this PR Created #8880 |
Summary
Important
The code was generated with Claude Code. The plan was heavily and carefully prepared beforehand.
Part of #8590
This PR adds a new document service that tracks references inside non-source snippets. Then these references are sent as a service to the JS Analyzer.
The infrastructure is very similar to how embedded bindings work, so the implementation was trivial, hence the use of AI
Test Plan
Added new tests
Docs
No changeset because we already have one