@hailstails/hone 0.1.0-pre.4 → 0.1.0-pre.6

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 (150) hide show
  1. package/ADOPTING.md +172 -38
  2. package/MIGRATING.md +58 -7
  3. package/README.md +117 -35
  4. package/THIRD-PARTY-NOTICES.md +1 -1
  5. package/api/audit.d.ts +3 -2
  6. package/api/rule-set.d.ts +2 -4
  7. package/chunks/chunk-3HFJHJDO.js +53 -0
  8. package/chunks/chunk-5LCLBXP7.js +76 -0
  9. package/chunks/{chunk-BX6QHLSZ.js → chunk-ET5EBSJX.js} +61 -6
  10. package/chunks/chunk-LDQUT742.js +15 -0
  11. package/chunks/{chunk-RZA3OVOO.js → chunk-LOYT2AGY.js} +10 -9
  12. package/chunks/chunk-MVK5KFJI.js +421 -0
  13. package/chunks/{chunk-FOAGAYXM.js → chunk-NCDYOPHG.js} +7224 -2361
  14. package/chunks/chunk-WPRR2MPJ.js +22 -0
  15. package/chunks/{chunk-EYCRDEXX.js → chunk-XB4PCY3Q.js} +2 -13
  16. package/core/check/tool-command.js +1130 -230
  17. package/core/mechanism-port/piece-failure-types.d.ts +14 -0
  18. package/core/mechanism-port/runner-module-types.d.ts +5 -0
  19. package/core/rule-set-reader/authored-rule-set-types.d.ts +48 -0
  20. package/core/values/json-value.d.ts +3 -0
  21. package/docs/adding-a-discipline-or-mechanism.md +29 -13
  22. package/docs/extending.md +358 -0
  23. package/docs/output-contract.md +326 -0
  24. package/mechanisms/audit/CD-1/any-cast.js +9 -37
  25. package/mechanisms/audit/CD-19/import-boundaries.js +79 -68
  26. package/mechanisms/audit/CD-19/piece.json +5 -0
  27. package/mechanisms/audit/CD-2/cast-expressions.js +14 -37
  28. package/mechanisms/audit/CD-2/piece.json +6 -1
  29. package/mechanisms/audit/CD-5/comments-directives.js +121 -55
  30. package/mechanisms/audit/CD-5/piece.json +7 -0
  31. package/mechanisms/audit/runner/README.md +4 -2
  32. package/mechanisms/audit/runner/runner.js +102 -36
  33. package/mechanisms/audit/runner/typescript-parse.d.ts +6 -0
  34. package/mechanisms/audit/runner/walker-piece.d.ts +5 -5
  35. package/mechanisms/eslint/CD-2/README.md +12 -0
  36. package/mechanisms/eslint/CD-2/cd2/cd2.eslint-plugin.js +16 -0
  37. package/mechanisms/eslint/CD-2/piece.json +25 -0
  38. package/mechanisms/eslint/runner/README.md +12 -5
  39. package/mechanisms/eslint/runner/runner.js +940 -232
  40. package/methods/README.md +2 -0
  41. package/methods/assessment-template.md +35 -0
  42. package/methods/lenses/clean-architecture.md +2 -2
  43. package/methods/lenses/decomposition.md +2 -2
  44. package/methods/lenses/defended-on-intent.md +7 -7
  45. package/methods/lenses/di-discipline.md +38 -26
  46. package/methods/lenses/errors-as-data.md +2 -2
  47. package/methods/lenses/function-first.md +2 -2
  48. package/methods/lenses/naming.md +2 -2
  49. package/methods/lenses/test-discipline.md +15 -13
  50. package/methods/lenses/type-soundness.md +2 -2
  51. package/methods/lenses/zod-boundary.md +2 -2
  52. package/package.json +5 -4
  53. package/rules/CD-1/CHECKS.md +37 -0
  54. package/rules/CD-1/README.md +17 -32
  55. package/rules/CD-1/discipline.json +16 -6
  56. package/rules/CD-10/CHECKS.md +49 -0
  57. package/rules/CD-10/README.md +21 -49
  58. package/rules/CD-11/CHECKS.md +13 -0
  59. package/rules/CD-11/README.md +14 -8
  60. package/rules/CD-12/CHECKS.md +13 -0
  61. package/rules/CD-12/README.md +14 -8
  62. package/rules/CD-13/CHECKS.md +13 -0
  63. package/rules/CD-13/README.md +14 -8
  64. package/rules/CD-14/CHECKS.md +49 -0
  65. package/rules/CD-14/README.md +22 -48
  66. package/rules/CD-15/CHECKS.md +40 -0
  67. package/rules/CD-15/README.md +22 -40
  68. package/rules/CD-16/CHECKS.md +7 -0
  69. package/rules/CD-16/README.md +3 -5
  70. package/rules/CD-17/CHECKS.md +37 -0
  71. package/rules/CD-17/README.md +17 -31
  72. package/rules/CD-18/CHECKS.md +13 -0
  73. package/rules/CD-18/README.md +15 -9
  74. package/rules/CD-19/CHECKS.md +49 -0
  75. package/rules/CD-19/README.md +18 -34
  76. package/rules/CD-19/discipline.json +6 -8
  77. package/rules/CD-2/CHECKS.md +56 -0
  78. package/rules/CD-2/README.md +19 -32
  79. package/rules/CD-2/discipline.json +93 -7
  80. package/rules/CD-20/CHECKS.md +7 -0
  81. package/rules/CD-20/README.md +3 -5
  82. package/rules/CD-21/CHECKS.md +13 -0
  83. package/rules/CD-21/README.md +14 -9
  84. package/rules/CD-22/CHECKS.md +13 -0
  85. package/rules/CD-22/README.md +13 -8
  86. package/rules/CD-23/CHECKS.md +35 -0
  87. package/rules/CD-23/README.md +14 -29
  88. package/rules/CD-24/CHECKS.md +7 -0
  89. package/rules/CD-24/README.md +3 -5
  90. package/rules/CD-25/CHECKS.md +38 -0
  91. package/rules/CD-25/README.md +20 -32
  92. package/rules/CD-26/CHECKS.md +36 -0
  93. package/rules/CD-26/README.md +18 -31
  94. package/rules/CD-27/CHECKS.md +45 -0
  95. package/rules/CD-27/README.md +18 -40
  96. package/rules/CD-28/CHECKS.md +13 -0
  97. package/rules/CD-28/README.md +14 -8
  98. package/rules/CD-29/CHECKS.md +13 -0
  99. package/rules/CD-29/README.md +12 -8
  100. package/rules/CD-3/CHECKS.md +42 -0
  101. package/rules/CD-3/README.md +20 -42
  102. package/rules/CD-30/CHECKS.md +13 -0
  103. package/rules/CD-30/README.md +13 -8
  104. package/rules/CD-31/CHECKS.md +13 -0
  105. package/rules/CD-31/README.md +12 -8
  106. package/rules/CD-32/CHECKS.md +13 -0
  107. package/rules/CD-32/README.md +13 -8
  108. package/rules/CD-33/CHECKS.md +13 -0
  109. package/rules/CD-33/README.md +13 -8
  110. package/rules/CD-34/CHECKS.md +13 -0
  111. package/rules/CD-34/README.md +12 -8
  112. package/rules/CD-39/CHECKS.md +13 -0
  113. package/rules/CD-39/README.md +13 -8
  114. package/rules/CD-4/CHECKS.md +13 -0
  115. package/rules/CD-4/README.md +15 -8
  116. package/rules/CD-40/CHECKS.md +39 -0
  117. package/rules/CD-40/README.md +17 -33
  118. package/rules/CD-41/CHECKS.md +54 -0
  119. package/rules/CD-41/README.md +23 -54
  120. package/rules/CD-42/CHECKS.md +47 -0
  121. package/rules/CD-42/README.md +19 -47
  122. package/rules/CD-43/CHECKS.md +37 -0
  123. package/rules/CD-43/README.md +15 -31
  124. package/rules/CD-44/CHECKS.md +48 -0
  125. package/rules/CD-44/README.md +20 -48
  126. package/rules/CD-45/CHECKS.md +13 -0
  127. package/rules/CD-45/README.md +14 -8
  128. package/rules/CD-46/CHECKS.md +7 -0
  129. package/rules/CD-46/README.md +16 -4
  130. package/rules/CD-47/CHECKS.md +37 -0
  131. package/rules/CD-47/README.md +16 -32
  132. package/rules/CD-5/CHECKS.md +52 -0
  133. package/rules/CD-5/README.md +22 -40
  134. package/rules/CD-5/discipline.json +66 -0
  135. package/rules/CD-6/CHECKS.md +51 -0
  136. package/rules/CD-6/README.md +22 -51
  137. package/rules/CD-7/CHECKS.md +46 -0
  138. package/rules/CD-7/README.md +23 -46
  139. package/rules/CD-7a/CHECKS.md +38 -0
  140. package/rules/CD-7a/README.md +14 -32
  141. package/rules/CD-8/CHECKS.md +42 -0
  142. package/rules/CD-8/README.md +20 -42
  143. package/rules/CD-9/CHECKS.md +13 -0
  144. package/rules/CD-9/README.md +15 -8
  145. package/rules/README.md +5 -3
  146. package/rules/SPIRIT.md +50 -0
  147. package/core/mechanism-port/runner-failure-types.d.ts +0 -38
  148. package/core/rule-set-reader/rule-set-types.d.ts +0 -41
  149. /package/api/{audit.js → audit.mjs} +0 -0
  150. /package/api/{rule-set.js → rule-set.mjs} +0 -0
@@ -4,57 +4,26 @@
4
4
 
5
5
  An orchestrator's body composes helper calls and assembles their results — nothing else. Inline branching or computation inside an orchestrator mixes two altitudes: the coordination it owns and the logic that belongs in a named helper. Keep orchestrators pure coordination so each level reads at one altitude.
6
6
 
7
- The sections below describe what the ESLint check covers.
8
-
9
- ## Clauses
10
-
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-41#cognitive-complexity` | eslint | a function whose cognitive complexity is above 15 |
14
- | `CD-41#function-length` | eslint | a function body longer than 50 lines |
15
- | `CD-41#orchestration-only` | review | an orchestrator only composes helper calls and assembles their results |
16
-
17
- Review lens: [decomposition](../../methods/lenses/decomposition.md). The lens reviews the whole rule, including what no check flags.
18
-
19
- ## What the check flags
20
- - The ESLint piece lints whatever files the team's ESLint run includes. It needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-41/README.md).
21
- - `hone-cd41/cognitive-complexity`: each function's cognitive complexity must be at most 15.
22
- - An `if`, `else if`, `switch`, ternary, `catch` and each loop adds 1 plus the current nesting depth.
23
- - An `else`, a `finally`, a labelled `break` or `continue`, and each run of the same logical operator add 1.
24
- - Nesting deepens inside `if`, loops, `switch`, `catch` and ternaries.
25
- - A nested function is scored on its own, starting one level deeper, and its score is not added to its parent.
26
- - Reported at the function's name.
27
- - `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.
28
- - `orchestration-only` is a judgement clause. It cannot be selected and is enforced by review.
29
-
30
- ## Example violation
31
- ```ts
32
- const settle = (orders: Order[]) => {
33
- for (const order of orders) {
34
- if (order.paid) {
35
- for (const line of order.lines) {
36
- if (line.refundable && line.quantity > 0) {
37
- refund(line);
38
- }
39
- }
40
- }
41
- }
42
- };
43
- ```
44
-
45
- ## How to fix
46
- ```ts
47
- const settle = (orders: Order[]) => orders.filter(isPaid).forEach(refundEligibleLines);
48
- ```
49
- Move each branch into a named helper so the orchestrator only composes calls.
50
-
51
- ## Exceptions
52
- 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 needs a `whyChain` and is forfeited once the file is touched. Judgement clauses cannot be selected and need no exception record. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
53
-
54
- ```json
55
- { "version": 1, "exceptions": [
56
- { "kind": "authorised-location", "clause": "CD-41#cognitive-complexity", "file": "src/legacy/tax-engine.ts", "reason": "..." }
57
- ] }
58
- ```
59
-
60
- 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`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
7
+ Review lens: [decomposition](../../methods/lenses/decomposition.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
+
9
+ ## Spirit
10
+
11
+ **What the friction is for.** A function that coordinates and computes at once has to be read at two levels of detail at once. The friction makes small named steps the easy shape, so each level reads as one idea.
12
+
13
+ **What a finding points at.** Match the sites against these causes.
14
+ - *Logic that never got a name.* A block of branching or computation sits inside a coordinator. Extract it into a named helper; the name says what it decides.
15
+ - *One function with several jobs.* It validates, decides and performs, so it grows long and tangled. Split it by job.
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
+ - *Shapes that do not meet.* The coordinator reshapes data between calls because its helpers disagree. Align the helpers' inputs and outputs.
18
+
19
+ **Where to go.** Coordinators read as a short list of named steps. Each helper does one thing at one level of detail.
20
+
21
+ **Reactions to distrust.**
22
+ - "It's only a little logic." A little logic in a coordinator is still a second level of detail to read. Give it a name.
23
+ - "Splitting makes it harder to follow." Named steps read faster than inline logic once the names are honest.
24
+ - "This branch is just plumbing." If it decides anything, it is logic. Name what it decides.
25
+
26
+ **Principles behind it.**
27
+ - *Composed Method* (Kent Beck, *Smalltalk Best Practice Patterns*). A method is a sequence of calls to other methods, all at the same level of abstraction.
28
+ - *One level of abstraction per function* (Robert C. Martin, *Clean Code*). Mixing coordination with detail forces the reader to switch levels mid-function.
29
+ - *Functions should do one thing* (Robert C. Martin, *Clean Code*). A coordinator's one thing is coordinating; computing is a second thing.
@@ -0,0 +1,47 @@
1
+ # CD-42 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: how the rule is checked, and how to record an exception where the rule allows one.
4
+
5
+ ## Clauses
6
+
7
+ | Clause | Mechanism | Checks |
8
+ | --- | --- | --- |
9
+ | `CD-42#useless-else` | eslint | an `else` after an `if` branch that always exits |
10
+
11
+ ## What the check flags
12
+ - The ESLint piece lints whatever files the team's ESLint run includes. It needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-42/README.md).
13
+ - Rule `hone-cd42/useless-else`: an `else` after an `if` branch that always exits is reported at the `else` keyword.
14
+ - A branch always exits when it ends in `return`, `throw`, `continue`, or `break` outside a switch. A nested `if` exits when both of its branches do. A `switch` exits when every non-empty case does.
15
+ - Along an `else if` chain whose earlier branches all exit, every `else` is reported.
16
+ - Allowed: an `else` after a branch that can fall through.
17
+
18
+ ## Example violation
19
+ ```ts
20
+ const label = (order: Order) => {
21
+ if (order.cancelled) {
22
+ return "cancelled";
23
+ } else {
24
+ return "active";
25
+ }
26
+ };
27
+ ```
28
+
29
+ ## How to fix
30
+ ```ts
31
+ const label = (order: Order) => {
32
+ if (order.cancelled) return "cancelled";
33
+ return "active";
34
+ };
35
+ ```
36
+ Handle the unhappy path first with an early return and leave the happy path as the final return.
37
+
38
+ ## Exceptions
39
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file must keep an else for an external reason. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. Judgement clauses cannot be selected and need no exception record. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
40
+
41
+ ```json
42
+ { "version": 1, "exceptions": [
43
+ { "kind": "authorised-location", "clause": "CD-42#useless-else", "file": "src/legacy/status.ts", "reason": "..." }
44
+ ] }
45
+ ```
46
+
47
+ 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`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
@@ -4,50 +4,22 @@
4
4
 
5
5
  Unhappy paths are handled first as guard clauses that return early; the happy path is the final, un-nested return at the bottom. There is no `else` after an early return. Guarding first keeps the main path flat and readable, instead of burying it inside nested conditionals.
6
6
 
7
- The sections below describe what the ESLint check covers.
8
-
9
- ## Clauses
10
-
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-42#useless-else` | eslint | an `else` after an `if` branch that always exits |
14
-
15
- Review lens: [decomposition](../../methods/lenses/decomposition.md). The lens reviews the whole rule, including what no check flags.
16
-
17
- ## What the check flags
18
- - The ESLint piece lints whatever files the team's ESLint run includes. It needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-42/README.md).
19
- - Rule `hone-cd42/useless-else`: an `else` after an `if` branch that always exits is reported at the `else` keyword.
20
- - A branch always exits when it ends in `return`, `throw`, `continue`, or `break` outside a switch. A nested `if` exits when both of its branches do. A `switch` exits when every non-empty case does.
21
- - Along an `else if` chain whose earlier branches all exit, every `else` is reported.
22
- - Allowed: an `else` after a branch that can fall through.
23
-
24
- ## Example violation
25
- ```ts
26
- const label = (order: Order) => {
27
- if (order.cancelled) {
28
- return "cancelled";
29
- } else {
30
- return "active";
31
- }
32
- };
33
- ```
34
-
35
- ## How to fix
36
- ```ts
37
- const label = (order: Order) => {
38
- if (order.cancelled) return "cancelled";
39
- return "active";
40
- };
41
- ```
42
- Handle the unhappy path first with an early return and leave the happy path as the final return.
43
-
44
- ## Exceptions
45
- Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file must keep an else for an external reason. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. Judgement clauses cannot be selected and need no exception record. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
46
-
47
- ```json
48
- { "version": 1, "exceptions": [
49
- { "kind": "authorised-location", "clause": "CD-42#useless-else", "file": "src/legacy/status.ts", "reason": "..." }
50
- ] }
51
- ```
52
-
53
- 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`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
7
+ Review lens: [decomposition](../../methods/lenses/decomposition.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
+
9
+ ## Spirit
10
+
11
+ **What the friction is for.** Nested conditions bury the main path. The friction makes "handle the failures first, then do the work" the easy shape, so the main path reads flat at the bottom.
12
+
13
+ **What a finding points at.** Match the sites against these causes.
14
+ - *Failures handled after success.* The happy path sits inside an if and the failure in the else. Invert it: return early on failure.
15
+ - *Several checks nested inside each other.* Each guard adds a level. Make each a separate early return.
16
+ - *A function with two jobs.* Both branches do real work. Split it into two functions.
17
+
18
+ **Where to go.** Guards at the top, each returning early. The final return is the happy path, with no else.
19
+
20
+ **Reactions to distrust.**
21
+ - "Single exit is cleaner." It forces nesting and a variable to carry the answer. Early returns keep each case in one place.
22
+ - "The else makes it explicit." After a return, the else adds only indentation.
23
+
24
+ **Principles behind it.**
25
+ - *Replace Nested Conditional with Guard Clauses* (Martin Fowler, *Refactoring*). Unusual cases leave early; the normal case reads straight down.
@@ -0,0 +1,37 @@
1
+ # CD-43 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: how the rule is checked, and how to record an exception where the rule allows one.
4
+
5
+ ## Clauses
6
+
7
+ | Clause | Mechanism | Checks |
8
+ | --- | --- | --- |
9
+ | `CD-43#boolean-signatures` | audit | a boolean type in a parameter, property signature or return |
10
+
11
+ ## What the check flags
12
+ - `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
13
+ - A declared type of `boolean`, or `boolean` unioned only with `null` and `undefined`, on a parameter, an interface or type-literal property, a function, method, arrow or accessor return, or a function, call or index signature.
14
+ - Allowed: `true` or `false` literals, `boolean | string`, aliases of boolean, type predicates such as `value is Item`, inferred types, variables and class fields.
15
+ - All boolean signatures are reported, including predicates such as `isReady(): boolean`. Telling evaluative booleans from state is left to review.
16
+
17
+ ## Example violation
18
+ ```ts
19
+ const render = (compact: boolean): string => "";
20
+ ```
21
+
22
+ ## How to fix
23
+ ```ts
24
+ const render = (mode: "compact" | "full"): string => "";
25
+ ```
26
+ Name each state in the type.
27
+
28
+ ## Exceptions
29
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file must follow an external interface that uses a boolean. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
30
+
31
+ ```json
32
+ { "version": 1, "exceptions": [
33
+ { "kind": "authorised-location", "clause": "CD-43#boolean-signatures", "file": "src/adapters/vendor-flags.ts", "reason": "..." }
34
+ ] }
35
+ ```
36
+
37
+ 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`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
@@ -4,40 +4,24 @@
4
4
 
5
5
  A boolean parameter, field, or return is an evaluative predicate the reader must decode at every call site — `true` for what? Prefer a string-literal or discriminated union that states the meaning in the value itself. Booleans that name a state or mode hide that meaning behind a bare truth value.
6
6
 
7
- The sections below describe what the audit check covers.
7
+ Review lens: [type-soundness](../../methods/lenses/type-soundness.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
 
9
- ## Clauses
9
+ ## Spirit
10
10
 
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-43#boolean-signatures` | audit | a boolean type in a parameter, property signature or return |
11
+ **What the friction is for.** A bare true or false says nothing about what it means. The friction makes naming the state the easy path, so a call site reads as what it does.
14
12
 
15
- Review lens: [type-soundness](../../methods/lenses/type-soundness.md). The lens reviews the whole rule, including what no check flags.
13
+ **What a finding points at.** Match the sites against these causes.
14
+ - *A mode passed as a flag.* A parameter switches the function between behaviours. Split the function, or name the modes as a union.
15
+ - *A state that will grow.* Today it is on or off; tomorrow there is a third case and a second flag. Name the states now.
16
+ - *Two flags that cannot both be true.* Pairs of booleans allow combinations that make no sense. One union rules them out.
17
+ - *An outcome as a boolean.* A result says success or not, and the reason is lost. Return a tagged outcome.
16
18
 
17
- ## What the check flags
18
- - `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
19
- - A declared type of `boolean`, or `boolean` unioned only with `null` and `undefined`, on a parameter, an interface or type-literal property, a function, method, arrow or accessor return, or a function, call or index signature.
20
- - Allowed: `true` or `false` literals, `boolean | string`, aliases of boolean, type predicates such as `value is Item`, inferred types, variables and class fields.
21
- - All boolean signatures are reported, including predicates such as `isReady(): boolean`. Telling evaluative booleans from state is left to review.
19
+ **Where to go.** States and modes are named values. A reader learns the meaning from the value itself.
22
20
 
23
- ## Example violation
24
- ```ts
25
- const render = (compact: boolean): string => "";
26
- ```
21
+ **Reactions to distrust.**
22
+ - "It's obviously a yes or no." Then name what yes means. If that is easy, the union is easy.
23
+ - "The library returns a boolean." Read it at the boundary and turn it into your own named state there.
27
24
 
28
- ## How to fix
29
- ```ts
30
- const render = (mode: "compact" | "full"): string => "";
31
- ```
32
- Name each state in the type.
33
-
34
- ## Exceptions
35
- Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file must follow an external interface that uses a boolean. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
36
-
37
- ```json
38
- { "version": 1, "exceptions": [
39
- { "kind": "authorised-location", "clause": "CD-43#boolean-signatures", "file": "src/adapters/vendor-flags.ts", "reason": "..." }
40
- ] }
41
- ```
42
-
43
- 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`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
25
+ **Principles behind it.**
26
+ - *Make illegal states unrepresentable* (Yaron Minsky). A union of named states rules out the combinations flags allow.
27
+ - *Flag arguments* (Robert C. Martin, *Clean Code*). A boolean argument announces that the function does more than one thing.
@@ -0,0 +1,48 @@
1
+ # CD-44 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: how the rule is checked, and how to record an exception where the rule allows one.
4
+
5
+ ## Clauses
6
+
7
+ | Clause | Mechanism | Checks |
8
+ | --- | --- | --- |
9
+ | `CD-44#parameter-mutation` | audit | assignment to, deletion from or in-place methods on a parameter's fields |
10
+ | `CD-44#parameter-reassignment` | eslint | assigning to, incrementing or destructuring into a parameter itself |
11
+
12
+ ## What the check flags
13
+ - `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
14
+ - Inside a function declaration, function expression, arrow function or method, where the root name is one of its parameters (including destructured and outer-function parameters):
15
+ - `parameter.field = value` and `parameter.a[0].b = value`
16
+ - `delete parameter.field`
17
+ - `parameter.push(...)`, `pop`, `shift`, `unshift`, `splice`, `sort`, `reverse`, `fill`, `copyWithin`
18
+ - Not detected: reassigning the parameter, `+=` and `++`, `Map.set`, and mutation through an alias (`const copy = input; copy.x = 1`).
19
+
20
+ ## What the ESLint check flags
21
+ Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-44/README.md).
22
+ - `hone-cd44/no-param-reassign` is ESLint's `no-param-reassign` with `{ "props": false }`.
23
+ - It flags assigning to a parameter, incrementing or decrementing it, and destructuring-assigning into it.
24
+ - A parameter's fields are not checked here; the audit's `parameter-mutation` clause covers them.
25
+
26
+ ## Example violation
27
+ ```ts
28
+ const addTotal = (order: Order) => {
29
+ order.total = 10;
30
+ };
31
+ ```
32
+
33
+ ## How to fix
34
+ ```ts
35
+ const withTotal = (order: Order): Order => ({ ...order, total: 10 });
36
+ ```
37
+ Copy before sorting or reversing: `[...items].sort()`.
38
+
39
+ ## Exceptions
40
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file must fill an output object supplied by an external API. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
41
+
42
+ ```json
43
+ { "version": 1, "exceptions": [
44
+ { "kind": "authorised-location", "clause": "CD-44#parameter-mutation", "file": "src/adapters/legacy-writer.ts", "reason": "..." }
45
+ ] }
46
+ ```
47
+
48
+ 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`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
@@ -4,51 +4,23 @@
4
4
 
5
5
  A function never mutates the fields of the parameters it receives — no assigning to a parameter's property, no pushing into a parameter's array, no sorting it in place. It returns new data instead. Mutating an input makes the function's effect invisible at the call site and couples the caller to an order of operations it cannot see.
6
6
 
7
- The sections below describe what the audit and ESLint checks cover.
8
-
9
- ## Clauses
10
-
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-44#parameter-mutation` | audit | assignment to, deletion from or in-place methods on a parameter's fields |
14
- | `CD-44#parameter-reassignment` | eslint | assigning to, incrementing or destructuring into a parameter itself |
15
-
16
- Review lens: [decomposition](../../methods/lenses/decomposition.md). The lens reviews the whole rule, including what no check flags.
17
-
18
- ## What the check flags
19
- - `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
20
- - Inside a function declaration, function expression, arrow function or method, where the root name is one of its parameters (including destructured and outer-function parameters):
21
- - `parameter.field = value` and `parameter.a[0].b = value`
22
- - `delete parameter.field`
23
- - `parameter.push(...)`, `pop`, `shift`, `unshift`, `splice`, `sort`, `reverse`, `fill`, `copyWithin`
24
- - Not detected: reassigning the parameter, `+=` and `++`, `Map.set`, and mutation through an alias (`const copy = input; copy.x = 1`).
25
-
26
- ## What the ESLint check flags
27
- Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-44/README.md).
28
- - `hone-cd44/no-param-reassign` is ESLint's `no-param-reassign` with `{ "props": false }`.
29
- - It flags assigning to a parameter, incrementing or decrementing it, and destructuring-assigning into it.
30
- - A parameter's fields are not checked here; the audit's `parameter-mutation` clause covers them.
31
-
32
- ## Example violation
33
- ```ts
34
- const addTotal = (order: Order) => {
35
- order.total = 10;
36
- };
37
- ```
38
-
39
- ## How to fix
40
- ```ts
41
- const withTotal = (order: Order): Order => ({ ...order, total: 10 });
42
- ```
43
- Copy before sorting or reversing: `[...items].sort()`.
44
-
45
- ## Exceptions
46
- Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file must fill an output object supplied by an external API. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
47
-
48
- ```json
49
- { "version": 1, "exceptions": [
50
- { "kind": "authorised-location", "clause": "CD-44#parameter-mutation", "file": "src/adapters/legacy-writer.ts", "reason": "..." }
51
- ] }
52
- ```
53
-
54
- 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`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
7
+ Review lens: [decomposition](../../methods/lenses/decomposition.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
+
9
+ ## Spirit
10
+
11
+ **What the friction is for.** A function that changes its inputs has an effect the call site cannot see. The friction makes returning new data the easy path, so every change is visible where it is used.
12
+
13
+ **What a finding points at.** Match the sites against these causes.
14
+ - *A function that both answers and changes.* It returns something and also edits what it was given. Return the new value; leave the input alone.
15
+ - *Ownership nobody decided.* Several functions edit one shared object in turn. Decide who builds the value, and pass results forward instead.
16
+ - *In-place sorting or pushing for convenience.* A library call mutates by default. Use the copying form, or copy first.
17
+ - *Accumulators passed in.* A collection is handed in to be filled. Return the items and let the caller combine them.
18
+
19
+ **Where to go.** Inputs are read-only. Functions return new values, and the caller decides what to keep.
20
+
21
+ **Reactions to distrust.**
22
+ - "Copying is slow." Usually unmeasured, and the rule makes no performance carve-out.
23
+ - "The caller wants the change." Then return it, and the caller can see it.
24
+
25
+ **Principles behind it.**
26
+ - *Functional core, imperative shell* (Gary Bernhardt). The core takes values and returns values; changes happen at the edge.
@@ -0,0 +1,13 @@
1
+ # CD-45 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: how the rule is checked, and how to record an exception where the rule allows one.
4
+
5
+ ## Clauses
6
+
7
+ | Clause | Mechanism | Checks |
8
+ | --- | --- | --- |
9
+ | `CD-45#parse-once` | review | validation runs once at the boundary and its types do not leak inward |
10
+
11
+ ## How it is checked
12
+
13
+ Every clause of this discipline is a judgement clause. It cannot be selected in `disciplines.json` and no mechanism checks it; a reviewer applies [the rule](README.md) with its review lens, as [ADOPTING.md](../../ADOPTING.md#9-apply-the-judgement-rules) describes. Selecting no clause of this discipline leaves nothing uncovered.
@@ -4,16 +4,22 @@
4
4
 
5
5
  Validation runs exactly once, at the boundary crossing, and yields a plain internal shape the rest of the code trusts by construction — it is never re-run deeper in, and the validation library's types never leak inward. Parse once at the seam, map to a domain shape, and let the inner layers depend on that shape, not on the validator.
6
6
 
7
- The sections below describe how the rule is checked.
7
+ Review lens: [zod-boundary](../../methods/lenses/zod-boundary.md). The lens reviews the whole rule, including what no check flags. How it is checked: [CHECKS.md](CHECKS.md). The thinking behind every rule: [the spirit of the rules](../SPIRIT.md).
8
8
 
9
- ## Clauses
9
+ ## Spirit
10
10
 
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-45#parse-once` | review | validation runs once at the boundary and its types do not leak inward |
11
+ **What the friction is for.** Checking the same data twice means nobody trusts the first check, and the validator's types spread inward. The friction makes parsing once and handing on a plain shape the easy path.
14
12
 
15
- Review lens: [zod-boundary](../../methods/lenses/zod-boundary.md). The lens reviews the whole rule, including what no check flags.
13
+ **What a finding points at.** Match the sites against these causes.
14
+ - *A boundary that does not finish its job.* The seam parses but passes the raw or validator-typed value on. Map it to a plain domain shape there.
15
+ - *Inner code that does not trust its inputs.* Inner functions parse again. Give them the parsed type so the check is unnecessary.
16
+ - *Validator types used as domain types.* The validation library's types appear in inner signatures. Declare your own types; the boundary maps to them.
16
17
 
17
- ## How it is checked
18
+ **Where to go.** One parse per crossing, at the seam. Inner layers depend on your own types, never on the validator.
18
19
 
19
- Every clause of this discipline is a judgement clause. It cannot be selected in `disciplines.json` and no mechanism checks it; a reviewer applies the rule above with its review lens, as [ADOPTING.md](../../ADOPTING.md#9-apply-the-judgement-rules) describes. Selecting no clause of this discipline leaves nothing uncovered.
20
+ **Reactions to distrust.**
21
+ - "Parsing again is safer." It is a sign the types inside cannot be trusted. Fix that instead.
22
+
23
+ **Principles behind it.**
24
+ - *Parse, don't validate* (Alexis King). After one parse the type carries the proof; checking again adds nothing.
25
+ - *Dependency Inversion Principle* (Robert C. Martin, SOLID). Inner layers depend on their own types, not on a library's.
@@ -0,0 +1,7 @@
1
+ # CD-46 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: how the rule is checked, and how to record an exception where the rule allows one.
4
+
5
+ ## How it is checked
6
+
7
+ This discipline has no clauses to select: the check applies it to every file carve-out. Run the check with `--base-revision`, and a `file-carve-out` record whose file changed since that revision is forfeited, so its findings come back and the run fails until the file is clean and the record is removed. Without `--base-revision`, any file carve-out makes the report list `forfeiture-unmeasured` and the run fails. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
@@ -4,10 +4,22 @@
4
4
 
5
5
  A suppression or exemption is inherited debt held at rest, not a standing licence: it buys "leave this file alone", nothing more. The moment a change edits an exempt file, that file forfeits its exemption — the change must bring the whole file into compliance for the exempted rule (the new lines and the pre-existing ones the exemption was masking) and remove the exemption entry, in the same change. There is no partial credit and no extracting the touched code into a clean helper while the exempt file stays dirty. If full compliance is out of scope, the move is to not touch the file. This rule governs how every other exemption decays and can never itself be exempted.
6
6
 
7
- The sections below describe how the rule is checked.
7
+ Review lens: none. A reviewer applies the rule text directly. How it is checked: [CHECKS.md](CHECKS.md). The thinking behind every rule: [the spirit of the rules](../SPIRIT.md).
8
8
 
9
- Review lens: none. A reviewer applies the rule text directly.
9
+ ## Spirit
10
10
 
11
- ## How it is checked
11
+ **What the friction is for.** A carve-out holds debt at rest. Without decay, it becomes a permanent licence. The friction makes touching a carved file the moment the debt is paid, so debt shrinks wherever work happens.
12
12
 
13
- This discipline has no clauses to select: the check applies it to every file carve-out. Run the check with `--base-revision`, and a `file-carve-out` record whose file changed since that revision is forfeited, so its findings come back and the run fails until the file is clean and the record is removed. Without `--base-revision`, any file carve-out makes the report list `forfeiture-unmeasured` and the run fails. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
13
+ **What a finding points at.** Match the forfeitures against these causes.
14
+ - *Debt in a file that changes often.* The carve-out keeps being forfeited. That file is where paying the debt is cheapest; pay it.
15
+ - *A file too big to bring into compliance.* Touching it means rewriting it, so it has too many jobs. Leave it untouched until a change can take the whole file, and plan that change.
16
+ - *Workarounds that avoid touching.* Code is extracted to avoid the file. That leaves the debt and the workaround; the rule forbids it.
17
+
18
+ **Where to go.** Carve-outs only shrink. Each touched file leaves clean.
19
+
20
+ **Reactions to distrust.**
21
+ - "It's a one-line change." The carve-out bought "leave this file alone". A one-line change is not leaving it alone.
22
+
23
+ **Principles behind it.**
24
+ - *The boy-scout rule.* Leave the code cleaner than you found it.
25
+ - *Technical debt* (Ward Cunningham). Debt not paid down accrues interest on every change.
@@ -0,0 +1,37 @@
1
+ # CD-47 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: how the rule is checked, and how to record an exception where the rule allows one.
4
+
5
+ ## Clauses
6
+
7
+ | Clause | Mechanism | Checks |
8
+ | --- | --- | --- |
9
+ | `CD-47#hermetic-git-spawns` | audit | a git spawn in a test without a hermetic `env` |
10
+
11
+ ## What the check flags
12
+ - Test files: `*.test.ts`, `*.test.tsx`, `*.test.mjs`, `*.test.js`, `*.spec.ts`, `*.spec.mjs`. Generated folders (`node_modules`, `dist`, `build`, `coverage`, `.git`, root `vendor`) are skipped; any other folder can be left out with `exclude` in disciplines.json.
13
+ - A line calling `spawnSync`, `spawn`, `execFileSync`, `execFile`, `execSync`, `exec`, `execa` or `execaSync` with `"git"` (or `'git'`, or a template literal) as the first argument.
14
+ - Allowed when, within that line and the next seven, an `env:` names `hermeticGitEnvironment`, `withoutInheritedGitBindings` or `environment`, and no nearby `env:` uses `process.env`. The helper is yours to provide.
15
+ - Not detected: a command string such as `execSync("git status")`, a split call, or a non-literal command. Whether the spawn is warranted at all is left to review.
16
+
17
+ ## Example violation
18
+ ```ts
19
+ spawnSync("git", ["init"], { cwd: directory });
20
+ ```
21
+
22
+ ## How to fix
23
+ ```ts
24
+ spawnSync("git", ["init"], { cwd: directory, env: hermeticGitEnvironment() });
25
+ ```
26
+ Build the environment without inherited git variables or the user's configuration, and run in a temporary directory.
27
+
28
+ ## Exceptions
29
+ Record exemptions only in `discipline-exceptions.json` at the repository root; core reads no other allowance file. Use `authorised-location` when a test file legitimately builds its environment another way. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
30
+
31
+ ```json
32
+ { "version": 1, "exceptions": [
33
+ { "kind": "authorised-location", "clause": "CD-47#hermetic-git-spawns", "file": "test/git-fixture.test.ts", "reason": "..." }
34
+ ] }
35
+ ```
36
+
37
+ 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`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.