@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,73 @@
1
+ /**
2
+ * @angular-modernizer/plugin-solid - God Switch Detection Rule
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)
14
+ *
15
+ * Recommended Refactoring:
16
+ * - Factory Pattern with strategy objects for each case type
17
+ * - Polymorphism with inheritance hierarchy
18
+ * - Strategy Pattern with interface-based dispatch
19
+ * - Command Pattern for action-based switches
20
+ *
21
+ * @example
22
+ * // Violation: switch with too many cases exceeds threshold
23
+ * function handleAction(action: string) {
24
+ * switch (action) {
25
+ * case 'create': return onCreate();
26
+ * case 'read': return onRead();
27
+ * // 9+ additional cases — "God Switch" pattern
28
+ * }
29
+ * }
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).
38
+ */
39
+ export declare class GodSwitchAnalysisRule implements AnalysisRule {
40
+ readonly id = "solid:god-switch";
41
+ readonly name = "God Switch Detection";
42
+ readonly description = "Detects switch statements with too many cases that violate OCP (configurable threshold, default: 10)";
43
+ readonly severity = "warning";
44
+ readonly category = "solid-violation";
45
+ readonly tags: string[];
46
+ analyze(context: AnalysisContext): Promise<AnalysisResult[]>;
47
+ /**
48
+ * Analyze a switch statement for God Switch pattern.
49
+ *
50
+ * @param switchStmt - The switch statement to analyze
51
+ * @param filePath - Path to the file containing the switch statement
52
+ * @param maxSwitchCases - Maximum allowed case clauses (configurable threshold)
53
+ */
54
+ private analyzeSwitchStatement;
55
+ /**
56
+ * Classify the switch type based on the expression pattern.
57
+ *
58
+ * Classification helps guide appropriate refactoring strategies:
59
+ * - type-based: Use inheritance/polymorphism
60
+ * - status-based: Use State Pattern
61
+ * - action-based: Use Command Pattern
62
+ * - event-based: Use Observer Pattern
63
+ * - command-based: Use Command Pattern
64
+ * - state-based: Use State Pattern
65
+ * - kind-based: Use Factory Pattern
66
+ * - category-based: Use Strategy Pattern
67
+ * - discriminated-union: Use type-safe discriminated unions
68
+ *
69
+ * Note: Order matters! Check more specific patterns (event, command) before generic ones (type).
70
+ */
71
+ private analyzeSwitchType;
72
+ }
73
+ //# sourceMappingURL=god-switch-analysis.rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"god-switch-analysis.rule.d.ts","sourceRoot":"","sources":["../../src/rules/god-switch-analysis.rule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,cAAc,EACf,MAAM,mCAAmC,CAAC;AAE3C;;;;;;GAMG;AACH,qBAAa,qBAAsB,YAAW,YAAY;IACxD,SAAgB,EAAE,sBAAsB;IACxC,SAAgB,IAAI,0BAA0B;IAC9C,SAAgB,WAAW,0GAC8E;IACzG,SAAgB,QAAQ,aAAa;IACrC,SAAgB,QAAQ,qBAAqB;IAC7C,SAAgB,IAAI,WAMlB;IAEI,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IA6BlE;;;;;;OAMG;IACH,OAAO,CAAC,sBAAsB;IAgE9B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,iBAAiB;CAgC1B"}
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ /**
3
+ * @angular-modernizer/plugin-solid - God Switch Detection Rule
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)
15
+ *
16
+ * Recommended Refactoring:
17
+ * - Factory Pattern with strategy objects for each case type
18
+ * - Polymorphism with inheritance hierarchy
19
+ * - Strategy Pattern with interface-based dispatch
20
+ * - Command Pattern for action-based switches
21
+ *
22
+ * @example
23
+ * // Violation: switch with too many cases exceeds threshold
24
+ * function handleAction(action: string) {
25
+ * switch (action) {
26
+ * case 'create': return onCreate();
27
+ * case 'read': return onRead();
28
+ * // 9+ additional cases — "God Switch" pattern
29
+ * }
30
+ * }
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).
41
+ */
42
+ class GodSwitchAnalysisRule {
43
+ id = 'solid:god-switch';
44
+ name = 'God Switch Detection';
45
+ description = 'Detects switch statements with too many cases that violate OCP (configurable threshold, default: 10)';
46
+ severity = 'warning';
47
+ category = 'solid-violation';
48
+ tags = [
49
+ 'solid',
50
+ 'ocp',
51
+ 'god-switch',
52
+ 'switch',
53
+ 'refactoring',
54
+ ];
55
+ async analyze(context) {
56
+ const violations = [];
57
+ const sourceFile = context.sourceFile;
58
+ // Read maxSwitchCases from configuration, defaulting to 10
59
+ const solidConfig = context.config['solid'];
60
+ const maxSwitchCases = solidConfig?.godSwitch?.maxCases ?? 10;
61
+ // Find all switch statements in the file
62
+ const switchStatements = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.SwitchStatement);
63
+ for (const switchStmt of switchStatements) {
64
+ const violation = this.analyzeSwitchStatement(switchStmt, context.filePath, maxSwitchCases);
65
+ if (violation !== null) {
66
+ violations.push(violation);
67
+ }
68
+ }
69
+ return violations;
70
+ }
71
+ /**
72
+ * Analyze a switch statement for God Switch pattern.
73
+ *
74
+ * @param switchStmt - The switch statement to analyze
75
+ * @param filePath - Path to the file containing the switch statement
76
+ * @param maxSwitchCases - Maximum allowed case clauses (configurable threshold)
77
+ */
78
+ analyzeSwitchStatement(switchStmt, filePath, maxSwitchCases) {
79
+ const caseBlock = switchStmt.getCaseBlock();
80
+ const clauses = caseBlock.getClauses();
81
+ // Filter to get only case clauses (exclude default)
82
+ const caseClauses = clauses.filter((c) => c.getKind() === ts_morph_1.SyntaxKind.CaseClause);
83
+ const caseCount = caseClauses.length;
84
+ // Check if case count exceeds threshold
85
+ if (caseCount <= maxSwitchCases) {
86
+ return null;
87
+ }
88
+ // Get switch expression for classification
89
+ const expression = switchStmt.getExpression();
90
+ const expressionText = expression.getText();
91
+ const switchType = this.analyzeSwitchType(expressionText);
92
+ // Check for default clause
93
+ const hasDefault = clauses.some((c) => c.getKind() === ts_morph_1.SyntaxKind.DefaultClause);
94
+ // Extract case labels for metadata
95
+ const caseLabels = caseClauses.map((c) => {
96
+ const caseClause = c.asKind(ts_morph_1.SyntaxKind.CaseClause);
97
+ if (caseClause) {
98
+ const expr = caseClause.getExpression();
99
+ // Strip quotes from string literals for cleaner metadata
100
+ const text = expr.getText();
101
+ return text.replaceAll(/^['"]|['"]$/g, '');
102
+ }
103
+ return 'unknown';
104
+ });
105
+ // Build violation result
106
+ return {
107
+ ruleId: this.id,
108
+ message: `God Switch detected: ${caseCount} cases (${switchType}). Consider Factory Pattern.`,
109
+ filePath,
110
+ line: switchStmt.getStartLineNumber(),
111
+ column: switchStmt.getStart() - switchStmt.getStartLinePos(),
112
+ suggestedFix: 'Refactor to Factory Pattern with strategy objects for each case type',
113
+ metadata: {
114
+ caseCount,
115
+ switchType,
116
+ switchExpression: expressionText,
117
+ hasDefault,
118
+ confidence: 0.9,
119
+ caseLabels,
120
+ violationType: 'god-switch',
121
+ principle: 'Open/Closed Principle',
122
+ },
123
+ };
124
+ }
125
+ /**
126
+ * Classify the switch type based on the expression pattern.
127
+ *
128
+ * Classification helps guide appropriate refactoring strategies:
129
+ * - type-based: Use inheritance/polymorphism
130
+ * - status-based: Use State Pattern
131
+ * - action-based: Use Command Pattern
132
+ * - event-based: Use Observer Pattern
133
+ * - command-based: Use Command Pattern
134
+ * - state-based: Use State Pattern
135
+ * - kind-based: Use Factory Pattern
136
+ * - category-based: Use Strategy Pattern
137
+ * - discriminated-union: Use type-safe discriminated unions
138
+ *
139
+ * Note: Order matters! Check more specific patterns (event, command) before generic ones (type).
140
+ */
141
+ analyzeSwitchType(expression) {
142
+ // Pattern matching on switch expression text
143
+ // Check specific patterns first to avoid false matches
144
+ if (/event/i.test(expression)) {
145
+ return 'event-based';
146
+ }
147
+ if (/command/i.test(expression)) {
148
+ return 'command-based';
149
+ }
150
+ if (/status/i.test(expression)) {
151
+ return 'status-based';
152
+ }
153
+ if (/action/i.test(expression)) {
154
+ return 'action-based';
155
+ }
156
+ if (/state/i.test(expression)) {
157
+ return 'state-based';
158
+ }
159
+ if (/kind/i.test(expression)) {
160
+ return 'kind-based';
161
+ }
162
+ if (/category/i.test(expression)) {
163
+ return 'category-based';
164
+ }
165
+ // Check generic pattern last
166
+ if (/type/i.test(expression)) {
167
+ return 'type-based';
168
+ }
169
+ // Default classification
170
+ return 'discriminated-union';
171
+ }
172
+ }
173
+ exports.GodSwitchAnalysisRule = GodSwitchAnalysisRule;
174
+ //# sourceMappingURL=god-switch-analysis.rule.js.map
@@ -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IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7B,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,yBAAyB;QACzB,OAAO,qBAAqB,CAAC;IAC/B,CAAC;CACF;AAnKD,sDAmKC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @angular-modernizer/plugin-solid - ISP Violation Rule
3
+ *
4
+ * Detects violations of the Interface Segregation Principle.
5
+ * Identifies interfaces with too many methods or mixed responsibilities.
6
+ *
7
+ * Detection Patterns:
8
+ * - Interfaces with more than X methods (configurable threshold)
9
+ * - Interfaces that mix different concerns (UI, Data, Business logic)
10
+ * - Classes implementing interfaces they don't fully use
11
+ *
12
+ * This rule helps ensure interfaces are focused and clients don't depend on methods they don't use.
13
+ *
14
+ * @example
15
+ * // Violation: interface forces implementations to define unrelated methods
16
+ * interface IWorker {
17
+ * work(): void;
18
+ * eat(): void; // Irrelevant for robots
19
+ * sleep(): void; // Irrelevant for robots
20
+ * }
21
+ */
22
+ import type { AnalysisRule, AnalysisContext, AnalysisResult } from '@angular-modernizer/plugin-system';
23
+ /**
24
+ * ISP Violation Rule - detects Interface Segregation Principle violations.
25
+ *
26
+ * This rule implements the Interface Segregation Principle by detecting
27
+ * interfaces that are too large or have mixed responsibilities.
28
+ */
29
+ export declare class ISPViolationRule implements AnalysisRule {
30
+ readonly id = "solid:isp-violation";
31
+ readonly name = "Interface Segregation Principle Violation";
32
+ readonly description = "Detects interfaces that are too large or have mixed responsibilities";
33
+ readonly severity = "warning";
34
+ readonly category = "solid-violation";
35
+ readonly tags: string[];
36
+ /**
37
+ * Maximum number of methods allowed in an interface.
38
+ */
39
+ private readonly maxMethodsInInterface;
40
+ /**
41
+ * Maximum number of interfaces a class can implement.
42
+ */
43
+ private readonly maxInterfacesPerClass;
44
+ /**
45
+ * Keywords that indicate different concerns.
46
+ */
47
+ private readonly concernKeywords;
48
+ analyze(context: AnalysisContext): Promise<AnalysisResult[]>;
49
+ /**
50
+ * Analyze an interface for ISP violations.
51
+ */
52
+ private analyzeInterface;
53
+ /**
54
+ * Analyze if a class implements interfaces it doesn't fully use.
55
+ */
56
+ private analyzeClassInterfaceUsage;
57
+ /**
58
+ * Analyze if an interface mixes different concerns.
59
+ */
60
+ private analyzeInterfaceConcerns;
61
+ }
62
+ //# sourceMappingURL=isp-violation.rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isp-violation.rule.d.ts","sourceRoot":"","sources":["../../src/rules/isp-violation.rule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAWH,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,cAAc,EACf,MAAM,mCAAmC,CAAC;AAE3C;;;;;GAKG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACnD,SAAgB,EAAE,yBAAyB;IAC3C,SAAgB,IAAI,+CAA+C;IACnE,SAAgB,WAAW,0EAC8C;IACzE,SAAgB,QAAQ,aAAa;IACrC,SAAgB,QAAQ,qBAAqB;IAC7C,SAAgB,IAAI,WAMlB;IAEF;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAK;IAE3C;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAK;IAE3C;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,eAAe,CA+B9B;IAEI,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAgClE;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAgExB;;OAEG;IACH,OAAO,CAAC,0BAA0B;IAwElC;;OAEG;IACH,OAAO,CAAC,wBAAwB;CAiCjC"}
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ /**
3
+ * @angular-modernizer/plugin-solid - ISP Violation Rule
4
+ *
5
+ * Detects violations of the Interface Segregation Principle.
6
+ * Identifies interfaces with too many methods or mixed responsibilities.
7
+ *
8
+ * Detection Patterns:
9
+ * - Interfaces with more than X methods (configurable threshold)
10
+ * - Interfaces that mix different concerns (UI, Data, Business logic)
11
+ * - Classes implementing interfaces they don't fully use
12
+ *
13
+ * This rule helps ensure interfaces are focused and clients don't depend on methods they don't use.
14
+ *
15
+ * @example
16
+ * // Violation: interface forces implementations to define unrelated methods
17
+ * interface IWorker {
18
+ * work(): void;
19
+ * eat(): void; // Irrelevant for robots
20
+ * sleep(): void; // Irrelevant for robots
21
+ * }
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.ISPViolationRule = void 0;
25
+ const ts_morph_1 = require("ts-morph");
26
+ /**
27
+ * ISP Violation Rule - detects Interface Segregation Principle violations.
28
+ *
29
+ * This rule implements the Interface Segregation Principle by detecting
30
+ * interfaces that are too large or have mixed responsibilities.
31
+ */
32
+ class ISPViolationRule {
33
+ id = 'solid:isp-violation';
34
+ name = 'Interface Segregation Principle Violation';
35
+ description = 'Detects interfaces that are too large or have mixed responsibilities';
36
+ severity = 'warning';
37
+ category = 'solid-violation';
38
+ tags = [
39
+ 'solid',
40
+ 'isp',
41
+ 'interface',
42
+ 'segregation',
43
+ 'architecture',
44
+ ];
45
+ /**
46
+ * Maximum number of methods allowed in an interface.
47
+ */
48
+ maxMethodsInInterface = 5;
49
+ /**
50
+ * Maximum number of interfaces a class can implement.
51
+ */
52
+ maxInterfacesPerClass = 3;
53
+ /**
54
+ * Keywords that indicate different concerns.
55
+ */
56
+ concernKeywords = {
57
+ ui: [
58
+ 'render',
59
+ 'display',
60
+ 'show',
61
+ 'hide',
62
+ 'click',
63
+ 'event',
64
+ 'component',
65
+ 'view',
66
+ ],
67
+ data: [
68
+ 'save',
69
+ 'load',
70
+ 'fetch',
71
+ 'query',
72
+ 'store',
73
+ 'persist',
74
+ 'cache',
75
+ 'repository',
76
+ ],
77
+ business: [
78
+ 'calculate',
79
+ 'validate',
80
+ 'process',
81
+ 'transform',
82
+ 'convert',
83
+ 'rule',
84
+ 'logic',
85
+ ],
86
+ lifecycle: ['init', 'destroy', 'create', 'setup', 'cleanup', 'initialize'],
87
+ };
88
+ async analyze(context) {
89
+ const violations = [];
90
+ const sourceFile = context.sourceFile;
91
+ // Find all interfaces in the file
92
+ const interfaces = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.InterfaceDeclaration);
93
+ for (const interfaceDecl of interfaces) {
94
+ const interfaceViolations = this.analyzeInterface(interfaceDecl, sourceFile.getFilePath());
95
+ violations.push(...interfaceViolations);
96
+ }
97
+ // Find classes that implement interfaces they don't fully use
98
+ const classes = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ClassDeclaration);
99
+ for (const classDecl of classes) {
100
+ const classViolations = this.analyzeClassInterfaceUsage(classDecl, sourceFile.getFilePath());
101
+ violations.push(...classViolations);
102
+ }
103
+ return Promise.resolve(violations);
104
+ }
105
+ /**
106
+ * Analyze an interface for ISP violations.
107
+ */
108
+ analyzeInterface(interfaceDecl, filePath) {
109
+ const violations = [];
110
+ try {
111
+ const interfaceName = interfaceDecl.getName();
112
+ const methods = interfaceDecl.getMethods();
113
+ const properties = interfaceDecl.getProperties();
114
+ // Check if interface has too many methods
115
+ if (methods.length > this.maxMethodsInInterface) {
116
+ const startLine = interfaceDecl.getStartLineNumber();
117
+ const startColumn = interfaceDecl.getStart() - interfaceDecl.getStartLinePos();
118
+ violations.push({
119
+ ruleId: this.id,
120
+ message: `Interface '${interfaceName}' has ${methods.length} methods, exceeding the recommended maximum of ${this.maxMethodsInInterface}. Consider splitting into smaller, focused interfaces.`,
121
+ filePath,
122
+ line: startLine,
123
+ column: startColumn,
124
+ suggestedFix: `Split '${interfaceName}' into smaller interfaces based on single responsibilities`,
125
+ metadata: {
126
+ interfaceName,
127
+ methodCount: methods.length,
128
+ maxAllowed: this.maxMethodsInInterface,
129
+ violationType: 'too-many-methods',
130
+ },
131
+ });
132
+ }
133
+ // Check if interface mixes different concerns
134
+ const concernAnalysis = this.analyzeInterfaceConcerns(methods, properties);
135
+ if (concernAnalysis.mixedConcerns) {
136
+ const startLine = interfaceDecl.getStartLineNumber();
137
+ const startColumn = interfaceDecl.getStart() - interfaceDecl.getStartLinePos();
138
+ violations.push({
139
+ ruleId: this.id,
140
+ message: `Interface '${interfaceName}' mixes multiple concerns: ${concernAnalysis.concerns.join(', ')}. Consider segregating into focused interfaces.`,
141
+ filePath,
142
+ line: startLine,
143
+ column: startColumn,
144
+ suggestedFix: `Create separate interfaces for each concern: ${concernAnalysis.concerns.map((c) => `${interfaceName}${c.charAt(0).toUpperCase() + c.slice(1)}`).join(', ')}`,
145
+ metadata: {
146
+ interfaceName,
147
+ concerns: concernAnalysis.concerns,
148
+ violationType: 'mixed-concerns',
149
+ },
150
+ });
151
+ }
152
+ }
153
+ catch (_error) {
154
+ // Continue with other interfaces
155
+ }
156
+ return violations;
157
+ }
158
+ /**
159
+ * Analyze if a class implements interfaces it doesn't fully use.
160
+ */
161
+ analyzeClassInterfaceUsage(classDecl, filePath) {
162
+ const violations = [];
163
+ try {
164
+ const className = classDecl.getName();
165
+ const implementedInterfaces = classDecl.getImplements();
166
+ // Check if class implements too many interfaces
167
+ if (implementedInterfaces.length > this.maxInterfacesPerClass) {
168
+ const startLine = classDecl.getStartLineNumber();
169
+ const startColumn = classDecl.getStart() - classDecl.getStartLinePos();
170
+ violations.push({
171
+ ruleId: this.id,
172
+ message: `Class '${className}' implements ${implementedInterfaces.length} interfaces, exceeding the recommended maximum of ${this.maxInterfacesPerClass}. Consider segregating interfaces or using composition.`,
173
+ filePath,
174
+ line: startLine,
175
+ column: startColumn,
176
+ suggestedFix: `Split '${className}' into smaller classes or use composition instead of implementing multiple interfaces`,
177
+ metadata: {
178
+ className,
179
+ interfaceCount: implementedInterfaces.length,
180
+ maxAllowed: this.maxInterfacesPerClass,
181
+ violationType: 'too-many-interfaces',
182
+ },
183
+ });
184
+ }
185
+ for (const impl of implementedInterfaces) {
186
+ const interfaceType = impl.getType();
187
+ const interfaceSymbol = interfaceType.getSymbol();
188
+ if (interfaceSymbol) {
189
+ // This is a simplified check - in a real implementation,
190
+ // we'd analyze which methods are actually used vs declared
191
+ const interfaceName = interfaceSymbol.getName();
192
+ // For now, just check if the class has any methods at all
193
+ // A more sophisticated analysis would check method usage
194
+ const classMethods = classDecl.getMethods();
195
+ if (classMethods.length === 0) {
196
+ const startLine = classDecl.getStartLineNumber();
197
+ const startColumn = classDecl.getStart() - classDecl.getStartLinePos();
198
+ violations.push({
199
+ ruleId: this.id,
200
+ message: `Class '${className}' implements interface '${interfaceName}' but may not use all its methods. Consider implementing only the methods you need.`,
201
+ filePath,
202
+ line: startLine,
203
+ column: startColumn,
204
+ suggestedFix: `Implement only the interface methods that '${className}' actually needs`,
205
+ metadata: {
206
+ className,
207
+ interfaceName,
208
+ violationType: 'unused-interface-methods',
209
+ },
210
+ });
211
+ }
212
+ }
213
+ }
214
+ }
215
+ catch (_error) {
216
+ // Continue with other classes
217
+ }
218
+ return violations;
219
+ }
220
+ /**
221
+ * Analyze if an interface mixes different concerns.
222
+ */
223
+ analyzeInterfaceConcerns(methods, properties) {
224
+ const concerns = new Set();
225
+ // Analyze method names for concerns
226
+ for (const method of methods) {
227
+ const methodName = method.getName().toLowerCase();
228
+ for (const [concern, keywords] of Object.entries(this.concernKeywords)) {
229
+ if (keywords.some((keyword) => methodName.includes(keyword))) {
230
+ concerns.add(concern);
231
+ }
232
+ }
233
+ }
234
+ // Analyze property names for concerns
235
+ for (const property of properties) {
236
+ const propertyName = property.getName().toLowerCase();
237
+ for (const [concern, keywords] of Object.entries(this.concernKeywords)) {
238
+ if (keywords.some((keyword) => propertyName.includes(keyword))) {
239
+ concerns.add(concern);
240
+ }
241
+ }
242
+ }
243
+ return {
244
+ mixedConcerns: concerns.size > 1,
245
+ concerns: Array.from(concerns),
246
+ };
247
+ }
248
+ }
249
+ exports.ISPViolationRule = ISPViolationRule;
250
+ //# sourceMappingURL=isp-violation.rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isp-violation.rule.js","sourceRoot":"","sources":["../../src/rules/isp-violation.rule.ts"],"names":[],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AK,MAAM,QAAQ,IAAI,UAAU,EAAE,CAAC;YAClC,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC,WAAW,EAAE,CAAC;YAEtD,KAAK,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;gBACvE,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;oBAC/D,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO;YACL,aAAa,EAAE,QAAQ,CAAC,IAAI,GAAG,CAAC;YAChC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;SAC/B,CAAC;IACJ,CAAC;CACF;AA/QD,4CA+QC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @angular-modernizer/plugin-solid - Liskov Substitution Principle Rule
3
+ *
4
+ * Detects classes that violate the Liskov Substitution Principle (LSP)
5
+ * by not being substitutable for their base types without changing program correctness.
6
+ *
7
+ * Detection Patterns:
8
+ * - Classes that don't implement all abstract methods from base classes
9
+ * - Methods that override base methods with incompatible signatures
10
+ * - Properties that change type incompatibly in derived classes
11
+ * - Missing interface implementations (excluding Angular internal properties starting with ɵ)
12
+ * - instanceof checks that indicate poor inheritance design
13
+ * - Abstract method implementations that throw exceptions or behave unexpectedly
14
+ *
15
+ * This rule helps ensure proper inheritance hierarchies and interface compliance.
16
+ * Note: Angular internal properties (starting with ɵ) are automatically ignored.
17
+ *
18
+ * @example
19
+ * // Violation: derived class weakens base contract
20
+ * class Bird { fly(): void {} }
21
+ * class Penguin extends Bird {
22
+ * fly(): void { throw new Error('Penguins cannot fly'); }
23
+ * }
24
+ */
25
+ import type { AnalysisRule, AnalysisContext, AnalysisResult } from '@angular-modernizer/plugin-system';
26
+ /**
27
+ * LSP Violation Rule - detects Liskov Substitution Principle violations.
28
+ *
29
+ * This rule implements the Liskov Substitution Principle by detecting
30
+ * inheritance and interface implementation issues that break substitutability.
31
+ */
32
+ export declare class LSPViolationRule implements AnalysisRule {
33
+ readonly id = "solid:lsp-violation";
34
+ readonly name = "Liskov Substitution Principle Violation";
35
+ readonly description = "Detects classes that violate the Liskov Substitution Principle";
36
+ readonly severity = "warning";
37
+ readonly category = "solid-violation";
38
+ readonly tags: string[];
39
+ analyze(context: AnalysisContext): Promise<AnalysisResult[]>;
40
+ /**
41
+ * Analyze a class for LSP violations.
42
+ */
43
+ private analyzeClass;
44
+ /**
45
+ * Check interface implementation compliance.
46
+ */
47
+ private checkInterfaceImplementation;
48
+ /**
49
+ * Check abstract method implementation compliance.
50
+ */
51
+ private checkAbstractMethodImplementation;
52
+ /**
53
+ * Check for inheritance-based violations like instanceof checks.
54
+ */
55
+ private checkInheritanceBasedViolations;
56
+ }
57
+ //# sourceMappingURL=lsp-violation.rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lsp-violation.rule.d.ts","sourceRoot":"","sources":["../../src/rules/lsp-violation.rule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAOH,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,cAAc,EACf,MAAM,mCAAmC,CAAC;AAE3C;;;;;GAKG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACnD,SAAgB,EAAE,yBAAyB;IAC3C,SAAgB,IAAI,6CAA6C;IACjE,SAAgB,WAAW,oEACwC;IACnE,SAAgB,QAAQ,aAAa;IACrC,SAAgB,QAAQ,qBAAqB;IAC7C,SAAgB,IAAI,WAOlB;IAEI,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAoBlE;;OAEG;IACH,OAAO,CAAC,YAAY;IAsCpB;;OAEG;IACH,OAAO,CAAC,4BAA4B;IA0FpC;;OAEG;IACH,OAAO,CAAC,iCAAiC;IAsGzC;;OAEG;IACH,OAAO,CAAC,+BAA+B;CAwExC"}