Registry
Aalexbit-codemod avatar

angularjs-component-complexity

Mine weighted AngularJS component complexity scores; read-only metrics

alexbit-codemod0 executions

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

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
npx codemod@latest workflow run -w codemods/angularjs-to-angular/angularjs-component-complexity \
  -t /path/to/angularjs/repo \
  --allow-dirty --no-interactive

Testing

bash
pnpm test

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.