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
I'll start by exploring the repository to understand the structure and locate the relevant code for the unused-class-members rule. Let's first see what's in the current directory.
- Assistant
Let me get a better understanding of the repository structure.
- Assistant
This is a Rust-based project (Cargo.toml). Let me look at the crate structure and find the unused-class-members rule implementation.
- Assistant
Let me look at the relevant crate for unused class members - it's in
crates/core/analyze/unused_members.rs. - Assistant
Good, so the main file is
crates/core/src/analyze/unused_members.rs. Let me also look at the svelte-related handling to understand how templates are parsed. - Assistant
Let me check the SFC (Single File Component) parsing to understand how Svelte templates are handled.
- Assistant
Let me examine the unused_members.rs file to understand how the unused-class-members rule works and how it handles template members.
- Assistant
Let me explore the existing tests for Svelte template member handling and the unused_members implementation:
- Assistant
Let me look at the relevant files to understand the issue better.
- Assistant
Let me look at the Svelte template collection implementation to understand what it currently tracks.
- Assistant
Let me look at the shared module to understand how expressions are analyzed:
- Assistant
Let me look at the template_usage module to understand how expressions are analyzed: -
- Assistant
Let me look at the template_usage module to understand how expressions are analyzed.
- Assistant
Good - the
TemplateUsagealready hasmember_accesseswhich tracksobj.memberpatterns. Let me now look at how unused_members.rs consumes this data: - Assistant
Now let me understand the flow. Let me look at how template usage data is resolved and used in the unused members analysis. Let me search for "template" references in unused_members.rs:
- Assistant
Let me look at how the member_accesses from templates are propagated to the unused_members check:
- Assistant
Let me find the visitor file:
- Assistant
Let me search for the visitor file:
- Assistant
Let me look at how member_accesses are tracked in the visitor:
- Assistant
Now let me look at the
resolved_bound_member_accessesfunction and howTemplateUsageis consumed: - Assistant
Hmm, let me look for where template usage is collected in the extract layer.
- Assistant
Let me look at the sfc.rs file to understand how template usage is applied:
- Assistant
Let me look at the
apply_template_usagefunction: - Assistant
Now I need to understand how the
member_accessesfrom theModuleInfoare consumed in the unused_members analysis. Let me look at the key logic: - Assistant
Let me look at the main analysis function in unused_members.rs where member accesses are resolved:
- Assistant
Let me look at how member accesses flow from
resolved_modulesto be consumed in the analysis: - Assistant
Let me look at how Vue template member accesses work, to understand how the existing mechanism is already working for Vue:
- Assistant
The Vue test
event_handler_member_call_maps_script_instance_to_classshows the key mechanism! There's abound_targetsmap that maps local variable names to class names, andcounter.bump()maps toCounter.bump. Let me check howbound_targetsare populated for Svelte: - Assistant
Let me look at how
template_visible_bound_targetsis populated: - Assistant
Let me understand
binding_target_names(): - Assistant
Let me look at how
binding_target_namesis populated - what gets into it: - Assistant
Now let me look at how
binding_target_namesgets populated - wherenew ClassName()creates a binding target: - Assistant
Let me look at what creates binding_target_names entries, specifically looking for
newexpressions (likenew ClassName()): - Assistant
Let me look at where
new ClassName()is handled: - Assistant
Let me look at how
new ClassName()is handled and howbinding_target_namesgets populated: - Assistant
Let me look at the section around line 2052:
- Assistant
Let me look at the Svelte template scanner to understand what exactly is tracked. Let me check the
apply_tagand related functions: - Assistant
Let me now look at
build_local_to_export_keysto understand how the member access mapping works: - Assistant
Let me look at
build_local_to_export_keys: - Assistant
Let me look at the
apply_markup_tagfunction in the Svelte template scanner to see how attribute values are handled: - Assistant
Let me look at the
apply_markup_tagfunction. - Assistant
Let me look at how the
collect_template_usage_with_bound_targetsis dispatched: - Assistant
Let me look at the full
apply_tagfunction to see the fallthrough case for plain expressions: - Assistant
Let me see the full apply_tag function:
- Assistant
Now I understand the flow. The Svelte template scanner calls
merge_expression_usage_allow_dollar_refs_with_bound_targets, and for bound targets (likeconst resultState = new ResultState()), theresultStateshould be inbound_targets. Let me now look at what tests exist for Svelte with bound targets: - Assistant
There are tests for Svelte with bound targets. Let me look at them:
- Assistant
Let me look at how
ResolvedModuleis constructed and how it flows into unused_members: - Assistant
Let me find where ResolvedModule is defined.
- Assistant
Let me look at the ResolvedModule type and its member_accesses field:
- Assistant
Now let me look at the existing integration tests for Svelte:
- Assistant
Let me look at the existing Angular template members test to understand the test pattern:
- Assistant
Let me look at the existing test fixtures for Svelte:
- Assistant
Let me look at the svelte-project fixture:
- Assistant
Let me understand how
ModuleInfoflows toResolvedModule: - Assistant
Let me now look at the
ModuleInfostructure to understand whatmember_accessesis and how it flows: - Assistant
Let me look at how
ResolvedModuleis populated withmember_accesses: - Assistant
Let me look at the core analysis function for unused_members to understand the full flow:
- Assistant
Now let me understand how
resolved.member_accessesis built fromModuleInfo: - Assistant
Let me check the
sfc_parsing.rsintegration test to see what's tested: - Assistant
Let me see more of this test and check for Svelte-related tests:
- Assistant
Let me look at the existing Svelte template member test:
- Assistant
There's already a test for Svelte template member tracking. Let me look at the fixture files to understand the current setup:
- Assistant
Good - the test already has
const counter = new Counter()and usescounter.bump()andcounter.valuein the template. Let me see what theutils.tsfile contains: - Assistant
Now I need to understand the full picture. Let me look at how the analysis processes SFC member accesses. Let me run the existing test to make sure it passes:
- Assistant
Let me fix the command.
- Assistant
Good, the test passes. Now let me think about the specific issue. The problem is about Svelte templates calling class methods via member expressions like
resultState.pin(...). Let me look at how the unused_members analysis propagates class member accesses. Let me look at thepropagate_class_inheritancefunction: - Assistant
Let me look at how SFC files are parsed in the main pipeline:
- Assistant
Let me look at the actual variable declarator handling to understand how
newexpressions create binding targets: - Assistant
Let me now understand the full analysis flow. I need to trace how SFC member accesses reach the unused_members analysis. Let me look at how
ResolvedModuleis constructed fromModuleInfo: - Assistant
Let me now look at
try_extract_factory_new_classand the factory pattern handling: - Assistant
Let me look at this function:
- Assistant
Now let me look at the key area where
newexpressions are handled in the variable declarator visitor: - Assistant
Let me look at where the
visit_variable_declaratorhandlesnewexpressions: - Assistant
Let me try a different approach. Let me create a reproduction script to understand the issue:
- Assistant
Let me look at how the analysis propagates member accesses, specifically looking for how instance bindings are handled:
- Assistant
Now I understand the issue. Let me trace through the Svelte template member access flow carefully. The key question is: in the hister repo, how is
resultStatecreated? Let me check if the issue could be about$state(new ResultState())(Svelte 5) or similar patterns wherenewis wrapped in a function call. Let me verify: - Assistant
Let me look at the full
try_extract_factory_new_classand related functions: - Assistant
Now I understand the issue! The
try_extract_factory_new_classonly handlesnew ClassName()wrapped in arrow functions or function expressions (likeuseState(() => new Foo())), but NOT direct arguments like$state(new ClassName()). In Svelte 5,$state(new ResultState())is the standard reactive pattern, and thenewexpression is a direct argument, not wrapped in a function.Let me verify this is the issue by creating a test:
- Assistant
Now let me implement the fix. First, let me add a helper function to extract
new ClassName()from direct arguments: - Assistant
Now let me add the helper function for direct argument new expressions. I'll add it after
try_extract_factory_new_class: - Assistant
Now let me add this function to the helpers file:
- Assistant
Now I need to add the new function. Let me find the exact location:
- Assistant
Let me add the new function after
try_extract_factory_new_class: - Assistant
Now let me verify the new function was added correctly:
- Assistant
Good. Now let me add the new condition in the
visit_variable_declaratorhandler. Let me find the right location: - Assistant
Now let me add the new condition for direct argument
newexpressions. I'll insert it after the existing factory pattern handler: - Assistant
Now let me add the new condition. I need to insert it after the closing
}on line 2075: - Assistant
Good, I can see the location. Now let me add the new condition:
- Assistant
I notice there's a duplicate comment on line 2094. Let me fix that:
- Assistant
I see there's still a duplicate comment line. Let me fix it:
- Assistant
There are still duplicate lines. Let me fix them:
- Assistant
Let me remove the duplicate line:
- Assistant
I keep creating duplicates. Let me fix the entire comment block properly:
- Assistant
Good, the edit looks correct now. Let me verify the code compiles:
- Assistant
Good, it compiles. Now let me run the existing tests to make sure I haven't broken anything:
- Assistant
Good, the existing tests pass. Now let me create a test fixture for the Svelte 5
$state()pattern. Let me first look at the existing svelte-project fixture to understand the structure: - Assistant
Let me create a new test fixture for the Svelte 5
$state()pattern: - Assistant
Now let me create the package.json and fixture files:
- Assistant
Now let me add an integration test for this fixture:
- Assistant
Let me look at the area after the existing Svelte test:
- Assistant
Now let me add the integration test. I'll add it after line 362:
- Assistant
I notice there's a duplicate
}on line 362. Let me fix that: - Assistant
Let me remove the duplicate
}: - Assistant
Good, the test looks correct. Now let me run the new test to see if it passes:
- Assistant
The new test passes. Let me also run the existing Svelte tests to make sure nothing is broken:
- Assistant
All Svelte tests pass. Now let me run the broader test suite to make sure nothing is broken:
- Assistant
All extract tests pass (1638 tests). Let me now run the core integration tests:
- Assistant
All 524 core integration tests pass. Now let me also add a unit test for the
try_extract_new_class_from_direct_argshelper: - Assistant
Let me look at the test module to add a test for the new helper:
- Assistant
Good. The integration test covers the full pipeline. Let me also add a unit test for the Svelte template scanner to verify it handles bound_targets with
$state(): - Assistant
Good, the template scanner tests already cover bound_targets. Let me run clippy to check for any issues:
- Assistant
Clippy passes cleanly. Let me also run clippy on the core package:
- Assistant
All clippy checks pass. Let me now run a broader set of tests to ensure nothing is broken:
- Assistant
All 45 member-related tests pass. Let me run the full workspace test suite to ensure nothing else is broken:
- Assistant
The one failing test
resolves_npm_sidecar_from_node_modules_rootis unrelated to my changes (it's about npm sidecar resolution). Let me verify it was already failing before my changes: - Assistant
Hmm, the test passes without my changes. Let me restore my changes and investigate:
- Assistant
The test passes when run individually. The previous failure was likely transient. Let me run the full workspace tests once more:
- Assistant
Let me check if this test failure is related to my changes:
- Assistant
Let me verify this is not related to my changes:
- Assistant
Good - this test failure is pre-existing (fails without my changes too). It's an environment issue with read-only directories. Let me restore my changes:
- Assistant
Now let me run the full test suite excluding the known-failing test:
- Assistant
All tests pass. Let me also run the fallow-cli tests excluding the known-failing one:
- Assistant
Let me check if this is a flaky test:
- Assistant
The test passes in isolation but fails in the full suite - it's a flaky test unrelated to my changes. Let me now review my changes:
- Assistant
Let me review each change:
- Assistant
Let me verify the test fixture files:
- Assistant
The test fixture looks correct. Let me run the complete test suite one more time to confirm everything passes:
- Assistant
All 18 SFC parsing tests pass. Let me also run the full extract package tests:
- Assistant
All 1638 extract tests pass. Let me run the full core tests:
- Assistant
All 524 core tests pass. Let me now do a final review of all the changes I've made:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.