@hailstails/hone 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/ADOPTING.md +6 -6
  2. package/CHANGELOG.md +38 -0
  3. package/MIGRATING.md +28 -5
  4. package/README.md +41 -14
  5. package/api/audit.d.ts +1 -1
  6. package/api/testing.js +3 -3
  7. package/chunks/chunk-335ITLPO.js +7 -0
  8. package/chunks/{chunk-5VXHQC4A.js → chunk-6SM3HKWO.js} +302 -637
  9. package/chunks/{chunk-PL2PNPAR.js → chunk-E6VR3VRV.js} +1 -6
  10. package/chunks/{chunk-H4V72FCW.js → chunk-FEWCJU7H.js} +9 -1
  11. package/chunks/chunk-WF3PPYRR.js +27 -0
  12. package/core/check/tool-command.js +797 -88
  13. package/core/mechanism-port/runner-result-types.d.ts +6 -0
  14. package/docs/adding-a-discipline-or-mechanism.md +4 -4
  15. package/docs/extending.md +5 -5
  16. package/docs/output-contract.md +60 -14
  17. package/mechanisms/audit/CD-27/test-body-logic.js +394 -46
  18. package/mechanisms/audit/runner/runner.js +1 -1
  19. package/mechanisms/audit/runner/typescript-parse.d.ts +2 -0
  20. package/mechanisms/audit/runner/walker-piece.d.ts +2 -1
  21. package/mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js +7 -4
  22. package/mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js +21 -11
  23. package/mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.js +15 -5
  24. package/mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.js +7 -3
  25. package/mechanisms/eslint/CD-41/README.md +1 -1
  26. package/mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.js +100 -28
  27. package/mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.js +8 -4
  28. package/mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.js +8 -4
  29. package/mechanisms/eslint/runner/README.md +10 -3
  30. package/mechanisms/eslint/runner/runner.js +1410 -1351
  31. package/methods/lenses/di-discipline.md +4 -5
  32. package/methods/lenses/test-discipline.md +1 -1
  33. package/package.json +1 -1
  34. package/rules/CD-1/CHECKS.md +2 -0
  35. package/rules/CD-10/CHECKS.md +2 -2
  36. package/rules/CD-12/README.md +1 -1
  37. package/rules/CD-14/CHECKS.md +2 -2
  38. package/rules/CD-15/CHECKS.md +4 -2
  39. package/rules/CD-17/CHECKS.md +2 -2
  40. package/rules/CD-17/README.md +3 -3
  41. package/rules/CD-19/CHECKS.md +2 -2
  42. package/rules/CD-2/CHECKS.md +4 -2
  43. package/rules/CD-23/CHECKS.md +2 -2
  44. package/rules/CD-25/CHECKS.md +3 -3
  45. package/rules/CD-25/README.md +3 -3
  46. package/rules/CD-26/CHECKS.md +2 -2
  47. package/rules/CD-27/CHECKS.md +384 -8
  48. package/rules/CD-27/README.md +1 -1
  49. package/rules/CD-27/discipline.json +130 -0
  50. package/rules/CD-3/CHECKS.md +2 -2
  51. package/rules/CD-40/CHECKS.md +2 -2
  52. package/rules/CD-41/CHECKS.md +12 -2
  53. package/rules/CD-41/README.md +2 -0
  54. package/rules/CD-41/discipline.json +14 -0
  55. package/rules/CD-42/CHECKS.md +2 -2
  56. package/rules/CD-43/CHECKS.md +2 -2
  57. package/rules/CD-44/CHECKS.md +2 -2
  58. package/rules/CD-47/CHECKS.md +2 -2
  59. package/rules/CD-5/CHECKS.md +2 -2
  60. package/rules/CD-6/CHECKS.md +2 -2
  61. package/rules/CD-7/CHECKS.md +2 -2
  62. package/rules/CD-7a/CHECKS.md +2 -2
  63. package/rules/CD-8/CHECKS.md +2 -2
  64. package/chunks/chunk-YLZ73C7O.js +0 -0
@@ -16,16 +16,28 @@ Read [the rule and its spirit](README.md) first. This page is the mechanics: wha
16
16
  Edition 1:
17
17
  - Test files only: `*.test.ts` and `*.test.tsx`. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
18
18
  - `if` statements, `try` statements, ternary expressions and `let` declarations.
19
- - Any method call with a computing or mutating name, on any receiver: `map`, `filter`, `reduce`, `find`, `forEach`, `join`, `slice`, `split`, `replace`, `includes`, `sort`, `trim`, `keys`, `values`, `push`, `pop`, `splice`, `fill` and similar string and array methods.
19
+ - A method call with a computing or mutating name, wherever it could be the string or array method of that name: `map`, `filter`, `reduce`, `find`, `forEach`, `join`, `slice`, `split`, `replace`, `includes`, `sort`, `trim`, `keys`, `values`, `push`, `pop`, `splice`, `fill` and similar string and array methods.
20
+ - Not flagged: a call with one of those names whose arguments no string or array method of that name accepts, which makes it the unit's own API. Either it passes an object literal where none of them takes an object, such as `paths.join({ segments: ["a", "b"] })`, or it passes more arguments than any of them takes, such as `screen.keys("x", true, true)`.
21
+ - Still flagged, though they look like that:
22
+ - a call whose receiver traces back to a built-in namespace such as `Object` or `Math`, a package or `node:` module (imported, required or loaded with `import()`), or a string or array literal. The trace follows variables declared in the test file, including names destructured from a traced module or namespace, such as `posix` after `const { posix } = path`, and a property read directly off an object literal declared there, such as `deps.path` after `const deps = { path }`;
23
+ - a call that spreads its arguments;
24
+ - an object at a position where a string or array method takes one, such as `rows.includes({ id: "a" })`, `rows.push({ id: "a" })`, `rows.reduce(sum, { total: 0 })`, `rows.find(isA, {})` or `text.split({ [Symbol.split]: splitter })`.
25
+ - What this check cannot know: it reads names and syntax, not types, so it cannot tell what a receiver is.
26
+ - It flags the unit's own method given a variable, such as `repository.find(query)`.
27
+ - It misses a string or array method taken off its receiver before the call.
28
+ - It does not trace a receiver that is a function parameter, an `it.each` row, a value from another module (even a relative module that re-exports a package), a name destructured from an object literal, or a property nested deeper in one, such as `deps.nested.path`; it reads these as the unit's own.
29
+ - It releases a method of another built-in or library type that shares a name, such as a stream's `values` or `reduce`, when that call passes an object or more arguments than the string or array method takes.
30
+
31
+ Only a check that reads types knows a receiver's identity, and Hone does not have one yet.
20
32
  - Loops are not flagged here; CD-15 covers them. `throw` is CD-10.
21
33
 
22
34
  Edition 2 also flags:
23
35
  - `??`, `||` and `&&`, and their assignment forms `??=`, `||=` and `&&=`.
24
36
  - Optional chaining: `a?.b`, `a?.[key]` and `f?.()`.
25
37
  - `switch` statements.
26
- - Computing calls on a built-in namespace: `JSON.stringify`, `JSON.parse`, `Object.assign`, `Object.fromEntries`, `Array.from` and any `Math` method.
38
+ - Computing calls on a built-in namespace: `JSON.stringify`, `JSON.parse`, `Object.assign`, `Object.fromEntries`, `Array.from` and any `Math` method. A finding on `JSON.stringify` or `JSON.parse` points at [CD-19](../CD-19/README.md); see [Serialising or parsing JSON](#serialising-or-parsing-json).
27
39
 
28
- Neither edition flags element access such as `calls[0]`, calls to free functions, or a method called through a computed key, such as `rows["map"]`. Helper files that tests import are not checked; only the test files themselves are.
40
+ Neither edition flags element access such as `calls[0]`, calls to free functions, a method called through a computed key, such as `rows["map"]`, or text built with a template literal. Helper files that tests import are not checked; only the test files themselves are.
29
41
 
30
42
  ## What the ESLint check flags
31
43
  Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-27/README.md).
@@ -53,18 +65,382 @@ expect(ids).toEqual(["a1", "b2"]);
53
65
  ```
54
66
  Write the expected value out. A method call in the act step is flagged too, so move such logic into the unit under test.
55
67
 
56
- Under edition 2, write a fallback or an optional call as the value it gives:
68
+ Each finding ends with `fix:` and the page and section for what it flagged, such as `(node_modules/@hailstails/hone/rules/CD-27/CHECKS.md#an-optional-chain-after-an-index)`.
69
+
70
+ ## Allowed forms in a test
71
+ Each section shows a flagged form first, then the forms to write instead, or the rule the finding points at. Every form to write instead passes every audit and ESLint clause Hone ships, at each edition its check declares, and compiles under the compiler options CD-3 requires. A test reads this page and holds every block on it to that. `assert`, `expect`, `it` and `vi` come from `vitest`, and a `declare const` line stands for the unit under test.
72
+
73
+ ### Branching with if
74
+ ```ts
75
+ declare const parse: (text: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failed" };
76
+ const parsed = parse("a");
77
+ if (parsed.outcome === "ok") {
78
+ expect(parsed.value).toBe("a");
79
+ }
80
+ ```
81
+ Compare the whole result:
82
+
83
+ ```ts
84
+ declare const parse: (text: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failed" };
85
+ expect(parse("a")).toEqual({ outcome: "ok", value: "a" });
86
+ ```
87
+
88
+ Or write one test per case, or one table:
89
+
90
+ ```ts
91
+ declare const parse: (text: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failed" };
92
+ it.each([
93
+ { text: "a", expected: { outcome: "ok", value: "a" } },
94
+ { text: "", expected: { outcome: "failed" } },
95
+ ])("parses $text", ({ text, expected }) => {
96
+ expect(parse(text)).toEqual(expected);
97
+ });
98
+ ```
99
+
100
+ ### A try block
101
+ ```ts
102
+ declare const load: (path: string) => string;
103
+ try {
104
+ load("missing.json");
105
+ } catch (error) {
106
+ expect(error).toBeInstanceOf(Error);
107
+ }
108
+ ```
109
+ Assert the throw:
110
+
111
+ ```ts
112
+ declare const load: (path: string) => string;
113
+ expect(() => load("missing.json")).toThrow(Error);
114
+ ```
115
+
116
+ ```ts
117
+ declare const loadLater: (path: string) => Promise<string>;
118
+ it("refuses a missing file", async () => {
119
+ await expect(loadLater("missing.json")).rejects.toThrow(Error);
120
+ });
121
+ ```
122
+
123
+ ### A ternary
124
+ ```ts
125
+ declare const discountFor: (customer: { readonly tier: "premium" | "standard" }) => number;
126
+ const tier = "premium";
127
+ expect(discountFor({ tier })).toBe(tier === "premium" ? 10 : 0);
128
+ ```
129
+ Write the value out, with one table row per case:
130
+
131
+ ```ts
132
+ declare const discountFor: (customer: { readonly tier: "premium" | "standard" }) => number;
133
+ it.each([
134
+ { tier: "premium", expected: 10 },
135
+ { tier: "standard", expected: 0 },
136
+ ] as const)("gives $expected off to a $tier customer", ({ tier, expected }) => {
137
+ expect(discountFor({ tier })).toBe(expected);
138
+ });
139
+ ```
140
+
141
+ ### A let
142
+ ```ts
143
+ declare const record: (store: { readonly save: (text: string) => void }) => void;
144
+ let saved = "";
145
+ record({ save: (text) => { saved = text; } });
146
+ expect(saved).toBe("a");
147
+ ```
148
+ Record the calls with `vi.fn` and assert them:
149
+
150
+ ```ts
151
+ declare const record: (store: { readonly save: (text: string) => void }) => void;
152
+ const save = vi.fn<(text: string) => void>();
153
+ record({ save });
154
+ expect(save).toHaveBeenCalledWith("a");
155
+ ```
156
+
157
+ ### A method that picks or tests an element
158
+ ```ts
159
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
160
+ expect(listTasks().find((task) => task.id === "a")).toEqual({ id: "a", status: "open" });
161
+ ```
162
+ Assert on the whole array:
163
+
164
+ ```ts
165
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
166
+ expect(listTasks()).toContainEqual({ id: "a", status: "open" });
167
+ ```
168
+
169
+ ```ts
170
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
171
+ expect(listTasks()).toEqual(expect.arrayContaining([expect.objectContaining({ id: "a" })]));
172
+ ```
173
+
174
+ The check cannot tell the unit's own method with one of these names from an array method when it is given a variable, such as `repository.find(query)`. That is a limit of the check, described under [What the check flags](#what-the-check-flags).
175
+
176
+ ### A method that computes a value
177
+ ```ts
178
+ declare const idsOf: (rows: readonly { readonly id: string }[]) => readonly string[];
179
+ const rows = [{ id: "a1" }, { id: "b2" }];
180
+ expect(idsOf(rows)).toEqual(rows.map((row) => row.id));
181
+ ```
182
+ Write the expected value out:
183
+
184
+ ```ts
185
+ declare const idsOf: (rows: readonly { readonly id: string }[]) => readonly string[];
186
+ expect(idsOf([{ id: "a1" }, { id: "b2" }])).toEqual(["a1", "b2"]);
187
+ ```
188
+
189
+ Or match the part that matters:
190
+
191
+ ```ts
192
+ declare const receiptOf: (order: { readonly total: number }) => { readonly total: number; readonly label: string };
193
+ expect(receiptOf({ total: 30 })).toMatchObject({ label: expect.stringContaining("30") });
194
+ ```
57
195
 
196
+ ### A method that mutates
58
197
  ```ts
59
- const expected = given ?? 1;
198
+ declare const namesOf: (team: string) => readonly string[];
199
+ const expected = ["Ada"];
200
+ expected.push("Grace");
201
+ expect(namesOf("core")).toEqual(expected);
60
202
  ```
203
+ Write the finished array out:
61
204
 
62
205
  ```ts
63
- expect(given).toBe(1);
206
+ declare const namesOf: (team: string) => readonly string[];
207
+ expect(namesOf("core")).toEqual(["Ada", "Grace"]);
64
208
  ```
65
209
 
210
+ ### A short-circuit
211
+ ```ts
212
+ declare const lookup: (id: string) => { readonly name: string } | undefined;
213
+ const found = lookup("a");
214
+ expect(found !== undefined && found.name === "Ada").toBe(true);
215
+ ```
216
+ Write the value a fallback gives. To narrow a value that may be missing, assert it is defined, then read it:
217
+
218
+ ```ts
219
+ declare const lookup: (id: string) => { readonly name: string } | undefined;
220
+ const found = lookup("a");
221
+ assert.isDefined(found);
222
+ expect(found.name).toBe("Ada");
223
+ ```
224
+
225
+ ### An optional chain after an index
226
+ ```ts
227
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
228
+ expect(listTasks()[0]?.id).toBe("a");
229
+ ```
230
+ Compare the whole element:
231
+
232
+ ```ts
233
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
234
+ expect(listTasks()[0]).toMatchObject({ id: "a" });
235
+ ```
236
+
237
+ Or destructure it and assert it is defined before reading it:
238
+
239
+ ```ts
240
+ declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
241
+ const [first] = listTasks();
242
+ assert.isDefined(first);
243
+ expect(first.id).toBe("a");
244
+ ```
245
+
246
+ ### An optional chain on a mock call
247
+ ```ts
248
+ declare const start: (run: (task: { readonly id: string }) => void) => void;
249
+ const run = vi.fn<(task: { readonly id: string }) => void>();
250
+ start(run);
251
+ expect(run.mock.calls[0]?.[0].id).toBe("a");
252
+ ```
253
+ Assert that call by its position:
254
+
255
+ ```ts
256
+ declare const start: (run: (task: { readonly id: string }) => void) => void;
257
+ const run = vi.fn<(task: { readonly id: string }) => void>();
258
+ start(run);
259
+ expect(run).toHaveBeenNthCalledWith(1, expect.objectContaining({ id: "a" }));
260
+ ```
261
+
262
+ Reading `run.mock.lastCall?.[0]` names this section too. Assert the last call:
263
+
264
+ ```ts
265
+ declare const start: (run: (task: { readonly id: string }) => void) => void;
266
+ const run = vi.fn<(task: { readonly id: string }) => void>();
267
+ start(run);
268
+ expect(run).toHaveBeenLastCalledWith({ id: "a" });
269
+ ```
270
+
271
+ ### An optional chain on a mock result
272
+ ```ts
273
+ declare const pricing: { readonly priceOf: (amount: number) => number };
274
+ declare const settle: (prices: { readonly priceOf: (amount: number) => number }) => void;
275
+ const priceOf = vi.spyOn(pricing, "priceOf");
276
+ settle(pricing);
277
+ expect(priceOf.mock.results[0]?.value).toBe(4);
278
+ ```
279
+ Assert what that call returned, by its position:
280
+
281
+ ```ts
282
+ declare const pricing: { readonly priceOf: (amount: number) => number };
283
+ declare const settle: (prices: { readonly priceOf: (amount: number) => number }) => void;
284
+ const priceOf = vi.spyOn(pricing, "priceOf");
285
+ settle(pricing);
286
+ expect(priceOf).toHaveNthReturnedWith(1, 4);
287
+ ```
288
+
289
+ `toHaveLastReturnedWith` asserts what the last call returned.
290
+
291
+ An optional chain on `mock.instances` or `mock.contexts` names [An optional chain after an index](#an-optional-chain-after-an-index).
292
+
293
+ ### An optional chain on a property
294
+ ```ts
295
+ declare const findUser: (id: string) => { readonly name: string } | undefined;
296
+ expect(findUser("a")?.name).toBe("Ada");
297
+ ```
298
+ Compare the whole value:
299
+
300
+ ```ts
301
+ declare const findUser: (id: string) => { readonly name: string } | undefined;
302
+ expect(findUser("a")).toMatchObject({ name: "Ada" });
303
+ ```
304
+
305
+ Or assert it is defined before reading it:
306
+
307
+ ```ts
308
+ declare const findUser: (id: string) => { readonly name: string } | undefined;
309
+ const user = findUser("a");
310
+ assert.isDefined(user);
311
+ expect(user.name).toBe("Ada");
312
+ ```
313
+
314
+ ### An optional call
315
+ ```ts
316
+ declare const observers: { readonly enter?: (node: string) => void };
317
+ observers.enter?.("a");
318
+ ```
319
+ Destructure the function, assert it is defined, then call it:
320
+
321
+ ```ts
322
+ declare const observers: { readonly enter?: (node: string) => void };
323
+ const { enter } = observers;
324
+ assert.isDefined(enter);
325
+ enter("a");
326
+ ```
327
+
328
+ A method that reads `this` loses it once taken off its object, so assert it is defined where it is and call it there:
329
+
330
+ ```ts
331
+ declare const tracker: { readonly entered: readonly string[]; enter?(node: string): void };
332
+ assert.isDefined(tracker.enter);
333
+ tracker.enter("a");
334
+ ```
335
+
336
+ ### A switch
337
+ ```ts
338
+ declare const areaOf: (shape: { readonly kind: "square"; readonly side: number } | { readonly kind: "circle"; readonly radius: number }) => number;
339
+ const shape = { kind: "square", side: 2 } as const;
340
+ switch (shape.kind) {
341
+ case "square":
342
+ expect(areaOf(shape)).toBe(4);
343
+ }
344
+ ```
345
+ Write one test per case, or one table:
346
+
347
+ ```ts
348
+ declare const areaOf: (shape: { readonly kind: "square"; readonly side: number } | { readonly kind: "circle"; readonly radius: number }) => number;
349
+ it.each([
350
+ { shape: { kind: "square", side: 2 } as const, expected: 4 },
351
+ { shape: { kind: "circle", radius: 0 } as const, expected: 0 },
352
+ ])("measures a $shape.kind", ({ shape, expected }) => {
353
+ expect(areaOf(shape)).toBe(expected);
354
+ });
355
+ ```
356
+
357
+ ### Serialising or parsing JSON
358
+ ```ts
359
+ declare const render: (row: { readonly id: string }) => string;
360
+ expect(JSON.parse(render({ id: "a" }))).toEqual({ id: "a" });
361
+ ```
362
+ A finding on `JSON.stringify` or `JSON.parse` names this section. [CD-19](../CD-19/README.md) is the rule for the runtime's standard library.
363
+
364
+ ### Merging objects
365
+ ```ts
366
+ const base = { method: "POST", path: "/tasks" } as const;
367
+ const request = Object.assign({}, base, { body: "a" });
368
+ expect(request.body).toBe("a");
369
+ ```
370
+ Write the object out, spreading what it copies:
371
+
372
+ ```ts
373
+ const base = { method: "POST", path: "/tasks" } as const;
374
+ const request = { ...base, body: "a" };
375
+ expect(request.body).toBe("a");
376
+ ```
377
+
378
+ A spread copies an `Error`'s own properties into a plain object, which is not an `Error`. To give an `Error` a property, assign it:
379
+
380
+ ```ts
381
+ declare const reasonOf: (error: Error & { readonly code?: string }) => string;
382
+ const missing: Error & { code?: string } = new Error("ENOENT");
383
+ missing.code = "ENOENT";
384
+ expect(reasonOf(missing)).toBe("missing");
385
+ ```
386
+
387
+ ### Building an object from entries
388
+ ```ts
389
+ declare const countsOf: (words: readonly string[]) => Readonly<Record<string, number>>;
390
+ expect(countsOf(["a"])).toEqual(Object.fromEntries([["a", 1]]));
391
+ ```
392
+ Write the object out:
393
+
394
+ ```ts
395
+ declare const countsOf: (words: readonly string[]) => Readonly<Record<string, number>>;
396
+ expect(countsOf(["a"])).toEqual({ a: 1 });
397
+ ```
398
+
399
+ ### Building an array from a length
400
+ ```ts
401
+ declare const pageOf: (rows: readonly { readonly id: number }[]) => readonly { readonly id: number }[];
402
+ expect(pageOf(Array.from({ length: 3 }, (_, index) => ({ id: index })))).toHaveLength(3);
403
+ ```
404
+ Write a short array out:
405
+
406
+ ```ts
407
+ declare const pageOf: (rows: readonly { readonly id: number }[]) => readonly { readonly id: number }[];
408
+ expect(pageOf([{ id: 0 }, { id: 1 }, { id: 2 }])).toHaveLength(3);
409
+ ```
410
+
411
+ An array too long to read written out, such as one row past a page size of 1,000, has no form on this page.
412
+
413
+ ### A Math call
414
+ ```ts
415
+ declare const roundedOf: (amount: number) => number;
416
+ expect(roundedOf(2.5)).toBe(Math.round(2.5));
417
+ ```
418
+ Write the number out:
419
+
420
+ ```ts
421
+ declare const roundedOf: (amount: number) => number;
422
+ expect(roundedOf(2.5)).toBe(3);
423
+ ```
424
+
425
+ ### Logic inside a function the test passes on
426
+ ```ts
427
+ declare const isInstalled: (fileKind: { readonly kindOf: (path: string) => "file" | "missing" }) => "installed" | "missing";
428
+ const installedFiles = ["bin/hone.js"];
429
+ expect(isInstalled({ kindOf: (path) => (installedFiles.includes(path) ? "file" : "missing") })).toBe("installed");
430
+ ```
431
+ A function a test writes as a property or method of an object literal, or gives to `vi.fn` or `mockImplementation`, is passed on: to the unit, to a table row, or to a double. Any flagged construct inside it names this section. Make it a `vi.fn` spy with a written-out return, and write out what it was asked:
432
+
433
+ ```ts
434
+ declare const isInstalled: (fileKind: { readonly kindOf: (path: string) => "file" | "missing" }) => "installed" | "missing";
435
+ const kindOf = vi.fn<(path: string) => "file" | "missing">().mockReturnValue("file");
436
+ expect(isInstalled({ kindOf })).toBe("installed");
437
+ expect(kindOf).toHaveBeenCalledExactlyOnceWith("bin/hone.js");
438
+ ```
439
+
440
+ [CD-25](../CD-25/README.md) is the rule for test doubles.
441
+
66
442
  ## Exceptions
67
- Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a test file legitimately needs logic. Use `file-carve-out` for debt in one file: it is forfeited once the file is touched, and needs a `whyChain` as below. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
443
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a test file legitimately needs logic. Use `file-carve-out` for debt in one file: it is forfeited once the file is touched, and needs no `whyChain`. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
68
444
 
69
445
  ```json
70
446
  { "version": 1, "exceptions": [
@@ -72,4 +448,4 @@ Add an entry to `discipline-exceptions.json` at the repository root. Use `author
72
448
  ] }
73
449
  ```
74
450
 
75
- By default every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. A record imported from an earlier system carries `provenance` instead. With `"fileExceptionWhyChains": "optional"` in `disciplines.json`, an `authorised-location` or `file-carve-out` may give only its `reason`; a `clause-wide-carve-out` still needs its `whyChain`. [The exceptions format](../../README.md#discipline-exceptionsjson) gives each shape.
451
+ An `authorised-location` or `clause-wide-carve-out` also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. A record imported from an earlier system carries `provenance` instead. A `file-carve-out` is debt and needs only its `kind`, `clause` and `file`; its `reason` is an optional note, and a `whyChain` or `provenance` it gives anyway is still judged. With `"fileExceptionWhyChains": "optional"` in `disciplines.json`, an `authorised-location` may give only its `reason`, which will be refused in the next major release. [The exceptions format](../../README.md#discipline-exceptionsjson) gives each shape.
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Rule
4
4
 
5
- Test bodies are zero-logic straight lines: no branching, no loops, no try, no ternary, no computed expectations — just arrange, act, assert against hardcoded values. Logic in a test is untested code testing code; variability is supplied by a stub or a fake clock and pinned, never accommodated with a conditional.
5
+ Test bodies are zero-logic straight lines: no branching, no loops, no try, no ternary, no computed expectations — just arrange, act, assert against hardcoded values. Logic in a test is untested code testing code; variability is supplied by a stub and pinned, never accommodated with a conditional.
6
6
 
7
7
  Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags. What each check flags, how to fix a flagged site, and how to record an exception: [CHECKS.md](CHECKS.md). The thinking behind every rule: [the spirit of the rules](../SPIRIT.md).
8
8
 
@@ -99,6 +99,118 @@
99
99
  2
100
100
  ],
101
101
  "edition": "2"
102
+ },
103
+ {
104
+ "name": "join on node:path with several segments",
105
+ "fileName": "node-path.test.ts",
106
+ "source": "import path from \"node:path\";\nexpect(path.join(\"a\", \"b\", \"c\")).toBe(\"a/b/c\");\n",
107
+ "expectedLines": [
108
+ 2
109
+ ]
110
+ },
111
+ {
112
+ "name": "a library helper given an object",
113
+ "fileName": "library.test.ts",
114
+ "source": "import _ from \"lodash\";\nexpect(_.find([{ id: \"a\" }], { id: \"a\" }, 0, 1)).toEqual({ id: \"a\" });\n",
115
+ "expectedLines": [
116
+ 2
117
+ ]
118
+ },
119
+ {
120
+ "name": "Object.entries given an object",
121
+ "fileName": "object-entries.test.ts",
122
+ "source": "expect(Object.entries({ a: 1 })).toEqual([[\"a\", 1]]);\n",
123
+ "expectedLines": [
124
+ 1
125
+ ]
126
+ },
127
+ {
128
+ "name": "join on a dynamic import of node:path",
129
+ "fileName": "dynamic-path.test.ts",
130
+ "source": "const path = await import(\"node:path\");\nexpect(path.join(\"a\", \"b\", \"c\")).toBe(\"a/b/c\");\n",
131
+ "expectedLines": [
132
+ 2
133
+ ]
134
+ },
135
+ {
136
+ "name": "join on a required node:path",
137
+ "fileName": "required-path.test.ts",
138
+ "source": "const path = require(\"node:path\");\nexpect(path.join(\"a\", \"b\", \"c\")).toBe(\"a/b/c\");\n",
139
+ "expectedLines": [
140
+ 2
141
+ ]
142
+ },
143
+ {
144
+ "name": "join on an import-equals of node:path",
145
+ "fileName": "import-equals-path.test.ts",
146
+ "source": "import path = require(\"node:path\");\nexpect(path.join(\"a\", \"b\", \"c\")).toBe(\"a/b/c\");\n",
147
+ "expectedLines": [
148
+ 2
149
+ ]
150
+ },
151
+ {
152
+ "name": "join on a member destructured from node:path",
153
+ "fileName": "posix-path.test.ts",
154
+ "source": "import path from \"node:path\";\nconst { posix } = path;\nexpect(posix.join(\"a\", \"b\", \"c\")).toBe(\"a/b/c\");\n",
155
+ "expectedLines": [
156
+ 3
157
+ ]
158
+ },
159
+ {
160
+ "name": "join on node:path held in an object literal",
161
+ "fileName": "held-path.test.ts",
162
+ "source": "import path from \"node:path\";\nconst deps = { path };\nexpect(deps.path.join(\"a\", \"b\", \"c\")).toBe(\"a/b/c\");\n",
163
+ "expectedLines": [
164
+ 3
165
+ ]
166
+ },
167
+ {
168
+ "name": "entries on an alias of Object",
169
+ "fileName": "object-alias.test.ts",
170
+ "source": "const o = Object;\nexpect(o.entries({ a: 1 })).toEqual([[\"a\", 1]]);\n",
171
+ "expectedLines": [
172
+ 2
173
+ ]
174
+ },
175
+ {
176
+ "name": "find given an object as this",
177
+ "fileName": "find-this.test.ts",
178
+ "source": "declare const rows: readonly { readonly id: string }[];\ndeclare const isA: (row: { readonly id: string }) => boolean;\nexpect(rows.find(isA, {})).toEqual({ id: \"a\" });\n",
179
+ "expectedLines": [
180
+ 3
181
+ ]
182
+ },
183
+ {
184
+ "name": "split given a splitter object",
185
+ "fileName": "split-protocol.test.ts",
186
+ "source": "declare const text: string;\ndeclare const splitter: (text: string) => string[];\nexpect(text.split({ [Symbol.split]: splitter })).toEqual([\"a\"]);\n",
187
+ "expectedLines": [
188
+ 3
189
+ ]
190
+ },
191
+ {
192
+ "name": "includes given an object",
193
+ "fileName": "includes-object.test.ts",
194
+ "source": "const rows = [{ id: \"a\" }];\nexpect(rows.includes({ id: \"a\" })).toBe(false);\n",
195
+ "expectedLines": [
196
+ 2
197
+ ]
198
+ },
199
+ {
200
+ "name": "reduce given an object to start from",
201
+ "fileName": "reduce-object.test.ts",
202
+ "source": "declare const sum: (total: { readonly total: number }, row: number) => { readonly total: number };\nexpect([1].reduce(sum, { total: 0 })).toEqual({ total: 1 });\n",
203
+ "expectedLines": [
204
+ 2
205
+ ]
206
+ },
207
+ {
208
+ "name": "a port method given a variable",
209
+ "fileName": "port-variable.test.ts",
210
+ "source": "declare const paths: { readonly join: (request: { readonly segments: readonly string[] }) => string };\nconst request = { segments: [\"a\"] };\nexpect(paths.join(request)).toBe(\"a\");\n",
211
+ "expectedLines": [
212
+ 3
213
+ ]
102
214
  }
103
215
  ],
104
216
  "allow": [
@@ -139,6 +251,24 @@
139
251
  "source": "const calls = [[1]];\nexpect(calls[0]).toEqual([1]);\n",
140
252
  "expectedLines": [],
141
253
  "edition": "2"
254
+ },
255
+ {
256
+ "name": "the adopter's own port method given an object",
257
+ "fileName": "own-port.test.ts",
258
+ "source": "declare const paths: { readonly join: (request: { readonly segments: readonly string[] }) => string };\nexpect(paths.join({ segments: [\"a\", \"b\"] })).toBe(\"a/b\");\n",
259
+ "expectedLines": []
260
+ },
261
+ {
262
+ "name": "the adopter's own method given more arguments than any built-in of its name takes",
263
+ "fileName": "own-arity.test.ts",
264
+ "source": "declare const screen: { readonly keys: (text: string, literal: boolean, submit: boolean) => void };\nscreen.keys(\"x\", true, true);\n",
265
+ "expectedLines": []
266
+ },
267
+ {
268
+ "name": "the adopter's own port imported from a relative module",
269
+ "fileName": "own-import.test.ts",
270
+ "source": "import { paths } from \"./paths.ts\";\nexpect(paths.join({ segments: [\"a\"] })).toBe(\"a\");\n",
271
+ "expectedLines": []
142
272
  }
143
273
  ]
144
274
  }
@@ -55,7 +55,7 @@ Put the flags in a shared base file that is not named `tsconfig.json`, and leave
55
55
  ```
56
56
 
57
57
  ## Exceptions
58
- Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a package must set the flag itself. Use `file-carve-out` for debt in one file: it is forfeited once the file is touched, and needs a `whyChain` as below. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
58
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a package must set the flag itself. Use `file-carve-out` for debt in one file: it is forfeited once the file is touched, and needs no `whyChain`. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
59
59
 
60
60
  ```json
61
61
  { "version": 1, "exceptions": [
@@ -63,4 +63,4 @@ Add an entry to `discipline-exceptions.json` at the repository root. Use `author
63
63
  ] }
64
64
  ```
65
65
 
66
- By default every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. A record imported from an earlier system carries `provenance` instead. With `"fileExceptionWhyChains": "optional"` in `disciplines.json`, an `authorised-location` or `file-carve-out` may give only its `reason`; a `clause-wide-carve-out` still needs its `whyChain`. [The exceptions format](../../README.md#discipline-exceptionsjson) gives each shape.
66
+ An `authorised-location` or `clause-wide-carve-out` also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. A record imported from an earlier system carries `provenance` instead. A `file-carve-out` is debt and needs only its `kind`, `clause` and `file`; its `reason` is an optional note, and a `whyChain` or `provenance` it gives anyway is still judged. With `"fileExceptionWhyChains": "optional"` in `disciplines.json`, an `authorised-location` may give only its `reason`, which will be refused in the next major release. [The exceptions format](../../README.md#discipline-exceptionsjson) gives each shape.
@@ -28,7 +28,7 @@ const createOrder = ({ customerId, items, currency }: OrderRequest) => ({ custom
28
28
  Take one object with named fields so each call site reads as a labelled contract.
29
29
 
30
30
  ## Exceptions
31
- Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file must implement a callback signature fixed by an external library. Use `file-carve-out` for debt in one file: it is forfeited once the file is touched, and needs a `whyChain` as below. Judgement clauses cannot be selected and need no exception record. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
31
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file must implement a callback signature fixed by an external library. Use `file-carve-out` for debt in one file: it is forfeited once the file is touched, and needs no `whyChain`. Judgement clauses cannot be selected and need no exception record. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
32
32
 
33
33
  ```json
34
34
  { "version": 1, "exceptions": [
@@ -36,4 +36,4 @@ Add an entry to `discipline-exceptions.json` at the repository root. Use `author
36
36
  ] }
37
37
  ```
38
38
 
39
- By default every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. A record imported from an earlier system carries `provenance` instead. With `"fileExceptionWhyChains": "optional"` in `disciplines.json`, an `authorised-location` or `file-carve-out` may give only its `reason`; a `clause-wide-carve-out` still needs its `whyChain`. [The exceptions format](../../README.md#discipline-exceptionsjson) gives each shape.
39
+ An `authorised-location` or `clause-wide-carve-out` also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. A record imported from an earlier system carries `provenance` instead. A `file-carve-out` is debt and needs only its `kind`, `clause` and `file`; its `reason` is an optional note, and a `whyChain` or `provenance` it gives anyway is still judged. With `"fileExceptionWhyChains": "optional"` in `disciplines.json`, an `authorised-location` may give only its `reason`, which will be refused in the next major release. [The exceptions format](../../README.md#discipline-exceptionsjson) gives each shape.
@@ -19,6 +19,16 @@ Read [the rule and its spirit](README.md) first. This page is the mechanics: wha
19
19
  - A nested function is scored on its own, starting one level deeper, and its score is not added to its parent.
20
20
  - Reported at the function's name.
21
21
  - `hone-cd41/function-length`: a function body may span at most 50 lines. Blank and comment lines count; lines holding only `{` or `}` do not. Getters and setters are not checked. Reported at the function.
22
+ - A test suite's body is not checked. A suite body is a function passed as an argument to the call that runs a suite:
23
+ - `describe`, `suite`, `fdescribe`, `xdescribe`, `fsuite` or `xsuite`, alone or followed only by the modifiers `each`, `for`, `only`, `skip`, `todo`, `concurrent`, `sequential`, `shuffle`, `skipIf` and `runIf`, such as `describe.each(table)(name, fn)`, `describe.each` with a template table, `describe.only.each(table)(name, fn)` or `describe.skipIf(condition)(name, fn)`;
24
+ - Playwright's `test.describe`, alone or followed only by `only`, `skip`, `fixme`, `serial` and `parallel`, such as `test.describe.serial.only(name, fn)`.
25
+ - A suite nested in a suite is not checked either.
26
+ - Everything else is checked as any function is:
27
+ - each function inside a suite's body: each `it` and `test` callback, each hook and each helper declared there;
28
+ - a function given to `describe.each` as a table entry;
29
+ - a callback on any other member of those names, such as `test.describe.configure(fn)` or `suite.add(name, fn)` on a benchmark suite;
30
+ - mocha's `context`, and any other suite function not listed above.
31
+ - The check matches names, not bindings, so a local function of the repository's own named `describe` or `suite` is treated as a suite when called that way.
22
32
  - `orchestration-only` is a judgement clause. It cannot be selected and is enforced by review.
23
33
 
24
34
  ## Example violation
@@ -43,7 +53,7 @@ const settle = (orders: Order[]) => orders.filter(isPaid).forEach(refundEligible
43
53
  Move each branch into a named helper so the orchestrator only composes calls.
44
54
 
45
55
  ## Exceptions
46
- Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file holds a function whose shape is fixed by an external contract. Use `file-carve-out` for debt in one file: it is forfeited once the file is touched, and needs a `whyChain` as below. Judgement clauses cannot be selected and need no exception record. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
56
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file holds a function whose shape is fixed by an external contract. Use `file-carve-out` for debt in one file: it is forfeited once the file is touched, and needs no `whyChain`. Judgement clauses cannot be selected and need no exception record. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
47
57
 
48
58
  ```json
49
59
  { "version": 1, "exceptions": [
@@ -51,4 +61,4 @@ Add an entry to `discipline-exceptions.json` at the repository root. Use `author
51
61
  ] }
52
62
  ```
53
63
 
54
- By default every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. A record imported from an earlier system carries `provenance` instead. With `"fileExceptionWhyChains": "optional"` in `disciplines.json`, an `authorised-location` or `file-carve-out` may give only its `reason`; a `clause-wide-carve-out` still needs its `whyChain`. [The exceptions format](../../README.md#discipline-exceptionsjson) gives each shape.
64
+ An `authorised-location` or `clause-wide-carve-out` also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. A record imported from an earlier system carries `provenance` instead. A `file-carve-out` is debt and needs only its `kind`, `clause` and `file`; its `reason` is an optional note, and a `whyChain` or `provenance` it gives anyway is still judged. With `"fileExceptionWhyChains": "optional"` in `disciplines.json`, an `authorised-location` may give only its `reason`, which will be refused in the next major release. [The exceptions format](../../README.md#discipline-exceptionsjson) gives each shape.
@@ -16,6 +16,8 @@ Review lens: [decomposition](../../methods/lenses/decomposition.md). The lens re
16
16
  - *Failures checked inline.* Nesting deepens because each failure is handled in place. Return early on failure, or let helpers return results the coordinator only routes.
17
17
  - *Shapes that do not meet.* The coordinator reshapes data between calls because its helpers disagree. Align the helpers' inputs and outputs.
18
18
 
19
+ **What a finding does not point at.** A test suite's `describe` body is a list of cases, not a coordinator, so its length is not a finding. Splitting a suite only to shorten it adds nothing. The tests and helpers inside it are still functions, and each is judged on its own.
20
+
19
21
  **Where to go.** Coordinators read as a short list of named steps. Each helper does one thing at one level of detail.
20
22
 
21
23
  **Reactions to distrust.**