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
I’ll first inspect the repository structure, package scripts, and Angular-related implementation/tests. Then I’ll reproduce the reported distinction, trace the property-to-type resolution path, implement the narrowest general fix, and run focused plus broader tests.
- Assistant
The project is Rust-based and the initial search omitted
crates, where the implementation likely lives. I’ll locate plugin modules and their fixtures/snapshots, then inspect the analyzer APIs used for class property initializer inference. - Assistant
A fixture named
angular-inject-class-membersalready targets this area, which should provide the fastest reproduction and indicate expected integration-test wiring. Since ripgrep is unavailable, I’ll usegrep/findto inspect that fixture and all Angular plugin source references. - Assistant
There are two related mechanisms: extraction already understands Angular
inject()for TypeScriptthis.inner.memberaccesses, whileunused_members.rsseparately maps HTML chain accesses through component fields. The bug is likely duplicated inference in the latter. I’ll inspect that mapping, the inherited-template fixture, and extracted class-member metadata to identify the correct source of truth. - Assistant
The HTML propagation consumes
ClassHeritage.instance_bindings; constructor types andnew/typed fields populate it, but apparently Angular call inference does not. I’ll inspect whereinstance_bindingsare constructed and how Angular imports are securely identified (including aliases), so the new case does not accidentally treat unrelatedinjectfunctions as Angular DI. - Assistant
The existing
extract_angular_inject_targetalready performs import-origin validation, but it currently only populates the visitor’s transientbinding_target_namesfor source-code accesses. The staticextract_class_instance_bindingshelper has no import context, so directly expanding it would misclassify same-named non-Angular functions. I’ll inspect both routines and class traversal ordering to decide whether to merge a validated binding into heritage during visitation. - Assistant
Because heritage is created before child property visits in export handlers, simply relying on
visit_property_definitionis too late unless heritage is updated there. A cleaner design is to make instance-binding extraction context-aware through an extractor method that starts with generic bindings and adds only validated Angularinject()fields, then use it at all three class-recording sites (local class, named export, default export). I’ll verify import records are available before export visitation and examine alias support inis_named_import_from. - Assistant
Imports are recorded in source order, and normal modules place imports before classes;
is_named_import_fromsupports local aliases by matchingImportInfo. However, ECMAScript permits imports after declarations, so a context method evaluated immediately during class visitation could miss valid late imports. The parser already performs post-walk finalization; I’ll inspect that lifecycle and local/export heritage synchronization to choose a robust two-pass approach or determine whether source-order dependence is an accepted convention. - Assistant
I’ll reproduce the issue before editing using a temporary fixture outside the repository (so no tests are modified). I’ll build/run the workspace CLI against the exact untyped
inject()pattern and capture the finding. - Assistant
The build reached the CLI crate but it has multiple binaries, so I’ll rerun explicitly with
--bin fallow. - Assistant
This version does not accept
--no-progress; I’ll run the exact supported command. - Assistant
The CLI resolves workspace root from the process working directory rather than the absolute config location, so that run analyzed the repository. I’ll rerun the built binary from the temporary fixture directory to obtain the intended baseline.
- Assistant
The baseline exactly reproduces the false positive. I’ll now add a context-aware class binding method that:
- preserves all existing typed/constructor/
newinference, - only examines untyped, non-private static-name fields,
- accepts
inject(Service)andinject<Service>(token), - validates that the callee is the named
injectimport from@angular/core(including aliases), then route all class export forms through it. This avoids broad name-based inference and duplicate typed bindings.
- preserves all existing typed/constructor/
- Assistant
The edit is structurally correct; the command only failed because
cargo fmt --checkreported formatting changes. I’ll apply formatting, compile, and run the focused extraction and Angular template integration tests. Compilation will also confirm the sibling-module method visibility and AST imports. - Assistant
Focused tests pass. Next I’ll rebuild the CLI and rerun the exact reproduction. I’ll also exercise two safety edges in temporary files: an aliased Angular import should resolve, while a same-named
injectimported from a custom container must remain unresolved and therefore must not incorrectly credit the service member. - Assistant
The aliased case passed and the unrelated function correctly remained flagged, but the unchanged exact fixture reused extraction cache produced by the pre-fix binary. Since changing the source invalidated that cache, this strongly indicates stale cache rather than a logic failure. I’ll restore the exact source, remove the fixture’s cache, and rerun to verify a fresh analysis.
- Assistant
A fresh exact run no longer reports
ExampleService.onValueChange; the only temporary finding is the deliberately added unused control file. I’ll remove that file and confirm a clean exact result, then run the complete extraction test suite plus both relevant core integration groups (angular_template_membersand the existing Angular inject member detection). Finally I’ll inspect formatting, diff, and repository status. - Assistant
All 1,681 extraction tests and focused integration tests pass; formatting and diff validation are clean. The final diff is limited to the two intended source files. I’ll run strict Clippy for the affected crate as the final static check, then review status once more before submitting.
- Assistant
Final checklist review:
- If an error was reported, I successfully reproduced it. I created the exact project in
/tmp, ran the pre-fix CLI from that directory, and observedExampleService.onValueChangereported as the sole unused class member. - If an error was reported, I confirmed the fix resolves it. After rebuilding and clearing the temporary extraction cache, the exact untyped
inject(ExampleService)reproduction reports✓ No issues found. - I thought about edge cases and made sure the fix handles them. The implementation reuses existing type/constructor/
newinference, ignores typed and private fields, supports Angularinjectaliases and generic type arguments, and validates import provenance so a custom same-namedinjectdoes not create false usage. Temporary alias and non-Angular controls behaved correctly. - All 1,681 tests passed, both Angular template integration tests passed, the existing Angular inject integration test passed, and strict Clippy, rustfmt, and diff checks all passed.
- If an error was reported, I successfully reproduced it. I created the exact project in
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.