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.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /fallow, current file: none) bash-$
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate relevant files. Let me first get an overview.
- Assistant
Let me get a better overview of the project structure.
- Assistant
This is a Rust project. Let me look at the crates directory to understand the structure.
- Assistant
Let me understand the project structure and find the relevant code for the
unused-class-membersrule. - Assistant
Let me look for the unused_members.rs file, which is likely where the unused-class-members rule is implemented.
- Assistant
Let me look at the unused_members.rs file to understand how the unused-class-members rule works.
- Assistant
Let me continue reading this file to understand how it handles Svelte templates. Let me search for "svelte" in the file.
- Assistant
No mention of "svelte" in unused_members.rs. Let me search for template-related logic more broadly.
- Assistant
Now let me understand how Angular templates are handled. I see references to
ANGULAR_TPL_SENTINEL. Let me also search for Vue and other template handling patterns. - Assistant
Now let me search for Svelte template handling throughout the codebase:
- Assistant
Let me search for how Vue/Angular template member expressions are tracked, and look for the extract code that handles templates:
- Assistant
Now I see how Angular template sentinel works. Let me understand the pattern:
- Angular template members are recorded with a special sentinel
ANGULAR_TPL_SENTINELas theobjectfield. - In the analysis phase (unused_members.rs), these sentinel accesses are detected and bridged to the owning class methods.
I need to create a similar mechanism for Svelte templates. Let me first understand how Svelte templates are parsed:
- Angular template members are recorded with a special sentinel
- Assistant
There's already a svelte.rs file! Let me read it to understand what's already there.
- Assistant
Let me read more of this file and understand how Svelte templates are handled, and then look at the Angular template handling to understand how the sentinel approach works.
- Assistant
Let me search for how the Svelte template handles member expressions and understand what's missing:
- Assistant
Let me look at the TemplateUsage struct to understand what it tracks.
- Assistant
Let me check the TemplateUsage struct:
- Assistant
Now let me understand how the Angular template chain accesses work and how they're bridged to the analysis phase. Let me look at the relevant parts more closely:
- Assistant
Now let me understand how Vue templates are handled, since the issue mentions Vue/Angular:
- Assistant
Let me understand the Svelte template scanning more deeply - looking at how expressions are processed and how bound_targets are used:
- Assistant
Let me look at the
apply_tagandapply_markup_tagfunctions and thebound_targetshandling: - Assistant
Let me now look at how
merge_expression_usage_allow_dollar_refs_with_bound_targetsworks and how it handles member expressions: - Assistant
Let me look at the
merge_expression_usage_allow_dollar_refs_with_bound_targetsfunction: - Assistant
Let me continue reading to find
merge_expression_usage_allow_dollar_refs_with_bound_targetsandmerge_snippet_usage_with_bound_targets: - Assistant
Now let me look at
analyze_template_snippet_with_bound_targetsto understand how bound_targets are processed: - Assistant
Now let me understand how Svelte template member accesses are captured and how they link to class members. Let me look at the full analysis flow:
- Assistant
Let me look at how bound_targets are populated for Svelte templates - this is where the link between template variable and class is established:
- Assistant
Let me look at the sfc.rs file to understand how bound_targets are populated:
- Assistant
Let me continue reading to understand how the bound_targets are populated for Svelte.
- Assistant
Let me continue reading to see how the template_visible_bound_targets are populated and how apply_template_usage works:
- Assistant
Let me continue reading to see how
apply_template_usageworks: - Assistant
Let me now understand the key flow - how
bound_targetsgets processed inanalyze_template_snippet_with_bound_targets: - Assistant
Let me look at the
remap_object_namefunction to understand how bound_targets are remapped: - Assistant
Now I understand the flow. The key is
remap_object_namewhich maps bound_targets to their class names. Let me now understand how HTML attributes in Svelte are processed: - Assistant
Let me look at the
apply_markup_tagfunction: - Assistant
Let me look at
merge_markup_brace_usageandmerge_attribute_value_usage: - Assistant
Now let me look at the existing tests in the svelte.rs file to understand what's currently being tested:
- Assistant
Let me look at the test for event handler arrow member access:
- Assistant
Now I see that the Svelte template scanner already correctly maps
counter.bump()toCounter.bumpwhencounteris a bound target. So the issue must be in how these member accesses are handled in the analysis phase. Let me look at how member accesses from SFC templates are used inunused_members.rs: - Assistant
Let me look at the Angular template chain accesses bridge logic to understand how it works:
- Assistant
Now let me understand how the member accesses from SFC files flow through the analysis. Let me look at the full analysis pipeline to see how SFC member accesses are processed:
- Assistant
Let me look at the main analysis function to see how member accesses are processed for SFC files:
- Assistant
Let me search for the main entry point of the unused_members analysis:
- Assistant
Let me look at the main entry point and trace through the logic.
- Assistant
Let me look at how regular member accesses are processed in the analysis:
- Assistant
Let me look at
build_local_to_export_keysto understand how local names map to export keys: - Assistant
Let me look at the function and the flow of how member accesses are processed.
- Assistant
Let me now understand how
binding_target_names()works to populatetemplate_visible_bound_targets: - Assistant
Now let me look at the main loop that processes member accesses to understand the full flow:
- Assistant
Now I see the main processing loop. Let me understand the SFC to ResolvedModule flow. Let me check how member_accesses flow from ModuleInfo to ResolvedModule:
- Assistant
Let me find the ResolvedModule struct:
- Assistant
Let me check the existing tests for SFC template handling in unused members:
- Assistant
Let me look at the integration test for SFC parsing to understand how it handles Svelte template member access:
- Assistant
Let me continue reading this test:
- Assistant
Let me look at the vue-project fixture to understand how the Vue template member access pattern works:
- Assistant
Let me look at the vue-project fixture to understand the pattern.
- Assistant
Let me look at the Vue fixture files and see how the Counter class is structured.
- Assistant
Let me look at the App.vue to see how the Counter class is used in a Vue template:
- Assistant
Now I see the pattern! In the Vue template, there's
const counter = new Counter()and thencounter.bump()andcounter.valuein the template. Let me look at the Counter class: - Assistant
Now I understand the pattern. The Vue test verifies that
Counter.bumpandCounter.valueare correctly credited when used from a Vue template viacounter.bump()andcounter.value. This works because:- The Vue SFC parser identifies
counteras a bound target mapping toCounter - The template scanner maps
counter.bump()toMemberAccess { object: "Counter", member: "bump" } - This gets added to the SFC module's
member_accesses - In the analysis,
local_to_export_keys["Counter"]resolves to the export key of theCounterclass - The member access is credited
Now the question is: why doesn't this work for Svelte? Let me check if there's a similar Svelte fixture or test:
- The Vue SFC parser identifies
- Assistant
Let me look at the existing svelte-project fixture:
- Assistant
Let me look at the existing svelte test fixture:
- Assistant
Now I can see the exact pattern. In the Svelte template, there's
const counter = new Counter()andcounter.bump()andcounter.valuein the template. This is the same pattern as the Vue test. Let me check if there's a test that verifies this for Svelte: Let me check the existing test for Svelte template event handlers: - Assistant
Let me check the sfc_parsing tests for Svelte template tests:
- Assistant
There's already a test for this! Let me look at it:
- Assistant
Let me run the existing test to see if it passes first:
- Assistant
Need to put
-- --nocaptureafter the test name. - Assistant
Let me find the right test path:
- Assistant
Good, the existing test passes! So the basic case works. Now I need to understand what's different in the hister case. Let me look at how
binding_target_namesgets populated in the visitor: - Assistant
Now I see there's already an existing test for Svelte class member access via template event handlers and it passes. Let me understand the exact scenario the issue describes. Let me create a minimal reproduction case by looking at how the SFC template scanner handles member expressions in different contexts:
- Assistant
Let me trace through the full code flow more carefully. Let me look at what the Svelte template scanner produces for member accesses on bound instances and how they flow through the analysis:
- Assistant
Let me look at how
binding_target_nameshandles Svelte 5's$state()pattern: - Assistant
Let me search more broadly for Svelte 5
$statehandling: - Assistant
Let me look more carefully at how
binding_target_namesgets populated and what patterns it handles: - Assistant
Let me look at all these insertions in context to understand what they handle:
- Assistant
Let me look at the broader context around
insert_binding_target: - Assistant
Let me search for where
newexpressions create binding_target_names entries: - Assistant
Let me look at the variable declarator handling where
const x = new ClassName()is detected: - Assistant
Now let me understand the flow from
ModuleInfo.member_accessestoResolvedModule.member_accesses. Let me find how ModuleInfo gets converted to ResolvedModule: - Assistant
Let me now create a focused reproduction test. First, let me understand how
binding_target_namesflows from the script into the SFC. Let me look more at the SFCapply_template_usageflow: - Assistant
Let me now search for the git log to see recent changes related to Svelte templates:
- Assistant
Let me search for commits related to Svelte member access:
- Assistant
Let me look at the commit for svelte template member access:
- Assistant
Let me look at the commit that added script-instance member access:
- Assistant
Now let me check if the commit
cadeb111(which added script-instance member access) is included in version 2.84.0: - Assistant
Let me check the ancestry of
cadeb111vs1fe7ae67: - Assistant
Let me look at how
parse_tag_attrsworks for Svelte event handlers to understand how attribute values are extracted: - Assistant
Let me look at the
build_typed_instance_binding_targetsfunction to understand how it works: - Assistant
Let me look at the
build_typed_instance_binding_targetsfunction: - Assistant
Let me continue reading
resolve_typed_instance_chain_targets: - Assistant
Let me look at
merge_intoto see how it handles member_accesses: - Assistant
Let me look at the
merge_intofunction: - Assistant
Now I understand the full flow. Let me look at the
record_exported_instance_bindingsmethod which populates instance bindings for class heritage: - Assistant
OK, now I have a thorough understanding of the codebase. Let me trace the issue systematically. I'll look at how the Svelte template scanner is invoked from the SFC extraction:
- Assistant
Let me look at the full
apply_tagfunction to understand all the expression contexts it handles: - Assistant
Let me continue reading to see the
@renderand other directive handling: - Assistant
Let me look at how
try_extract_factory_new_classworks, as it might handle wrappednewexpressions: - Assistant
Let me search for
try_extract_factory_new_class: - Assistant
Let me take a different approach and look at the actual flow end-to-end. Let me create a small reproduction test to verify what happens:
- Assistant
Let me now approach this systematically. I need to understand what the actual issue is. Let me look at how
propagate_accesses_through_typed_instance_bindingshandles simple (non-chained) member accesses: - Assistant
Now I understand the core issue. The
resolve_typed_instance_chain_targetsfunction returns empty for simple (non-dotted) member access objects. This means member accesses from Svelte templates on bound instances that aren't directly matched viabound_targetsare lost.Let me now create a reproduction test to confirm my theory. First, let me look at how
$state(new ClassName())patterns would fail: - Assistant
Now I have a comprehensive understanding. The issue is about methods called on class instances that are referenced in Svelte templates. The existing test works when
const counter = new Counter()is directly in the SFC script. But the problem arises when the instance is imported from another module.Let me verify my understanding by creating a reproduction test:
- Assistant
Let me step back and focus on understanding the actual codebase better. Let me run the existing tests first:
- Assistant
Good, the existing test passes. Now let me create a reproduction. Let me look at how the Svelte template scanner handles member accesses on imported instances. Let me create a test fixture where the class instance comes from another module:
- Assistant
OK, I've thoroughly analyzed the codebase. Let me now focus on understanding the exact issue and implementing a fix.
The key insight is in the
analyze_template_snippet_with_bound_targetsfunction. When a Svelte template hasresultState.pin(), the expression is parsed.resultStatemust be in eitherimported_bindingsorbound_targetsto be tracked as an unresolved target. If it's not in either set, the member access is filtered out.The existing test works because
bound_targetsmapscounter→Counter(fromconst counter = new Counter()). But if the instance is created through a wrapper like$state(new ResultState()), thebinding_target_nameswon't capture it.Let me verify this theory by creating a targeted unit test:
- Assistant
Let me look at the
try_extract_factory_new_classhelper to understand how it extracts class names from wrapper calls: - Assistant
Now I have a clear picture. Let me implement the fix. The issue is that the visitor doesn't detect
new ClassName()when it's wrapped in a function call like$state(new ResultState()). Let me add support for this pattern: - Assistant
Let me now implement the fix. I'll add a helper to detect
new ClassName()inside wrapper function calls, and add the corresponding check in the visitor. Then I'll also handle the case whereresultStateis imported but thenewis in a different module.First, let me add the helper:
- Assistant
Now let me add the helper function. I'll add
try_extract_wrapped_new_classaftertry_extract_factory_new_class: - Assistant
Let me now add the helper function. I'll add
try_extract_wrapped_new_classaftertry_extract_factory_new_class: - Assistant
Wait, I need to check if the
try_extract_factory_new_classfunction has a proper closing brace. Let me verify: - Assistant
I see that the
try_extract_factory_new_classfunction is missing its closing brace! Let me fix this: - Assistant
I see there's a duplicate doc comment line. Let me fix that:
- Assistant
I still see duplicate doc lines. Let me fix this properly:
- Assistant
Good, the helpers.rs looks clean now. Let me add the check in
visit_impl.rsfor theconst x = wrapper(new ClassName())pattern: - Assistant
Now let me add the check for
const x = wrapper(new ClassName())pattern. I'll add it after the factory call candidate check: - Assistant
Good, the visitor fix is in place. Now let me compile and run the existing tests to make sure I haven't broken anything:
- Assistant
Let me fix the package name:
- Assistant
Good, it compiles! Now let me run the existing tests:
- Assistant
All 1638 extract tests pass. Now let me run the integration tests:
- Assistant
All 523 integration tests pass! Now let me add a test for the new
$state(new ClassName())pattern in the Svelte template tests: - Assistant
Now let me create a proper integration test. First, let me create a new test fixture for Svelte 5 patterns with
$state(): - Assistant
Let me create the fixture files:
- Assistant
Now let me add the integration test:
- Assistant
Let me add the integration test after the existing Svelte test:
- Assistant
Now let me run the new test to see if it passes:
- Assistant
The new test passes! Let me run all integration tests to make sure nothing is broken:
- Assistant
All 524 tests pass (523 original + 1 new). Now let me also run the full test suite:
- Assistant
There's a pre-existing test failure
fix_batch_aborts_when_a_target_directory_is_read_only. Let me verify this is not related to my changes: - Assistant
Good, this is a pre-existing failure unrelated to my changes. Let me restore my changes:
- Assistant
Now let me run the full test suite (excluding the known pre-existing failure) to verify everything is solid:
- Assistant
All tests pass except for the pre-existing failure. Let me check if I need to bump the cache version since the extraction logic changed:
- Assistant
Let me find the actual CACHE_VERSION constant:
- Assistant
I need to bump the cache version since the extraction semantics changed. Let me update it:
- Assistant
Let me bump the cache version and add a comment:
- Assistant
Let me now run the full test suite again to verify everything passes with the cache version bump:
- Assistant
All tests pass (except for the pre-existing unrelated failure). Let me now review all my changes:
- Assistant
Let me review the full diff:
- Assistant
Let me verify my changes are complete and correct by reviewing them:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →