@angular-modernizer/plugin-solid 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +835 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/orchestrators/god-switch-transform-orchestrator.d.ts +350 -0
- package/dist/orchestrators/god-switch-transform-orchestrator.d.ts.map +1 -0
- package/dist/orchestrators/god-switch-transform-orchestrator.js +1165 -0
- package/dist/orchestrators/god-switch-transform-orchestrator.js.map +1 -0
- package/dist/orchestrators/service-dip-violation-transform.orchestrator.d.ts +72 -0
- package/dist/orchestrators/service-dip-violation-transform.orchestrator.d.ts.map +1 -0
- package/dist/orchestrators/service-dip-violation-transform.orchestrator.js +243 -0
- package/dist/orchestrators/service-dip-violation-transform.orchestrator.js.map +1 -0
- package/dist/rules/dip-violation.rule.d.ts +54 -0
- package/dist/rules/dip-violation.rule.d.ts.map +1 -0
- package/dist/rules/dip-violation.rule.js +156 -0
- package/dist/rules/dip-violation.rule.js.map +1 -0
- package/dist/rules/god-switch-analysis.rule.d.ts +73 -0
- package/dist/rules/god-switch-analysis.rule.d.ts.map +1 -0
- package/dist/rules/god-switch-analysis.rule.js +174 -0
- package/dist/rules/god-switch-analysis.rule.js.map +1 -0
- package/dist/rules/isp-violation.rule.d.ts +62 -0
- package/dist/rules/isp-violation.rule.d.ts.map +1 -0
- package/dist/rules/isp-violation.rule.js +250 -0
- package/dist/rules/isp-violation.rule.js.map +1 -0
- package/dist/rules/lsp-violation.rule.d.ts +57 -0
- package/dist/rules/lsp-violation.rule.d.ts.map +1 -0
- package/dist/rules/lsp-violation.rule.js +321 -0
- package/dist/rules/lsp-violation.rule.js.map +1 -0
- package/dist/rules/ocp-violation.rule.d.ts +69 -0
- package/dist/rules/ocp-violation.rule.d.ts.map +1 -0
- package/dist/rules/ocp-violation.rule.js +204 -0
- package/dist/rules/ocp-violation.rule.js.map +1 -0
- package/dist/rules/service-dip-violation.analysis.rule.d.ts +85 -0
- package/dist/rules/service-dip-violation.analysis.rule.d.ts.map +1 -0
- package/dist/rules/service-dip-violation.analysis.rule.js +217 -0
- package/dist/rules/service-dip-violation.analysis.rule.js.map +1 -0
- package/dist/rules/srp-violation.rule.d.ts +71 -0
- package/dist/rules/srp-violation.rule.d.ts.map +1 -0
- package/dist/rules/srp-violation.rule.js +307 -0
- package/dist/rules/srp-violation.rule.js.map +1 -0
- package/dist/solid-plugin.d.ts +82 -0
- package/dist/solid-plugin.d.ts.map +1 -0
- package/dist/solid-plugin.js +115 -0
- package/dist/solid-plugin.js.map +1 -0
- package/dist/transform-rules/god-switch-transform.rule.d.ts +128 -0
- package/dist/transform-rules/god-switch-transform.rule.d.ts.map +1 -0
- package/dist/transform-rules/god-switch-transform.rule.js +167 -0
- package/dist/transform-rules/god-switch-transform.rule.js.map +1 -0
- package/dist/transform-rules/service-dip-violation.transform.rule.d.ts +75 -0
- package/dist/transform-rules/service-dip-violation.transform.rule.d.ts.map +1 -0
- package/dist/transform-rules/service-dip-violation.transform.rule.js +115 -0
- package/dist/transform-rules/service-dip-violation.transform.rule.js.map +1 -0
- package/package.json +59 -0
- package/src/index.ts +30 -0
- package/src/orchestrators/god-switch-transform-orchestrator.ts +1562 -0
- package/src/orchestrators/service-dip-violation-transform.orchestrator.ts +331 -0
- package/src/rules/dip-violation.rule.ts +194 -0
- package/src/rules/god-switch-analysis.rule.ts +209 -0
- package/src/rules/isp-violation.rule.ts +315 -0
- package/src/rules/lsp-violation.rule.ts +393 -0
- package/src/rules/ocp-violation.rule.ts +264 -0
- package/src/rules/service-dip-violation.analysis.rule.ts +285 -0
- package/src/rules/srp-violation.rule.ts +366 -0
- package/src/solid-plugin.ts +127 -0
- package/src/transform-rules/god-switch-transform.rule.ts +189 -0
- package/src/transform-rules/service-dip-violation.transform.rule.ts +134 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @angular-modernizer/plugin-solid - God Switch Transform Rule
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GodSwitchTransformRule = void 0;
|
|
7
|
+
const god_switch_transform_orchestrator_js_1 = require("../orchestrators/god-switch-transform-orchestrator.js");
|
|
8
|
+
/**
|
|
9
|
+
* Transform rule that converts large switch statements into maintainable Factory Pattern implementations.
|
|
10
|
+
*
|
|
11
|
+
* **Problem:**
|
|
12
|
+
* Large switch statements (10+ cases) violate SOLID principles:
|
|
13
|
+
* - Open/Closed Principle: Adding new cases requires modifying the switch
|
|
14
|
+
* - Single Responsibility: Switch handles multiple concerns
|
|
15
|
+
* - Difficult to test, maintain, and extend
|
|
16
|
+
*
|
|
17
|
+
* **Solution:**
|
|
18
|
+
* Transforms God Switch into Factory Pattern using Strategy pattern:
|
|
19
|
+
* 1. Extract each case into a separate Strategy class
|
|
20
|
+
* 2. Generate a Factory class to create strategy instances
|
|
21
|
+
* 3. Replace switch statement with factory call
|
|
22
|
+
*
|
|
23
|
+
* **Before:**
|
|
24
|
+
* ```typescript
|
|
25
|
+
* switch (type) {
|
|
26
|
+
* case 'A':
|
|
27
|
+
* return handleA();
|
|
28
|
+
* case 'B':
|
|
29
|
+
* return handleB();
|
|
30
|
+
* // ... 10+ more cases
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* **After:**
|
|
35
|
+
* ```typescript
|
|
36
|
+
* interface TypeStrategy {
|
|
37
|
+
* execute(): Result;
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* class AStrategy implements TypeStrategy {
|
|
41
|
+
* execute(): Result { return handleA(); }
|
|
42
|
+
* }
|
|
43
|
+
*
|
|
44
|
+
* class TypeFactory {
|
|
45
|
+
* createStrategy(type: string): TypeStrategy {
|
|
46
|
+
* const strategies = { A: AStrategy, B: BStrategy, ... };
|
|
47
|
+
* return new strategies[type]();
|
|
48
|
+
* }
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* const strategy = factory.createStrategy(type);
|
|
52
|
+
* return strategy.execute();
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* **Configuration:**
|
|
56
|
+
* ```json
|
|
57
|
+
* {
|
|
58
|
+
* "transformationType": "god-switch-transform",
|
|
59
|
+
* "godSwitch": {
|
|
60
|
+
* "minCaseCount": 10,
|
|
61
|
+
* "generateInterfaces": true,
|
|
62
|
+
* "generateFactory": true,
|
|
63
|
+
* "strategyNamingPattern": "{CaseValue}Strategy",
|
|
64
|
+
* "factoryNamingPattern": "{SwitchExpression}Factory"
|
|
65
|
+
* }
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @see GodSwitchTransformOrchestrator for detailed transformation logic
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* // Transformation triggered via MCP tool or programmatic API
|
|
73
|
+
* const rule = new GodSwitchTransformRule();
|
|
74
|
+
* const result = await rule.transform(context);
|
|
75
|
+
*
|
|
76
|
+
* if (result.modified) {
|
|
77
|
+
* console.info('Successfully transformed God Switch to Factory Pattern');
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
class GodSwitchTransformRule {
|
|
82
|
+
/**
|
|
83
|
+
* Unique identifier following plugin-name:rule-name convention.
|
|
84
|
+
*/
|
|
85
|
+
id = 'solid:god-switch-transform';
|
|
86
|
+
/**
|
|
87
|
+
* Human-readable name for the transformation.
|
|
88
|
+
*/
|
|
89
|
+
name = 'God Switch to Factory Pattern';
|
|
90
|
+
/**
|
|
91
|
+
* Detailed description of the transformation's purpose and behavior.
|
|
92
|
+
*/
|
|
93
|
+
description = 'Transforms large switch statements into maintainable Factory Pattern implementations using the Strategy pattern';
|
|
94
|
+
/**
|
|
95
|
+
* Category indicating this is a code restructuring transformation.
|
|
96
|
+
*/
|
|
97
|
+
category = 'refactoring';
|
|
98
|
+
/**
|
|
99
|
+
* Tags for discoverability and filtering.
|
|
100
|
+
*/
|
|
101
|
+
tags = [
|
|
102
|
+
'solid',
|
|
103
|
+
'god-switch',
|
|
104
|
+
'factory-pattern',
|
|
105
|
+
'strategy-pattern',
|
|
106
|
+
'refactoring',
|
|
107
|
+
'maintainability',
|
|
108
|
+
];
|
|
109
|
+
/**
|
|
110
|
+
* Orchestrator instance that performs the actual transformation logic.
|
|
111
|
+
* Following the "Thin Rule, Thick Orchestrator" pattern.
|
|
112
|
+
*/
|
|
113
|
+
orchestrator = new god_switch_transform_orchestrator_js_1.GodSwitchTransformOrchestrator();
|
|
114
|
+
/**
|
|
115
|
+
* Transforms God Switch violations into Factory Pattern implementations.
|
|
116
|
+
*
|
|
117
|
+
* **Process:**
|
|
118
|
+
* 1. Validates transformation type from configuration
|
|
119
|
+
* 2. Captures initial source file state
|
|
120
|
+
* 3. Delegates to orchestrator for transformation
|
|
121
|
+
* 4. Detects modifications by comparing file state
|
|
122
|
+
* 5. Returns structured result with modification status
|
|
123
|
+
*
|
|
124
|
+
* **Idempotency:**
|
|
125
|
+
* Running multiple times on the same file is safe - the orchestrator
|
|
126
|
+
* checks for existing factory implementations and skips already-transformed switches.
|
|
127
|
+
*
|
|
128
|
+
* **Atomicity:**
|
|
129
|
+
* The orchestrator uses backup/rollback mechanisms to ensure all-or-nothing semantics.
|
|
130
|
+
* If any step fails, the source file is restored to its original state.
|
|
131
|
+
*
|
|
132
|
+
* @param context - Transform context containing source file, configuration, and API access
|
|
133
|
+
* @returns Promise resolving to transformation result with modification status and message
|
|
134
|
+
*/
|
|
135
|
+
async transform(context) {
|
|
136
|
+
const { sourceFile, filePath } = context;
|
|
137
|
+
// Check plugin configuration for transformation type
|
|
138
|
+
const pluginConfig = context.config['@angular-modernizer/plugin-solid'];
|
|
139
|
+
const transformationType = pluginConfig?.['transformationType'];
|
|
140
|
+
// Early return if transformation type doesn't match
|
|
141
|
+
if (transformationType !== 'god-switch-transform') {
|
|
142
|
+
return {
|
|
143
|
+
ruleId: this.id,
|
|
144
|
+
modified: false,
|
|
145
|
+
message: 'Transformation type not applicable',
|
|
146
|
+
filePath,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
// Capture initial state for change detection
|
|
150
|
+
const initialText = sourceFile.getFullText();
|
|
151
|
+
// Delegate to orchestrator for transformation logic
|
|
152
|
+
this.orchestrator.run(context);
|
|
153
|
+
// Detect modifications by comparing file state
|
|
154
|
+
const modified = sourceFile.getFullText() !== initialText;
|
|
155
|
+
// Return structured result
|
|
156
|
+
return {
|
|
157
|
+
ruleId: this.id,
|
|
158
|
+
modified,
|
|
159
|
+
message: modified
|
|
160
|
+
? 'Successfully transformed God Switch to Factory Pattern'
|
|
161
|
+
: 'No God Switch violations found to transform',
|
|
162
|
+
filePath,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.GodSwitchTransformRule = GodSwitchTransformRule;
|
|
167
|
+
//# sourceMappingURL=god-switch-transform.rule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"god-switch-transform.rule.js","sourceRoot":"","sources":["../../src/transform-rules/god-switch-transform.rule.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAQH,gHAAuG;AAEvG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AACH,MAAa,sBAAsB;IACjC;;OAEG;IACM,EAAE,GAAG,4BAA4B,CAAC;IAE3C;;OAEG;IACM,IAAI,GAAG,+BAA+B,CAAC;IAEhD;;OAEG;IACM,WAAW,GAClB,iHAAiH,CAAC;IAEpH;;OAEG;IACM,QAAQ,GAAG,aAAa,CAAC;IAElC;;OAEG;IACM,IAAI,GAAG;QACd,OAAO;QACP,YAAY;QACZ,iBAAiB;QACjB,kBAAkB;QAClB,aAAa;QACb,iBAAiB;KAClB,CAAC;IAEF;;;OAGG;IACc,YAAY,GAAG,IAAI,qEAA8B,EAAE,CAAC;IAErE;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,SAAS,CACb,OAAoC;QAEpC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;QAEzC,qDAAqD;QACrD,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,kCAAkC,CAEzD,CAAC;QACd,MAAM,kBAAkB,GAAG,YAAY,EAAE,CAAC,oBAAoB,CAEjD,CAAC;QAEd,oDAAoD;QACpD,IAAI,kBAAkB,KAAK,sBAAsB,EAAE,CAAC;YAClD,OAAO;gBACL,MAAM,EAAE,IAAI,CAAC,EAAE;gBACf,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,oCAAoC;gBAC7C,QAAQ;aACT,CAAC;QACJ,CAAC;QAED,6CAA6C;QAC7C,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;QAE7C,oDAAoD;QACpD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE/B,+CAA+C;QAC/C,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,EAAE,KAAK,WAAW,CAAC;QAE1D,2BAA2B;QAC3B,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,EAAE;YACf,QAAQ;YACR,OAAO,EAAE,QAAQ;gBACf,CAAC,CAAC,wDAAwD;gBAC1D,CAAC,CAAC,6CAA6C;YACjD,QAAQ;SACT,CAAC;IACJ,CAAC;CACF;AAvGD,wDAuGC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/plugin-solid - Service DIP Violation Transform Rule
|
|
3
|
+
*/
|
|
4
|
+
import type { TransformRule, TransformContext, TransformResult } from '@angular-modernizer/plugin-system';
|
|
5
|
+
import type { PublicApi } from '@angular-modernizer/api';
|
|
6
|
+
/**
|
|
7
|
+
* Transform rule that resolves constructor-injection DIP violations by introducing interfaces and InjectionTokens.
|
|
8
|
+
*
|
|
9
|
+
* **Problem:**
|
|
10
|
+
* `@Injectable` classes injecting other `@Injectable` classes by concrete type violate the
|
|
11
|
+
* Dependency Inversion Principle. The consuming class is coupled to the implementation,
|
|
12
|
+
* making it hard to substitute or test in isolation.
|
|
13
|
+
*
|
|
14
|
+
* **Solution:**
|
|
15
|
+
* For each violating constructor parameter:
|
|
16
|
+
* 1. Extract a public interface (`I${ClassName}`) from the injected service
|
|
17
|
+
* 2. Generate an `InjectionToken<IClassName>` in the injected file
|
|
18
|
+
* 3. Replace the parameter type with the interface name
|
|
19
|
+
* 4. Add `@Inject(TOKEN)` to the parameter
|
|
20
|
+
* 5. Add all necessary imports to both files
|
|
21
|
+
*
|
|
22
|
+
* **Before:**
|
|
23
|
+
* ```typescript
|
|
24
|
+
* @Injectable()
|
|
25
|
+
* export class UserService {
|
|
26
|
+
* constructor(private orderService: OrderService) {}
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* **After (consuming file):**
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { Inject } from '@angular/core';
|
|
33
|
+
* import { IOrderService, ORDER_SERVICE_TOKEN } from './order.service';
|
|
34
|
+
*
|
|
35
|
+
* @Injectable()
|
|
36
|
+
* export class UserService {
|
|
37
|
+
* constructor(@Inject(ORDER_SERVICE_TOKEN) private orderService: IOrderService) {}
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* **After (injected service file):**
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import { InjectionToken } from '@angular/core';
|
|
44
|
+
*
|
|
45
|
+
* export interface IOrderService {
|
|
46
|
+
* getOrder(id: string): Order;
|
|
47
|
+
* }
|
|
48
|
+
* export const ORDER_SERVICE_TOKEN = new InjectionToken<IOrderService>('order-service');
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* **Configuration:**
|
|
52
|
+
* ```json
|
|
53
|
+
* {
|
|
54
|
+
* "@angular-modernizer/plugin-solid": {
|
|
55
|
+
* "transformationType": "service-dip-violation-transform"
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* **Idempotency:**
|
|
61
|
+
* Parameters that already have an `@Inject` decorator are skipped.
|
|
62
|
+
* Interfaces that already exist in the injected file are not re-created.
|
|
63
|
+
*
|
|
64
|
+
* @see ServiceDipViolationTransformOrchestrator for detailed transformation logic
|
|
65
|
+
*/
|
|
66
|
+
export declare class ServiceDipViolationTransformRule implements TransformRule {
|
|
67
|
+
readonly id = "solid:service-dip-violation-transform";
|
|
68
|
+
readonly name = "Service DIP Violation \u2192 Interface + InjectionToken";
|
|
69
|
+
readonly description = "Replaces concrete constructor injection with interface-based injection using InjectionToken";
|
|
70
|
+
readonly category = "refactoring";
|
|
71
|
+
readonly tags: string[];
|
|
72
|
+
private readonly orchestrator;
|
|
73
|
+
transform(context: TransformContext<PublicApi>): Promise<TransformResult>;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=service-dip-violation.transform.rule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-dip-violation.transform.rule.d.ts","sourceRoot":"","sources":["../../src/transform-rules/service-dip-violation.transform.rule.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,eAAe,EAChB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,qBAAa,gCAAiC,YAAW,aAAa;IACpE,QAAQ,CAAC,EAAE,2CAA2C;IACtD,QAAQ,CAAC,IAAI,6DAAwD;IACrE,QAAQ,CAAC,WAAW,iGAC4E;IAChG,QAAQ,CAAC,QAAQ,iBAAiB;IAClC,QAAQ,CAAC,IAAI,WAMX;IAEF,OAAO,CAAC,QAAQ,CAAC,YAAY,CACoB;IAE3C,SAAS,CACb,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,GACnC,OAAO,CAAC,eAAe,CAAC;CA0C5B"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @angular-modernizer/plugin-solid - Service DIP Violation Transform Rule
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ServiceDipViolationTransformRule = void 0;
|
|
7
|
+
const service_dip_violation_transform_orchestrator_js_1 = require("../orchestrators/service-dip-violation-transform.orchestrator.js");
|
|
8
|
+
/**
|
|
9
|
+
* Transform rule that resolves constructor-injection DIP violations by introducing interfaces and InjectionTokens.
|
|
10
|
+
*
|
|
11
|
+
* **Problem:**
|
|
12
|
+
* `@Injectable` classes injecting other `@Injectable` classes by concrete type violate the
|
|
13
|
+
* Dependency Inversion Principle. The consuming class is coupled to the implementation,
|
|
14
|
+
* making it hard to substitute or test in isolation.
|
|
15
|
+
*
|
|
16
|
+
* **Solution:**
|
|
17
|
+
* For each violating constructor parameter:
|
|
18
|
+
* 1. Extract a public interface (`I${ClassName}`) from the injected service
|
|
19
|
+
* 2. Generate an `InjectionToken<IClassName>` in the injected file
|
|
20
|
+
* 3. Replace the parameter type with the interface name
|
|
21
|
+
* 4. Add `@Inject(TOKEN)` to the parameter
|
|
22
|
+
* 5. Add all necessary imports to both files
|
|
23
|
+
*
|
|
24
|
+
* **Before:**
|
|
25
|
+
* ```typescript
|
|
26
|
+
* @Injectable()
|
|
27
|
+
* export class UserService {
|
|
28
|
+
* constructor(private orderService: OrderService) {}
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* **After (consuming file):**
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { Inject } from '@angular/core';
|
|
35
|
+
* import { IOrderService, ORDER_SERVICE_TOKEN } from './order.service';
|
|
36
|
+
*
|
|
37
|
+
* @Injectable()
|
|
38
|
+
* export class UserService {
|
|
39
|
+
* constructor(@Inject(ORDER_SERVICE_TOKEN) private orderService: IOrderService) {}
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* **After (injected service file):**
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { InjectionToken } from '@angular/core';
|
|
46
|
+
*
|
|
47
|
+
* export interface IOrderService {
|
|
48
|
+
* getOrder(id: string): Order;
|
|
49
|
+
* }
|
|
50
|
+
* export const ORDER_SERVICE_TOKEN = new InjectionToken<IOrderService>('order-service');
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* **Configuration:**
|
|
54
|
+
* ```json
|
|
55
|
+
* {
|
|
56
|
+
* "@angular-modernizer/plugin-solid": {
|
|
57
|
+
* "transformationType": "service-dip-violation-transform"
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* **Idempotency:**
|
|
63
|
+
* Parameters that already have an `@Inject` decorator are skipped.
|
|
64
|
+
* Interfaces that already exist in the injected file are not re-created.
|
|
65
|
+
*
|
|
66
|
+
* @see ServiceDipViolationTransformOrchestrator for detailed transformation logic
|
|
67
|
+
*/
|
|
68
|
+
class ServiceDipViolationTransformRule {
|
|
69
|
+
id = 'solid:service-dip-violation-transform';
|
|
70
|
+
name = 'Service DIP Violation → Interface + InjectionToken';
|
|
71
|
+
description = 'Replaces concrete constructor injection with interface-based injection using InjectionToken';
|
|
72
|
+
category = 'refactoring';
|
|
73
|
+
tags = [
|
|
74
|
+
'solid',
|
|
75
|
+
'dip',
|
|
76
|
+
'interfaces',
|
|
77
|
+
'injection-token',
|
|
78
|
+
'dependency-inversion',
|
|
79
|
+
];
|
|
80
|
+
orchestrator = new service_dip_violation_transform_orchestrator_js_1.ServiceDipViolationTransformOrchestrator();
|
|
81
|
+
async transform(context) {
|
|
82
|
+
const { filePath } = context;
|
|
83
|
+
const pluginConfig = context.config['@angular-modernizer/plugin-solid'];
|
|
84
|
+
const transformationType = pluginConfig?.['transformationType'];
|
|
85
|
+
if (transformationType !== 'service-dip-violation-transform') {
|
|
86
|
+
return {
|
|
87
|
+
ruleId: this.id,
|
|
88
|
+
modified: false,
|
|
89
|
+
message: 'Transformation type not applicable',
|
|
90
|
+
filePath,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const { sourceFile } = context;
|
|
94
|
+
const initialText = sourceFile.getFullText();
|
|
95
|
+
const result = this.orchestrator.run(context);
|
|
96
|
+
const modified = sourceFile.getFullText() !== initialText;
|
|
97
|
+
return {
|
|
98
|
+
ruleId: this.id,
|
|
99
|
+
modified,
|
|
100
|
+
message: modified
|
|
101
|
+
? `Transformed ${result.changeCount} DIP violation(s): introduced interface + InjectionToken`
|
|
102
|
+
: result.errors.length > 0
|
|
103
|
+
? `No transformations applied (${result.errors.length} error(s))`
|
|
104
|
+
: 'No DIP violations found to transform',
|
|
105
|
+
filePath,
|
|
106
|
+
changeCount: result.changeCount,
|
|
107
|
+
metadata: {
|
|
108
|
+
transformedParams: result.transformedParams,
|
|
109
|
+
errors: result.errors,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.ServiceDipViolationTransformRule = ServiceDipViolationTransformRule;
|
|
115
|
+
//# sourceMappingURL=service-dip-violation.transform.rule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-dip-violation.transform.rule.js","sourceRoot":"","sources":["../../src/transform-rules/service-dip-violation.transform.rule.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAQH,sIAA4H;AAE5H;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,MAAa,gCAAgC;IAClC,EAAE,GAAG,uCAAuC,CAAC;IAC7C,IAAI,GAAG,oDAAoD,CAAC;IAC5D,WAAW,GAClB,6FAA6F,CAAC;IACvF,QAAQ,GAAG,aAAa,CAAC;IACzB,IAAI,GAAG;QACd,OAAO;QACP,KAAK;QACL,YAAY;QACZ,iBAAiB;QACjB,sBAAsB;KACvB,CAAC;IAEe,YAAY,GAC3B,IAAI,0FAAwC,EAAE,CAAC;IAEjD,KAAK,CAAC,SAAS,CACb,OAAoC;QAEpC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;QAE7B,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,kCAAkC,CAEzD,CAAC;QACd,MAAM,kBAAkB,GAAG,YAAY,EAAE,CAAC,oBAAoB,CAEjD,CAAC;QAEd,IAAI,kBAAkB,KAAK,iCAAiC,EAAE,CAAC;YAC7D,OAAO;gBACL,MAAM,EAAE,IAAI,CAAC,EAAE;gBACf,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,oCAAoC;gBAC7C,QAAQ;aACT,CAAC;QACJ,CAAC;QAED,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QAC/B,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;QAE7C,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE9C,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,EAAE,KAAK,WAAW,CAAC;QAE1D,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,EAAE;YACf,QAAQ;YACR,OAAO,EAAE,QAAQ;gBACf,CAAC,CAAC,eAAe,MAAM,CAAC,WAAW,0DAA0D;gBAC7F,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;oBACxB,CAAC,CAAC,+BAA+B,MAAM,CAAC,MAAM,CAAC,MAAM,YAAY;oBACjE,CAAC,CAAC,sCAAsC;YAC5C,QAAQ;YACR,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,QAAQ,EAAE;gBACR,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;gBAC3C,MAAM,EAAE,MAAM,CAAC,MAAM;aACtB;SACF,CAAC;IACJ,CAAC;CACF;AA7DD,4EA6DC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@angular-modernizer/plugin-solid",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Analysis plugin for detecting SOLID principle violations.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"angular",
|
|
7
|
+
"modernization",
|
|
8
|
+
"typescript",
|
|
9
|
+
"ast",
|
|
10
|
+
"ts-morph",
|
|
11
|
+
"solid",
|
|
12
|
+
"code-analysis"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/eiweiss/tsanalyzer.git",
|
|
18
|
+
"directory": "packages/plugin-solid"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/eiweiss/tsanalyzer#readme",
|
|
21
|
+
"bugs": "https://github.com/eiweiss/tsanalyzer/issues",
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"src",
|
|
26
|
+
"!dist/**/__tests__/**",
|
|
27
|
+
"!src/**/__tests__/**",
|
|
28
|
+
"!src/**/*.test.ts",
|
|
29
|
+
"!src/**/*.spec.ts"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@angular-modernizer/plugin-system": "0.1.0",
|
|
33
|
+
"@angular-modernizer/api": "0.1.0",
|
|
34
|
+
"@angular-modernizer/core": "0.1.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/jest": "^30.0.0",
|
|
38
|
+
"jest": "^30.2.0",
|
|
39
|
+
"ts-jest": "^29.4.5"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"typedocOptions": {
|
|
45
|
+
"entryPoints": [
|
|
46
|
+
"./src/index.ts"
|
|
47
|
+
],
|
|
48
|
+
"tsconfig": "./tsconfig.json"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc --build",
|
|
52
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
53
|
+
"test": "jest",
|
|
54
|
+
"test:watch": "jest --watch",
|
|
55
|
+
"test:coverage": "jest --coverage",
|
|
56
|
+
"lint": "eslint src/**/*.ts",
|
|
57
|
+
"lint:fix": "eslint src/**/*.ts --fix"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/plugin-solid
|
|
3
|
+
*
|
|
4
|
+
* SOLID principles analysis plugin for the Angular Modernization Platform.
|
|
5
|
+
* Detects architectural violations and provides guidance for better code structure.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { SolidPlugin } from './solid-plugin.js';
|
|
9
|
+
|
|
10
|
+
// Analysis Rules
|
|
11
|
+
export { DIPViolationRule } from './rules/dip-violation.rule.js';
|
|
12
|
+
export { SingleResponsibilityRule } from './rules/srp-violation.rule.js';
|
|
13
|
+
export { LSPViolationRule } from './rules/lsp-violation.rule.js';
|
|
14
|
+
export { OCPViolationRule } from './rules/ocp-violation.rule.js';
|
|
15
|
+
export { ISPViolationRule } from './rules/isp-violation.rule.js';
|
|
16
|
+
export { GodSwitchAnalysisRule } from './rules/god-switch-analysis.rule.js';
|
|
17
|
+
export { ServiceDipViolationRule } from './rules/service-dip-violation.analysis.rule.js';
|
|
18
|
+
export type {
|
|
19
|
+
ServiceDipViolationConfig,
|
|
20
|
+
ServiceDipViolationMetadata,
|
|
21
|
+
} from './rules/service-dip-violation.analysis.rule.js';
|
|
22
|
+
|
|
23
|
+
// Transform Rules
|
|
24
|
+
export { GodSwitchTransformRule } from './transform-rules/god-switch-transform.rule.js';
|
|
25
|
+
export { ServiceDipViolationTransformRule } from './transform-rules/service-dip-violation.transform.rule.js';
|
|
26
|
+
|
|
27
|
+
// Orchestrators (for advanced usage)
|
|
28
|
+
export { GodSwitchTransformOrchestrator } from './orchestrators/god-switch-transform-orchestrator.js';
|
|
29
|
+
export { ServiceDipViolationTransformOrchestrator } from './orchestrators/service-dip-violation-transform.orchestrator.js';
|
|
30
|
+
export type { ServiceDipTransformResult } from './orchestrators/service-dip-violation-transform.orchestrator.js';
|