service member referenced in an Angular external template is reported as unused when the…
- User
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:tsreadonly 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:json{ "name": "fallow-angular-template-repro", "version": "1.0.0", "private": true, "dependencies": { "@angular/core": "^20.0.0" } } -
Create
.fallowrc.json:json
-
- Assistant
Investigating how the Angular plugin resolves component properties initialized with
inject()so we can fix the untyped case. - Assistant
Implementing support for untyped
inject()inextract_class_instance_bindings, which currently only handles type annotations andnewexpressions. - Assistant
Adding unit and integration tests:
- Assistant
Both tests passed. Running related tests to check for regressions:
- Assistant
Fixed. The issue was in
extract_class_instance_bindings, which builds the property→type map used to credit service members referenced from Angular external templates.Root cause: That function handled type annotations (
svc: ExampleService = ...), constructor parameter properties, andnewinitializers, but not untypedinject()initializers (readonly exampleService = inject(ExampleService)). The visitor already mappedthis.exampleService.*for in-class member access viabinding_target_names, but external templates rely oninstance_bindings— so only the untypedinject()case failed.Fix:
- Added
extract_inject_call_target()inhelpers.rsto extract the injected type from bothinject(Foo)andinject<Foo>()call shapes. - Extended to record inject-based bindings for Angular-decorated classes (, , , ).
- Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.