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.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /fallow, current file: none) bash-$
- Assistant
I’ll first map the repository and locate the unused-class-member rule plus existing framework template tracking. Then I’ll reproduce the Svelte case with the project’s own test/fixture conventions, patch the shared analysis path, and run the focused and broader relevant tests.
- Assistant
rgis unavailable, so I’ll usegrep/find. This is a Rust workspace; I’m narrowing the search to source and fixture files and inspecting the workspace test commands before changing anything. - Assistant
The relevant logic is split between extraction (
template_usage.rs/SFC parsing) and the core bridge inunused_members.rs. I’ll inspect the data structures and the Vue/Angular bridge carefully, then identify existing unit-test helpers so the regression can be reproduced without altering test files. - Assistant
The generic snippet analyzer already supports a
bound_targetsmap and emits remapped member accesses. The likely gap is that Svelte script bindings are not added to that map (or Svelte uses a script form the binding collector misses). I’ll now inspect construction ofbound_targets, SFC kind-specific behavior, and extractor tests around Svelte/Vue member expressions. - Assistant
There is already a Svelte bound-target regression test for an event-handler arrow, indicating the reported shape may differ in declaration form (e.g.
let resultState: ResultStateinitialized later, Svelte$state, or imported factory). I’ll inspect exactly which script bindings are exported to templates and compare that with the hister-style declaration implied by the issue. - Assistant
The checked-in code appears to contain a recent partial fix for exactly
const counter = new Counter()in Svelte, yet the issue says methods remain false positives. I need verify end-to-end rather than trust extraction-only tests. I’ll inspect the core member resolution and run/build a small temporary hister-like project through the CLI, first with a direct constructor and then likely Svelte state/prop declaration variants. - Assistant
A likely hister/Svelte 5 pattern is a typed destructured
$props()binding:let { resultState }: { resultState: ResultState } = $props();That local semantically resolves to
ResultState, but the current binding collector’s advertised cases are simple typed variables and constructors. I’ll confirm by adding no repository tests: create a temporary in-repo example/debug harness via an existing extraction test invocation or CLI project, observe the false positive, then remove it. First I’ll inspect variable-declaration binding extraction to design a general typed-destructuring fix. - Assistant
The gap is confirmed in code:
visit_variable_declarationcallsrecord_typed_bindingonly when the declarator itself is aBindingIdentifier; object-pattern declarations are ignored, even though helpers already understand nested object type annotations for dotted bindings. I’ll inspect those helpers and OXC AST object-pattern fields to implement recursive pairing of destructured local bindings with their corresponding annotation properties, including aliases/defaults/nesting rather than hardcoding$props. - Assistant
For inline annotations, existing utilities can pair
resultStatewith the type pathresultState -> ResultState. But idiomatic Svelte commonly useslet { resultState }: Props = $props()wherePropsis a local interface/type alias. A robust fix should resolve local object-shape declarations too. I’ll inspectextract_nested_type_bindings, declaration metadata, and whether a local type-shape registry already exists before adding narrowly scoped state. - Assistant
I’ll reproduce through the real CLI in
/tmp(not by modifying tests). The project will export a reachableResultStateclass and consume a typed$props()instance only from Svelte markup; JSON output will show whetherpinis incorrectly reported. I’ll test both inline object annotations and a namedPropsinterface to establish the required scope. - Assistant
The build toolchain initialized successfully, but the CLI crate has multiple binaries. I’ll rerun explicitly with
--bin fallow; if--cwdis not the accepted flag, the CLI help will reveal the proper project-root option. - Assistant
The CLI uses the process working directory. I’ll run the built binary from the temporary project and capture JSON output.
- Assistant
The end-to-end reproduction succeeds: both
pinand truly unusedunusedare reported, proving the false positive. The namedPropsinterface means merely supporting inline patterns is insufficient.I’ll add a module-local registry of object type shapes (interfaces and type aliases), then resolve object destructuring annotations against it. To keep behavior conservative, only statically named properties with direct class/interface type references will produce bindings; renames/defaults and nested patterns will be paired by property path, while rest/computed/unknown properties remain unbound. Before editing, I’m checking OXC node definitions and visitor ordering/finalization so declarations after use also work.
- Assistant
Finalization matters: SFC code reads
binding_target_names()immediately after visiting, beforemerge_intoperforms delayed resolution. I’ll therefore make destructured bindings resolve eagerly when possible and add them to the extractor’s normal finalization sequence for declaration-order independence, then explicitly finalize before SFC template maps are copied. This also avoids changing any public interface.Implementation pieces:
- Extract object-property type paths from both type literals and interface bodies.
- Pair destructuring property paths with local names (supports
{ prop: alias = value }and nested objects). - Store candidates for named local shapes and resolve them after traversal.
- Finalize those candidates before SFC template scanning obtains the map.
- Bump extraction cache schema because emitted
member_accesseschanges.
- Assistant
The cache is already at 102 due later changes, so I’ll bump it to 103 and document this semantic extraction change. I’m now applying the helper and extractor-state modifications, then will compile immediately to catch AST/type issues.
- Assistant
The foundational state is in place. I’ll now wire collection and resolution into the visitor. I’ll also move candidate resolution before exported-instance recording in finalization so all downstream consumers see the completed map, not just Svelte.
- Assistant
Compilation found one missing OXC type import in
helpers.rs; the logic otherwise type-checked far enough to reach that declaration. I’ll add the explicitTSInterfaceBodyimport (the helper module does not wildcard-import AST types), then rerun formatting and compilation. - Assistant
The import grouping differed from my expected text, so the automated replacement did not apply. I’ll patch the actual import line directly and compile again.
- Assistant
The extraction crate now compiles cleanly. I’ll bump/document the cache version, run the focused extraction tests, rebuild the CLI, and rerun the exact reproduction. The expected corrected output is only
ResultState.unused;pinmust disappear. I’ll then vary declaration order and destructuring aliases/defaults to validate edge cases. - Assistant
The real reproduction is fixed: only the deliberately unused method remains. My initial focused test filters used
--exactwithout module-qualified names and therefore ran zero tests; I’ll correct that by using substring filters.Before broader tests, I’m validating:
- the
Propsinterface declared after$props()(delayed resolution), - renamed/defaulted destructuring,
- inline object annotation,
- shadowing remains handled by the existing template semantic analyzer.
- the
- Assistant
All edge-case reproductions now credit
pin, leaving onlyunused, and both existing focused tests pass. I’ll review the full diff for accidental complexity/comment formatting and assess whether the implementation can be simplified. Then I’ll run all extraction tests and Clippy for the affected crate. - Assistant
The diff is clean. To minimize unrelated behavior, I’ll restore the preexisting finalization order for exported-instance recording; typed-destructuring still resolves before bound member accesses and SFC has explicit preparation, so the fix remains intact without changing export-sentinel timing. Then I’ll run the entire extraction test suite and Clippy.
- Assistant
The full extraction suite (1,638 tests) and strict Clippy pass. One important Svelte 5 edge remains:
$props<Props>()often carries the type on the call rather than on the binding:let { resultState } = $props<Props>();The current patch handles
: Props = $props()but not this equivalent form. Since the expected behavior says the local “resolves to an instance,” I’ll extend the same conservative binding path to a single$propstype argument, without treating arbitrary generic calls as destructured class instances. I’ll first inspect OXC call type-argument fields and existing Svelte rune detection conventions. - Assistant
OXC exposes exactly what is needed, and a public helper already extracts a referenced type name from a raw
TSType. I’ll refactor the internal method to accept either annotation source, recognize only an identifier callee named$props, and use its sole type argument. Then I’ll compile and validate generic interface and inline generic forms through the CLI. - Assistant
Both
$props<Props>()and$props<{…}>()forms now work, including aliasing and type declaration after the variable. The implementation remains conservative: it activates only for$props, and only object-shape properties whose types are statically named references become class targets.I’ll rerun formatting checks, all extraction tests, strict Clippy, and the original annotation-form end-to-end reproduction one final time. Then I’ll inspect the final diff/status and submit if clean.
- Assistant
Verification is clean:
- formatting and diff checks pass;
- all 1,638 extraction tests pass;
- strict Clippy passes;
- the real CLI reproduction now reports only the intentionally unused method.
I’ll do one final source diff scan for scope and then submit. Per the requested checklist:
- Reproduced the reported error: yes; the temporary Svelte project initially reported both template-called
pinand truly unusedunused. - Confirmed the fix resolves it: yes; the same project now reports only
unused, for annotation and generic$propsforms. - Considered edge cases: yes; validated named/inline types, declarations after use, nested patterns, aliases/defaults, and both Svelte typing syntaxes; unsupported/computed properties remain conservatively unbound.
- Ran affected existing tests: yes; all
fallow-extracttests pass, along with strict Clippy and end-to-end CLI validation.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →