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 structure to understand the codebase.
Assistant
This is "fallow" - a Rust linter. Let me explore the crate structure and find the
unused-class-membersrule.Assistant
Let me look at the Svelte-related code. Let me check the svelte plugin and the template member expression tracking for Vue/Angular.
Assistant
Let me look at how Vue/Angular template member-access tracking works. Let me look at the angular_template_members test first to understand the expected behavior.
Assistant
This is a big file. Let me understand how Svelte is handled. Let me look at the sveltekit plugin and the discovery/walk. Let me first understand how template scanning works for Svelte and how member_accesses are collected.
Let me search for how Svelte files are parsed/scanned.
Assistant
Let me understand how Svelte templates are parsed. Let me search for how .svelte files are parsed in the extract module.
Assistant
Now let me look at the svelte.rs file and the vue.rs file to compare. The key function is
collect_template_usage_with_bound_targets. Let me look at how Vue handles bound targets vs Svelte.Assistant
Now let me look at the Svelte scanner. Let me read the whole file.
Assistant
Let me see the middle portion of the svelte.rs file.
Assistant
Now let me look at the shared.rs file to compare the Vue and Svelte merge functions.
Assistant
Now let me look at
analyze_template_snippet_with_bound_targetsin template_usage.rs.Assistant
The key function
analyze_template_snippet_with_bound_targetslooks correct. The issue is likely that bound_targets is not being populated/passed for Svelte files. Let me look at the SFC pipeline.Assistant
The bound_targets is populated from
extractor.binding_target_names(). Let me look at that function.Assistant
Let me look at how
binding_target_namesis populated fornew ClassName()declarations.Assistant
Let me search for where
new ClassName()is registered into binding_target_names.Assistant
Let me look at the
apply_template_usagefunction in sfc.rs.Assistant
Let me check whether there are Svelte bound_targets tests and check the difference. Let me search the svelte.rs tests for bound_targets.
Assistant
Let me look at the Svelte bound_targets tests.
Assistant
Let me look at the integration tests for SFC parsing to understand how to reproduce end-to-end.
Assistant
Let me look at the test fixtures and how class member tracking is tested end-to-end for Vue/Svelte.
Assistant
Let me look at the analysis layer in unused_members.rs where template member accesses are resolved (lines ~1620-1720).
Assistant
Let me look at how
accessed_membersis built from member_accesses generally (the regular pipeline).Assistant
Let me look at the
resolve_bound_member_accessesfunction and how member_accesses withobject == "ResultState"(a class name) are credited. Let me search for where accessed_members gets entries from member_accesses where the object is a class name (a regular member access likeResultState.pin).Assistant
Let me look at the
resolve_typed_instance_chain_targetsfunction and thetyped_instance_targets.Assistant
Let me look at the visitor's
resolve_bound_member_accesses(mod.rs lines 600-670).Assistant
Let me find where
resolve_bound_object_nameis called and how member accesses on bound instances are recorded at extract time.Assistant
Let me look at the
resolve_bound_member_accessesfunction in mod.rs.Assistant
Let me look at the main analyze function structure to find how
ResultState.pin(object=class name) is credited.Assistant
Let me look at the existing vue-project fixture and check for class member tracking tests.
Assistant
There's a
Counterclass withbump()andunused(). InApp.svelte,const counter = new Counter()and the template usescounter.bump()andcounter.value. This is exactly the pattern! Let me check the existing test coverage for this.Assistant
Let me check the existing svelte test and the exported-instance-class-members fixture to understand the cross-file instance pattern.
Assistant
Let me check the test for the exported-instance-class-members fixture.
Assistant
Let me build and run the existing svelte tests to establish a baseline.
Assistant
The existing pattern (instance created in the SFC) works. The issue likely involves cross-file instances. Let me create a reproduction fixture with the instance created in a separate file.
Assistant
Let me create a reproduction fixture with the cross-file instance pattern in Svelte.
Assistant
The temp test file isn't picked up. Let me check how integration test modules are organized.
Assistant
I need to register the module. Let me add it to the integration_test.rs.
Assistant
The cross-file pattern works. Let me reproduce the Svelte 5 runes
$state(new ResultState())pattern, which the visitor may not recognize as a bound target.Assistant
I've reproduced an FP with the
$staterune pattern. Let me also test the basic in-SFCnewpattern with a direct call in mustache (not wrapped in arrow) to narrow down the exact conditions.Assistant
The in-SFC
newpattern works; the$staterune pattern fails. Let me check the CHANGELOG and git history for Svelte-related context to understand the intended fix direction.Assistant
The CHANGELOG confirms the existing fix relies on the script's binding-target table, populated by recognizing
const x = new Class(). The gap is rune-wrapped creation like$state(new Class()). Let me verify a few more variants to ensure I understand the full scope before fixing.Assistant
Confirmed:
$state(new ResultState())is the gap. Now let me look at the visitor's variable declaration handling to add rune-wrapper recognition.Assistant
Let me check
record_typed_bindingto understand existing typed-binding handling.Assistant
So
record_typed_bindingpopulates binding_target_names from type annotations likelet resultState: ResultState = .... But it usesresolve_class_type_paramwhich substitutes type params. For a plainResultStatetype name,resolve_class_type_paramreturnsSome("ResultState")if it's not a type param. Let me checkresolve_class_type_param.Wait — so
let resultState: ResultState = $state(new ResultState())would have a type annotationResultState, andrecord_typed_bindingwould recordbinding_target_names["resultState"] = "ResultState"! Let me check whether that's the case.Let me look at
resolve_class_type_param.Assistant
let resultState: ResultState = ...would record a bound target viarecord_typed_binding. Let me test the annotated variant to confirm it works, narrowing the fix to the unannotated rune case.Assistant
Let me look at
try_extract_factory_new_classand helpers to match the argument extraction style.Assistant
Let me look for a helper that extracts the class name from a
new ClassName()expression directly. Let me check if there'sextract_new_class_from_expressionor similar. Let me search.Assistant
Let me look at the
new_url_import_sourcehelper to match theNewExpressionsignature style.Assistant
Let me check the imports in visit_impl.rs for
ArgumentandNewExpression.Assistant
Let me check whether
Argumenthas anas_expression()method in the oxc version used.Assistant
Argument::as_expression()exists. Now let me implement. First, add the helper functions in helpers.rs.Assistant
Now let me add the helpers. First update the imports:
Assistant
The sed didn't match. Let me use the edit tool. Let me open the file.
Assistant
Now let me add the helper functions after
is_builtin_constructor.Assistant
I introduced a duplicate tail of
is_builtin_constructor. Let me fix it.Assistant
I have a duplicate set of helpers. Let me remove the second duplicate block (lines 1248-1285).
Assistant
Now let me verify the helpers file is clean and add the visit_impl.rs handling. Let me check the helpers exist once.
Assistant
Now let me add the handling in visit_impl.rs after the
const x = new ClassName()block.Assistant
Now let me insert the rune-wrapped handling after the
const x = new ClassName()block (line 2061).Assistant
I accidentally removed the closing brace of the first block. Let me fix it.
Assistant
Let me add a blank line between the two blocks for readability.
Assistant
Now let me build and run the reproduction test.
Assistant
The fix works. Now let me test edge cases:
$derived, shadowing by template locals, and the cross-file exported-const pattern. Let me write a more comprehensive temp test.Assistant
Let me test the shadowing edge case to ensure template locals still shadow the rune-wrapped binding.
Assistant
Shadowing works correctly. Now let me run the broader test suites to ensure no regressions. Let me run the extract crate unit tests.
Assistant
All extract tests pass. Now let me run the core integration tests for svelte/vue/angular/member-detection.
Assistant
All pass. Let me run the full core integration test suite to be safe.
Assistant
All 524 pass. Let me run the core lib unit tests too.
Assistant
Let me also verify the cross-file
export default new ClassName()instance pattern works (to ensure the fix is complete and I understand the full scope).Assistant
The cross-file
export default new ClassName()pattern also fails. Let me check whether this is Svelte-specific or a general limitation by testing the equivalent plain TS.Assistant
The
export default new ClassName()cross-file case is a general limitation (fails in plain TS too), so it's out of scope for this Svelte-specific issue. My fix targets the rune-wrapped instance creation. Since the extracted shape changes for affected Svelte files, let me check the cache version.Assistant
I should bump
CACHE_VERSIONsince the extractedmember_accessesshape changes for affected Svelte files. Let me bump it.Assistant
Let me check if there are tests asserting a specific CACHE_VERSION value that need updating.
Assistant
No hardcoded version assertion. Let me run the cache tests to confirm the version bump is fine.
Assistant
All cache tests pass. Now let me clean up all temporary test artifacts (fixture, temp test file, mod registration).
Assistant
Let me remove the temp mod registration I added to integration_test.rs.
Assistant
Now let me verify the temp artifacts are gone and rebuild + run the relevant tests once more to confirm everything compiles cleanly.
Assistant
Let me run the relevant existing tests plus clippy to ensure code quality.
Assistant
Clippy passes with no warnings. Let me review the final diff.
Assistant
The diff is clean. However, I guessed the issue number (#724) which I can't verify. Let me remove the specific issue-number references to avoid asserting an incorrect number, keeping descriptive references instead.
Assistant
The replace didn't match because of the line-wrap. Let me use the edit tool on the specific lines.
Lines 1225-1226 are:
code/// underlying class's members. See issue #724 (Svelte template member /// expressions on a bound instance).Let me edit those two lines.
Assistant
Now let me update the visit_impl.rs and cache/types.rs comments to remove the
#724reference.Assistant
Let me verify no
#724references remain and rebuild.Assistant
No
#724references remain and the build succeeds. Let me run the extract lib tests and sfc_parsing integration tests once more to confirm everything passes after the comment edits.Assistant
Let me do a final end-to-end reproduction to confirm the fix resolves the issue, then clean up.
Assistant
The fix resolves the FP. Now let me clean up all temporary artifacts.
Assistant
Only the 3 source files are modified. Let me run a final fmt check and clippy with tests to ensure code quality compliance.
Assistant
fmt and clippy both pass cleanly. Let me do a final review of the complete diff.
Assistant
The diff is clean and coherent. Let me run the full core integration test suite one final time to confirm no regressions (temp test removed).
Assistant
All 523 existing integration tests pass. Let me do a final workspace build check to ensure nothing else breaks with the cache version bump.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.