@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,307 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @angular-modernizer/plugin-solid - SRP Violation Rule
|
|
4
|
+
*
|
|
5
|
+
* Detects Single Responsibility Principle violations in classes.
|
|
6
|
+
*
|
|
7
|
+
* Detection Patterns:
|
|
8
|
+
* - Classes with too many methods (configurable threshold, default: 15)
|
|
9
|
+
* - Classes mixing multiple responsibility categories
|
|
10
|
+
*
|
|
11
|
+
* Responsibility Categories:
|
|
12
|
+
* - UI: render, display, show, hide, toggle, open, close
|
|
13
|
+
* - Business: calculate, validate, process, transform, compute
|
|
14
|
+
* - HTTP: fetch, get, post, put, delete, request, call
|
|
15
|
+
* - Data: save, load, store, retrieve, persist, cache
|
|
16
|
+
* - Event: emit, dispatch, trigger, fire, notify, publish
|
|
17
|
+
* - Lifecycle: init, destroy, cleanup, setup, teardown
|
|
18
|
+
*
|
|
19
|
+
* This rule helps enforce the Single Responsibility Principle by identifying
|
|
20
|
+
* classes that are doing too much or handling multiple unrelated concerns.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Violation: class mixes HTTP, business, and UI concerns
|
|
24
|
+
* class UserComponent {
|
|
25
|
+
* fetchUsers() {} // HTTP concern
|
|
26
|
+
* calculateTotal() {} // Business concern
|
|
27
|
+
* renderChart() {} // UI concern
|
|
28
|
+
* }
|
|
29
|
+
*/
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.SingleResponsibilityRule = void 0;
|
|
32
|
+
const ts_morph_1 = require("ts-morph");
|
|
33
|
+
/**
|
|
34
|
+
* SRP Violation Rule - detects Single Responsibility Principle violations.
|
|
35
|
+
*
|
|
36
|
+
* This rule implements the Single Responsibility Principle by detecting
|
|
37
|
+
* classes with too many methods or mixed responsibilities.
|
|
38
|
+
*/
|
|
39
|
+
class SingleResponsibilityRule {
|
|
40
|
+
id = 'solid:srp-single-responsibility-violation';
|
|
41
|
+
name = 'Single Responsibility Principle Violation';
|
|
42
|
+
description = 'Detects classes with too many methods or mixed responsibilities';
|
|
43
|
+
severity = 'warning';
|
|
44
|
+
category = 'solid-violation';
|
|
45
|
+
tags = [
|
|
46
|
+
'solid',
|
|
47
|
+
'srp',
|
|
48
|
+
'single-responsibility',
|
|
49
|
+
'architecture',
|
|
50
|
+
'maintainability',
|
|
51
|
+
];
|
|
52
|
+
/**
|
|
53
|
+
* Default threshold for maximum number of methods in a class.
|
|
54
|
+
*/
|
|
55
|
+
maxMethodsThreshold = 15;
|
|
56
|
+
/**
|
|
57
|
+
* Minimum number of different responsibility categories to flag as mixed.
|
|
58
|
+
*/
|
|
59
|
+
minMixedResponsibilities = 3;
|
|
60
|
+
/**
|
|
61
|
+
* Responsibility categories for method classification.
|
|
62
|
+
*/
|
|
63
|
+
responsibilityCategories = [
|
|
64
|
+
{
|
|
65
|
+
name: 'UI',
|
|
66
|
+
keywords: [
|
|
67
|
+
'render',
|
|
68
|
+
'display',
|
|
69
|
+
'show',
|
|
70
|
+
'hide',
|
|
71
|
+
'toggle',
|
|
72
|
+
'open',
|
|
73
|
+
'close',
|
|
74
|
+
'view',
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'Business',
|
|
79
|
+
keywords: [
|
|
80
|
+
'calculate',
|
|
81
|
+
'validate',
|
|
82
|
+
'process',
|
|
83
|
+
'transform',
|
|
84
|
+
'compute',
|
|
85
|
+
'check',
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'HTTP',
|
|
90
|
+
keywords: [
|
|
91
|
+
'fetch',
|
|
92
|
+
'get',
|
|
93
|
+
'post',
|
|
94
|
+
'put',
|
|
95
|
+
'delete',
|
|
96
|
+
'request',
|
|
97
|
+
'call',
|
|
98
|
+
'api',
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'Data',
|
|
103
|
+
keywords: [
|
|
104
|
+
'save',
|
|
105
|
+
'load',
|
|
106
|
+
'store',
|
|
107
|
+
'retrieve',
|
|
108
|
+
'persist',
|
|
109
|
+
'cache',
|
|
110
|
+
'read',
|
|
111
|
+
'write',
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'Event',
|
|
116
|
+
keywords: [
|
|
117
|
+
'emit',
|
|
118
|
+
'dispatch',
|
|
119
|
+
'trigger',
|
|
120
|
+
'fire',
|
|
121
|
+
'notify',
|
|
122
|
+
'publish',
|
|
123
|
+
'subscribe',
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: 'Lifecycle',
|
|
128
|
+
keywords: [
|
|
129
|
+
'init',
|
|
130
|
+
'destroy',
|
|
131
|
+
'cleanup',
|
|
132
|
+
'setup',
|
|
133
|
+
'teardown',
|
|
134
|
+
'start',
|
|
135
|
+
'stop',
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
async analyze(context) {
|
|
140
|
+
const violations = [];
|
|
141
|
+
const sourceFile = context.sourceFile;
|
|
142
|
+
// Find all class declarations in the file
|
|
143
|
+
const classes = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ClassDeclaration);
|
|
144
|
+
for (const classDecl of classes) {
|
|
145
|
+
const classViolations = this.checkClass(classDecl, sourceFile.getFilePath());
|
|
146
|
+
violations.push(...classViolations);
|
|
147
|
+
}
|
|
148
|
+
return Promise.resolve(violations);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Check if a class violates SRP.
|
|
152
|
+
*/
|
|
153
|
+
checkClass(classDecl, filePath) {
|
|
154
|
+
const violations = [];
|
|
155
|
+
try {
|
|
156
|
+
const className = classDecl.getName() ?? '<anonymous>';
|
|
157
|
+
const methods = classDecl.getMethods();
|
|
158
|
+
// Skip empty or very small classes
|
|
159
|
+
if (methods.length === 0) {
|
|
160
|
+
return violations;
|
|
161
|
+
}
|
|
162
|
+
// Check for too many methods
|
|
163
|
+
if (methods.length > this.maxMethodsThreshold) {
|
|
164
|
+
const startLine = classDecl.getStartLineNumber();
|
|
165
|
+
const startColumn = classDecl.getStart() - classDecl.getStartLinePos();
|
|
166
|
+
violations.push({
|
|
167
|
+
ruleId: this.id,
|
|
168
|
+
message: `Class '${className}' has ${methods.length} methods (threshold: ${this.maxMethodsThreshold}). Consider splitting into smaller, focused classes.`,
|
|
169
|
+
filePath,
|
|
170
|
+
line: startLine,
|
|
171
|
+
column: startColumn,
|
|
172
|
+
suggestedFix: `Refactor '${className}' by extracting related methods into separate classes, each with a single responsibility.`,
|
|
173
|
+
metadata: {
|
|
174
|
+
className,
|
|
175
|
+
methodCount: methods.length,
|
|
176
|
+
threshold: this.maxMethodsThreshold,
|
|
177
|
+
violationType: 'too-many-methods',
|
|
178
|
+
principle: 'SRP',
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
// Check for single-method multi-concern (Cat 2)
|
|
183
|
+
for (const method of methods) {
|
|
184
|
+
const methodViolation = this.analyzeMethodBodyConcerns(method, className, filePath);
|
|
185
|
+
if (methodViolation) {
|
|
186
|
+
violations.push(methodViolation);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// Check for mixed responsibilities
|
|
190
|
+
const responsibilities = this.analyzeResponsibilities(methods);
|
|
191
|
+
if (responsibilities.size >= this.minMixedResponsibilities) {
|
|
192
|
+
const startLine = classDecl.getStartLineNumber();
|
|
193
|
+
const startColumn = classDecl.getStart() - classDecl.getStartLinePos();
|
|
194
|
+
const responsibilityList = Array.from(responsibilities).join(', ');
|
|
195
|
+
violations.push({
|
|
196
|
+
ruleId: this.id,
|
|
197
|
+
message: `Class '${className}' appears to have mixed responsibilities: ${responsibilityList}. Consider separating these concerns.`,
|
|
198
|
+
filePath,
|
|
199
|
+
line: startLine,
|
|
200
|
+
column: startColumn,
|
|
201
|
+
suggestedFix: `Extract methods into separate classes based on their responsibilities.`,
|
|
202
|
+
metadata: {
|
|
203
|
+
className,
|
|
204
|
+
responsibilities: Array.from(responsibilities),
|
|
205
|
+
violationType: 'mixed-responsibilities',
|
|
206
|
+
principle: 'SRP',
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return violations;
|
|
211
|
+
}
|
|
212
|
+
catch (_error) {
|
|
213
|
+
// If we can't analyze the class, skip it
|
|
214
|
+
return violations;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Detect a single method that mixes ≥4 distinct concern categories AND is ≥20 lines.
|
|
219
|
+
* Scans the full method body text for concern keywords (same categories as class-level).
|
|
220
|
+
*/
|
|
221
|
+
analyzeMethodBodyConcerns(method, className, filePath) {
|
|
222
|
+
const methodName = method.getName();
|
|
223
|
+
if (!methodName) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
// Skip Angular lifecycle hooks
|
|
227
|
+
if (methodName.startsWith('ng')) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
const body = method.getBody();
|
|
231
|
+
if (!body) {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
// Too short to meaningfully mix concerns
|
|
235
|
+
const lineCount = method.getEndLineNumber() - method.getStartLineNumber();
|
|
236
|
+
if (lineCount < 20) {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
const bodyText = body.getFullText().toLowerCase();
|
|
240
|
+
const detectedConcerns = [];
|
|
241
|
+
for (const category of this.responsibilityCategories) {
|
|
242
|
+
for (const keyword of category.keywords) {
|
|
243
|
+
if (bodyText.includes(keyword)) {
|
|
244
|
+
if (!detectedConcerns.includes(category.name)) {
|
|
245
|
+
detectedConcerns.push(category.name);
|
|
246
|
+
}
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (detectedConcerns.length < 4) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
ruleId: this.id,
|
|
256
|
+
message: `Method '${methodName}' in '${className}' mixes ${detectedConcerns.length} concerns (${detectedConcerns.join(', ')}) in one body.`,
|
|
257
|
+
filePath,
|
|
258
|
+
line: method.getStartLineNumber(),
|
|
259
|
+
column: method.getStart() - method.getStartLinePos(),
|
|
260
|
+
suggestedFix: `Extract each concern into a dedicated private method or service to honour the Single Responsibility Principle.`,
|
|
261
|
+
metadata: {
|
|
262
|
+
className,
|
|
263
|
+
methodName,
|
|
264
|
+
concerns: detectedConcerns,
|
|
265
|
+
violationType: 'single-method-multi-concern',
|
|
266
|
+
principle: 'SRP',
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Analyze the responsibilities of methods in a class.
|
|
272
|
+
* Returns a set of responsibility category names found.
|
|
273
|
+
*/
|
|
274
|
+
analyzeResponsibilities(methods) {
|
|
275
|
+
const responsibilities = new Set();
|
|
276
|
+
for (const method of methods) {
|
|
277
|
+
try {
|
|
278
|
+
const methodName = method.getName();
|
|
279
|
+
if (!methodName) {
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
// Skip Angular lifecycle methods (interface methods)
|
|
283
|
+
if (methodName.startsWith('ng')) {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
// Convert to lowercase for case-insensitive matching
|
|
287
|
+
const lowerName = methodName.toLowerCase();
|
|
288
|
+
// Check each responsibility category
|
|
289
|
+
for (const category of this.responsibilityCategories) {
|
|
290
|
+
for (const keyword of category.keywords) {
|
|
291
|
+
if (lowerName.includes(keyword)) {
|
|
292
|
+
responsibilities.add(category.name);
|
|
293
|
+
break; // Found a match for this category, move to next category
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
catch (_error) {
|
|
299
|
+
// Skip methods that can't be analyzed
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return responsibilities;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
exports.SingleResponsibilityRule = SingleResponsibilityRule;
|
|
307
|
+
//# sourceMappingURL=srp-violation.rule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"srp-violation.rule.js","sourceRoot":"","sources":["../../src/rules/srp-violation.rule.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;;;AAEH,uCAIkB;AAelB;;;;;GAKG;AACH,MAAa,wBAAwB;IACnB,EAAE,GAAG,2CAA2C,CAAC;IACjD,IAAI,GAAG,2CAA2C,CAAC;IACnD,WAAW,GACzB,iEAAiE,CAAC;IACpD,QAAQ,GAAG,SAAS,CAAC;IACrB,QAAQ,GAAG,iBAAiB,CAAC;IAC7B,IAAI,GAAG;QACrB,OAAO;QACP,KAAK;QACL,uBAAuB;QACvB,cAAc;QACd,iBAAiB;KAClB,CAAC;IAEF;;OAEG;IACc,mBAAmB,GAAG,EAAE,CAAC;IAE1C;;OAEG;IACc,wBAAwB,GAAG,CAAC,CAAC;IAE9C;;OAEG;IACc,wBAAwB,GAA6B;QACpE;YACE,IAAI,EAAE,IAAI;YACV,QAAQ,EAAE;gBACR,QAAQ;gBACR,SAAS;gBACT,MAAM;gBACN,MAAM;gBACN,QAAQ;gBACR,MAAM;gBACN,OAAO;gBACP,MAAM;aACP;SACF;QACD;YACE,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE;gBACR,WAAW;gBACX,UAAU;gBACV,SAAS;gBACT,WAAW;gBACX,SAAS;gBACT,OAAO;aACR;SACF;QACD;YACE,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE;gBACR,OAAO;gBACP,KAAK;gBACL,MAAM;gBACN,KAAK;gBACL,QAAQ;gBACR,SAAS;gBACT,MAAM;gBACN,KAAK;aACN;SACF;QACD;YACE,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE;gBACR,MAAM;gBACN,MAAM;gBACN,OAAO;gBACP,UAAU;gBACV,SAAS;gBACT,OAAO;gBACP,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CAAC;gBACpC,IAAI,CAAC,UAAU,EAAE,CAAC;oBAChB,SAAS;gBACX,CAAC;gBAED,qDAAqD;gBACrD,IAAI,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;oBAChC,SAAS;gBACX,CAAC;gBAED,qDAAqD;gBACrD,MAAM,SAAS,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;gBAE3C,qCAAqC;gBACrC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,wBAAwB,EAAE,CAAC;oBACrD,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;wBACxC,IAAI,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;4BAChC,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;4BACpC,MAAM,CAAC,yDAAyD;wBAClE,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,OAAO,MAAM,EAAE,CAAC;gBAChB,sCAAsC;gBACtC,SAAS;YACX,CAAC;QACH,CAAC;QAED,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF;AAvTD,4DAuTC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
import type { Plugin, AnalysisRule, TransformRule, ValidationRule, IKernel } from '@angular-modernizer/plugin-system';
|
|
8
|
+
/**
|
|
9
|
+
* SOLID Principles Analysis Plugin
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* This plugin provides analysis rules for detecting violations of SOLID principles
|
|
13
|
+
* in Angular applications. It focuses on architectural issues that can lead to
|
|
14
|
+
* maintainability problems.
|
|
15
|
+
*
|
|
16
|
+
* ## Current Rules
|
|
17
|
+
*
|
|
18
|
+
* ### Analysis Rules
|
|
19
|
+
* - {@link DIPViolationRule}: Detects direct service instantiation (DIP violation)
|
|
20
|
+
* - {@link ServiceDipViolationRule}: Detects concrete constructor injection instead of interfaces (DIP violation)
|
|
21
|
+
* - {@link SingleResponsibilityRule}: Detects classes with too many responsibilities (SRP violation)
|
|
22
|
+
* - {@link LSPViolationRule}: Detects inheritance and interface implementation issues (LSP violation)
|
|
23
|
+
* - {@link OCPViolationRule}: Detects code that violates the Open/Closed Principle (OCP violation)
|
|
24
|
+
* - {@link ISPViolationRule}: Detects interface segregation violations (ISP violation)
|
|
25
|
+
* - {@link GodSwitchAnalysisRule}: Detects large switch statements (God Switch anti-pattern)
|
|
26
|
+
*
|
|
27
|
+
* ### Transform Rules
|
|
28
|
+
* - {@link GodSwitchTransformRule}: Transforms God Switch violations into Factory Pattern implementations
|
|
29
|
+
*
|
|
30
|
+
* ## Future Rules (Planned)
|
|
31
|
+
*
|
|
32
|
+
* - MissingInterfaceRule: Services without interfaces (DIP)
|
|
33
|
+
* - CircularDependencyRule: Import cycles (architectural)
|
|
34
|
+
* - FatInterfaceRule: Interfaces with too many methods (ISP)
|
|
35
|
+
*
|
|
36
|
+
* @see {@link DIPViolationRule} for the DIP implementation
|
|
37
|
+
* @see {@link SingleResponsibilityRule} for the SRP implementation
|
|
38
|
+
* @see {@link GodSwitchTransformRule} for the God Switch transformation
|
|
39
|
+
*/
|
|
40
|
+
export declare class SolidPlugin implements Plugin {
|
|
41
|
+
/**
|
|
42
|
+
* Unique plugin identifier.
|
|
43
|
+
*/
|
|
44
|
+
readonly name = "@angular-modernizer/plugin-solid";
|
|
45
|
+
/**
|
|
46
|
+
* Plugin version (from package.json).
|
|
47
|
+
*/
|
|
48
|
+
readonly version = "0.1.0";
|
|
49
|
+
/**
|
|
50
|
+
* Plugin description.
|
|
51
|
+
*/
|
|
52
|
+
readonly description = "Provides SOLID principles analysis for architectural violations";
|
|
53
|
+
/**
|
|
54
|
+
* Plugin author.
|
|
55
|
+
*/
|
|
56
|
+
readonly author = "Angular Modernization Platform";
|
|
57
|
+
/**
|
|
58
|
+
* Initialize the plugin.
|
|
59
|
+
*
|
|
60
|
+
* @param _kernel - The Kernel instance for accessing infrastructure
|
|
61
|
+
*/
|
|
62
|
+
initialize(_kernel: IKernel): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Get all analysis rules provided by this plugin.
|
|
65
|
+
*
|
|
66
|
+
* @returns Array of analysis rules for SOLID violations
|
|
67
|
+
*/
|
|
68
|
+
getAnalysisRules(): AnalysisRule[];
|
|
69
|
+
/**
|
|
70
|
+
* Get all transformation rules provided by this plugin.
|
|
71
|
+
*
|
|
72
|
+
* @returns Array of transformation rules for SOLID violations
|
|
73
|
+
*/
|
|
74
|
+
getTransformRules(): TransformRule[];
|
|
75
|
+
/**
|
|
76
|
+
* Get all validation rules provided by this plugin.
|
|
77
|
+
*
|
|
78
|
+
* @returns Empty array (no validation rules yet)
|
|
79
|
+
*/
|
|
80
|
+
getValidationRules(): ValidationRule[];
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=solid-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid-plugin.d.ts","sourceRoot":"","sources":["../src/solid-plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,MAAM,EACN,YAAY,EACZ,aAAa,EACb,cAAc,EACd,OAAO,EACR,MAAM,mCAAmC,CAAC;AAW3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,WAAY,YAAW,MAAM;IACxC;;OAEG;IACH,SAAgB,IAAI,sCAAsC;IAE1D;;OAEG;IACH,SAAgB,OAAO,WAAW;IAElC;;OAEG;IACH,SAAgB,WAAW,qEACyC;IAEpE;;OAEG;IACH,SAAgB,MAAM,oCAAoC;IAE1D;;;;OAIG;IACG,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjD;;;;OAIG;IACH,gBAAgB,IAAI,YAAY,EAAE;IAYlC;;;;OAIG;IACH,iBAAiB,IAAI,aAAa,EAAE;IAOpC;;;;OAIG;IACH,kBAAkB,IAAI,cAAc,EAAE;CAIvC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @angular-modernizer/plugin-solid - Main Plugin
|
|
4
|
+
*
|
|
5
|
+
* The main entry point for the SOLID principles analysis plugin.
|
|
6
|
+
* Provides analysis rules for detecting SOLID principle violations.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SolidPlugin = void 0;
|
|
10
|
+
const dip_violation_rule_js_1 = require("./rules/dip-violation.rule.js");
|
|
11
|
+
const srp_violation_rule_js_1 = require("./rules/srp-violation.rule.js");
|
|
12
|
+
const lsp_violation_rule_js_1 = require("./rules/lsp-violation.rule.js");
|
|
13
|
+
const ocp_violation_rule_js_1 = require("./rules/ocp-violation.rule.js");
|
|
14
|
+
const isp_violation_rule_js_1 = require("./rules/isp-violation.rule.js");
|
|
15
|
+
const god_switch_analysis_rule_js_1 = require("./rules/god-switch-analysis.rule.js");
|
|
16
|
+
const god_switch_transform_rule_js_1 = require("./transform-rules/god-switch-transform.rule.js");
|
|
17
|
+
const service_dip_violation_transform_rule_js_1 = require("./transform-rules/service-dip-violation.transform.rule.js");
|
|
18
|
+
const service_dip_violation_analysis_rule_js_1 = require("./rules/service-dip-violation.analysis.rule.js");
|
|
19
|
+
/**
|
|
20
|
+
* SOLID Principles Analysis Plugin
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* This plugin provides analysis rules for detecting violations of SOLID principles
|
|
24
|
+
* in Angular applications. It focuses on architectural issues that can lead to
|
|
25
|
+
* maintainability problems.
|
|
26
|
+
*
|
|
27
|
+
* ## Current Rules
|
|
28
|
+
*
|
|
29
|
+
* ### Analysis Rules
|
|
30
|
+
* - {@link DIPViolationRule}: Detects direct service instantiation (DIP violation)
|
|
31
|
+
* - {@link ServiceDipViolationRule}: Detects concrete constructor injection instead of interfaces (DIP violation)
|
|
32
|
+
* - {@link SingleResponsibilityRule}: Detects classes with too many responsibilities (SRP violation)
|
|
33
|
+
* - {@link LSPViolationRule}: Detects inheritance and interface implementation issues (LSP violation)
|
|
34
|
+
* - {@link OCPViolationRule}: Detects code that violates the Open/Closed Principle (OCP violation)
|
|
35
|
+
* - {@link ISPViolationRule}: Detects interface segregation violations (ISP violation)
|
|
36
|
+
* - {@link GodSwitchAnalysisRule}: Detects large switch statements (God Switch anti-pattern)
|
|
37
|
+
*
|
|
38
|
+
* ### Transform Rules
|
|
39
|
+
* - {@link GodSwitchTransformRule}: Transforms God Switch violations into Factory Pattern implementations
|
|
40
|
+
*
|
|
41
|
+
* ## Future Rules (Planned)
|
|
42
|
+
*
|
|
43
|
+
* - MissingInterfaceRule: Services without interfaces (DIP)
|
|
44
|
+
* - CircularDependencyRule: Import cycles (architectural)
|
|
45
|
+
* - FatInterfaceRule: Interfaces with too many methods (ISP)
|
|
46
|
+
*
|
|
47
|
+
* @see {@link DIPViolationRule} for the DIP implementation
|
|
48
|
+
* @see {@link SingleResponsibilityRule} for the SRP implementation
|
|
49
|
+
* @see {@link GodSwitchTransformRule} for the God Switch transformation
|
|
50
|
+
*/
|
|
51
|
+
class SolidPlugin {
|
|
52
|
+
/**
|
|
53
|
+
* Unique plugin identifier.
|
|
54
|
+
*/
|
|
55
|
+
name = '@angular-modernizer/plugin-solid';
|
|
56
|
+
/**
|
|
57
|
+
* Plugin version (from package.json).
|
|
58
|
+
*/
|
|
59
|
+
version = '0.1.0';
|
|
60
|
+
/**
|
|
61
|
+
* Plugin description.
|
|
62
|
+
*/
|
|
63
|
+
description = 'Provides SOLID principles analysis for architectural violations';
|
|
64
|
+
/**
|
|
65
|
+
* Plugin author.
|
|
66
|
+
*/
|
|
67
|
+
author = 'Angular Modernization Platform';
|
|
68
|
+
/**
|
|
69
|
+
* Initialize the plugin.
|
|
70
|
+
*
|
|
71
|
+
* @param _kernel - The Kernel instance for accessing infrastructure
|
|
72
|
+
*/
|
|
73
|
+
async initialize(_kernel) {
|
|
74
|
+
// No initialization needed for now
|
|
75
|
+
// Future: Load configuration, register analyzers, etc.
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get all analysis rules provided by this plugin.
|
|
79
|
+
*
|
|
80
|
+
* @returns Array of analysis rules for SOLID violations
|
|
81
|
+
*/
|
|
82
|
+
getAnalysisRules() {
|
|
83
|
+
return [
|
|
84
|
+
new dip_violation_rule_js_1.DIPViolationRule(),
|
|
85
|
+
new srp_violation_rule_js_1.SingleResponsibilityRule(),
|
|
86
|
+
new lsp_violation_rule_js_1.LSPViolationRule(),
|
|
87
|
+
new ocp_violation_rule_js_1.OCPViolationRule(),
|
|
88
|
+
new isp_violation_rule_js_1.ISPViolationRule(),
|
|
89
|
+
new god_switch_analysis_rule_js_1.GodSwitchAnalysisRule(),
|
|
90
|
+
new service_dip_violation_analysis_rule_js_1.ServiceDipViolationRule(),
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get all transformation rules provided by this plugin.
|
|
95
|
+
*
|
|
96
|
+
* @returns Array of transformation rules for SOLID violations
|
|
97
|
+
*/
|
|
98
|
+
getTransformRules() {
|
|
99
|
+
return [
|
|
100
|
+
new god_switch_transform_rule_js_1.GodSwitchTransformRule(),
|
|
101
|
+
new service_dip_violation_transform_rule_js_1.ServiceDipViolationTransformRule(),
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get all validation rules provided by this plugin.
|
|
106
|
+
*
|
|
107
|
+
* @returns Empty array (no validation rules yet)
|
|
108
|
+
*/
|
|
109
|
+
getValidationRules() {
|
|
110
|
+
// Future: Add validation rules to verify fixes
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.SolidPlugin = SolidPlugin;
|
|
115
|
+
//# sourceMappingURL=solid-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid-plugin.js","sourceRoot":"","sources":["../src/solid-plugin.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AASH,yEAAiE;AACjE,yEAAyE;AACzE,yEAAiE;AACjE,yEAAiE;AACjE,yEAAiE;AACjE,qFAA4E;AAC5E,iGAAwF;AACxF,uHAA6G;AAC7G,2GAAyF;AAEzF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAa,WAAW;IACtB;;OAEG;IACa,IAAI,GAAG,kCAAkC,CAAC;IAE1D;;OAEG;IACa,OAAO,GAAG,OAAO,CAAC;IAElC;;OAEG;IACa,WAAW,GACzB,iEAAiE,CAAC;IAEpE;;OAEG;IACa,MAAM,GAAG,gCAAgC,CAAC;IAE1D;;;;OAIG;IACH,KAAK,CAAC,UAAU,CAAC,OAAgB;QAC/B,mCAAmC;QACnC,uDAAuD;IACzD,CAAC;IAED;;;;OAIG;IACH,gBAAgB;QACd,OAAO;YACL,IAAI,wCAAgB,EAAE;YACtB,IAAI,gDAAwB,EAAE;YAC9B,IAAI,wCAAgB,EAAE;YACtB,IAAI,wCAAgB,EAAE;YACtB,IAAI,wCAAgB,EAAE;YACtB,IAAI,mDAAqB,EAAE;YAC3B,IAAI,gEAAuB,EAAE;SAC9B,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,iBAAiB;QACf,OAAO;YACL,IAAI,qDAAsB,EAAE;YAC5B,IAAI,0EAAgC,EAAE;SACvC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,kBAAkB;QAChB,+CAA+C;QAC/C,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAtED,kCAsEC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/plugin-solid - God Switch 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 converts large switch statements into maintainable Factory Pattern implementations.
|
|
8
|
+
*
|
|
9
|
+
* **Problem:**
|
|
10
|
+
* Large switch statements (10+ cases) violate SOLID principles:
|
|
11
|
+
* - Open/Closed Principle: Adding new cases requires modifying the switch
|
|
12
|
+
* - Single Responsibility: Switch handles multiple concerns
|
|
13
|
+
* - Difficult to test, maintain, and extend
|
|
14
|
+
*
|
|
15
|
+
* **Solution:**
|
|
16
|
+
* Transforms God Switch into Factory Pattern using Strategy pattern:
|
|
17
|
+
* 1. Extract each case into a separate Strategy class
|
|
18
|
+
* 2. Generate a Factory class to create strategy instances
|
|
19
|
+
* 3. Replace switch statement with factory call
|
|
20
|
+
*
|
|
21
|
+
* **Before:**
|
|
22
|
+
* ```typescript
|
|
23
|
+
* switch (type) {
|
|
24
|
+
* case 'A':
|
|
25
|
+
* return handleA();
|
|
26
|
+
* case 'B':
|
|
27
|
+
* return handleB();
|
|
28
|
+
* // ... 10+ more cases
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* **After:**
|
|
33
|
+
* ```typescript
|
|
34
|
+
* interface TypeStrategy {
|
|
35
|
+
* execute(): Result;
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* class AStrategy implements TypeStrategy {
|
|
39
|
+
* execute(): Result { return handleA(); }
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* class TypeFactory {
|
|
43
|
+
* createStrategy(type: string): TypeStrategy {
|
|
44
|
+
* const strategies = { A: AStrategy, B: BStrategy, ... };
|
|
45
|
+
* return new strategies[type]();
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* const strategy = factory.createStrategy(type);
|
|
50
|
+
* return strategy.execute();
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* **Configuration:**
|
|
54
|
+
* ```json
|
|
55
|
+
* {
|
|
56
|
+
* "transformationType": "god-switch-transform",
|
|
57
|
+
* "godSwitch": {
|
|
58
|
+
* "minCaseCount": 10,
|
|
59
|
+
* "generateInterfaces": true,
|
|
60
|
+
* "generateFactory": true,
|
|
61
|
+
* "strategyNamingPattern": "{CaseValue}Strategy",
|
|
62
|
+
* "factoryNamingPattern": "{SwitchExpression}Factory"
|
|
63
|
+
* }
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @see GodSwitchTransformOrchestrator for detailed transformation logic
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Transformation triggered via MCP tool or programmatic API
|
|
71
|
+
* const rule = new GodSwitchTransformRule();
|
|
72
|
+
* const result = await rule.transform(context);
|
|
73
|
+
*
|
|
74
|
+
* if (result.modified) {
|
|
75
|
+
* console.info('Successfully transformed God Switch to Factory Pattern');
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare class GodSwitchTransformRule implements TransformRule {
|
|
80
|
+
/**
|
|
81
|
+
* Unique identifier following plugin-name:rule-name convention.
|
|
82
|
+
*/
|
|
83
|
+
readonly id = "solid:god-switch-transform";
|
|
84
|
+
/**
|
|
85
|
+
* Human-readable name for the transformation.
|
|
86
|
+
*/
|
|
87
|
+
readonly name = "God Switch to Factory Pattern";
|
|
88
|
+
/**
|
|
89
|
+
* Detailed description of the transformation's purpose and behavior.
|
|
90
|
+
*/
|
|
91
|
+
readonly description = "Transforms large switch statements into maintainable Factory Pattern implementations using the Strategy pattern";
|
|
92
|
+
/**
|
|
93
|
+
* Category indicating this is a code restructuring transformation.
|
|
94
|
+
*/
|
|
95
|
+
readonly category = "refactoring";
|
|
96
|
+
/**
|
|
97
|
+
* Tags for discoverability and filtering.
|
|
98
|
+
*/
|
|
99
|
+
readonly tags: string[];
|
|
100
|
+
/**
|
|
101
|
+
* Orchestrator instance that performs the actual transformation logic.
|
|
102
|
+
* Following the "Thin Rule, Thick Orchestrator" pattern.
|
|
103
|
+
*/
|
|
104
|
+
private readonly orchestrator;
|
|
105
|
+
/**
|
|
106
|
+
* Transforms God Switch violations into Factory Pattern implementations.
|
|
107
|
+
*
|
|
108
|
+
* **Process:**
|
|
109
|
+
* 1. Validates transformation type from configuration
|
|
110
|
+
* 2. Captures initial source file state
|
|
111
|
+
* 3. Delegates to orchestrator for transformation
|
|
112
|
+
* 4. Detects modifications by comparing file state
|
|
113
|
+
* 5. Returns structured result with modification status
|
|
114
|
+
*
|
|
115
|
+
* **Idempotency:**
|
|
116
|
+
* Running multiple times on the same file is safe - the orchestrator
|
|
117
|
+
* checks for existing factory implementations and skips already-transformed switches.
|
|
118
|
+
*
|
|
119
|
+
* **Atomicity:**
|
|
120
|
+
* The orchestrator uses backup/rollback mechanisms to ensure all-or-nothing semantics.
|
|
121
|
+
* If any step fails, the source file is restored to its original state.
|
|
122
|
+
*
|
|
123
|
+
* @param context - Transform context containing source file, configuration, and API access
|
|
124
|
+
* @returns Promise resolving to transformation result with modification status and message
|
|
125
|
+
*/
|
|
126
|
+
transform(context: TransformContext<PublicApi>): Promise<TransformResult>;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=god-switch-transform.rule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"god-switch-transform.rule.d.ts","sourceRoot":"","sources":["../../src/transform-rules/god-switch-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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AACH,qBAAa,sBAAuB,YAAW,aAAa;IAC1D;;OAEG;IACH,QAAQ,CAAC,EAAE,gCAAgC;IAE3C;;OAEG;IACH,QAAQ,CAAC,IAAI,mCAAmC;IAEhD;;OAEG;IACH,QAAQ,CAAC,WAAW,qHACgG;IAEpH;;OAEG;IACH,QAAQ,CAAC,QAAQ,iBAAiB;IAElC;;OAEG;IACH,QAAQ,CAAC,IAAI,WAOX;IAEF;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAwC;IAErE;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,SAAS,CACb,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,GACnC,OAAO,CAAC,eAAe,CAAC;CAwC5B"}
|