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 understand the issue. There's a linting tool called "Fallow" that has a rule called
unused-class-members. The issue is about false positives when class methods are called from Svelte templates via member expressions (e.g.,resultState.pin(...)in markup).Let me first explore the repository structure to understand the codebase.
- Assistant
Let me look at the Rust crates structure since this seems to be a Rust project.
- Assistant
Let me look for files related to the unused-class-members rule.
- Assistant
Let me look at the main files related to this issue:
- Assistant
Let me continue reading the unused_members.rs file:
- Assistant
Let me search for template-related patterns in the unused_members.rs file:
- Assistant
Let me look at the Angular template handling to understand the pattern:
- Assistant
Let me look at the SFC template extraction for Svelte:
- Assistant
Let me look at the Svelte template extraction:
- Assistant
Let me look at how member accesses are tracked in templates:
- Assistant
Let me look at the TemplateUsage struct and how member accesses are collected:
- Assistant
Let me look at the TemplateUsage struct:
- Assistant
Now let me look at how the template usage data flows to the unused members analysis. Let me check the SFC template module:
- Assistant
Now let me look at how SFC template usage flows into the unused members analysis:
- Assistant
No results. Let me check how Angular template usage is tracked:
- Assistant
Let me look at how member accesses from templates flow into the unused members analysis:
- Assistant
Let me look at how member accesses are processed:
- Assistant
Let me look at the section that processes main member accesses:
- Assistant
Let me look at how the main member accesses are collected:
- Assistant
Let me look at the main entry point:
- Assistant
Let me look at the
find_unused_membersfunction: - Assistant
Let me look at how Angular template member accesses are handled:
- Assistant
Let me look at the SFC extraction to understand how template usage flows into the module info:
- Assistant
Let me look at how the SFC pipeline builds the ModuleInfo for Svelte files:
- Assistant
Let me look at the
apply_template_usagefunction: - Assistant
Let me look at how bound_targets are collected in the SFC extraction:
- Assistant
Let me look at how
binding_target_namesworks: - Assistant
Let me look at the
resolve_bound_member_accessesmethod: - Assistant
Let me look at how
build_local_to_export_keysworks: - Assistant
Let me look at this function:
- Assistant
Let me check how the SFC file's ModuleInfo is used in the graph:
- Assistant
Let me look at how the SFC ModuleInfo is fed into the graph. Let me check the extract pipeline:
- Assistant
Let me look at how the graph builds resolved modules from ModuleInfo:
- Assistant
Let me look at the ResolvedModule struct:
- Assistant
Let me look for existing test fixtures related to Svelte templates and unused class members:
- Assistant
Let me look at the test
svelte_template_event_handlers_mark_class_members_used: - Assistant
Let me look at the test fixture:
- Assistant
Let me find the fixture path:
- Assistant
Let me find where
fixture_pathis defined: - Assistant
Let me look at this function:
- Assistant
Let me find the svelte-project fixture:
- Assistant
Let me look at the fixture files:
- Assistant
Let me look at the App.svelte file:
- Assistant
Let me look at the Counter class in utils.ts:
- Assistant
Let me understand the issue better. Let me look at the test that already passes and compare with the failing scenario:
- Assistant
Let me look at how bound_targets are collected:
- Assistant
Let me look at the false_positive_fixes.rs test file:
- Assistant
Let me look at the member_detection.rs test file:
- Assistant
Let me look at the angular_template_members test:
- Assistant
Let me try to reproduce the issue by creating a test case. First, let me understand what the issue scenario might look like:
- Assistant
Let me run the existing test to verify it passes:
- Assistant
The existing test passes. Now let me think about what the issue scenario might be. Let me check if there's a difference when the class is defined in the same file:
- Assistant
Let me look at how the visitor populates
binding_target_namesfor class instantiation: - Assistant
Let me look at how
const x = new ClassName()is handled: - Assistant
Let me look at how
const x = new ClassName()is handled: - Assistant
Let me check if
letdeclarations are handled differently fromconstin binding target names: - Assistant
Let me look at the visit_variable_declaration function:
- Assistant
Let me look at the
propagate_accesses_through_typed_instance_bindingsfunction: - Assistant
Let me look at the
build_typed_instance_binding_targetsfunction: - Assistant
Let me look at this function:
- Assistant
Let me check if
resolve_bound_member_accessesruns during SFC extraction: - Assistant
Let me look at the
merge_intofunction: - Assistant
Let me look at the
merge_intofunction: - Assistant
Let me look at the
resolve_bound_member_accessesfunction: - Assistant
Let me check if the issue is about the class being defined in the same file. Let me create a test case:
- Assistant
Let me check how SFC exports are handled:
- Assistant
Let me look at the
merge_script_into_modulefunction: - Assistant
Let me look at how the ModuleInfoExtractor extracts member accesses:
- Assistant
Let me look at the
visit_static_member_expressionfunction: - Assistant
Let me look at the second
visit_static_member_expression: - Assistant
Let me look at the main loop in
find_unused_membersthat processes member accesses: - Assistant
Let me look at how class_heritage is populated for Svelte files:
- Assistant
Let me look at
record_exported_instance_bindings: - Assistant
Let me look at
propagate_accesses_through_instance_exports: - Assistant
Let me look at this function:
- Assistant
Let me look at how Vue handles template member accesses:
- Assistant
Let me look at the
analyze_template_snippet_with_bound_targetsfunction more carefully: - Assistant
Let me continue reading:
- Assistant
Let me check if the visitor handles separate assignments:
- Assistant
Let me look at the
visit_assignment_expressionfunction: - Assistant
Let me try to create a concrete test case to reproduce the issue. Let me first understand what the issue scenario looks like:
- Assistant
Let me create a test fixture to reproduce the issue:
- Assistant
Let me run the analysis on this fixture to see if the issue is reproduced:
- Assistant
Let me write a small script to test my custom fixture:
- Assistant
Let me run the CLI on my test fixture:
- Assistant
The basic case works! Let me try more complex scenarios that might reproduce the issue:
- Assistant
Let me try another scenario - using
letinstead ofconst: - Assistant
Good, that also works. Let me try more scenarios. Let me try when the instance is created through a function call or store:
- Assistant
Let me try a scenario where the class instance is created via a different pattern:
- Assistant
Found a scenario that fails! Let me investigate further. The reactive assignment
$: state = resultState;causes the issue becausestateis not inbound_targets. Let me try more scenarios: - Assistant
This is a key finding! The
$state(new ResultState())pattern fails! Let me check how the visitor handles wrapped new expressions: - Assistant
Let me look at this function:
- Assistant
Let me look at how the Svelte template scanner handles expressions:
- Assistant
Let me look at these functions:
- Assistant
Let me look at the
merge_snippet_usage_with_bound_targetsfunction: - Assistant
Let me check if the visitor handles
$statecalls: - Assistant
Let me try a scenario with Svelte's
bind:this: - Assistant
Now let me try with
$state()wrapping: - Assistant
I've reproduced the issue. The
$state(new ResultState())pattern causes all methods to be reported as unused because the visitor doesn't recognize$state(new ClassName())as creating aClassNameinstance.Let me now look at the visitor code to understand where to add the fix:
- Assistant
Now let me look at the helpers to see if there's a function to extract new class from call arguments:
- Assistant
Now I understand the issue. The
$state(new ClassName())pattern isn't recognized by the visitor. Let me also check what other similar patterns might exist. Let me look at the issue description again more carefully: - Assistant
Interesting! The aliasing case also fails. Let me try more:
- Assistant
OK, now I understand the issue better. Let me check if the
$state()wrapper is specifically what causes the problem, or if there's a more general issue. Let me look at how Angular handles chain accesses via instance_bindings: - Assistant
Let me test a type-annotated declaration pattern:
- Assistant
Good, the type-annotated case works. Let me test the
$state()case more carefully with various Svelte 5 patterns: - Assistant
Good, the basic
const resultState = new ResultState()pattern works perfectly. Now let me test the$state()wrapping case which is the most likely Svelte 5 scenario: - Assistant
I see that
$state(),$derived(), and aliasing all cause issues. The core problem is that the visitor doesn't detectlet x = $state(new ClassName())as creating a binding target. Let me look at the visitor code to understand where to add the fix: - Assistant
Now I understand the issue. The visitor handles
const x = new ClassName()but notlet x = $state(new ClassName()). I need to add support for wrapper calls that contain aNewExpression. Let me also check how the helpers work: - Assistant
Now I need to add a helper function to extract a class name from a direct
new ClassName()argument in a call expression. Let me implement the fix: - Assistant
Let me add a new helper function
try_extract_direct_new_classthat extracts a class name from a directnew ClassName()argument. I'll add it after the existingtry_extract_factory_new_classfunction. - Assistant
Now let me add the new helper function. I'll add it after
try_extract_factory_new_class: - Assistant
Now I need to add the helper function. Let me add it after line 1114 (the closing brace of
try_extract_factory_new_class). - Assistant
Now let me add the new helper function:
- Assistant
Now I need to add the pattern in
visit_impl.rsthat uses this new helper function. Let me add it after the existing factory pattern: - Assistant
Now let me add the new pattern for
let x = wrapper(new ClassName()): - Assistant
Now let me verify the code compiles and test it:
- Assistant
Let me test it with the
$state()case: - Assistant
The
$state()case now works. Let me also test the other scenarios: - Assistant
Let me fix the test:
- Assistant
The
$state.raw()case also works. Now let me run the existing tests to make sure I didn't break anything: - Assistant
Let me run the integration tests for fallow-core:
- Assistant
One test failed. Let me look at this test to understand what's happening:
- Assistant
Let me look at this test:
- Assistant
Let me look at the fixture to understand the failing test:
- Assistant
Let me look at the fixture files:
- Assistant
I see the issue. My new pattern is too aggressive - it matches
Promise.resolve(new Aggregate())which should NOT create a binding. I need to restrict it to only match simple identifier calls (like$state(...)) and not member expression calls (likePromise.resolve(...)): - Assistant
I need to restrict the pattern to only match simple identifier calls (not member expression calls like
Promise.resolve()): - Assistant
Now let me rebuild and test:
- Assistant
Let me run the failing test:
- Assistant
The test passes now. Let me run all integration tests:
- Assistant
All 523 tests pass. Let me also run the extract crate tests:
- Assistant
All 1638 tests pass. Now let me verify my fix works with the CLI on all the test scenarios:
- Assistant
Let me also test with
const: - Assistant
Let me also test the original basic case to make sure it still works:
- Assistant
Let me also run the specific Svelte template test:
- Assistant
Let me now run the full test suite across all crates to make sure nothing is broken:
- Assistant
Let me check if this test failure is related to my changes:
- Assistant
The CLI fix test failure is unrelated to my changes (it's about filesystem permissions). Let me verify the extract tests still pass:
- Assistant
Let me run the graph crate tests too:
- Assistant
Let me verify the
$state.raw()case more carefully: - Assistant
I see,
$state.raw()is failing because it's a member expression call. Let me extend the pattern to also handle Svelte rune member expressions: - Assistant
I need to extend the pattern to also handle Svelte rune member expressions like
$state.raw(new ClassName()). Let me update the pattern: - Assistant
Now I need to add the
is_reactive_wrapper_calleehelper function. Let me find where to add it: - Assistant
Let me add the helper function near the other helper functions at the bottom of the file:
- Assistant
Let me add the helper function before
static_argument_object_name: - Assistant
Now let me rebuild and test:
- Assistant
Let me test the
$state.raw()case: - Assistant
Hmm,
$state.raw()is still failing. Let me check why. Theis_reactive_wrapper_calleefunction should match$state.rawas aStaticMemberExpressionwhose object isIdentifier("$state"). Let me check if the function is being called correctly.Actually, wait.
$state.rawis a member expression, but$statestarts with$. Soid.name.starts_with('$')should be true. Let me check...Actually, I think the issue might be that
$stateis treated as a Svelte compiler transform and might not be parsed as a regular identifier by oxc. Let me check...Actually, oxc should parse
$state.raw(new ResultState())as a regular call expression with a static member expression callee. The$stateidentifier is a valid JavaScript identifier.Let me add some debug output to see what's happening:
- Assistant
Let me add a debug test to see what's happening:
- Assistant
Let me investigate why
$state.raw()is failing. Let me check if there's acontinuestatement: - Assistant
Let me check if the SFC extraction even runs on my test fixture. Let me look at what happens during the extraction:
- Assistant
Let me run a quick test to see if the pattern is being reached:
- Assistant
Let me write a quick test to debug the $state.raw case:
- Assistant
Let me write a unit test to debug the $state.raw case:
- Assistant
Let me add a quick debug test to check if the
$state.rawcase is handled: - Assistant
Let me investigate why $state.raw still fails. Let me add a more targeted test:
- Assistant
OK, with a type annotation it works. The issue is that
$state.raw(new ResultState())alone (without type annotation) is not creating a binding target. Let me investigate why. Let me check if the$state.rawpattern is actually reaching my new code: - Assistant
Let me re-check the $state.raw(new ResultState()) case to make sure my fix is actually being used:
- Assistant
Wait, the debug build works! Let me rebuild the release binary and test again:
- Assistant
Now let me run all the tests to make sure everything works:
- Assistant
All 523 tests pass. Let me run the extract tests too:
- Assistant
All 1638 extract tests pass. Let me now do a comprehensive test of all the scenarios:
- Assistant
Let me check test 4 more carefully:
- Assistant
Let me also test that
Promise.resolve()doesn't create a false positive: - Assistant
All scenarios work correctly.
Promise.resolve()correctly doesn't create a binding target. Let me run the full test suite one more time: - Assistant
All tests pass. Let me now review all the changes I've made:
- Assistant
Let me add a blank line after the new function in helpers.rs:
- Assistant
I need to add a blank line after the
try_extract_direct_new_classfunction: - Assistant
Let me run the full test suite one final time to make sure everything is clean:
- Assistant
Let me run the extract tests separately:
- Assistant
All 1638 extract tests pass. Let me clean up and review the final changes:
- Assistant
The changes look clean. Let me clean up the temporary test directory:
- Assistant
Now let me run the final comprehensive test to make sure everything works:
- Assistant
Let me verify all test suites pass:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.