Aalexbit-codemod

angularjs-component-complexity

Mine weighted AngularJS component complexity scores; read-only metrics

miningmetricsangularjscode-miningmigration-assessmentcomponent_complexity_score
PRO
0 executions
Use dashboard

Run locally

npx codemod angularjs-component-complexity

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-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

SignalWeight
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:

ScoreBandRiskAutomationEffortPhase
≤3triviallowfull1phase-3
≤9lowlowfull2phase-3
≤18mediummediumpartial3phase-3
≤30highhighpartial8phase-4
>30rewritecriticalmanual13phase-4

Metrics

MetricCardinalities
component_complexity_scorecomponent_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.
  • templateUrl complexity 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

Ready to contribute?

Build your own codemod and share it with the community.