angularjs-component-complexity
Read-only mining codemod that computes a weighted migration-complexity score for every
AngularJS .component() and .directive() registration in a file. No files are written to the
target repo.
How the score is computed
| Signal | Weight |
|---|---|
| Each binding / isolate-scope property | +1 |
| Isolate scope present (bindings object at all) | +1 |
Has link | +5 |
Has compile | +8 |
Template complexity proxy (template length / templateUrl) | +1 to +3 |
Each $watch / $watchGroup / $watchCollection call | +2 |
$scope reference count (capped at 6) | +1 each |
DOM / $compile / jQuery usage | +4 each |
Service DI count (controller or directive factory params, excluding $scope/$element/$attrs/$transclude) | +1 each |
For directives, the analysis runs over the whole factory function (the function passed to
.directive(name, factory)), since link/compile closures are typically returned from inside
it. For components, it runs over the resolved controller function (inline, a named
controller: X reference, or a controller registered elsewhere via .controller('X', ...)).
The total score maps to a complexity_band:
| Score | Band | Risk | Automation | Effort | Phase |
|---|---|---|---|---|---|
| ≤3 | trivial | low | full | 1 | phase-3 |
| ≤9 | low | low | full | 2 | phase-3 |
| ≤18 | medium | medium | partial | 3 | phase-3 |
| ≤30 | high | high | partial | 8 | phase-4 |
| >30 | rewrite | critical | manual | 13 | phase-4 |
Metrics
| Metric | Cardinalities |
|---|---|
component_complexity_score | component_or_directive_name, kind, score, complexity_band, score_breakdown, file, line, snippet, migration_category, risk, automation, effort_points, recommended_phase |
score_breakdown is a short key=value,... string (e.g.
bindings=2,isolateScope=true,link=false,compile=false,template=3,watch=1,scopeRefs=5,dom=0,di=3)
so you can see which signals drove the score without re-parsing the file.
Limitations
- File-local: controller/directive-factory resolution only looks within the same file. A
controller: 'NamedCtrl'string that resolves to a controller registered in a different file
will not be found, and DI/$watch/DOM usage inside it will not be counted. templateUrlcomplexity is a fixed proxy score (the referenced template file's contents are
not read), since this is a single-file AST miner.- Weights are heuristic and tuned for relative ranking (trivial vs. rewrite), not an exact
time/cost estimate.
Run
bash
Testing
bash
Development
bash
License
MIT