@angular-modernizer/plugin-solid 1.0.0 → 1.2.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/README.md +34 -48
- package/dist/index.d.ts +15 -4
- package/dist/index.js +14 -3
- package/dist/orchestrators/god-switch-transform-orchestrator.d.ts +3 -14
- package/dist/orchestrators/god-switch-transform-orchestrator.js +1 -13
- package/dist/orchestrators/service-dip-violation-transform.orchestrator.d.ts +38 -24
- package/dist/orchestrators/service-dip-violation-transform.orchestrator.js +28 -24
- package/dist/rules/dip-violation.rule.d.ts +14 -17
- package/dist/rules/dip-violation.rule.js +16 -19
- package/dist/rules/god-switch-analysis.rule.d.ts +13 -26
- package/dist/rules/god-switch-analysis.rule.js +15 -28
- package/dist/rules/isp-violation.rule.d.ts +12 -17
- package/dist/rules/isp-violation.rule.js +14 -19
- package/dist/rules/lsp-violation.rule.d.ts +15 -21
- package/dist/rules/lsp-violation.rule.js +17 -23
- package/dist/rules/ocp-violation.rule.d.ts +9 -18
- package/dist/rules/ocp-violation.rule.js +11 -20
- package/dist/rules/service-dip-violation.analysis.rule.d.ts +28 -19
- package/dist/rules/service-dip-violation.analysis.rule.js +13 -20
- package/dist/rules/srp-violation.rule.d.ts +19 -29
- package/dist/rules/srp-violation.rule.js +21 -31
- package/dist/solid-plugin.d.ts +3 -14
- package/dist/solid-plugin.js +3 -14
- package/dist/transform-rules/god-switch-transform.rule.d.ts +0 -3
- package/dist/transform-rules/god-switch-transform.rule.js +0 -3
- package/dist/transform-rules/service-dip-violation.transform.rule.d.ts +0 -3
- package/dist/transform-rules/service-dip-violation.transform.rule.js +0 -3
- package/package.json +5 -11
package/README.md
CHANGED
|
@@ -42,14 +42,14 @@ Detects classes with more than 15 public methods or mixed responsibility categor
|
|
|
42
42
|
### DIPViolationRule
|
|
43
43
|
|
|
44
44
|
**Rule ID:** `solid:dip-violation-direct-instantiation`
|
|
45
|
-
**Severity:**
|
|
45
|
+
**Severity:** Warning
|
|
46
46
|
|
|
47
47
|
Detects direct instantiation of services and the service locator anti-pattern.
|
|
48
48
|
|
|
49
49
|
Detection patterns:
|
|
50
50
|
- `new MyService()` in constructors or methods
|
|
51
51
|
- `new MyRepository()` in component methods
|
|
52
|
-
- Direct instantiation of classes ending with
|
|
52
|
+
- Direct instantiation of classes ending with `Service`, `Repository`, `Store`, `Manager`, `Api`, `Client`, `Provider`, `Facade`, `Helper`, `Util` or `Utils`
|
|
53
53
|
- `injector.get()` service locator calls
|
|
54
54
|
|
|
55
55
|
**Before:**
|
|
@@ -105,12 +105,12 @@ export class UserComponent {
|
|
|
105
105
|
|
|
106
106
|
---
|
|
107
107
|
|
|
108
|
-
###
|
|
108
|
+
### ServiceDipViolationRule
|
|
109
109
|
|
|
110
|
-
**Rule ID:** `solid:dip-violation
|
|
110
|
+
**Rule ID:** `solid:service-dip-violation`
|
|
111
111
|
**Severity:** Warning
|
|
112
112
|
|
|
113
|
-
Detects constructor parameters that inject concrete `@Injectable` classes rather than interfaces. Has a transform counterpart (`
|
|
113
|
+
Detects constructor parameters of `@Injectable` classes that inject concrete `@Injectable` classes rather than interfaces. The constructor option `crossLayerOnly` limits the results to injections between different path-based layers (`shared`, `features`, `core`, `lib`, `app`, `config`). Has a transform counterpart (`ServiceDipViolationTransformRule`) in this plugin that creates an `I{ClassName}` interface and `InjectionToken` in the service file, and updates the consuming file with an `@Inject` decorator.
|
|
114
114
|
|
|
115
115
|
---
|
|
116
116
|
|
|
@@ -235,12 +235,14 @@ const context = ContextFactory.createAnalysisContext({
|
|
|
235
235
|
|
|
236
236
|
---
|
|
237
237
|
|
|
238
|
-
###
|
|
238
|
+
### ISPViolationRule
|
|
239
|
+
|
|
240
|
+
**Rule ID:** `solid:isp-violation`
|
|
241
|
+
**Severity:** Warning
|
|
239
242
|
|
|
240
|
-
|
|
241
|
-
**Severity:** Error
|
|
243
|
+
Detects interfaces with more than 5 methods, interfaces whose members mix concerns (UI, data, business logic), classes implementing more than 3 interfaces, and classes that implement an interface but declare no methods.
|
|
242
244
|
|
|
243
|
-
|
|
245
|
+
`solid:import-direction-violation` and `solid:circular-dependency` use the `solid:` prefix but belong to `@angular-modernizer/plugin-architecture`.
|
|
244
246
|
|
|
245
247
|
---
|
|
246
248
|
|
|
@@ -249,7 +251,7 @@ Detects imports that violate the configured layer direction rules. Requires `lay
|
|
|
249
251
|
**Rule ID:** `solid:ocp-violation`
|
|
250
252
|
**Severity:** Warning
|
|
251
253
|
|
|
252
|
-
Detects
|
|
254
|
+
Detects methods that require modification to extend behavior: switch statements with more than 5 cases, if/else chains with more than 4 branches, and methods with more than 4 parameters.
|
|
253
255
|
|
|
254
256
|
---
|
|
255
257
|
|
|
@@ -258,7 +260,7 @@ Detects classes that require modification to extend behavior, including type-che
|
|
|
258
260
|
**Rule ID:** `solid:lsp-violation`
|
|
259
261
|
**Severity:** Warning
|
|
260
262
|
|
|
261
|
-
Detects
|
|
263
|
+
Detects classes that break substitutability: missing members of implemented interfaces, unimplemented abstract methods, abstract method implementations that throw "not implemented", and `instanceof` checks (3 or more in one method count as excessive).
|
|
262
264
|
|
|
263
265
|
---
|
|
264
266
|
|
|
@@ -418,6 +420,15 @@ Transformation guarantees:
|
|
|
418
420
|
|
|
419
421
|
---
|
|
420
422
|
|
|
423
|
+
### ServiceDipViolationTransformRule
|
|
424
|
+
|
|
425
|
+
**Rule ID:** `solid:service-dip-violation-transform`
|
|
426
|
+
**Transformation Type:** `service-dip-violation-transform`
|
|
427
|
+
|
|
428
|
+
Fixes `solid:service-dip-violation` findings. For each constructor parameter of an `@Injectable` class that injects a concrete `@Injectable` class, it adds an `I{ClassName}` interface (public method signatures) and a `{CLASS_NAME}_TOKEN` `InjectionToken` to the injected service file, changes the parameter type to the interface, adds `@Inject(TOKEN)` and the needed imports. Parameters that already have `@Inject` are skipped; an existing interface is not created again.
|
|
429
|
+
|
|
430
|
+
---
|
|
431
|
+
|
|
421
432
|
## Factory Pattern Comparison
|
|
422
433
|
|
|
423
434
|
| Aspect | God Switch | Factory Pattern |
|
|
@@ -577,34 +588,13 @@ console.log('Low:', bySeverity.low || 0);
|
|
|
577
588
|
|
|
578
589
|
## Configuration Options
|
|
579
590
|
|
|
580
|
-
|
|
591
|
+
Most rules use fixed thresholds. Configurable are:
|
|
581
592
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
*/
|
|
588
|
-
serviceSuffixes?: string[];
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* Exclude patterns for files/directories
|
|
592
|
-
* Default: ['**/node_modules/**', '**/dist/**']
|
|
593
|
-
*/
|
|
594
|
-
excludePatterns?: string[];
|
|
595
|
-
|
|
596
|
-
/**
|
|
597
|
-
* Include auto-fix suggestions
|
|
598
|
-
* Default: true
|
|
599
|
-
*/
|
|
600
|
-
includeAutoFixes?: boolean;
|
|
601
|
-
|
|
602
|
-
/**
|
|
603
|
-
* Custom service detection patterns
|
|
604
|
-
*/
|
|
605
|
-
customPatterns?: RegExp[];
|
|
606
|
-
}
|
|
607
|
-
```
|
|
593
|
+
| Rule | Option | Default | Source |
|
|
594
|
+
|-|-|-|-|
|
|
595
|
+
| `solid:god-switch` | `solid.godSwitch.maxCases` | `10` | `context.config` |
|
|
596
|
+
| `solid:god-switch-transform` | `godSwitch.minCaseCount`, `generateInterfaces`, `generateFactory`, `strategyNamingPattern`, `factoryNamingPattern` | `10`, `true`, `true`, `'{CaseValue}Strategy'`, `'{SwitchExpression}Factory'` | `context.config` |
|
|
597
|
+
| `solid:service-dip-violation` | `crossLayerOnly` | `false` | `ServiceDipViolationRule` constructor |
|
|
608
598
|
|
|
609
599
|
### Example Configuration
|
|
610
600
|
|
|
@@ -612,12 +602,9 @@ interface DIPViolationConfig {
|
|
|
612
602
|
const context = ContextFactory.createAnalysisContext({
|
|
613
603
|
sourceFile,
|
|
614
604
|
project,
|
|
615
|
-
api: createPublicApi(),
|
|
605
|
+
api: createPublicApi(project),
|
|
616
606
|
config: {
|
|
617
|
-
|
|
618
|
-
excludePatterns: ['**/generated/**', '**/vendor/**'],
|
|
619
|
-
includeAutoFixes: true,
|
|
620
|
-
customPatterns: [/.*Client$/, /.*Provider$/],
|
|
607
|
+
solid: { godSwitch: { maxCases: 15 } },
|
|
621
608
|
},
|
|
622
609
|
});
|
|
623
610
|
```
|
|
@@ -631,20 +618,20 @@ packages/plugin-solid/
|
|
|
631
618
|
src/
|
|
632
619
|
rules/
|
|
633
620
|
dip-violation.rule.ts
|
|
634
|
-
srp-
|
|
621
|
+
srp-violation.rule.ts
|
|
635
622
|
god-switch-analysis.rule.ts
|
|
636
623
|
ocp-violation.rule.ts
|
|
637
624
|
lsp-violation.rule.ts
|
|
638
|
-
|
|
639
|
-
dip-violation
|
|
625
|
+
isp-violation.rule.ts
|
|
626
|
+
service-dip-violation.analysis.rule.ts
|
|
640
627
|
orchestrators/
|
|
641
628
|
god-switch-transform-orchestrator.ts
|
|
642
629
|
service-dip-violation-transform.orchestrator.ts
|
|
643
630
|
transform-rules/
|
|
644
631
|
god-switch-transform.rule.ts
|
|
632
|
+
service-dip-violation.transform.rule.ts
|
|
645
633
|
solid-plugin.ts
|
|
646
634
|
index.ts
|
|
647
|
-
types.ts
|
|
648
635
|
__tests__/
|
|
649
636
|
rules/
|
|
650
637
|
dip-violation.rule.test.ts
|
|
@@ -830,6 +817,5 @@ class SolidPlugin implements Plugin {
|
|
|
830
817
|
## See Also
|
|
831
818
|
|
|
832
819
|
- [README.md](../../README.md) - Project overview
|
|
833
|
-
- [DEVELOPMENT_GUIDE.md](../../DEVELOPMENT_GUIDE.md) - Architecture details
|
|
834
820
|
- [packages/api/README.md](../api/README.md) - Public API tools
|
|
835
821
|
- [packages/plugin-analyzer/README.md](../plugin-analyzer/README.md) - Project analysis rules
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* SOLID principles plugin for the Angular Modernizer.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* {@link SolidPlugin} registers seven analysis rules and two transform rules:
|
|
5
|
+
* - {@link DIPViolationRule}, {@link ServiceDipViolationRule}: Dependency Inversion
|
|
6
|
+
* - {@link SingleResponsibilityRule}: Single Responsibility
|
|
7
|
+
* - {@link OCPViolationRule}, {@link GodSwitchAnalysisRule}: Open/Closed
|
|
8
|
+
* - {@link LSPViolationRule}: Liskov Substitution
|
|
9
|
+
* - {@link ISPViolationRule}: Interface Segregation
|
|
10
|
+
* - {@link GodSwitchTransformRule}: replaces a large switch with a factory and
|
|
11
|
+
* strategy classes ({@link GodSwitchTransformOrchestrator})
|
|
12
|
+
* - {@link ServiceDipViolationTransformRule}: replaces concrete constructor
|
|
13
|
+
* injection with an interface and an `InjectionToken`
|
|
14
|
+
* ({@link ServiceDipViolationTransformOrchestrator})
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
6
17
|
*/
|
|
7
18
|
export { SolidPlugin } from './solid-plugin.js';
|
|
8
19
|
export { DIPViolationRule } from './rules/dip-violation.rule.js';
|
|
@@ -15,7 +26,7 @@ export { ServiceDipViolationRule } from './rules/service-dip-violation.analysis.
|
|
|
15
26
|
export type { ServiceDipViolationConfig, ServiceDipViolationMetadata, } from './rules/service-dip-violation.analysis.rule.js';
|
|
16
27
|
export { GodSwitchTransformRule } from './transform-rules/god-switch-transform.rule.js';
|
|
17
28
|
export { ServiceDipViolationTransformRule } from './transform-rules/service-dip-violation.transform.rule.js';
|
|
18
|
-
export { GodSwitchTransformOrchestrator } from './orchestrators/god-switch-transform-orchestrator.js';
|
|
29
|
+
export { GodSwitchTransformOrchestrator, type GodSwitchTransformConfig, } from './orchestrators/god-switch-transform-orchestrator.js';
|
|
19
30
|
export { ServiceDipViolationTransformOrchestrator } from './orchestrators/service-dip-violation-transform.orchestrator.js';
|
|
20
31
|
export type { ServiceDipTransformResult } from './orchestrators/service-dip-violation-transform.orchestrator.js';
|
|
21
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* SOLID principles plugin for the Angular Modernizer.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* {@link SolidPlugin} registers seven analysis rules and two transform rules:
|
|
6
|
+
* - {@link DIPViolationRule}, {@link ServiceDipViolationRule}: Dependency Inversion
|
|
7
|
+
* - {@link SingleResponsibilityRule}: Single Responsibility
|
|
8
|
+
* - {@link OCPViolationRule}, {@link GodSwitchAnalysisRule}: Open/Closed
|
|
9
|
+
* - {@link LSPViolationRule}: Liskov Substitution
|
|
10
|
+
* - {@link ISPViolationRule}: Interface Segregation
|
|
11
|
+
* - {@link GodSwitchTransformRule}: replaces a large switch with a factory and
|
|
12
|
+
* strategy classes ({@link GodSwitchTransformOrchestrator})
|
|
13
|
+
* - {@link ServiceDipViolationTransformRule}: replaces concrete constructor
|
|
14
|
+
* injection with an interface and an `InjectionToken`
|
|
15
|
+
* ({@link ServiceDipViolationTransformOrchestrator})
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
7
18
|
*/
|
|
8
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
20
|
exports.ServiceDipViolationTransformOrchestrator = exports.GodSwitchTransformOrchestrator = exports.ServiceDipViolationTransformRule = exports.GodSwitchTransformRule = exports.ServiceDipViolationRule = exports.GodSwitchAnalysisRule = exports.ISPViolationRule = exports.OCPViolationRule = exports.LSPViolationRule = exports.SingleResponsibilityRule = exports.DIPViolationRule = exports.SolidPlugin = void 0;
|
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/plugin-solid - God Switch Transform Orchestrator
|
|
3
|
-
*
|
|
4
|
-
* The central "brain" of the God Switch transformation plugin.
|
|
5
|
-
* Transforms large switch statements into maintainable Factory Pattern implementations.
|
|
6
|
-
*
|
|
7
|
-
* Philosophy: "API-Driven Orchestration"
|
|
8
|
-
* - Receives all capabilities via TransformContext
|
|
9
|
-
* - Uses ts-morph for all AST operations
|
|
10
|
-
* - Stateless - no constructor dependencies
|
|
11
|
-
* - Pure business logic, no low-level manipulation
|
|
12
|
-
*/
|
|
13
1
|
import type { TransformContext } from '@angular-modernizer/plugin-system';
|
|
14
2
|
import type { PublicApi } from '@angular-modernizer/api';
|
|
15
3
|
/**
|
|
16
|
-
* Configuration options for God Switch transformation
|
|
4
|
+
* Configuration options for God Switch transformation, read from
|
|
5
|
+
* `context.config.godSwitch`.
|
|
17
6
|
*/
|
|
18
7
|
export interface GodSwitchTransformConfig {
|
|
19
8
|
/**
|
|
@@ -79,7 +68,7 @@ export interface GodSwitchTransformConfig {
|
|
|
79
68
|
* sourceFile,
|
|
80
69
|
* project,
|
|
81
70
|
* api,
|
|
82
|
-
* config: { minCaseCount: 10 }
|
|
71
|
+
* config: { godSwitch: { minCaseCount: 10 } }
|
|
83
72
|
* });
|
|
84
73
|
* orchestrator.run(context);
|
|
85
74
|
* ```
|
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @angular-modernizer/plugin-solid - God Switch Transform Orchestrator
|
|
4
|
-
*
|
|
5
|
-
* The central "brain" of the God Switch transformation plugin.
|
|
6
|
-
* Transforms large switch statements into maintainable Factory Pattern implementations.
|
|
7
|
-
*
|
|
8
|
-
* Philosophy: "API-Driven Orchestration"
|
|
9
|
-
* - Receives all capabilities via TransformContext
|
|
10
|
-
* - Uses ts-morph for all AST operations
|
|
11
|
-
* - Stateless - no constructor dependencies
|
|
12
|
-
* - Pure business logic, no low-level manipulation
|
|
13
|
-
*/
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.GodSwitchTransformOrchestrator = void 0;
|
|
16
4
|
const ts_morph_1 = require("ts-morph");
|
|
@@ -48,7 +36,7 @@ const ts_morph_1 = require("ts-morph");
|
|
|
48
36
|
* sourceFile,
|
|
49
37
|
* project,
|
|
50
38
|
* api,
|
|
51
|
-
* config: { minCaseCount: 10 }
|
|
39
|
+
* config: { godSwitch: { minCaseCount: 10 } }
|
|
52
40
|
* });
|
|
53
41
|
* orchestrator.run(context);
|
|
54
42
|
* ```
|
|
@@ -1,47 +1,61 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/plugin-solid - Service DIP Violation Transform Orchestrator
|
|
3
|
-
*
|
|
4
|
-
* Transforms concrete constructor injection into interface-based injection:
|
|
5
|
-
*
|
|
6
|
-
* BEFORE:
|
|
7
|
-
* constructor(private svc: OrderService) {}
|
|
8
|
-
*
|
|
9
|
-
* AFTER (in consuming file):
|
|
10
|
-
* constructor(@Inject(ORDER_SERVICE_TOKEN) private svc: IOrderService) {}
|
|
11
|
-
*
|
|
12
|
-
* AFTER (in injected service file):
|
|
13
|
-
* export interface IOrderService { methodA(): void; ... }
|
|
14
|
-
* export const ORDER_SERVICE_TOKEN = new InjectionToken<IOrderService>('order-service');
|
|
15
|
-
*
|
|
16
|
-
* Philosophy: "Thin Rule, Thick Orchestrator"
|
|
17
|
-
* - Stateless — no constructor dependencies
|
|
18
|
-
* - All operations via ts-morph AST (direct, not via context.api.transformation.importManager)
|
|
19
|
-
* - Idempotent: skips params already decorated with @Inject
|
|
20
|
-
* - Multi-file: modifies both consuming file and injected service file
|
|
21
|
-
*/
|
|
22
1
|
import type { TransformContext } from '@angular-modernizer/plugin-system';
|
|
23
2
|
import type { PublicApi } from '@angular-modernizer/api';
|
|
3
|
+
/**
|
|
4
|
+
* Result of {@link ServiceDipViolationTransformOrchestrator.run}.
|
|
5
|
+
*/
|
|
24
6
|
export interface ServiceDipTransformResult {
|
|
7
|
+
/** Number of constructor parameters that were transformed. */
|
|
25
8
|
changeCount: number;
|
|
9
|
+
/** One entry per transformed constructor parameter. */
|
|
26
10
|
transformedParams: {
|
|
11
|
+
/** Name of the class whose constructor was changed. */
|
|
27
12
|
injectingClass: string;
|
|
13
|
+
/** Name of the constructor parameter. */
|
|
28
14
|
parameterName: string;
|
|
15
|
+
/** Interface now used as the parameter type (`I` + injected class name). */
|
|
29
16
|
interfaceName: string;
|
|
17
|
+
/** Injection token passed to `@Inject` (e.g. `ORDER_SERVICE_TOKEN`). */
|
|
30
18
|
tokenName: string;
|
|
31
19
|
}[];
|
|
20
|
+
/** Per-parameter failures as `Class.param: message`; other parameters still run. */
|
|
32
21
|
errors: string[];
|
|
33
22
|
}
|
|
34
23
|
/**
|
|
35
|
-
* Orchestrator for DIP violation transformation
|
|
24
|
+
* Orchestrator for DIP violation transformation: turns concrete constructor
|
|
25
|
+
* injection into interface-based injection.
|
|
36
26
|
*
|
|
37
|
-
* For each constructor parameter
|
|
27
|
+
* For each constructor parameter of an `@Injectable` class that injects a
|
|
28
|
+
* concrete `@Injectable` class:
|
|
38
29
|
* 1. Derives interface name (`I${ClassName}`) and token name (`CLASS_NAME_TOKEN`)
|
|
39
|
-
* 2. Inserts the interface
|
|
30
|
+
* 2. Inserts the interface (public method signatures) and the
|
|
31
|
+
* `InjectionToken` into the injected service file, unless the interface
|
|
32
|
+
* already exists there
|
|
40
33
|
* 3. Replaces the parameter type with the interface name
|
|
41
34
|
* 4. Adds `@Inject(TOKEN)` to the parameter
|
|
42
35
|
* 5. Ensures all required imports are present in both files
|
|
36
|
+
*
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // before
|
|
39
|
+
* constructor(private svc: OrderService) {}
|
|
40
|
+
* // after, consuming file
|
|
41
|
+
* constructor(@Inject(ORDER_SERVICE_TOKEN) private svc: IOrderService) {}
|
|
42
|
+
* // after, injected service file
|
|
43
|
+
* export interface IOrderService { methodA(): void; }
|
|
44
|
+
* export const ORDER_SERVICE_TOKEN = new InjectionToken<IOrderService>('order-service');
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* Works directly on the ts-morph AST and modifies two files (the consuming
|
|
48
|
+
* file and the injected service file). Idempotent: parameters that already
|
|
49
|
+
* have `@Inject` are skipped. Declaration files are skipped.
|
|
43
50
|
*/
|
|
44
51
|
export declare class ServiceDipViolationTransformOrchestrator {
|
|
52
|
+
/**
|
|
53
|
+
* Transforms all concrete `@Injectable` constructor parameters in
|
|
54
|
+
* `context.sourceFile`.
|
|
55
|
+
*
|
|
56
|
+
* @param context - Transform context of the consuming file
|
|
57
|
+
* @returns Transformed parameters, change count and per-parameter errors
|
|
58
|
+
*/
|
|
45
59
|
run(context: TransformContext<PublicApi>): ServiceDipTransformResult;
|
|
46
60
|
private transformParam;
|
|
47
61
|
private insertInterfaceAndToken;
|
|
@@ -1,40 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @angular-modernizer/plugin-solid - Service DIP Violation Transform Orchestrator
|
|
4
|
-
*
|
|
5
|
-
* Transforms concrete constructor injection into interface-based injection:
|
|
6
|
-
*
|
|
7
|
-
* BEFORE:
|
|
8
|
-
* constructor(private svc: OrderService) {}
|
|
9
|
-
*
|
|
10
|
-
* AFTER (in consuming file):
|
|
11
|
-
* constructor(@Inject(ORDER_SERVICE_TOKEN) private svc: IOrderService) {}
|
|
12
|
-
*
|
|
13
|
-
* AFTER (in injected service file):
|
|
14
|
-
* export interface IOrderService { methodA(): void; ... }
|
|
15
|
-
* export const ORDER_SERVICE_TOKEN = new InjectionToken<IOrderService>('order-service');
|
|
16
|
-
*
|
|
17
|
-
* Philosophy: "Thin Rule, Thick Orchestrator"
|
|
18
|
-
* - Stateless — no constructor dependencies
|
|
19
|
-
* - All operations via ts-morph AST (direct, not via context.api.transformation.importManager)
|
|
20
|
-
* - Idempotent: skips params already decorated with @Inject
|
|
21
|
-
* - Multi-file: modifies both consuming file and injected service file
|
|
22
|
-
*/
|
|
23
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
3
|
exports.ServiceDipViolationTransformOrchestrator = void 0;
|
|
25
4
|
const ts_morph_1 = require("ts-morph");
|
|
26
5
|
const node_path_1 = require("node:path");
|
|
27
6
|
/**
|
|
28
|
-
* Orchestrator for DIP violation transformation
|
|
7
|
+
* Orchestrator for DIP violation transformation: turns concrete constructor
|
|
8
|
+
* injection into interface-based injection.
|
|
29
9
|
*
|
|
30
|
-
* For each constructor parameter
|
|
10
|
+
* For each constructor parameter of an `@Injectable` class that injects a
|
|
11
|
+
* concrete `@Injectable` class:
|
|
31
12
|
* 1. Derives interface name (`I${ClassName}`) and token name (`CLASS_NAME_TOKEN`)
|
|
32
|
-
* 2. Inserts the interface
|
|
13
|
+
* 2. Inserts the interface (public method signatures) and the
|
|
14
|
+
* `InjectionToken` into the injected service file, unless the interface
|
|
15
|
+
* already exists there
|
|
33
16
|
* 3. Replaces the parameter type with the interface name
|
|
34
17
|
* 4. Adds `@Inject(TOKEN)` to the parameter
|
|
35
18
|
* 5. Ensures all required imports are present in both files
|
|
19
|
+
*
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // before
|
|
22
|
+
* constructor(private svc: OrderService) {}
|
|
23
|
+
* // after, consuming file
|
|
24
|
+
* constructor(@Inject(ORDER_SERVICE_TOKEN) private svc: IOrderService) {}
|
|
25
|
+
* // after, injected service file
|
|
26
|
+
* export interface IOrderService { methodA(): void; }
|
|
27
|
+
* export const ORDER_SERVICE_TOKEN = new InjectionToken<IOrderService>('order-service');
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* Works directly on the ts-morph AST and modifies two files (the consuming
|
|
31
|
+
* file and the injected service file). Idempotent: parameters that already
|
|
32
|
+
* have `@Inject` are skipped. Declaration files are skipped.
|
|
36
33
|
*/
|
|
37
34
|
class ServiceDipViolationTransformOrchestrator {
|
|
35
|
+
/**
|
|
36
|
+
* Transforms all concrete `@Injectable` constructor parameters in
|
|
37
|
+
* `context.sourceFile`.
|
|
38
|
+
*
|
|
39
|
+
* @param context - Transform context of the consuming file
|
|
40
|
+
* @returns Transformed parameters, change count and per-parameter errors
|
|
41
|
+
*/
|
|
38
42
|
run(context) {
|
|
39
43
|
const { sourceFile } = context;
|
|
40
44
|
const result = {
|
|
@@ -1,29 +1,26 @@
|
|
|
1
|
+
import type { AnalysisRule, AnalysisContext, AnalysisResult } from '@angular-modernizer/plugin-system';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Detects direct instantiation of services (Dependency Inversion Principle violation).
|
|
3
|
+
* DIP Violation Rule (`solid:dip-violation-direct-instantiation`) - detects
|
|
4
|
+
* direct service instantiation (Dependency Inversion Principle violation).
|
|
5
5
|
*
|
|
6
|
-
* Detection
|
|
7
|
-
* - new
|
|
8
|
-
*
|
|
6
|
+
* Detection patterns:
|
|
7
|
+
* - `new X()` anywhere in the file where `X` ends with a service suffix
|
|
8
|
+
* (`Service`, `Repository`, `Store`, `Manager`, `Api`, `Client`, `Provider`,
|
|
9
|
+
* `Facade`, `Helper`, `Util`, `Utils`); metadata `violationType:
|
|
10
|
+
* 'direct-instantiation'`
|
|
11
|
+
* - Service locator calls `<receiver>.get(...)` where the receiver matches
|
|
12
|
+
* `/injector/i`; metadata `violationType: 'service-locator-pattern'`
|
|
9
13
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* NOTE: This rule uses pattern matching for service detection since it analyzes NewExpressions
|
|
13
|
-
* rather than ClassDeclarations. For class-level service detection, use ServiceDetector.
|
|
14
|
+
* Service detection matches names because the rule looks at `new`
|
|
15
|
+
* expressions, not class declarations.
|
|
14
16
|
*
|
|
15
17
|
* @example
|
|
18
|
+
* ```typescript
|
|
16
19
|
* // Violation: direct instantiation bypasses Angular DI
|
|
17
20
|
* class OrderService {
|
|
18
21
|
* private userService = new UserService(); // DIP violation
|
|
19
22
|
* }
|
|
20
|
-
|
|
21
|
-
import type { AnalysisRule, AnalysisContext, AnalysisResult } from '@angular-modernizer/plugin-system';
|
|
22
|
-
/**
|
|
23
|
-
* DIP Violation Rule - detects direct service instantiation.
|
|
24
|
-
*
|
|
25
|
-
* This rule implements the Dependency Inversion Principle by detecting
|
|
26
|
-
* direct instantiation of services, which should be injected instead.
|
|
23
|
+
* ```
|
|
27
24
|
*/
|
|
28
25
|
export declare class DIPViolationRule implements AnalysisRule {
|
|
29
26
|
readonly id = "solid:dip-violation-direct-instantiation";
|
|
@@ -1,32 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DIPViolationRule = void 0;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
2
5
|
/**
|
|
3
|
-
*
|
|
6
|
+
* DIP Violation Rule (`solid:dip-violation-direct-instantiation`) - detects
|
|
7
|
+
* direct service instantiation (Dependency Inversion Principle violation).
|
|
4
8
|
*
|
|
5
|
-
*
|
|
9
|
+
* Detection patterns:
|
|
10
|
+
* - `new X()` anywhere in the file where `X` ends with a service suffix
|
|
11
|
+
* (`Service`, `Repository`, `Store`, `Manager`, `Api`, `Client`, `Provider`,
|
|
12
|
+
* `Facade`, `Helper`, `Util`, `Utils`); metadata `violationType:
|
|
13
|
+
* 'direct-instantiation'`
|
|
14
|
+
* - Service locator calls `<receiver>.get(...)` where the receiver matches
|
|
15
|
+
* `/injector/i`; metadata `violationType: 'service-locator-pattern'`
|
|
6
16
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* - Direct instantiation of classes matching service patterns (Service, Repository, Store, etc.)
|
|
10
|
-
*
|
|
11
|
-
* This rule helps enforce proper dependency injection patterns in Angular applications.
|
|
12
|
-
*
|
|
13
|
-
* NOTE: This rule uses pattern matching for service detection since it analyzes NewExpressions
|
|
14
|
-
* rather than ClassDeclarations. For class-level service detection, use ServiceDetector.
|
|
17
|
+
* Service detection matches names because the rule looks at `new`
|
|
18
|
+
* expressions, not class declarations.
|
|
15
19
|
*
|
|
16
20
|
* @example
|
|
21
|
+
* ```typescript
|
|
17
22
|
* // Violation: direct instantiation bypasses Angular DI
|
|
18
23
|
* class OrderService {
|
|
19
24
|
* private userService = new UserService(); // DIP violation
|
|
20
25
|
* }
|
|
21
|
-
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.DIPViolationRule = void 0;
|
|
24
|
-
const ts_morph_1 = require("ts-morph");
|
|
25
|
-
/**
|
|
26
|
-
* DIP Violation Rule - detects direct service instantiation.
|
|
27
|
-
*
|
|
28
|
-
* This rule implements the Dependency Inversion Principle by detecting
|
|
29
|
-
* direct instantiation of services, which should be injected instead.
|
|
26
|
+
* ```
|
|
30
27
|
*/
|
|
31
28
|
class DIPViolationRule {
|
|
32
29
|
id = 'solid:dip-violation-direct-instantiation';
|
|
@@ -1,40 +1,27 @@
|
|
|
1
|
+
import type { AnalysisRule, AnalysisContext, AnalysisResult } from '@angular-modernizer/plugin-system';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Detects switch statements with too many cases that violate the Open/Closed Principle.
|
|
5
|
-
* These "God Switches" are hard to maintain and extend, requiring modification for every new case.
|
|
6
|
-
*
|
|
7
|
-
* Detection Pattern:
|
|
8
|
-
* - Switch statements exceeding configurable threshold (default: 10 case clauses, excluding default)
|
|
9
|
-
* - Classification of switch type based on expression patterns
|
|
10
|
-
* - Confidence scoring for violations
|
|
11
|
-
*
|
|
12
|
-
* Configuration:
|
|
13
|
-
* - context.config.solid.godSwitch.maxCases - Maximum allowed case clauses (default: 10)
|
|
3
|
+
* God Switch Analysis Rule (`solid:god-switch`) - detects switch statements
|
|
4
|
+
* with too many cases (Open/Closed Principle violation).
|
|
14
5
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
6
|
+
* Reports every switch statement with more case clauses (excluding
|
|
7
|
+
* `default`) than the threshold. The threshold is read from
|
|
8
|
+
* `context.config.solid.godSwitch.maxCases` (default: 10). Each result
|
|
9
|
+
* carries the case count, a classification of the switch expression
|
|
10
|
+
* (`switchType`) and a confidence score. Recommended refactorings: factory
|
|
11
|
+
* with strategy objects, polymorphism, strategy or command pattern;
|
|
12
|
+
* {@link GodSwitchTransformRule} applies the factory variant.
|
|
20
13
|
*
|
|
21
14
|
* @example
|
|
15
|
+
* ```typescript
|
|
22
16
|
* // Violation: switch with too many cases exceeds threshold
|
|
23
17
|
* function handleAction(action: string) {
|
|
24
18
|
* switch (action) {
|
|
25
19
|
* case 'create': return onCreate();
|
|
26
20
|
* case 'read': return onRead();
|
|
27
|
-
* // 9+ additional cases
|
|
21
|
+
* // 9+ additional cases - "God Switch" pattern
|
|
28
22
|
* }
|
|
29
23
|
* }
|
|
30
|
-
|
|
31
|
-
import type { AnalysisRule, AnalysisContext, AnalysisResult } from '@angular-modernizer/plugin-system';
|
|
32
|
-
/**
|
|
33
|
-
* God Switch Analysis Rule - detects switch statements with too many cases.
|
|
34
|
-
*
|
|
35
|
-
* This rule identifies large switch statements that violate OCP
|
|
36
|
-
* and provides classification and metadata to guide refactoring.
|
|
37
|
-
* The threshold is configurable via context.config.solid.godSwitch.maxCases (default: 10).
|
|
24
|
+
* ```
|
|
38
25
|
*/
|
|
39
26
|
export declare class GodSwitchAnalysisRule implements AnalysisRule {
|
|
40
27
|
readonly id = "solid:god-switch";
|
|
@@ -1,43 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GodSwitchAnalysisRule = void 0;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
2
5
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* Detects switch statements with too many cases that violate the Open/Closed Principle.
|
|
6
|
-
* These "God Switches" are hard to maintain and extend, requiring modification for every new case.
|
|
7
|
-
*
|
|
8
|
-
* Detection Pattern:
|
|
9
|
-
* - Switch statements exceeding configurable threshold (default: 10 case clauses, excluding default)
|
|
10
|
-
* - Classification of switch type based on expression patterns
|
|
11
|
-
* - Confidence scoring for violations
|
|
12
|
-
*
|
|
13
|
-
* Configuration:
|
|
14
|
-
* - context.config.solid.godSwitch.maxCases - Maximum allowed case clauses (default: 10)
|
|
6
|
+
* God Switch Analysis Rule (`solid:god-switch`) - detects switch statements
|
|
7
|
+
* with too many cases (Open/Closed Principle violation).
|
|
15
8
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
9
|
+
* Reports every switch statement with more case clauses (excluding
|
|
10
|
+
* `default`) than the threshold. The threshold is read from
|
|
11
|
+
* `context.config.solid.godSwitch.maxCases` (default: 10). Each result
|
|
12
|
+
* carries the case count, a classification of the switch expression
|
|
13
|
+
* (`switchType`) and a confidence score. Recommended refactorings: factory
|
|
14
|
+
* with strategy objects, polymorphism, strategy or command pattern;
|
|
15
|
+
* {@link GodSwitchTransformRule} applies the factory variant.
|
|
21
16
|
*
|
|
22
17
|
* @example
|
|
18
|
+
* ```typescript
|
|
23
19
|
* // Violation: switch with too many cases exceeds threshold
|
|
24
20
|
* function handleAction(action: string) {
|
|
25
21
|
* switch (action) {
|
|
26
22
|
* case 'create': return onCreate();
|
|
27
23
|
* case 'read': return onRead();
|
|
28
|
-
* // 9+ additional cases
|
|
24
|
+
* // 9+ additional cases - "God Switch" pattern
|
|
29
25
|
* }
|
|
30
26
|
* }
|
|
31
|
-
|
|
32
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
-
exports.GodSwitchAnalysisRule = void 0;
|
|
34
|
-
const ts_morph_1 = require("ts-morph");
|
|
35
|
-
/**
|
|
36
|
-
* God Switch Analysis Rule - detects switch statements with too many cases.
|
|
37
|
-
*
|
|
38
|
-
* This rule identifies large switch statements that violate OCP
|
|
39
|
-
* and provides classification and metadata to guide refactoring.
|
|
40
|
-
* The threshold is configurable via context.config.solid.godSwitch.maxCases (default: 10).
|
|
27
|
+
* ```
|
|
41
28
|
*/
|
|
42
29
|
class GodSwitchAnalysisRule {
|
|
43
30
|
id = 'solid:god-switch';
|