Skip to content

feat(compiler-cli): add unusedAnimations extended diagnostic - #72359

Draft
JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:feat/unused-animations-diagnostic
Draft

JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:feat/unused-animations-diagnostic

Conversation

@JeanMeche

Copy link
Copy Markdown
Member

Summary

Adds a new extended diagnostic unusedAnimations (NG8120) that warns when legacy animation triggers declared in @Component.animations are never referenced in the component's template or host bindings.

Key details

  • No ts.TypeChecker required (NGP-compatible): Follows the same architecture as unusedStandaloneImports (NG8113) — implemented as a SourceFileValidatorRule in ngtsc and as checkUnusedAnimations in the ngp preprocessor backed by ng-analyze (oxc_semantic).
  • Template & host binding awareness: Recognizes static attributes (@trigger), bound attributes ([@trigger]=...), animation event listeners ((@trigger.start) / (@trigger.done)), control flow / <ng-template> blocks, and host bindings/listeners (host: { '[@trigger]': ..., '(@trigger.start)': ... }, @HostBinding('@trigger'), @HostListener('@trigger.done')).
  • Diagnostic anchoring:
    • When all statically-declared animations are unused (and no dynamic animations are present), reports All animations are unused on the animations property key.
    • Otherwise reports Animation trigger '<name>' is not used within the template of <Component> on each unused trigger expression or local constant reference.
  • Avoids false positives: Skips triggers originating from shared (exported or imported) animations arrays and handles dynamic animations conservatively.
  • Configurable: Controlled via angularCompilerOptions.extendedDiagnostics.checks.unusedAnimations ('warning' | 'error' | 'suppress').

Test plan

  • bazel test //packages/compiler-cli/test/ngtsc:ngtsc
  • bazel test //packages/compiler-cli/test/ngtsc:ngtsc_ngp
  • bazel test //packages/compiler-cli/preprocessor/test:test
  • bazel test //packages/compiler-cli/preprocessor/ng-analyze:all
  • bazel test //packages/compiler-cli:all //packages/compiler/test/typecheck:all

@angular-robot angular-robot Bot added detected: feature PR contains a feature commit area: compiler Issues related to `ngc`, Angular's template compiler labels Dec 5, 2026
@ngbot ngbot Bot added this to the Backlog milestone Dec 5, 2026
@JeanMeche
JeanMeche force-pushed the feat/unused-animations-diagnostic branch 2 times, most recently from 9b47178 to 9efffc9 Compare December 5, 2026 17:55
Adds a new extended diagnostic `unusedAnimations` (NG8120) that detects legacy animation triggers declared in `@Component.animations` that are never referenced in the component's template or host bindings.

The check does not depend on `ts.TypeChecker` and is implemented with full parity in both `ngtsc` (via `UnusedAnimationsRule`) and the `ngp` preprocessor (via `ng-analyze` and `checkUnusedAnimations`).
@JeanMeche
JeanMeche force-pushed the feat/unused-animations-diagnostic branch from 9efffc9 to 1d61cde Compare December 5, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: compiler Issues related to `ngc`, Angular's template compiler detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant