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
Let me start by exploring the repository structure to understand what we're working with.
Assistant
This is a Rust project. Let me explore the structure further.
Assistant
Let me look at the SFC handling in the extract module:
Assistant
Now let me look at the Svelte template scanner file:
Assistant
Let me see the full svelte.rs file:
Assistant
Let me look at the shared.rs and the template_usage module:
Assistant
Now let me look at the shared.rs:
Assistant
Let me see how Vue handles this. Let me look at the Vue template scanner:
Assistant
Now let me look at how the Svelte scanner integrates with the SFC module:
Assistant
Now let me look at how the unused-class-members are detected:
Assistant
That's a big file. Let me look at the key parts:
Assistant
Let me look at the rest of the svelte.rs to understand the full file:
Assistant
Let me look at the relevant test in detail to understand the issue:
Assistant
Let me look at the actual hister repo case from the issue:
Assistant
Let me look at the result-state.svelte file:
Assistant
Let me find the Svelte prop discovery code:
Assistant
Let me search for svelte-related code in the visitor:
Assistant
Let me look at how the Svelte prop is being handled:
Assistant
Let me look at how
letdeclarations with destructuring are handled:Assistant
Now I see the issue. Let me look at the specific case:
In the
ResultActionsMenu.svelte:<script lang="ts"> import type { ResultState } from '$lib/result-state.svelte'; ... let { url, title, domain, resultState, query, pinned = false, canWrite = true, onDelete, removeResult, removeResultsByDomain, }: Props = $props(); ... </script>So
resultState: ResultStateis a Svelte 5 prop with a type annotation. The visitor should record this as a binding toResultState.But looking at
visit_variable_declaration, it only handlesBindingPattern::BindingIdentifierfor the type annotation. The destructuring patternlet { resultState, ... }: PropshasBindingPattern::ObjectPattern, notBindingIdentifier.So the visitor needs to handle the object destructuring pattern to record the typed bindings. Let me check the current handling:
Assistant
Let me look at how the visitor handles test cases for Svelte:
Assistant
Let me first understand the codebase. Let me look at what tests exist for the bound targets:
Assistant
Let me see how the
binding_target_namesare collected from the script body:Assistant
Let me look at the binding_target_names structure in the visitor:
Assistant
Let me first set up a test that reproduces the issue:
Assistant
Let me first look at the existing tests for Svelte and see if there's a pattern I can follow:
Assistant
Now let me write a test in the existing test file to reproduce the issue:
Assistant
Let me write a quick test in the existing svelte.rs file to see if the test from the issue currently passes:
Assistant
Now let me write a test that uses the full SFC pipeline to confirm the issue:
Assistant
Let me write the test directly in the existing tests/sfc.rs:
Assistant
Now let me add a quick test at the end of the sfc.rs file:
Assistant
Now let me run this test:
Assistant
The test confirms the issue. Now let me understand the visitor and look at the existing code:
Assistant
Let me check the AST structure:
Assistant
Let me explore the existing handling in the visitor. Let me look at how the visitor handles destructuring patterns in general:
Assistant
Let me look at the structure of the failing case. Let me also look at the test cases that exist for Svelte:
Assistant
Let me explore the AST structure for the test case to understand what I need to handle:
Assistant
Let me write a simpler test to understand the AST structure better:
Assistant
Let me look for code that processes destructuring patterns with type annotations:
Assistant
Let me look at how interfaces are stored:
Assistant
Let me look at the local signature refs and see how they store the type info:
Assistant
Let me look at how the visitor could store interface definitions:
Assistant
Let me look at the visitor structure to understand where to add the new field:
Assistant
Now let me look at the rest of the visitor structure:
Assistant
Let me first see the tests for the Svelte template scanner to understand what's expected:
Assistant
Let me look at the
record_typed_bindingandvisit_variable_declarationagain to understand the full context:Assistant
Let me first remove the temporary test and understand the approach better:
Assistant
Let me now understand the actual code flow better. Let me check what the current output of the visitor is for this case:
Assistant
Now I understand. Let me implement the fix. First, let me look at what existing tests cover similar functionality:
Assistant
Now let me understand what AST is generated for the Svelte 5 props pattern. Let me look at the patterns that we need to handle:
Assistant
Let me look at the AST for the pattern in detail by writing a simple test:
Assistant
Now let me start implementing the fix. First, let me remove the debug test:
Assistant
Let me revert the test changes:
Assistant
Now let me start implementing the fix. First, let me explore the visitor structure to find the best place to add the new code:
Assistant
Now let me look at the visit_variable_declaration to see what we have:
Assistant
Let me now start implementing the fix. First, let me add the new field:
Assistant
Now let me add a new field for interface property types. Let me look at the visitor imports first:
Assistant
Now let me add the field. First, let me look at the place to add it:
Assistant
Now let me add the new field. I'll add it after
local_type_declarations:Assistant
Now let me add the new field:
Assistant
Now let me add the method to populate this field. Let me first look at the visit_declaration area for interface declarations:
Assistant
Now let me also look at the type alias handling and the export default interface handling:
Assistant
Now let me look at the helpers file to understand what's exported:
Assistant
Now let me add the helper function in helpers.rs to extract interface property types:
Assistant
Now let me add the helper function import and use it in the visit_impl.rs:
Assistant
Now let me update the visit_declaration to populate the
local_interface_property_typesfield:Assistant
Now let me add the logic to handle the destructuring pattern. First, let me add a method to record typed bindings from an ObjectPattern:
Assistant
Now I need to add the import for
BindingPropertyif it's not already imported:Assistant
Now let me update the
visit_variable_declarationto use the new method:Assistant
Now let me try to compile:
Assistant
Let me check the AST structure for
BindingProperty:Assistant
So
BindingPropertyis a struct, not an enum. Let me check the actual struct definition:Assistant
Let me check how
ObjectPattern.propertiesis used elsewhere:Assistant
Let me fix the
BindingPropertyusage in visit_impl.rs:Assistant
Now let me add the missing imports for
TSInterfaceDeclarationandTSTypeAliasDeclarationin helpers.rs:Assistant
Now let me try to compile again:
Assistant
Let me fix the type name:
Assistant
Now let me fix the Cow issue:
Assistant
Compilation succeeded. Now let me re-add my test:
Assistant
The test passes! Now let me also test with the more complex case from the issue with multiple methods:
Assistant
Both tests pass. Now let me also test with type alias (
type Props = {...}):Assistant
All three tests pass. Now let me think about edge cases:
- What if the interface is declared AFTER the destructuring? (Svelte 5 props pattern)
- What if the interface has nested types?
- What if there are renaming patterns (
{ resultState: rs })? - What about non-existent property names?
Let me think about these. The visitor walks top-down, so if the interface is declared after the destructuring, it won't be in
local_interface_property_typesyet. Let me check this:Assistant
Let me look at the output to see if the edge case works:
Assistant
Let me also test the renaming pattern:
Assistant
The rename case works. Now let me clean up the temporary tests:
Assistant
Now let me look at where the existing svelte tests are in the codebase:
Assistant
Let me run the existing svelte tests to make sure they still pass:
Assistant
All 88 svelte tests pass. Now let me run all the tests in the extract crate to make sure nothing else broke:
Assistant
All 1638 tests pass! Now let me also run the full test suite:
Assistant
The only failure is unrelated to my changes. Let me check this:
Assistant
The failure is pre-existing and unrelated to my changes. Let me confirm my changes are still in place:
Assistant
Now let me also think about the case where the type isn't defined in the current file. Let me also check the case for inherited interfaces:
Assistant
Let me revert the test file and add a proper test in the existing test file:
Assistant
Let me look at the code I've added:
Assistant
me also check the merge_into for SFC scripts to ensure the visitor state is properly preserved:
Assistant
Let me run all the tests to make sure everything works:
Assistant
All 1638 tests pass. Now let me also test the full hister case manually to ensure it works:
Assistant
All 4 methods from the issue (
onOpen,pin,updateLabel,addSkipRule) are now correctly tracked asResultState.method. Let me revert the test:Assistant
me also run the integration test to make sure nothing is broken:
Assistant
All 523 tests in fallow-core pass. Let me also run a broader test suite:
Assistant
All tests pass. Let me also test fallow-cli excluding the broken test:
Assistant
Let me also run the integration test with the hister repo to verify the fix works end-to-end:
Assistant
me run fallow on the hister repo to verify the fix works:
Assistant
. Let me try without the --no-config option:
Assistant
me see if the unused-class-members rule actually fires:
Assistant
The fix works! "No issues found" - all the methods are correctly identified as used. Let me also test by reverting my changes to confirm:
Assistant
"No local changes to save" means I didn't make any changes (other than to the visitor files I already committed in git diff). Wait, my changes ARE in the working tree. Let me check:
Assistant
Wait, the test passes even without my fix. Let me check if the entry points I configured are actually analyzing the ResultActionsMenu.svelte:
Assistant
Let me also see if the
result-state.svelte.tsis being analyzed:Assistant
Let me check the version of fallow that was used in the bug report:
Assistant
Let me try with the user's config but with
unused-class-membersenabled:Assistant
Let me look at the routes to see if ResultActionsMenu is actually used:
Assistant
So
ResultActionsMenuis used inwebui/app/src/routes/+page.svelte. The user's config haswebui/app/src/routes/**/+*.svelteas an entry point, so it should be analyzing this file.But wait, the issue may not have been the file system but the actual class member access detection. Let me look at the
result-state.svelte.tsfile - it hasresultState.onOpen()etc. Let me check if these are being tracked:Assistant
Wait, I'm running with my changes stashed. Let me re-apply and test:
Assistant
Wait, I'm now in /tmp/hister-test. Let me go back to the fallow directory:
Assistant
My changes were stashed. Let me re-apply them:
Assistant
Good, my changes are back. Let me rebuild:
Assistant
Let me also verify the fix works for the issue with a self-contained test:
Assistant
The fix works. Now let me verify by reverting the fix and seeing if the issue appears:
Assistant
Let me re-apply my changes and investigate further:
Assistant
Let me investigate why the hister integration test doesn't reproduce the issue:
Assistant
Let me check the cross-file tracking code:
Assistant
Let me check the typed instance targets:
Assistant
Let me look at how instance bindings are populated:
Assistant
Let me look at the cross-file tracking more carefully:
Assistant
Let me look at the merge_script_into_module:
Assistant
OK so
template_visible_bound_targetsis populated fromextractor.binding_target_names()(filtered to excludethis.*entries). With my fix, this should includeresultState -> ResultState.Then in
apply_template_usage, the Svelte template scanner uses these targets to credit member accesses.But wait, the
combined.member_accessesare also extended from the template scanner. Let me check this:Assistant
Let me verify the test works now:
Assistant
Let me also verify that the test fails without the fix:
Assistant
The test was stashed too. Let me re-add it and verify the failure without the fix:
Assistant
The test correctly reproduces the issue. Now let me revert the test changes:
Assistant
Now let me also run the cargo build to make sure my changes compile correctly:
Assistant
Now let me also check the linting:
Assistant
No clippy warnings. Let me also check the formatting:
Assistant
Formatting is now correct. Let me also check clippy:
Assistant
No clippy warnings. Let me also run all the tests one more time:
Assistant
Let me also look at the diff to verify my final changes:
Assistant
Let me also test the edge case where the interface is imported from another file:
Assistant
Let me revert the test:
Assistant
Now let me also clean up the test files I created:
Assistant
Let me also confirm the test still works:
Assistant
All 1638 tests pass. Let me also run the full workspace tests one more time:
Assistant
All tests pass. Let me also run the fallow-cli tests (excluding the pre-existing failure):
Assistant
All other tests pass. Let me also verify the full diff:
Assistant
Let me do a final verification with a self-contained test:
Assistant
The fix works. "No issues found" means all the methods (
onOpen,pin,updateLabel,addSkipRule) are correctly identified as used. Let me also verify by reverting and seeing the issue:Assistant
Hmm, even without the fix, the test passes. This means the integration test isn't actually reproducing the issue. Let me investigate why.
Wait, the issue might be that the Svelte file is being parsed as a single module, and the visitor detects the import. The cross-file tracking then handles it.
Let me check what's different. Let me look at the .svelte.ts file extension:
Assistant
Let me investigate why the hister integration test doesn't reproduce the issue. Let me check the file structure:
Assistant
So the integration test only shows
WebSocketManager.isOpenas unused. TheResultStatemethods are correctly being tracked.This is strange. The issue claims that the methods are reported as unused, but they're not in this test. Let me look more carefully at the hister code:
Wait, let me see the +page.svelte which uses ResultActionsMenu:
Assistant
Interesting! In the +page.svelte, the
ResultStateis instantiated asnew ResultState(initialLabel). So the visitor would record this as a binding:getResultStatereturnsResultState- The
statefromgetResultStateis aResultState - The template uses
state.pin(...)etc.
Let me check this:
Assistant
Let me look at how
ResultActionsMenuis used:Assistant
Let me verify by reverting and re-testing:
Assistant
Let me re-apply my changes:
Assistant
Let me look at the other files using ResultState:
Assistant
Let me check if there's another path that handles this. Let me look at the +page.svelte:
Assistant
Let me check what the visitor does with the import:
Assistant
So in the +page.svelte case, the
state.displayLabelaccess is NOT being captured. Thestateis fromgetResultStatewhich returnsResultState. The visitor should track this through the return type annotation.Let me check what the visitor does for the function return type. Let me also check the test in hister - if my fix isn't needed because the cross-file tracking handles it differently, I need to know.
Wait, let me check the test result more carefully. The member accesses are only
resultStates.has,resultStates.set,resultStates.get. Thestate.displayLabelaccess is NOT captured. This is because the visitor doesn't track the function return type binding.So if
state.displayLabelis not captured, thenResultState.displayLabelis not credited. But the integration test on the hister repo doesn't show this as unused. Why?Let me check:
Assistant
Let me check if the issue is in how
stateis bound in +page.svelte:Assistant
Let me try with a different entry point pattern:
Assistant
Let me also run the full test suite to make sure my fix doesn't break anything:
Assistant
The only failure is the pre-existing unrelated test. All my changes pass. Let me also clean up:
Assistant
Let me check the final state of my changes:
Assistant
Now let me think about the checklist before submitting:
Checklist:
-
If an error was reported in the issue description, I have successfully reproduced it.
- YES: I created a unit test that reproduces the issue. Without my fix, the test fails (member accesses are empty). With my fix, the test passes (member accesses include
ResultState.pin).
- YES: I created a unit test that reproduces the issue. Without my fix, the test fails (member accesses are empty). With my fix, the test passes (member accesses include
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- YES: The unit test passes with my fix.
-
I have thought about edge cases and made sure my fix handles them as well.
- YES: I tested:
- Interface declared before destructuring
- Type alias declared before destructuring
- Renaming pattern (
{ resultState: rs })
- YES: I tested:
-
Assistant
Let me also verify the final diff one more time:
Assistant
The diff is clean and minimal. Let me also do a final verification:
Assistant
All checks pass. Let me also do a final review of my changes:
Assistant
Let me also do a final review of the changes by looking at them in context:
Assistant
The code is well-documented. Now let me submit my changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.