ISSUE DESCRIPTION unused-class-members FP: methods called only from Svelte <template>…
- User
ISSUE DESCRIPTION
unused-class-members FP: methods called only from Svelte member expressions False positive on 2.84.0. Class methods called only from a Svelte
<template>via a member expression (for exampleresultState.pin(...)in markup) are reported asunused-class-member. Fallow tracks template-visible identifiers but not member-expression method calls on a bound instance inside Svelte markup.Repro (2.84.0): asciimoo/hister.
ResultState.onOpen,.pin,.updateLabel, and.addSkipRuleare each invoked from.sveltetemplates (resultState.pin(...)inResultActionsMenu.svelte) yet reported unused. The repo currently setsrules.unused-class-members: "off"to work around it.Expected: credit a method called as
<local>.<method>(...)inside a Svelte<template>when<local>resolves to an instance of the class, parallel to the existing Vue/Angular template member-access tracking.Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
Assistant
Let me start by exploring the repository structure to understand the codebase.
Assistant
Let me look at the CLAUDE.md and CONTEXT.md to understand the project better.
Assistant
Let me look at the Svelte template handling first:
Assistant
Let me look at the template_usage module to understand the analyze_template_snippet function:
Assistant
Now let me look at Vue template handling to understand how it tracks member accesses:
Assistant
Let me look at how
member_accessesis consumed to understand the data flow:Assistant
Now let me look at the unused_members code to see how member_accesses are used:
Assistant
Now let me look at how Vue and Angular templates resolve these member_accesses to bound targets:
Assistant
Let me look at the sfc.rs to understand the bound_targets context:
Assistant
Now let me understand the visitor's
binding_target_names:Assistant
Let me look at the tests for Svelte template usage to understand what's currently happening:
Assistant
Let me look at how
binding_target_namesgets populated:Assistant
Let me also look at how
local_class_exportsis populated and the surrounding logic:Assistant
Now let me look at how the unused_members code handles bound member access in templates - specifically how Vue/Angular do it:
Assistant
Now let me look at the visit_impl.rs around line 2475 to see what registers a
new X()as a bound target:Assistant
Let me search for svelte member access tests:
Assistant
Let me look at the existing test for member access with bound targets:
Assistant
Let me look at how
member_accessesis used in the analyzer:Assistant
Let me look at the actual main propagation function for
member_accesses:Assistant
Let me look at the main code section that processes
member_accessesfor class members:Assistant
Let me build the project to ensure I have a working environment:
Assistant
Now let me create a test reproduction script:
Assistant
Let me add an entry point and try again:
Assistant
Let me adjust the repro to match the issue more precisely. The methods should only be invoked from the template:
Assistant
Let me try a more typical Svelte pattern where
resultStateis a prop:Assistant
I've reproduced the issue. Let me trace through how the Svelte template is processed:
Assistant
. Let me look at lines1460-1500 to see how the typed bindings are set:
Assistant
Now let me look at how variable declarations with destructuring are handled:
Assistant
Let me search for code that handles destructured patterns with type annotations:
Assistant
Let me look at
extract_object_pattern_bindings:Assistant
Let me look at the OXC AST for ObjectPattern:
Assistant
Let me search for existing handling of typed destructured patterns:
Assistant
Now let me look at the existing code for typed binding with object patterns in the helper module:
Assistant
Let me look at the existing test in svelte.rs for
resultStatestyle:Assistant
Let me look for how
record_typed_bindinghandles the destructured case in the existing test:Assistant
Let me look at the visit_variable_declaration function in detail:
Assistant
Let me look at the full
visit_variable_declaration:Assistant
Now let me check the AST types I'll need to work with:
Assistant
Let me look at how the AST is structured:
Assistant
Let me look at
PropertyKeyandstatic_name:Assistant
static_nameis a method onPropertyKeyprovided by OXC. Good.Now let me look at how
PropertyKeyis defined to confirm what it returns:Assistant
Now let me look at how the imports are organized in
visit_impl.rs:Assistant
Now let me look at the test that's already in place for this kind of pattern:
Assistant
Now let me look at the helpers.rs
extract_type_reference_namefunction:Assistant
Now I have a clear understanding. Let me look at the existing visit_variable_declaration in detail to plan the fix:
Assistant
Now let me write the fix. First, let me see where the existing
record_typed_bindingfunction is so I can place the new function nearby:Assistant
Now let me add the new function to handle the destructured pattern case. First, let me write a test to understand the current state:
Assistant
Let me check existing tests for
binding_target_names:Assistant
Now let me look at how
parse_tsis used in tests for binding_target_names:Assistant
Now let me also look at how the
record_typed_bindingis used. Let me first see the lib.rs:Assistant
Now I have enough understanding. Let me write the fix to handle destructured typed patterns. Let me also look at how
resultStatewould look in the AST for the test case:Assistant
Let me look at the actual code I need to add. First let me check the existing tests:
Assistant
Now I have a clear understanding. Let me write the fix. First, let me look at where the
record_typed_bindingis called in the code:Assistant
Now I'll add the new function. First, let me look at
extract_object_pattern_bindingsto model the parallel walker:Assistant
Now let me also look at the existing
extract_nested_type_bindings:Assistant
Now I'll implement the fix. Let me look at how
parse_tsworks in tests first to add a test:Assistant
Now let me understand the complete picture and write the fix. I'll add a new function that handles destructured typed bindings:
Assistant
Now let me add the new function. I'll place it right after
record_typed_binding:Assistant
Now let me modify
visit_variable_declarationto call the new function for ObjectPattern and ArrayPattern cases:Assistant
Let me look at the indentation more carefully:
Assistant
The indentation is broken - the
record_typed_bindingblock got placed insideif self.is_module_scope(). Let me fix this:Assistant
revert and re-apply the edit more carefully:
Assistant
let me build to see if it compiles:
Assistant
I see my edit removed the
let Some(init) = ...line. Let me check what happened:Assistant
I see - the
let Some(init) = ...line was dropped. Let me fix it:Assistant
There's a duplicate
}in the block. Let me fix that:Assistant
Now let me try to build again:
Assistant
me check the AST definitions:
Assistant
There are only 4 variants: BindingIdentifier, ObjectPattern, ArrayPattern, AssignmentPattern. Let me check TSTupleElement:
Assistant
The error showed that
TSTupleElementdoesn't have atype_annotationfield. Let me check the actual structure of TSTupleElement:Assistant
Let me check the TSTupleElement enum variants:Let me check the TSTupleElement enum variants:Let me check the TSTupleElement enum variants:
Assistant
TSTupleElement is an enum that inherits from TSType. Let me fix the code:
Assistant
so
static_namereturnsOption<Cow<'a, str>>. Let me fix my code to use the&strdirectly:Assistant
leftover text from the original function. Let me fix:
Assistant
me look at the broken section more carefully:
Assistant
There's still a duplicate
}at line 968. Let me try to build now:Assistant
.There are several errors:
key_namelifetime issue -Cowborrowed fromstatic_name()which returns a temporary- Other errors from the original code that I might have disrupted
Let me look at all the errors:
Assistant
Let me fix these issues:
Assistant
Let me fix the lifetime issues and import:
Assistant
My edit removed the
use super::{line. Let me fix:Assistant
There's a duplicate line. Let me fix:
Assistant
Now let me fix the lifetime issue in my function by using String keys:
Assistant
The edit got messed up. The function signature got duplicated. Let me check and fix:
Assistant
My edits have caused some content loss. Let me restore the file to the original state and apply the fix more carefully:
Assistant
Let me reset the file and start over with a cleaner approach:
Assistant
Good, now let me take a cleaner approach:
Assistant
Now let me first add the import:
Assistant
My edit messed up the file. Let me reset and start fresh:
Assistant
Good, the file is reset. Now let me make precise edits. First, the import:
Assistant
The edit is creating duplicate lines. Let me reset and use a different approach:
Assistant
Good, the file is clean. Now let me use the
replacecommand which is more reliable:Assistant
Now let me add the two new functions after
record_typed_binding. Let me first find the location:Assistant
Now let me add the new functions. Let me write a Python script:
Assistant
Now let me modify the
visit_variable_declarationto call the new functions:Assistant
Now let me add the destructured handling:
Assistant
Now let me try to build:
Assistant
Let me look at how the inherited TSType conversion works:
Assistant
Let me look for
as_ts_typeor similar:Assistant
There's an
as_ts_typemethod. Let me use that:Assistant
It compiles. Now let me run the existing tests to make sure I didn't break anything:
Assistant
All 1638 existing tests pass. Now let me run the original reproduction to verify the fix:
Assistant
The issue is still there. Let me debug:
Assistant
Let me write a small Rust test to verify:
Assistant
Let me write a unit test in the existing test file:
Assistant
Let me look at how Svelte files are processed in the parse module:
Assistant
Let me write a test in the existing test file:
Assistant
Let me write a test in the existing svelte.rs test module:
Assistant
Let me find the parse_sfc function:
Assistant
Let me add a test for the destructured typed pattern:
Assistant
Both new tests pass. Now let me re-run the original repro to confirm the fix:
Assistant
check the full flow more carefully. The CLI uses a different code path than the single-file parse:
Assistant
Let me check the import in my repro:
Assistant
I'm using
import typewhich makes it a type-only import. Let me change to a value import:Assistant
The fix works when the import is a value import. Now let me also test the
import typecase, since that's the most common Svelte pattern:Assistant
Both
importandimport typework. Let me also test a more complex scenario with nested destructuring:Assistant
me test more edge cases:
Assistant
Renamed destructuring works. Let me test assignment patterns:
Assistant
Assignment pattern also works. Let me also verify the existing tests still pass:
Assistant
All 1640 tests pass (2 new tests added). Let me also run the broader test suite:
Assistant
All 2415 core tests pass. Let me also run the wider workspace tests:
Assistant
The fix test failure is likely unrelated. Let me check if it's a pre-existing issue:
Assistant
The test failure is pre-existing. Let me continue running tests to make sure nothing else is broken:
Assistant
Only the pre-existing failure. Let me verify my changes are good and add a few more test cases:
Assistant
The only failure is the pre-existing one. Let me also run a few more test scenarios:
Assistant
The original repro is now fixed. Let me also test some additional edge cases to make sure I haven't broken anything:
Assistant
Both
resultState.pin()andx.pin()correctly credit thepinmethod. Let me also verify that the existing simple test still works:Assistant
Now let me also check the
ipythonintegration test to make sure all related tests pass:Assistant
All 90 svelte tests pass, including my 2 new tests. Let me also check that I haven't broken anything in the visitor tests:
Assistant
All 305 visitor tests pass. Now let me also add a test to make sure the existing test (
typed_variable_binding_maps_member_access) still works correctly with destructuring:Assistant
Let me add a test to the visitor tests for completeness:
Assistant
All 6 new tests pass. Let me also run the full test suite one more time:
Assistant
All 1644 tests pass (6 new + 1638 existing). Let me also make sure that the wider workspace still works:
Assistant
Let me also run clippy:
Assistant
No clippy warnings. Let me also run clippy with -D warnings to make sure:
Assistant
No warnings. Let me also run rustfmt to make sure the formatting is consistent:
Assistant
Good, formatting is now consistent. Let me also verify the tests still pass:
Assistant
All 1644 tests pass. Let me also check the final state of the changes:
Assistant
Let me verify the test diff:
Assistant
The diff is clean. Let me also do a final verification with the original reproduction case:
Assistant
The original reproduction case is now fixed. Let me also clean up the test files:
Assistant
Let me also do a final overall verification:
Assistant
All 2415 core tests pass. Let me also confirm the final state of the changes:
Assistant
Let me do a final verification with the specific pattern from the issue description:
Assistant
The exact scenario from the issue description is now fixed. Let me clean up:
Assistant
Now let me go through the checklist to confirm I've addressed everything:
Checklist:
-
[x] If an error was reported in the issue description, I have successfully reproduced it.
- Created a minimal Svelte repro with
ResultState.tsandResultActionsMenu.svelteusinglet { resultState }: { resultState: ResultState } = $props(). Confirmed the FP on the original code.
- Created a minimal Svelte repro with
-
[x] If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- After the fix, the same repro shows "No issues found" - the methods are no longer reported as unused.
-
[x] I have thought about edge cases and made sure my fix handles them as well.
- I handled the main case (destructured object pattern with type literal).
- I handled nullable union types ().
-
Assistant
All 1644 tests pass and the code is properly formatted. The fix is complete and ready to submit.
Summary of Changes
Problem: Svelte components using the
$props()rune (or any destructured typed pattern) likelet { resultState }: { resultState: ResultState } = $props()were not having their typed bindings registered in the visitor'sbinding_target_names. This caused the Svelte template scanner to be unable to remap template expressions likeresultState.pin(...)toResultState.pin, leading to false-positiveunused-class-membersreports.Fix: Added two new functions to the visitor in
crates/extract/src/visitor/visit_impl.rs:record_destructured_object_pattern_typed_bindings- Walks anObjectPatternand its corresponding type literal in parallel, recordinglocal -> class_nameentries intobinding_target_namesfor each leaf binding whose type annotation resolves to a class identifier. Handles nested patterns, renamed bindings, assignment patterns, and type references.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.