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
I'll start by exploring the repository structure to understand the codebase.
Assistant
This is a Rust project (Fallow linter). Let me explore the crates structure and find the unused-class-members rule.
Assistant
Let me look at the Svelte plugin and the template member access tracking for Vue/Angular.
Assistant
Now let me look at the unused_members.rs file to understand how the rule works, particularly the Vue/Angular template member-access tracking.
Assistant
Let me explore the extract crate, which likely handles the parsing of Svelte/Vue/Angular files.
Assistant
Let me look at the Svelte scanner, the Vue scanner, and the
TemplateUsagetype.Assistant
Let me see the middle section of the svelte.rs that was truncated.
Assistant
Now let me look at the
shared.rsfile, especiallymerge_expression_usage_allow_dollar_refs_with_bound_targetsand related functions.Assistant
Now let me look at the
template_usage.rsfile, especially theanalyze_template_snippet_with_bound_targetsfunction andTemplateUsagetype.Assistant
Now let me look at the sfc.rs file to understand how
bound_targetsis built and wherecollect_template_usage_with_bound_targetsis invoked.Assistant
Now I need to understand
binding_target_names()which builds thebound_targetsmap. Let me find it.Assistant
Let me look at the relevant sections in mod.rs to understand the binding_target_names structure.
Assistant
Let me look at the unused_members.rs analyze layer, particularly how member accesses are tracked and credited for classes.
Assistant
Let me look at how
newexpressions and class instance bindings are handled in visit_impl.rs.Assistant
Let me look at how
new Foo()creates a binding target. Let me search for the visit of NewExpression or how binding targets get added fornewexpressions.Assistant
Let me look at
build_local_to_export_keysto understand how the analyze layer maps local names to export keys.Assistant
Let me look at the existing integration tests for Svelte member access tracking to understand the test patterns.
Assistant
There's already a test
svelte_template_event_handlers_mark_class_members_used. Let me look at it and the fixture.Assistant
Let me look at the svelte-project fixture to understand the existing Counter class usage pattern.
Assistant
Let me check the build setup and run the existing Svelte test to confirm it passes.
Assistant
Let me look at the visitor's member access collection to understand what member accesses are captured.
Assistant
The existing test passes. Let me investigate the actual scenario more. Let me check the git log and recent changelog entries about Svelte template member access.
Assistant
There's a commit
cadeb111 fix(svelte): credit @attach directives and script-instance member access. Let me look at that commit to understand the script-instance member access part.Assistant
Let me look at the instance export handling in the analyze layer.
Assistant
Let me look at the
INSTANCE_EXPORT_SENTINELto understand the singleton instance export scenario.Assistant
The existing test passes for
counter.bump(). Let me create a reproduction fixture to understand the actual failing scenario from the hister repo. Let me first try the singleton-import pattern.Assistant
Let me check the test helpers to create a temporary reproduction test.
Assistant
Let me create a temporary test file to reproduce. First, let me create the fixture in the repo's tests dir and a temporary test.
Assistant
I need to register this test module in the integration_test mod.rs. Let me check the mod.rs.
Assistant
The singleton-import case works. Let me try the local
new ResultState()case (matching the existing fixture pattern).Assistant
Both work. Let me test the method-reference case (passing the method, not calling it) and direct text interpolation.
Assistant
Still works. Let me test direct text interpolation and various other forms. Let me test
{resultState.pin()}in a text node.Assistant
All simple cases work. The issue likely involves
resultStatebeing a Svelte prop (export let) or passed across components. Let me test the prop case.Assistant
Interesting — in the singleton case, the class export itself was unused so member analysis was skipped. Let me make the class reachable AND test the singleton scenario properly.
Assistant
All scenarios pass. Let me look at how
INSTANCE_EXPORT_SENTINELis generated, since the issue may involve a Svelte store pattern.Assistant
Let me look at
propagate_factory_call_accessesto understand how factory-call sentinel accesses are credited.Assistant
Let me test the module-context script scenario, where the instance is created in
<script context="module">.Assistant
Let me make the temp test stricter to print exact results, and test the Svelte store pattern (
$resultState).Assistant
I reproduced a false positive with the store pattern. Let me test a few more scenarios to pin down the exact hister pattern. Let me test the cross-file singleton (singleton and class in different files).
Assistant
Let me check the benchmarks directory and search for any reference to hister or ResultState patterns.
Assistant
Let me look at how Vue handles class member template access and check the vue-project fixture for class instances.
Assistant
Let me examine the Vue fixture and how Vue credits class members from templates, plus check the vue scanner's bound target handling.
Assistant
Let me inspect the extract crate's API to directly check what member_accesses a Svelte file produces.
Assistant
Let me write a temporary unit test in the extract crate to inspect the member_accesses produced for various Svelte scenarios.
Assistant
Let me create a temporary test in the extract crate's sfc.rs tests (or a separate temp file) to print member_accesses. Let me add a temporary test function to a temp file in the extract crate's tests dir. Actually, the sfc.rs has
#[cfg(all(test, not(miri)))] mod tests. I'll create a temp test file in the extract crate.Actually, the simplest: write a temp test in the extract crate's tests dir. Let me check the extract tests structure.
Assistant
Let me write a temporary test in
/fallow/crates/extract/src/tests/mod.rsor a new temp test module. Let me look at the tests/mod.rs.Assistant
Let me create a temporary test file in the extract crate to print member_accesses for various Svelte scenarios.
Assistant
Excellent! This is very revealing. Let me add more cases — the imported-store (
$resultState.pin()) and a prop without type — to the inspect test.Assistant
I have rich data now. The clearest FP matching the literal
resultState.pin(...)example (no$) is the module-context scenario, where the instance binding lives in<script context="module">(not template-visible). Let me set up a clean end-to-end reproduction.Assistant
I reproduced the exact false positive from the issue:
ResultState.onOpen,.pin,.updateLabel,.addSkipRuleall reported unused when called from the Svelte template viaresultState.pin()whereresultStateis created in<script context="module">. Let me check whether any existing tests rely on module-context Svelte imports being excluded from template-visible tracking.Assistant
I've reproduced the exact false positive. The root cause: Svelte
<script context="module">declarations are accessible from the template, butmerge_script_into_moduleonly collectsbinding_target_namesfrom template-visible (instance) scripts. SoresultStatecreated in module context isn't a known bound target, and template callsresultState.pin()aren't credited.Note the existing test
svelte_module_context_import_is_not_visible_to_templateintentionally keeps module-context imports non-template-visible, so I'll only extend bound targets (instance bindings), preserving import behavior. Let me look at the exact code to edit.Assistant
Now let me implement the fix. I'll modify the bound-targets collection to also include Svelte module-context scripts (whose declarations are template-accessible), while keeping imports limited to template-visible scripts.
Assistant
Now let me bump the cache version (extraction semantics changed) and rebuild.
Assistant
The fix works. Now let me verify the existing tests still pass, especially the module-context import test and the existing member-credit tests.
Assistant
All sfc tests pass. Let me specifically confirm the module-context import test still passes and run the broader Svelte/member integration tests.
Assistant
Let me run the member-detection and unused-class-member integration tests plus the full extract test suite.
Assistant
Let me test the module-context local (non-exported) variant to ensure robustness, and verify the fix generalizes.
Assistant
The module-context local variant also works. Let me run the full extract lib test suite and broader core integration tests to ensure nothing breaks.
Assistant
All 524 core integration tests pass. Let me review my change and check for clippy/style issues, since the repo uses strict linting.
Assistant
Let me check the formatter config and reformat the long line with explicit parentheses for clarity and line-width compliance.
Assistant
Let me reformat the change for clarity and line-width compliance with explicit parentheses.
Assistant
I now have duplicate comment blocks. Let me view the current state and clean it up.
Assistant
Let me replace the duplicated comment block with a single clean version.
Assistant
Now let me rebuild and re-run the verification plus clippy to ensure clean linting.
Assistant
Clippy is clean. Let me run the full extract lib tests and core SFC/member tests once more after the reformat.
Assistant
All tests pass. Let me run the full extract crate test suite (all targets) and the graph crate tests to ensure no broader regressions.
Assistant
Let me restore the fixture to the exact issue scenario (exported module-context singleton) for a final faithful verification.
Assistant
The fix is verified. Now let me clean up all temporary files and revert the test-module registrations I added, keeping only the source fix.
Assistant
Wait,
crates/core/tests/integration_test.rsis still showing as modified. Let me check the diff — it should be reverted now. Let me verify.Assistant
There's a leftover blank line removal. Let me restore the original blank line.
Assistant
Now only the two source files are modified. Let me verify
extract/src/tests/mod.rsis fully reverted and confirm the build + a final test pass.Assistant
All tests pass with the temp files removed (523 core + 1638 extract). Let me do a final review of the complete diff.
Assistant
The diff is clean and minimal. Let me do a final build of the CLI and run clippy on the whole affected chain to be thorough.
Assistant
Let me confirm there are no leftover untracked files from my temporary work.
Assistant
The fix is complete and clean. Only two source files are modified, with no leftover temp files. Let me do one final full verification run of the core integration suite to be 100% sure.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.