@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,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/plugin-solid - Main Plugin
|
|
3
|
+
*
|
|
4
|
+
* The main entry point for the SOLID principles analysis plugin.
|
|
5
|
+
* Provides analysis rules for detecting SOLID principle violations.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
Plugin,
|
|
10
|
+
AnalysisRule,
|
|
11
|
+
TransformRule,
|
|
12
|
+
ValidationRule,
|
|
13
|
+
IKernel
|
|
14
|
+
} from '@angular-modernizer/plugin-system';
|
|
15
|
+
import { DIPViolationRule } from './rules/dip-violation.rule.js';
|
|
16
|
+
import { SingleResponsibilityRule } from './rules/srp-violation.rule.js';
|
|
17
|
+
import { LSPViolationRule } from './rules/lsp-violation.rule.js';
|
|
18
|
+
import { OCPViolationRule } from './rules/ocp-violation.rule.js';
|
|
19
|
+
import { ISPViolationRule } from './rules/isp-violation.rule.js';
|
|
20
|
+
import { GodSwitchAnalysisRule } from './rules/god-switch-analysis.rule.js';
|
|
21
|
+
import { GodSwitchTransformRule } from './transform-rules/god-switch-transform.rule.js';
|
|
22
|
+
import { ServiceDipViolationTransformRule } from './transform-rules/service-dip-violation.transform.rule.js';
|
|
23
|
+
import { ServiceDipViolationRule } from './rules/service-dip-violation.analysis.rule.js';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* SOLID Principles Analysis Plugin
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* This plugin provides analysis rules for detecting violations of SOLID principles
|
|
30
|
+
* in Angular applications. It focuses on architectural issues that can lead to
|
|
31
|
+
* maintainability problems.
|
|
32
|
+
*
|
|
33
|
+
* ## Current Rules
|
|
34
|
+
*
|
|
35
|
+
* ### Analysis Rules
|
|
36
|
+
* - {@link DIPViolationRule}: Detects direct service instantiation (DIP violation)
|
|
37
|
+
* - {@link ServiceDipViolationRule}: Detects concrete constructor injection instead of interfaces (DIP violation)
|
|
38
|
+
* - {@link SingleResponsibilityRule}: Detects classes with too many responsibilities (SRP violation)
|
|
39
|
+
* - {@link LSPViolationRule}: Detects inheritance and interface implementation issues (LSP violation)
|
|
40
|
+
* - {@link OCPViolationRule}: Detects code that violates the Open/Closed Principle (OCP violation)
|
|
41
|
+
* - {@link ISPViolationRule}: Detects interface segregation violations (ISP violation)
|
|
42
|
+
* - {@link GodSwitchAnalysisRule}: Detects large switch statements (God Switch anti-pattern)
|
|
43
|
+
*
|
|
44
|
+
* ### Transform Rules
|
|
45
|
+
* - {@link GodSwitchTransformRule}: Transforms God Switch violations into Factory Pattern implementations
|
|
46
|
+
*
|
|
47
|
+
* ## Future Rules (Planned)
|
|
48
|
+
*
|
|
49
|
+
* - MissingInterfaceRule: Services without interfaces (DIP)
|
|
50
|
+
* - CircularDependencyRule: Import cycles (architectural)
|
|
51
|
+
* - FatInterfaceRule: Interfaces with too many methods (ISP)
|
|
52
|
+
*
|
|
53
|
+
* @see {@link DIPViolationRule} for the DIP implementation
|
|
54
|
+
* @see {@link SingleResponsibilityRule} for the SRP implementation
|
|
55
|
+
* @see {@link GodSwitchTransformRule} for the God Switch transformation
|
|
56
|
+
*/
|
|
57
|
+
export class SolidPlugin implements Plugin {
|
|
58
|
+
/**
|
|
59
|
+
* Unique plugin identifier.
|
|
60
|
+
*/
|
|
61
|
+
public readonly name = '@angular-modernizer/plugin-solid';
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Plugin version (from package.json).
|
|
65
|
+
*/
|
|
66
|
+
public readonly version = '0.1.0';
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Plugin description.
|
|
70
|
+
*/
|
|
71
|
+
public readonly description =
|
|
72
|
+
'Provides SOLID principles analysis for architectural violations';
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Plugin author.
|
|
76
|
+
*/
|
|
77
|
+
public readonly author = 'Angular Modernization Platform';
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Initialize the plugin.
|
|
81
|
+
*
|
|
82
|
+
* @param _kernel - The Kernel instance for accessing infrastructure
|
|
83
|
+
*/
|
|
84
|
+
async initialize(_kernel: IKernel): Promise<void> {
|
|
85
|
+
// No initialization needed for now
|
|
86
|
+
// Future: Load configuration, register analyzers, etc.
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get all analysis rules provided by this plugin.
|
|
91
|
+
*
|
|
92
|
+
* @returns Array of analysis rules for SOLID violations
|
|
93
|
+
*/
|
|
94
|
+
getAnalysisRules(): AnalysisRule[] {
|
|
95
|
+
return [
|
|
96
|
+
new DIPViolationRule(),
|
|
97
|
+
new SingleResponsibilityRule(),
|
|
98
|
+
new LSPViolationRule(),
|
|
99
|
+
new OCPViolationRule(),
|
|
100
|
+
new ISPViolationRule(),
|
|
101
|
+
new GodSwitchAnalysisRule(),
|
|
102
|
+
new ServiceDipViolationRule(),
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get all transformation rules provided by this plugin.
|
|
108
|
+
*
|
|
109
|
+
* @returns Array of transformation rules for SOLID violations
|
|
110
|
+
*/
|
|
111
|
+
getTransformRules(): TransformRule[] {
|
|
112
|
+
return [
|
|
113
|
+
new GodSwitchTransformRule(),
|
|
114
|
+
new ServiceDipViolationTransformRule(),
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Get all validation rules provided by this plugin.
|
|
120
|
+
*
|
|
121
|
+
* @returns Empty array (no validation rules yet)
|
|
122
|
+
*/
|
|
123
|
+
getValidationRules(): ValidationRule[] {
|
|
124
|
+
// Future: Add validation rules to verify fixes
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
}
|