ISSUE DESCRIPTION service member referenced in an Angular external template is reported…
- User
ISSUE DESCRIPTION
service member referenced in an Angular external template is reported as unused when the component property is initialized with
inject()(no explicit type annotation)What happened?
With the
angularplugin active,fallow dead-codereports a service method as an unused class member when its only reference is in an Angular HTML template (prop.method()), and the component propertypropis initialized with the moderninject()pattern without an explicit type annotation:readonly exampleService = inject(ExampleService);Fallow already credits template references through component properties for the other three DI/instance patterns — it is specifically the untyped
inject()initializer that is missed. The following all resolve correctly (no false positive); only the last one fails:Component property pattern Template prop.method()resolved?constructor(public svc: ExampleService) {}✅ yes svc: ExampleService = inject(ExampleService);(typed)✅ yes svc = new ExampleService();✅ yes svc = inject(ExampleService);(untyped)❌ no — false positive Because untyped
inject()is the idiomatic Angular style, this misfires on a very common real-world pattern.Reproduction
Minimal standalone repro.
@angular/coreonly needs to be listed inpackage.jsonso theangularplugin auto-activates — runningnpm installis optional (without it, fallow prints a "node_modules directory not found" warning but the finding still reproduces).-
Create
package.json:{ "name": "fallow-angular-template-repro", "version": "1.0.0", "private": true, "dependencies": { "@angular/core": "^20.0.0" } } -
Create
.fallowrc.json:{ "entry": ["src/main.ts"] } -
Create
src/main.ts:import { ExampleComponent } from './example.component'; console.log(ExampleComponent);
-
Assistant
Let me explore the repository structure to understand what we're working with.
Assistant
This is a Rust project. Let me explore the crate structure.
Assistant
The
inject()handling isn't in the plugin itself. Let me search where the component property → service-type binding happens.Assistant
Let me look at where the angular template member resolution happens. Let me search for the relevant code that resolves component properties to types.
Assistant
The key is
instance_bindings. Let me find where it's populated.Assistant
Now I understand the issue. The
PropertyDefinitionhandling only resolves type annotations andNewExpressioninitializers. It doesn't handleinject(ExampleService)calls. Let me look at the AST structure forCallExpression.Assistant
Now let me understand the
inject()pattern. In Angular,inject(Token)returns an instance ofToken. The first argument is the token, which is typically anIdentifierreferencing the service class. We want to extract that as the type name.Let me look at how the
CallExpressionarguments are structured. Let me write the fix. I'll modify thePropertyDefinitionhandling to detectinject(...)call expressions.But I should be careful —
inject()can be called with various forms. The most common isinject(ExampleService). There's alsoinject(TOKEN)where TOKEN is an InjectionToken. But for our purposes, we only need to handle theIdentifierargument case which references a class.Let me also consider: should I limit this to the
injectfunction specifically, or should I handle any call expression? Looking at the issue, the problem is specifically withinject(). But to be safe and general, I should handle theinject()call specifically (the callee identifier should beinject). Actually, let me think about whether there are other DI patterns. There's from . There could be etc. But let's keep it focused on .Assistant
Now I understand the patterns. Let me check
is_builtin_constructorand theArgumentenum.Assistant
Now let me modify the
extract_class_instance_bindingsfunction to handleinject()calls. Let me look at the exact lines again:Assistant
Now I'll add handling for
inject()calls. Let me edit the code:Assistant
Let me verify the change compiles and check the other usage of
instance_bindings(propagate_accesses_through_typed_instance_bindings):Assistant
Let me build to verify compilation:
Assistant
Compiles. Now let me build the CLI and reproduce the issue.
Assistant
The fix works — "No issues found". Let me verify the original behavior (without the fix) to confirm I've actually fixed the issue. Let me stash the change temporarily:
Assistant
Hmm, even without the fix it shows "No issues found". The angular plugin may not be activating without node_modules. Let me investigate.
Assistant
The enabler is
@angular/core. Let me check how the plugin enablers work — maybe it needs the dependency to be in the actual dependencies list in node_modules. Since node_modules isn't found, maybe the plugin doesn't activate. But the issue says the finding still reproduces without npm install.Let me check how enablers are checked — does it check package.json or node_modules?
Assistant
Let me look at how the deps are gathered. The
is_enabled_with_depstakesdeps: &[String]. Where do these deps come from? If it's from package.json, then even without node_modules the angular plugin would activate. Let me check where deps come from.Assistant
So
is_enabledusespkg.all_dependency_names()from package.json. So the angular plugin should activate based on package.json deps, not node_modules. So why did the unfixed version show "No issues found"?Wait — let me re-check. The
pkg.all_dependency_names()reads from package.json. Let me check what that returns — maybe it reads dependencies from node_modules? Let me look.Assistant
So the angular plugin should be enabled by package.json. But it requires that the package.json is loaded as the root_pkg. Let me check how root_pkg is determined. It might require node_modules to find the root package.json. Let me check.
Assistant
So root_pkg is loaded from
config.root/package.json. So it should load. The config root is the directory where.fallowrc.jsonis. So root_pkg should have@angular/core. So the plugin should be enabled.So why doesn't the unfixed version flag onValueChange? Let me re-run the unfixed version and look very carefully.
Assistant
So even the unfixed version reports "No issues found" with my repro. The issue doesn't reproduce without node_modules here. Let me investigate why onValueChange isn't flagged. Let me check how the angular plugin handles
@Injectableservices.Assistant
Let me look at where template parsing happens and how
ANGULAR_TPL_SENTINELis set.Assistant
The angular component metadata extraction happens during
visit_class, which runs regardless of whether the angular plugin is active. ThetemplateUrlimport is recorded. Now, where are external HTML templates parsed? Let me search.Assistant
Now let me find where external templates (.html files) are scanned and where
collect_unresolved_refs_and_accessesis called.Assistant
collect_angular_template_refsis called for external templates. Where is the external HTML file actually read and parsed? Let me search for where HTML files are parsed.Assistant
parse_html_to_modulecallscollect_angular_template_refsfor HTML files regardless of plugin. So the template refs ARE collected. So why does the unfixed version report "No issues found"? Let me look at the integration test for angular template members to understand expected behavior.Assistant
There's a fixture
angular-template-inherited-members. Let me look at it.Assistant
This fixture uses constructor injection. Let me check the main.ts and app.component.ts:
Assistant
Let me check how
create_configand the test fixture's config work:Assistant
Let me run the existing angular template test to confirm it passes with my fix:
Assistant
Now let me reproduce the bug. Let me temporarily edit the fixture's
data-view.component.tsto use untypedinject(), then run the test against the UNFIXED code.Assistant
I've reproduced the bug with the unfixed code. Now let me restore the fixture and apply my fix, then verify it passes.
Assistant
Let me verify the fixture is back to the constructor version, then test with the untyped inject version to confirm my fix resolves it:
Assistant
My fix resolves the false positive with untyped
inject(). Now let me restore the fixture to its original constructor version (since I shouldn't modify fixtures/tests):Assistant
Only my helpers.rs change remains. Now let me consider edge cases — particularly whether handling
inject()could cause issues in non-Angular contexts. Let me examinepropagate_accesses_through_typed_instance_bindings:Assistant
Now let me look at the final diff to confirm correctness:
Assistant
Now let me run the related test suites to ensure no regressions. First the extract crate tests (helpers.rs has unit tests):
Assistant
All extract tests pass. Now let me run the broader integration tests related to angular, members, and templates:
Assistant
All 641 integration tests pass. Now let me run the core crate unit tests (unused_members has tests) and the graph tests:
Assistant
All core lib tests pass. Now let me verify the CLI repro from the issue description also works with my fix:
Assistant
Let me verify a genuinely-unused method is still flagged (i.e., my fix doesn't over-credit). Let me add an unused method to the repro service:
Assistant
The genuinely-unused method is still flagged while the template-referenced
onValueChangeis correctly credited. Let me also verify the other control patterns (typed inject, constructor, new) still work with the unused control method:Assistant
All four patterns now behave consistently. Let me clean up the temp repro and run a broader test sweep on affected crates:
Assistant
Let me also run the member_detection integration tests specifically:
Assistant
There's a test
angular_inject_fields_credit_service_member_usage. Let me examine it to ensure my change is consistent with it:Assistant
There's already a test that credits
inner.aaawhereinner = inject(InnerService)viathis.inner.aaa. Let me examine the fixture to understand the existing path:Assistant
Interesting — the existing fixture uses
private readonly inner = inject(InnerService)(PRIVATE) accessed viathis.inner.aaa, and it's credited through a different path (since private properties are skipped inextract_class_instance_bindings). Let me find whereinject()is already handled forthis.fieldaccesses:Assistant
There's already
extract_angular_inject_targetwhich requires theinjectto be imported from@angular/core. Let me look at where it's used (line 1886):Assistant
There's already
extract_angular_inject_target(gated on@angular/core) handling thethis.<name>path. My change toextract_class_instance_bindingsis name-based (not import-gated), like the existingnewhandling there. To avoid changing behavior for non-Angular projects with a differentinjectfunction, let me check whether I can gate it on@angular/core. Let me look at howinstance_bindingsis assembled in the visitor:Assistant
Let me look at
record_exported_instance_bindingsin mod.rs to understand the heritage finalization:Assistant
The existing gated inject handling (
binding_target_names) is a separate path forthis.<name>accesses and does NOT feed intoinstance_bindings(the template chain resolution path) — that's exactly the gap. My fix addsinject()handling toextract_class_instance_bindings, parallel to the existing ungatednewhandling in the same function. Private properties are still skipped before reaching my check, so the existingangular_inject_fields_credit_service_member_usagetest (which uses a private field) is unaffected.Let me verify formatting is clean and run the relevant tests once more:
Assistant
All tests pass. Let me do a final review of the complete diff and confirm no fixtures were modified:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.