@archest/vitest 1.0.1 → 1.0.3

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 (191) hide show
  1. package/dist/index.d.ts +16 -0
  2. package/dist/index.js +1 -13
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +44 -764
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/matchers/index.d.ts +16 -0
  7. package/dist/matchers/models.d.ts +201 -0
  8. package/node_modules/@archest/core/dist/classes/locateClasses.d.ts +5 -0
  9. package/node_modules/@archest/core/dist/classes/types.d.ts +25 -0
  10. package/node_modules/@archest/core/dist/dto.d.ts +78 -0
  11. package/node_modules/@archest/core/dist/files/checkDependOnExternalModule.d.ts +3 -0
  12. package/node_modules/@archest/core/dist/files/getFileDependencies.d.ts +2 -0
  13. package/node_modules/@archest/core/dist/files/locateFiles.d.ts +4 -0
  14. package/node_modules/@archest/core/dist/files/types.d.ts +17 -0
  15. package/node_modules/@archest/core/dist/functions/locateFunctions.d.ts +5 -0
  16. package/node_modules/@archest/core/dist/functions/types.d.ts +19 -0
  17. package/node_modules/@archest/core/dist/index.d.ts +43 -0
  18. package/node_modules/@archest/core/dist/index.js +14 -0
  19. package/node_modules/@archest/core/dist/index.js.map +1 -0
  20. package/node_modules/@archest/core/dist/index.mjs +615 -0
  21. package/node_modules/@archest/core/dist/index.mjs.map +1 -0
  22. package/node_modules/@archest/core/dist/layers/createLayeredArchitecture.d.ts +3 -0
  23. package/node_modules/@archest/core/dist/layers/getLayerDependencies.d.ts +2 -0
  24. package/node_modules/@archest/core/dist/layers/types.d.ts +8 -0
  25. package/node_modules/@archest/core/dist/project/parseProject.d.ts +55 -0
  26. package/node_modules/@archest/core/dist/properties/locateProperties.d.ts +5 -0
  27. package/node_modules/@archest/core/dist/properties/types.d.ts +17 -0
  28. package/node_modules/@archest/core/dist/shared/sharedCheckHaveMaxCyclomaticComplexity.d.ts +1 -0
  29. package/node_modules/@archest/core/dist/shared/sharedCheckHaveMinMaintainabilityIndex.d.ts +1 -0
  30. package/node_modules/@archest/core/dist/shared/sharedCheckHaveModifier.d.ts +7 -0
  31. package/node_modules/@archest/core/dist/shared/sharedCheckHaveNameMatchingFileName.d.ts +3 -0
  32. package/node_modules/@archest/core/dist/shared/sharedCheckMatchNamePattern.d.ts +1 -0
  33. package/node_modules/@archest/core/dist/slices/locateSlices.d.ts +3 -0
  34. package/node_modules/@archest/core/dist/slices/types.d.ts +8 -0
  35. package/node_modules/@archest/core/package.json +49 -0
  36. package/node_modules/@archest/core-rust/core-rust.darwin-arm64.node +0 -0
  37. package/node_modules/@archest/core-rust/core-rust.linux-x64-gnu.node +0 -0
  38. package/node_modules/@archest/core-rust/core-rust.win32-x64-msvc.node +0 -0
  39. package/node_modules/@archest/core-rust/index.d.ts +16 -0
  40. package/node_modules/@archest/core-rust/index.js +316 -0
  41. package/node_modules/@archest/core-rust/package.json +34 -0
  42. package/package.json +12 -1
  43. package/dist/src/core/classes/locateClasses.d.ts +0 -3
  44. package/dist/src/core/classes/types.d.ts +0 -14
  45. package/dist/src/core/files/getFileDependencies.d.ts +0 -2
  46. package/dist/src/core/files/locateFiles.d.ts +0 -3
  47. package/dist/src/core/files/types.d.ts +0 -10
  48. package/dist/src/core/functions/locateFunctions.d.ts +0 -3
  49. package/dist/src/core/functions/types.d.ts +0 -11
  50. package/dist/src/core/layers/createLayeredArchitecture.d.ts +0 -3
  51. package/dist/src/core/layers/getLayerDependencies.d.ts +0 -2
  52. package/dist/src/core/layers/types.d.ts +0 -8
  53. package/dist/src/core/project/parseProject.d.ts +0 -22
  54. package/dist/src/core/properties/locateProperties.d.ts +0 -3
  55. package/dist/src/core/properties/types.d.ts +0 -10
  56. package/dist/src/core/shared/sharedCheckHaveMaxCyclomaticComplexity.d.ts +0 -1
  57. package/dist/src/core/shared/sharedCheckHaveMinMaintainabilityIndex.d.ts +0 -1
  58. package/dist/src/core/shared/sharedCheckHaveModifier.d.ts +0 -2
  59. package/dist/src/core/shared/sharedCheckHaveNameMatchingFileName.d.ts +0 -2
  60. package/dist/src/core/shared/sharedCheckMatchNamePattern.d.ts +0 -1
  61. package/dist/src/core/slices/locateSlices.d.ts +0 -3
  62. package/dist/src/core/slices/types.d.ts +0 -8
  63. package/dist/src/index.d.ts +0 -35
  64. package/dist/src/matchers/index.d.ts +0 -20
  65. package/src/core/classes/classCheckExtendClass.test.ts +0 -30
  66. package/src/core/classes/classCheckExtendClass.ts +0 -41
  67. package/src/core/classes/classCheckHaveMaxCyclomaticComplexity.test.ts +0 -8
  68. package/src/core/classes/classCheckHaveMaxCyclomaticComplexity.ts +0 -35
  69. package/src/core/classes/classCheckHaveModifier.test.ts +0 -30
  70. package/src/core/classes/classCheckHaveModifier.ts +0 -17
  71. package/src/core/classes/classCheckHaveNameMatchingFileName.test.ts +0 -30
  72. package/src/core/classes/classCheckHaveNameMatchingFileName.ts +0 -15
  73. package/src/core/classes/classCheckImplementInterface.test.ts +0 -30
  74. package/src/core/classes/classCheckImplementInterface.ts +0 -43
  75. package/src/core/classes/classCheckMatchNamePattern.test.ts +0 -8
  76. package/src/core/classes/classCheckMatchNamePattern.ts +0 -17
  77. package/src/core/classes/classCheckResideInFolder.test.ts +0 -8
  78. package/src/core/classes/classCheckResideInFolder.ts +0 -31
  79. package/src/core/classes/locateClasses.test.ts +0 -13
  80. package/src/core/classes/locateClasses.ts +0 -127
  81. package/src/core/classes/types.ts +0 -16
  82. package/src/core/files/checkDependOnFilesInFolder.test.ts +0 -7
  83. package/src/core/files/checkDependOnFilesInFolder.ts +0 -36
  84. package/src/core/files/fileCheckBeFreeOfCycles.test.ts +0 -7
  85. package/src/core/files/fileCheckBeFreeOfCycles.ts +0 -72
  86. package/src/core/files/fileCheckHaveMaxCyclomaticComplexity.test.ts +0 -8
  87. package/src/core/files/fileCheckHaveMaxCyclomaticComplexity.ts +0 -35
  88. package/src/core/files/fileCheckHaveMaxExportedFunctions.test.ts +0 -32
  89. package/src/core/files/fileCheckHaveMaxExportedFunctions.ts +0 -45
  90. package/src/core/files/fileCheckHaveMinMaintainabilityIndex.test.ts +0 -8
  91. package/src/core/files/fileCheckHaveMinMaintainabilityIndex.ts +0 -19
  92. package/src/core/files/fileCheckMatchNamePattern.test.ts +0 -30
  93. package/src/core/files/fileCheckMatchNamePattern.ts +0 -17
  94. package/src/core/files/getFileDependencies.ts +0 -43
  95. package/src/core/files/locateFiles.test.ts +0 -30
  96. package/src/core/files/locateFiles.ts +0 -31
  97. package/src/core/files/types.ts +0 -12
  98. package/src/core/functions/functionCheckHaveExplicitReturnType.test.ts +0 -30
  99. package/src/core/functions/functionCheckHaveExplicitReturnType.ts +0 -29
  100. package/src/core/functions/functionCheckHaveMaxCyclomaticComplexity.test.ts +0 -8
  101. package/src/core/functions/functionCheckHaveMaxCyclomaticComplexity.ts +0 -20
  102. package/src/core/functions/functionCheckHaveMinMaintainabilityIndex.test.ts +0 -8
  103. package/src/core/functions/functionCheckHaveMinMaintainabilityIndex.ts +0 -20
  104. package/src/core/functions/functionCheckHaveModifier.test.ts +0 -30
  105. package/src/core/functions/functionCheckHaveModifier.ts +0 -18
  106. package/src/core/functions/functionCheckHaveNameMatchingFileName.test.ts +0 -30
  107. package/src/core/functions/functionCheckHaveNameMatchingFileName.ts +0 -16
  108. package/src/core/functions/functionCheckMatchNamePattern.test.ts +0 -30
  109. package/src/core/functions/functionCheckMatchNamePattern.ts +0 -18
  110. package/src/core/functions/locateFunctions.test.ts +0 -16
  111. package/src/core/functions/locateFunctions.ts +0 -47
  112. package/src/core/functions/types.ts +0 -13
  113. package/src/core/layers/checkLayeredArchitecture.test.ts +0 -23
  114. package/src/core/layers/checkLayeredArchitecture.ts +0 -15
  115. package/src/core/layers/createLayeredArchitecture.test.ts +0 -13
  116. package/src/core/layers/createLayeredArchitecture.ts +0 -15
  117. package/src/core/layers/getLayerDependencies.ts +0 -45
  118. package/src/core/layers/layer.test.ts +0 -12
  119. package/src/core/layers/layer.ts +0 -10
  120. package/src/core/layers/layerShouldNotBeAccessedByAnyLayer.test.ts +0 -14
  121. package/src/core/layers/layerShouldNotBeAccessedByAnyLayer.ts +0 -40
  122. package/src/core/layers/layerShouldOnlyBeAccessedBy.test.ts +0 -15
  123. package/src/core/layers/layerShouldOnlyBeAccessedBy.ts +0 -48
  124. package/src/core/layers/types.ts +0 -9
  125. package/src/core/metrics/calculateCyclomaticComplexity.test.ts +0 -23
  126. package/src/core/metrics/calculateCyclomaticComplexity.ts +0 -36
  127. package/src/core/metrics/calculateMaintainabilityIndex.test.ts +0 -38
  128. package/src/core/metrics/calculateMaintainabilityIndex.ts +0 -47
  129. package/src/core/project/parseProject.test.ts +0 -19
  130. package/src/core/project/parseProject.ts +0 -216
  131. package/src/core/properties/locateProperties.test.ts +0 -19
  132. package/src/core/properties/locateProperties.ts +0 -41
  133. package/src/core/properties/propertyCheckBeReadonly.test.ts +0 -32
  134. package/src/core/properties/propertyCheckBeReadonly.ts +0 -27
  135. package/src/core/properties/types.ts +0 -12
  136. package/src/core/shared/sharedCheckHaveMaxCyclomaticComplexity.test.ts +0 -30
  137. package/src/core/shared/sharedCheckHaveMaxCyclomaticComplexity.ts +0 -23
  138. package/src/core/shared/sharedCheckHaveMinMaintainabilityIndex.test.ts +0 -30
  139. package/src/core/shared/sharedCheckHaveMinMaintainabilityIndex.ts +0 -23
  140. package/src/core/shared/sharedCheckHaveModifier.test.ts +0 -31
  141. package/src/core/shared/sharedCheckHaveModifier.ts +0 -51
  142. package/src/core/shared/sharedCheckHaveNameMatchingFileName.test.ts +0 -17
  143. package/src/core/shared/sharedCheckHaveNameMatchingFileName.ts +0 -36
  144. package/src/core/shared/sharedCheckMatchNamePattern.test.ts +0 -29
  145. package/src/core/shared/sharedCheckMatchNamePattern.ts +0 -22
  146. package/src/core/slices/locateSlices.test.ts +0 -22
  147. package/src/core/slices/locateSlices.ts +0 -35
  148. package/src/core/slices/sliceCheckBeFreeOfCycles.test.ts +0 -26
  149. package/src/core/slices/sliceCheckBeFreeOfCycles.ts +0 -91
  150. package/src/core/slices/sliceCheckHaveMaxDistanceFromMainSequence.test.ts +0 -27
  151. package/src/core/slices/sliceCheckHaveMaxDistanceFromMainSequence.ts +0 -110
  152. package/src/core/slices/types.ts +0 -9
  153. package/src/core/testUtils.ts +0 -61
  154. package/src/core/types.ts +0 -19
  155. package/src/core/utils/ruleBuilder.test.ts +0 -24
  156. package/src/core/utils/ruleBuilder.ts +0 -28
  157. package/src/index.ts +0 -35
  158. package/src/matchers/index.ts +0 -331
  159. package/test/architecture.test.ts +0 -152
  160. package/tsconfig.json +0 -18
  161. package/vite.config.ts +0 -18
  162. /package/{dist/src/core → node_modules/@archest/core/dist}/classes/classCheckExtendClass.d.ts +0 -0
  163. /package/{dist/src/core → node_modules/@archest/core/dist}/classes/classCheckHaveMaxCyclomaticComplexity.d.ts +0 -0
  164. /package/{dist/src/core → node_modules/@archest/core/dist}/classes/classCheckHaveModifier.d.ts +0 -0
  165. /package/{dist/src/core → node_modules/@archest/core/dist}/classes/classCheckHaveNameMatchingFileName.d.ts +0 -0
  166. /package/{dist/src/core → node_modules/@archest/core/dist}/classes/classCheckImplementInterface.d.ts +0 -0
  167. /package/{dist/src/core → node_modules/@archest/core/dist}/classes/classCheckMatchNamePattern.d.ts +0 -0
  168. /package/{dist/src/core → node_modules/@archest/core/dist}/classes/classCheckResideInFolder.d.ts +0 -0
  169. /package/{dist/src/core → node_modules/@archest/core/dist}/files/checkDependOnFilesInFolder.d.ts +0 -0
  170. /package/{dist/src/core → node_modules/@archest/core/dist}/files/fileCheckBeFreeOfCycles.d.ts +0 -0
  171. /package/{dist/src/core → node_modules/@archest/core/dist}/files/fileCheckHaveMaxCyclomaticComplexity.d.ts +0 -0
  172. /package/{dist/src/core → node_modules/@archest/core/dist}/files/fileCheckHaveMaxExportedFunctions.d.ts +0 -0
  173. /package/{dist/src/core → node_modules/@archest/core/dist}/files/fileCheckHaveMinMaintainabilityIndex.d.ts +0 -0
  174. /package/{dist/src/core → node_modules/@archest/core/dist}/files/fileCheckMatchNamePattern.d.ts +0 -0
  175. /package/{dist/src/core → node_modules/@archest/core/dist}/functions/functionCheckHaveExplicitReturnType.d.ts +0 -0
  176. /package/{dist/src/core → node_modules/@archest/core/dist}/functions/functionCheckHaveMaxCyclomaticComplexity.d.ts +0 -0
  177. /package/{dist/src/core → node_modules/@archest/core/dist}/functions/functionCheckHaveMinMaintainabilityIndex.d.ts +0 -0
  178. /package/{dist/src/core → node_modules/@archest/core/dist}/functions/functionCheckHaveModifier.d.ts +0 -0
  179. /package/{dist/src/core → node_modules/@archest/core/dist}/functions/functionCheckHaveNameMatchingFileName.d.ts +0 -0
  180. /package/{dist/src/core → node_modules/@archest/core/dist}/functions/functionCheckMatchNamePattern.d.ts +0 -0
  181. /package/{dist/src/core → node_modules/@archest/core/dist}/layers/checkLayeredArchitecture.d.ts +0 -0
  182. /package/{dist/src/core → node_modules/@archest/core/dist}/layers/layer.d.ts +0 -0
  183. /package/{dist/src/core → node_modules/@archest/core/dist}/layers/layerShouldNotBeAccessedByAnyLayer.d.ts +0 -0
  184. /package/{dist/src/core → node_modules/@archest/core/dist}/layers/layerShouldOnlyBeAccessedBy.d.ts +0 -0
  185. /package/{dist/src/core → node_modules/@archest/core/dist}/metrics/calculateCyclomaticComplexity.d.ts +0 -0
  186. /package/{dist/src/core → node_modules/@archest/core/dist}/metrics/calculateMaintainabilityIndex.d.ts +0 -0
  187. /package/{dist/src/core → node_modules/@archest/core/dist}/properties/propertyCheckBeReadonly.d.ts +0 -0
  188. /package/{dist/src/core → node_modules/@archest/core/dist}/slices/sliceCheckBeFreeOfCycles.d.ts +0 -0
  189. /package/{dist/src/core → node_modules/@archest/core/dist}/slices/sliceCheckHaveMaxDistanceFromMainSequence.d.ts +0 -0
  190. /package/{dist/src/core → node_modules/@archest/core/dist}/types.d.ts +0 -0
  191. /package/{dist/src/core → node_modules/@archest/core/dist}/utils/ruleBuilder.d.ts +0 -0
package/dist/index.mjs CHANGED
@@ -1,749 +1,20 @@
1
- import * as e from "typescript";
2
- import * as t from "node:path";
3
- import { dirname as n } from "node:path";
4
- import { expect as r } from "vitest";
5
- //#region \0rolldown/runtime.js
6
- var i = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
7
- if (typeof require < "u") return require.apply(this, arguments);
8
- throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
9
- });
10
- //#endregion
11
- //#region src/core/classes/classCheckExtendClass.ts
12
- function a(t, n, r) {
13
- let i = [];
14
- for (let a of t.classes) {
15
- let t = a.name?.text || "Anonymous", o = !1;
16
- if (a.heritageClauses) {
17
- for (let t of a.heritageClauses) if (t.token === e.SyntaxKind.ExtendsKeyword) {
18
- for (let r of t.types) if (e.isIdentifier(r.expression) && r.expression.text === n) {
19
- o = !0;
20
- break;
21
- }
22
- }
23
- }
24
- r && o ? i.push(`Class ${t} extends ${n}, but it shouldn't.`) : !r && !o && i.push(`Class ${t} does not extend ${n}, but it should.`);
25
- }
26
- return {
27
- pass: i.length === 0,
28
- message: () => i.join("\n")
29
- };
30
- }
31
- //#endregion
32
- //#region src/core/metrics/calculateCyclomaticComplexity.ts
33
- function o(t) {
34
- let n = 1, r = (t) => {
35
- switch (t.kind) {
36
- case e.SyntaxKind.IfStatement:
37
- case e.SyntaxKind.ForStatement:
38
- case e.SyntaxKind.ForInStatement:
39
- case e.SyntaxKind.ForOfStatement:
40
- case e.SyntaxKind.WhileStatement:
41
- case e.SyntaxKind.DoStatement:
42
- case e.SyntaxKind.CaseClause:
43
- case e.SyntaxKind.CatchClause:
44
- case e.SyntaxKind.ConditionalExpression:
45
- n++;
46
- break;
47
- case e.SyntaxKind.BinaryExpression: {
48
- let r = t;
49
- (r.operatorToken.kind === e.SyntaxKind.AmpersandAmpersandToken || r.operatorToken.kind === e.SyntaxKind.BarBarToken || r.operatorToken.kind === e.SyntaxKind.QuestionQuestionToken) && n++;
50
- break;
51
- }
52
- }
53
- e.forEachChild(t, r);
54
- };
55
- return e.forEachChild(t, r), n;
56
- }
57
- //#endregion
58
- //#region src/core/utils/ruleBuilder.ts
59
- function s(e, t, n) {
60
- let r = [];
61
- for (let i of e) {
62
- let { passes: e, failMessage: a, failNotMessage: o } = n(i);
63
- t && e ? o && r.push(o) : !t && !e && a && r.push(a);
64
- }
65
- return {
66
- pass: r.length === 0,
67
- message: () => r.join("\n")
68
- };
69
- }
70
- //#endregion
71
- //#region src/core/shared/sharedCheckHaveMaxCyclomaticComplexity.ts
72
- function c(e, t, n, r, i, a) {
73
- return s(e, a, (e) => {
74
- let a = t(e), o = n(e), s = o > i, c = `${r} ${a || "Anonymous"}`;
75
- return {
76
- passes: !s,
77
- failMessage: `${c} has a total cyclomatic complexity of ${o}, which exceeds the maximum of ${i}.`,
78
- failNotMessage: `${c} has a total cyclomatic complexity of ${o}, which exceeds the maximum of ${i}, but it shouldn't.`
79
- };
80
- });
81
- }
82
- //#endregion
83
- //#region src/core/classes/classCheckHaveMaxCyclomaticComplexity.ts
84
- function l(t, n, r) {
85
- return c(t.classes, (e) => e.name?.text, (t) => {
86
- let n = 0, r = (t) => {
87
- (e.isMethodDeclaration(t) || e.isConstructorDeclaration(t) || e.isGetAccessor(t) || e.isSetAccessor(t)) && (n += o(t)), e.forEachChild(t, r);
88
- };
89
- return r(t), n;
90
- }, "Class", n, r);
91
- }
92
- //#endregion
93
- //#region src/core/shared/sharedCheckHaveModifier.ts
94
- function u(t, n, r, i, a) {
95
- let o;
96
- switch (i) {
97
- case "export":
98
- o = e.SyntaxKind.ExportKeyword;
99
- break;
100
- case "default":
101
- o = e.SyntaxKind.DefaultKeyword;
102
- break;
103
- case "abstract":
104
- o = e.SyntaxKind.AbstractKeyword;
105
- break;
106
- case "async":
107
- o = e.SyntaxKind.AsyncKeyword;
108
- break;
109
- case "public":
110
- o = e.SyntaxKind.PublicKeyword;
111
- break;
112
- case "private":
113
- o = e.SyntaxKind.PrivateKeyword;
114
- break;
115
- default: throw Error(`Modifier ${i} is not fully supported.`);
116
- }
117
- return s(t, a, (t) => {
118
- let a = n(t), s = e.canHaveModifiers(t) ? e.getModifiers(t) : void 0, c = s ? s.some((e) => e.kind === o) : !1, l = `${r} ${a || "Anonymous"}`;
119
- return {
120
- passes: c,
121
- failMessage: `${l} does not have modifier ${i}, but it should.`,
122
- failNotMessage: `${l} has modifier ${i}, but it shouldn't.`
123
- };
124
- });
125
- }
126
- //#endregion
127
- //#region src/core/classes/classCheckHaveModifier.ts
128
- function d(e, t, n) {
129
- return u(e.classes, (e) => e.name?.text, "Class", t, n);
130
- }
131
- //#endregion
132
- //#region src/core/shared/sharedCheckHaveNameMatchingFileName.ts
133
- function f(n, r, i, a) {
134
- return s(n, a, (n) => {
135
- let a = r(n), o = n.getSourceFile ? n.getSourceFile() : n.parent ? e.getSourceFileOfNode(n) : void 0;
136
- if (!o) return {
137
- passes: !0,
138
- failMessage: "",
139
- failNotMessage: ""
140
- };
141
- let s = t.basename(o.fileName, t.extname(o.fileName)), c = a === s, l = `${i} ${a || "Anonymous"}`;
142
- return {
143
- passes: c,
144
- failMessage: `${l} does not have a name matching its filename ${s}, but it should.`,
145
- failNotMessage: `${l} has a name matching its filename ${s}, but it shouldn't.`
146
- };
147
- });
148
- }
149
- //#endregion
150
- //#region src/core/classes/classCheckHaveNameMatchingFileName.ts
151
- function p(e, t) {
152
- return f(e.classes, (e) => e.name?.text, "Class", t);
153
- }
154
- //#endregion
155
- //#region src/core/classes/classCheckImplementInterface.ts
156
- function m(t, n, r) {
157
- let i = [];
158
- for (let a of t.classes) {
159
- let t = a.name?.text || "Anonymous", o = !1;
160
- if (a.heritageClauses) {
161
- for (let t of a.heritageClauses) if (t.token === e.SyntaxKind.ImplementsKeyword) {
162
- for (let r of t.types) if (e.isIdentifier(r.expression) && r.expression.text === n) {
163
- o = !0;
164
- break;
165
- }
166
- }
167
- }
168
- r && o ? i.push(`Class ${t} implements ${n}, but it shouldn't.`) : !r && !o && i.push(`Class ${t} does not implement ${n}, but it should.`);
169
- }
170
- return {
171
- pass: i.length === 0,
172
- message: () => i.join("\n")
173
- };
174
- }
175
- //#endregion
176
- //#region src/core/shared/sharedCheckMatchNamePattern.ts
177
- function h(e, t, n, r, i) {
178
- let a = typeof r == "string" ? new RegExp(r) : r;
179
- return s(e, i, (e) => {
180
- let i = t(e), o = i ? a.test(i) : !1, s = `${n} ${i || "Anonymous"}`;
181
- return {
182
- passes: o,
183
- failMessage: `${s} does not match pattern ${r}, but it should.`,
184
- failNotMessage: `${s} matches pattern ${r}, but it shouldn't.`
185
- };
186
- });
187
- }
188
- //#endregion
189
- //#region src/core/classes/classCheckMatchNamePattern.ts
190
- function g(e, t, n) {
191
- return h(e.classes, (e) => e.name?.text, "Class", t, n);
192
- }
193
- //#endregion
194
- //#region src/core/classes/classCheckResideInFolder.ts
195
- function _(e, t, n) {
196
- let r = [];
197
- for (let i of e.classes) {
198
- let e = i.name?.text || "Anonymous Class", a = i.getSourceFile(), o = a.fileName.includes(`/${t}/`) || a.fileName.includes(`\\${t}\\`);
199
- 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.`);
200
- }
201
- return {
202
- pass: r.length === 0,
203
- message: () => r.join("\n")
204
- };
205
- }
206
- //#endregion
207
- //#region src/core/classes/locateClasses.ts
208
- function v(t, n, r) {
209
- let i = t;
210
- if (r?.inFolder && (i = i.filter((t) => {
211
- let n = t.getSourceFile ? t.getSourceFile() : t.parent ? e.getSourceFileOfNode(t) : void 0;
212
- return n ? n.fileName.includes(`/${r.inFolder}/`) || n.fileName.includes(`\\${r.inFolder}\\`) : !1;
213
- })), r?.matchNamePattern) {
214
- let e = typeof r.matchNamePattern == "string" ? new RegExp(r.matchNamePattern) : r.matchNamePattern;
215
- i = i.filter((t) => {
216
- let n = t.name?.text;
217
- return n && e.test(n);
218
- });
219
- }
220
- if (r?.withDecorator && (i = i.filter((t) => {
221
- let n = e.canHaveDecorators(t) ? e.getDecorators(t) : void 0, i = !1;
222
- if (n) for (let t of n) {
223
- let n = t.expression, a = "";
224
- e.isIdentifier(n) ? a = n.text : e.isCallExpression(n) && e.isIdentifier(n.expression) && (a = n.expression.text), a === r.withDecorator && (i = !0);
225
- }
226
- return i;
227
- })), r?.extending && (i = i.filter((t) => {
228
- if (t.heritageClauses) {
229
- for (let n of t.heritageClauses) if (n.token === e.SyntaxKind.ExtendsKeyword) {
230
- for (let t of n.types) if (e.isIdentifier(t.expression) && t.expression.text === r.extending) return !0;
231
- }
232
- }
233
- return !1;
234
- })), r?.implementing && (i = i.filter((t) => {
235
- if (t.heritageClauses) {
236
- for (let n of t.heritageClauses) if (n.token === e.SyntaxKind.ImplementsKeyword) {
237
- for (let t of n.types) if (e.isIdentifier(t.expression) && t.expression.text === r.implementing) return !0;
238
- }
239
- }
240
- return !1;
241
- })), r?.havingModifier) {
242
- let t;
243
- switch (r.havingModifier) {
244
- case "export":
245
- t = e.SyntaxKind.ExportKeyword;
246
- break;
247
- case "default":
248
- t = e.SyntaxKind.DefaultKeyword;
249
- break;
250
- case "abstract":
251
- t = e.SyntaxKind.AbstractKeyword;
252
- break;
253
- default: throw Error(`Modifier ${r.havingModifier} is not fully supported.`);
254
- }
255
- i = i.filter((n) => (e.canHaveModifiers(n) ? e.getModifiers(n) : void 0)?.some((e) => e.kind === t));
256
- }
257
- return {
258
- type: "ClassLocator",
259
- classes: i,
260
- program: n
261
- };
262
- }
263
- //#endregion
264
- //#region src/core/files/getFileDependencies.ts
265
- function y(t, n) {
266
- let r = [], i = n.getCompilerOptions(), a = (n) => {
267
- if (e.isImportDeclaration(n)) {
268
- let a = n.moduleSpecifier.text, o = e.resolveModuleName(a, t.fileName, i, e.sys);
269
- o.resolvedModule?.resolvedFileName && (o.resolvedModule.isExternalLibraryImport || r.push(o.resolvedModule.resolvedFileName));
270
- } else if (e.isExportDeclaration(n) && n.moduleSpecifier) {
271
- let a = n.moduleSpecifier.text, o = e.resolveModuleName(a, t.fileName, i, e.sys);
272
- o.resolvedModule?.resolvedFileName && (o.resolvedModule.isExternalLibraryImport || r.push(o.resolvedModule.resolvedFileName));
273
- }
274
- e.forEachChild(n, a);
275
- };
276
- return a(t), r;
277
- }
278
- //#endregion
279
- //#region src/core/files/checkDependOnFilesInFolder.ts
280
- function b(e, t, n) {
281
- let r = [];
282
- for (let i of e.files) {
283
- let a = y(i, e.program).some((e) => e.includes(`/${t}/`) || e.includes(`\\${t}\\`));
284
- n && a ? r.push(`File ${i.fileName} depends on files in ${t}, but it shouldn't.`) : !n && !a && r.push(`File ${i.fileName} does not depend on files in ${t}, but it should.`);
285
- }
286
- return {
287
- pass: r.length === 0,
288
- message: () => r.join("\n")
289
- };
290
- }
291
- //#endregion
292
- //#region src/core/files/fileCheckBeFreeOfCycles.ts
293
- function x(e, t) {
294
- let n = [], r = new Set(e.files.map((e) => e.fileName)), i = /* @__PURE__ */ new Map();
295
- for (let t of e.files) {
296
- let n = t.fileName, a = y(t, e.program).filter((e) => r.has(e));
297
- i.set(n, a);
298
- }
299
- let a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), s = [], c = (e, t) => {
300
- if (o.has(e)) {
301
- let n = t.indexOf(e), r = [...t.slice(n), e].join("->");
302
- return s.some((e) => e.join("->") === r) || s.push([...t.slice(n), e]), !0;
303
- }
304
- if (a.has(e)) return !1;
305
- a.add(e), o.add(e), t.push(e);
306
- let n = i.get(e) || [];
307
- for (let e of n) c(e, t);
308
- return o.delete(e), t.pop(), !1;
309
- };
310
- for (let e of i.keys()) a.has(e) || c(e, []);
311
- if (t && s.length === 0) n.push("Expected cyclic dependencies, but found none.");
312
- else if (!t && s.length > 0) for (let e of s) n.push(`Cycle detected: ${e.join(" -> ")}`);
313
- return {
314
- pass: n.length === 0,
315
- message: () => n.join("\n")
316
- };
317
- }
318
- //#endregion
319
- //#region src/core/files/fileCheckHaveMaxCyclomaticComplexity.ts
320
- function S(t, n, r) {
321
- return c(t.files, (e) => e.fileName, (t) => {
322
- let n = 0, r = (t) => {
323
- (e.isFunctionDeclaration(t) || e.isMethodDeclaration(t) || e.isArrowFunction(t) || e.isFunctionExpression(t)) && (n += o(t)), e.forEachChild(t, r);
324
- };
325
- return r(t), n;
326
- }, "File", n, r);
327
- }
328
- //#endregion
329
- //#region src/core/files/fileCheckHaveMaxExportedFunctions.ts
330
- function C(t, n, r) {
331
- let i = [];
332
- for (let a of t.files) {
333
- let t = 0;
334
- e.forEachChild(a, (n) => {
335
- e.isFunctionDeclaration(n) && (e.canHaveModifiers(n) ? e.getModifiers(n) : void 0)?.some((t) => t.kind === e.SyntaxKind.ExportKeyword) && t++;
336
- });
337
- let o = t > n;
338
- r && o ? i.push(`File ${a.fileName} has ${t} exported functions, which exceeds the maximum of ${n}, but it shouldn't.`) : !r && o && i.push(`File ${a.fileName} has ${t} exported functions, which exceeds the maximum of ${n}.`);
339
- }
340
- return {
341
- pass: r ? i.length > 0 : i.length === 0,
342
- message: () => i.join("\n") || (r ? "Expected some files to exceed maximum exported functions, but none did." : "")
343
- };
344
- }
345
- //#endregion
346
- //#region src/core/metrics/calculateMaintainabilityIndex.ts
347
- function w(t) {
348
- let n = 0, r = 0, i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), s = 1, c = t.getSourceFile();
349
- if (c) {
350
- let e = c.getLineAndCharacterOfPosition(t.getStart());
351
- s = c.getLineAndCharacterOfPosition(t.getEnd()).line - e.line + 1;
352
- }
353
- let l = (t) => {
354
- e.isBinaryExpression(t) || e.isPrefixUnaryExpression(t) || e.isPostfixUnaryExpression(t) ? (n++, i.add(t.kind)) : (e.isIdentifier(t) || e.isLiteralExpression(t)) && (r++, a.add(t.getText(c))), e.forEachChild(t, l);
355
- };
356
- l(t);
357
- let u = n + r, d = i.size + a.size, f = d === 0 ? 0 : u * Math.log2(d), p = o(t);
358
- return Math.max(0, (171 - 5.2 * Math.log(f || 1) - .23 * p - 16.2 * Math.log(s)) * 100 / 171);
359
- }
360
- //#endregion
361
- //#region src/core/shared/sharedCheckHaveMinMaintainabilityIndex.ts
362
- function T(e, t, n, r, i, a) {
363
- return s(e, a, (e) => {
364
- let a = t(e), o = n(e), s = o < i, c = `${r} ${a || "Anonymous"}`;
365
- return {
366
- passes: !s,
367
- failMessage: `${c} has a maintainability index of ${o.toFixed(2)}, which falls below the minimum of ${i}.`,
368
- failNotMessage: `${c} has a maintainability index of ${o.toFixed(2)}, which falls below the minimum of ${i}, but it shouldn't.`
369
- };
370
- });
371
- }
372
- //#endregion
373
- //#region src/core/files/fileCheckHaveMinMaintainabilityIndex.ts
374
- function E(e, t, n) {
375
- return T(e.files, (e) => e.fileName, w, "File", t, n);
376
- }
377
- //#endregion
378
- //#region src/core/files/fileCheckMatchNamePattern.ts
379
- function D(e, t, n) {
380
- return h(e.files, (e) => e.fileName, "File", t, n);
381
- }
382
- //#endregion
383
- //#region src/core/files/locateFiles.ts
384
- function O(e, t, n) {
385
- let r = e;
386
- if (n?.inFolder && (r = r.filter((e) => e.fileName.includes(`/${n.inFolder}/`) || e.fileName.includes(`\\${n.inFolder}\\`))), n?.matchNamePattern) {
387
- let e = typeof n.matchNamePattern == "string" ? new RegExp(n.matchNamePattern) : n.matchNamePattern;
388
- r = r.filter((t) => e.test(t.fileName));
389
- }
390
- return {
391
- type: "FileLocator",
392
- files: r,
393
- program: t
394
- };
395
- }
396
- //#endregion
397
- //#region src/core/functions/functionCheckHaveExplicitReturnType.ts
398
- function k(t, n) {
399
- let r = [];
400
- for (let i of t.functions) {
401
- let t = i.name && e.isIdentifier(i.name) ? i.name.text : "Anonymous Function", a = !!i.type;
402
- n && a ? r.push(`Function ${t} has an explicit return type, but it shouldn't.`) : !n && !a && r.push(`Function ${t} does not have an explicit return type, but it should.`);
403
- }
404
- return {
405
- pass: r.length === 0,
406
- message: () => r.join("\n")
407
- };
408
- }
409
- //#endregion
410
- //#region src/core/functions/functionCheckHaveMaxCyclomaticComplexity.ts
411
- function A(t, n, r) {
412
- return c(t.functions, (t) => t.name && e.isIdentifier(t.name) ? t.name.text : void 0, o, "Function", n, r);
413
- }
414
- //#endregion
415
- //#region src/core/functions/functionCheckHaveMinMaintainabilityIndex.ts
416
- function j(t, n, r) {
417
- return T(t.functions, (t) => t.name && e.isIdentifier(t.name) ? t.name.text : void 0, w, "Function", n, r);
418
- }
419
- //#endregion
420
- //#region src/core/functions/functionCheckHaveModifier.ts
421
- function M(t, n, r) {
422
- return u(t.functions, (t) => t.name && e.isIdentifier(t.name) ? t.name.text : void 0, "Function", n, r);
423
- }
424
- //#endregion
425
- //#region src/core/functions/functionCheckHaveNameMatchingFileName.ts
426
- function N(t, n) {
427
- return f(t.functions, (t) => t.name && e.isIdentifier(t.name) ? t.name.text : void 0, "Function", n);
428
- }
429
- //#endregion
430
- //#region src/core/functions/functionCheckMatchNamePattern.ts
431
- function P(t, n, r) {
432
- return h(t.functions, (t) => t.name && e.isIdentifier(t.name) ? t.name.text : void 0, "Function", n, r);
433
- }
434
- //#endregion
435
- //#region src/core/functions/locateFunctions.ts
436
- function F(t, n, r) {
437
- let i = t;
438
- if (r?.inFolder && (i = i.filter((t) => {
439
- let n = t.getSourceFile ? t.getSourceFile() : t.parent ? e.getSourceFileOfNode(t) : void 0;
440
- return n ? n.fileName.includes(`/${r.inFolder}/`) || n.fileName.includes(`\\${r.inFolder}\\`) : !1;
441
- })), r?.matchNamePattern) {
442
- let t = typeof r.matchNamePattern == "string" ? new RegExp(r.matchNamePattern) : r.matchNamePattern;
443
- i = i.filter((n) => n.name && e.isIdentifier(n.name) && t.test(n.name.text));
444
- }
445
- return r?.isTopLevel && (i = i.filter((t) => e.isSourceFile(t.parent))), {
446
- type: "FunctionLocator",
447
- functions: i,
448
- program: n
449
- };
450
- }
451
- //#endregion
452
- //#region src/core/layers/checkLayeredArchitecture.ts
453
- function I(e) {
454
- let t = [];
455
- for (let n of e.assertions) t.push(...n(e.files));
456
- return {
457
- pass: t.length === 0,
458
- message: () => t.join("\n")
459
- };
460
- }
461
- //#endregion
462
- //#region src/core/layers/createLayeredArchitecture.ts
463
- function L(e, t) {
464
- return {
465
- type: "LayeredArchitecture",
466
- files: e,
467
- layers: /* @__PURE__ */ new Map(),
468
- assertions: [],
469
- program: t
470
- };
471
- }
472
- //#endregion
473
- //#region src/core/layers/layer.ts
474
- function R(e, t, n) {
475
- return e.layers.set(t, n), e;
476
- }
477
- //#endregion
478
- //#region src/core/layers/getLayerDependencies.ts
479
- function z(t, n) {
480
- let r = [], i = n.getCompilerOptions(), a = (n) => {
481
- if (e.isImportDeclaration(n)) {
482
- let a = n.moduleSpecifier.text, o = e.resolveModuleName(a, t.fileName, i, e.sys);
483
- o.resolvedModule?.resolvedFileName && !o.resolvedModule.isExternalLibraryImport && r.push(o.resolvedModule.resolvedFileName);
484
- } else if (e.isExportDeclaration(n) && n.moduleSpecifier) {
485
- let a = n.moduleSpecifier.text, o = e.resolveModuleName(a, t.fileName, i, e.sys);
486
- o.resolvedModule?.resolvedFileName && !o.resolvedModule.isExternalLibraryImport && r.push(o.resolvedModule.resolvedFileName);
487
- }
488
- e.forEachChild(n, a);
489
- };
490
- return a(t), r;
491
- }
492
- //#endregion
493
- //#region src/core/layers/layerShouldNotBeAccessedByAnyLayer.ts
494
- function B(e, t) {
495
- if (!e.layers.has(t)) throw Error(`Layer ${t} is not defined`);
496
- return e.assertions.push((n) => {
497
- let r = [], i = e.layers.get(t);
498
- for (let a of n) {
499
- let n = a.fileName;
500
- !n.includes(`/${i}/`) && !n.includes(`\\${i}\\`) && z(a, e.program).some((e) => e.includes(`/${i}/`) || e.includes(`\\${i}\\`)) && r.push(`File ${n} accesses layer ${t} but it shouldn't.`);
501
- }
502
- return r;
503
- }), e;
504
- }
505
- //#endregion
506
- //#region src/core/layers/layerShouldOnlyBeAccessedBy.ts
507
- function V(e, t, n) {
508
- if (!e.layers.has(t)) throw Error(`Layer ${t} is not defined`);
509
- return e.assertions.push((r) => {
510
- let i = [], a = e.layers.get(t), o = n.map((t) => e.layers.get(t));
511
- for (let s of r) {
512
- let r = s.fileName, c = o.some((e) => r.includes(`/${e}/`) || r.includes(`\\${e}\\`));
513
- !r.includes(`/${a}/`) && !r.includes(`\\${a}\\`) && !c && z(s, e.program).some((e) => e.includes(`/${a}/`) || e.includes(`\\${a}\\`)) && i.push(`File ${r} accesses layer ${t} but only ${n.join(", ")} are allowed.`);
514
- }
515
- return i;
516
- }), e;
517
- }
518
- //#endregion
519
- //#region src/core/properties/locateProperties.ts
520
- function H(t, n, r) {
521
- let i = t;
522
- if (r?.inFolder && (i = i.filter((t) => {
523
- let n = t.getSourceFile ? t.getSourceFile() : t.parent ? e.getSourceFileOfNode(t) : void 0;
524
- return n ? n.fileName.includes(`/${r.inFolder}/`) || n.fileName.includes(`\\${r.inFolder}\\`) : !1;
525
- })), r?.matchNamePattern) {
526
- let t = typeof r.matchNamePattern == "string" ? new RegExp(r.matchNamePattern) : r.matchNamePattern;
527
- i = i.filter((n) => e.isIdentifier(n.name) && t.test(n.name.text));
528
- }
529
- return {
530
- type: "PropertyLocator",
531
- properties: i,
532
- program: n
533
- };
534
- }
535
- //#endregion
536
- //#region src/core/slices/locateSlices.ts
537
- function U(e, t, n) {
538
- let r = n.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "([^/\\\\]+)"), i = new RegExp(r), a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
539
- for (let t of e) {
540
- let e = t.fileName.match(i);
541
- if (e?.[1]) {
542
- let n = e[1];
543
- a.add(n), o.has(n) || o.set(n, []), o.get(n)?.push(t);
544
- }
545
- }
546
- return {
547
- type: "SliceLocator",
548
- slicePattern: i,
549
- sliceIds: a,
550
- sliceFiles: o,
551
- program: t
552
- };
553
- }
554
- //#endregion
555
- //#region src/core/project/parseProject.ts
556
- function W(t = {}) {
557
- let r = {}, a = t.tsConfigFilePath || e.findConfigFile(process.cwd(), e.sys.fileExists, "tsconfig.json"), o;
558
- if (a) {
559
- let t = e.readConfigFile(a, e.sys.readFile), s = e.parseJsonConfigFileContent(t.config, e.sys, n(a), void 0, a, void 0, [{
560
- extension: ".vue",
561
- isMixedContent: !0,
562
- scriptKind: e.ScriptKind.TS
563
- }, {
564
- extension: ".svelte",
565
- isMixedContent: !0,
566
- scriptKind: e.ScriptKind.TS
567
- }]);
568
- r = s.options;
569
- let c = e.createCompilerHost(r), l = c.getSourceFile, u;
570
- try {
571
- u = i("@vue/compiler-sfc");
572
- } catch {}
573
- c.getSourceFile = (t, n, r, i) => {
574
- if (t.endsWith(".vue")) {
575
- let r = e.sys.readFile(t);
576
- if (r) {
577
- let i = "";
578
- if (u) {
579
- let e = u.parse(r), t = e.descriptor.script, n = e.descriptor.scriptSetup;
580
- t && (i += `${t.content}\n`), n && (i += `${n.content}\n`);
581
- } else {
582
- let e = r.match(/<script[^>]*>(.*?)<\/script>/s);
583
- e && (i = e[1]);
584
- }
585
- return e.createSourceFile(t, i, n, !0, e.ScriptKind.TS);
586
- }
587
- }
588
- if (t.endsWith(".svelte")) {
589
- let r = e.sys.readFile(t);
590
- if (r) {
591
- let i = "", a = r.match(/<script[^>]*>(.*?)<\/script>/s);
592
- return a && (i = a[1]), e.createSourceFile(t, i, n, !0, e.ScriptKind.TS);
593
- }
594
- }
595
- return l(t, n, r, i);
596
- }, o = e.createProgram({
597
- rootNames: s.fileNames,
598
- options: r,
599
- host: c
600
- }), o.getTypeChecker();
601
- } else throw Error("Could not find tsconfig.json");
602
- let s = () => o.getSourceFiles().filter((e) => !e.isDeclarationFile && !e.fileName.includes("node_modules"));
603
- return {
604
- getFiles: (e) => O(s(), o, e),
605
- getClasses: (t) => {
606
- let n = [];
607
- for (let t of s()) {
608
- let r = (t) => {
609
- e.isClassDeclaration(t) && n.push(t), e.forEachChild(t, r);
610
- };
611
- r(t);
612
- }
613
- return v(n, o, t);
614
- },
615
- layeredArchitecture: () => {
616
- let e = L(s(), o), t = {
617
- layer: (n, r) => (e = R(e, n, r), t),
618
- whereLayer: (n) => ({
619
- shouldNotBeAccessedByAnyLayer: () => (e = B(e, n), t),
620
- shouldOnlyBeAccessedBy: (...r) => (e = V(e, n, r), t)
621
- }),
622
- check: () => I(e),
623
- get data() {
624
- return e;
625
- }
626
- };
627
- return t;
628
- },
629
- getFunctions: (t) => {
630
- let n = [];
631
- for (let t of s()) {
632
- let r = (t) => {
633
- (e.isFunctionDeclaration(t) || e.isMethodDeclaration(t) || e.isArrowFunction(t)) && n.push(t), e.forEachChild(t, r);
634
- };
635
- r(t);
636
- }
637
- return F(n, o, t);
638
- },
639
- getProperties: (t) => {
640
- let n = [];
641
- for (let t of s()) {
642
- let r = (t) => {
643
- e.isPropertyDeclaration(t) && n.push(t), e.forEachChild(t, r);
644
- };
645
- r(t);
646
- }
647
- return H(n, o, t);
648
- },
649
- getSlices: (e) => U(s(), o, e)
650
- };
651
- }
652
- //#endregion
653
- //#region src/core/properties/propertyCheckBeReadonly.ts
654
- function G(t, n) {
655
- let r = [];
656
- for (let i of t.properties) {
657
- let t = e.isIdentifier(i.name) ? i.name.text : "Anonymous Property", a = (e.canHaveModifiers(i) ? e.getModifiers(i) : void 0)?.some((t) => t.kind === e.SyntaxKind.ReadonlyKeyword);
658
- n && a ? r.push(`Property ${t} is readonly, but it shouldn't be.`) : !n && !a && r.push(`Property ${t} is not readonly, but it should be.`);
659
- }
660
- return {
661
- pass: r.length === 0,
662
- message: () => r.join("\n")
663
- };
664
- }
665
- //#endregion
666
- //#region src/core/slices/sliceCheckBeFreeOfCycles.ts
667
- function K(t, n) {
668
- let r = /* @__PURE__ */ new Map();
669
- for (let e of t.sliceIds) r.set(e, /* @__PURE__ */ new Set());
670
- for (let [n, i] of t.sliceFiles.entries()) for (let a of i) e.forEachChild(a, (i) => {
671
- if (e.isImportDeclaration(i) && i.moduleSpecifier && e.isStringLiteral(i.moduleSpecifier)) {
672
- let o = i.moduleSpecifier.text, s = e.resolveModuleName(o, a.fileName, t.program.getCompilerOptions(), e.sys);
673
- if (s.resolvedModule?.resolvedFileName) {
674
- let e = s.resolvedModule.resolvedFileName.match(t.slicePattern);
675
- if (e?.[1]) {
676
- let i = e[1];
677
- i !== n && t.sliceIds.has(i) && r.get(n)?.add(i);
678
- }
679
- }
680
- }
681
- });
682
- let i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), o = [], s = (e, t) => {
683
- i.add(e), a.add(e);
684
- for (let n of r.get(e) || []) if (!i.has(n)) {
685
- if (s(n, [...t, n])) return !0;
686
- } else if (a.has(n)) return o.push(`Cycle detected between slices: ${t.join(" -> ")} -> ${n}`), !0;
687
- return a.delete(e), !1;
688
- };
689
- for (let e of t.sliceIds) i.has(e) || s(e, [e]);
690
- return n ? {
691
- pass: o.length > 0,
692
- message: () => o.length > 0 ? "" : "Expected cycles between slices but found none."
693
- } : {
694
- pass: o.length === 0,
695
- message: () => o.join("\n")
696
- };
697
- }
698
- //#endregion
699
- //#region src/core/slices/sliceCheckHaveMaxDistanceFromMainSequence.ts
700
- function q(t, n, r) {
701
- let i = [], a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
702
- for (let e of t.sliceIds) a.set(e, /* @__PURE__ */ new Set()), o.set(e, /* @__PURE__ */ new Set());
703
- for (let [n, r] of t.sliceFiles.entries()) for (let i of r) e.forEachChild(i, (r) => {
704
- if (e.isImportDeclaration(r) && r.moduleSpecifier && e.isStringLiteral(r.moduleSpecifier)) {
705
- let s = r.moduleSpecifier.text, c = e.resolveModuleName(s, i.fileName, t.program.getCompilerOptions(), e.sys);
706
- if (c.resolvedModule?.resolvedFileName) {
707
- let e = c.resolvedModule.resolvedFileName.match(t.slicePattern);
708
- if (e?.[1]) {
709
- let r = e[1];
710
- r !== n && t.sliceIds.has(r) && (a.get(n)?.add(r), o.get(r)?.add(n));
711
- }
712
- }
713
- }
714
- });
715
- for (let s of t.sliceIds) {
716
- let c = a.get(s)?.size, l = o.get(s)?.size, u = t.sliceFiles.get(s), d = 0, f = 0;
717
- for (let t of u) {
718
- let n = (t) => {
719
- e.isClassDeclaration(t) ? (f++, (e.canHaveModifiers(t) ? e.getModifiers(t) : void 0)?.some((t) => t.kind === e.SyntaxKind.AbstractKeyword) && d++) : e.isInterfaceDeclaration(t) && (f++, d++), e.forEachChild(t, n);
720
- };
721
- n(t);
722
- }
723
- let p = c + l === 0 ? 0 : c / (l + c), m = f === 0 ? 0 : d / f, h = Math.abs(m + p - 1), g = h > n;
724
- r && g ? i.push(`Slice ${s} has a Distance from the Main Sequence of ${h.toFixed(2)}, which exceeds the maximum of ${n}, but it shouldn't.`) : !r && g && i.push(`Slice ${s} has a Distance from the Main Sequence of ${h.toFixed(2)}, which exceeds the maximum of ${n}.`);
725
- }
726
- return {
727
- pass: r ? i.length > 0 : i.length === 0,
728
- message: () => i.join("\n") || (r ? "Expected some slices to exceed maximum distance from main sequence, but none did." : "")
729
- };
730
- }
731
- //#endregion
1
+ import { checkDependOnExternalModule as e, checkDependOnFilesInFolder as t, checkLayeredArchitecture as n, classCheckExtendClass as r, classCheckHaveMaxCyclomaticComplexity as i, classCheckHaveModifier as a, classCheckHaveNameMatchingFileName as o, classCheckImplementInterface as s, classCheckMatchNamePattern as c, classCheckResideInFolder as l, fileCheckBeFreeOfCycles as u, fileCheckHaveMaxCyclomaticComplexity as d, fileCheckHaveMaxExportedFunctions as f, fileCheckHaveMinMaintainabilityIndex as p, fileCheckMatchNamePattern as m, functionCheckHaveExplicitReturnType as h, functionCheckHaveMaxCyclomaticComplexity as g, functionCheckHaveMinMaintainabilityIndex as _, functionCheckHaveModifier as v, functionCheckHaveNameMatchingFileName as y, functionCheckMatchNamePattern as b, parseProject as x, propertyCheckBeReadonly as S, sliceCheckBeFreeOfCycles as C, sliceCheckHaveMaxDistanceFromMainSequence as w } from "@archest/core";
2
+ import { expect as T } from "vitest";
732
3
  //#region src/matchers/index.ts
733
- function J() {
734
- r.extend({
4
+ function E() {
5
+ T.extend({
735
6
  toPass(e) {
736
7
  let t;
737
- t = e?.data && e.data.type === "LayeredArchitecture" ? I(e.data) : e;
738
- let { pass: n, message: r } = t;
8
+ t = e?.data && e.data.type === "LayeredArchitecture" ? n(e.data) : e;
9
+ let { pass: r, message: i } = t;
739
10
  return {
740
- pass: this.isNot ? !n : n,
741
- message: n ? () => "Expected rule not to pass" : () => r()
11
+ pass: this.isNot ? !r : r,
12
+ message: r ? () => "Expected rule not to pass" : () => i()
742
13
  };
743
14
  },
744
15
  toResideInFolder(e, t) {
745
16
  let n;
746
- if (e.type === "ClassLocator") n = _(e, t, this.isNot);
17
+ if (e.type === "ClassLocator") n = l(e, t, this.isNot);
747
18
  else throw Error(`toResideInFolder matcher does not support ${e.type}`);
748
19
  return {
749
20
  pass: this.isNot ? !n.pass : n.pass,
@@ -752,8 +23,8 @@ function J() {
752
23
  },
753
24
  toHaveModifier(e, t) {
754
25
  let n;
755
- if (e.type === "ClassLocator") n = d(e, t, this.isNot);
756
- else if (e.type === "FunctionLocator") n = M(e, t, this.isNot);
26
+ if (e.type === "ClassLocator") n = a(e, t, this.isNot);
27
+ else if (e.type === "FunctionLocator") n = v(e, t, this.isNot);
757
28
  else throw Error(`toHaveModifier matcher does not support ${e.type}`);
758
29
  return {
759
30
  pass: this.isNot ? !n.pass : n.pass,
@@ -762,7 +33,7 @@ function J() {
762
33
  },
763
34
  toExtendClass(e, t) {
764
35
  let n;
765
- if (e.type === "ClassLocator") n = a(e, t, this.isNot);
36
+ if (e.type === "ClassLocator") n = r(e, t, this.isNot);
766
37
  else throw Error(`toExtendClass matcher does not support ${e.type}`);
767
38
  return {
768
39
  pass: this.isNot ? !n.pass : n.pass,
@@ -771,7 +42,7 @@ function J() {
771
42
  },
772
43
  toImplementInterface(e, t) {
773
44
  let n;
774
- if (e.type === "ClassLocator") n = m(e, t, this.isNot);
45
+ if (e.type === "ClassLocator") n = s(e, t, this.isNot);
775
46
  else throw Error(`toImplementInterface matcher does not support ${e.type}`);
776
47
  return {
777
48
  pass: this.isNot ? !n.pass : n.pass,
@@ -780,7 +51,7 @@ function J() {
780
51
  },
781
52
  toHaveExplicitReturnType(e) {
782
53
  let t;
783
- if (e.type === "FunctionLocator") t = k(e, this.isNot);
54
+ if (e.type === "FunctionLocator") t = h(e, this.isNot);
784
55
  else throw Error(`toHaveExplicitReturnType matcher does not support ${e.type}`);
785
56
  return {
786
57
  pass: this.isNot ? !t.pass : t.pass,
@@ -789,26 +60,35 @@ function J() {
789
60
  },
790
61
  toBeReadonly(e) {
791
62
  let t;
792
- if (e.type === "PropertyLocator") t = G(e, this.isNot);
63
+ if (e.type === "PropertyLocator") t = S(e, this.isNot);
793
64
  else throw Error(`toBeReadonly matcher does not support ${e.type}`);
794
65
  return {
795
66
  pass: this.isNot ? !t.pass : t.pass,
796
67
  message: t.message
797
68
  };
798
69
  },
799
- toDependOnFilesInFolder(e, t) {
800
- let n;
801
- if (e.type === "FileLocator") n = b(e, t, this.isNot);
70
+ toDependOnFilesInFolder(e, n) {
71
+ let r;
72
+ if (e.type === "FileLocator") r = t(e, n, this.isNot);
802
73
  else throw Error(`toDependOnFilesInFolder matcher does not support ${e.type}`);
803
74
  return {
804
- pass: this.isNot ? !n.pass : n.pass,
805
- message: n.message
75
+ pass: this.isNot ? !r.pass : r.pass,
76
+ message: r.message
77
+ };
78
+ },
79
+ toDependOnExternalModule(t, n) {
80
+ let r;
81
+ if (t.type === "FileLocator") r = e(t, n, this.isNot);
82
+ else throw Error(`toDependOnExternalModule matcher does not support ${t.type}`);
83
+ return {
84
+ pass: this.isNot ? !r.pass : r.pass,
85
+ message: r.message
806
86
  };
807
87
  },
808
88
  toBeFreeOfCycles(e) {
809
89
  let t;
810
- if (e.type === "FileLocator") t = x(e, this.isNot);
811
- else if (e.type === "SliceLocator") t = K(e, this.isNot);
90
+ if (e.type === "FileLocator") t = u(e, this.isNot);
91
+ else if (e.type === "SliceLocator") t = C(e, this.isNot);
812
92
  else throw Error(`toBeFreeOfCycles matcher does not support ${e.type}`);
813
93
  return {
814
94
  pass: this.isNot ? !t.pass : t.pass,
@@ -817,9 +97,9 @@ function J() {
817
97
  },
818
98
  toMatchNamePattern(e, t) {
819
99
  let n;
820
- if (e.type === "FileLocator") n = D(e, t, this.isNot);
821
- else if (e.type === "ClassLocator") n = g(e, t, this.isNot);
822
- else if (e.type === "FunctionLocator") n = P(e, t, this.isNot);
100
+ if (e.type === "FileLocator") n = m(e, t, this.isNot);
101
+ else if (e.type === "ClassLocator") n = c(e, t, this.isNot);
102
+ else if (e.type === "FunctionLocator") n = b(e, t, this.isNot);
823
103
  else throw Error(`toMatchNamePattern matcher does not support ${e.type}`);
824
104
  return {
825
105
  pass: this.isNot ? !n.pass : n.pass,
@@ -828,9 +108,9 @@ function J() {
828
108
  },
829
109
  toHaveMaxCyclomaticComplexity(e, t) {
830
110
  let n;
831
- if (e.type === "FileLocator") n = S(e, t, this.isNot);
832
- else if (e.type === "ClassLocator") n = l(e, t, this.isNot);
833
- else if (e.type === "FunctionLocator") n = A(e, t, this.isNot);
111
+ if (e.type === "FileLocator") n = d(e, t, this.isNot);
112
+ else if (e.type === "ClassLocator") n = i(e, t, this.isNot);
113
+ else if (e.type === "FunctionLocator") n = g(e, t, this.isNot);
834
114
  else throw Error(`toHaveMaxCyclomaticComplexity matcher does not support ${e.type}`);
835
115
  return {
836
116
  pass: this.isNot ? !n.pass : n.pass,
@@ -839,8 +119,8 @@ function J() {
839
119
  },
840
120
  toHaveMinMaintainabilityIndex(e, t) {
841
121
  let n;
842
- if (e.type === "FileLocator") n = E(e, t, this.isNot);
843
- else if (e.type === "FunctionLocator") n = j(e, t, this.isNot);
122
+ if (e.type === "FileLocator") n = p(e, t, this.isNot);
123
+ else if (e.type === "FunctionLocator") n = _(e, t, this.isNot);
844
124
  else throw Error(`toHaveMinMaintainabilityIndex matcher does not support ${e.type}`);
845
125
  return {
846
126
  pass: this.isNot ? !n.pass : n.pass,
@@ -849,7 +129,7 @@ function J() {
849
129
  },
850
130
  toHaveMaxDistanceFromMainSequence(e, t) {
851
131
  let n;
852
- if (e.type === "SliceLocator") n = q(e, t, this.isNot);
132
+ if (e.type === "SliceLocator") n = w(e, t, this.isNot);
853
133
  else throw Error(`toHaveMaxDistanceFromMainSequence matcher does not support ${e.type}`);
854
134
  return {
855
135
  pass: this.isNot ? !n.pass : n.pass,
@@ -858,8 +138,8 @@ function J() {
858
138
  },
859
139
  toHaveNameMatchingFileName(e) {
860
140
  let t;
861
- if (e.type === "FunctionLocator") t = N(e, this.isNot);
862
- else if (e.type === "ClassLocator") t = p(e, this.isNot);
141
+ if (e.type === "FunctionLocator") t = y(e, this.isNot);
142
+ else if (e.type === "ClassLocator") t = o(e, this.isNot);
863
143
  else throw Error(`toHaveNameMatchingFileName matcher does not support ${e.type}`);
864
144
  return {
865
145
  pass: this.isNot ? !t.pass : t.pass,
@@ -868,7 +148,7 @@ function J() {
868
148
  },
869
149
  toHaveMaxExportedFunctions(e, t) {
870
150
  let n;
871
- if (e.type === "FileLocator") n = C(e, t, this.isNot);
151
+ if (e.type === "FileLocator") n = f(e, t, this.isNot);
872
152
  else throw Error(`toHaveMaxExportedFunctions matcher does not support ${e.type}`);
873
153
  return {
874
154
  pass: this.isNot ? !n.pass : n.pass,
@@ -878,6 +158,6 @@ function J() {
878
158
  });
879
159
  }
880
160
  //#endregion
881
- export { b as checkDependOnFilesInFolder, I as checkLayeredArchitecture, a as classCheckExtendClass, l as classCheckHaveMaxCyclomaticComplexity, d as classCheckHaveModifier, p as classCheckHaveNameMatchingFileName, m as classCheckImplementInterface, g as classCheckMatchNamePattern, _ as classCheckResideInFolder, L as createLayeredArchitecture, x as fileCheckBeFreeOfCycles, S as fileCheckHaveMaxCyclomaticComplexity, C as fileCheckHaveMaxExportedFunctions, E as fileCheckHaveMinMaintainabilityIndex, D as fileCheckMatchNamePattern, k as functionCheckHaveExplicitReturnType, A as functionCheckHaveMaxCyclomaticComplexity, j as functionCheckHaveMinMaintainabilityIndex, M as functionCheckHaveModifier, N as functionCheckHaveNameMatchingFileName, P as functionCheckMatchNamePattern, R as layer, B as layerShouldNotBeAccessedByAnyLayer, V as layerShouldOnlyBeAccessedBy, v as locateClasses, O as locateFiles, F as locateFunctions, H as locateProperties, U as locateSlices, W as parseProject, G as propertyCheckBeReadonly, J as setupMatchers, K as sliceCheckBeFreeOfCycles, q as sliceCheckHaveMaxDistanceFromMainSequence };
161
+ export { x as parseProject, E as setupMatchers };
882
162
 
883
163
  //# sourceMappingURL=index.mjs.map