@hailstails/hone 2.0.0-pre.4 → 2.0.0-pre.5

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 (133) hide show
  1. package/ADOPTING.md +4 -15
  2. package/CHANGELOG.md +34 -0
  3. package/MIGRATING.md +6 -6
  4. package/README.md +3 -4
  5. package/chunks/{chunk-FPIP7JEC.js → chunk-4AJQHZ7I.js} +1 -1
  6. package/chunks/{chunk-CXM5KBZX.js → chunk-6LTJRJOE.js} +1 -1
  7. package/chunks/{chunk-PVSC4SE3.js → chunk-BISP2JOL.js} +4 -6
  8. package/chunks/{chunk-YGMO5Z6U.js → chunk-EFUWHLZK.js} +187 -193
  9. package/chunks/{chunk-BRANVR7K.js → chunk-FRE5IA3C.js} +1 -1
  10. package/chunks/{chunk-E4D5WDRX.js → chunk-GMLT3MHO.js} +252 -254
  11. package/chunks/chunk-M4VSJ27S.js +139 -0
  12. package/chunks/chunk-ND3EOGDK.js +2350 -0
  13. package/chunks/chunk-ONDBACCR.js +14332 -0
  14. package/chunks/{chunk-LD766VWU.js → chunk-U6W65ZOF.js} +31 -2
  15. package/chunks/{chunk-BKQ3K766.js → chunk-WPEOCLTP.js} +39 -33
  16. package/chunks/{chunk-A3RL4O5V.js → chunk-XNIXPQQ5.js} +35 -2
  17. package/docs/extending.md +2 -2
  18. package/methods/lenses/function-first.md +2 -2
  19. package/package.json +1 -1
  20. package/rules/README.md +5 -3
  21. package/rules/SPIRIT.md +1 -1
  22. package/rules/numbers.md +4 -4
  23. package/rules/principles/no-leak-across-a-boundary.md +1 -1
  24. package/rules/principles.md +1 -1
  25. package/rules/record-kinds/authorised-location.md +1 -1
  26. package/rules/records.md +11 -19
  27. package/rules/rules.md +5 -5
  28. package/rules/sources.md +6 -7
  29. package/rules/typescript/checks.md +55 -387
  30. package/rules/typescript/recipes/adapter-per-outside-party.md +10 -5
  31. package/rules/typescript/recipes/assert-to-narrow.md +114 -4
  32. package/rules/typescript/recipes/closure-factory.md +5 -5
  33. package/rules/typescript/recipes/companion-test-file.md +5 -3
  34. package/rules/typescript/recipes/composed-orchestrator.md +6 -4
  35. package/rules/typescript/recipes/composition-root.md +5 -3
  36. package/rules/typescript/recipes/{bounded-context-generic.md → constrained-context-generic.md} +6 -4
  37. package/rules/typescript/recipes/copy-never-write-in.md +6 -4
  38. package/rules/typescript/recipes/declared-not-bundled.md +5 -3
  39. package/rules/typescript/recipes/dependency-record.md +5 -3
  40. package/rules/typescript/recipes/domain-vocabulary-list.md +5 -3
  41. package/rules/typescript/recipes/entity-module.md +8 -5
  42. package/rules/typescript/recipes/exact-pins-and-a-lock-file.md +5 -3
  43. package/rules/typescript/recipes/extension-outside-the-vendored-code.md +5 -3
  44. package/rules/typescript/recipes/failure-asserted-as-a-value.md +44 -4
  45. package/rules/typescript/recipes/failure-mapping-at-the-adapter.md +8 -5
  46. package/rules/typescript/recipes/fix-the-declaration-not-the-value.md +5 -3
  47. package/rules/typescript/recipes/functional-iteration.md +8 -3
  48. package/rules/typescript/recipes/guard-clauses.md +5 -3
  49. package/rules/typescript/recipes/integration-test-owns-its-scratch.md +5 -3
  50. package/rules/typescript/recipes/integration-test-suffix.md +5 -3
  51. package/rules/typescript/recipes/it-each-over-typed-rows.md +117 -0
  52. package/rules/typescript/recipes/map-out-at-the-adapter.md +36 -4
  53. package/rules/typescript/recipes/meaning-in-names-not-comments.md +5 -5
  54. package/rules/typescript/recipes/named-exported-type.md +5 -3
  55. package/rules/typescript/recipes/narrow-ports.md +5 -3
  56. package/rules/typescript/recipes/one-argument-object.md +8 -3
  57. package/rules/typescript/recipes/{port-in-the-domain.md → port-in-a-module-of-its-own.md} +7 -5
  58. package/rules/typescript/recipes/ports-in-the-argument.md +5 -3
  59. package/rules/typescript/recipes/repo-scripts-only.md +5 -3
  60. package/rules/typescript/recipes/result-union.md +5 -5
  61. package/rules/typescript/recipes/screaming-folders.md +5 -5
  62. package/rules/typescript/recipes/shared-strict-base-config.md +5 -5
  63. package/rules/typescript/recipes/stub-with-vi-fn.md +130 -0
  64. package/rules/typescript/recipes/tagged-union-and-exhaustive-switch.md +5 -3
  65. package/rules/typescript/recipes/whole-words.md +5 -3
  66. package/rules/typescript/recipes/whole-written-out-expectation.md +284 -4
  67. package/rules/typescript/recipes/world-values-through-a-port.md +5 -3
  68. package/rules/typescript/recipes/zod-at-the-producers-adapter.md +8 -3
  69. package/rules/typescript/recipes.md +567 -21
  70. package/rules/typescript/symptoms/ambient-randomness.md +1 -1
  71. package/rules/typescript/symptoms/answer-set-in-a-hook.md +1 -1
  72. package/rules/typescript/symptoms/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site.md +1 -1
  73. package/rules/typescript/symptoms/{assertion-outside-a-test.md → assertion-outside-a-test-body.md} +1 -1
  74. package/rules/typescript/symptoms/branch-in-a-test/test-body.md +10 -184
  75. package/rules/typescript/symptoms/branch-in-a-test.md +11 -1
  76. package/rules/typescript/symptoms/claimed-type/non-null-assertions.md +1 -1
  77. package/rules/typescript/symptoms/{code-or-prose-read-as-text.md → code-or-prose-read-as-text-in-a-test.md} +2 -2
  78. package/rules/typescript/symptoms/computed-value-in-a-test/test-body.md +26 -117
  79. package/rules/typescript/symptoms/computed-value-in-a-test.md +1 -1
  80. package/rules/typescript/symptoms/date-used-directly.md +1 -1
  81. package/rules/typescript/symptoms/default-for-a-required-value.md +1 -1
  82. package/rules/typescript/symptoms/double-with-a-body/logic-in-a-passed-function.md +1 -18
  83. package/rules/typescript/symptoms/double-with-a-body.md +1 -1
  84. package/rules/typescript/symptoms/{export-from-a-test-file.md → export-from-a-test.md} +1 -1
  85. package/rules/typescript/symptoms/failure-shaped-as-success.md +1 -1
  86. package/rules/typescript/symptoms/inherited-environment-in-a-subprocess/git-spawn-environment.md +1 -1
  87. package/rules/typescript/symptoms/inner-layer-imports-outer.md +1 -1
  88. package/rules/typescript/symptoms/library-class-built-in-place.md +1 -1
  89. package/rules/typescript/symptoms/loop-keyword/loop-statement.md +1 -1
  90. package/rules/typescript/symptoms/outside-import-past-a-boundary/import-or-require.md +1 -0
  91. package/rules/typescript/symptoms/outside-import-past-a-boundary.md +5 -4
  92. package/rules/typescript/symptoms/outside-type-in-a-signature.md +2 -2
  93. package/rules/typescript/symptoms/{port-outside-the-domain.md → port-beside-its-adapter.md} +2 -2
  94. package/rules/typescript/symptoms/port-named-for-a-mechanism.md +1 -1
  95. package/rules/typescript/symptoms/process-global-used-in-place.md +1 -1
  96. package/rules/typescript/symptoms/rebinding/test-body.md +1 -18
  97. package/rules/typescript/symptoms/rebinding.md +11 -1
  98. package/rules/typescript/symptoms/schema-past-its-adapter.md +2 -2
  99. package/rules/typescript/symptoms/text-past-its-reader/test-body.md +2 -17
  100. package/rules/typescript/symptoms/text-past-its-reader.md +1 -1
  101. package/rules/typescript/symptoms/throw-or-catch-in-a-test/try-block.md +1 -25
  102. package/rules/typescript/symptoms/type-declared-in-a-test/test-type-declaration.md +1 -1
  103. package/rules/typescript/symptoms/unasserted-call.md +1 -1
  104. package/rules/typescript/symptoms.md +35 -35
  105. package/src/domain/language-layer/authored-item-types.d.ts +21 -5
  106. package/src/domain/runner/runner-result-types.d.ts +1 -2
  107. package/src/eslint-plugin.js +40 -38
  108. package/src/hone.js +15 -13638
  109. package/src/infrastructure/disciplines-file/version-one-names.json +4 -5
  110. package/src/infrastructure/engines/eslint/runner/runner.js +55 -45
  111. package/src/infrastructure/engines/walker/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site/assertion-site.js +1 -1
  112. package/src/infrastructure/engines/walker/branch-in-a-test/test-body/test-body-logic.js +39 -65
  113. package/src/infrastructure/engines/walker/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read/raw-read.js +1 -1
  114. package/src/infrastructure/engines/walker/{export-from-a-test-file → export-from-a-test}/test-file-export/test-file-export.js +1 -1
  115. package/src/infrastructure/engines/walker/runner/runner.js +10 -10
  116. package/src/infrastructure/engines/walker/strictness-weakened/strict/compiler-overrides.js +3 -3
  117. package/src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/test-type-declaration.examples.json +15 -3
  118. package/src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/test-type-declaration.js +118 -4
  119. package/src/measure-engines.process.js +80 -0
  120. package/src/testing.js +81 -9
  121. package/chunks/chunk-7FVSZ2VL.js +0 -1304
  122. package/chunks/chunk-BIDD2YWP.js +0 -398
  123. package/rules/record-kinds/boundary-record.md +0 -9
  124. package/rules/typescript/recipes/iteach-over-typed-rows.md +0 -18
  125. package/rules/typescript/recipes/stub-with-vifn.md +0 -20
  126. /package/rules/typescript/symptoms/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read.md +0 -0
  127. /package/rules/typescript/symptoms/{export-from-a-test-file → export-from-a-test}/test-file-export.md +0 -0
  128. /package/src/infrastructure/engines/walker/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site/assertion-site.examples.json +0 -0
  129. /package/src/infrastructure/engines/walker/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site/piece.json +0 -0
  130. /package/src/infrastructure/engines/walker/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read/piece.json +0 -0
  131. /package/src/infrastructure/engines/walker/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read/raw-read.examples.json +0 -0
  132. /package/src/infrastructure/engines/walker/{export-from-a-test-file → export-from-a-test}/test-file-export/piece.json +0 -0
  133. /package/src/infrastructure/engines/walker/{export-from-a-test-file → export-from-a-test}/test-file-export/test-file-export.examples.json +0 -0
@@ -2,17 +2,297 @@
2
2
 
3
3
  ```json
4
4
  {
5
- "serves": {
6
- "rule": "straight-through-tests"
7
- },
5
+ "serves": [
6
+ {
7
+ "rule": "straight-through-tests"
8
+ }
9
+ ],
8
10
  "standing": "accepted",
9
11
  "reason": {
10
12
  "text": "\"no find, use bare access in tests for determinstic insistence on behaviours\".",
11
13
  "standing": "accepted"
12
- }
14
+ },
15
+ "examples": [
16
+ {
17
+ "anchor": "branching-with-if",
18
+ "answers": [
19
+ {
20
+ "check": "branch-in-a-test#test-body",
21
+ "form": "branching-with-if"
22
+ }
23
+ ]
24
+ },
25
+ {
26
+ "anchor": "a-short-circuit",
27
+ "answers": [
28
+ {
29
+ "check": "branch-in-a-test#test-body",
30
+ "form": "a-short-circuit"
31
+ }
32
+ ]
33
+ },
34
+ {
35
+ "anchor": "an-optional-chain-after-an-index",
36
+ "answers": [
37
+ {
38
+ "check": "branch-in-a-test#test-body",
39
+ "form": "an-optional-chain-after-an-index"
40
+ }
41
+ ]
42
+ },
43
+ {
44
+ "anchor": "a-method-that-picks-or-tests-an-element",
45
+ "answers": [
46
+ {
47
+ "check": "computed-value-in-a-test#test-body",
48
+ "form": "a-method-that-picks-or-tests-an-element"
49
+ }
50
+ ]
51
+ },
52
+ {
53
+ "anchor": "a-method-that-computes-a-value",
54
+ "answers": [
55
+ {
56
+ "check": "computed-value-in-a-test#test-body",
57
+ "form": "a-method-that-computes-a-value"
58
+ }
59
+ ]
60
+ },
61
+ {
62
+ "anchor": "a-method-that-mutates",
63
+ "answers": [
64
+ {
65
+ "check": "computed-value-in-a-test#test-body",
66
+ "form": "a-method-that-mutates"
67
+ }
68
+ ]
69
+ },
70
+ {
71
+ "anchor": "merging-objects",
72
+ "answers": [
73
+ {
74
+ "check": "computed-value-in-a-test#test-body",
75
+ "form": "merging-objects"
76
+ }
77
+ ]
78
+ },
79
+ {
80
+ "anchor": "building-an-object-from-entries",
81
+ "answers": [
82
+ {
83
+ "check": "computed-value-in-a-test#test-body",
84
+ "form": "building-an-object-from-entries"
85
+ }
86
+ ]
87
+ },
88
+ {
89
+ "anchor": "building-an-array-from-a-length",
90
+ "answers": [
91
+ {
92
+ "check": "computed-value-in-a-test#test-body",
93
+ "form": "building-an-array-from-a-length"
94
+ }
95
+ ]
96
+ },
97
+ {
98
+ "anchor": "a-math-call",
99
+ "answers": [
100
+ {
101
+ "check": "computed-value-in-a-test#test-body",
102
+ "form": "a-math-call"
103
+ }
104
+ ]
105
+ },
106
+ {
107
+ "anchor": "serialising-or-parsing-json",
108
+ "answers": [
109
+ {
110
+ "check": "text-past-its-reader#test-body",
111
+ "form": "serialising-or-parsing-json"
112
+ }
113
+ ]
114
+ }
115
+ ]
13
116
  }
14
117
  ```
15
118
 
16
119
  - **Method:** Assert the whole returned value with `toEqual` against a written-out literal. Read list items by bare index after an assert, never with `find`.
17
120
  - **You can tell because:** The expected value is a literal in the test.
18
121
  - **Industry name:** Literal Value (Meszaros).
122
+
123
+ ## Examples
124
+
125
+ ### Branching with if
126
+ ```ts
127
+ declare const parse: (text: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failed" };
128
+ const parsed = parse("a");
129
+ if (parsed.outcome === "ok") {
130
+ expect(parsed.value).toBe("a");
131
+ }
132
+ ```
133
+
134
+ Compare the whole result:
135
+
136
+ ```ts
137
+ declare const parse: (text: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failed" };
138
+ expect(parse("a")).toEqual({ outcome: "ok", value: "a" });
139
+ ```
140
+
141
+ ### A short-circuit
142
+ ```ts
143
+ declare const assign: (task: { readonly id: string; readonly owner?: string }) => { readonly id: string; readonly owner: string };
144
+ const task: { readonly id: string; readonly owner?: string } = { id: "a" };
145
+ expect(assign(task)).toEqual({ id: "a", owner: task.owner ?? "none" });
146
+ ```
147
+
148
+ Write the expected value out:
149
+
150
+ ```ts
151
+ declare const assign: (task: { readonly id: string; readonly owner?: string }) => { readonly id: string; readonly owner: string };
152
+ expect(assign({ id: "a" })).toEqual({ id: "a", owner: "none" });
153
+ ```
154
+
155
+ ### An optional chain after an index
156
+ ```ts
157
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
158
+ expect(listTasks()[0]?.id).toBe("a");
159
+ ```
160
+
161
+ Assert the whole array:
162
+
163
+ ```ts
164
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
165
+ expect(listTasks()).toEqual([
166
+ { id: "a", status: "open" },
167
+ { id: "b", status: "done" },
168
+ ]);
169
+ ```
170
+
171
+ Or read the element by bare index after an assert:
172
+
173
+ ```ts
174
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
175
+ const tasks = listTasks();
176
+ assert.isDefined(tasks[0]);
177
+ expect(tasks[0]).toEqual({ id: "a", status: "open" });
178
+ ```
179
+
180
+ ### A method that picks or tests an element
181
+ ```ts
182
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
183
+ expect(listTasks().find((task) => task.id === "a")).toEqual({ id: "a", status: "open" });
184
+ ```
185
+
186
+ Assert the whole array:
187
+
188
+ ```ts
189
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
190
+ expect(listTasks()).toEqual([
191
+ { id: "a", status: "open" },
192
+ { id: "b", status: "done" },
193
+ ]);
194
+ ```
195
+
196
+ Or read the element by bare index after an assert:
197
+
198
+ ```ts
199
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
200
+ const tasks = listTasks();
201
+ assert.isDefined(tasks[0]);
202
+ expect(tasks[0]).toEqual({ id: "a", status: "open" });
203
+ ```
204
+
205
+ ### A method that computes a value
206
+ ```ts
207
+ declare const idsOf: (rows: readonly { readonly id: string }[]) => readonly string[];
208
+ const rows = [{ id: "a1" }, { id: "b2" }];
209
+ expect(idsOf(rows)).toEqual(rows.map((row) => row.id));
210
+ ```
211
+
212
+ Write the expected value out:
213
+
214
+ ```ts
215
+ declare const idsOf: (rows: readonly { readonly id: string }[]) => readonly string[];
216
+ expect(idsOf([{ id: "a1" }, { id: "b2" }])).toEqual(["a1", "b2"]);
217
+ ```
218
+
219
+ ### A method that mutates
220
+ ```ts
221
+ declare const namesOf: (team: string) => readonly string[];
222
+ const expected = ["Ada"];
223
+ expected.push("Grace");
224
+ expect(namesOf("core")).toEqual(expected);
225
+ ```
226
+
227
+ Write the finished array out:
228
+
229
+ ```ts
230
+ declare const namesOf: (team: string) => readonly string[];
231
+ expect(namesOf("core")).toEqual(["Ada", "Grace"]);
232
+ ```
233
+
234
+ ### Merging objects
235
+ ```ts
236
+ declare const requestFor: (task: { readonly body: string }) => { readonly method: "POST"; readonly path: string; readonly body: string };
237
+ const base = { method: "POST", path: "/tasks" } as const;
238
+ expect(requestFor({ body: "a" })).toEqual(Object.assign({}, base, { body: "a" }));
239
+ ```
240
+
241
+ Write the whole object out:
242
+
243
+ ```ts
244
+ declare const requestFor: (task: { readonly body: string }) => { readonly method: "POST"; readonly path: string; readonly body: string };
245
+ expect(requestFor({ body: "a" })).toEqual({ method: "POST", path: "/tasks", body: "a" });
246
+ ```
247
+
248
+ ### Building an object from entries
249
+ ```ts
250
+ declare const countsOf: (words: readonly string[]) => Readonly<Record<string, number>>;
251
+ expect(countsOf(["a"])).toEqual(Object.fromEntries([["a", 1]]));
252
+ ```
253
+
254
+ Write the object out:
255
+
256
+ ```ts
257
+ declare const countsOf: (words: readonly string[]) => Readonly<Record<string, number>>;
258
+ expect(countsOf(["a"])).toEqual({ a: 1 });
259
+ ```
260
+
261
+ ### Building an array from a length
262
+ ```ts
263
+ declare const pageOf: (rows: readonly { readonly id: number }[]) => readonly { readonly id: number }[];
264
+ expect(pageOf(Array.from({ length: 3 }, (_, index) => ({ id: index })))).toHaveLength(3);
265
+ ```
266
+
267
+ Write the array out, and assert the whole array that comes back:
268
+
269
+ ```ts
270
+ declare const pageOf: (rows: readonly { readonly id: number }[]) => readonly { readonly id: number }[];
271
+ expect(pageOf([{ id: 0 }, { id: 1 }, { id: 2 }])).toEqual([{ id: 0 }, { id: 1 }, { id: 2 }]);
272
+ ```
273
+
274
+ ### A Math call
275
+ ```ts
276
+ declare const roundedOf: (amount: number) => number;
277
+ expect(roundedOf(2.5)).toBe(Math.round(2.5));
278
+ ```
279
+
280
+ Write the number out:
281
+
282
+ ```ts
283
+ declare const roundedOf: (amount: number) => number;
284
+ expect(roundedOf(2.5)).toEqual(3);
285
+ ```
286
+
287
+ ### Serialising or parsing JSON
288
+ ```ts
289
+ declare const render: (row: { readonly id: string }) => string;
290
+ expect(JSON.parse(render({ id: "a" }))).toEqual({ id: "a" });
291
+ ```
292
+
293
+ Assert the object the unit gives back, written out:
294
+
295
+ ```ts
296
+ declare const rowOf: (row: { readonly id: string }) => { readonly id: string };
297
+ expect(rowOf({ id: "a" })).toEqual({ id: "a" });
298
+ ```
@@ -2,9 +2,11 @@
2
2
 
3
3
  ```json
4
4
  {
5
- "serves": {
6
- "rule": "ports-declared-inside"
7
- },
5
+ "serves": [
6
+ {
7
+ "rule": "ports-declared-inside"
8
+ }
9
+ ],
8
10
  "standing": "accepted",
9
11
  "reason": {
10
12
  "text": "\"date creates non determinism and leaks the world in\"; \"we have a uuid factory, you should not be importing dependencies\".",
@@ -2,9 +2,14 @@
2
2
 
3
3
  ```json
4
4
  {
5
- "serves": {
6
- "principle": "no-leak-across-a-boundary"
7
- },
5
+ "serves": [
6
+ {
7
+ "principle": "no-leak-across-a-boundary"
8
+ },
9
+ {
10
+ "rule": "declared-not-asserted"
11
+ }
12
+ ],
8
13
  "standing": "accepted",
9
14
  "reason": {
10
15
  "text": "\"my insistence on not writing complex logic to parse\"; \"Hand rolled is potentially a messy and lossy option?\"; \"Zod is the wire.\"",