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 first inspect the repository structure and locate the unused-class-members rule and existing framework template tracking. Then I’ll reproduce the Svelte false positive using the project’s test conventions, implement the narrow framework integration, and run the relevant existing test suites.
- Assistant
The relevant behavior appears concentrated in
crates/extract, with explicit comments for Vue, Angular, and Glimmer template-to-class-member bridges. I’ll inspect those extraction paths, Svelte parsing, and the associated fixture-based tests to identify the missing data flow rather than adding a broad name-only suppression. - Assistant
There is already a Svelte test named for a bound class member call, suggesting the current code handles one syntactic form but misses the reported direct markup expressions or has an incomplete binding-resolution path. I’ll read that test and the collector APIs/call site to reproduce the exact gap before changing code.
- Assistant
The current branch already resolves
const counter = new Counter()in an arrow event handler. The reported application likely uses a different script binding shape (for example Svelte reactive state, typed declarations, assignment, or an imported instance), or direct expressions are not routed identically. I’ll inspect howtemplate_visible_bound_targetsis populated and how expression parsing maps identifiers to targets. - Assistant
The direct
{resultState.pin(...)}path is present and should invoke the bound-target-aware expression analyzer. The likely failure is therefore the binding itself. I’ll inspect the analyzer’s supported binding forms and use git history/status plus the project version to determine whether this checkout contains an incomplete prior fix. I’ll also run the existing targeted test as a baseline. - Assistant
The baseline targeted test passes, confirming only a subset is covered. I’ll search for any bundled hister fixture and inspect
ResultState-like initialization conventions in Svelte tests. I’ll also verify plain/direct expression behavior independently through an existing test harness command, then test likely Svelte 5$state(new ResultState(...)), typed bindings, and assignments, since the issue namesresultStateand a modern Svelte repository. - Assistant
The existing fixture confirms direct construction. To avoid guessing, I’ll inspect the fixture’s expected class-member results and recent commits touching Svelte/template bound-target code. This should reveal whether the repository already has infrastructure added for another issue but lacks the exact regression fixture/end-to-end crediting expected here.
- Assistant
The key discovery is that a recent prior fix (
cadeb111) intentionally added Svelte instance member tracking, but only provesconst counter = new Counter(). The issue asks specifically for<local>.<method>when<local>“resolves to an instance,” so I’ll inspect that change and end-to-end analysis tests. A likely defect is that the extractor emits the remapped access but the graph resolver only credits imported class targets under certain import/export forms. - Assistant
A plausible real-world distinction is that
resultStateis a component prop typed asResultState, not locally constructed. I’ll create temporary (outside-repository) Svelte 4 and Svelte 5 reproductions and run the actual CLI withunused-class-membersenabled. This will reproduce which binding form still false-positives without modifying tests. - Assistant
The temporary fixture is ready; the CLI crate has multiple binaries, so I’ll rerun explicitly with the
fallowbinary and inspect JSON output. - Assistant
The end-to-end reproduction isolates the defect:
export let resultState: ResultStateis correctly credited.- Svelte 5
$props()destructuring is not: both inline object type and namedPropsreport the called methods. - An actually unused method remains reported.
I’ll now inspect variable declaration/type helpers and local interface metadata to implement property-level target extraction for destructured typed props. The implementation should remain general TypeScript binding resolution (and thus naturally feed Svelte template tracking), with shadowing already handled by the scanner.
- Assistant
Currently
visit_variable_declarationdeliberately callsrecord_typed_bindingonly for a single identifier, so object destructuring is skipped entirely. The helper can already extract property paths from inline type literals, but named interfaces require a small local type-property map or AST lookup. I’ll inspect the exact helper and interface visitor lifecycle to choose the least invasive design. - Assistant
A robust solution needs to be order-independent (the
Propsinterface may appear before or after$props) and support aliases such as{ resultState: state }. I’ll reuse the existing object-pattern path extractor, add lightweight local structural type bindings collected from interfaces/type aliases, queue destructured typed-binding candidates as owned strings, and resolve them during extractor finalization. First I’ll inspect finalization order and the pattern helper semantics. - Assistant
I can keep this focused without adding a full type system:
- For inline structural annotations, correlate
extract_nested_type_bindingspaths with object-pattern local names immediately. - For a named local
Props, collect its direct/nested property type paths into an owned map and resolve queued destructuring candidates after the AST walk. - Do not infer untyped
$propsor arbitrary runtime objects, avoiding false positives. - Preserve aliases/default patterns through the existing object-pattern helper.
I’ll inspect
into_module_infoto place resolution before bound-member remapping, then edit only visitor internals/helpers. - For inline structural annotations, correlate
- Assistant
One SFC-specific lifecycle detail matters: template scanning reads
binding_target_namesbeforemerge_intofinalization. I’ll make the accessor mutable and have it resolve pending typed destructuring before returning, while also invoking the same resolution in normal finalization. This keeps.tsbehavior order-independent and ensures SFC templates see the completed map. I’ll verify call sites before editing. - Assistant
I’ll implement owned structural-type metadata and pending candidates now. The path correlation maps source property paths (e.g.
resultState) to actual locals (including aliases/defaults), and only records a target when the annotation’s property has a single syntactically resolvable class type. - Assistant
The reusable type-property extraction is in place. Next I’ll add the pending candidate structures and resolution pass to
ModuleInfoExtractor, then wire interface/type-alias collection and object-pattern declarations in the visitor. - Assistant
I’ll wire three visitor points: helper imports, declaration-time structural metadata capture, and variable-time destructuring capture. Inline annotations resolve immediately; named annotations queue for the accessor/finalizer.
- Assistant
Compilation found a missing explicit AST import in
helpers.rs; the logic itself type-checks far enough to reach that declaration. I’ll addTSInterfaceDeclarationto the helper imports and rerun the check. - Assistant
I’ll update that import and run both compilation and the temporary end-to-end reproduction.
- Assistant
The code compiles, but the reproduction is unchanged, including inline structural typing. That means Oxc’s destructured annotation is attached to the
ObjectPatternrather than exposed throughVariableDeclarator::type_annotationin the way the existing identifier branch assumes. I’ll inspect the Oxc AST definitions and, if needed, briefly instrument the SFC target map to confirm before adjusting the visitor. - Assistant
I’ll read those definitions to identify the correct annotation accessor and update the matching logic accordingly.
- Assistant
The annotation is indeed on
VariableDeclarator, so the branch should run. I’ll add a temporary diagnostic at the SFC boundary to print the completed target map for the reproduction; this is the fastest way to distinguish capture failure from template analyzer failure, and I’ll remove it immediately afterward. - Assistant
No diagnostics appeared because the CLI reused its extraction cache. I’ll clear only the temporary fixture’s cache, rerun the instrumentation, and restore the source file again.
- Assistant
The completed target map is correct for all three components (
resultState -> ResultState); the prior unchanged result was stale cache output. I’ll rerun clean with restored source and verify only the deliberately unused methods remain. This also indicates the production extraction cache version must be bumped so existing users do not retain the false positive after upgrading. - Assistant
The clean end-to-end reproduction now credits both Svelte 5 forms; only
addSkipRule(not invoked in the temporary fixture) andgenuinelyUnusedremain. I’ll bump the extraction cache version from 102 to 103, review the complete diff for accidental broad changes, then run formatting and the affected extractor/core tests. - Assistant
The diff is focused, though the cache-version comment still describes the previous bump. I’ll update that comment to document the new invalidation reason, then run the entire extractor test suite and the core SFC integration tests.
- Assistant
I’ll append a “Bumped to 103” rationale and launch the relevant tests.
- Assistant
All 1,638 extractor tests and 17 SFC integration tests pass. I’ll do one extra temporary edge verification for source-order independence, destructuring aliases/defaults, and all four reported methods; then run Clippy on the affected crate and inspect repository cleanliness.
- Assistant
The edge reproduction now invokes all four reported methods across legacy props, inline Svelte 5 props, and a named
Propsdeclared after use with an aliased local; onlygenuinelyUnusedremains. Clippy passes with warnings denied.Checklist review:
- Reproduced the reported error: Yes. The temporary end-to-end CLI fixture on 2.84.0 reported Svelte 5 template-only
ResultState.onOpenand.updateLabelas unused. - Confirmed the fix resolves it: Yes. After clearing cache and applying the fix, all invoked methods—including alias/source-order cases and all four names from the report—were credited; the intentionally unused method remained reported.
- Considered edge cases: Yes. The implementation handles inline object types, named interfaces/type aliases, declarations after use, destructuring aliases/default bindings, nested property paths, and preserves template-local shadowing. It does not infer untyped or ambiguous runtime objects.
- Ran affected existing tests: Yes. All 1,638
fallow-extracttests and all 17 SFC core integration tests passed; also passed.
- Reproduced the reported error: Yes. The temporary end-to-end CLI fixture on 2.84.0 reported Svelte 5 template-only
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.