@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.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +835 -0
  3. package/dist/index.d.ts +21 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +37 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/orchestrators/god-switch-transform-orchestrator.d.ts +350 -0
  8. package/dist/orchestrators/god-switch-transform-orchestrator.d.ts.map +1 -0
  9. package/dist/orchestrators/god-switch-transform-orchestrator.js +1165 -0
  10. package/dist/orchestrators/god-switch-transform-orchestrator.js.map +1 -0
  11. package/dist/orchestrators/service-dip-violation-transform.orchestrator.d.ts +72 -0
  12. package/dist/orchestrators/service-dip-violation-transform.orchestrator.d.ts.map +1 -0
  13. package/dist/orchestrators/service-dip-violation-transform.orchestrator.js +243 -0
  14. package/dist/orchestrators/service-dip-violation-transform.orchestrator.js.map +1 -0
  15. package/dist/rules/dip-violation.rule.d.ts +54 -0
  16. package/dist/rules/dip-violation.rule.d.ts.map +1 -0
  17. package/dist/rules/dip-violation.rule.js +156 -0
  18. package/dist/rules/dip-violation.rule.js.map +1 -0
  19. package/dist/rules/god-switch-analysis.rule.d.ts +73 -0
  20. package/dist/rules/god-switch-analysis.rule.d.ts.map +1 -0
  21. package/dist/rules/god-switch-analysis.rule.js +174 -0
  22. package/dist/rules/god-switch-analysis.rule.js.map +1 -0
  23. package/dist/rules/isp-violation.rule.d.ts +62 -0
  24. package/dist/rules/isp-violation.rule.d.ts.map +1 -0
  25. package/dist/rules/isp-violation.rule.js +250 -0
  26. package/dist/rules/isp-violation.rule.js.map +1 -0
  27. package/dist/rules/lsp-violation.rule.d.ts +57 -0
  28. package/dist/rules/lsp-violation.rule.d.ts.map +1 -0
  29. package/dist/rules/lsp-violation.rule.js +321 -0
  30. package/dist/rules/lsp-violation.rule.js.map +1 -0
  31. package/dist/rules/ocp-violation.rule.d.ts +69 -0
  32. package/dist/rules/ocp-violation.rule.d.ts.map +1 -0
  33. package/dist/rules/ocp-violation.rule.js +204 -0
  34. package/dist/rules/ocp-violation.rule.js.map +1 -0
  35. package/dist/rules/service-dip-violation.analysis.rule.d.ts +85 -0
  36. package/dist/rules/service-dip-violation.analysis.rule.d.ts.map +1 -0
  37. package/dist/rules/service-dip-violation.analysis.rule.js +217 -0
  38. package/dist/rules/service-dip-violation.analysis.rule.js.map +1 -0
  39. package/dist/rules/srp-violation.rule.d.ts +71 -0
  40. package/dist/rules/srp-violation.rule.d.ts.map +1 -0
  41. package/dist/rules/srp-violation.rule.js +307 -0
  42. package/dist/rules/srp-violation.rule.js.map +1 -0
  43. package/dist/solid-plugin.d.ts +82 -0
  44. package/dist/solid-plugin.d.ts.map +1 -0
  45. package/dist/solid-plugin.js +115 -0
  46. package/dist/solid-plugin.js.map +1 -0
  47. package/dist/transform-rules/god-switch-transform.rule.d.ts +128 -0
  48. package/dist/transform-rules/god-switch-transform.rule.d.ts.map +1 -0
  49. package/dist/transform-rules/god-switch-transform.rule.js +167 -0
  50. package/dist/transform-rules/god-switch-transform.rule.js.map +1 -0
  51. package/dist/transform-rules/service-dip-violation.transform.rule.d.ts +75 -0
  52. package/dist/transform-rules/service-dip-violation.transform.rule.d.ts.map +1 -0
  53. package/dist/transform-rules/service-dip-violation.transform.rule.js +115 -0
  54. package/dist/transform-rules/service-dip-violation.transform.rule.js.map +1 -0
  55. package/package.json +59 -0
  56. package/src/index.ts +30 -0
  57. package/src/orchestrators/god-switch-transform-orchestrator.ts +1562 -0
  58. package/src/orchestrators/service-dip-violation-transform.orchestrator.ts +331 -0
  59. package/src/rules/dip-violation.rule.ts +194 -0
  60. package/src/rules/god-switch-analysis.rule.ts +209 -0
  61. package/src/rules/isp-violation.rule.ts +315 -0
  62. package/src/rules/lsp-violation.rule.ts +393 -0
  63. package/src/rules/ocp-violation.rule.ts +264 -0
  64. package/src/rules/service-dip-violation.analysis.rule.ts +285 -0
  65. package/src/rules/srp-violation.rule.ts +366 -0
  66. package/src/solid-plugin.ts +127 -0
  67. package/src/transform-rules/god-switch-transform.rule.ts +189 -0
  68. package/src/transform-rules/service-dip-violation.transform.rule.ts +134 -0
@@ -0,0 +1,85 @@
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
+ import type { AnalysisRule, AnalysisContext, AnalysisResult } from '@angular-modernizer/plugin-system';
18
+ export interface ServiceDipViolationConfig {
19
+ /**
20
+ * When true, only report violations that cross architectural layer boundaries.
21
+ * Layers are inferred from path segments: shared, features, core, lib, app, config.
22
+ * Default: false (report all concrete constructor injections).
23
+ */
24
+ crossLayerOnly?: boolean;
25
+ }
26
+ export interface ServiceDipViolationMetadata {
27
+ violationType: 'concrete-injection';
28
+ injectedClass: string;
29
+ injectingClass: string;
30
+ parameterName: string;
31
+ suggestedInterfaceName: string;
32
+ confidence: number;
33
+ isBidirectional: boolean;
34
+ isCrossLayer: boolean;
35
+ injectingLayer?: string;
36
+ injectedLayer?: string;
37
+ }
38
+ /**
39
+ * Service DIP Violation Rule — detects concrete `` constructor injection.
40
+ *
41
+ * Reports when an `` class injects another `` class directly instead
42
+ * of depending on an abstraction (interface). Provides a suggested interface name
43
+ * (`I` + injected class name) and a human-readable suggested fix.
44
+ *
45
+ * @example
46
+ * // Violation detected:
47
+ * class UserService {
48
+ * constructor(private orderService: OrderService) {}
49
+ * }
50
+ *
51
+ * // Suggested fix:
52
+ * class UserService {
53
+ * constructor(private orderService: IOrderService) {}
54
+ * }
55
+ */
56
+ export declare class ServiceDipViolationRule implements AnalysisRule {
57
+ readonly id = "solid:service-dip-violation";
58
+ readonly name = "Service DIP Violation";
59
+ readonly description = "Detects @Injectable classes injecting other @Injectable classes by concrete type instead of interface";
60
+ readonly severity = "warning";
61
+ readonly category = "solid-violation";
62
+ readonly tags: string[];
63
+ private readonly config;
64
+ constructor(config?: ServiceDipViolationConfig);
65
+ analyze(context: AnalysisContext): Promise<AnalysisResult[]>;
66
+ private checkParameter;
67
+ /**
68
+ * Resolves the class declaration that a constructor parameter's type refers to.
69
+ * Uses ts-morph's type checker — works across files within the same Project.
70
+ */
71
+ private resolveServiceDeclaration;
72
+ /**
73
+ * Checks whether a class has an `` decorator.
74
+ * Pattern copied from angular-service-without-injectable.rule.ts.
75
+ */
76
+ private hasInjectableDecorator;
77
+ /**
78
+ * Extracts the architectural layer from a file path by scanning path segments.
79
+ * Path-based fallback adapted from import-direction-violation.rule.ts.
80
+ *
81
+ * Returns undefined when no known layer segment is found.
82
+ */
83
+ private extractLayer;
84
+ }
85
+ //# sourceMappingURL=service-dip-violation.analysis.rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-dip-violation.analysis.rule.d.ts","sourceRoot":"","sources":["../../src/rules/service-dip-violation.analysis.rule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,cAAc,EACf,MAAM,mCAAmC,CAAC;AAE3C,MAAM,WAAW,yBAAyB;IACxC;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,2BAA2B;IAC1C,aAAa,EAAE,oBAAoB,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,uBAAwB,YAAW,YAAY;IAC1D,SAAgB,EAAE,iCAAiC;IACnD,SAAgB,IAAI,2BAA2B;IAC/C,SAAgB,WAAW,2GAC+E;IAC1G,SAAgB,QAAQ,aAAa;IACrC,SAAgB,QAAQ,qBAAqB;IAC7C,SAAgB,IAAI,WAA0D;IAE9E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;gBAEvC,MAAM,GAAE,yBAA8B;IAI5C,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAyClE,OAAO,CAAC,cAAc;IAmEtB;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IAoBjC;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAM9B;;;;;OAKG;IACH,OAAO,CAAC,YAAY;CAqDrB"}
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ /**
3
+ * @angular-modernizer/plugin-solid - Service DIP Violation Rule
4
+ *
5
+ * Detects constructor injection of concrete `` classes instead of interfaces
6
+ * (Dependency Inversion Principle violation).
7
+ *
8
+ * Detection Pattern:
9
+ * - `` class whose constructor parameter type resolves to another `` class
10
+ * - Both the injecting class and the injected type must have ``
11
+ * - Optional: cross-layer detection via path-based layer extraction
12
+ *
13
+ * Sibling to DIPViolationRule (solid:dip-violation-direct-instantiation) which detects
14
+ * `new MyService()` usage. This rule detects `constructor(private svc: ConcreteService)`.
15
+ *
16
+ * TransformRule + Orchestrator is deferred to v2.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.ServiceDipViolationRule = void 0;
20
+ const ts_morph_1 = require("ts-morph");
21
+ /**
22
+ * Service DIP Violation Rule — detects concrete `` constructor injection.
23
+ *
24
+ * Reports when an `` class injects another `` class directly instead
25
+ * of depending on an abstraction (interface). Provides a suggested interface name
26
+ * (`I` + injected class name) and a human-readable suggested fix.
27
+ *
28
+ * @example
29
+ * // Violation detected:
30
+ * class UserService {
31
+ * constructor(private orderService: OrderService) {}
32
+ * }
33
+ *
34
+ * // Suggested fix:
35
+ * class UserService {
36
+ * constructor(private orderService: IOrderService) {}
37
+ * }
38
+ */
39
+ class ServiceDipViolationRule {
40
+ id = 'solid:service-dip-violation';
41
+ name = 'Service DIP Violation';
42
+ description = 'Detects @Injectable classes injecting other @Injectable classes by concrete type instead of interface';
43
+ severity = 'warning';
44
+ category = 'solid-violation';
45
+ tags = ['solid', 'dip', 'interfaces', 'dependency-injection'];
46
+ config;
47
+ constructor(config = {}) {
48
+ this.config = config;
49
+ }
50
+ async analyze(context) {
51
+ const sourceFile = context.sourceFile;
52
+ // Skip declaration files
53
+ if (sourceFile.getFilePath().endsWith('.d.ts')) {
54
+ return [];
55
+ }
56
+ const violations = [];
57
+ const injectingFilePath = sourceFile.getFilePath();
58
+ for (const classDecl of sourceFile.getClasses()) {
59
+ if (!this.hasInjectableDecorator(classDecl)) {
60
+ continue;
61
+ }
62
+ const ctor = classDecl.getConstructors()[0];
63
+ if (!ctor) {
64
+ continue;
65
+ }
66
+ for (const param of ctor.getParameters()) {
67
+ const violation = this.checkParameter(classDecl, param, injectingFilePath, context);
68
+ if (violation) {
69
+ violations.push(violation);
70
+ }
71
+ }
72
+ }
73
+ return violations;
74
+ }
75
+ // ---------------------------------------------------------------------------
76
+ // Core detection
77
+ // ---------------------------------------------------------------------------
78
+ checkParameter(injectingClass, param, injectingFilePath, _context) {
79
+ const injectedDecl = this.resolveServiceDeclaration(param);
80
+ if (!injectedDecl) {
81
+ return null;
82
+ }
83
+ if (!this.hasInjectableDecorator(injectedDecl)) {
84
+ return null;
85
+ }
86
+ const injectedClass = injectedDecl.getName() ?? 'Unknown';
87
+ const injectingClassName = injectingClass.getName() ?? 'Unknown';
88
+ const paramName = param.getName();
89
+ const suggestedInterfaceName = `I${injectedClass}`;
90
+ // Layer information
91
+ const injectedSourceFile = injectedDecl.getSourceFile();
92
+ const injectedFilePath = injectedSourceFile.getFilePath();
93
+ const injectingLayer = this.extractLayer(injectingFilePath);
94
+ const injectedLayer = this.extractLayer(injectedFilePath);
95
+ const isCrossLayer = injectingLayer !== undefined &&
96
+ injectedLayer !== undefined &&
97
+ injectingLayer !== injectedLayer;
98
+ // Apply crossLayerOnly filter
99
+ if (this.config.crossLayerOnly && !isCrossLayer) {
100
+ return null;
101
+ }
102
+ const metadata = {
103
+ violationType: 'concrete-injection',
104
+ injectedClass,
105
+ injectingClass: injectingClassName,
106
+ parameterName: paramName,
107
+ suggestedInterfaceName,
108
+ confidence: 0.95,
109
+ isBidirectional: false,
110
+ isCrossLayer,
111
+ ...(injectingLayer !== undefined ? { injectingLayer } : {}),
112
+ ...(injectedLayer !== undefined ? { injectedLayer } : {}),
113
+ };
114
+ return {
115
+ ruleId: this.id,
116
+ message: `${injectingClassName} injects concrete class ${injectedClass} via constructor. ` +
117
+ `Depend on an interface (${suggestedInterfaceName}) instead.`,
118
+ filePath: injectingFilePath,
119
+ line: param.getStartLineNumber(),
120
+ column: param.getStart() - param.getStartLinePos(),
121
+ suggestedFix: `Extract interface ${suggestedInterfaceName} from ${injectedClass}, ` +
122
+ `add injection token, and replace the parameter type with ${suggestedInterfaceName}.`,
123
+ metadata: metadata,
124
+ };
125
+ }
126
+ // ---------------------------------------------------------------------------
127
+ // Helpers
128
+ // ---------------------------------------------------------------------------
129
+ /**
130
+ * Resolves the class declaration that a constructor parameter's type refers to.
131
+ * Uses ts-morph's type checker — works across files within the same Project.
132
+ */
133
+ resolveServiceDeclaration(param) {
134
+ try {
135
+ const declarations = param.getType().getSymbol()?.getDeclarations();
136
+ if (!declarations || declarations.length === 0) {
137
+ return null;
138
+ }
139
+ for (const decl of declarations) {
140
+ if (ts_morph_1.Node.isClassDeclaration(decl)) {
141
+ return decl;
142
+ }
143
+ }
144
+ return null;
145
+ }
146
+ catch {
147
+ return null;
148
+ }
149
+ }
150
+ /**
151
+ * Checks whether a class has an `` decorator.
152
+ * Pattern copied from angular-service-without-injectable.rule.ts.
153
+ */
154
+ hasInjectableDecorator(classDecl) {
155
+ return classDecl
156
+ .getDecorators()
157
+ .some((decorator) => decorator.getName() === 'Injectable');
158
+ }
159
+ /**
160
+ * Extracts the architectural layer from a file path by scanning path segments.
161
+ * Path-based fallback adapted from import-direction-violation.rule.ts.
162
+ *
163
+ * Returns undefined when no known layer segment is found.
164
+ */
165
+ extractLayer(filePath) {
166
+ const parts = filePath.split('/');
167
+ // Exact segment match (highest confidence)
168
+ const exactLayers = [
169
+ 'shared',
170
+ 'features',
171
+ 'core',
172
+ 'lib',
173
+ 'libs',
174
+ 'app',
175
+ 'config',
176
+ 'environments',
177
+ 'domain',
178
+ ];
179
+ for (let i = parts.length - 1; i >= 0; i--) {
180
+ const part = parts[i]?.toLowerCase();
181
+ if (!part) {
182
+ continue;
183
+ }
184
+ if (exactLayers.includes(part)) {
185
+ return part === 'libs' ? 'lib' : part;
186
+ }
187
+ }
188
+ // Substring match (lower confidence — still useful)
189
+ for (let i = parts.length - 1; i >= 0; i--) {
190
+ const part = parts[i]?.toLowerCase();
191
+ if (!part) {
192
+ continue;
193
+ }
194
+ if (part.includes('shared')) {
195
+ return 'shared';
196
+ }
197
+ if (part.includes('features')) {
198
+ return 'features';
199
+ }
200
+ if (part.includes('core')) {
201
+ return 'core';
202
+ }
203
+ if (part.includes('libs') || part.includes('lib')) {
204
+ return 'lib';
205
+ }
206
+ if (part.includes('app')) {
207
+ return 'app';
208
+ }
209
+ if (part.includes('config') || part.includes('environments')) {
210
+ return 'config';
211
+ }
212
+ }
213
+ return undefined;
214
+ }
215
+ }
216
+ exports.ServiceDipViolationRule = ServiceDipViolationRule;
217
+ //# sourceMappingURL=service-dip-violation.analysis.rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-dip-violation.analysis.rule.js","sourceRoot":"","sources":["../../src/rules/service-dip-violation.analysis.rule.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,uCAIkB;AA6BlB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,uBAAuB;IAClB,EAAE,GAAG,6BAA6B,CAAC;IACnC,IAAI,GAAG,uBAAuB,CAAC;IAC/B,WAAW,GACzB,uGAAuG,CAAC;IAC1F,QAAQ,GAAG,SAAS,CAAC;IACrB,QAAQ,GAAG,iBAAiB,CAAC;IAC7B,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,sBAAsB,CAAC,CAAC;IAE7D,MAAM,CAA4B;IAEnD,YAAY,SAAoC,EAAE;QAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAwB;QACpC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QAEtC,yBAAyB;QACzB,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/C,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,UAAU,GAAqB,EAAE,CAAC;QACxC,MAAM,iBAAiB,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;QAEnD,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE,EAAE,CAAC;YAChD,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC5C,SAAS;YACX,CAAC;YAED,MAAM,IAAI,GAAG,SAAS,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC;YAC5C,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,SAAS;YACX,CAAC;YAED,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;gBACz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;YAC3C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;YACrC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,SAAS;YACX,CAAC;YACD,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC5B,OAAO,QAAQ,CAAC;YAClB,CAAC;YACD,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC9B,OAAO,UAAU,CAAC;YACpB,CAAC;YACD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC1B,OAAO,MAAM,CAAC;YAChB,CAAC;YACD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBAClD,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;gBAC7D,OAAO,QAAQ,CAAC;YAClB,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAxND,0DAwNC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @angular-modernizer/plugin-solid - SRP Violation Rule
3
+ *
4
+ * Detects Single Responsibility Principle violations in classes.
5
+ *
6
+ * Detection Patterns:
7
+ * - Classes with too many methods (configurable threshold, default: 15)
8
+ * - Classes mixing multiple responsibility categories
9
+ *
10
+ * Responsibility Categories:
11
+ * - UI: render, display, show, hide, toggle, open, close
12
+ * - Business: calculate, validate, process, transform, compute
13
+ * - HTTP: fetch, get, post, put, delete, request, call
14
+ * - Data: save, load, store, retrieve, persist, cache
15
+ * - Event: emit, dispatch, trigger, fire, notify, publish
16
+ * - Lifecycle: init, destroy, cleanup, setup, teardown
17
+ *
18
+ * This rule helps enforce the Single Responsibility Principle by identifying
19
+ * classes that are doing too much or handling multiple unrelated concerns.
20
+ *
21
+ * @example
22
+ * // Violation: class mixes HTTP, business, and UI concerns
23
+ * class UserComponent {
24
+ * fetchUsers() {} // HTTP concern
25
+ * calculateTotal() {} // Business concern
26
+ * renderChart() {} // UI concern
27
+ * }
28
+ */
29
+ import type { AnalysisRule, AnalysisContext, AnalysisResult } from '@angular-modernizer/plugin-system';
30
+ /**
31
+ * SRP Violation Rule - detects Single Responsibility Principle violations.
32
+ *
33
+ * This rule implements the Single Responsibility Principle by detecting
34
+ * classes with too many methods or mixed responsibilities.
35
+ */
36
+ export declare class SingleResponsibilityRule implements AnalysisRule {
37
+ readonly id = "solid:srp-single-responsibility-violation";
38
+ readonly name = "Single Responsibility Principle Violation";
39
+ readonly description = "Detects classes with too many methods or mixed responsibilities";
40
+ readonly severity = "warning";
41
+ readonly category = "solid-violation";
42
+ readonly tags: string[];
43
+ /**
44
+ * Default threshold for maximum number of methods in a class.
45
+ */
46
+ private readonly maxMethodsThreshold;
47
+ /**
48
+ * Minimum number of different responsibility categories to flag as mixed.
49
+ */
50
+ private readonly minMixedResponsibilities;
51
+ /**
52
+ * Responsibility categories for method classification.
53
+ */
54
+ private readonly responsibilityCategories;
55
+ analyze(context: AnalysisContext): Promise<AnalysisResult[]>;
56
+ /**
57
+ * Check if a class violates SRP.
58
+ */
59
+ private checkClass;
60
+ /**
61
+ * Detect a single method that mixes ≥4 distinct concern categories AND is ≥20 lines.
62
+ * Scans the full method body text for concern keywords (same categories as class-level).
63
+ */
64
+ private analyzeMethodBodyConcerns;
65
+ /**
66
+ * Analyze the responsibilities of methods in a class.
67
+ * Returns a set of responsibility category names found.
68
+ */
69
+ private analyzeResponsibilities;
70
+ }
71
+ //# sourceMappingURL=srp-violation.rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"srp-violation.rule.d.ts","sourceRoot":"","sources":["../../src/rules/srp-violation.rule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAOH,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,cAAc,EACf,MAAM,mCAAmC,CAAC;AAU3C;;;;;GAKG;AACH,qBAAa,wBAAyB,YAAW,YAAY;IAC3D,SAAgB,EAAE,+CAA+C;IACjE,SAAgB,IAAI,+CAA+C;IACnE,SAAgB,WAAW,qEACyC;IACpE,SAAgB,QAAQ,aAAa;IACrC,SAAgB,QAAQ,qBAAqB;IAC7C,SAAgB,IAAI,WAMlB;IAEF;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAM;IAE1C;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAK;IAE9C;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CA2EvC;IAEI,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAoBlE;;OAEG;IACH,OAAO,CAAC,UAAU;IA+ElB;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IA6DjC;;;OAGG;IACH,OAAO,CAAC,uBAAuB;CAmChC"}