unused-class-members FP: methods called only from Svelte <template> member expressions…
- User
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.
- Assistant
Let me look at the actual hister repro to understand how
resultStateis bound. - Assistant
Now let me check how the sfc template usage merges member accesses and how analysis resolves them for type-only imports:
- Assistant
The analysis layer resolves imports regardless of type-only status. Now let me look at the extractor struct to add the new state:
- Assistant
Now I'll implement. First, the helpers refactor:
- Assistant
Now the extractor state in
mod.rs: - Assistant
Now add the recorder + finalize methods. Let me add them near
resolve_factory_call_candidates: - Assistant
Now wire it into the two finalize paths:
- Assistant
Now the visit-time capture in
visit_impl.rs. First the variable declaration hook: - Assistant
Now record the interface/alias property maps in
visit_declaration: - Assistant
Now the SFC path — resolve pending destructures before
binding_target_names()is read for template bound targets: - Assistant
Now a visitor-level test for the plain TS path. Let me check the test helpers:
- Assistant
All pass. Since extraction output changes for unchanged sources (new member accesses), the extraction cache must be invalidated — let me bump
CACHE_VERSION: - Assistant
Now run the full extract test suite and clippy:
- Assistant
Now end-to-end validation against the actual hister repo:
- Assistant
Passes in isolation. Let me confirm whether it's a pre-existing flake unrelated to my change:
- Assistant
The earlier failure was a flake — full CLI suite passes on rerun. Final gates — fmt and workspace clippy:
- Assistant
All gates pass. Let me document the new detection capability in
.claude/rules/detection.md, following the project convention: - Assistant
The fix is complete and verified. Summary:
Root cause
The Svelte template scanner already resolves member expressions (
resultState.pin(...)) through bound targets — alocal → ClassNamemap — but that map was only populated from value-derived bindings (const counter = new Counter()). In hister,resultStateis a Svelte 5 typed prop:let { resultState }: Props = $props()with a localinterface Props { resultState: ResultState }. Typed object destructures were never registered, so template member calls on the prop resolved to nothing and the class methods reported asunused-class-member.Fix (all in
crates/extract)visitor/visit_impl.rs—visit_variable_declarationnow handlesObjectPatterndeclarators with a type annotation viarecord_typed_object_destructure: inline type literals (: { svc: Service }) resolve immediately (with dotted aliases for nested object types, rename{ counter: c }and default{ pinned = false }unwrapping); type references (: Props) record aPendingTypedDestructure.visit_declarationnow collects interface bodies and type-literal alias bodies intolocal_object_type_properties.visitor/mod.rs— new finalize passresolve_pending_typed_destructuresresolves pending entries against the collected type maps (source-order independent), inserting intobinding_target_nameswithout overwriting more-precise value-derived bindings. Wired into bothinto_module_infoandmerge_into.sfc.rs— the SFC pipeline runs the pending resolution before readingbinding_target_names()for template bound targets (that read happens beforemerge_into's finalize); the method drains its queue so it's idempotent.visitor/helpers.rs— refactored theTSTypeLiteralwalker into sharedcollect_signature_type_bindings(interface bodies and type literals share theTSSignatureshape) and addedextract_type_alias_object_bindings.cache/types.rs—CACHE_VERSION102 → 103 (pre-fix cache entries lack the new member accesses).
Unknown type references (imported
Props, globals) resolve to nothing and drop silently — no fabricated accesses. Type-only class imports credit correctly becausebuild_local_to_export_keysdoesn't filter onis_type_only. Vue SFCs benefit automatically since the change is visitor-level.Verification
- 7 new tests (3 SFC-level mirroring the hister shape incl. alias-after-use ordering; 4 visitor-level incl. the negative case) — all pass
- Full workspace: extract 1645 ✓, CLI 2151 ✓ (one unrelated
health::coverageyarn-sidecar test flaked in the parallel run; passes standalone and in module runs, on both clean and patched trees),cargo fmt --check✓,cargo clippy --workspace --all-targets -D warnings✓ - End-to-end on asciimoo/hister with
unused-class-membersre-enabled: the fourResultStateFPs (onOpen,pin,updateLabel,addSkipRule) are gone; the one remaining finding (WebSocketManager.isOpen) is a genuine true positive, confirming the fix doesn't blanket-credit
One note: I attempted to document the new capability in
.claude/rules/detection.mdper project convention, but that file is edit-protected in this session — worth adding when this lands.
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
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →