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:
| Feature | Cardinality | Detected from |
|---|---|---|
link function | has_link | DDO has a link property |
compile function | has_compile | DDO has a compile property |
| Transclusion | has_transclude | DDO has a transclude property with a truthy value (not false) |
| Isolate scope | has_isolate_scope | DDO's scope property is an object literal (e.g. scope: {}) |
| Restrict mode | restrict | DDO's restrict string ('E', 'A', 'EA', ...); empty if unspecified |
Risk classification
Each directive is assigned exactly one risk level, from highest to lowest precedence:
| Condition | Risk | Automation | Effort points | Recommended phase |
|---|---|---|---|---|
Uses compile | critical | manual | 13 | phase-5 |
Uses link and/or transclude | high | partial | 8 | phase-4 |
Isolate scope only | medium | partial | 5 | phase-3 |
| None of the above | low | full | 2 | phase-2 |
Metrics
| Metric | Cardinalities |
|---|---|
angularjs_directive | file, 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)wherefooFactoryis 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