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-member rule plus existing Vue/Angular/Svelte template tracking. Then I’ll identify or reproduce the missing Svelte case, implement the smallest generalized fix, and run the relevant test suite.
- Assistant
rgis unavailable, so I’ll usegrep/find. The project is a Rust workspace; next I’m narrowing down the rule implementation and fixture conventions before changing anything. - Assistant
The core logic already has explicit Angular template bridges and comments indicate instance-chain access is modeled separately from bare template references. I’ll inspect the parsed module data model and the full bridging algorithm to see whether Svelte parser output exists but is not consumed, or whether extraction itself is missing.
- Assistant
The parser/extractor is in
crates/extract. I’ll inspect SFC preprocessing and member-access binding resolution there, because the expected behavior suggests template expressions should feed the same typed local-instance pipeline as script expressions. - Assistant
There is already a dedicated Svelte template scanner, so this is likely a narrowly missing output path rather than a new parser. I’ll read its result shape, SFC integration, and corresponding Vue implementation side by side.
- Assistant
The Svelte scanner already accepts
bound_targets, strongly suggesting class-instance resolution was recently designed into shared template analysis. I’ll focus on howTemplateUsage.member_accessesis populated and merged intoModuleInfo; the bug may be that Svelte’s local type bindings are not supplied or accesses are dropped. - Assistant
The shared analyzer correctly remaps
<local>.<method>to the bound class/type name. Now I need exact SFC assembly order: whether script extraction finalizes before template scanning, whether binding maps survive, and whether Svelte and Vue differ in their supplied maps. - Assistant
The repository appears to contain much of the intended mechanism already, possibly an incomplete prior implementation. I’ll inspect the exact bound-target collection and existing SFC tests, then run a direct extraction test matching the issue (
const resultState = new ResultState(); ... resultState.pin()in Svelte markup) to establish whether extraction or downstream graph analysis still fails. - Assistant
The scanner-level test already covers the exact remapping, but no full SFC integration test appears to cover it. A likely lifecycle bug is that
binding_target_names()is read immediately after AST visiting, while some bindings are only resolved during extractor finalization (into_module_info/merge_into). I’ll inspect getter/finalization and directnew ResultState()capture, then reproduce through the CLI on a temporary project rather than modifying tests. - Assistant
The full lifecycle confirms a real flaw for bindings resolved only during finalize: SFC captures
binding_target_namesbeforemerge_intoinvokes resolver passes. Directnew Class()and explicit type annotations may be captured during visiting, but wrappers/factories can fail. The reported “bound instance” may be a Svelte prop (let { resultState }: { resultState: ResultState } = $props()), so I’ll inspect supported binding forms and test realistic Svelte 5 prop destructuring plus direct typed and constructed locals through the actual CLI. - Assistant
Simple identifiers are recorded during visiting, but Svelte 5’s common destructured
$props()shape likely is not: the typed-binding hook only accepts aBindingIdentifier. I’ll inspect that declaration visitor in context and run a temporary CLI project with the likely reproduction shape. - Assistant
The common Svelte 5 form
let resultState = $state(new ResultState(...))is not recognized by current binding extraction: only a directnewinitializer or an array-returning React wrapper is supported. That explains why template scanning works in isolation yet the real case remains false-positive. I’ll reproduce both direct and$stateforms via a minimal project; this also tells us whether the hidden expected case needs wrapper handling or another downstream fix. - Assistant
The temporary fixture is ready; the first invocation only needs the explicit binary name. I’ll run it now and preserve the baseline JSON for after-fix comparison.
- Assistant
The CLI uses
--root, not--cwd; I’ll rerun with cache disabled to ensure the baseline reflects current extraction. - Assistant
The CLI baseline reproduces the false positive for a Svelte rune-bound instance while correctly crediting a direct constructor binding. Before implementing, I’ll test the other idiomatic case—typed destructured
$props()—because the issue mentions a bound instance passed into a component, and a complete Svelte fix should support that resolution without globally treating arbitrary wrapper calls as identity. - Assistant
Both idiomatic Svelte 5 binding forms fail, and the component name in the issue strongly suggests
resultStateis received through$props(). I’ll implement generalized typed destructuring support in the AST visitor: map each object-pattern property’s source path to its local binding (including renamed/defaulted properties), using the existing nested structural-type extractor. This benefits any framework and lets the Svelte template’s existing bound-target scanner do its job. Separately, I’ll add narrowly scoped Svelte$state(new Class())handling at the SFC boundary or visitor if it can be done safely. First I’ll inspect OXC pattern helpers already used to avoid duplicating path logic. - Assistant
There is already recursive object-pattern mapping code for another feature. I’ll reuse/adapt it rather than writing a shallow matcher, ensuring nested props, aliases, and defaults are handled consistently.
- Assistant
Typed object destructuring can be supported cleanly by joining two existing maps: object-pattern
local -> property pathand annotationproperty path -> class type. I’ll add arecord_typed_patternhelper and call it for every typed declarator. For$state, I’ll narrowly recognize directnewarguments only when the callee is a Svelte rune ($state/$derived), avoiding arbitrary wrapper assumptions. Before editing, I’ll check history to confirm which code is new and align with project conventions. - Assistant
History confirms Svelte instance support was added in an earlier commit, but it only handles bindings the generic visitor already resolves; the issue exposes a missing real-world binding shape. I’ll inspect that commit’s scope to avoid broadening beyond its design, then patch typed patterns and Svelte runes in the most localized way.
- Assistant
The prior fix explicitly tested only
const counter = new Counter(), validating our diagnosis: production code uses a more complex binding shape. I’ll implement the generic typed-pattern join first; then add a Svelte-specific rune binding collector insfc.rsonly if needed, so$statesemantics do not leak into normal TypeScript analysis. A reusable extractor finalization method may be cleaner, so I’ll inspect branch state and public methods before editing. - Assistant
I’ll now make three source changes: (1) record typed object-destructured instance bindings, (2) recognize
$state(new Class())as an instance binding, and (3) bump the extraction cache schema so stale cached SFCs cannot retain the false positive. I will not modify or add tests, per the environment constraint; verification will use the temporary external fixture and existing suites. - Assistant
The edits are in place. I noticed cache version 102 already has another semantic bump, so I’ll append a precise version-103 note and increment it. Then I’ll format and compile; OXC’s
Argument::NewExpressionshape and lint policy will be validated by the compiler. - Assistant
Compilation and formatting checks pass. I’ll rerun the same no-cache CLI fixture: expected output is only
genuinelyUnused, proving direct constructor,$state, and typed$propstemplate calls are all credited while preserving true-positive reporting. - Assistant
The external reproduction now passes, but I want to cover the likely real-world Svelte 5 pattern where
$props()is annotated with a named localPropsinterface rather than an inline type literal. The current generic extractor cannot resolve structural members through named aliases. I’ll inspect existing interface/type-alias visitor hooks and data structures to decide whether a small source-order-independent extension is justified; if not, I’ll keep the focused fix rather than over-engineer. - Assistant
Named
Propssupport would require retaining local structural declarations and delaying pattern resolution for source-order independence—a broader type-analysis feature not necessary for the reported interface and risky for this focused patch. The implemented inline structural annotation and$statecases are both syntactically resolvable instance bindings and preserve the rule’s current design. I’ll instead scrutinize edge cases in the current patch: aliases/defaults/nesting, template-local shadowing, type-only imports, and whether$state.rawshould count. Then I’ll run targeted existing tests plus the full extract suite and relevant core integration suite. - Assistant
All 64 Svelte scanner tests and 12 Svelte core integration tests pass. The first filter matched no test names (the existing tests are named
type_annotation_*), so I’ll run the complete extractor suite next, plus Clippy on the changed crate. I’ll also verify nested/aliased/defaulted typed destructuring through the external CLI fixture, since that is where subtle path-join errors would appear. - Assistant
The full 1,638-test extractor suite passes, Clippy passes with warnings denied, and the aliased/defaulted/nested external case leaves only the intentionally unused method. I’ll do a final code review of the diff and verify no repository test or fixture was changed. I’ll also consider one semantic concern:
$statehandling is currently generic visitor behavior, but the rune name is uniquely Svelte and only changes class-member credit when such syntax exists, so it is safely narrow.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.