@autotelic/joggle 0.0.0-stage → 0.1.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.
Files changed (101) hide show
  1. package/JOGGLE.md +634 -0
  2. package/LICENSE +21 -0
  3. package/README.md +88 -2
  4. package/bin/joggle.js +6 -0
  5. package/dist/answer-store.js +305 -0
  6. package/dist/architecture.js +190 -0
  7. package/dist/ask.js +184 -0
  8. package/dist/astro.js +75 -0
  9. package/dist/atoms.js +76 -0
  10. package/dist/bundles.js +156 -0
  11. package/dist/calibration.js +60 -0
  12. package/dist/candidates.js +561 -0
  13. package/dist/canonical.js +24 -0
  14. package/dist/cascade.js +98 -0
  15. package/dist/check.js +854 -0
  16. package/dist/cluster.js +69 -0
  17. package/dist/config.js +195 -0
  18. package/dist/content-mappers.js +83 -0
  19. package/dist/decision.js +203 -0
  20. package/dist/fingerprint.js +61 -0
  21. package/dist/git.js +127 -0
  22. package/dist/gitignore.js +65 -0
  23. package/dist/glob.js +51 -0
  24. package/dist/imports.js +153 -0
  25. package/dist/jsonc.js +95 -0
  26. package/dist/main.js +630 -0
  27. package/dist/manifest.js +42 -0
  28. package/dist/meta.js +170 -0
  29. package/dist/moves.js +47 -0
  30. package/dist/operation.js +133 -0
  31. package/dist/parsecache.js +264 -0
  32. package/dist/plans.js +425 -0
  33. package/dist/plugin.js +71 -0
  34. package/dist/plugins.js +136 -0
  35. package/dist/policy.js +676 -0
  36. package/dist/presets/composition.js +32 -0
  37. package/dist/report.js +474 -0
  38. package/dist/reporting.js +132 -0
  39. package/dist/result.js +28 -0
  40. package/dist/roles.js +303 -0
  41. package/dist/rule.js +194 -0
  42. package/dist/rules/append-only-honoured.js +190 -0
  43. package/dist/rules/bundle-conformance.js +245 -0
  44. package/dist/rules/call-pattern.js +209 -0
  45. package/dist/rules/cluster-verdict.js +700 -0
  46. package/dist/rules/compose-types.js +250 -0
  47. package/dist/rules/data-error-as-outage.js +482 -0
  48. package/dist/rules/declared-staleness.js +242 -0
  49. package/dist/rules/dependency-fit.js +297 -0
  50. package/dist/rules/deviation-has-a-shape.js +225 -0
  51. package/dist/rules/doc-matches-code.js +191 -0
  52. package/dist/rules/duplicate-call-run.js +240 -0
  53. package/dist/rules/duplicate-implementation.js +89 -0
  54. package/dist/rules/duplicate-meaning.js +130 -0
  55. package/dist/rules/fact-or-derivation.js +202 -0
  56. package/dist/rules/field-type-drift.js +373 -0
  57. package/dist/rules/generic-carries-a-caller.js +198 -0
  58. package/dist/rules/hoist-to-domain.js +288 -0
  59. package/dist/rules/import-architecture.js +393 -0
  60. package/dist/rules/index.js +105 -0
  61. package/dist/rules/inferred-over-recorded.js +214 -0
  62. package/dist/rules/intent-drift.js +286 -0
  63. package/dist/rules/invariant-has-a-reconciler.js +190 -0
  64. package/dist/rules/language-drift.js +234 -0
  65. package/dist/rules/meaning-switched-by-flag.js +189 -0
  66. package/dist/rules/module-direction.js +231 -0
  67. package/dist/rules/name-as-address.js +216 -0
  68. package/dist/rules/name-the-primitive.js +203 -0
  69. package/dist/rules/naming-drift.js +218 -0
  70. package/dist/rules/nullability-drift.js +220 -0
  71. package/dist/rules/object-shape.js +280 -0
  72. package/dist/rules/one-concept-one-type.js +243 -0
  73. package/dist/rules/page-needs-composition.js +227 -0
  74. package/dist/rules/reimplemented-primitive.js +283 -0
  75. package/dist/rules/reversal.js +264 -0
  76. package/dist/rules/rule-judgment.js +252 -0
  77. package/dist/rules/schema-excludes-domain-value.js +190 -0
  78. package/dist/rules/shallow-module.js +204 -0
  79. package/dist/rules/single-path.js +237 -0
  80. package/dist/rules/structural-collapse.js +198 -0
  81. package/dist/rules/temporal-coupling.js +205 -0
  82. package/dist/rules/types-over-logic.js +198 -0
  83. package/dist/rules/unaccounted-drop.js +190 -0
  84. package/dist/rules/unbounded-default-read.js +227 -0
  85. package/dist/run-cache.js +132 -0
  86. package/dist/schema.js +285 -0
  87. package/dist/similarity.js +119 -0
  88. package/dist/source.js +30 -0
  89. package/dist/sql.js +34 -0
  90. package/dist/stages.js +39 -0
  91. package/dist/state.js +65 -0
  92. package/dist/testing.js +131 -0
  93. package/dist/tsconfig-scope.js +32 -0
  94. package/dist/tsgo.js +127 -0
  95. package/dist/typefacts.js +455 -0
  96. package/dist/typetrace.js +283 -0
  97. package/dist/verdict.js +65 -0
  98. package/dist/vocabulary.js +365 -0
  99. package/dist/workspace.js +1963 -0
  100. package/extensions/joggle.ts +454 -0
  101. package/package.json +85 -3
@@ -0,0 +1,393 @@
1
+ import { Effect, Order } from "effect";
2
+ import { Decision } from "effect/ai";
3
+ import { cyclesIn, directionViolations, layerOf, layersFrom, purityViolations, } from "../architecture.js";
4
+ import { Atoms } from "../atoms.js";
5
+ import {} from "../plans.js";
6
+ import { verdictsOf } from "../plans.js";
7
+ import { locator, messages, reporter } from "../reporting.js";
8
+ import { verdictOf } from "../verdict.js";
9
+ import { inGraphScope, outcome, qualityOf, } from "../rule.js";
10
+ const LAYER_RULE = "joggle/layer-direction";
11
+ const CYCLE_RULE = "joggle/import-cycle";
12
+ const PURITY_RULE = "joggle/layer-purity";
13
+ /** Every architecture rule reports through these. */
14
+ const ARCHITECTURE_MESSAGES = messages({
15
+ upward_import: "{{from}} imports {{to}}, which sits in {{toLayer}} -- a layer above {{fromLayer}}.",
16
+ upward_import_help: "joggle.config.json declares the layers bottom-up, so {{fromLayer}} may not depend on {{toLayer}}. Move the shared piece down, or invert the dependency by passing it in.",
17
+ import_cycle: "Import cycle: {{files}}.",
18
+ import_cycle_help: "Break the loop by moving the shared piece below both modules, or by passing the dependency in.",
19
+ forbidden_import: "{{from}} imports {{specifier}}, which the {{layer}} layer forbids.",
20
+ forbidden_import_help: "The {{layer}} layer declares {{pattern}} forbidden in joggle.config.json, so nothing inside it may reach for {{specifier}}. Take what this needs as an argument, or move the file out of the layer.",
21
+ });
22
+ /**
23
+ * Where an import statement sits, as an offset the engine turns into a location.
24
+ *
25
+ * The import graph carries specifiers but not positions, and a finding with no
26
+ * position is a finding a reader has to go looking for.
27
+ */
28
+ const spanOf = (files, edge) => {
29
+ const file = files.get(edge.importer);
30
+ if (file === undefined)
31
+ return { file: edge.importer, start: 0 };
32
+ for (const quote of ['"', "'"]) {
33
+ const index = file.text.indexOf(quote + edge.specifier + quote);
34
+ if (index !== -1)
35
+ return { file: edge.importer, start: index };
36
+ }
37
+ return { file: edge.importer, start: 0 };
38
+ };
39
+ const filesByPath = (workspace) => new Map(workspace.files.map((file) => [file.path, file]));
40
+ /**
41
+ * Read one verdict against its violating label.
42
+ *
43
+ * The band, not the rule: a decisive answer is a finding, a non-decisive one is
44
+ * recorded (`flagged: ...`), and any other label is a decline with its reason.
45
+ */
46
+ const readVerdict = (answer, violating, declineReason) => {
47
+ const verdict = verdictOf(answer, [violating]);
48
+ if (verdict === undefined) {
49
+ return { action: "report", review: false };
50
+ }
51
+ if (verdict.label !== violating) {
52
+ return { action: "drop", stage: "declined", reason: declineReason(verdict.label ?? "unreadable") };
53
+ }
54
+ const quality = qualityOf({
55
+ score: verdict.probability,
56
+ margin: verdict.margin,
57
+ confidence: verdict.confidence,
58
+ });
59
+ if (quality.quality === "drop") {
60
+ return {
61
+ action: "drop",
62
+ stage: "gated",
63
+ reason: quality.reason,
64
+ };
65
+ }
66
+ return { action: "report", review: quality.quality === "review" };
67
+ };
68
+ /**
69
+ * Dependencies point one way.
70
+ *
71
+ * The upward edge is decidable from the import graph. Whether the layer
72
+ * assignment is what is wrong, or the import is a genuine mistake, is the
73
+ * question.
74
+ */
75
+ export const layerDirection = {
76
+ id: LAYER_RULE,
77
+ severity: "warn",
78
+ description: "A module imports from a layer that sits above it.",
79
+ judged: true,
80
+ onUnavailable: "report",
81
+ messages: ARCHITECTURE_MESSAGES,
82
+ plan: Effect.fn("joggle/layer-direction")(function* (workspace, scope, context) {
83
+ const layers = layersFrom(context.config);
84
+ if (layers.length === 0) {
85
+ return {
86
+ plans: [],
87
+ read: () => outcome([], [
88
+ "no layers are declared in the config, so there is no direction to check -- not the same as finding none",
89
+ ]),
90
+ };
91
+ }
92
+ const all = directionViolations(workspace.imports, layers);
93
+ const violations = scope.changed === undefined ? all : all.filter((violation) => inGraphScope(scope, violation.from));
94
+ const report = reporter(layerDirection, locator(workspace));
95
+ const files = filesByPath(workspace);
96
+ const edgeAt = new Map(workspace.imports.edges.map((edge) => [edge.importer + "\u0000" + edge.to, edge]));
97
+ const candidates = violations.flatMap((violation) => {
98
+ const edge = edgeAt.get(violation.from + "\u0000" + violation.to);
99
+ return edge === undefined ? [] : [{ violation, edge }];
100
+ });
101
+ const atoms = yield* Atoms;
102
+ const planned = yield* Effect.forEach(candidates, (candidate) => Effect.gen(function* () {
103
+ const { violation, edge } = candidate;
104
+ const id = yield* atoms.add({
105
+ from: violation.from,
106
+ to: violation.to,
107
+ fromLayer: violation.fromLayer,
108
+ toLayer: violation.toLayer,
109
+ specifier: edge.specifier,
110
+ });
111
+ const plan = {
112
+ ruleId: LAYER_RULE,
113
+ subject: violation.from + " -> " + violation.to,
114
+ concerns: [violation.from],
115
+ atoms: [id],
116
+ violations: { verdict: ["upward"] },
117
+ decisions: {
118
+ verdict: Decision.classify({
119
+ instructions: [
120
+ "`atoms[" + id + "].from` (" + violation.fromLayer + ") imports `atoms[" + id + "].to` (" + violation.toLayer + "), and the config declares " + violation.toLayer + " above " + violation.fromLayer + ", so this edge points upward.",
121
+ "Is that an upward dependency to break, or is the layer assignment itself what is wrong?",
122
+ "Answer `upward` when the dependency genuinely points the wrong way, so the shared piece should move down or be passed in.",
123
+ "Answer `misclassified` when the importing or imported file is in the wrong layer, so the config should change.",
124
+ "Answer `exception` when the upward edge is deliberate and acceptable.",
125
+ ].join("\n"),
126
+ criteria: {
127
+ upward: "A real upward dependency. Move the shared piece down, or invert it.",
128
+ misclassified: "The layer assignment is wrong, not the import.",
129
+ exception: "A deliberate, acceptable exception.",
130
+ },
131
+ }),
132
+ },
133
+ read: (answers) => answers,
134
+ };
135
+ return { candidate, id, plan };
136
+ }), { concurrency: "unbounded" });
137
+ const unranked = workspace.files.filter((file) => layerOf(layers, file.path) === undefined).length;
138
+ const ranked = workspace.files.length - unranked;
139
+ return {
140
+ plans: planned.map((value) => value.plan),
141
+ read: (answers) => {
142
+ const verdicts = verdictsOf(answers);
143
+ const diagnostics = [];
144
+ const drops = [];
145
+ planned.forEach((value, index) => {
146
+ const { violation, edge } = value.candidate;
147
+ const outcomeOf = readVerdict(verdicts[index]?.["verdict"], "upward", (label) => label === "misclassified" ? "the layer assignment is what is wrong" : "a deliberate exception");
148
+ if (outcomeOf.action === "drop") {
149
+ drops.push({
150
+ ruleId: LAYER_RULE,
151
+ subject: violation.from + " -> " + violation.to,
152
+ stage: outcomeOf.stage,
153
+ reason: outcomeOf.reason,
154
+ });
155
+ return;
156
+ }
157
+ const verdict = verdicts[index]?.["verdict"];
158
+ const confidence = verdict !== undefined && "confidence" in verdict ? verdict.confidence : undefined;
159
+ diagnostics.push(report({
160
+ about: spanOf(files, edge),
161
+ messageId: "upward_import",
162
+ data: {
163
+ from: violation.from,
164
+ to: violation.to,
165
+ toLayer: violation.toLayer,
166
+ fromLayer: violation.fromLayer,
167
+ },
168
+ helpId: "upward_import_help",
169
+ identity: [LAYER_RULE, violation.from, violation.to].join("\u0000"),
170
+ judged: true,
171
+ confidence,
172
+ severity: outcomeOf.review ? "info" : "warn",
173
+ }));
174
+ });
175
+ return outcome(diagnostics, [
176
+ `${violations.length} upward import(s) among ${ranked} ranked file(s) in ${layers.length} declared layer(s); ${unranked} file(s) in no layer` +
177
+ (all.length > violations.length ? `; ${all.length - violations.length} outside the scope of this run` : ""),
178
+ ], drops);
179
+ },
180
+ };
181
+ }),
182
+ };
183
+ /**
184
+ * A module imports, directly or indirectly, from itself.
185
+ *
186
+ * The cycle is decidable. Whether it is a real mutual dependency to break, or a
187
+ * false positive (a barrel, an erased type edge), is the question.
188
+ */
189
+ export const importCycle = {
190
+ id: CYCLE_RULE,
191
+ severity: "warn",
192
+ description: "A module imports, directly or indirectly, from itself.",
193
+ judged: true,
194
+ onUnavailable: "report",
195
+ messages: ARCHITECTURE_MESSAGES,
196
+ plan: Effect.fn("joggle/import-cycle")(function* (workspace, scope) {
197
+ const report = reporter(importCycle, locator(workspace));
198
+ const cycles = cyclesIn(workspace.imports);
199
+ const runtime = cycles.filter((cycle) => cycle.runtime);
200
+ const named = cycles.filter((cycle) => !cycle.runtime);
201
+ const inCycleScope = (files) => scope.changed === undefined || files.some((file) => inGraphScope(scope, file));
202
+ const anchorOf = (files) => scope.changed === undefined
203
+ ? files[0] ?? ""
204
+ : files.find((file) => inGraphScope(scope, file)) ?? files[0] ?? "";
205
+ const scopedRuntime = runtime.filter((cycle) => inCycleScope(cycle.loop));
206
+ const scopedNamed = named.filter((cycle) => inCycleScope(cycle.loop));
207
+ const erasedEntirely = scopedNamed.filter((cycle) => cycle.typeOnly).length;
208
+ const partlyErased = scopedNamed.length - erasedEntirely;
209
+ const outside = runtime.length - scopedRuntime.length;
210
+ const atoms = yield* Atoms;
211
+ const planned = yield* Effect.forEach(scopedRuntime, (cycle) => Effect.gen(function* () {
212
+ const first = anchorOf(cycle.loop);
213
+ const members = new Set(cycle.loop);
214
+ // The edges that make the loop, so the question can tell a real mutual
215
+ // dependency from a barrel or a re-export instead of reading file names.
216
+ const edges = workspace.imports.edges
217
+ .filter((edge) => members.has(edge.importer) && members.has(edge.to))
218
+ .map((edge) => ({ from: edge.importer, to: edge.to, specifier: edge.specifier }));
219
+ const id = yield* atoms.add({ files: cycle.loop, runtime: cycle.runtime, typeOnly: cycle.typeOnly, edges });
220
+ const plan = {
221
+ ruleId: CYCLE_RULE,
222
+ subject: cycle.loop.join(" -> "),
223
+ concerns: [...cycle.loop],
224
+ atoms: [id],
225
+ violations: { verdict: ["cycle"] },
226
+ decisions: {
227
+ verdict: Decision.classify({
228
+ instructions: [
229
+ `\`atoms[${id}].files\` is an import cycle: ${[...cycle.loop, first].join(" -> ")}.`,
230
+ `\`atoms[${id}].edges\` is the import statements that close the loop, with the specifier each one uses.`,
231
+ "Is that a real mutual dependency to break, or a false positive?",
232
+ "Answer `cycle` when two or more of the modules genuinely need each other, so the loop should be broken.",
233
+ "Answer `false_positive` when the loop is an artefact -- a barrel or index re-export, a specifier that resolves to a type only, or an edge that is erased at build time.",
234
+ ].join("\n"),
235
+ criteria: {
236
+ cycle: "A real loop. Move the shared piece below both, or pass it in.",
237
+ false_positive: "Not a real mutual dependency. Nothing to break.",
238
+ },
239
+ }),
240
+ },
241
+ read: (answers) => answers,
242
+ };
243
+ return { cycle, first, id, plan };
244
+ }), { concurrency: "unbounded" });
245
+ return {
246
+ plans: planned.map((value) => value.plan),
247
+ read: (answers) => {
248
+ const verdicts = verdictsOf(answers);
249
+ const diagnostics = [];
250
+ const drops = [];
251
+ planned.forEach((value, index) => {
252
+ const { cycle, first } = value;
253
+ const subject = cycle.loop.join(" -> ");
254
+ const outcomeOf = readVerdict(verdicts[index]?.["verdict"], "cycle", () => "the cycle cannot cause a load-order problem");
255
+ if (outcomeOf.action === "drop") {
256
+ drops.push({ ruleId: CYCLE_RULE, subject, stage: outcomeOf.stage, reason: outcomeOf.reason });
257
+ return;
258
+ }
259
+ const verdict = verdicts[index]?.["verdict"];
260
+ const confidence = verdict !== undefined && "confidence" in verdict ? verdict.confidence : undefined;
261
+ diagnostics.push(report({
262
+ about: { file: first, start: 0 },
263
+ messageId: "import_cycle",
264
+ data: { files: [...cycle.loop, first].join(" -> ") },
265
+ helpId: "import_cycle_help",
266
+ identity: [CYCLE_RULE, ...[...cycle.loop].sort(Order.String)].join("\u0000"),
267
+ judged: true,
268
+ confidence,
269
+ severity: outcomeOf.review ? "info" : "warn",
270
+ }));
271
+ });
272
+ return outcome(diagnostics, [
273
+ `${scopedRuntime.length} runtime cycle(s), ${erasedEntirely} type-only, ${partlyErased} partly erased, in ${workspace.imports.edges.length} import edge(s)` +
274
+ (outside > 0 ? `; ${outside} cycle(s) outside the scope of this run` : ""),
275
+ ...scopedNamed.map((cycle) => cycle.typeOnly
276
+ ? `type-only cycle, erased entirely at build time: ${cycle.loop.join(" -> ")}`
277
+ : `cycle with an erased edge, so broken before it loads: ${cycle.loop.join(" -> ")}`),
278
+ ], drops);
279
+ },
280
+ };
281
+ }),
282
+ };
283
+ /** A module imports something its layer forbids. */
284
+ export const layerPurity = {
285
+ id: PURITY_RULE,
286
+ severity: "warn",
287
+ description: "A module imports something its layer forbids.",
288
+ judged: true,
289
+ onUnavailable: "report",
290
+ messages: ARCHITECTURE_MESSAGES,
291
+ plan: Effect.fn("joggle/layer-purity")(function* (workspace, scope, context) {
292
+ const layers = layersFrom(context.config);
293
+ const constrained = layers.filter((layer) => layer.forbid.length > 0);
294
+ if (constrained.length === 0) {
295
+ return {
296
+ plans: [],
297
+ read: () => outcome([], [
298
+ "no layer declares a forbidden import, so there was nothing to check -- not the same as finding none",
299
+ ]),
300
+ };
301
+ }
302
+ const all = purityViolations(workspace.imports, layers);
303
+ const violations = scope.changed === undefined ? all : all.filter((violation) => inGraphScope(scope, violation.importer));
304
+ const report = reporter(layerPurity, locator(workspace));
305
+ const files = filesByPath(workspace);
306
+ const edgeAt = new Map(workspace.imports.edges.map((edge) => [edge.importer + "\u0000" + edge.specifier, edge]));
307
+ const candidates = violations.flatMap((violation) => {
308
+ const edge = edgeAt.get(violation.importer + "\u0000" + violation.specifier);
309
+ return edge === undefined ? [] : [{ violation, edge }];
310
+ });
311
+ const atoms = yield* Atoms;
312
+ const planned = yield* Effect.forEach(candidates, (candidate) => Effect.gen(function* () {
313
+ const { violation } = candidate;
314
+ const id = yield* atoms.add({
315
+ from: violation.importer,
316
+ specifier: violation.specifier,
317
+ layer: violation.layer,
318
+ pattern: violation.pattern,
319
+ });
320
+ const plan = {
321
+ ruleId: PURITY_RULE,
322
+ subject: violation.importer + " -> " + violation.specifier,
323
+ concerns: [violation.importer],
324
+ atoms: [id],
325
+ violations: { verdict: ["forbidden"] },
326
+ decisions: {
327
+ verdict: Decision.classify({
328
+ instructions: [
329
+ "The " + violation.layer + " layer declares `atoms[" + id + "].pattern` forbidden, and `atoms[" + id + "].from` imports `atoms[" + id + "].specifier`, which matches it.",
330
+ "Is that a forbidden dependency, or a pattern that matched the wrong thing?",
331
+ "Answer `forbidden` when the import genuinely reaches for what the layer forbids.",
332
+ "Answer `false_match` when the pattern matched something the layer does not actually forbid.",
333
+ ].join("\n"),
334
+ criteria: {
335
+ forbidden: "A real forbidden dependency. Take it as an argument, or move the file out of the layer.",
336
+ false_match: "The pattern matched the wrong thing.",
337
+ },
338
+ }),
339
+ },
340
+ read: (answers) => answers,
341
+ };
342
+ return { candidate, id, plan };
343
+ }), { concurrency: "unbounded" });
344
+ return {
345
+ plans: planned.map((value) => value.plan),
346
+ read: (answers) => {
347
+ const verdicts = verdictsOf(answers);
348
+ const diagnostics = [];
349
+ const drops = [];
350
+ planned.forEach((value, index) => {
351
+ const { violation, edge } = value.candidate;
352
+ const subject = violation.importer + " -> " + violation.specifier;
353
+ const outcomeOf = readVerdict(verdicts[index]?.["verdict"], "forbidden", () => "the pattern matched something the layer does not forbid");
354
+ if (outcomeOf.action === "drop") {
355
+ drops.push({ ruleId: PURITY_RULE, subject, stage: outcomeOf.stage, reason: outcomeOf.reason });
356
+ return;
357
+ }
358
+ const verdict = verdicts[index]?.["verdict"];
359
+ const confidence = verdict !== undefined && "confidence" in verdict ? verdict.confidence : undefined;
360
+ diagnostics.push(report({
361
+ about: spanOf(files, edge),
362
+ messageId: "forbidden_import",
363
+ data: {
364
+ from: violation.importer,
365
+ specifier: violation.specifier,
366
+ layer: violation.layer,
367
+ pattern: violation.pattern,
368
+ },
369
+ helpId: "forbidden_import_help",
370
+ identity: [PURITY_RULE, violation.importer, violation.specifier].join("\u0000"),
371
+ judged: true,
372
+ confidence,
373
+ severity: outcomeOf.review ? "info" : "warn",
374
+ }));
375
+ });
376
+ return outcome(diagnostics, [
377
+ violations.length +
378
+ " forbidden import(s) across " +
379
+ constrained.length +
380
+ " constrained layer(s)" +
381
+ (all.length > violations.length
382
+ ? "; " + String(all.length - violations.length) + " outside the scope of this run"
383
+ : ""),
384
+ ], drops);
385
+ },
386
+ };
387
+ }),
388
+ };
389
+ export const importArchitectureRules = [
390
+ layerDirection,
391
+ layerPurity,
392
+ importCycle,
393
+ ];
@@ -0,0 +1,105 @@
1
+ import { duplicateImplementation } from "./duplicate-implementation.js";
2
+ import { duplicateCallRun } from "./duplicate-call-run.js";
3
+ import { duplicateMeaning } from "./duplicate-meaning.js";
4
+ import { importArchitectureRules } from "./import-architecture.js";
5
+ import { dependencyFit } from "./dependency-fit.js";
6
+ import { docMatchesCode } from "./doc-matches-code.js";
7
+ import { fieldTypeDrift } from "./field-type-drift.js";
8
+ import { languageDrift } from "./language-drift.js";
9
+ import { callPattern } from "./call-pattern.js";
10
+ import { nameAsAddress } from "./name-as-address.js";
11
+ import { moduleDirection } from "./module-direction.js";
12
+ import { objectShape } from "./object-shape.js";
13
+ import { composeTypes } from "./compose-types.js";
14
+ import { nameThePrimitive } from "./name-the-primitive.js";
15
+ import { ruleJudgment } from "./rule-judgment.js";
16
+ import { shallowModule } from "./shallow-module.js";
17
+ import { temporalCoupling } from "./temporal-coupling.js";
18
+ import { hoistToDomain } from "./hoist-to-domain.js";
19
+ import { namingDrift } from "./naming-drift.js";
20
+ import { reimplementedPrimitive } from "./reimplemented-primitive.js";
21
+ import { oneConceptOneType } from "./one-concept-one-type.js";
22
+ import { reversal } from "./reversal.js";
23
+ import { structuralCollapse } from "./structural-collapse.js";
24
+ import { nullabilityDrift } from "./nullability-drift.js";
25
+ import { dataErrorAsOutage } from "./data-error-as-outage.js";
26
+ import { typesOverLogic } from "./types-over-logic.js";
27
+ import { singlePath } from "./single-path.js";
28
+ import { unaccountedDrop } from "./unaccounted-drop.js";
29
+ import { genericCarriesACaller } from "./generic-carries-a-caller.js";
30
+ import { schemaExcludesDomainValue } from "./schema-excludes-domain-value.js";
31
+ import { meaningSwitchedByFlag } from "./meaning-switched-by-flag.js";
32
+ import { unboundedDefaultRead } from "./unbounded-default-read.js";
33
+ import { inferredOverRecorded } from "./inferred-over-recorded.js";
34
+ import { appendOnlyHonoured } from "./append-only-honoured.js";
35
+ import { declaredStaleness } from "./declared-staleness.js";
36
+ import { deviationHasAConcept } from "./deviation-has-a-shape.js";
37
+ import { factOrDerivation } from "./fact-or-derivation.js";
38
+ import { invariantHasAReconciler } from "./invariant-has-a-reconciler.js";
39
+ import { intentDrift } from "./intent-drift.js";
40
+ import { Context, Layer } from "effect";
41
+ /**
42
+ * The registry. Add a rule by writing one file and one line here.
43
+ *
44
+ * The rules that run without being asked for. The composition pattern is not
45
+ * here. It is a preset -- five rules that encode one starter repository's
46
+ * architecture, plus the page rule that judges whether a page follows it. A tool
47
+ * that runs somebody's opinions by default is a tool that gets switched off by
48
+ * the first team whose architecture differs, which is most of them.
49
+ *
50
+ * What is here is either derived from the code under analysis (import direction,
51
+ * cycles, field-set composition) or a question with no architecture in it
52
+ * (duplication, naming drift, undeclared dependencies).
53
+ */
54
+ export const allRules = [
55
+ ...importArchitectureRules,
56
+ composeTypes,
57
+ callPattern,
58
+ moduleDirection,
59
+ nameAsAddress,
60
+ objectShape,
61
+ nameThePrimitive,
62
+ ruleJudgment,
63
+ shallowModule,
64
+ temporalCoupling,
65
+ dependencyFit,
66
+ docMatchesCode,
67
+ fieldTypeDrift,
68
+ hoistToDomain,
69
+ languageDrift,
70
+ duplicateCallRun,
71
+ duplicateImplementation,
72
+ duplicateMeaning,
73
+ namingDrift,
74
+ reimplementedPrimitive,
75
+ oneConceptOneType,
76
+ structuralCollapse,
77
+ reversal,
78
+ nullabilityDrift,
79
+ dataErrorAsOutage,
80
+ typesOverLogic,
81
+ singlePath,
82
+ unaccountedDrop,
83
+ genericCarriesACaller,
84
+ schemaExcludesDomainValue,
85
+ meaningSwitchedByFlag,
86
+ unboundedDefaultRead,
87
+ inferredOverRecorded,
88
+ factOrDerivation,
89
+ declaredStaleness,
90
+ appendOnlyHonoured,
91
+ deviationHasAConcept,
92
+ invariantHasAReconciler,
93
+ intentDrift,
94
+ ];
95
+ /**
96
+ * The rule set, as a service.
97
+ *
98
+ * A run does not read a hardcoded array; it reads whatever the context provides.
99
+ * That is what lets a preset be a layer, a test provide three rules, and a
100
+ * repository add its own without editing this file.
101
+ */
102
+ export class Rules extends Context.Service()("@joggle/Rules") {
103
+ }
104
+ /** The built-in rules, as the default `Rules` layer. */
105
+ export const builtIn = Layer.succeed(Rules, allRules);