@hailstails/hone 0.0.0-stage → 0.1.0-pre.2

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 (186) hide show
  1. package/ADOPTING.md +314 -0
  2. package/LICENSE +17 -0
  3. package/MIGRATING.md +238 -0
  4. package/README.md +216 -2
  5. package/THIRD-PARTY-NOTICES.md +354 -0
  6. package/chunks/chunk-233U4FBA.js +42 -0
  7. package/chunks/chunk-7ZJZZBSS.js +14909 -0
  8. package/chunks/chunk-HBY4ZWSP.js +79 -0
  9. package/chunks/chunk-HJA4CX7C.js +24 -0
  10. package/chunks/chunk-NZLE2WMY.js +35 -0
  11. package/chunks/chunk-QWA6OVLC.js +11 -0
  12. package/chunks/chunk-TRCB27ET.js +202 -0
  13. package/core/check/tool-command.js +2305 -0
  14. package/docs/adding-a-discipline-or-mechanism.md +195 -0
  15. package/docs/why-chain-contract.md +78 -0
  16. package/mechanisms/audit/CD-1/any-cast.js +81 -0
  17. package/mechanisms/audit/CD-1/piece.json +13 -0
  18. package/mechanisms/audit/CD-10/piece.json +13 -0
  19. package/mechanisms/audit/CD-10/throws-in-tests.js +49 -0
  20. package/mechanisms/audit/CD-14/class-syntax.js +70 -0
  21. package/mechanisms/audit/CD-14/piece.json +13 -0
  22. package/mechanisms/audit/CD-15/loops.js +40 -0
  23. package/mechanisms/audit/CD-15/piece.json +13 -0
  24. package/mechanisms/audit/CD-17/clock-sources.js +29 -0
  25. package/mechanisms/audit/CD-17/piece.json +13 -0
  26. package/mechanisms/audit/CD-19/import-boundaries.js +80 -0
  27. package/mechanisms/audit/CD-19/piece.json +13 -0
  28. package/mechanisms/audit/CD-2/cast-expressions.js +81 -0
  29. package/mechanisms/audit/CD-2/piece.json +13 -0
  30. package/mechanisms/audit/CD-23/export-test-sibling.js +56 -0
  31. package/mechanisms/audit/CD-23/piece.json +13 -0
  32. package/mechanisms/audit/CD-25/dependency-isolation.js +53 -0
  33. package/mechanisms/audit/CD-25/piece.json +13 -0
  34. package/mechanisms/audit/CD-26/module-mocking.js +51 -0
  35. package/mechanisms/audit/CD-26/piece.json +13 -0
  36. package/mechanisms/audit/CD-27/piece.json +13 -0
  37. package/mechanisms/audit/CD-27/test-body-logic.js +107 -0
  38. package/mechanisms/audit/CD-3/compiler-overrides.js +955 -0
  39. package/mechanisms/audit/CD-3/piece.json +49 -0
  40. package/mechanisms/audit/CD-43/boolean-signatures.js +55 -0
  41. package/mechanisms/audit/CD-43/piece.json +13 -0
  42. package/mechanisms/audit/CD-44/parameter-mutation.js +92 -0
  43. package/mechanisms/audit/CD-44/piece.json +13 -0
  44. package/mechanisms/audit/CD-47/hermetic-git-spawns.js +44 -0
  45. package/mechanisms/audit/CD-47/piece.json +13 -0
  46. package/mechanisms/audit/CD-5/comments-directives.js +73 -0
  47. package/mechanisms/audit/CD-5/piece.json +13 -0
  48. package/mechanisms/audit/CD-6/identifier-names.js +132 -0
  49. package/mechanisms/audit/CD-6/piece.json +13 -0
  50. package/mechanisms/audit/CD-7/categorical-paths.js +55 -0
  51. package/mechanisms/audit/CD-7/piece.json +13 -0
  52. package/mechanisms/audit/CD-7a/factory-return-types.js +42 -0
  53. package/mechanisms/audit/CD-7a/piece.json +13 -0
  54. package/mechanisms/audit/CD-8/piece.json +13 -0
  55. package/mechanisms/audit/CD-8/switch-defaults.js +43 -0
  56. package/mechanisms/audit/runner/README.md +38 -0
  57. package/mechanisms/audit/runner/runner.js +546 -0
  58. package/mechanisms/eslint/CD-1/README.md +12 -0
  59. package/mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js +50 -0
  60. package/mechanisms/eslint/CD-1/piece.json +23 -0
  61. package/mechanisms/eslint/CD-10/README.md +9 -0
  62. package/mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js +55 -0
  63. package/mechanisms/eslint/CD-10/piece.json +15 -0
  64. package/mechanisms/eslint/CD-14/README.md +11 -0
  65. package/mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.js +88 -0
  66. package/mechanisms/eslint/CD-14/piece.json +31 -0
  67. package/mechanisms/eslint/CD-27/README.md +12 -0
  68. package/mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.js +83 -0
  69. package/mechanisms/eslint/CD-27/piece.json +23 -0
  70. package/mechanisms/eslint/CD-40/README.md +7 -0
  71. package/mechanisms/eslint/CD-40/cd40/cd40.eslint-plugin.js +16 -0
  72. package/mechanisms/eslint/CD-40/piece.json +21 -0
  73. package/mechanisms/eslint/CD-41/README.md +12 -0
  74. package/mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.js +228 -0
  75. package/mechanisms/eslint/CD-41/piece.json +23 -0
  76. package/mechanisms/eslint/CD-42/README.md +9 -0
  77. package/mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.js +75 -0
  78. package/mechanisms/eslint/CD-42/piece.json +15 -0
  79. package/mechanisms/eslint/CD-44/README.md +7 -0
  80. package/mechanisms/eslint/CD-44/cd44/cd44.eslint-plugin.js +16 -0
  81. package/mechanisms/eslint/CD-44/piece.json +20 -0
  82. package/mechanisms/eslint/CD-6/README.md +9 -0
  83. package/mechanisms/eslint/CD-6/cd6/cd6.eslint-plugin.js +16 -0
  84. package/mechanisms/eslint/CD-6/piece.json +217 -0
  85. package/mechanisms/eslint/CD-7/README.md +9 -0
  86. package/mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.js +52 -0
  87. package/mechanisms/eslint/CD-7/piece.json +15 -0
  88. package/mechanisms/eslint/runner/README.md +43 -0
  89. package/mechanisms/eslint/runner/runner.js +4248 -0
  90. package/methods/README.md +18 -0
  91. package/methods/lenses/clean-architecture.md +167 -0
  92. package/methods/lenses/decomposition.md +159 -0
  93. package/methods/lenses/defended-on-intent.md +178 -0
  94. package/methods/lenses/di-discipline.md +156 -0
  95. package/methods/lenses/errors-as-data.md +88 -0
  96. package/methods/lenses/function-first.md +193 -0
  97. package/methods/lenses/naming.md +127 -0
  98. package/methods/lenses/test-discipline.md +166 -0
  99. package/methods/lenses/type-soundness.md +135 -0
  100. package/methods/lenses/zod-boundary.md +158 -0
  101. package/package.json +65 -4
  102. package/rules/CD-1/README.md +43 -0
  103. package/rules/CD-1/discipline.json +185 -0
  104. package/rules/CD-10/README.md +55 -0
  105. package/rules/CD-10/discipline.json +133 -0
  106. package/rules/CD-11/README.md +19 -0
  107. package/rules/CD-11/discipline.json +12 -0
  108. package/rules/CD-12/README.md +19 -0
  109. package/rules/CD-12/discipline.json +12 -0
  110. package/rules/CD-13/README.md +19 -0
  111. package/rules/CD-13/discipline.json +12 -0
  112. package/rules/CD-14/README.md +54 -0
  113. package/rules/CD-14/discipline.json +173 -0
  114. package/rules/CD-15/README.md +48 -0
  115. package/rules/CD-15/discipline.json +73 -0
  116. package/rules/CD-16/README.md +17 -0
  117. package/rules/CD-17/README.md +42 -0
  118. package/rules/CD-17/discipline.json +51 -0
  119. package/rules/CD-18/README.md +19 -0
  120. package/rules/CD-18/discipline.json +12 -0
  121. package/rules/CD-19/README.md +45 -0
  122. package/rules/CD-19/discipline.json +65 -0
  123. package/rules/CD-2/README.md +43 -0
  124. package/rules/CD-2/discipline.json +65 -0
  125. package/rules/CD-20/README.md +17 -0
  126. package/rules/CD-21/README.md +19 -0
  127. package/rules/CD-21/discipline.json +12 -0
  128. package/rules/CD-22/README.md +19 -0
  129. package/rules/CD-22/discipline.json +12 -0
  130. package/rules/CD-23/README.md +41 -0
  131. package/rules/CD-23/discipline.json +57 -0
  132. package/rules/CD-24/README.md +17 -0
  133. package/rules/CD-25/README.md +43 -0
  134. package/rules/CD-25/discipline.json +57 -0
  135. package/rules/CD-26/README.md +42 -0
  136. package/rules/CD-26/discipline.json +57 -0
  137. package/rules/CD-27/README.md +51 -0
  138. package/rules/CD-27/discipline.json +233 -0
  139. package/rules/CD-28/README.md +19 -0
  140. package/rules/CD-28/discipline.json +12 -0
  141. package/rules/CD-29/README.md +19 -0
  142. package/rules/CD-29/discipline.json +12 -0
  143. package/rules/CD-3/README.md +48 -0
  144. package/rules/CD-3/discipline.json +363 -0
  145. package/rules/CD-30/README.md +19 -0
  146. package/rules/CD-30/discipline.json +12 -0
  147. package/rules/CD-31/README.md +19 -0
  148. package/rules/CD-31/discipline.json +12 -0
  149. package/rules/CD-32/README.md +19 -0
  150. package/rules/CD-32/discipline.json +12 -0
  151. package/rules/CD-33/README.md +19 -0
  152. package/rules/CD-33/discipline.json +12 -0
  153. package/rules/CD-34/README.md +19 -0
  154. package/rules/CD-34/discipline.json +12 -0
  155. package/rules/CD-39/README.md +19 -0
  156. package/rules/CD-39/discipline.json +12 -0
  157. package/rules/CD-4/README.md +19 -0
  158. package/rules/CD-4/discipline.json +12 -0
  159. package/rules/CD-40/README.md +45 -0
  160. package/rules/CD-40/discipline.json +58 -0
  161. package/rules/CD-41/README.md +60 -0
  162. package/rules/CD-41/discipline.json +124 -0
  163. package/rules/CD-42/README.md +53 -0
  164. package/rules/CD-42/discipline.json +61 -0
  165. package/rules/CD-43/README.md +43 -0
  166. package/rules/CD-43/discipline.json +65 -0
  167. package/rules/CD-44/README.md +54 -0
  168. package/rules/CD-44/discipline.json +111 -0
  169. package/rules/CD-45/README.md +19 -0
  170. package/rules/CD-45/discipline.json +12 -0
  171. package/rules/CD-46/README.md +13 -0
  172. package/rules/CD-47/README.md +47 -0
  173. package/rules/CD-47/discipline.json +57 -0
  174. package/rules/CD-5/README.md +46 -0
  175. package/rules/CD-5/discipline.json +65 -0
  176. package/rules/CD-6/README.md +57 -0
  177. package/rules/CD-6/discipline.json +165 -0
  178. package/rules/CD-7/README.md +52 -0
  179. package/rules/CD-7/discipline.json +142 -0
  180. package/rules/CD-7a/README.md +44 -0
  181. package/rules/CD-7a/discipline.json +57 -0
  182. package/rules/CD-8/README.md +48 -0
  183. package/rules/CD-8/discipline.json +57 -0
  184. package/rules/CD-9/README.md +19 -0
  185. package/rules/CD-9/discipline.json +12 -0
  186. package/rules/README.md +52 -0
@@ -0,0 +1,185 @@
1
+ {
2
+ "version": 1,
3
+ "id": "CD-1",
4
+ "clauses": [
5
+ {
6
+ "kind": "mechanical",
7
+ "id": "any-cast",
8
+ "summary": "No any, ever",
9
+ "mechanisms": [
10
+ "audit"
11
+ ],
12
+ "anchor": {
13
+ "kind": "file"
14
+ },
15
+ "cases": {
16
+ "flag": [
17
+ {
18
+ "name": "as any assertion",
19
+ "fileName": "parse.ts",
20
+ "source": "export const parsed = JSON.parse(text) as any;\n",
21
+ "expectedLines": [
22
+ 1
23
+ ]
24
+ },
25
+ {
26
+ "name": "angle-bracket any assertion",
27
+ "fileName": "angle.ts",
28
+ "source": "declare const candidate: unknown;\nexport const narrowed = <any>candidate;\n",
29
+ "expectedLines": [
30
+ 2
31
+ ]
32
+ },
33
+ {
34
+ "name": "as any on a later line",
35
+ "fileName": "later.ts",
36
+ "source": "declare const candidate: unknown;\nconst first = 1;\nexport const narrowed = candidate as any;\n",
37
+ "expectedLines": [
38
+ 3
39
+ ]
40
+ }
41
+ ],
42
+ "allow": [
43
+ {
44
+ "name": "as unknown assertion",
45
+ "fileName": "unknown.ts",
46
+ "source": "export const parsed = JSON.parse(text) as unknown;\n",
47
+ "expectedLines": []
48
+ },
49
+ {
50
+ "name": "const assertion",
51
+ "fileName": "const-assertion.ts",
52
+ "source": "export const PERMITTED_LITERAL = \"permitted\" as const;\n",
53
+ "expectedLines": []
54
+ },
55
+ {
56
+ "name": "bare any annotation is left to review",
57
+ "fileName": "annotation.ts",
58
+ "source": "declare const candidate: unknown;\nexport const direct: any = candidate;\n",
59
+ "expectedLines": []
60
+ }
61
+ ]
62
+ }
63
+ },
64
+ {
65
+ "kind": "mechanical",
66
+ "id": "explicit-any",
67
+ "summary": "No any, ever",
68
+ "mechanisms": [
69
+ "eslint"
70
+ ],
71
+ "anchor": {
72
+ "kind": "keyword",
73
+ "keyword": "any"
74
+ },
75
+ "cases": {
76
+ "flag": [
77
+ {
78
+ "name": "any return annotation",
79
+ "fileName": "src/parse.ts",
80
+ "source": "export const parse = (text: string): any => JSON.parse(text);\n",
81
+ "expectedLines": [
82
+ 1
83
+ ]
84
+ },
85
+ {
86
+ "name": "any type argument",
87
+ "fileName": "src/table.ts",
88
+ "source": "export const table = new Map<string, any>();\n",
89
+ "expectedLines": [
90
+ 1
91
+ ]
92
+ },
93
+ {
94
+ "name": "as any cast",
95
+ "fileName": "src/value.ts",
96
+ "source": "export const value = JSON.parse(\"1\") as any;\n",
97
+ "expectedLines": [
98
+ 1
99
+ ]
100
+ }
101
+ ],
102
+ "allow": [
103
+ {
104
+ "name": "unknown return annotation",
105
+ "fileName": "src/parse.ts",
106
+ "source": "export const parse = (text: string): unknown => JSON.parse(text);\n",
107
+ "expectedLines": []
108
+ },
109
+ {
110
+ "name": "the word any in a string",
111
+ "fileName": "src/label.ts",
112
+ "source": "export const label = \"any\";\n",
113
+ "expectedLines": []
114
+ }
115
+ ]
116
+ }
117
+ },
118
+ {
119
+ "kind": "mechanical",
120
+ "id": "implicit-any-let",
121
+ "summary": "No any, ever",
122
+ "mechanisms": [
123
+ "eslint"
124
+ ],
125
+ "anchor": {
126
+ "kind": "keyword",
127
+ "keyword": "let"
128
+ },
129
+ "cases": {
130
+ "flag": [
131
+ {
132
+ "name": "let without a type or initialiser",
133
+ "fileName": "src/total.ts",
134
+ "source": "let total;\nexport { total };\n",
135
+ "expectedLines": [
136
+ 1
137
+ ]
138
+ },
139
+ {
140
+ "name": "var without a type or initialiser",
141
+ "fileName": "src/count.ts",
142
+ "source": "var count;\nexport { count };\n",
143
+ "expectedLines": [
144
+ 1
145
+ ]
146
+ },
147
+ {
148
+ "name": "one report for two untyped bindings",
149
+ "fileName": "src/pair.ts",
150
+ "source": "let first, second;\nexport { first, second };\n",
151
+ "expectedLines": [
152
+ 1
153
+ ]
154
+ }
155
+ ],
156
+ "allow": [
157
+ {
158
+ "name": "let with an initialiser",
159
+ "fileName": "src/total.ts",
160
+ "source": "let total = 0;\nexport { total };\n",
161
+ "expectedLines": []
162
+ },
163
+ {
164
+ "name": "let with a type annotation",
165
+ "fileName": "src/total.ts",
166
+ "source": "let total: number;\nexport { total };\n",
167
+ "expectedLines": []
168
+ },
169
+ {
170
+ "name": "for-of head",
171
+ "fileName": "src/each.ts",
172
+ "source": "export const each = (items: readonly number[]): void => {\n for (let item of items) {\n void item;\n }\n};\n",
173
+ "expectedLines": []
174
+ },
175
+ {
176
+ "name": "declaration file",
177
+ "fileName": "src/env.d.ts",
178
+ "source": "declare let flag;\n",
179
+ "expectedLines": []
180
+ }
181
+ ]
182
+ }
183
+ }
184
+ ]
185
+ }
@@ -0,0 +1,55 @@
1
+ # CD-10: Throws permitted in exactly two contexts
2
+
3
+ ## Rule
4
+
5
+ Throwing is confined to a closed, named set of contexts: a startup-invariant check that fails at boot, and a branch made unreachable by exhaustive type narrowing. Defensive throws — "this should never happen", "guard against impossible state" — are forbidden: if you can name the state, you can model it as a result variant. A library that throws is caught at the boundary and converted to a result. Tests carry no exemption; they surface failures through assertions, not by throwing.
6
+
7
+ The sections below describe what the audit and ESLint checks cover.
8
+
9
+ ## Clauses
10
+
11
+ | Clause | Mechanism | Checks |
12
+ | --- | --- | --- |
13
+ | `CD-10#throws-in-tests` | audit | a `throw` statement in a test file |
14
+ | `CD-10#throw-only-error` | eslint | a `throw` of something that is not an error object |
15
+
16
+ Review lens: [errors-as-data](../../methods/lenses/errors-as-data.md). The lens reviews the whole rule, including what no check flags.
17
+
18
+ ## What the check flags
19
+ - Test files only: `*.test.ts` and `*.test.tsx`. `*.spec.ts` and `.js` tests are not read. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
20
+ - Every `throw` statement, wherever it sits in the file.
21
+ - Allowed: assertion calls such as `expect(...)`.
22
+ - The source rule also confines throwing in production code to a closed list of contexts. The check does not look at production files; that part is left to review.
23
+
24
+ ## What the ESLint check flags
25
+ Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-10/README.md).
26
+ - `hone-cd10/throw-only-error` flags a `throw` of a literal, an object literal, a binary expression, a template or tagged template, or `undefined`. It follows the thrown value through `a ? b : c`, `a || b`, assignment and sequence expressions.
27
+ - Allowed: `new Error(...)`, identifiers, calls and member access.
28
+ - This clause applies to every file the ESLint run includes, not only tests.
29
+
30
+ ## Example violation
31
+ ```ts
32
+ it("loads the account", () => {
33
+ const result = load("a1");
34
+ if (result.outcome === "failed") throw new Error("load failed");
35
+ });
36
+ ```
37
+
38
+ ## How to fix
39
+ ```ts
40
+ it("loads the account", () => {
41
+ expect(load("a1")).toEqual({ outcome: "ok", value: account });
42
+ });
43
+ ```
44
+ Assert on the whole result. Branching in tests is also reported by CD-27.
45
+
46
+ ## Exceptions
47
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a test file legitimately needs a throw, such as a shared test harness. 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).
48
+
49
+ ```json
50
+ { "version": 1, "exceptions": [
51
+ { "kind": "authorised-location", "clause": "CD-10#throws-in-tests", "file": "src/legacy/harness.test.ts", "reason": "..." }
52
+ ] }
53
+ ```
54
+
55
+ 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.
@@ -0,0 +1,133 @@
1
+ {
2
+ "version": 1,
3
+ "id": "CD-10",
4
+ "clauses": [
5
+ {
6
+ "kind": "mechanical",
7
+ "id": "throws-in-tests",
8
+ "summary": "Throws permitted in exactly two contexts",
9
+ "mechanisms": [
10
+ "audit"
11
+ ],
12
+ "anchor": {
13
+ "kind": "file"
14
+ },
15
+ "cases": {
16
+ "flag": [
17
+ {
18
+ "name": "throw inside a test",
19
+ "fileName": "src/load.test.ts",
20
+ "source": "it(\"loads\", () => {\n const result = { outcome: \"ok\" };\n if (result.outcome !== \"ok\") throw new Error(\"load failed\");\n});\n",
21
+ "expectedLines": [
22
+ 3
23
+ ]
24
+ },
25
+ {
26
+ "name": "throw in a tsx test",
27
+ "fileName": "src/view.test.tsx",
28
+ "source": "const a = 1;\nthrow new Error(\"bad\");\n",
29
+ "expectedLines": [
30
+ 2
31
+ ]
32
+ }
33
+ ],
34
+ "allow": [
35
+ {
36
+ "name": "assertion in a test",
37
+ "fileName": "src/load.test.ts",
38
+ "source": "it(\"loads\", () => {\n expect(1).toBe(1);\n});\n",
39
+ "expectedLines": []
40
+ },
41
+ {
42
+ "name": "throw in production code is left to review",
43
+ "fileName": "src/load.ts",
44
+ "source": "export const load = (): never => {\n throw new Error(\"failed\");\n};\n",
45
+ "expectedLines": []
46
+ },
47
+ {
48
+ "name": "spec files are not read",
49
+ "fileName": "src/load.spec.ts",
50
+ "source": "throw new Error(\"bad\");\n",
51
+ "expectedLines": []
52
+ }
53
+ ]
54
+ }
55
+ },
56
+ {
57
+ "kind": "mechanical",
58
+ "id": "throw-only-error",
59
+ "summary": "Throws permitted in exactly two contexts",
60
+ "mechanisms": [
61
+ "eslint"
62
+ ],
63
+ "anchor": {
64
+ "kind": "keyword",
65
+ "keyword": "throw"
66
+ },
67
+ "cases": {
68
+ "flag": [
69
+ {
70
+ "name": "string literal",
71
+ "fileName": "src/fail.ts",
72
+ "source": "export const fail = (): never => {\n throw \"failed\";\n};\n",
73
+ "expectedLines": [
74
+ 2
75
+ ]
76
+ },
77
+ {
78
+ "name": "object literal",
79
+ "fileName": "src/fail.ts",
80
+ "source": "export const fail = (): never => {\n throw { code: 1 };\n};\n",
81
+ "expectedLines": [
82
+ 2
83
+ ]
84
+ },
85
+ {
86
+ "name": "template literal",
87
+ "fileName": "src/fail.ts",
88
+ "source": "export const fail = (code: number): never => {\n throw `failed ${code}`;\n};\n",
89
+ "expectedLines": [
90
+ 2
91
+ ]
92
+ },
93
+ {
94
+ "name": "undefined",
95
+ "fileName": "src/fail.ts",
96
+ "source": "export const fail = (): never => {\n throw undefined;\n};\n",
97
+ "expectedLines": [
98
+ 2
99
+ ]
100
+ },
101
+ {
102
+ "name": "conditional with a literal branch",
103
+ "fileName": "src/fail.ts",
104
+ "source": "export const fail = (ready: string): never => {\n throw ready === \"yes\" ? new Error(\"x\") : \"x\";\n};\n",
105
+ "expectedLines": [
106
+ 2
107
+ ]
108
+ }
109
+ ],
110
+ "allow": [
111
+ {
112
+ "name": "new Error",
113
+ "fileName": "src/fail.ts",
114
+ "source": "export const fail = (): never => {\n throw new Error(\"failed\");\n};\n",
115
+ "expectedLines": []
116
+ },
117
+ {
118
+ "name": "an identifier",
119
+ "fileName": "src/fail.ts",
120
+ "source": "export const fail = (error: Error): never => {\n throw error;\n};\n",
121
+ "expectedLines": []
122
+ },
123
+ {
124
+ "name": "a call",
125
+ "fileName": "src/fail.ts",
126
+ "source": "export const fail = (make: () => Error): never => {\n throw make();\n};\n",
127
+ "expectedLines": []
128
+ }
129
+ ]
130
+ }
131
+ }
132
+ ]
133
+ }
@@ -0,0 +1,19 @@
1
+ # CD-11: Operational error envelopes are plain data, not classes
2
+
3
+ ## Rule
4
+
5
+ Operational error envelopes are plain, tagged data — constructed by a factory, inspected by a type guard, dispatched by an exhaustive switch on the tag — never authored classes extending the runtime's error type. Data-shaped errors compose, narrow, and serialise; class hierarchies for operational failure do not. The only authored error class is the single startup-invariant one the throw rule permits.
6
+
7
+ The sections below describe how the rule is checked.
8
+
9
+ ## Clauses
10
+
11
+ | Clause | Mechanism | Checks |
12
+ | --- | --- | --- |
13
+ | `CD-11#error-envelopes` | review | operational errors are tagged data built by a factory and dispatched on their tag |
14
+
15
+ Review lens: [errors-as-data](../../methods/lenses/errors-as-data.md). The lens reviews the whole rule, including what no check flags.
16
+
17
+ ## How it is checked
18
+
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.
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 1,
3
+ "id": "CD-11",
4
+ "clauses": [
5
+ {
6
+ "kind": "judgement",
7
+ "id": "error-envelopes",
8
+ "summary": "operational errors are tagged data built by a factory and dispatched on their tag",
9
+ "enforcedBy": "review"
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,19 @@
1
+ # CD-12: Repositories are the primary storage abstraction
2
+
3
+ ## Rule
4
+
5
+ Storage sits behind a repository port. Domain code talks to the port; an adapter composes the raw storage-driver primitives behind it. The domain never imports the storage driver or a filesystem primitive directly — so the storage technology can change without the domain knowing.
6
+
7
+ The sections below describe how the rule is checked.
8
+
9
+ ## Clauses
10
+
11
+ | Clause | Mechanism | Checks |
12
+ | --- | --- | --- |
13
+ | `CD-12#repository-ports` | review | storage sits behind a repository port and domain code never imports a storage driver |
14
+
15
+ Review lens: [clean-architecture](../../methods/lenses/clean-architecture.md). The lens reviews the whole rule, including what no check flags.
16
+
17
+ ## How it is checked
18
+
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.
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 1,
3
+ "id": "CD-12",
4
+ "clauses": [
5
+ {
6
+ "kind": "judgement",
7
+ "id": "repository-ports",
8
+ "summary": "storage sits behind a repository port and domain code never imports a storage driver",
9
+ "enforcedBy": "review"
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,19 @@
1
+ # CD-13: Kernel layer boundaries are non-negotiable
2
+
3
+ ## Rule
4
+
5
+ Dependencies point inward and only inward: the domain depends on nothing, the application layer orchestrates the domain, adapters implement the ports the inner layers declare, and transports are leaves at the edge. An inner layer importing an outer one is the violation — it is what inverts the dependency direction the architecture exists to protect.
6
+
7
+ The sections below describe how the rule is checked.
8
+
9
+ ## Clauses
10
+
11
+ | Clause | Mechanism | Checks |
12
+ | --- | --- | --- |
13
+ | `CD-13#layer-boundaries` | review | dependencies point inward and an inner layer never imports an outer one |
14
+
15
+ Review lens: [clean-architecture](../../methods/lenses/clean-architecture.md). The lens reviews the whole rule, including what no check flags.
16
+
17
+ ## How it is checked
18
+
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.
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 1,
3
+ "id": "CD-13",
4
+ "clauses": [
5
+ {
6
+ "kind": "judgement",
7
+ "id": "layer-boundaries",
8
+ "summary": "dependencies point inward and an inner layer never imports an outer one",
9
+ "enforcedBy": "review"
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,54 @@
1
+ # CD-14: Zero class authoring; classes only at external-library call sites
2
+
3
+ ## Rule
4
+
5
+ Behaviour is composed from functions and closures, not authored classes — state lives in a factory that closes over it. A class appears only where an external library's API demands `new` at the call site; that instance is created inside the wrapping factory and held internally, never re-exported as a class. The rule is per-declaration, not per-export: even a non-exported authored class is a violation.
6
+
7
+ The sections below describe what the audit and ESLint checks cover.
8
+
9
+ ## Clauses
10
+
11
+ | Clause | Mechanism | Checks |
12
+ | --- | --- | --- |
13
+ | `CD-14#class-syntax` | audit or eslint | a class declaration or expression outside ambient code |
14
+ | `CD-14#static-only-class` | eslint | a class whose members are all static |
15
+ | `CD-14#library-construction` | review | library classes are built only in wrapping factories and never re-exported |
16
+
17
+ Review lens: [function-first](../../methods/lenses/function-first.md). The lens reviews the whole rule, including what no check flags.
18
+
19
+ ## What the check flags
20
+ - TypeScript source files; declaration files (`.d.ts`) are skipped. Generated folders (`node_modules`, `dist`, `build`, `coverage`, `.git`, root `vendor`) are skipped by the audit mechanism; any other folder can be left out with `exclude` in disciplines.json. The ESLint piece lints whatever files the team's ESLint run includes.
21
+ - Any class declaration, class expression, `abstract class`, nested class, or class inside a runtime `namespace`, reported at the `class` keyword.
22
+ - Allowed: `declare class`, classes inside `declare module`, `declare global` or `declare namespace`, and `new Client()` on a class imported from a library.
23
+ - `library-construction` is a judgement clause. It cannot be selected and is enforced by review.
24
+
25
+ ## What the ESLint check flags
26
+ Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-14/README.md).
27
+ - `hone/no-extraneous-class` is typescript-eslint's `no-extraneous-class` with `allowConstructorOnly: true`, `allowEmpty: true`, `allowStaticOnly: false` and `allowWithDecorator: true`.
28
+ - It flags a class whose members are all static.
29
+ - Allowed: empty classes, decorated classes and classes that extend another class.
30
+
31
+ ## Example violation
32
+ ```ts
33
+ export class Counter {}
34
+ ```
35
+
36
+ ## How to fix
37
+ ```ts
38
+ export const createCounter = () => {
39
+ let count = 0;
40
+ return { increment: () => (count += 1) };
41
+ };
42
+ ```
43
+ Return an object of functions from a factory that closes over its state.
44
+
45
+ ## Exceptions
46
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a class is required, such as an adapter extending a library base class. 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-14#class-syntax", "file": "src/adapters/vendor-client.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.