@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,285 +0,0 @@
1
- /**
2
- * @angular-modernizer/plugin-solid - Service DIP Violation Rule
3
- *
4
- * Detects constructor injection of concrete `` classes instead of interfaces
5
- * (Dependency Inversion Principle violation).
6
- *
7
- * Detection Pattern:
8
- * - `` class whose constructor parameter type resolves to another `` class
9
- * - Both the injecting class and the injected type must have ``
10
- * - Optional: cross-layer detection via path-based layer extraction
11
- *
12
- * Sibling to DIPViolationRule (solid:dip-violation-direct-instantiation) which detects
13
- * `new MyService()` usage. This rule detects `constructor(private svc: ConcreteService)`.
14
- *
15
- * TransformRule + Orchestrator is deferred to v2.
16
- */
17
-
18
- import {
19
- Node,
20
- type ClassDeclaration,
21
- type ParameterDeclaration,
22
- } from 'ts-morph';
23
- import type {
24
- AnalysisRule,
25
- AnalysisContext,
26
- AnalysisResult,
27
- } from '@angular-modernizer/plugin-system';
28
-
29
- export interface ServiceDipViolationConfig {
30
- /**
31
- * When true, only report violations that cross architectural layer boundaries.
32
- * Layers are inferred from path segments: shared, features, core, lib, app, config.
33
- * Default: false (report all concrete constructor injections).
34
- */
35
- crossLayerOnly?: boolean;
36
- }
37
-
38
- export interface ServiceDipViolationMetadata {
39
- violationType: 'concrete-injection';
40
- injectedClass: string;
41
- injectingClass: string;
42
- parameterName: string;
43
- suggestedInterfaceName: string;
44
- confidence: number;
45
- isBidirectional: boolean;
46
- isCrossLayer: boolean;
47
- injectingLayer?: string;
48
- injectedLayer?: string;
49
- }
50
-
51
- /**
52
- * Service DIP Violation Rule — detects concrete `` constructor injection.
53
- *
54
- * Reports when an `` class injects another `` class directly instead
55
- * of depending on an abstraction (interface). Provides a suggested interface name
56
- * (`I` + injected class name) and a human-readable suggested fix.
57
- *
58
- * @example
59
- * // Violation detected:
60
- * class UserService {
61
- * constructor(private orderService: OrderService) {}
62
- * }
63
- *
64
- * // Suggested fix:
65
- * class UserService {
66
- * constructor(private orderService: IOrderService) {}
67
- * }
68
- */
69
- export class ServiceDipViolationRule implements AnalysisRule {
70
- public readonly id = 'solid:service-dip-violation';
71
- public readonly name = 'Service DIP Violation';
72
- public readonly description =
73
- 'Detects @Injectable classes injecting other @Injectable classes by concrete type instead of interface';
74
- public readonly severity = 'warning';
75
- public readonly category = 'solid-violation';
76
- public readonly tags = ['solid', 'dip', 'interfaces', 'dependency-injection'];
77
-
78
- private readonly config: ServiceDipViolationConfig;
79
-
80
- constructor(config: ServiceDipViolationConfig = {}) {
81
- this.config = config;
82
- }
83
-
84
- async analyze(context: AnalysisContext): Promise<AnalysisResult[]> {
85
- const sourceFile = context.sourceFile;
86
-
87
- // Skip declaration files
88
- if (sourceFile.getFilePath().endsWith('.d.ts')) {
89
- return [];
90
- }
91
-
92
- const violations: AnalysisResult[] = [];
93
- const injectingFilePath = sourceFile.getFilePath();
94
-
95
- for (const classDecl of sourceFile.getClasses()) {
96
- if (!this.hasInjectableDecorator(classDecl)) {
97
- continue;
98
- }
99
-
100
- const ctor = classDecl.getConstructors()[0];
101
- if (!ctor) {
102
- continue;
103
- }
104
-
105
- for (const param of ctor.getParameters()) {
106
- const violation = this.checkParameter(
107
- classDecl,
108
- param,
109
- injectingFilePath,
110
- context,
111
- );
112
- if (violation) {
113
- violations.push(violation);
114
- }
115
- }
116
- }
117
-
118
- return violations;
119
- }
120
-
121
- // ---------------------------------------------------------------------------
122
- // Core detection
123
- // ---------------------------------------------------------------------------
124
-
125
- private checkParameter(
126
- injectingClass: ClassDeclaration,
127
- param: ParameterDeclaration,
128
- injectingFilePath: string,
129
- _context: AnalysisContext,
130
- ): AnalysisResult | null {
131
- const injectedDecl = this.resolveServiceDeclaration(param);
132
- if (!injectedDecl) {
133
- return null;
134
- }
135
- if (!this.hasInjectableDecorator(injectedDecl)) {
136
- return null;
137
- }
138
-
139
- const injectedClass = injectedDecl.getName() ?? 'Unknown';
140
- const injectingClassName = injectingClass.getName() ?? 'Unknown';
141
- const paramName = param.getName();
142
- const suggestedInterfaceName = `I${injectedClass}`;
143
-
144
- // Layer information
145
- const injectedSourceFile = injectedDecl.getSourceFile();
146
- const injectedFilePath = injectedSourceFile.getFilePath();
147
-
148
- const injectingLayer = this.extractLayer(injectingFilePath);
149
- const injectedLayer = this.extractLayer(injectedFilePath);
150
- const isCrossLayer =
151
- injectingLayer !== undefined &&
152
- injectedLayer !== undefined &&
153
- injectingLayer !== injectedLayer;
154
-
155
- // Apply crossLayerOnly filter
156
- if (this.config.crossLayerOnly && !isCrossLayer) {
157
- return null;
158
- }
159
-
160
- const metadata: ServiceDipViolationMetadata = {
161
- violationType: 'concrete-injection',
162
- injectedClass,
163
- injectingClass: injectingClassName,
164
- parameterName: paramName,
165
- suggestedInterfaceName,
166
- confidence: 0.95,
167
- isBidirectional: false,
168
- isCrossLayer,
169
- ...(injectingLayer !== undefined ? { injectingLayer } : {}),
170
- ...(injectedLayer !== undefined ? { injectedLayer } : {}),
171
- };
172
-
173
- return {
174
- ruleId: this.id,
175
- message:
176
- `${injectingClassName} injects concrete class ${injectedClass} via constructor. ` +
177
- `Depend on an interface (${suggestedInterfaceName}) instead.`,
178
- filePath: injectingFilePath,
179
- line: param.getStartLineNumber(),
180
- column: param.getStart() - param.getStartLinePos(),
181
- suggestedFix:
182
- `Extract interface ${suggestedInterfaceName} from ${injectedClass}, ` +
183
- `add injection token, and replace the parameter type with ${suggestedInterfaceName}.`,
184
- metadata: metadata as unknown as Record<string, unknown>,
185
- };
186
- }
187
-
188
- // ---------------------------------------------------------------------------
189
- // Helpers
190
- // ---------------------------------------------------------------------------
191
-
192
- /**
193
- * Resolves the class declaration that a constructor parameter's type refers to.
194
- * Uses ts-morph's type checker — works across files within the same Project.
195
- */
196
- private resolveServiceDeclaration(
197
- param: ParameterDeclaration,
198
- ): ClassDeclaration | null {
199
- try {
200
- const declarations = param.getType().getSymbol()?.getDeclarations();
201
- if (!declarations || declarations.length === 0) {
202
- return null;
203
- }
204
-
205
- for (const decl of declarations) {
206
- if (Node.isClassDeclaration(decl)) {
207
- return decl;
208
- }
209
- }
210
- return null;
211
- } catch {
212
- return null;
213
- }
214
- }
215
-
216
- /**
217
- * Checks whether a class has an `` decorator.
218
- * Pattern copied from angular-service-without-injectable.rule.ts.
219
- */
220
- private hasInjectableDecorator(classDecl: ClassDeclaration): boolean {
221
- return classDecl
222
- .getDecorators()
223
- .some((decorator) => decorator.getName() === 'Injectable');
224
- }
225
-
226
- /**
227
- * Extracts the architectural layer from a file path by scanning path segments.
228
- * Path-based fallback adapted from import-direction-violation.rule.ts.
229
- *
230
- * Returns undefined when no known layer segment is found.
231
- */
232
- private extractLayer(filePath: string): string | undefined {
233
- const parts = filePath.split('/');
234
-
235
- // Exact segment match (highest confidence)
236
- const exactLayers = [
237
- 'shared',
238
- 'features',
239
- 'core',
240
- 'lib',
241
- 'libs',
242
- 'app',
243
- 'config',
244
- 'environments',
245
- 'domain',
246
- ];
247
- for (let i = parts.length - 1; i >= 0; i--) {
248
- const part = parts[i]?.toLowerCase();
249
- if (!part) {
250
- continue;
251
- }
252
- if (exactLayers.includes(part)) {
253
- return part === 'libs' ? 'lib' : part;
254
- }
255
- }
256
-
257
- // Substring match (lower confidence — still useful)
258
- for (let i = parts.length - 1; i >= 0; i--) {
259
- const part = parts[i]?.toLowerCase();
260
- if (!part) {
261
- continue;
262
- }
263
- if (part.includes('shared')) {
264
- return 'shared';
265
- }
266
- if (part.includes('features')) {
267
- return 'features';
268
- }
269
- if (part.includes('core')) {
270
- return 'core';
271
- }
272
- if (part.includes('libs') || part.includes('lib')) {
273
- return 'lib';
274
- }
275
- if (part.includes('app')) {
276
- return 'app';
277
- }
278
- if (part.includes('config') || part.includes('environments')) {
279
- return 'config';
280
- }
281
- }
282
-
283
- return undefined;
284
- }
285
- }