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.
Assistant
The issue is about false positives for
unused-class-membersrule in a tool called "Fallow" (which appears to be a linter/code analysis tool). The problem is that class methods called only from Svelte<template>via member expressions (likeresultState.pin(...)) are incorrectly reported as unused.Let me start by exploring the repository structure to understand what we're dealing with.
Assistant
This is a Rust project (Fallow). Let me explore the structure more, particularly the
cratesdirectory.Assistant
Let me find files related to "unused-class-members" rule.
Assistant
Let me explore the relevant files. First, let me look at the main unused members analysis file and also search for Svelte-related code.
Assistant
Let me look at the key files. First, the Svelte template extraction and the unused members analysis.
Assistant
Let me also look at the relevant unused members analysis file and the shared SFC template code.
Assistant
Let me look at the shared SFC template code and understand how Vue/Angular handle member expressions
Assistant
Let me look at the template_usage module:
Assistant
Let me open this file:
Assistant
Let me see the full file to understand how member accesses are tracked.
Assistant
Let me continue reading the file.
Assistant
Now let me look at the Svelte template parser more closely, particularly how it handles expressions and whether it calls the right functions for member expression tracking
Assistant
Let me look at how Vue and Angular handle member expressions in templates. Let me search for the Vue template handler
Assistant
Let me look at how Vue handles member expressions in templates, as the issue says it's parallel to Vue/Angular tracking
Assistant
Let me look at how the Vue template handler processes expressions and member accesses:
Assistant
Let me look at the Svelte template handler more carefully to understand how it handles member expressions:
Assistant
Let me look at how the SFC module builds
bound_targetsfor different frameworks:Assistant
Let me search for bound_targets in s
Assistant
Let me look at the relevant section of sfc.rs that builds
template_visible_bound_targetsAssistant
Let me look at
merge_script_into_moduleandapply_template_usageAssistant
Now I need to understand how
binding_target_names()works inModuleInfoExtractorAssistant
Let me find where
ModuleInfoExtractoris defined.Assistant
Let me look more closely at the Svelte template handler to compare with Vue. Let me look at the Vue handler first
Assistant
Let me look at the Svelte handler for event handler and attribute parsing, and compare with Vue. First, let me look at the Svelte code for handling
on:clicketc.Assistant
Let me just open the file at a specific line.
Assistant
Let me look at
merge_expression_usage_allow_dollar_refs_with_bound_targetsin shared.rsAssistant
Let me look at these functions in shared.rs.
Assistant
Let me look at the visitor code to understand how
binding_target_namesis populatedAssistant
Let me look at the visit_impl.rs to see how
binding_target_namesentries are createdAssistant
Let me look at these insert points more closely:
Assistant
Let me look at lines around 1280-1310 and 2470-2490:
Assistant
Let me search for Svelte-specific binding code in the visitor
Assistant
Let me search for where variable declarations are handled and how they feed into
binding_target_namesAssistant
Let me look at lines 2030-2110 for how variable declarations create binding targets
Assistant
Let me search for Svelte runes handling in the codebase
Assistant
Let me look at how Svelte processes attribute values and event handlers, particularly
on:click={...}Assistant
Let me look at
merge_attribute_value_usageanddirective_binding_namein the Svelte handlerAssistant
Let me look at
parse_tag_attrsin shared.rsAssistant
Let me look at
parse_tag_attrsin sharedAssistant
Let me look at
merge_markup_brace_usagein the Svelte handlerAssistant
Let me look at the Svelte-specific tests for member access tracking
Assistant
Let me look at the Svelte member access test at line 938
Assistant
Let me look at
is_template_visible_scriptAssistant
Let me look at
is_template_visible_scriptAssistant
Let me look at
apply_template_usagein sfc.rsAssistant
Let me look at the
collect_template_usage_with_bound_targetsin sfc_templateAssistant
Let me look at how the visitor extracts member accesses from call expressions like
resultState.pin(id)Assistant
Let me look at
visit_static_member_expressionat line 289Assistant
Let me search for the main
visit_static_member_expressionin `ModuleInfoExtractorAssistant
Let me look at the
ModuleInfoExtractor'svisit_static_member_expressionat line 2497Assistant
Let me find the
static_member_object_namefunctionAssistant
Let me look at this function.
Assistant
Let me look at the integration tests for Svelte member access
Assistant
Let me look at the sfc_parsing tests for Svelte member access
Assistant
Let me look at the test and the test fixture for the Svelte project
Assistant
Let me look at the svelte-project fixture
Assistant
Let me look at the App.svelte
Assistant
Let me run the existing tests to see if they pass currently.
Assistant
Let me run the test more specifically.
Assistant
Let me look at the
find_unused_membersfunction to understand how member accesses are matched to classAssistant
Let me look at the
find_unused_membersfunction and the member access resolutionAssistant
Let me look at the main
find_unused_membersfunction.Assistant
Let me create a minimal reproduction case to test the issue. First, let me look at how to run the fallow CLI on a test fixture.
Assistant
Let me create a minimal reproduction fixture to test the issue
Assistant
Let me create the test files.
Assistant
Now let me run fallow on this fixture.
Assistant
Let me check the CLI options.
Assistant
Let me run the dead-code analysis.
Assistant
Let me try Svelte 5's
$state()patternAssistant
I reproduced the issue! The
$state()wrapper preventsbinding_target_namesfrom being populated. Let me find the helper function that extractsnew ClassNamefrom factory callsAssistant
Let me find the function
Assistant
Let me find the file
Assistant
Let me look at the helper function
Assistant
Let me look at this function
Assistant
Let me look at the argument handling in the visitor to understand what variants are available
Assistant
Let me check how
Argument::as_expression()is usedAssistant
Now I understand the issue. The
$state()wrapper in Svelte 5 prevents thebinding_target_namesfrom being populated becauselet x = $state(new ClassName())is aCallExpressionwrapping aNewExpression, and the existing code only handlesnew ClassName()directly or through factory arrow functions.Let me implement the fix. First, let me look at the exact location in
visit_impl.rswhere I need to add the new pattern.Assistant
Let me check how Argument is defined and what patterns are available
Assistant
Let me look at the existing handling of
Argumentto understand what's availableAssistant
Let me look at line 960-970 in helpers.rs
Assistant
Now I'll implement the fix. I need to:
- Add a helper function to extract
new ClassName()from call arguments - Add a pattern in
visit_impl.rsforconst x = call(new ClassName(...))
Let me first add the helper function in
helpers.rs- Add a helper function to extract
Assistant
Now let me add the new helper function. I'll add it right after
try_extract_factory_new_classAssistant
Let me use the replace command instead.
Assistant
Let me verify the file was modified correctly.
Assistant
Let me check the function body
Assistant
The function body is malformed because bash expanded the
!character. Let me fix itAssistant
Let me use a different approach to fix the file
Assistant
Let me verify the fix
Assistant
Now let me add the new pattern in
visit_impl.rs. I'll add it after theconst x = new ClassName(...)block.Assistant
Let me verify the changes in visit_impl.rs
Assistant
Now let me build and test the fix
Assistant
Now let me test with the reproduction case
Assistant
Let me run the existing tests to ensure nothing is broken
Assistant
Let me test without
$stateto confirm the basic case worksAssistant
Let me create a more debug-oriented test. Let me check if the AST correctly parses
$stateAssistant
The fix is working!
pinis now recognized as used. Let me re-test with all 4 methodsAssistant
Excellent! The fix works! Let me now test with other patterns to make sure it's robust
Assistant
Let me run more edge case
Assistant
All edge cases pass. Let me now run the full test suite to make sure nothing is broken
Assistant
Let me look at the failing test
Assistant
Let me look at this
Assistant
Let me look at the test fixture
Assistant
Let me look at the fixture files
Assistant
I see the issue. My change is too aggressive - it matches
Promise.resolve(new Aggregate())which shouldn't bindreadytoAggregate. I need to restrict the pattern to only match when the callee is a simple identifier (not a member expression likePromise.resolve).Let me update the pattern in visit_impl.rs
Assistant
Let me verify the change and rebuild
Assistant
Now let me rebuild and run all tests
Assistant
Now
Assistant
All 523 tests pass! Let me verify the reproduction case still works too
Assistant
All test cases work correctly. Let me now run the full test suite
Assistant
Let me check if this test failure is pre-existing and unrelated to my changes
Assistant
The test was already failing before my changes - it's a pre-existing issue. Let me restore my changes.
Assistant
Let me run the extract crate tests to ensure the Svelte template tests pass
Assistant
All tests pass. Let me also verify my changes look clean by reviewing
Assistant
The changes look clean and correct. Let me clean up the temporary test files
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.