@angular-modernizer/plugin-solid 1.1.0 → 2.0.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/CHANGELOG.md +270 -0
- package/README.md +103 -99
- package/dist/index.d.ts +5 -3
- package/dist/index.js +4 -2
- package/dist/rules/dip-violation.rule.d.ts +30 -31
- package/dist/rules/dip-violation.rule.js +246 -112
- package/dist/rules/god-switch-analysis.rule.d.ts +44 -33
- package/dist/rules/god-switch-analysis.rule.js +146 -109
- package/dist/rules/isp-violation.rule.d.ts +35 -33
- package/dist/rules/isp-violation.rule.js +83 -202
- package/dist/rules/lsp-violation.rule.d.ts +15 -39
- package/dist/rules/lsp-violation.rule.js +17 -300
- package/dist/rules/ocp-violation.rule.d.ts +52 -36
- package/dist/rules/ocp-violation.rule.js +227 -145
- package/dist/rules/service-dip-violation.analysis.rule.d.ts +32 -56
- package/dist/rules/service-dip-violation.analysis.rule.js +21 -192
- package/dist/rules/srp-violation.rule.d.ts +36 -71
- package/dist/rules/srp-violation.rule.js +78 -384
- package/dist/solid-plugin.d.ts +13 -8
- package/dist/solid-plugin.js +17 -11
- package/package.json +7 -6
|
@@ -3,30 +3,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.OCPViolationRule = void 0;
|
|
4
4
|
const ts_morph_1 = require("ts-morph");
|
|
5
5
|
/**
|
|
6
|
-
* OCP Violation Rule (`solid:ocp-violation`) -
|
|
7
|
-
*
|
|
6
|
+
* OCP Violation Rule (`solid:ocp-violation`) - reports if-else chains that
|
|
7
|
+
* dispatch on one value, so every new value means editing the chain.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* One finding per chain (`violationType: 'long-if-else-chain'`, severity
|
|
10
|
+
* warning, at the first `if`) when the chain has more than 4 conditions
|
|
11
|
+
* (the `if` plus its `else if` links; a final plain `else` is not counted)
|
|
12
|
+
* and every condition compares the same discriminant with `===` or `==`,
|
|
13
|
+
* also as `a === x || a === y`. The discriminant is a variable, parameter,
|
|
14
|
+
* property access chain (`this.state.kind`) or element access with a
|
|
15
|
+
* reference or literal key (`values[key]`); two references are the same
|
|
16
|
+
* when they resolve to the same symbols and keys, names alone do not match.
|
|
17
|
+
*
|
|
18
|
+
* Chains are checked everywhere in the file: methods, constructors, nested
|
|
19
|
+
* classes and functions outside classes. Switch statements are reported by
|
|
20
|
+
* `solid:god-switch`, parameter counts by no SOLID rule.
|
|
13
21
|
*
|
|
14
22
|
* @example
|
|
15
23
|
* ```typescript
|
|
16
|
-
* //
|
|
17
|
-
* function
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
24
|
+
* // Reported: 5 conditions on `kind`
|
|
25
|
+
* function area(kind: string): number {
|
|
26
|
+
* if (kind === 'circle') return 1;
|
|
27
|
+
* else if (kind === 'square') return 2;
|
|
28
|
+
* else if (kind === 'triangle') return 3;
|
|
29
|
+
* else if (kind === 'hexagon') return 4;
|
|
30
|
+
* else if (kind === 'star') return 5;
|
|
31
|
+
* return 0;
|
|
23
32
|
* }
|
|
24
33
|
* ```
|
|
25
34
|
*/
|
|
26
35
|
class OCPViolationRule {
|
|
27
36
|
id = 'solid:ocp-violation';
|
|
28
37
|
name = 'Open/Closed Principle Violation';
|
|
29
|
-
description = 'Detects
|
|
38
|
+
description = 'Detects if-else chains that compare one discriminant in more than 4 conditions (Open/Closed Principle)';
|
|
30
39
|
severity = 'warning';
|
|
31
40
|
category = 'solid-violation';
|
|
32
41
|
tags = [
|
|
@@ -36,159 +45,232 @@ class OCPViolationRule {
|
|
|
36
45
|
'extensibility',
|
|
37
46
|
'architecture',
|
|
38
47
|
];
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
*/
|
|
42
|
-
maxSwitchCases = 5;
|
|
43
|
-
/**
|
|
44
|
-
* Maximum number of if-else conditions in a chain.
|
|
45
|
-
*/
|
|
46
|
-
maxIfElseChain = 4;
|
|
47
|
-
/**
|
|
48
|
-
* Maximum number of parameters allowed in a method.
|
|
49
|
-
*/
|
|
50
|
-
maxMethodParameters = 4;
|
|
48
|
+
/** Conditions a chain may have before it is reported. */
|
|
49
|
+
maxConditions = 4;
|
|
51
50
|
async analyze(context) {
|
|
52
|
-
const violations = [];
|
|
53
51
|
const sourceFile = context.sourceFile;
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return Promise.resolve(
|
|
52
|
+
const filePath = sourceFile.getFilePath();
|
|
53
|
+
const symbolIds = new Map();
|
|
54
|
+
const results = sourceFile
|
|
55
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.IfStatement)
|
|
56
|
+
.filter((ifStmt) => !this.isElseIfLink(ifStmt))
|
|
57
|
+
.flatMap((ifStmt) => this.checkChain(ifStmt, filePath, symbolIds));
|
|
58
|
+
return Promise.resolve(results);
|
|
61
59
|
}
|
|
62
|
-
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
for (const method of methods) {
|
|
72
|
-
const methodViolations = this.analyzeMethod(method, className, filePath);
|
|
73
|
-
violations.push(...methodViolations);
|
|
74
|
-
}
|
|
75
|
-
// Check for switch statements in the class
|
|
76
|
-
const switchStatements = classDecl.getDescendantsOfKind(ts_morph_1.SyntaxKind.SwitchStatement);
|
|
77
|
-
for (const switchStmt of switchStatements) {
|
|
78
|
-
const violation = this.analyzeSwitchStatement(switchStmt, className, filePath);
|
|
79
|
-
if (violation !== null) {
|
|
80
|
-
violations.push(violation);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// Check for long if-else chains (only analyze top-level if statements)
|
|
84
|
-
const ifStatements = classDecl.getDescendantsOfKind(ts_morph_1.SyntaxKind.IfStatement);
|
|
85
|
-
for (const ifStmt of ifStatements) {
|
|
86
|
-
// Only analyze if statements that are not part of an else-if chain
|
|
87
|
-
const parent = ifStmt.getParent();
|
|
88
|
-
if (parent.getKind() === ts_morph_1.SyntaxKind.IfStatement) {
|
|
89
|
-
continue; // Skip else-if statements, they are analyzed as part of the chain
|
|
90
|
-
}
|
|
91
|
-
const violation = this.analyzeIfElseChain(ifStmt, className, filePath);
|
|
92
|
-
if (violation !== null) {
|
|
93
|
-
violations.push(violation);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
60
|
+
/** True when the `if` is the `else` branch of another `if`. */
|
|
61
|
+
isElseIfLink(ifStmt) {
|
|
62
|
+
const parent = ifStmt.getParent();
|
|
63
|
+
return (ts_morph_1.Node.isIfStatement(parent) && parent.getElseStatement() === ifStmt);
|
|
64
|
+
}
|
|
65
|
+
checkChain(first, filePath, symbolIds) {
|
|
66
|
+
const conditions = this.chainConditions(first);
|
|
67
|
+
if (conditions.length <= this.maxConditions) {
|
|
68
|
+
return [];
|
|
96
69
|
}
|
|
97
|
-
|
|
98
|
-
|
|
70
|
+
const discriminant = this.commonDiscriminant(conditions, symbolIds);
|
|
71
|
+
if (discriminant === undefined) {
|
|
72
|
+
return [];
|
|
99
73
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
analyzeMethod(method, className, filePath) {
|
|
106
|
-
const violations = [];
|
|
107
|
-
const methodName = method.getName();
|
|
108
|
-
// Check 1: Too many parameters
|
|
109
|
-
const parameters = method.getParameters();
|
|
110
|
-
if (parameters.length > this.maxMethodParameters) {
|
|
111
|
-
violations.push({
|
|
74
|
+
const owner = this.chainOwner(first);
|
|
75
|
+
const discriminantText = discriminant.node.getText();
|
|
76
|
+
const conditionCount = conditions.length;
|
|
77
|
+
return [
|
|
78
|
+
{
|
|
112
79
|
ruleId: this.id,
|
|
113
|
-
|
|
80
|
+
severity: 'warning',
|
|
81
|
+
message: `If-else chain in '${owner.functionName}' compares '${discriminantText}' in ${conditionCount} conditions (threshold: ${this.maxConditions}). Consider a lookup map or polymorphism.`,
|
|
114
82
|
filePath,
|
|
115
|
-
line:
|
|
116
|
-
column:
|
|
117
|
-
suggestedFix: `
|
|
83
|
+
line: first.getStartLineNumber(),
|
|
84
|
+
column: first.getStart() - first.getStartLinePos(),
|
|
85
|
+
suggestedFix: `Replace the chain on '${discriminantText}' with a lookup map, or with polymorphism when the branches carry behavior.`,
|
|
118
86
|
metadata: {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
87
|
+
functionName: owner.functionName,
|
|
88
|
+
...(owner.className === undefined
|
|
89
|
+
? {}
|
|
90
|
+
: { className: owner.className }),
|
|
91
|
+
discriminant: discriminantText,
|
|
92
|
+
conditionCount,
|
|
93
|
+
maxConditions: this.maxConditions,
|
|
94
|
+
violationType: 'long-if-else-chain',
|
|
124
95
|
principle: 'OCP',
|
|
125
96
|
},
|
|
126
|
-
}
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
/** Conditions of the `if` and of its `else if` links, in order. */
|
|
101
|
+
chainConditions(first) {
|
|
102
|
+
const conditions = [];
|
|
103
|
+
let current = first;
|
|
104
|
+
while (current !== undefined) {
|
|
105
|
+
conditions.push(current.getExpression());
|
|
106
|
+
const elseStmt = current.getElseStatement();
|
|
107
|
+
current = ts_morph_1.Node.isIfStatement(elseStmt) ? elseStmt : undefined;
|
|
127
108
|
}
|
|
128
|
-
return
|
|
109
|
+
return conditions;
|
|
129
110
|
}
|
|
130
111
|
/**
|
|
131
|
-
*
|
|
112
|
+
* The reference every comparison of every condition shares, or
|
|
113
|
+
* `undefined` when a condition is no equality comparison or no reference
|
|
114
|
+
* is shared.
|
|
132
115
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
116
|
+
commonDiscriminant(conditions, symbolIds) {
|
|
117
|
+
let common;
|
|
118
|
+
for (const condition of conditions) {
|
|
119
|
+
const comparisons = this.comparisons(condition);
|
|
120
|
+
if (comparisons === undefined) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
for (const [left, right] of comparisons) {
|
|
124
|
+
const operands = [left, right]
|
|
125
|
+
.map((operand) => this.reference(operand, symbolIds))
|
|
126
|
+
.filter((ref) => ref !== undefined);
|
|
127
|
+
common =
|
|
128
|
+
common === undefined
|
|
129
|
+
? operands
|
|
130
|
+
: common.filter((ref) => operands.some((operand) => operand.key === ref.key));
|
|
131
|
+
if (common.length === 0) {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
151
135
|
}
|
|
152
|
-
return
|
|
136
|
+
return common?.[0];
|
|
153
137
|
}
|
|
154
138
|
/**
|
|
155
|
-
*
|
|
139
|
+
* Operand pairs of `===`/`==` comparisons joined by `||`, or `undefined`
|
|
140
|
+
* when the condition has another shape.
|
|
156
141
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
142
|
+
comparisons(condition) {
|
|
143
|
+
const expr = this.unwrap(condition);
|
|
144
|
+
if (!ts_morph_1.Node.isBinaryExpression(expr)) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
const operator = expr.getOperatorToken().getKind();
|
|
148
|
+
if (operator === ts_morph_1.SyntaxKind.BarBarToken) {
|
|
149
|
+
const left = this.comparisons(expr.getLeft());
|
|
150
|
+
const right = this.comparisons(expr.getRight());
|
|
151
|
+
return left === undefined || right === undefined
|
|
152
|
+
? undefined
|
|
153
|
+
: [...left, ...right];
|
|
154
|
+
}
|
|
155
|
+
const isEquality = operator === ts_morph_1.SyntaxKind.EqualsEqualsEqualsToken ||
|
|
156
|
+
operator === ts_morph_1.SyntaxKind.EqualsEqualsToken;
|
|
157
|
+
return isEquality ? [[expr.getLeft(), expr.getRight()]] : undefined;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Canonical key of a variable, parameter, property access chain or element
|
|
161
|
+
* access, built from symbols (`this` for a `this` root; the property name
|
|
162
|
+
* only when the receiver has no type information). `undefined` for
|
|
163
|
+
* anything else.
|
|
164
|
+
*/
|
|
165
|
+
reference(operand, symbolIds) {
|
|
166
|
+
const node = this.unwrap(operand);
|
|
167
|
+
const key = this.referenceKey(node, symbolIds);
|
|
168
|
+
return key === undefined ? undefined : { key, node };
|
|
169
|
+
}
|
|
170
|
+
referenceKey(node, symbolIds) {
|
|
171
|
+
if (node.getKind() === ts_morph_1.SyntaxKind.ThisKeyword) {
|
|
172
|
+
return 'this';
|
|
173
|
+
}
|
|
174
|
+
if (ts_morph_1.Node.isIdentifier(node)) {
|
|
175
|
+
const symbol = node.getSymbol();
|
|
176
|
+
return symbol === undefined
|
|
177
|
+
? undefined
|
|
178
|
+
: `s${this.symbolId(symbol, symbolIds)}`;
|
|
179
|
+
}
|
|
180
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(node)) {
|
|
181
|
+
const receiver = this.referenceKey(this.unwrap(node.getExpression()), symbolIds);
|
|
182
|
+
if (receiver === undefined) {
|
|
183
|
+
return undefined;
|
|
166
184
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
185
|
+
const symbol = node.getNameNode().getSymbol();
|
|
186
|
+
const segment = symbol === undefined
|
|
187
|
+
? `n:${node.getName()}`
|
|
188
|
+
: `s${this.symbolId(symbol, symbolIds)}`;
|
|
189
|
+
return `${receiver}.${segment}`;
|
|
190
|
+
}
|
|
191
|
+
if (ts_morph_1.Node.isElementAccessExpression(node)) {
|
|
192
|
+
const receiver = this.referenceKey(this.unwrap(node.getExpression()), symbolIds);
|
|
193
|
+
const argument = node.getArgumentExpression();
|
|
194
|
+
const index = argument === undefined
|
|
195
|
+
? undefined
|
|
196
|
+
: this.elementKey(this.unwrap(argument), symbolIds);
|
|
197
|
+
return receiver === undefined || index === undefined
|
|
198
|
+
? undefined
|
|
199
|
+
: `${receiver}[${index}]`;
|
|
200
|
+
}
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
/** Key of an element access argument: a reference or a string or number literal. */
|
|
204
|
+
elementKey(node, symbolIds) {
|
|
205
|
+
if (ts_morph_1.Node.isStringLiteral(node) ||
|
|
206
|
+
ts_morph_1.Node.isNoSubstitutionTemplateLiteral(node)) {
|
|
207
|
+
return `l:${JSON.stringify(node.getLiteralValue())}`;
|
|
208
|
+
}
|
|
209
|
+
if (ts_morph_1.Node.isNumericLiteral(node)) {
|
|
210
|
+
return `l:${node.getLiteralValue()}`;
|
|
211
|
+
}
|
|
212
|
+
return this.referenceKey(node, symbolIds);
|
|
213
|
+
}
|
|
214
|
+
symbolId(symbol, symbolIds) {
|
|
215
|
+
const known = symbolIds.get(symbol);
|
|
216
|
+
if (known !== undefined) {
|
|
217
|
+
return known;
|
|
218
|
+
}
|
|
219
|
+
const id = symbolIds.size;
|
|
220
|
+
symbolIds.set(symbol, id);
|
|
221
|
+
return id;
|
|
222
|
+
}
|
|
223
|
+
/** Strips parentheses and non-null assertions. */
|
|
224
|
+
unwrap(expr) {
|
|
225
|
+
if (ts_morph_1.Node.isParenthesizedExpression(expr) || ts_morph_1.Node.isNonNullExpression(expr)) {
|
|
226
|
+
return this.unwrap(expr.getExpression());
|
|
227
|
+
}
|
|
228
|
+
return expr;
|
|
229
|
+
}
|
|
230
|
+
/** Name of the function, method or accessor that holds the chain. */
|
|
231
|
+
chainOwner(ifStmt) {
|
|
232
|
+
const fn = ifStmt.getFirstAncestor((ancestor) => this.isFunctionLike(ancestor));
|
|
233
|
+
if (fn === undefined) {
|
|
234
|
+
return { functionName: '<top level>' };
|
|
235
|
+
}
|
|
236
|
+
const name = this.functionName(fn);
|
|
237
|
+
const parent = fn.getParent();
|
|
238
|
+
if (ts_morph_1.Node.isClassDeclaration(parent) || ts_morph_1.Node.isClassExpression(parent)) {
|
|
239
|
+
const className = parent.getName() ?? '<anonymous>';
|
|
240
|
+
return { functionName: `${className}.${name}`, className };
|
|
241
|
+
}
|
|
242
|
+
return { functionName: name };
|
|
243
|
+
}
|
|
244
|
+
isFunctionLike(node) {
|
|
245
|
+
return (ts_morph_1.Node.isFunctionDeclaration(node) ||
|
|
246
|
+
ts_morph_1.Node.isMethodDeclaration(node) ||
|
|
247
|
+
ts_morph_1.Node.isConstructorDeclaration(node) ||
|
|
248
|
+
ts_morph_1.Node.isGetAccessorDeclaration(node) ||
|
|
249
|
+
ts_morph_1.Node.isSetAccessorDeclaration(node) ||
|
|
250
|
+
ts_morph_1.Node.isArrowFunction(node) ||
|
|
251
|
+
ts_morph_1.Node.isFunctionExpression(node));
|
|
252
|
+
}
|
|
253
|
+
functionName(fn) {
|
|
254
|
+
if (ts_morph_1.Node.isConstructorDeclaration(fn)) {
|
|
255
|
+
return 'constructor';
|
|
256
|
+
}
|
|
257
|
+
if (ts_morph_1.Node.isFunctionDeclaration(fn) ||
|
|
258
|
+
ts_morph_1.Node.isMethodDeclaration(fn) ||
|
|
259
|
+
ts_morph_1.Node.isGetAccessorDeclaration(fn) ||
|
|
260
|
+
ts_morph_1.Node.isSetAccessorDeclaration(fn) ||
|
|
261
|
+
ts_morph_1.Node.isFunctionExpression(fn)) {
|
|
262
|
+
const name = fn.getName();
|
|
263
|
+
if (name !== undefined) {
|
|
264
|
+
return name;
|
|
172
265
|
}
|
|
173
266
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
line: ifStmt.getStartLineNumber(),
|
|
180
|
-
column: ifStmt.getStart() - ifStmt.getStartLinePos(),
|
|
181
|
-
suggestedFix: `Replace if-else chain with polymorphism or strategy pattern to make the code open for extension.`,
|
|
182
|
-
metadata: {
|
|
183
|
-
className,
|
|
184
|
-
chainLength,
|
|
185
|
-
maxAllowed: this.maxIfElseChain,
|
|
186
|
-
violationType: 'long-if-else-chain',
|
|
187
|
-
principle: 'OCP',
|
|
188
|
-
},
|
|
189
|
-
};
|
|
267
|
+
const holder = fn.getParent();
|
|
268
|
+
if (ts_morph_1.Node.isVariableDeclaration(holder) ||
|
|
269
|
+
ts_morph_1.Node.isPropertyDeclaration(holder) ||
|
|
270
|
+
ts_morph_1.Node.isPropertyAssignment(holder)) {
|
|
271
|
+
return holder.getName();
|
|
190
272
|
}
|
|
191
|
-
return
|
|
273
|
+
return '<anonymous function>';
|
|
192
274
|
}
|
|
193
275
|
}
|
|
194
276
|
exports.OCPViolationRule = OCPViolationRule;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import type { AnalysisRule, AnalysisContext, AnalysisResult } from '@angular-modernizer/plugin-system';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Former options of {@link ServiceDipViolationRule}. The rule reports
|
|
4
|
+
* nothing, so no option has an effect.
|
|
5
|
+
*
|
|
6
|
+
* @deprecated Has no effect; removed in 3.0.
|
|
4
7
|
*/
|
|
5
8
|
export interface ServiceDipViolationConfig {
|
|
6
|
-
/**
|
|
7
|
-
* When true, only report violations that cross architectural layer boundaries.
|
|
8
|
-
* Layers are inferred from path segments: shared, features, core, lib, app, config.
|
|
9
|
-
* Default: false (report all concrete constructor injections).
|
|
10
|
-
*/
|
|
9
|
+
/** @deprecated Has no effect. */
|
|
11
10
|
crossLayerOnly?: boolean;
|
|
12
11
|
}
|
|
13
12
|
/**
|
|
14
|
-
* Metadata of
|
|
13
|
+
* Metadata of former {@link ServiceDipViolationRule} results. The rule reports
|
|
14
|
+
* nothing, so no result carries it.
|
|
15
|
+
*
|
|
16
|
+
* @deprecated No result carries it; removed in 3.0.
|
|
15
17
|
*/
|
|
16
18
|
export interface ServiceDipViolationMetadata {
|
|
17
19
|
/** Always `concrete-injection`. */
|
|
@@ -24,71 +26,45 @@ export interface ServiceDipViolationMetadata {
|
|
|
24
26
|
parameterName: string;
|
|
25
27
|
/** Suggested interface name: `I` + injected class name. */
|
|
26
28
|
suggestedInterfaceName: string;
|
|
27
|
-
/**
|
|
29
|
+
/** Former constant confidence. */
|
|
28
30
|
confidence: number;
|
|
29
|
-
/**
|
|
31
|
+
/** Former constant `false`. */
|
|
30
32
|
isBidirectional: boolean;
|
|
31
|
-
/** Whether both layers
|
|
33
|
+
/** Whether both path layers were known and differed. */
|
|
32
34
|
isCrossLayer: boolean;
|
|
33
|
-
/**
|
|
35
|
+
/** Path layer of the injecting file. */
|
|
34
36
|
injectingLayer?: string;
|
|
35
|
-
/**
|
|
37
|
+
/** Path layer of the injected file. */
|
|
36
38
|
injectedLayer?: string;
|
|
37
39
|
}
|
|
38
40
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* {@link ServiceDipViolationConfig.crossLayerOnly}, only injections between
|
|
47
|
-
* different path-based layers are reported. Declaration files are skipped.
|
|
41
|
+
* Former check for concrete `@Injectable` constructor injection
|
|
42
|
+
* (`solid:service-dip-violation`). Reports nothing: injecting a concrete
|
|
43
|
+
* `@Injectable` class is Angular's normal DI, not a defect. The one harmful
|
|
44
|
+
* shape, an injection against the layer direction, is always an import
|
|
45
|
+
* upwards, which `architecture:layer-boundary-violation` reports for the
|
|
46
|
+
* configured `layers` / `layersSource` (and suppresses with its
|
|
47
|
+
* `suppressionComments` markers).
|
|
48
48
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
49
|
+
* The id stays registered so configurations naming it keep loading; ConfigLoader
|
|
50
|
+
* warns that `rules['solid:service-dip-violation']` has no effect. The
|
|
51
|
+
* `service-dip-violation-transform` ({@link ServiceDipViolationTransformRule})
|
|
52
|
+
* detects its targets itself and keeps working.
|
|
51
53
|
*
|
|
52
|
-
* @
|
|
53
|
-
*
|
|
54
|
-
* // Violation detected:
|
|
55
|
-
* class UserService {
|
|
56
|
-
* constructor(private orderService: OrderService) {}
|
|
57
|
-
* }
|
|
58
|
-
*
|
|
59
|
-
* // Suggested fix:
|
|
60
|
-
* class UserService {
|
|
61
|
-
* constructor(private orderService: IOrderService) {}
|
|
62
|
-
* }
|
|
63
|
-
* ```
|
|
54
|
+
* @deprecated Reports nothing; removed in 3.0. Layer direction is checked by
|
|
55
|
+
* `architecture:layer-boundary-violation`.
|
|
64
56
|
*/
|
|
65
57
|
export declare class ServiceDipViolationRule implements AnalysisRule {
|
|
66
58
|
readonly id = "solid:service-dip-violation";
|
|
67
|
-
readonly name = "Service DIP Violation";
|
|
68
|
-
readonly description = "
|
|
59
|
+
readonly name = "Service DIP Violation (deprecated)";
|
|
60
|
+
readonly description = "Deprecated, reports nothing: injections against the layer direction are reported by architecture:layer-boundary-violation";
|
|
69
61
|
readonly severity = "warning";
|
|
70
62
|
readonly category = "solid-violation";
|
|
71
63
|
readonly tags: string[];
|
|
72
|
-
private readonly config;
|
|
73
|
-
constructor(config?: ServiceDipViolationConfig);
|
|
74
|
-
analyze(context: AnalysisContext): Promise<AnalysisResult[]>;
|
|
75
|
-
private checkParameter;
|
|
76
|
-
/**
|
|
77
|
-
* Resolves the class declaration that a constructor parameter's type refers to.
|
|
78
|
-
* Uses ts-morph's type checker — works across files within the same Project.
|
|
79
|
-
*/
|
|
80
|
-
private resolveServiceDeclaration;
|
|
81
|
-
/**
|
|
82
|
-
* Checks whether a class has an `@Injectable` decorator.
|
|
83
|
-
* Pattern copied from angular-service-without-injectable.rule.ts.
|
|
84
|
-
*/
|
|
85
|
-
private hasInjectableDecorator;
|
|
86
64
|
/**
|
|
87
|
-
*
|
|
88
|
-
* Path-based fallback adapted from import-direction-violation.rule.ts.
|
|
89
|
-
*
|
|
90
|
-
* Returns undefined when no known layer segment is found.
|
|
65
|
+
* @param _config - Ignored; kept so existing callers compile.
|
|
91
66
|
*/
|
|
92
|
-
|
|
67
|
+
constructor(_config?: ServiceDipViolationConfig);
|
|
68
|
+
analyze(_context: AnalysisContext): Promise<AnalysisResult[]>;
|
|
93
69
|
}
|
|
94
70
|
//# sourceMappingURL=service-dip-violation.analysis.rule.d.ts.map
|