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:
| Cardinality | Detected from |
|---|---|
uses_scope | $scope appears anywhere in the controller factory (as a DI parameter, array-DI dependency, or body reference) |
controller_as | The 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_scope | controller_as | Risk | Automation | Effort points | Recommended phase |
|---|---|---|---|---|---|
true | false | high | partial | 8 | phase-4 |
true | true | medium | partial | 5 | phase-3 |
false | false | medium | partial | 5 | phase-3 |
false | true | low | full | 2 | phase-2 |
Metrics
| Metric | Cardinalities |
|---|---|
angularjs_controller | file, 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 touses_scope: false/controller_as: falseunless 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 withuses_scope: false(unknown, since the factory body isn't visible in this file).
Run
bash
Testing
bash
License
MIT