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 first map the repository and locate the unused-class-members rule plus existing Svelte/Vue/Angular template tracking. Then I’ll identify or construct the closest existing test/reproduction, implement the smallest general fix, and run focused and broader tests.
- Assistant
The project is Rust-based and centralizes framework template usage in
crates/extract/src/template_usage.rs. I’ll inspect that implementation, the unused-member analyzer, and fixture/test conventions to understand where Svelte differs from the already-supported frameworks. - Assistant
The shared analyzer already supports a
bound_targetsmap that remaps a template-local object name to its underlying binding, exactly the primitive likely needed. Next I’ll trace who builds that map for each framework and where class member accesses are consumed. - Assistant
The extraction visitor later resolves bound object names into class/type targets. I’ll now inspect SFC parsing and tests around existing Svelte member access assertions, along with binding registration in the visitor.
- Assistant
There is already a narrowly named Svelte regression test for an event-handler arrow call, suggesting partial support landed but not all expression paths. I’ll compare that case against direct calls and inspect how
bound_targetsflows through Svelte’s scanners and SFC extraction. - Assistant
The top-level pipeline does collect local-to-class bindings and passes them into both frameworks. The failure is therefore likely in a Svelte syntax path that still invokes the import-only helper. I’ll isolate all analyzer calls in the Svelte scanner and inspect their arguments, then run the focused extraction tests to establish the current baseline.
- Assistant
Direct bound-target plumbing is present and the simple
const counter = new Counter()case passes. The reported project likely uses Svelte 5 runes (commonlylet resultState = $state(new ResultState(...))), while the existing regression only covers a bare constructor initializer. I’ll inspect constructor-binding extraction to verify whether wrapped instances are omitted, and use a temporary source variation to reproduce that exact gap without changing tests. - Assistant
The visitor only recognizes a bare
NewExpressionfor ordinary identifier declarations. Svelte$state(new Class())is therefore unbound. Before changing this generically, I’ll inspect nearby helper conventions and the exact AST handling to choose a conservative wrapper rule (ideally Svelte rune-specific rather than treating arbitrary functions as identity wrappers). - Assistant
A
$statewrapper is one plausible case, but the component name in the report (ResultActionsMenu) also strongly suggestsresultStateis received as a typed Svelte prop, e.g.let { resultState }: Props = $props(), rather than constructed locally. I’ll inspect type-binding extraction, especially destructured variables with type aliases/interfaces, because the expected wording says “when<local>resolves to an instance of the class,” which likely includes typed props. - Assistant
Type extraction exists for class properties, but I need verify whether variable declarations invoke it. I’ll inspect the call at line ~839 and the beginning of variable-declaration visitation; then I’ll create a temporary executable example using likely Svelte prop forms and run the CLI to confirm which form reproduces the false positive end-to-end.
- Assistant
This reveals the concrete gap: typed bindings are recorded only for
BindingIdentifier, notObjectPattern. Svelte 5’s canonical props syntax is destructured$props()with an inline object type, soresultStatenever entersbinding_target_names; consequently the template scanner has nothing to resolve. I’ll validate this with a temporary fixture and the CLI, then implement conservative typed object-destructuring mapping (including aliases/nesting where statically resolvable) using existing type-binding extraction. - Assistant
The temporary project is ready; the first CLI invocation only selected an ambiguous Cargo package binary, so I’ll rerun explicitly with
--bin fallow. Conveniently, the visitor already contains an object-pattern path-to-local mapper for Playwright fixtures; I’ll inspect and potentially reuse/generalize it rather than duplicate destructuring logic. - Assistant
The existing mapper returns
local_name -> source_property_path, exactly what typed destructuring needs. I’ll run the reproduction from its working directory, then add a smallrecord_typed_pattern_bindingsmethod that handles both identifiers and object patterns by joining that mapper withextract_nested_type_bindings. This naturally supports renamed/defaulted/nested properties while ignoring rest/computed shapes that cannot be resolved safely. - Assistant
The end-to-end reproduction confirms the false positive: both
pinand genuinely unusedunusedare reported. A robust fix must also account for the commoninterface Props { resultState: ResultState }/type Props = {...}annotation, not just inline literals. I’ll inspect existing type-alias/interface registries in the visitor and lifecycle ordering so the fix can resolve named prop shapes without introducing broad type inference. - Assistant
The current registry is Playwright-specific and only records aliases, so reusing it would couple unrelated behavior and still miss interfaces/source order. I’ll keep the fix scoped: add a general module-local structural type map plus pending typed destructuring records resolved during finalization. It will collect property-path → referenced-type entries from interfaces and type aliases, then map destructured local names to those paths. Inline structural annotations can resolve immediately; named annotations resolve after the full walk. First I’ll inspect finalization order and Oxc interface member shape to integrate cleanly.
- Assistant
I’ll implement this in three focused pieces: (1) expose structural property bindings for interface bodies alongside the existing type-literal helper, (2) store named structural shapes and pending destructured annotations in the extractor, and (3) resolve pending locals before template-visible bindings are read/finalized. The matching remains syntactic and conservative—only static property keys and simple referenced class types are credited.
- Assistant
I’ve identified the exact insertion points. I’ll now modify only source files (no repository tests, per instruction), then format and compile before rerunning the temporary reproduction in both inline-type and named-interface forms.
- Assistant
The first edit added pattern resolution and interface extraction, but named type aliases need a helper accepting
TSTypedirectly (the existing API accepts only a full annotation). I deliberately stopped before inserting unsafe allocator-dependent code. I’ll add that clean API, wire alias/interface registration, add extractor storage, and invoke pending resolution before bound member resolution and before SFC extraction reads the map. Note SFC reads map beforemerge_into; check pipeline: extractor binding names directly after visit, so pending must resolve before getter, perhaps getter immutable can't. In sfc at earlier snippet it accesses before merge. We can have getter?binding_target_names(&mut self)and resolve. Call currently extractor mutable likely. Search only. - Assistant
There is only one caller of the binding getter, and it owns a mutable extractor, so I’ll make that getter finalize pending typed patterns before returning the map. The normal module finalizers will call the same resolver explicitly. This ensures Svelte sees named prop bindings before template scanning, while preserving ordinary extraction behavior.
- Assistant
Compilation found two mechanical issues: Oxc names the interface body type differently (or does not re-export that name), and methods defined in the sibling
visit_implmodule needpub(super)visibility for calls frommod.rs. I’ll query the dependency’s AST definition, correct both, and recompile. - Assistant
The type exists;
helpers.rsuses an explicit AST import list that omitted it. I’ll add the import and widen only the resolver method to sibling-module visibility. - Assistant
The extraction crate now compiles. I’ll rebuild the CLI and rerun the original inline-type reproduction, then switch only the annotation to a named interface declared after the variable (testing source-order independence). In both cases
pinshould disappear whileunusedremains. - Assistant
Both reproductions are fixed and the genuinely unused method remains reported, including renamed props and a forward-declared interface. I’ll also smoke-test a named type alias with a defaulted destructuring binding, then run the full extraction test suite and the focused core SFC/member suites. Afterward I’ll inspect Clippy/diff for maintainability issues.
- Assistant
All 1,638 extraction tests and 20 focused core SFC integration tests pass. The temporary nested alias/default case also behaves correctly. I’ll now review the complete diff for accidental breadth or redundant code and run the repository’s Clippy policy on the affected crate.
- Assistant
The diff is clean and Clippy passes with warnings denied. The implementation is general but no broader than existing typed-identifier behavior: it only adds equivalent support for object destructuring, using static type/property names. I’ll run the complete core integration suite (not only SFC-filtered), then perform a final status/diff check and remove the temporary reproduction directory outside the repo.
- Assistant
All 523 core integration tests pass. Before submitting, I’ll do one final history/context check around the pre-existing simple Svelte bound-instance test to ensure this patch addresses the intended remaining gap rather than duplicating a recent partial fix, then summarize the checklist and submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.