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 start by exploring the repository structure to understand the codebase and locate relevant files. Let's first look at the root directory.
- Assistant
Let me get a better understanding of the repository structure. It seems like this is a JavaScript/TypeScript linting tool called "fallow". Let me explore more.
- Assistant
Let me understand the issue. The issue is about "unused-class-members" false positive in a linter called "fallow". When a class method is called from a Svelte template via member expression (like
resultState.pin(...)), the method is reported as unused. The fix should credit a method called as<local>.<method>(...)inside a Svelte<template>when<local>resolves to an instance of the class.Let me explore the repository to find the relevant code for the "unused-class-members" rule.
- Assistant
Let me search for the unused-class-members rule.
- Assistant
Let me look at the core analysis file for unused members and the SFC template extraction:
- Assistant
Let me explore the Svelte template extraction file and the unused members analysis.
- Assistant
Let me examine the unused members analysis module and how it handles template usage:
- Assistant
Let me look at the shared.rs file to understand how member expressions are currently tracked, and also the TemplateUsage structure.
- Assistant
Now let me look at the
TemplateUsagestructure andanalyze_template_snippetfunction: - Assistant
Now I need to understand how
member_accessesfromTemplateUsageare used in theunused_members.rsanalysis. Let me look at how template usage flows into the unused members check. - Assistant
Let me look at the relevant areas in unused_members.rs more closely:
- Assistant
Let me look at the area around line 1622 to understand how template member accesses are bridged to component classes.
- Assistant
Let me now look at how the Svelte template scanning works and how the results are used in the extract phase:
- Assistant
Let me look at the SFC module to understand how Svelte templates are processed, especially how
template_usageis handled: - Assistant
Now let me understand the SFC extraction pipeline:
- Assistant
Let me look at the SFC extraction function that handles template usage and bound targets:
- Assistant
Let me look at the
apply_template_usagefunction and theprocess_sfcfunction: - Assistant
Now let me look at how
MemberAccessis used in the unused members analysis to understand the flow: - Assistant
Let me look at the
resolve_bound_member_accessesfunction: - Assistant
Let me look at how
resolve_bound_object_nameworks to understand the full resolution chain: - Assistant
Let me look at how
resolve_bound_object_nameworks: - Assistant
Now let me understand how the unused members analysis works with template member accesses. Let me check the Svelte scanner to see how it handles member accesses in template expressions:
- Assistant
Let me look at the
apply_tagfunction andapply_markup_tagfunction to understand how expressions and member accesses are tracked in Svelte templates. - Assistant
Now I need to understand how
bound_targetsare populated for Svelte files. Let me check how the visitor tracksbinding_target_names: - Assistant
Let me look at how
bound_targetsflow from the SFC pipeline to the unused members analysis: - Assistant
Let me look at how
binding_target_namesgets populated in the visitor: - Assistant
Let me look at the full
resolve_factory_call_candidatesmethod: - Assistant
Now let me understand how member accesses are processed in the unused members analysis:
- Assistant
Let me look at how the SFC pipeline populates
template_visible_bound_targetsand how theunused_membersanalysis processes the resultingmember_accesses: - Assistant
Let me look at the test for Svelte template member access tracking and the existing integration test for Svelte:
- Assistant
Let me look at the test for Svelte template member usage:
- Assistant
Now let me understand how the
TemplateUsagefeeds into the unused members analysis. Let me look atresolve_typed_instance_chain_targets: - Assistant
Let me look at that function:
- Assistant
Let me look at how
template_usage.member_accessesare used in the analysis and check for Svelte-specific handling: - Assistant
Let me look more closely at the
analyze_template_snippet_with_bound_targetsfunction to understand how it resolves member accesses: - Assistant
Let me look at how
merge_intoworks vsinto_module_info: - Assistant
Let me look at the
merge_intofunction: - Assistant
Now let me look at how
binding_target_namesis populated, especially fornewexpressions: - Assistant
Let me look at how
binding_target_namesis populated fornewexpressions and understand the chain: - Assistant
Let me look at the code around line 835 and 843 in visit_impl.rs to understand how binding_target_names are populated for variable declarations with
newexpressions: - Assistant
Let me look at the code around line 2039 where variable declarations with
newexpressions are handled: - Assistant
Now I understand the core issue better. When
let resultState = new ResultState()is in the script, the extractor populatesbinding_target_nameswithresultState -> ResultState. Then the template scanner usesbound_targetsto resolveresultState.pin(...).Let me check the test case for Angular template members to understand how the expected pattern works:
- Assistant
Let me look at how the
propagate_class_inheritancefunction handles template member accesses and how the Svelte case is different: - Assistant
Let me look at the main analysis function to understand the full flow:
- Assistant
Let me now look at how the Svelte template scanner handles member expressions and the
bound_targetsflow. Let me check the existing SFC tests: - Assistant
Let me look at the existing SFC tests for Svelte and understand how bound targets are used:
- Assistant
Let me look at the integration test for
sfc_parsing: - Assistant
Let me look at the existing test for
svelte_template_event_handlers_mark_class_members_used: - Assistant
Let me look at the svelte-project fixture to understand the current test case:
- Assistant
Let me find where the test fixtures are located.
- Assistant
Let me find the fixtures directory.
- Assistant
Let me look at the common.rs to understand the fixture_path function:
- Assistant
Let me look at the svelte-project fixture to understand the current test case.
- Assistant
Let me explore the svelte-project fixture:
- Assistant
Let me check the Svelte template test case to see how Counter.bump and Counter.value are currently handled.
- Assistant
Let me look at the Counter class definition:
- Assistant
Let me understand how
local_to_export_keysis built: - Assistant
Let me look at
build_local_to_export_keys: - Assistant
Let me look at how the member_accesses are used in the actual analysis. Let me look at the main analysis function:
- Assistant
Let me look at the main analysis function for unused members to understand the flow:
- Assistant
Let me search for the main analysis function:
- Assistant
Let me look at the main analysis function
find_unused_members: - Assistant
Let me look at how the
ModuleInfoExtractorhandles member accesses in call expressions: - Assistant
Let me look at
visit_static_member_expressionto understand how member accesses are recorded: - Assistant
Let me look at
static_member_object_nameto understand how object names are resolved: - Assistant
Let me look at
static_member_object_name: - Assistant
Let me look at the full existing svelte-project fixture to understand how it works:
- Assistant
Let me understand when
binding_target_namesgets populated fornewexpressions: - Assistant
Let me check the visitor code to see how
newexpressions are handled: - Assistant
Let me look at how
newexpressions are handled: - Assistant
Let me look at the context where the
newexpression handling occurs: - Assistant
Now I have a good understanding of the code flow. Let me create a reproduction to verify the issue. First, let me build the project to make sure tests can run:
- Assistant
Let me run the existing Svelte-related tests to see if they pass:
- Assistant
Let me look at the scoped_used_class_members test:
- Assistant
Now let me look at how the Vue template handles class members in comparison to Svelte:
- Assistant
Let me look at the Vue fixture to understand how it handles class member access in templates:
- Assistant
Let me search for any known issues or TODOs related to Svelte template member access:
- Assistant
Now I have a deep understanding of the code flow. Let me create a minimal reproduction test to verify the issue. I'll create a test fixture that mimics the described scenario:
- Assistant
Let me create a test fixture and a test to reproduce the issue:
- Assistant
Let me create the test fixture files:
- Assistant
Let me create a test fixture that demonstrates the exact issue - a class with methods called via member expressions in Svelte templates:
- Assistant
Let me create the Svelte template that calls methods on an instance:
- Assistant
Now let me write a test that runs the analysis on this fixture:
- Assistant
Now let me run this test to see if it passes or fails:
- Assistant
The test passes! This means the basic scenario works. Let me think about what specific pattern in hister might cause the issue. Let me look at how Vue handles template member access differently, since the issue mentions "parallel to the existing Vue/Angular template member-access tracking":
- Assistant
Interesting, the test passes! So the basic case works. Let me think about what specific pattern in hister might cause the issue. Let me try a case where the class is defined in the same file (not imported):
- Assistant
Let me update main.ts to import this too:
- Assistant
Let me add a test for the inline class case:
- Assistant
Let me run this test:
- Assistant
Let me check the false_positive_fixes tests for any Svelte-related patterns:
- Assistant
Let me look at CLAUDE.md for any guidance on how to approach this issue:
- Assistant
The basic test passes. Let me think about what specific scenario in the hister repo might cause this. Let me try a prop-based pattern where the instance is NOT created via
new: - Assistant
Let me update main.ts to import this as well:
- Assistant
Let me add a test for the prop-based case:
- Assistant
Let me look at how the Svelte prop case handles type annotations - specifically when the instance comes from a
$props()orexport let: - Assistant
Interesting, even the $props() case passes! Let me look at
extract_nested_type_bindingsto understand why: - Assistant
Let me search for this function:
- Assistant
Let me look at this function:
- Assistant
Let me restructure the test to isolate the prop-based case. The current test might pass because App.svelte already credits the methods via
new. Let me create a separate fixture: - Assistant
Let me create a separate fixture where the instance comes ONLY from a prop, not from
new: - Assistant
Let me create the state file:
- Assistant
Let me create the Svelte component that receives the instance as a prop:
- Assistant
Let me create the main.ts and a parent component:
- Assistant
Now let me add a test for this prop-based case:
- Assistant
Now let me run this test to see if it fails (which would reproduce the issue):
- Assistant
I've reproduced the issue. The test fails because when
resultStatecomes from$props()with type annotation{ resultState: ResultState }, the methods are not tracked. Let me understand the root cause by looking at how binding_target_names are populated for destructured typed patterns: - Assistant
Now I've reproduced the issue! The test fails because when
resultStateis a prop (received via$props()with a type annotation), the binding target isn't populated. Let me understand the root cause by looking at how destructured typed bindings are handled: - Assistant
Let me look at
extract_object_pattern_bindings: - Assistant
Now I understand the root cause. The issue is that
record_typed_bindingis only called forBindingIdentifierpatterns (line 1993), not forObjectPattern(destructured) patterns. When a Svelte component receives a prop vialet { resultState }: { resultState: ResultState } = $props(), theObjectPatterndoesn't go throughrecord_typed_binding, soresultState → ResultStateis never added tobinding_target_names.Let me look at the full visitor to understand how to fix this:
- Assistant
Now I understand the root cause. The
record_typed_bindingfunction (line 1993) only handlesBindingIdentifierpatterns, notObjectPattern(destructured) patterns. When a Svelte component receives a prop vialet { resultState }: { resultState: ResultState } = $props(), the destructuredObjectPatterndoesn't go throughrecord_typed_binding, soresultState → ResultStateis never added tobinding_target_names, and the template scanner can't resolve member accesses onresultState.Let me implement the fix:
- Assistant
Let me look at the full
record_typed_bindingandextract_nested_type_bindingsfunctions: - Assistant
Now let me implement the fix. I need to add handling for
ObjectPatternwith type annotations invisit_variable_declaration: - Assistant
Let me now understand the exact code I need to modify. I need to look at how
extract_nested_type_bindingsreturns its results and how to map them to the ObjectPattern's local names: - Assistant
Now I understand the root cause. The
record_typed_bindingfunction only handlesBindingIdentifierpatterns (line 1993). When a Svelte component haslet { resultState }: { resultState: ResultState } = $props(), theObjectPatterndoesn't go throughrecord_typed_binding, soresultState → ResultStateis never added tobinding_target_names. The template scanner then can't resolveresultState.pin(...)toResultState.pin.Let me implement the fix. I need to add handling for
ObjectPatternwith type annotations invisit_variable_declaration: - Assistant
Now let me implement the fix. I need to add handling for
ObjectPatternwith type annotations: - Assistant
Now I need to implement the
record_object_pattern_typed_bindingsmethod. Let me find the right place to add it: - Assistant
Now let me add the
record_object_pattern_typed_bindingsmethod. I'll add it right afterrecord_typed_binding: - Assistant
Now I need to add the
record_object_pattern_typed_bindingsmethod right afterrecord_typed_binding. Let me write it: - Assistant
Now I need to add the
collect_object_pattern_path_localshelper function. Let me add it near the existingcollect_object_pattern_bindings: - Assistant
Let me add the
collect_object_pattern_path_localsfunction after thecollect_object_pattern_bindingsfunction: - Assistant
Let me add the helper function right after the existing
collect_object_pattern_bindings: - Assistant
Now let me apply both changes. First, let me add the helper function:
- Assistant
Let me add the helper function after
collect_object_pattern_bindings: - Assistant
Let me fix the spacing - add a blank line before
resolve_object_to_fixture_path: - Assistant
Good, the helper function is added. Now I need to add the
record_object_pattern_typed_bindingsmethod to theModuleInfoExtractorimpl block. Let me find the right place: - Assistant
Let me look at the code around
record_typed_bindingto find where to add the new method: - Assistant
Now let me add the new method after
record_typed_binding: - Assistant
Good, the method is added. Now I need to add the call in
visit_variable_declarationforObjectPatternwith type annotations. Let me find the current code: - Assistant
Let me look at the context around line 2061 to add the new call:
- Assistant
Now let me add the ObjectPattern handling right after the BindingIdentifier handling:
- Assistant
I see there's a duplicate
}and a duplicatelet Some(init)line. Let me fix this: - Assistant
There's still a duplicate
let Some(init)line. Let me remove it: - Assistant
There's a duplicate line. Let me fix it:
- Assistant
Good, the code looks correct now. Let me verify the changes by looking at the key parts:
- Assistant
The code looks good. Now let me run the failing test to see if the fix works:
- Assistant
The fix works. Let me now run all existing Svelte-related tests to make sure nothing is broken:
- Assistant
All 16 Svelte-related tests pass. Let me run the broader test suite to make sure nothing else is broken:
- Assistant
All 527 integration tests pass. Let me also run the extract crate tests:
- Assistant
All 1638 extract tests pass. Let me also run the full workspace tests:
- Assistant
The failure is
fix_batch_aborts_when_a_target_directory_is_read_onlywhich seems to be a pre-existing file system permission issue. Let me verify it's not related to my changes: - Assistant
Let me verify the CLI test failure is pre-existing by checking if it fails without my changes:
- Assistant
The CLI test failure is pre-existing (likely running as root in the container, where read-only permissions don't apply). Let me verify by checking git status to confirm my changes:
- Assistant
Let me clean up the test fixtures and tests I initially created that just test the basic
newcase (which already works): - Assistant
Let me also clean up the redundant tests from sfc_parsing.rs. Let me review what tests I added:
- Assistant
Let me view the test content to understand what to keep and what to remove:
- Assistant
I need to remove the first three tests that reference the now-deleted fixture. Let me replace them with just the prop-based test:
- Assistant
Let me remove the first three tests that reference the deleted fixture and keep only the prop-based test:
- Assistant
There's a duplicate test. Let me remove the duplicate:
- Assistant
Good, the file looks clean now. Let me run the tests again to make sure everything works:
- Assistant
Let me run all the integration tests to make sure nothing is broken:
- Assistant
All 524 integration tests pass. Let me also run the extract crate tests to make sure:
- Assistant
All 1638 extract tests pass. Let me verify the final state of changes:
- Assistant
Let me check the full status to see all changes:
- Assistant
Let me view the final diff to make sure everything is correct:
- Assistant
Let me also check the test file diff:
- Assistant
Let me check the test fixture files:
- Assistant
Let me run all the tests one final time to make sure everything passes:
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 →