Aalexbit-codemod

angularjs-directive-inventory

Mine AngularJS directives (link, compile, transclusion, isolate scope); read-only metrics

miningmetricsangularjscode-miningmigration-assessmentangularjs_directive
PRO
0 executions
Use dashboard

Run locally

npx codemod angularjs-directive-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-directive-inventory

Read-only mining codemod that inventories AngularJS .directive('name', ...) registrations for Angular migration assessment. No files are written to the target repo; findings are emitted as metrics only.

What it does

Finds every .directive('name', factory) call (including the dependency-injection array form, ['$dep', function($dep) {...}]) and inspects the directive-definition object (DDO) returned by the factory to classify:

FeatureCardinalityDetected from
link functionhas_linkDDO has a link property
compile functionhas_compileDDO has a compile property
Transclusionhas_transcludeDDO has a transclude property with a truthy value (not false)
Isolate scopehas_isolate_scopeDDO's scope property is an object literal (e.g. scope: {})
Restrict moderestrictDDO's restrict string ('E', 'A', 'EA', ...); empty if unspecified

Risk classification

Each directive is assigned exactly one risk level, from highest to lowest precedence:

ConditionRiskAutomationEffort pointsRecommended phase
Uses compilecriticalmanual13phase-5
Uses link and/or transcludehighpartial8phase-4
Isolate scope onlymediumpartial5phase-3
None of the abovelowfull2phase-2

Metrics

MetricCardinalities
angularjs_directivefile, line, snippet, directive_name, has_link, has_compile, has_transclude, has_isolate_scope, restrict, migration_category (directive), risk, automation, effort_points, recommended_phase

Known limitations

  • Only directives registered with a literal string name are inventoried; dynamic names (e.g. .directive(variable, ...)) 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 (e.g. .directive('foo', fooFactory) where fooFactory is declared elsewhere) fall back to a best-effort scan for directive-like keys within the reachable subtree, and may under-report if not visible.

Run

bash

Testing

bash

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.