Registry
Aalexbit-codemod avatar

angularjs-scope-coupling

Mine AngularJS $scope/$rootScope coupling, watchers, events, broadcasts; read-only metrics

alexbit-codemod0 executions

  • mining
  • metrics
  • angularjs
  • code-mining
  • migration-assessment
  • scope_coupling

angularjs-scope-coupling

Read-only mining codemod that scans AngularJS JavaScript source for $scope/$rootScope
coupling and emits a scope_coupling metric for migration assessment. It never modifies
files โ€” every match is reported via codemod:metrics and the transform always returns null.

What it detects

  • Bare $scope / $rootScope references (DI parameters, arguments, generic property access)
  • $watch, $watchCollection, $watchGroup
  • $on, $broadcast, $emit โ€” flagged high risk when bound to $rootScope (global event
    bus coupling), medium risk on plain $scope
  • $apply, $applyAsync, $digest, $evalAsync โ€” safe to drop under Angular's zone-based
    change detection, so these are fully automatable

Metric cardinality

Each finding increments scope_coupling with:

ts
{
  file: "app/invoices/invoice.controller.js",
  line: "14",
  snippet: "$rootScope.$broadcast",
  pattern_kind: "$scope" | "$rootScope" | "$watch" | "$watchCollection" | "$watchGroup" | "$on" | "$broadcast" | "$emit" | "$apply" | "$applyAsync" | "$digest" | "$evalAsync",
  migration_category: "scope",
  risk: "low" | "medium" | "high",
  automation: "full" | "partial" | "manual",
  effort_points: "1" | "2" | "3" | "5" | "8",
  recommended_phase: "phase-2" | "phase-3",
}

Installation

bash
# Install from registry
codemod run angularjs-scope-coupling

# Or run locally
codemod run -w workflow.yaml

Development

bash
# Test the transformation
pnpm test

# Validate the workflow
codemod workflow validate -w workflow.yaml

# Publish to registry
codemod login
codemod publish

License

MIT

Ready to evolve your codebase?

Build tailored, compiler-aware skills to assess, plan, and automate complex codebase changes.