@angular-modernizer/plugin-solid 0.3.0 → 1.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.
Files changed (67) hide show
  1. package/README.md +34 -48
  2. package/dist/index.d.ts +15 -4
  3. package/dist/index.js +14 -3
  4. package/dist/orchestrators/god-switch-transform-orchestrator.d.ts +3 -14
  5. package/dist/orchestrators/god-switch-transform-orchestrator.js +1 -13
  6. package/dist/orchestrators/service-dip-violation-transform.orchestrator.d.ts +38 -24
  7. package/dist/orchestrators/service-dip-violation-transform.orchestrator.js +28 -24
  8. package/dist/rules/dip-violation.rule.d.ts +14 -17
  9. package/dist/rules/dip-violation.rule.js +16 -19
  10. package/dist/rules/god-switch-analysis.rule.d.ts +13 -26
  11. package/dist/rules/god-switch-analysis.rule.js +15 -28
  12. package/dist/rules/isp-violation.rule.d.ts +12 -17
  13. package/dist/rules/isp-violation.rule.js +14 -19
  14. package/dist/rules/lsp-violation.rule.d.ts +15 -21
  15. package/dist/rules/lsp-violation.rule.js +17 -23
  16. package/dist/rules/ocp-violation.rule.d.ts +9 -18
  17. package/dist/rules/ocp-violation.rule.js +11 -20
  18. package/dist/rules/service-dip-violation.analysis.rule.d.ts +29 -20
  19. package/dist/rules/service-dip-violation.analysis.rule.js +14 -21
  20. package/dist/rules/srp-violation.rule.d.ts +19 -29
  21. package/dist/rules/srp-violation.rule.js +21 -31
  22. package/dist/solid-plugin.d.ts +3 -14
  23. package/dist/solid-plugin.js +3 -14
  24. package/dist/transform-rules/god-switch-transform.rule.d.ts +0 -3
  25. package/dist/transform-rules/god-switch-transform.rule.js +0 -3
  26. package/dist/transform-rules/service-dip-violation.transform.rule.d.ts +0 -3
  27. package/dist/transform-rules/service-dip-violation.transform.rule.js +0 -3
  28. package/package.json +20 -16
  29. package/dist/index.d.ts.map +0 -1
  30. package/dist/index.js.map +0 -1
  31. package/dist/orchestrators/god-switch-transform-orchestrator.d.ts.map +0 -1
  32. package/dist/orchestrators/god-switch-transform-orchestrator.js.map +0 -1
  33. package/dist/orchestrators/service-dip-violation-transform.orchestrator.d.ts.map +0 -1
  34. package/dist/orchestrators/service-dip-violation-transform.orchestrator.js.map +0 -1
  35. package/dist/rules/dip-violation.rule.d.ts.map +0 -1
  36. package/dist/rules/dip-violation.rule.js.map +0 -1
  37. package/dist/rules/god-switch-analysis.rule.d.ts.map +0 -1
  38. package/dist/rules/god-switch-analysis.rule.js.map +0 -1
  39. package/dist/rules/isp-violation.rule.d.ts.map +0 -1
  40. package/dist/rules/isp-violation.rule.js.map +0 -1
  41. package/dist/rules/lsp-violation.rule.d.ts.map +0 -1
  42. package/dist/rules/lsp-violation.rule.js.map +0 -1
  43. package/dist/rules/ocp-violation.rule.d.ts.map +0 -1
  44. package/dist/rules/ocp-violation.rule.js.map +0 -1
  45. package/dist/rules/service-dip-violation.analysis.rule.d.ts.map +0 -1
  46. package/dist/rules/service-dip-violation.analysis.rule.js.map +0 -1
  47. package/dist/rules/srp-violation.rule.d.ts.map +0 -1
  48. package/dist/rules/srp-violation.rule.js.map +0 -1
  49. package/dist/solid-plugin.d.ts.map +0 -1
  50. package/dist/solid-plugin.js.map +0 -1
  51. package/dist/transform-rules/god-switch-transform.rule.d.ts.map +0 -1
  52. package/dist/transform-rules/god-switch-transform.rule.js.map +0 -1
  53. package/dist/transform-rules/service-dip-violation.transform.rule.d.ts.map +0 -1
  54. package/dist/transform-rules/service-dip-violation.transform.rule.js.map +0 -1
  55. package/src/index.ts +0 -30
  56. package/src/orchestrators/god-switch-transform-orchestrator.ts +0 -1562
  57. package/src/orchestrators/service-dip-violation-transform.orchestrator.ts +0 -331
  58. package/src/rules/dip-violation.rule.ts +0 -194
  59. package/src/rules/god-switch-analysis.rule.ts +0 -209
  60. package/src/rules/isp-violation.rule.ts +0 -315
  61. package/src/rules/lsp-violation.rule.ts +0 -393
  62. package/src/rules/ocp-violation.rule.ts +0 -264
  63. package/src/rules/service-dip-violation.analysis.rule.ts +0 -285
  64. package/src/rules/srp-violation.rule.ts +0 -533
  65. package/src/solid-plugin.ts +0 -127
  66. package/src/transform-rules/god-switch-transform.rule.ts +0 -189
  67. package/src/transform-rules/service-dip-violation.transform.rule.ts +0 -134
@@ -1,189 +0,0 @@
1
- /**
2
- * @angular-modernizer/plugin-solid - God Switch Transform Rule
3
- */
4
-
5
- import type {
6
- TransformRule,
7
- TransformContext,
8
- TransformResult,
9
- } from '@angular-modernizer/plugin-system';
10
- import type { PublicApi } from '@angular-modernizer/api';
11
- import { GodSwitchTransformOrchestrator } from '../orchestrators/god-switch-transform-orchestrator.js';
12
-
13
- /**
14
- * Transform rule that converts large switch statements into maintainable Factory Pattern implementations.
15
- *
16
- * **Problem:**
17
- * Large switch statements (10+ cases) violate SOLID principles:
18
- * - Open/Closed Principle: Adding new cases requires modifying the switch
19
- * - Single Responsibility: Switch handles multiple concerns
20
- * - Difficult to test, maintain, and extend
21
- *
22
- * **Solution:**
23
- * Transforms God Switch into Factory Pattern using Strategy pattern:
24
- * 1. Extract each case into a separate Strategy class
25
- * 2. Generate a Factory class to create strategy instances
26
- * 3. Replace switch statement with factory call
27
- *
28
- * **Before:**
29
- * ```typescript
30
- * switch (type) {
31
- * case 'A':
32
- * return handleA();
33
- * case 'B':
34
- * return handleB();
35
- * // ... 10+ more cases
36
- * }
37
- * ```
38
- *
39
- * **After:**
40
- * ```typescript
41
- * interface TypeStrategy {
42
- * execute(): Result;
43
- * }
44
- *
45
- * class AStrategy implements TypeStrategy {
46
- * execute(): Result { return handleA(); }
47
- * }
48
- *
49
- * class TypeFactory {
50
- * createStrategy(type: string): TypeStrategy {
51
- * const strategies = { A: AStrategy, B: BStrategy, ... };
52
- * return new strategies[type]();
53
- * }
54
- * }
55
- *
56
- * const strategy = factory.createStrategy(type);
57
- * return strategy.execute();
58
- * ```
59
- *
60
- * **Configuration:**
61
- * ```json
62
- * {
63
- * "transformationType": "god-switch-transform",
64
- * "godSwitch": {
65
- * "minCaseCount": 10,
66
- * "generateInterfaces": true,
67
- * "generateFactory": true,
68
- * "strategyNamingPattern": "{CaseValue}Strategy",
69
- * "factoryNamingPattern": "{SwitchExpression}Factory"
70
- * }
71
- * }
72
- * ```
73
- *
74
- * @see GodSwitchTransformOrchestrator for detailed transformation logic
75
- * @example
76
- * ```typescript
77
- * // Transformation triggered via MCP tool or programmatic API
78
- * const rule = new GodSwitchTransformRule();
79
- * const result = await rule.transform(context);
80
- *
81
- * if (result.modified) {
82
- * console.info('Successfully transformed God Switch to Factory Pattern');
83
- * }
84
- * ```
85
- */
86
- export class GodSwitchTransformRule implements TransformRule {
87
- /**
88
- * Unique identifier following plugin-name:rule-name convention.
89
- */
90
- readonly id = 'solid:god-switch-transform';
91
-
92
- /**
93
- * Human-readable name for the transformation.
94
- */
95
- readonly name = 'God Switch to Factory Pattern';
96
-
97
- /**
98
- * Detailed description of the transformation's purpose and behavior.
99
- */
100
- readonly description =
101
- 'Transforms large switch statements into maintainable Factory Pattern implementations using the Strategy pattern';
102
-
103
- /**
104
- * Category indicating this is a code restructuring transformation.
105
- */
106
- readonly category = 'refactoring';
107
-
108
- /**
109
- * Tags for discoverability and filtering.
110
- */
111
- readonly tags = [
112
- 'solid',
113
- 'god-switch',
114
- 'factory-pattern',
115
- 'strategy-pattern',
116
- 'refactoring',
117
- 'maintainability',
118
- ];
119
-
120
- /**
121
- * Orchestrator instance that performs the actual transformation logic.
122
- * Following the "Thin Rule, Thick Orchestrator" pattern.
123
- */
124
- private readonly orchestrator = new GodSwitchTransformOrchestrator();
125
-
126
- /**
127
- * Transforms God Switch violations into Factory Pattern implementations.
128
- *
129
- * **Process:**
130
- * 1. Validates transformation type from configuration
131
- * 2. Captures initial source file state
132
- * 3. Delegates to orchestrator for transformation
133
- * 4. Detects modifications by comparing file state
134
- * 5. Returns structured result with modification status
135
- *
136
- * **Idempotency:**
137
- * Running multiple times on the same file is safe - the orchestrator
138
- * checks for existing factory implementations and skips already-transformed switches.
139
- *
140
- * **Atomicity:**
141
- * The orchestrator uses backup/rollback mechanisms to ensure all-or-nothing semantics.
142
- * If any step fails, the source file is restored to its original state.
143
- *
144
- * @param context - Transform context containing source file, configuration, and API access
145
- * @returns Promise resolving to transformation result with modification status and message
146
- */
147
- async transform(
148
- context: TransformContext<PublicApi>,
149
- ): Promise<TransformResult> {
150
- const { sourceFile, filePath } = context;
151
-
152
- // Check plugin configuration for transformation type
153
- const pluginConfig = context.config['@angular-modernizer/plugin-solid'] as
154
- | Record<string, unknown>
155
- | undefined;
156
- const transformationType = pluginConfig?.['transformationType'] as
157
- | string
158
- | undefined;
159
-
160
- // Early return if transformation type doesn't match
161
- if (transformationType !== 'god-switch-transform') {
162
- return {
163
- ruleId: this.id,
164
- modified: false,
165
- message: 'Transformation type not applicable',
166
- filePath,
167
- };
168
- }
169
-
170
- // Capture initial state for change detection
171
- const initialText = sourceFile.getFullText();
172
-
173
- // Delegate to orchestrator for transformation logic
174
- this.orchestrator.run(context);
175
-
176
- // Detect modifications by comparing file state
177
- const modified = sourceFile.getFullText() !== initialText;
178
-
179
- // Return structured result
180
- return {
181
- ruleId: this.id,
182
- modified,
183
- message: modified
184
- ? 'Successfully transformed God Switch to Factory Pattern'
185
- : 'No God Switch violations found to transform',
186
- filePath,
187
- };
188
- }
189
- }
@@ -1,134 +0,0 @@
1
- /**
2
- * @angular-modernizer/plugin-solid - Service DIP Violation Transform Rule
3
- */
4
-
5
- import type {
6
- TransformRule,
7
- TransformContext,
8
- TransformResult,
9
- } from '@angular-modernizer/plugin-system';
10
- import type { PublicApi } from '@angular-modernizer/api';
11
- import { ServiceDipViolationTransformOrchestrator } from '../orchestrators/service-dip-violation-transform.orchestrator.js';
12
-
13
- /**
14
- * Transform rule that resolves constructor-injection DIP violations by introducing interfaces and InjectionTokens.
15
- *
16
- * **Problem:**
17
- * `@Injectable` classes injecting other `@Injectable` classes by concrete type violate the
18
- * Dependency Inversion Principle. The consuming class is coupled to the implementation,
19
- * making it hard to substitute or test in isolation.
20
- *
21
- * **Solution:**
22
- * For each violating constructor parameter:
23
- * 1. Extract a public interface (`I${ClassName}`) from the injected service
24
- * 2. Generate an `InjectionToken<IClassName>` in the injected file
25
- * 3. Replace the parameter type with the interface name
26
- * 4. Add `@Inject(TOKEN)` to the parameter
27
- * 5. Add all necessary imports to both files
28
- *
29
- * **Before:**
30
- * ```typescript
31
- * @Injectable()
32
- * export class UserService {
33
- * constructor(private orderService: OrderService) {}
34
- * }
35
- * ```
36
- *
37
- * **After (consuming file):**
38
- * ```typescript
39
- * import { Inject } from '@angular/core';
40
- * import { IOrderService, ORDER_SERVICE_TOKEN } from './order.service';
41
- *
42
- * @Injectable()
43
- * export class UserService {
44
- * constructor(@Inject(ORDER_SERVICE_TOKEN) private orderService: IOrderService) {}
45
- * }
46
- * ```
47
- *
48
- * **After (injected service file):**
49
- * ```typescript
50
- * import { InjectionToken } from '@angular/core';
51
- *
52
- * export interface IOrderService {
53
- * getOrder(id: string): Order;
54
- * }
55
- * export const ORDER_SERVICE_TOKEN = new InjectionToken<IOrderService>('order-service');
56
- * ```
57
- *
58
- * **Configuration:**
59
- * ```json
60
- * {
61
- * "@angular-modernizer/plugin-solid": {
62
- * "transformationType": "service-dip-violation-transform"
63
- * }
64
- * }
65
- * ```
66
- *
67
- * **Idempotency:**
68
- * Parameters that already have an `@Inject` decorator are skipped.
69
- * Interfaces that already exist in the injected file are not re-created.
70
- *
71
- * @see ServiceDipViolationTransformOrchestrator for detailed transformation logic
72
- */
73
- export class ServiceDipViolationTransformRule implements TransformRule {
74
- readonly id = 'solid:service-dip-violation-transform';
75
- readonly name = 'Service DIP Violation → Interface + InjectionToken';
76
- readonly description =
77
- 'Replaces concrete constructor injection with interface-based injection using InjectionToken';
78
- readonly category = 'refactoring';
79
- readonly tags = [
80
- 'solid',
81
- 'dip',
82
- 'interfaces',
83
- 'injection-token',
84
- 'dependency-inversion',
85
- ];
86
-
87
- private readonly orchestrator =
88
- new ServiceDipViolationTransformOrchestrator();
89
-
90
- async transform(
91
- context: TransformContext<PublicApi>,
92
- ): Promise<TransformResult> {
93
- const { filePath } = context;
94
-
95
- const pluginConfig = context.config['@angular-modernizer/plugin-solid'] as
96
- | Record<string, unknown>
97
- | undefined;
98
- const transformationType = pluginConfig?.['transformationType'] as
99
- | string
100
- | undefined;
101
-
102
- if (transformationType !== 'service-dip-violation-transform') {
103
- return {
104
- ruleId: this.id,
105
- modified: false,
106
- message: 'Transformation type not applicable',
107
- filePath,
108
- };
109
- }
110
-
111
- const { sourceFile } = context;
112
- const initialText = sourceFile.getFullText();
113
-
114
- const result = this.orchestrator.run(context);
115
-
116
- const modified = sourceFile.getFullText() !== initialText;
117
-
118
- return {
119
- ruleId: this.id,
120
- modified,
121
- message: modified
122
- ? `Transformed ${result.changeCount} DIP violation(s): introduced interface + InjectionToken`
123
- : result.errors.length > 0
124
- ? `No transformations applied (${result.errors.length} error(s))`
125
- : 'No DIP violations found to transform',
126
- filePath,
127
- changeCount: result.changeCount,
128
- metadata: {
129
- transformedParams: result.transformedParams,
130
- errors: result.errors,
131
- },
132
- };
133
- }
134
- }