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
Let me start by understanding the issue. The problem is about false positives in
unused-class-membersrule in a tool called "Fallow" (which appears to be a static analysis/linting tool). The issue is that class methods called only from Svelte<template>via member expressions (e.g.,resultState.pin(...)in markup) are reported asunused-class-member.The expected behavior is to credit a method called as
<local>.<method>(...)inside a Svelte<template>when<local>resolves to an instance of the class, similar to existing Vue/Angular template member-access tracking.Let me first explore the repository structure to understand what we're dealing with.
Assistant
This is a Rust project (based on Cargo.toml). Let me look at the structure more. This appears to be the "Fallow" tool - a static analysis/linting tool. Let me explore the crates directory since that's likely where the source code is.
Assistant
Let me look for the "unused-class-members" rule. It's likely in the core crate.
Assistant
Let me look at the core analyze file for unused members, and also search for Svelte-related files
Assistant
Let me look at the relevant files for Svelte template extraction and the unused members analysis.
Assistant
Let me do one at a time.
Assistant
Let me see the shared.rs for the merge expression function and also look at how Vue handles member
Assistant
Let me find and look at the
template_usagemodule which containsanalyze_template_snippetandanalyze_template_snippet_with_bound_targets.Assistant
Let me look at the template_usage.rs file.
Assistant
Now let me look at how the unused members analysis uses template member accesses. Let me check the unused_members.rs file.
Assistant
Let me understand how the Svelte template usage data flows into the unused members analysis. Let me search for where
member_accessesfrom templates are usedAssistant
Let me look at the SFC extraction module to understand how Svelte templates are processed
Assistant
Let me look at the rest of sfc.rs, focusing on
apply_template_usageandmerge_script_into_moduleAssistant
Let me look at the
merge_script_into_modulefunction starting at line 306 andapply_template_usageat line 502.Assistant
Now I see the flow! In
apply_template_usage, the template usage is collected and then:combined.member_accesses.extend(template_usage.member_accesses)- member accesses from template are addedcombined.whole_object_uses.extend(template_usage.whole_object_uses)- whole object uses are added
Now let me look at
is_template_visible_scriptto see when Svelte scripts are template-visible:Assistant
Let me look at the
binding_target_namesmethod and theModuleInfoExtractorto understand whatbound_targetslook like:Assistant
Let me look at the visitor's
resolve_bound_member_accessesandmerge_intoAssistant
Now let me look at the
merge_intofunction to see how bound member accesses are resolved and merged into the module info.Assistant
Let me look at
resolve_bound_member_accessesto understand how bound member accesses are resolvedAssistant
Now let me look at the
resolve_bound_member_accessesfunction, which is the key function:Assistant
Let me look at the
resolve_bound_member_accessesfunction at line 689.Assistant
Let me look at how
binding_target_namesis populated in the visitor, particularly around lines 835 and 843Assistant
Let me look at how
binding_target_namesgets populated for variable declarationsAssistant
Let me look at the area around line 1282-1320 to see the function that inserts binding targets
Assistant
Let me search for
record_typed_bindingto understand when binding targets are recordedAssistant
Let me look at the full
parse_sfc_to_modulefunction to see the complete flowAssistant
Let me see the full
apply_tagfunction in svelte.rsAssistant
Let me see the rest of the
apply_tagfunction, specifically the fallthrough case for plain expressionsAssistant
Let me check how the
ModuleInfoExtractorextracts member accessesAssistant
Let me look at the
collect_member_accessesfunction around line 425Assistant
Let me search for where member expression accesses are collected in the visitor
Assistant
Let me look at the
visit_static_member_expressionfunction at line 289Assistant
Let me look at the main
visit_static_member_expressionat line 2497Assistant
Let me look at the dispatch in
mod.rsforsfc_templateAssistant
Let me look at the full sfc_template/mod.rs
Assistant
Let me look at the Vue template scanner for comparison, since the issue says Vue/Angular already handle this correctly
Assistant
Let me check the tests at the bottom of svelte.rs for bound target member access tests
Assistant
There are Svelte-specific tests for bound target member access! Let me look at them
Assistant
Let me look at the tests around line 780-800 to see the curly brace expression tests
Assistant
Let me look at the
apply_markup_tagfunction to understand how event handler attributes are processedAssistant
Let me search for existing tests for curly brace expressions with bound targets in Svelte
Assistant
Let me search for the test section in svelte.rs for bound_targets tests
Assistant
Let me look at the
find_unused_membersfunction to understand how member accesses are used in the analysisAssistant
Let me find the main loop in
find_unused_membersthat processes member_accessesAssistant
Let me look at the
find_unused_membersfunction starting at line 1419Assistant
Let me look at
build_local_to_export_keysto understand how member accesses are resolvedAssistant
Let me look at
build_local_to_export_keysat line 397Assistant
Let me look at how
binding_target_namesgets populated for variable declarations without explicit type annotationsAssistant
Let me look at the
visit_variable_declarationfunction at line 1983Assistant
Let me run the existing Svelte template tests to see their current status
Assistant
Let me look at the test
svelte_event_handler_arrow_member_call_marks_bound_class_member_usageAssistant
Let me look at that test
Assistant
Let me find the
parse_sfctest helperAssistant
Let me look at the parse_sfc function
Assistant
Let me write a quick test to reproduce the issue with curly brace expressions
Assistant
Let me instead add a temporary test to the existing test file and run it.
Assistant
Let me add a temporary test for curly brace expressions with bound targets
Assistant
Let me add a test for curly brace expressions with bound targets
Assistant
Let me run the new tests
Assistant
Let me try running with a broader filter
Assistant
Let me check if the tests were inserted correctly
Assistant
Let me check the file content around line 509
Assistant
Let me use the edit command to insert the test. First, let me open the file
Assistant
Let me use the edit command to insert the test after line
Assistant
Let me fix the missing blank line before the
Assistant
Now let me run the test
Assistant
The test passes! So curly brace expressions work. Let me check what happens when the variable is declared without a type annotation (like
const resultState = new ResultState()without: ResultStateAssistant
Let me search for how
newexpressions are handled in the visitorAssistant
Let me look at
visit_new_expressionat line 2347Assistant
Let me look at
record_object_binding_targetsAssistant
Let me look at the area around line 2052 in visit_impl.rs
Assistant
Let me look at integration tests related to Svelte template member access and unused members
Assistant
Let me look at the integration test
Assistant
Let me look at the fixture for this integration test
Assistant
Let me look at the fixture files
Assistant
Let me look at the App.svelte fixture
Assistant
Let me look at the utils.ts fixture
Assistant
Let me run the integration test to see if
Assistant
Let me look at the
is_builtin_constructorfunction that might be skipping legitimate constructAssistant
Let me search for is_builtin_constructor
Assistant
Let me look at the is_builtin_constructor function
Assistant
Let me search for how member_accesses flow from ModuleInfo to ResolvedModule
Assistant
Let me search for where ResolvedModule gets constructed with member_accesses
Assistant
Let me look at the ResolvedModule struct definition
Assistant
Let me look at the ResolvedModule struct
Assistant
Let me find where member_accesses is copied from ModuleInfo to ResolvedModule
Assistant
Let me look at the resolution code where member_accesses is copied
Assistant
Let me search for Svelte 5 runes handling in the codebase
Assistant
Let me look at recent git changes to the Svelte template scanner
Assistant
Let me search for tests where a class is defined locally in the Svelte file
Assistant
Let me look at the
merge_attribute_value_usagefunction in svelteAssistant
Let me look at the
merge_attribute_value_usagefunctionAssistant
Let me search for
propagate_accesses_through_typed_instance_bindingsAssistant
Let me look at this function at line 890
Assistant
Let me look at
build_typed_instance_binding_targetsAssistant
Let me look at
build_typed_instance_binding_targetsat line 790Assistant
Let me search for
instance_bindingsin the codebaseAssistant
Let me look at `extract_class_instance_bindings
Assistant
Let me look at git log for changes related to the Svelte template scanner
Assistant
Let me look at the commit
cadeb111which mentions "script-instance member accessAssistant
Let me look at the diff for this commit
Assistant
Let me look at the current
apply_markup_tagfunction in svelte.rs to see if it passes bound_targets correctlyAssistant
Let me look at the
scan_curly_sectionfunction in scanners.rsAssistant
Let me look at the
parse_tag_attrsfunction in sharedAssistant
Let me look at the
parse_tag_attrsfunction at line 570Assistant
Let me compare the Vue and Svelte template scanners more carefully. Let me look at how Vue's
collect_template_usage_with_bound_targetsdiffers from Svelte'sAssistant
Let me search for
$statehandling in the codebaseAssistant
Let me look at the factory call candidate handler in the visitor
Assistant
Let me look at the main loop in
find_unused_membersthat processes exports and checks for unused membersAssistant
Let me continue reading the member checking logic
Assistant
Let me check how
class_heritageis populated in the visitorAssistant
Let me look at the declarations.rs to see how class_heritage is populated
Assistant
Let me revert my test changes and think about this more carefully
Assistant
Let me check if the visitor handles
export letdeclarations for binding targetsAssistant
Let me look at the
visit_export_named_declarationfunctionAssistant
Let me look at the git log for changes to the files involved in the issue
Assistant
Let me look at commit
b4305cbb- "credit class members reached via new Class().method() receivers"Assistant
Let me look at commit
22f80965- "fix(vue): credit script-instance member access in templates"Assistant
Let me check the integration test for Svelte template member access more carefully
Assistant
Let me search for any TODO/FIXME comments related to Svelte or template member access
Assistant
Let me try a different approach - let me look at the actual issue in the context of how the early return in the Svelte scanner affects things. Let me also look at the
apply_template_usagefunction more carefullyAssistant
Let me now create a test where the class is defined in the same Svelte file and used only from the template. This is a key scenario I haven't verified
Assistant
Let me look at how
resolved_modulesis built in the analysis phaseAssistant
Let me look at the analyze function
Assistant
Let me search for where
find_unused_membersis calledAssistant
Let me look at the main analysis pipeline where
find_unused_membersis calledAssistant
Now I think I understand the issue. Let me verify my theory by looking at the
is_template_visible_scriptfunction and the Svelte module script handling.The issue is likely that
context="module"scripts in Svelte are NOT considered template-visible, but their exports and binding targets ARE available in the template. If theresultStateinstance is created in a module script (or theResultStateclass is imported in a module script), the binding targets from that script would not be intemplate_visible_bound_targets, causing the template member access to not be properly remapped.Let me check the
is_template_visible_scriptfunctionAssistant
Let me check if there are tests that verify the current behavior of module scripts not being template-visible
Assistant
Let me look at the test `svelte_module_context_import_is_not_visible_to_template
Assistant
Let me now implement the fix. Based on my analysis, the main issue is the early return in the Svelte scanner that prevents the scan from running when both
imported_bindingsandbound_targetsare empty. This should be removed to match the Vue scanner behavior. Additionally, I should also make module scripts template-visible for Svelte since their exports and binding targets are available in the template.Let me first look at the early return in the Svelte scanner
Assistant
Let me now implement the fix. Based on my analysis, I need to:
- Remove the early return from the Svelte scanner's
collect_template_usage_with_bound_targetsfunction to match the Vue scanner behavior - Change
is_template_visible_scriptto include module scripts for Svelte (since module script exports and binding targets are available in the template)
But wait, for fix 2, I need to be careful about the test
svelte_module_context_import_is_not_visible_to_template. Let me look at the test again and update it if needed.Let me first implement the fixes:
- Remove the early return from the Svelte scanner's
Assistant
Let me remove the early return from the Svelte scanner
Assistant
I have a duplicate line. Let me fix it
Assistant
There's still a duplicate. Let me fix it properly
Assistant
Now let me also fix the
is_template_visible_scriptto include module scripts for binding targets but not for imports. Actually, let me look at themerge_script_into_modulefunction more carefully to see how to separate imports from binding targets.Assistant
Let me now modify the
merge_script_into_modulefunction to include module script binding targets for Svelte. I'll keep the import behavior unchanged (module scripts are not template-visible for imports), but always include binding targets for SvelteAssistant
Let me now modify the
merge_script_into_modulefunction to include module script binding targets for SvelteAssistant
Now let me run the tests to see if my changes compile and the tests pass
Assistant
All Svelte tests pass. Let me also run the integration test
Assistant
Let me now run the full test suite to make sure everything passes
Assistant
All tests pass. Let me also run the core tests
Assistant
Let me now verify my changes by creating a test that specifically tests the module script binding target scenario
Assistant
Let me add a test for module script binding targets
Assistant
Let me add a test for module script binding targets
Assistant
Let me fix the missing blank line
Assistant
Let me fix the duplicate
#[test]Assistant
Let me run my new test
Assistant
Let me run all Svelte tests to confirm everything passes
Assistant
Let me run the full test suite to make sure nothing is broken
Assistant
Let me also run the core tests
Assistant
All tests pass. Let me now review the complete diff of my changes
Assistant
Let me verify that the test
empty_imported_bindings_returns_empty_usagestill passes with my changesAssistant
Let me look at the test
empty_imported_bindings_returns_empty_usageto understand what it testsAssistant
Let me also run a broader set of tests to make sure everything is solid
Assistant
All tests pass. Let me now submit the changes
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.