@archest/jest 1.0.1
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/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +162 -0
- package/dist/index.mjs.map +1 -0
- package/dist/matchers/index.d.ts +23 -0
- package/dist/matchers/models.d.ts +201 -0
- package/node_modules/@archest/core/dist/classes/classCheckExtendClass.d.ts +3 -0
- package/node_modules/@archest/core/dist/classes/classCheckHaveMaxCyclomaticComplexity.d.ts +3 -0
- package/node_modules/@archest/core/dist/classes/classCheckHaveModifier.d.ts +3 -0
- package/node_modules/@archest/core/dist/classes/classCheckHaveNameMatchingFileName.d.ts +3 -0
- package/node_modules/@archest/core/dist/classes/classCheckImplementInterface.d.ts +3 -0
- package/node_modules/@archest/core/dist/classes/classCheckMatchNamePattern.d.ts +3 -0
- package/node_modules/@archest/core/dist/classes/classCheckResideInFolder.d.ts +3 -0
- package/node_modules/@archest/core/dist/classes/locateClasses.d.ts +5 -0
- package/node_modules/@archest/core/dist/classes/types.d.ts +25 -0
- package/node_modules/@archest/core/dist/dto.d.ts +78 -0
- package/node_modules/@archest/core/dist/files/checkDependOnExternalModule.d.ts +3 -0
- package/node_modules/@archest/core/dist/files/checkDependOnFilesInFolder.d.ts +3 -0
- package/node_modules/@archest/core/dist/files/fileCheckBeFreeOfCycles.d.ts +3 -0
- package/node_modules/@archest/core/dist/files/fileCheckHaveMaxCyclomaticComplexity.d.ts +3 -0
- package/node_modules/@archest/core/dist/files/fileCheckHaveMaxExportedFunctions.d.ts +3 -0
- package/node_modules/@archest/core/dist/files/fileCheckHaveMinMaintainabilityIndex.d.ts +3 -0
- package/node_modules/@archest/core/dist/files/fileCheckMatchNamePattern.d.ts +3 -0
- package/node_modules/@archest/core/dist/files/getFileDependencies.d.ts +2 -0
- package/node_modules/@archest/core/dist/files/locateFiles.d.ts +4 -0
- package/node_modules/@archest/core/dist/files/types.d.ts +17 -0
- package/node_modules/@archest/core/dist/functions/functionCheckHaveExplicitReturnType.d.ts +3 -0
- package/node_modules/@archest/core/dist/functions/functionCheckHaveMaxCyclomaticComplexity.d.ts +3 -0
- package/node_modules/@archest/core/dist/functions/functionCheckHaveMinMaintainabilityIndex.d.ts +3 -0
- package/node_modules/@archest/core/dist/functions/functionCheckHaveModifier.d.ts +3 -0
- package/node_modules/@archest/core/dist/functions/functionCheckHaveNameMatchingFileName.d.ts +3 -0
- package/node_modules/@archest/core/dist/functions/functionCheckMatchNamePattern.d.ts +3 -0
- package/node_modules/@archest/core/dist/functions/locateFunctions.d.ts +5 -0
- package/node_modules/@archest/core/dist/functions/types.d.ts +19 -0
- package/node_modules/@archest/core/dist/index.d.ts +43 -0
- package/node_modules/@archest/core/dist/index.js +14 -0
- package/node_modules/@archest/core/dist/index.js.map +1 -0
- package/node_modules/@archest/core/dist/index.mjs +607 -0
- package/node_modules/@archest/core/dist/index.mjs.map +1 -0
- package/node_modules/@archest/core/dist/layers/checkLayeredArchitecture.d.ts +3 -0
- package/node_modules/@archest/core/dist/layers/createLayeredArchitecture.d.ts +3 -0
- package/node_modules/@archest/core/dist/layers/getLayerDependencies.d.ts +2 -0
- package/node_modules/@archest/core/dist/layers/layer.d.ts +2 -0
- package/node_modules/@archest/core/dist/layers/layerShouldNotBeAccessedByAnyLayer.d.ts +2 -0
- package/node_modules/@archest/core/dist/layers/layerShouldOnlyBeAccessedBy.d.ts +2 -0
- package/node_modules/@archest/core/dist/layers/types.d.ts +8 -0
- package/node_modules/@archest/core/dist/metrics/calculateCyclomaticComplexity.d.ts +2 -0
- package/node_modules/@archest/core/dist/metrics/calculateMaintainabilityIndex.d.ts +2 -0
- package/node_modules/@archest/core/dist/project/parseProject.d.ts +55 -0
- package/node_modules/@archest/core/dist/properties/locateProperties.d.ts +5 -0
- package/node_modules/@archest/core/dist/properties/propertyCheckBeReadonly.d.ts +3 -0
- package/node_modules/@archest/core/dist/properties/types.d.ts +17 -0
- package/node_modules/@archest/core/dist/shared/sharedCheckHaveMaxCyclomaticComplexity.d.ts +1 -0
- package/node_modules/@archest/core/dist/shared/sharedCheckHaveMinMaintainabilityIndex.d.ts +1 -0
- package/node_modules/@archest/core/dist/shared/sharedCheckHaveModifier.d.ts +7 -0
- package/node_modules/@archest/core/dist/shared/sharedCheckHaveNameMatchingFileName.d.ts +3 -0
- package/node_modules/@archest/core/dist/shared/sharedCheckMatchNamePattern.d.ts +1 -0
- package/node_modules/@archest/core/dist/slices/locateSlices.d.ts +3 -0
- package/node_modules/@archest/core/dist/slices/sliceCheckBeFreeOfCycles.d.ts +3 -0
- package/node_modules/@archest/core/dist/slices/sliceCheckHaveMaxDistanceFromMainSequence.d.ts +3 -0
- package/node_modules/@archest/core/dist/slices/types.d.ts +8 -0
- package/node_modules/@archest/core/dist/types.d.ts +11 -0
- package/node_modules/@archest/core/dist/utils/ruleBuilder.d.ts +6 -0
- package/node_modules/@archest/core/package.json +49 -0
- package/node_modules/@archest/core-rust/core-rust.darwin-arm64.node +0 -0
- package/node_modules/@archest/core-rust/index.d.ts +16 -0
- package/node_modules/@archest/core-rust/index.js +316 -0
- package/node_modules/@archest/core-rust/package.json +34 -0
- package/package.json +56 -0
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
import * as e from "node:path";
|
|
2
|
+
import { dirname as t } from "node:path";
|
|
3
|
+
import { ArchestProject as n } from "@archest/core-rust";
|
|
4
|
+
import * as r from "typescript";
|
|
5
|
+
//#region src/classes/classCheckExtendClass.ts
|
|
6
|
+
function i(e, t, n) {
|
|
7
|
+
let r = [];
|
|
8
|
+
for (let i of e.classes) {
|
|
9
|
+
let e = i.name || "Anonymous", a = !1;
|
|
10
|
+
i.extends === t && (a = !0), n && a ? r.push(`Class ${e} extends ${t}, but it shouldn't.`) : !n && !a && r.push(`Class ${e} does not extend ${t}, but it should.`);
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
pass: r.length === 0,
|
|
14
|
+
message: () => r.join("\n")
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/utils/ruleBuilder.ts
|
|
19
|
+
function a(e, t, n) {
|
|
20
|
+
let r = [];
|
|
21
|
+
for (let i of e) {
|
|
22
|
+
let { passes: e, failMessage: a, failNotMessage: o } = n(i);
|
|
23
|
+
t && e ? o && r.push(o) : !t && !e && a && r.push(a);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
pass: r.length === 0,
|
|
27
|
+
message: () => r.join("\n")
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/shared/sharedCheckHaveMaxCyclomaticComplexity.ts
|
|
32
|
+
function o(e, t, n, r, i, o) {
|
|
33
|
+
return a(e, o, (e) => {
|
|
34
|
+
let a = t(e), o = n(e), s = o > i, c = `${r} ${a || "Anonymous"}`;
|
|
35
|
+
return {
|
|
36
|
+
passes: !s,
|
|
37
|
+
failMessage: `${c} has a total cyclomatic complexity of ${o}, which exceeds the maximum of ${i}.`,
|
|
38
|
+
failNotMessage: `${c} has a total cyclomatic complexity of ${o}, which exceeds the maximum of ${i}, but it shouldn't.`
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/classes/classCheckHaveMaxCyclomaticComplexity.ts
|
|
44
|
+
function s(e, t, n) {
|
|
45
|
+
return o(e.classes, (e) => e.name, (e) => e.cyclomatic_complexity || 0, "Class", t, n);
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/shared/sharedCheckHaveModifier.ts
|
|
49
|
+
function c(e, t, n, r, i) {
|
|
50
|
+
return a(e, i, (e) => {
|
|
51
|
+
let i = t(e), a = !1;
|
|
52
|
+
switch (r) {
|
|
53
|
+
case "export":
|
|
54
|
+
a = !!e.is_exported;
|
|
55
|
+
break;
|
|
56
|
+
case "default":
|
|
57
|
+
a = !!e.is_default;
|
|
58
|
+
break;
|
|
59
|
+
case "abstract":
|
|
60
|
+
a = !!e.is_abstract;
|
|
61
|
+
break;
|
|
62
|
+
case "async":
|
|
63
|
+
a = !!e.is_async;
|
|
64
|
+
break;
|
|
65
|
+
case "readonly":
|
|
66
|
+
a = !!e.is_readonly;
|
|
67
|
+
break;
|
|
68
|
+
default: throw Error(`Modifier ${r} is not fully supported.`);
|
|
69
|
+
}
|
|
70
|
+
let o = `${n} ${i || "Anonymous"}`;
|
|
71
|
+
return {
|
|
72
|
+
passes: a,
|
|
73
|
+
failMessage: `${o} does not have modifier ${r}, but it should.`,
|
|
74
|
+
failNotMessage: `${o} has modifier ${r}, but it shouldn't.`
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/classes/classCheckHaveModifier.ts
|
|
80
|
+
function l(e, t, n) {
|
|
81
|
+
return c(e.classes, (e) => e.name, "Class", t, n);
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/shared/sharedCheckHaveNameMatchingFileName.ts
|
|
85
|
+
function u(t, n, r, i) {
|
|
86
|
+
return a(t, i, (t) => {
|
|
87
|
+
let i = n(t);
|
|
88
|
+
if (!t._filePath) return {
|
|
89
|
+
passes: !0,
|
|
90
|
+
failMessage: "",
|
|
91
|
+
failNotMessage: ""
|
|
92
|
+
};
|
|
93
|
+
let a = e.basename(t._filePath, e.extname(t._filePath)), o = i === a, s = `${r} ${i || "Anonymous"}`;
|
|
94
|
+
return {
|
|
95
|
+
passes: o,
|
|
96
|
+
failMessage: `${s} does not have a name matching its filename ${a}, but it should.`,
|
|
97
|
+
failNotMessage: `${s} has a name matching its filename ${a}, but it shouldn't.`
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/classes/classCheckHaveNameMatchingFileName.ts
|
|
103
|
+
function d(e, t) {
|
|
104
|
+
return u(e.classes, (e) => e.name, "Class", t);
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/classes/classCheckImplementInterface.ts
|
|
108
|
+
function f(e, t, n) {
|
|
109
|
+
let r = [];
|
|
110
|
+
for (let i of e.classes) {
|
|
111
|
+
let e = i.name || "Anonymous", a = !1;
|
|
112
|
+
i.implements.includes(t) && (a = !0), n && a ? r.push(`Class ${e} implements ${t}, but it shouldn't.`) : !n && !a && r.push(`Class ${e} does not implement ${t}, but it should.`);
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
pass: r.length === 0,
|
|
116
|
+
message: () => r.join("\n")
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/shared/sharedCheckMatchNamePattern.ts
|
|
121
|
+
function p(e, t, n, r, i) {
|
|
122
|
+
let o = typeof r == "string" ? new RegExp(r) : r;
|
|
123
|
+
return a(e, i, (e) => {
|
|
124
|
+
let i = t(e), a = i ? o.test(i) : !1, s = `${n} ${i || "Anonymous"}`;
|
|
125
|
+
return {
|
|
126
|
+
passes: a,
|
|
127
|
+
failMessage: `${s} does not match pattern ${r}, but it should.`,
|
|
128
|
+
failNotMessage: `${s} matches pattern ${r}, but it shouldn't.`
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/classes/classCheckMatchNamePattern.ts
|
|
134
|
+
function m(e, t, n) {
|
|
135
|
+
return p(e.classes, (e) => e.name, "Class", t, n);
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/classes/classCheckResideInFolder.ts
|
|
139
|
+
function h(e, t, n) {
|
|
140
|
+
let r = [];
|
|
141
|
+
for (let i of e.classes) {
|
|
142
|
+
let e = i.name || "Anonymous Class", a = i._filePath, o = a.includes(`/${t}/`) || a.includes(`\\${t}\\`);
|
|
143
|
+
n && o ? r.push(`Class ${e} resides in ${t}, but it shouldn't.`) : !n && !o && r.push(`Class ${e} does not reside in ${t}, but it should.`);
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
pass: r.length === 0,
|
|
147
|
+
message: () => r.join("\n")
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/classes/locateClasses.ts
|
|
152
|
+
function g(e, t, n) {
|
|
153
|
+
let r = e;
|
|
154
|
+
if (n?.inFolder && (r = r.filter((e) => e._filePath.includes(`/${n.inFolder}/`) || e._filePath.includes(`\\${n.inFolder}\\`))), n?.matchNamePattern) {
|
|
155
|
+
let e = typeof n.matchNamePattern == "string" ? new RegExp(n.matchNamePattern) : n.matchNamePattern;
|
|
156
|
+
r = r.filter((t) => t.name && e.test(t.name));
|
|
157
|
+
}
|
|
158
|
+
return n?.withDecorator && (r = r.filter((e) => e.decorators.includes(n.withDecorator))), n?.extending && (r = r.filter((e) => e.extends === n.extending)), n?.implementing && (r = r.filter((e) => e.implements.includes(n.implementing))), n?.havingModifier && (r = r.filter((e) => {
|
|
159
|
+
switch (n.havingModifier) {
|
|
160
|
+
case "export": return e.is_exported;
|
|
161
|
+
case "default": return e.is_default;
|
|
162
|
+
case "abstract": return e.is_abstract;
|
|
163
|
+
default: throw Error(`Modifier ${n.havingModifier} is not fully supported.`);
|
|
164
|
+
}
|
|
165
|
+
})), {
|
|
166
|
+
type: "ClassLocator",
|
|
167
|
+
classes: r,
|
|
168
|
+
projectData: t
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/files/checkDependOnExternalModule.ts
|
|
173
|
+
function _(e, t, n) {
|
|
174
|
+
let r = [], i = typeof t == "string" ? new RegExp(t) : t;
|
|
175
|
+
for (let a of e.files) {
|
|
176
|
+
let e = (a.external_dependencies || []).some((e) => i.test(e));
|
|
177
|
+
n && e ? r.push(`${a.path} incorrectly depends on external module '${t}'`) : !n && !e && r.push(`${a.path} does not depend on external module '${t}'`);
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
pass: r.length === 0,
|
|
181
|
+
message: () => r.join("\n")
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/files/getFileDependencies.ts
|
|
186
|
+
function v(e, t) {
|
|
187
|
+
return e.dependencies || [];
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/files/checkDependOnFilesInFolder.ts
|
|
191
|
+
function y(e, t, n) {
|
|
192
|
+
let r = [];
|
|
193
|
+
for (let i of e.files) {
|
|
194
|
+
let a = v(i, e.projectData).some((e) => e.includes(`/${t}/`) || e.includes(`\\${t}\\`));
|
|
195
|
+
n && a ? r.push(`File ${i.path} depends on files in ${t}, but it shouldn't.`) : !n && !a && r.push(`File ${i.path} does not depend on files in ${t}, but it should.`);
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
pass: r.length === 0,
|
|
199
|
+
message: () => r.join("\n")
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/files/fileCheckBeFreeOfCycles.ts
|
|
204
|
+
function b(e, t) {
|
|
205
|
+
let n = e.files.map((e) => e.path), r = e.archestProject;
|
|
206
|
+
if (!r) return {
|
|
207
|
+
pass: !0,
|
|
208
|
+
message: () => "Mock pass: archestProject not in registry"
|
|
209
|
+
};
|
|
210
|
+
let i = r.checkFileCycles(n, !!t);
|
|
211
|
+
return {
|
|
212
|
+
pass: i.pass,
|
|
213
|
+
message: () => i.message
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/files/fileCheckHaveMaxCyclomaticComplexity.ts
|
|
218
|
+
function x(e, t, n) {
|
|
219
|
+
return o(e.files, (e) => e.path, (e) => {
|
|
220
|
+
let t = 0;
|
|
221
|
+
for (let n of e.functions) t += n.cyclomatic_complexity || 0;
|
|
222
|
+
for (let n of e.classes) t += n.cyclomatic_complexity || 0;
|
|
223
|
+
return t;
|
|
224
|
+
}, "File", t, n);
|
|
225
|
+
}
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/files/fileCheckHaveMaxExportedFunctions.ts
|
|
228
|
+
function S(e, t, n) {
|
|
229
|
+
let r = [];
|
|
230
|
+
for (let i of e.files) {
|
|
231
|
+
let e = i.functions.filter((e) => e.is_exported).length, a = e > t;
|
|
232
|
+
n && a ? r.push(`File ${i.path} has ${e} exported functions, which exceeds the maximum of ${t}, but it shouldn't.`) : !n && a && r.push(`File ${i.path} has ${e} exported functions, which exceeds the maximum of ${t}.`);
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
pass: n ? r.length > 0 : r.length === 0,
|
|
236
|
+
message: () => r.join("\n") || (n ? "Expected some files to exceed maximum exported functions, but none did." : "")
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/shared/sharedCheckHaveMinMaintainabilityIndex.ts
|
|
241
|
+
function C(e, t, n, r, i, o) {
|
|
242
|
+
return a(e, o, (e) => {
|
|
243
|
+
let a = t(e), o = n(e), s = o < i, c = `${r} ${a || "Anonymous"}`;
|
|
244
|
+
return {
|
|
245
|
+
passes: !s,
|
|
246
|
+
failMessage: `${c} has a maintainability index of ${o.toFixed(2)}, which falls below the minimum of ${i}.`,
|
|
247
|
+
failNotMessage: `${c} has a maintainability index of ${o.toFixed(2)}, which falls below the minimum of ${i}, but it shouldn't.`
|
|
248
|
+
};
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/files/fileCheckHaveMinMaintainabilityIndex.ts
|
|
253
|
+
function w(e, t, n) {
|
|
254
|
+
return C(e.files, (e) => e.path, (e) => e.functions.length > 0 && e.functions[0].maintainability_index || 100, "File", t, n);
|
|
255
|
+
}
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/files/fileCheckMatchNamePattern.ts
|
|
258
|
+
function T(e, t, n) {
|
|
259
|
+
return p(e.files, (e) => e.path, "File", t, n);
|
|
260
|
+
}
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region src/files/locateFiles.ts
|
|
263
|
+
function E(e, t, n, r) {
|
|
264
|
+
let i = e;
|
|
265
|
+
if (r?.inFolder && (i = i.filter((e) => e.path.includes(`/${r.inFolder}/`) || e.path.includes(`\\${r.inFolder}\\`))), r?.matchNamePattern) {
|
|
266
|
+
let e = typeof r.matchNamePattern == "string" ? new RegExp(r.matchNamePattern) : r.matchNamePattern;
|
|
267
|
+
i = i.filter((t) => e.test(t.path));
|
|
268
|
+
}
|
|
269
|
+
let a = {
|
|
270
|
+
type: "FileLocator",
|
|
271
|
+
files: i,
|
|
272
|
+
projectData: t
|
|
273
|
+
};
|
|
274
|
+
return n && Object.defineProperty(a, "archestProject", {
|
|
275
|
+
value: n,
|
|
276
|
+
enumerable: !1
|
|
277
|
+
}), a;
|
|
278
|
+
}
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/functions/functionCheckHaveExplicitReturnType.ts
|
|
281
|
+
function D(e, t) {
|
|
282
|
+
let n = [];
|
|
283
|
+
for (let r of e.functions) {
|
|
284
|
+
let e = r.name || "Anonymous Function", i = r.has_explicit_return_type;
|
|
285
|
+
t && i ? n.push(`Function ${e} has an explicit return type, but it shouldn't.`) : !t && !i && n.push(`Function ${e} does not have an explicit return type, but it should.`);
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
pass: n.length === 0,
|
|
289
|
+
message: () => n.join("\n")
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/functions/functionCheckHaveMaxCyclomaticComplexity.ts
|
|
294
|
+
function O(e, t, n) {
|
|
295
|
+
return o(e.functions, (e) => e.name, (e) => e.cyclomatic_complexity || 0, "Function", t, n);
|
|
296
|
+
}
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/functions/functionCheckHaveMinMaintainabilityIndex.ts
|
|
299
|
+
function k(e, t, n) {
|
|
300
|
+
return C(e.functions, (e) => e.name, (e) => e.maintainability_index || 100, "Function", t, n);
|
|
301
|
+
}
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region src/functions/functionCheckHaveModifier.ts
|
|
304
|
+
function A(e, t, n) {
|
|
305
|
+
return c(e.functions, (e) => e.name, "Function", t, n);
|
|
306
|
+
}
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region src/functions/functionCheckHaveNameMatchingFileName.ts
|
|
309
|
+
function j(e, t) {
|
|
310
|
+
return u(e.functions, (e) => e.name, "Function", t);
|
|
311
|
+
}
|
|
312
|
+
//#endregion
|
|
313
|
+
//#region src/functions/functionCheckMatchNamePattern.ts
|
|
314
|
+
function M(e, t, n) {
|
|
315
|
+
return p(e.functions, (e) => e.name, "Function", t, n);
|
|
316
|
+
}
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/functions/locateFunctions.ts
|
|
319
|
+
function N(e, t, n) {
|
|
320
|
+
let r = e;
|
|
321
|
+
if (n?.inFolder && (r = r.filter((e) => e._filePath.includes(`/${n.inFolder}/`) || e._filePath.includes(`\\${n.inFolder}\\`))), n?.matchNamePattern) {
|
|
322
|
+
let e = typeof n.matchNamePattern == "string" ? new RegExp(n.matchNamePattern) : n.matchNamePattern;
|
|
323
|
+
r = r.filter((t) => t.name && e.test(t.name));
|
|
324
|
+
}
|
|
325
|
+
return n?.isTopLevel && (r = r.filter((e) => e.is_top_level)), {
|
|
326
|
+
type: "FunctionLocator",
|
|
327
|
+
functions: r,
|
|
328
|
+
projectData: t
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/layers/checkLayeredArchitecture.ts
|
|
333
|
+
function P(e) {
|
|
334
|
+
let t = [];
|
|
335
|
+
for (let n of e.assertions) t.push(...n(e.files));
|
|
336
|
+
return {
|
|
337
|
+
pass: t.length === 0,
|
|
338
|
+
message: () => t.join("\n")
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region src/layers/createLayeredArchitecture.ts
|
|
343
|
+
function F(e, t) {
|
|
344
|
+
return {
|
|
345
|
+
type: "LayeredArchitecture",
|
|
346
|
+
files: e,
|
|
347
|
+
layers: /* @__PURE__ */ new Map(),
|
|
348
|
+
assertions: [],
|
|
349
|
+
projectData: t
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
//#endregion
|
|
353
|
+
//#region src/layers/layer.ts
|
|
354
|
+
function I(e, t, n) {
|
|
355
|
+
return e.layers.set(t, n), e;
|
|
356
|
+
}
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/layers/getLayerDependencies.ts
|
|
359
|
+
function L(e, t) {
|
|
360
|
+
return e.dependencies || [];
|
|
361
|
+
}
|
|
362
|
+
//#endregion
|
|
363
|
+
//#region src/layers/layerShouldNotBeAccessedByAnyLayer.ts
|
|
364
|
+
function R(e, t) {
|
|
365
|
+
if (!e.layers.has(t)) throw Error(`Layer ${t} is not defined`);
|
|
366
|
+
return e.assertions.push((n) => {
|
|
367
|
+
let r = [], i = e.layers.get(t);
|
|
368
|
+
for (let a of n) {
|
|
369
|
+
let n = a.path;
|
|
370
|
+
!n.includes(`/${i}/`) && !n.includes(`\\${i}\\`) && L(a, e.projectData).some((e) => e.includes(`/${i}/`) || e.includes(`\\${i}\\`)) && r.push(`File ${n} accesses layer ${t} but it shouldn't.`);
|
|
371
|
+
}
|
|
372
|
+
return r;
|
|
373
|
+
}), e;
|
|
374
|
+
}
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/layers/layerShouldOnlyBeAccessedBy.ts
|
|
377
|
+
function z(e, t, n) {
|
|
378
|
+
if (!e.layers.has(t)) throw Error(`Layer ${t} is not defined`);
|
|
379
|
+
return e.assertions.push((r) => {
|
|
380
|
+
let i = [], a = e.layers.get(t), o = n.map((t) => e.layers.get(t));
|
|
381
|
+
for (let s of r) {
|
|
382
|
+
let r = s.path, c = o.some((e) => r.includes(`/${e}/`) || r.includes(`\\${e}\\`));
|
|
383
|
+
!r.includes(`/${a}/`) && !r.includes(`\\${a}\\`) && !c && L(s, e.projectData).some((e) => e.includes(`/${a}/`) || e.includes(`\\${a}\\`)) && i.push(`File ${r} accesses layer ${t} but only ${n.join(", ")} are allowed.`);
|
|
384
|
+
}
|
|
385
|
+
return i;
|
|
386
|
+
}), e;
|
|
387
|
+
}
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region src/properties/locateProperties.ts
|
|
390
|
+
function B(e, t, n) {
|
|
391
|
+
let r = e;
|
|
392
|
+
if (n?.inFolder && (r = r.filter((e) => e._filePath.includes(`/${n.inFolder}/`) || e._filePath.includes(`\\${n.inFolder}\\`))), n?.matchNamePattern) {
|
|
393
|
+
let e = typeof n.matchNamePattern == "string" ? new RegExp(n.matchNamePattern) : n.matchNamePattern;
|
|
394
|
+
r = r.filter((t) => e.test(t.name));
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
type: "PropertyLocator",
|
|
398
|
+
properties: r,
|
|
399
|
+
projectData: t
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
//#endregion
|
|
403
|
+
//#region src/slices/locateSlices.ts
|
|
404
|
+
function V(e, t, n) {
|
|
405
|
+
let r = n.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "([^/\\\\]+)"), i = new RegExp(r), a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
|
|
406
|
+
for (let t of e) {
|
|
407
|
+
let e = t.path.match(i);
|
|
408
|
+
if (e?.[1]) {
|
|
409
|
+
let n = e[1];
|
|
410
|
+
a.add(n), o.has(n) || o.set(n, []), o.get(n)?.push(t);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return {
|
|
414
|
+
type: "SliceLocator",
|
|
415
|
+
slicePattern: i,
|
|
416
|
+
sliceIds: a,
|
|
417
|
+
sliceFiles: o,
|
|
418
|
+
projectData: t
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region src/project/parseProject.ts
|
|
423
|
+
function H(e = {}) {
|
|
424
|
+
let i = e.tsConfigFilePath || r.findConfigFile(process.cwd(), r.sys.fileExists, "tsconfig.json");
|
|
425
|
+
if (!i) throw Error("Could not find tsconfig.json");
|
|
426
|
+
let a = t(i), o = r.readConfigFile(i, r.sys.readFile);
|
|
427
|
+
e.include && (o.config.include = e.include), e.exclude && (o.config.exclude = e.exclude);
|
|
428
|
+
let s = r.parseJsonConfigFileContent(o.config, r.sys, a, void 0, i, void 0, [{
|
|
429
|
+
extension: ".vue",
|
|
430
|
+
isMixedContent: !0,
|
|
431
|
+
scriptKind: r.ScriptKind.TS
|
|
432
|
+
}, {
|
|
433
|
+
extension: ".svelte",
|
|
434
|
+
isMixedContent: !0,
|
|
435
|
+
scriptKind: r.ScriptKind.TS
|
|
436
|
+
}]), c = n.parse(s.fileNames), l = JSON.parse(c.getProjectData());
|
|
437
|
+
return {
|
|
438
|
+
projectData: l,
|
|
439
|
+
getFiles: (e) => E(l.files, l, c, e),
|
|
440
|
+
getClasses: (e) => g(l.files.flatMap((e) => e.classes.map((t) => ({
|
|
441
|
+
...t,
|
|
442
|
+
_filePath: e.path
|
|
443
|
+
}))), l, e),
|
|
444
|
+
layeredArchitecture: () => {
|
|
445
|
+
let e = F(l.files, l), t = {
|
|
446
|
+
layer: (n, r) => (e = I(e, n, r), t),
|
|
447
|
+
whereLayer: (n) => ({
|
|
448
|
+
shouldNotBeAccessedByAnyLayer: () => (e = R(e, n), t),
|
|
449
|
+
shouldOnlyBeAccessedBy: (...r) => (e = z(e, n, r), t)
|
|
450
|
+
}),
|
|
451
|
+
check: () => P(e),
|
|
452
|
+
get data() {
|
|
453
|
+
return e;
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
return t;
|
|
457
|
+
},
|
|
458
|
+
getFunctions: (e) => N(l.files.flatMap((e) => e.functions.map((t) => ({
|
|
459
|
+
...t,
|
|
460
|
+
_filePath: e.path
|
|
461
|
+
}))), l, e),
|
|
462
|
+
getProperties: (e) => B(l.files.flatMap((e) => e.properties.map((t) => ({
|
|
463
|
+
...t,
|
|
464
|
+
_filePath: e.path
|
|
465
|
+
}))), l, e),
|
|
466
|
+
getSlices: (e) => V(l.files, l, e)
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region src/properties/propertyCheckBeReadonly.ts
|
|
471
|
+
function U(e, t) {
|
|
472
|
+
let n = [];
|
|
473
|
+
for (let r of e.properties) {
|
|
474
|
+
let e = r.name || "Anonymous Property", i = r.is_readonly;
|
|
475
|
+
t && i ? n.push(`Property ${e} is readonly, but it shouldn't be.`) : !t && !i && n.push(`Property ${e} is not readonly, but it should be.`);
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
pass: n.length === 0,
|
|
479
|
+
message: () => n.join("\n")
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/slices/sliceCheckBeFreeOfCycles.ts
|
|
484
|
+
function W(e, t) {
|
|
485
|
+
let n = /* @__PURE__ */ new Map();
|
|
486
|
+
for (let t of e.sliceIds) n.set(t, /* @__PURE__ */ new Set());
|
|
487
|
+
for (let [t, r] of e.sliceFiles.entries()) for (let i of r) if (i.dependencies) for (let r of i.dependencies) {
|
|
488
|
+
let i = r.match(e.slicePattern);
|
|
489
|
+
if (i?.[1]) {
|
|
490
|
+
let r = i[1];
|
|
491
|
+
r !== t && e.sliceIds.has(r) && n.get(t)?.add(r);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
let r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = [], o = (e, t) => {
|
|
495
|
+
r.add(e), i.add(e);
|
|
496
|
+
for (let s of n.get(e) || []) if (!r.has(s)) {
|
|
497
|
+
if (o(s, [...t, s])) return !0;
|
|
498
|
+
} else if (i.has(s)) return a.push(`Cycle detected between slices: ${t.join(" -> ")} -> ${s}`), !0;
|
|
499
|
+
return i.delete(e), !1;
|
|
500
|
+
};
|
|
501
|
+
for (let t of e.sliceIds) r.has(t) || o(t, [t]);
|
|
502
|
+
return t ? {
|
|
503
|
+
pass: a.length > 0,
|
|
504
|
+
message: () => a.length > 0 ? "" : "Expected cycles between slices but found none."
|
|
505
|
+
} : {
|
|
506
|
+
pass: a.length === 0,
|
|
507
|
+
message: () => a.join("\n")
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
//#endregion
|
|
511
|
+
//#region src/slices/sliceCheckHaveMaxDistanceFromMainSequence.ts
|
|
512
|
+
function G(e, t, n) {
|
|
513
|
+
let r = [], i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
|
|
514
|
+
for (let t of e.sliceIds) i.set(t, /* @__PURE__ */ new Set()), a.set(t, /* @__PURE__ */ new Set());
|
|
515
|
+
for (let [t, n] of e.sliceFiles.entries()) for (let r of n) if (r.dependencies) for (let n of r.dependencies) {
|
|
516
|
+
let r = n.match(e.slicePattern);
|
|
517
|
+
if (r?.[1]) {
|
|
518
|
+
let n = r[1];
|
|
519
|
+
n !== t && e.sliceIds.has(n) && (i.get(t)?.add(n), a.get(n)?.add(t));
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
for (let o of e.sliceIds) {
|
|
523
|
+
let s = i.get(o)?.size || 0, c = a.get(o)?.size || 0, l = e.sliceFiles.get(o), u = 0, d = 0;
|
|
524
|
+
for (let e of l) for (let t of e.classes) d++, t.is_abstract && u++;
|
|
525
|
+
let f = s + c === 0 ? 0 : s / (c + s), p = d === 0 ? 0 : u / d, m = Math.abs(p + f - 1), h = m > t;
|
|
526
|
+
n && h ? r.push(`Slice ${o} has a Distance from the Main Sequence of ${m.toFixed(2)}, which exceeds the maximum of ${t}, but it shouldn't.`) : !n && h && r.push(`Slice ${o} has a Distance from the Main Sequence of ${m.toFixed(2)}, which exceeds the maximum of ${t}.`);
|
|
527
|
+
}
|
|
528
|
+
return {
|
|
529
|
+
pass: n ? r.length > 0 : r.length === 0,
|
|
530
|
+
message: () => r.join("\n") || (n ? "Expected some slices to exceed maximum distance from main sequence, but none did." : "")
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
//#endregion
|
|
534
|
+
//#region src/testUtils.ts
|
|
535
|
+
function K(e, t = "test.ts") {
|
|
536
|
+
return r.createSourceFile(t, e, r.ScriptTarget.Latest, !0);
|
|
537
|
+
}
|
|
538
|
+
function q(e) {
|
|
539
|
+
return { files: e.map((e) => ({
|
|
540
|
+
path: e.fileName,
|
|
541
|
+
classes: Y(e),
|
|
542
|
+
functions: X(e),
|
|
543
|
+
properties: Z(e)
|
|
544
|
+
})) };
|
|
545
|
+
}
|
|
546
|
+
function J(e) {
|
|
547
|
+
return n.parseMock(JSON.stringify(e));
|
|
548
|
+
}
|
|
549
|
+
function Y(e) {
|
|
550
|
+
let t = [];
|
|
551
|
+
return r.forEachChild(e, (n) => {
|
|
552
|
+
if (r.isClassDeclaration(n)) {
|
|
553
|
+
let i = null, a = [];
|
|
554
|
+
if (n.heritageClauses) for (let e of n.heritageClauses) {
|
|
555
|
+
if (e.token === r.SyntaxKind.ExtendsKeyword) for (let t of e.types) r.isIdentifier(t.expression) && (i = t.expression.text);
|
|
556
|
+
if (e.token === r.SyntaxKind.ImplementsKeyword) for (let t of e.types) r.isIdentifier(t.expression) && a.push(t.expression.text);
|
|
557
|
+
}
|
|
558
|
+
let o = [];
|
|
559
|
+
if (r.canHaveDecorators(n)) {
|
|
560
|
+
let e = r.getDecorators(n);
|
|
561
|
+
if (e) for (let t of e) r.isIdentifier(t.expression) ? o.push(t.expression.text) : r.isCallExpression(t.expression) && r.isIdentifier(t.expression.expression) && o.push(t.expression.expression.text);
|
|
562
|
+
}
|
|
563
|
+
t.push({
|
|
564
|
+
name: n.name?.text || null,
|
|
565
|
+
is_exported: r.canHaveModifiers(n) && r.getModifiers(n)?.some((e) => e.kind === r.SyntaxKind.ExportKeyword) || !1,
|
|
566
|
+
is_default: r.canHaveModifiers(n) && r.getModifiers(n)?.some((e) => e.kind === r.SyntaxKind.DefaultKeyword) || !1,
|
|
567
|
+
is_abstract: r.canHaveModifiers(n) && r.getModifiers(n)?.some((e) => e.kind === r.SyntaxKind.AbstractKeyword) || !1,
|
|
568
|
+
extends: i,
|
|
569
|
+
implements: a,
|
|
570
|
+
decorators: o,
|
|
571
|
+
_filePath: e.fileName
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
}), t;
|
|
575
|
+
}
|
|
576
|
+
function X(e) {
|
|
577
|
+
let t = [];
|
|
578
|
+
return r.forEachChild(e, (n) => {
|
|
579
|
+
if (r.isFunctionDeclaration(n) || r.isMethodDeclaration(n) || r.isArrowFunction(n)) {
|
|
580
|
+
let i = null;
|
|
581
|
+
(r.isFunctionDeclaration(n) || r.isMethodDeclaration(n)) && (i = n.name?.getText() || null), t.push({
|
|
582
|
+
name: i,
|
|
583
|
+
is_exported: r.canHaveModifiers(n) && r.getModifiers(n)?.some((e) => e.kind === r.SyntaxKind.ExportKeyword) || !1,
|
|
584
|
+
is_async: r.canHaveModifiers(n) && r.getModifiers(n)?.some((e) => e.kind === r.SyntaxKind.AsyncKeyword) || !1,
|
|
585
|
+
is_top_level: !0,
|
|
586
|
+
has_explicit_return_type: !!n.type,
|
|
587
|
+
_filePath: e.fileName
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
}), t;
|
|
591
|
+
}
|
|
592
|
+
function Z(e) {
|
|
593
|
+
let t = [];
|
|
594
|
+
return r.forEachChild(e, (n) => {
|
|
595
|
+
r.isClassDeclaration(n) && n.members.forEach((n) => {
|
|
596
|
+
r.isPropertyDeclaration(n) && t.push({
|
|
597
|
+
name: n.name.getText(),
|
|
598
|
+
is_readonly: r.canHaveModifiers(n) && r.getModifiers(n)?.some((e) => e.kind === r.SyntaxKind.ReadonlyKeyword) || !1,
|
|
599
|
+
_filePath: e.fileName
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
}), t;
|
|
603
|
+
}
|
|
604
|
+
//#endregion
|
|
605
|
+
export { _ as checkDependOnExternalModule, y as checkDependOnFilesInFolder, P as checkLayeredArchitecture, i as classCheckExtendClass, s as classCheckHaveMaxCyclomaticComplexity, l as classCheckHaveModifier, d as classCheckHaveNameMatchingFileName, f as classCheckImplementInterface, m as classCheckMatchNamePattern, h as classCheckResideInFolder, F as createLayeredArchitecture, J as createMockArchestProject, q as createMockProgram, K as createSourceFile, b as fileCheckBeFreeOfCycles, x as fileCheckHaveMaxCyclomaticComplexity, S as fileCheckHaveMaxExportedFunctions, w as fileCheckHaveMinMaintainabilityIndex, T as fileCheckMatchNamePattern, D as functionCheckHaveExplicitReturnType, O as functionCheckHaveMaxCyclomaticComplexity, k as functionCheckHaveMinMaintainabilityIndex, A as functionCheckHaveModifier, j as functionCheckHaveNameMatchingFileName, M as functionCheckMatchNamePattern, Y as getClasses, X as getFunctions, Z as getProperties, I as layer, R as layerShouldNotBeAccessedByAnyLayer, z as layerShouldOnlyBeAccessedBy, g as locateClasses, E as locateFiles, N as locateFunctions, B as locateProperties, V as locateSlices, H as parseProject, U as propertyCheckBeReadonly, W as sliceCheckBeFreeOfCycles, G as sliceCheckHaveMaxDistanceFromMainSequence };
|
|
606
|
+
|
|
607
|
+
//# sourceMappingURL=index.mjs.map
|