Aalexbit-codemod

angularjs-controller-inventory

Mine AngularJS controllers, $scope usage, controller-as patterns; read-only metrics

miningmetricsangularjscode-miningmigration-assessmentangularjs_controller
PRO
0 executions
Use dashboard

Run locally

npx codemod angularjs-controller-inventory

This is a Pro codemod. Preview changes and insights for free, no login or code sharing required. Applying changes and accessing insights requires a paid plan and sign in.Learn more

angularjs-controller-inventory

Read-only mining codemod that inventories AngularJS controllers for Angular migration assessment. No files are written to the target repo; findings are emitted as metrics only.

What it does

Finds every .controller('Name', factory) registration (including the dependency-injection array form) plus "controller-as" usage anywhere else in the file (controller: 'Name as vm', or the split controller: 'Name' + controllerAs: 'vm' pair used by directives, components, and ui-router/ngRoute route definitions). Controllers that are only ever referenced via controller-as syntax (never registered with .controller() in the same file) are still inventoried, since that's a strong migration signal on its own.

For each controller, two signals drive the risk classification:

CardinalityDetected from
uses_scope$scope appears anywhere in the controller factory (as a DI parameter, array-DI dependency, or body reference)
controller_asThe factory binds its public API to this (var vm = this; vm.foo = ... / this.foo = ...), or the controller name is referenced elsewhere in the file via controller-as syntax

Risk classification

$scope-coupled controllers need more manual rework to port to Angular component classes than clean controller-as ones:

uses_scopecontroller_asRiskAutomationEffort pointsRecommended phase
truefalsehighpartial8phase-4
truetruemediumpartial5phase-3
falsefalsemediumpartial5phase-3
falsetruelowfull2phase-2

Metrics

MetricCardinalities
angularjs_controllerfile, line, snippet, controller_name, uses_scope, controller_as, migration_category (controller), risk, automation, effort_points, recommended_phase

Known limitations

  • Only controllers registered with a literal string name are inventoried; dynamic names are skipped since they can't be classified statically.
  • The factory function must be an inline function/arrow function, optionally wrapped in a DI array. Factories referenced only by identifier fall back to uses_scope: false / controller_as: false unless a controller-as reference for that name is found elsewhere in the file.
  • Controller-as references that don't correspond to a .controller() registration in the same file are reported with uses_scope: false (unknown, since the factory body isn't visible in this file).

Run

bash

Testing

bash

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.