@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.
- package/ADOPTING.md +314 -0
- package/LICENSE +17 -0
- package/MIGRATING.md +238 -0
- package/README.md +216 -2
- package/THIRD-PARTY-NOTICES.md +354 -0
- package/chunks/chunk-233U4FBA.js +42 -0
- package/chunks/chunk-7ZJZZBSS.js +14909 -0
- package/chunks/chunk-HBY4ZWSP.js +79 -0
- package/chunks/chunk-HJA4CX7C.js +24 -0
- package/chunks/chunk-NZLE2WMY.js +35 -0
- package/chunks/chunk-QWA6OVLC.js +11 -0
- package/chunks/chunk-TRCB27ET.js +202 -0
- package/core/check/tool-command.js +2305 -0
- package/docs/adding-a-discipline-or-mechanism.md +195 -0
- package/docs/why-chain-contract.md +78 -0
- package/mechanisms/audit/CD-1/any-cast.js +81 -0
- package/mechanisms/audit/CD-1/piece.json +13 -0
- package/mechanisms/audit/CD-10/piece.json +13 -0
- package/mechanisms/audit/CD-10/throws-in-tests.js +49 -0
- package/mechanisms/audit/CD-14/class-syntax.js +70 -0
- package/mechanisms/audit/CD-14/piece.json +13 -0
- package/mechanisms/audit/CD-15/loops.js +40 -0
- package/mechanisms/audit/CD-15/piece.json +13 -0
- package/mechanisms/audit/CD-17/clock-sources.js +29 -0
- package/mechanisms/audit/CD-17/piece.json +13 -0
- package/mechanisms/audit/CD-19/import-boundaries.js +80 -0
- package/mechanisms/audit/CD-19/piece.json +13 -0
- package/mechanisms/audit/CD-2/cast-expressions.js +81 -0
- package/mechanisms/audit/CD-2/piece.json +13 -0
- package/mechanisms/audit/CD-23/export-test-sibling.js +56 -0
- package/mechanisms/audit/CD-23/piece.json +13 -0
- package/mechanisms/audit/CD-25/dependency-isolation.js +53 -0
- package/mechanisms/audit/CD-25/piece.json +13 -0
- package/mechanisms/audit/CD-26/module-mocking.js +51 -0
- package/mechanisms/audit/CD-26/piece.json +13 -0
- package/mechanisms/audit/CD-27/piece.json +13 -0
- package/mechanisms/audit/CD-27/test-body-logic.js +107 -0
- package/mechanisms/audit/CD-3/compiler-overrides.js +955 -0
- package/mechanisms/audit/CD-3/piece.json +49 -0
- package/mechanisms/audit/CD-43/boolean-signatures.js +55 -0
- package/mechanisms/audit/CD-43/piece.json +13 -0
- package/mechanisms/audit/CD-44/parameter-mutation.js +92 -0
- package/mechanisms/audit/CD-44/piece.json +13 -0
- package/mechanisms/audit/CD-47/hermetic-git-spawns.js +44 -0
- package/mechanisms/audit/CD-47/piece.json +13 -0
- package/mechanisms/audit/CD-5/comments-directives.js +73 -0
- package/mechanisms/audit/CD-5/piece.json +13 -0
- package/mechanisms/audit/CD-6/identifier-names.js +132 -0
- package/mechanisms/audit/CD-6/piece.json +13 -0
- package/mechanisms/audit/CD-7/categorical-paths.js +55 -0
- package/mechanisms/audit/CD-7/piece.json +13 -0
- package/mechanisms/audit/CD-7a/factory-return-types.js +42 -0
- package/mechanisms/audit/CD-7a/piece.json +13 -0
- package/mechanisms/audit/CD-8/piece.json +13 -0
- package/mechanisms/audit/CD-8/switch-defaults.js +43 -0
- package/mechanisms/audit/runner/README.md +38 -0
- package/mechanisms/audit/runner/runner.js +546 -0
- package/mechanisms/eslint/CD-1/README.md +12 -0
- package/mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js +50 -0
- package/mechanisms/eslint/CD-1/piece.json +23 -0
- package/mechanisms/eslint/CD-10/README.md +9 -0
- package/mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js +55 -0
- package/mechanisms/eslint/CD-10/piece.json +15 -0
- package/mechanisms/eslint/CD-14/README.md +11 -0
- package/mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.js +88 -0
- package/mechanisms/eslint/CD-14/piece.json +31 -0
- package/mechanisms/eslint/CD-27/README.md +12 -0
- package/mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.js +83 -0
- package/mechanisms/eslint/CD-27/piece.json +23 -0
- package/mechanisms/eslint/CD-40/README.md +7 -0
- package/mechanisms/eslint/CD-40/cd40/cd40.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-40/piece.json +21 -0
- package/mechanisms/eslint/CD-41/README.md +12 -0
- package/mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.js +228 -0
- package/mechanisms/eslint/CD-41/piece.json +23 -0
- package/mechanisms/eslint/CD-42/README.md +9 -0
- package/mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.js +75 -0
- package/mechanisms/eslint/CD-42/piece.json +15 -0
- package/mechanisms/eslint/CD-44/README.md +7 -0
- package/mechanisms/eslint/CD-44/cd44/cd44.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-44/piece.json +20 -0
- package/mechanisms/eslint/CD-6/README.md +9 -0
- package/mechanisms/eslint/CD-6/cd6/cd6.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-6/piece.json +217 -0
- package/mechanisms/eslint/CD-7/README.md +9 -0
- package/mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.js +52 -0
- package/mechanisms/eslint/CD-7/piece.json +15 -0
- package/mechanisms/eslint/runner/README.md +43 -0
- package/mechanisms/eslint/runner/runner.js +4248 -0
- package/methods/README.md +18 -0
- package/methods/lenses/clean-architecture.md +167 -0
- package/methods/lenses/decomposition.md +159 -0
- package/methods/lenses/defended-on-intent.md +178 -0
- package/methods/lenses/di-discipline.md +156 -0
- package/methods/lenses/errors-as-data.md +88 -0
- package/methods/lenses/function-first.md +193 -0
- package/methods/lenses/naming.md +127 -0
- package/methods/lenses/test-discipline.md +166 -0
- package/methods/lenses/type-soundness.md +135 -0
- package/methods/lenses/zod-boundary.md +158 -0
- package/package.json +65 -4
- package/rules/CD-1/README.md +43 -0
- package/rules/CD-1/discipline.json +185 -0
- package/rules/CD-10/README.md +55 -0
- package/rules/CD-10/discipline.json +133 -0
- package/rules/CD-11/README.md +19 -0
- package/rules/CD-11/discipline.json +12 -0
- package/rules/CD-12/README.md +19 -0
- package/rules/CD-12/discipline.json +12 -0
- package/rules/CD-13/README.md +19 -0
- package/rules/CD-13/discipline.json +12 -0
- package/rules/CD-14/README.md +54 -0
- package/rules/CD-14/discipline.json +173 -0
- package/rules/CD-15/README.md +48 -0
- package/rules/CD-15/discipline.json +73 -0
- package/rules/CD-16/README.md +17 -0
- package/rules/CD-17/README.md +42 -0
- package/rules/CD-17/discipline.json +51 -0
- package/rules/CD-18/README.md +19 -0
- package/rules/CD-18/discipline.json +12 -0
- package/rules/CD-19/README.md +45 -0
- package/rules/CD-19/discipline.json +65 -0
- package/rules/CD-2/README.md +43 -0
- package/rules/CD-2/discipline.json +65 -0
- package/rules/CD-20/README.md +17 -0
- package/rules/CD-21/README.md +19 -0
- package/rules/CD-21/discipline.json +12 -0
- package/rules/CD-22/README.md +19 -0
- package/rules/CD-22/discipline.json +12 -0
- package/rules/CD-23/README.md +41 -0
- package/rules/CD-23/discipline.json +57 -0
- package/rules/CD-24/README.md +17 -0
- package/rules/CD-25/README.md +43 -0
- package/rules/CD-25/discipline.json +57 -0
- package/rules/CD-26/README.md +42 -0
- package/rules/CD-26/discipline.json +57 -0
- package/rules/CD-27/README.md +51 -0
- package/rules/CD-27/discipline.json +233 -0
- package/rules/CD-28/README.md +19 -0
- package/rules/CD-28/discipline.json +12 -0
- package/rules/CD-29/README.md +19 -0
- package/rules/CD-29/discipline.json +12 -0
- package/rules/CD-3/README.md +48 -0
- package/rules/CD-3/discipline.json +363 -0
- package/rules/CD-30/README.md +19 -0
- package/rules/CD-30/discipline.json +12 -0
- package/rules/CD-31/README.md +19 -0
- package/rules/CD-31/discipline.json +12 -0
- package/rules/CD-32/README.md +19 -0
- package/rules/CD-32/discipline.json +12 -0
- package/rules/CD-33/README.md +19 -0
- package/rules/CD-33/discipline.json +12 -0
- package/rules/CD-34/README.md +19 -0
- package/rules/CD-34/discipline.json +12 -0
- package/rules/CD-39/README.md +19 -0
- package/rules/CD-39/discipline.json +12 -0
- package/rules/CD-4/README.md +19 -0
- package/rules/CD-4/discipline.json +12 -0
- package/rules/CD-40/README.md +45 -0
- package/rules/CD-40/discipline.json +58 -0
- package/rules/CD-41/README.md +60 -0
- package/rules/CD-41/discipline.json +124 -0
- package/rules/CD-42/README.md +53 -0
- package/rules/CD-42/discipline.json +61 -0
- package/rules/CD-43/README.md +43 -0
- package/rules/CD-43/discipline.json +65 -0
- package/rules/CD-44/README.md +54 -0
- package/rules/CD-44/discipline.json +111 -0
- package/rules/CD-45/README.md +19 -0
- package/rules/CD-45/discipline.json +12 -0
- package/rules/CD-46/README.md +13 -0
- package/rules/CD-47/README.md +47 -0
- package/rules/CD-47/discipline.json +57 -0
- package/rules/CD-5/README.md +46 -0
- package/rules/CD-5/discipline.json +65 -0
- package/rules/CD-6/README.md +57 -0
- package/rules/CD-6/discipline.json +165 -0
- package/rules/CD-7/README.md +52 -0
- package/rules/CD-7/discipline.json +142 -0
- package/rules/CD-7a/README.md +44 -0
- package/rules/CD-7a/discipline.json +57 -0
- package/rules/CD-8/README.md +48 -0
- package/rules/CD-8/discipline.json +57 -0
- package/rules/CD-9/README.md +19 -0
- package/rules/CD-9/discipline.json +12 -0
- package/rules/README.md +52 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"id": "CD-14",
|
|
4
|
+
"clauses": [
|
|
5
|
+
{
|
|
6
|
+
"kind": "mechanical",
|
|
7
|
+
"id": "class-syntax",
|
|
8
|
+
"summary": "Zero class authoring; classes only at external-library call sites",
|
|
9
|
+
"mechanisms": [
|
|
10
|
+
"audit",
|
|
11
|
+
"eslint"
|
|
12
|
+
],
|
|
13
|
+
"anchor": {
|
|
14
|
+
"kind": "keyword",
|
|
15
|
+
"keyword": "class"
|
|
16
|
+
},
|
|
17
|
+
"cases": {
|
|
18
|
+
"flag": [
|
|
19
|
+
{
|
|
20
|
+
"name": "class declaration",
|
|
21
|
+
"fileName": "decl.ts",
|
|
22
|
+
"source": "export class Alpha {}\n",
|
|
23
|
+
"expectedLines": [
|
|
24
|
+
1
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "class expression",
|
|
29
|
+
"fileName": "expr.ts",
|
|
30
|
+
"source": "export const Beta = class {};\n",
|
|
31
|
+
"expectedLines": [
|
|
32
|
+
1
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "export default class across two lines",
|
|
37
|
+
"fileName": "default.ts",
|
|
38
|
+
"source": "export default\nclass {}\n",
|
|
39
|
+
"expectedLines": [
|
|
40
|
+
2
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "abstract class",
|
|
45
|
+
"fileName": "abstract.ts",
|
|
46
|
+
"source": "export abstract class Gamma {}\n",
|
|
47
|
+
"expectedLines": [
|
|
48
|
+
1
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"name": "nested class",
|
|
53
|
+
"fileName": "nested.ts",
|
|
54
|
+
"source": "export function make() {\n class Delta {}\n return Delta;\n}\n",
|
|
55
|
+
"expectedLines": [
|
|
56
|
+
2
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "runtime namespace class",
|
|
61
|
+
"fileName": "space.ts",
|
|
62
|
+
"source": "export namespace Space {\n export class Epsilon {}\n}\n",
|
|
63
|
+
"expectedLines": [
|
|
64
|
+
2
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"name": "new anonymous class",
|
|
69
|
+
"fileName": "anon.ts",
|
|
70
|
+
"source": "export const zeta = new (class {})();\n",
|
|
71
|
+
"expectedLines": [
|
|
72
|
+
1
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"allow": [
|
|
77
|
+
{
|
|
78
|
+
"name": "declare class",
|
|
79
|
+
"fileName": "ambient.ts",
|
|
80
|
+
"source": "declare class Eta {}\n",
|
|
81
|
+
"expectedLines": []
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"name": "declare module",
|
|
85
|
+
"fileName": "module.ts",
|
|
86
|
+
"source": "declare module \"lib\" {\n class Theta {}\n}\n",
|
|
87
|
+
"expectedLines": []
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"name": "declare global",
|
|
91
|
+
"fileName": "global.ts",
|
|
92
|
+
"source": "export {};\ndeclare global {\n class Iota {}\n}\n",
|
|
93
|
+
"expectedLines": []
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"name": "nested declare namespace",
|
|
97
|
+
"fileName": "outer.ts",
|
|
98
|
+
"source": "declare namespace Outer {\n namespace Inner {\n class Kappa {}\n }\n}\n",
|
|
99
|
+
"expectedLines": []
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"name": "declaration file",
|
|
103
|
+
"fileName": "x.d.ts",
|
|
104
|
+
"source": "export class Lambda {}\n",
|
|
105
|
+
"expectedLines": []
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"name": "library construction",
|
|
109
|
+
"fileName": "client.ts",
|
|
110
|
+
"source": "import { Client } from \"lib\";\nexport const client = new Client();\n",
|
|
111
|
+
"expectedLines": []
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"kind": "judgement",
|
|
118
|
+
"id": "library-construction",
|
|
119
|
+
"summary": "library classes are constructed only in wrapping factories and never re-exported",
|
|
120
|
+
"enforcedBy": "review"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"kind": "mechanical",
|
|
124
|
+
"id": "static-only-class",
|
|
125
|
+
"summary": "Zero class authoring; classes only at external-library call sites",
|
|
126
|
+
"mechanisms": [
|
|
127
|
+
"eslint"
|
|
128
|
+
],
|
|
129
|
+
"anchor": {
|
|
130
|
+
"kind": "keyword",
|
|
131
|
+
"keyword": "class"
|
|
132
|
+
},
|
|
133
|
+
"cases": {
|
|
134
|
+
"flag": [
|
|
135
|
+
{
|
|
136
|
+
"name": "class with only static members",
|
|
137
|
+
"fileName": "src/paths.ts",
|
|
138
|
+
"source": "export class Paths {\n static root = \"/\";\n}\n",
|
|
139
|
+
"expectedLines": [
|
|
140
|
+
1
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
"allow": [
|
|
145
|
+
{
|
|
146
|
+
"name": "empty class",
|
|
147
|
+
"fileName": "src/empty.ts",
|
|
148
|
+
"source": "export class Empty {}\n",
|
|
149
|
+
"expectedLines": []
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"name": "class with an instance member",
|
|
153
|
+
"fileName": "src/store.ts",
|
|
154
|
+
"source": "export class Store {\n value = 1;\n}\n",
|
|
155
|
+
"expectedLines": []
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"name": "decorated static-only class",
|
|
159
|
+
"fileName": "src/paths.ts",
|
|
160
|
+
"source": "@sealed\nexport class Paths {\n static root = \"/\";\n}\n",
|
|
161
|
+
"expectedLines": []
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"name": "static-only class that extends another",
|
|
165
|
+
"fileName": "src/paths.ts",
|
|
166
|
+
"source": "export class Paths extends Base {\n static root = \"/\";\n}\n",
|
|
167
|
+
"expectedLines": []
|
|
168
|
+
}
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# CD-15: Iteration is functional transformation, never an imperative loop
|
|
2
|
+
|
|
3
|
+
## Rule
|
|
4
|
+
|
|
5
|
+
Iteration is a transformation, expressed with `map`, `reduce`, `flatMap`, `filter`, or `Array.from` — so it reads as data flowing through a pipeline rather than as mutable imperative stepping. Pure side-effect iteration (logging, registering listeners) uses `forEach` with a callback that returns void. The two imperative shapes this rule replaces are element iteration (`for…of`) and counted iteration (`for (let i = 0; …; i++)`): the first becomes a functional traversal, and the second becomes `Array.from({ length }, mapper)` where the index is derived from position rather than incremented by a manual counter that can drift out of bounds.
|
|
6
|
+
|
|
7
|
+
**Async stream consumption is iteration this rule does not reach.** Draining an `AsyncIterable` — pulling `await iterator.next()` until exhaustion, or the `for await…of` that desugars to it — is permitted at sites declared as authorised locations for CD-15. The functional forms cannot express it: `map`/`reduce`/`flatMap` over an `AsyncIterable` require materialising the whole stream, which destroys the bounded-residency property that streaming exists to provide. This is a structural fact about the language, not debt — a drain loop at a declared site is fully compliant, carries no paydown obligation, and takes an authorised-location entry, never a carve-out. Everything the rule does reach still binds inside such a loop: the body is a transformation, accumulator updates are whole-value replacements rather than in-place mutation, and synchronous iteration over materialised collections stays functional.
|
|
8
|
+
|
|
9
|
+
The sections below describe what the audit check covers.
|
|
10
|
+
|
|
11
|
+
## Clauses
|
|
12
|
+
|
|
13
|
+
| Clause | Mechanism | Checks |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| `CD-15#loops` | audit | `for...of`, `for await`, counted `for` and `while` loops |
|
|
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
|
+
- `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
21
|
+
- Lines matching `for (... of ...)` (with or without `await`), `for (init; test; step)` and `while (`. This includes `do...while`. Each kind is reported once per line.
|
|
22
|
+
- Matching is on raw lines, so loop headers split over several lines are missed and the same text inside a string is flagged. Comment lines are ignored.
|
|
23
|
+
- The source rule names element and counted iteration; the check also flags `while`.
|
|
24
|
+
- Draining an `AsyncIterable` with `for await` is allowed by the rule at declared sites; record it as an `authorised-location`.
|
|
25
|
+
|
|
26
|
+
## Example violation
|
|
27
|
+
```ts
|
|
28
|
+
for (const order of orders) {
|
|
29
|
+
totals.push(order.total);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## How to fix
|
|
34
|
+
```ts
|
|
35
|
+
const totals = orders.map((order) => order.total);
|
|
36
|
+
```
|
|
37
|
+
Replace a counted loop with `Array.from({ length }, (_, position) => ...)`.
|
|
38
|
+
|
|
39
|
+
## Exceptions
|
|
40
|
+
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file drains an async stream and cannot use a functional form. 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-15#loops", "file": "src/streams/drain.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.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"id": "CD-15",
|
|
4
|
+
"clauses": [
|
|
5
|
+
{
|
|
6
|
+
"kind": "mechanical",
|
|
7
|
+
"id": "loops",
|
|
8
|
+
"summary": "Iteration is functional transformation, never an imperative loop",
|
|
9
|
+
"mechanisms": [
|
|
10
|
+
"audit"
|
|
11
|
+
],
|
|
12
|
+
"anchor": {
|
|
13
|
+
"kind": "file"
|
|
14
|
+
},
|
|
15
|
+
"cases": {
|
|
16
|
+
"flag": [
|
|
17
|
+
{
|
|
18
|
+
"name": "for-of loop",
|
|
19
|
+
"fileName": "for-of.ts",
|
|
20
|
+
"source": "declare const orders: readonly { readonly total: number }[];\nconst totals: number[] = [];\nfor (const order of orders) {\n totals.push(order.total);\n}\n",
|
|
21
|
+
"expectedLines": [
|
|
22
|
+
3
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "for-await loop",
|
|
27
|
+
"fileName": "for-await.ts",
|
|
28
|
+
"source": "declare const stream: AsyncIterable<number>;\nfor await (const entry of stream) console.log(entry);\n",
|
|
29
|
+
"expectedLines": [
|
|
30
|
+
2
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"name": "counted for loop",
|
|
35
|
+
"fileName": "counted.ts",
|
|
36
|
+
"source": "for (let index = 0; index < 2; index++) console.log(index);\n",
|
|
37
|
+
"expectedLines": [
|
|
38
|
+
1
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "while loop",
|
|
43
|
+
"fileName": "while.ts",
|
|
44
|
+
"source": "declare const queue: number[];\nwhile (queue.length) queue.pop();\n",
|
|
45
|
+
"expectedLines": [
|
|
46
|
+
2
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
"allow": [
|
|
51
|
+
{
|
|
52
|
+
"name": "array pipeline",
|
|
53
|
+
"fileName": "pipeline.ts",
|
|
54
|
+
"source": "export const totals = (orders: readonly { readonly total: number }[]): readonly number[] => orders.map((order) => order.total);\n",
|
|
55
|
+
"expectedLines": []
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "loop text in a comment line",
|
|
59
|
+
"fileName": "commented.ts",
|
|
60
|
+
"source": "// while (queue.length) drain();\nexport const value = 1;\n",
|
|
61
|
+
"expectedLines": []
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"name": "switch statement",
|
|
65
|
+
"fileName": "switch.ts",
|
|
66
|
+
"source": "export const pick = (kind: \"a\" | \"b\"): number => {\n switch (kind) {\n case \"a\": return 1;\n case \"b\": return 2;\n }\n};\n",
|
|
67
|
+
"expectedLines": []
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# CD-16: No counted for loops
|
|
2
|
+
|
|
3
|
+
## Rule
|
|
4
|
+
|
|
5
|
+
Collapsed into [CD-15](../CD-15/README.md) — counted-loop iteration and
|
|
6
|
+
element iteration are two faces of the same intent (iteration is functional
|
|
7
|
+
transformation, not imperative looping). CD-15 now carries both. This id is
|
|
8
|
+
retained as a redirect so existing citations resolve; it is not independently
|
|
9
|
+
enforced.
|
|
10
|
+
|
|
11
|
+
The sections below describe how the rule is checked.
|
|
12
|
+
|
|
13
|
+
Review lens: [function-first](../../methods/lenses/function-first.md). The lens reviews the whole rule, including what no check flags.
|
|
14
|
+
|
|
15
|
+
## How it is checked
|
|
16
|
+
|
|
17
|
+
This discipline has no clauses of its own. Its rule is carried by [CD-15](../CD-15/README.md); select that discipline's clauses instead.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# CD-17: Clock is the only time source
|
|
2
|
+
|
|
3
|
+
## Rule
|
|
4
|
+
|
|
5
|
+
Time is an injected capability, not an ambient global: domain code never calls the runtime's now-primitives directly, it reads the current instant through a clock port. Real time enters through exactly one clock abstraction; tests inject a fake clock and advance it deterministically. Bare time construction anywhere else makes behaviour un-fakeable and non-deterministic.
|
|
6
|
+
|
|
7
|
+
The sections below describe what the audit check covers.
|
|
8
|
+
|
|
9
|
+
## Clauses
|
|
10
|
+
|
|
11
|
+
| Clause | Mechanism | Checks |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| `CD-17#clock-sources` | audit | `Date.now()` and `new Date` |
|
|
14
|
+
|
|
15
|
+
Review lens: [di-discipline](../../methods/lenses/di-discipline.md), [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags.
|
|
16
|
+
|
|
17
|
+
## What the check flags
|
|
18
|
+
- `.ts` and `.tsx` files, including tests. Generated folders (`node_modules`, `dist`, `build`, `coverage`, `.git`, root `vendor`) are skipped; any other folder or file can be left out with `exclude` in disciplines.json.
|
|
19
|
+
- Any line containing `Date.now()` or `new Date`, one finding per line. Comments and strings are matched too.
|
|
20
|
+
- Other time sources (`performance.now`, timers) are not checked; they are left to review.
|
|
21
|
+
|
|
22
|
+
## Example violation
|
|
23
|
+
```ts
|
|
24
|
+
const startedAt = Date.now();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## How to fix
|
|
28
|
+
```ts
|
|
29
|
+
const startedAt = clock.now();
|
|
30
|
+
```
|
|
31
|
+
Accept a clock as a dependency and read time only through it. The one real implementation lives in an adapter.
|
|
32
|
+
|
|
33
|
+
## Exceptions
|
|
34
|
+
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` for the file that is the single real clock implementation. 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).
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{ "version": 1, "exceptions": [
|
|
38
|
+
{ "kind": "authorised-location", "clause": "CD-17#clock-sources", "file": "src/adapters/system-clock.ts", "reason": "..." }
|
|
39
|
+
] }
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
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,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"id": "CD-17",
|
|
4
|
+
"clauses": [
|
|
5
|
+
{
|
|
6
|
+
"kind": "mechanical",
|
|
7
|
+
"id": "clock-sources",
|
|
8
|
+
"summary": "Clock is the only time source",
|
|
9
|
+
"mechanisms": [
|
|
10
|
+
"audit"
|
|
11
|
+
],
|
|
12
|
+
"anchor": {
|
|
13
|
+
"kind": "file"
|
|
14
|
+
},
|
|
15
|
+
"cases": {
|
|
16
|
+
"flag": [
|
|
17
|
+
{
|
|
18
|
+
"name": "Date.now call",
|
|
19
|
+
"fileName": "started-at.ts",
|
|
20
|
+
"source": "export const startedAt = Date.now();\n",
|
|
21
|
+
"expectedLines": [
|
|
22
|
+
1
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "new Date construction",
|
|
27
|
+
"fileName": "wall-clock.ts",
|
|
28
|
+
"source": "export const stampNow = (): number => new Date().getTime();\n",
|
|
29
|
+
"expectedLines": [
|
|
30
|
+
1
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"allow": [
|
|
35
|
+
{
|
|
36
|
+
"name": "injected clock",
|
|
37
|
+
"fileName": "injected.ts",
|
|
38
|
+
"source": "export const stamp = (clock: { readonly now: () => number }): number => clock.now();\n",
|
|
39
|
+
"expectedLines": []
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "parsing a date string",
|
|
43
|
+
"fileName": "src/parse.ts",
|
|
44
|
+
"source": "export const parsed = (request: { readonly text: string }): number => Date.parse(request.text);\n",
|
|
45
|
+
"expectedLines": []
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# CD-18: Process-lifecycle operations arrive through an injected port
|
|
2
|
+
|
|
3
|
+
## Rule
|
|
4
|
+
|
|
5
|
+
Process-lifecycle side effects — signal handlers, exit, kill, high-resolution timing — are a capability that arrives through an injected port, not reached for ambiently on the runtime's process global. Confining them behind a port makes lifecycle behaviour composable and fakeable in tests, instead of a hidden dependency on the running process.
|
|
6
|
+
|
|
7
|
+
The sections below describe how the rule is checked.
|
|
8
|
+
|
|
9
|
+
## Clauses
|
|
10
|
+
|
|
11
|
+
| Clause | Mechanism | Checks |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| `CD-18#process-lifecycle-ports` | review | process signals, exit, kill and high-resolution timing arrive through an injected port |
|
|
14
|
+
|
|
15
|
+
Review lens: [di-discipline](../../methods/lenses/di-discipline.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,45 @@
|
|
|
1
|
+
# CD-19: External dependencies confined to wrapping ports at the boundary
|
|
2
|
+
|
|
3
|
+
## Rule
|
|
4
|
+
|
|
5
|
+
Every dependency on code the project does not own — a third-party library or the runtime's own standard library alike — is confined to a single wrapping port at the boundary; the rest of the codebase depends on that port, never the vendor or platform surface, runtime or type-only. A dependency swap then touches one file, the vendor's types never leak inward, and each confined capability is nameable and fakeable in tests. There is no inline carve-out: a stdlib call in the middle of business logic is as much a violation as a scattered library import. Opening a new wrapping site for a new dependency is a deliberate, recorded decision.
|
|
6
|
+
|
|
7
|
+
The sections below describe what the audit check covers.
|
|
8
|
+
|
|
9
|
+
## Clauses
|
|
10
|
+
|
|
11
|
+
| Clause | Mechanism | Checks |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| `CD-19#import-boundaries` | audit | imports of a fixed list of libraries, and any `node:` import |
|
|
14
|
+
|
|
15
|
+
Review lens: [function-first](../../methods/lenses/function-first.md). The lens reviews the whole rule, including what no check flags.
|
|
16
|
+
|
|
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 line with `from "<name>"` for: `eslint winston winston-transport better-sqlite3 pino hono @hono/node-server hono/cors hono/cookie hono/types hono/utils/http-status jose @modelcontextprotocol/sdk zod-to-json-schema uuid`. Type-only imports and matches inside strings are flagged too.
|
|
20
|
+
- A `node:` specifier in an import, `export ... from`, `import("node:...")`, `import type`, `import x = require(...)` or `require("node:...")`. Unprefixed `fs` is not detected.
|
|
21
|
+
- The source rule covers every third-party dependency; the check covers only the list above. The rest is left to review.
|
|
22
|
+
|
|
23
|
+
## Example violation
|
|
24
|
+
```ts
|
|
25
|
+
import { readFileSync } from "node:fs";
|
|
26
|
+
import { v4 } from "uuid";
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## How to fix
|
|
30
|
+
```ts
|
|
31
|
+
import { createFileReader } from "./file-reader.ts";
|
|
32
|
+
import { createIdGenerator } from "./id-generator.ts";
|
|
33
|
+
```
|
|
34
|
+
Import your own port. Only the wrapping file imports the library.
|
|
35
|
+
|
|
36
|
+
## Exceptions
|
|
37
|
+
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` for the file that is the wrapping boundary for that dependency. 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).
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{ "version": 1, "exceptions": [
|
|
41
|
+
{ "kind": "authorised-location", "clause": "CD-19#import-boundaries", "file": "src/adapters/file-reader.ts", "reason": "..." }
|
|
42
|
+
] }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
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,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"id": "CD-19",
|
|
4
|
+
"clauses": [
|
|
5
|
+
{
|
|
6
|
+
"kind": "mechanical",
|
|
7
|
+
"id": "import-boundaries",
|
|
8
|
+
"summary": "External dependencies confined to wrapping ports at the boundary",
|
|
9
|
+
"mechanisms": [
|
|
10
|
+
"audit"
|
|
11
|
+
],
|
|
12
|
+
"anchor": {
|
|
13
|
+
"kind": "file"
|
|
14
|
+
},
|
|
15
|
+
"cases": {
|
|
16
|
+
"flag": [
|
|
17
|
+
{
|
|
18
|
+
"name": "banned library import",
|
|
19
|
+
"fileName": "imports-winston.ts",
|
|
20
|
+
"source": "import winston from \"winston\";\n\nexport const useWinston = (): unknown => winston;\n",
|
|
21
|
+
"expectedLines": [
|
|
22
|
+
1
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "node: import",
|
|
27
|
+
"fileName": "reads-file.ts",
|
|
28
|
+
"source": "import { readFileSync } from \"node:fs\";\n\nexport const read = readFileSync;\n",
|
|
29
|
+
"expectedLines": [
|
|
30
|
+
1
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"name": "require of a node: module",
|
|
35
|
+
"fileName": "requires.ts",
|
|
36
|
+
"source": "export const loaded = require(\"node:path\");\n",
|
|
37
|
+
"expectedLines": [
|
|
38
|
+
1
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"allow": [
|
|
43
|
+
{
|
|
44
|
+
"name": "project-owned import",
|
|
45
|
+
"fileName": "own.ts",
|
|
46
|
+
"source": "import { logger } from \"./logger-port.ts\";\n\nexport const log = logger;\n",
|
|
47
|
+
"expectedLines": []
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "unlisted library import",
|
|
51
|
+
"fileName": "other.ts",
|
|
52
|
+
"source": "import { z } from \"zod\";\n\nexport const schema = z;\n",
|
|
53
|
+
"expectedLines": []
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "unprefixed fs is not detected",
|
|
57
|
+
"fileName": "bare-fs.ts",
|
|
58
|
+
"source": "import { readFileSync } from \"fs\";\n\nexport const read = readFileSync;\n",
|
|
59
|
+
"expectedLines": []
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# CD-2: Closed enumerated list of permitted cast sites
|
|
2
|
+
|
|
3
|
+
## Rule
|
|
4
|
+
|
|
5
|
+
A type assertion tells the compiler the value is something the compiler cannot see — it is a claim the type system can no longer check. Casting is therefore permitted only at a closed, enumerated list of sites where an external boundary genuinely forces it (library-introspection and raw-row narrowing shapes the project names explicitly). Everywhere else a cast is a design smell: the type is wrong, so fix the type rather than assert over it. Adding a site to the permitted list is a deliberate, recorded amendment, not an inline decision.
|
|
6
|
+
|
|
7
|
+
The sections below describe what the audit check covers.
|
|
8
|
+
|
|
9
|
+
## Clauses
|
|
10
|
+
|
|
11
|
+
| Clause | Mechanism | Checks |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| `CD-2#cast-expressions` | audit | a type assertion that is not on the permitted list |
|
|
14
|
+
|
|
15
|
+
Review lens: [type-soundness](../../methods/lenses/type-soundness.md). The lens reviews the whole rule, including what no check flags.
|
|
16
|
+
|
|
17
|
+
## What the check flags
|
|
18
|
+
- `.ts` and `.tsx` files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
19
|
+
- Every `x as T` and `<T>x` assertion except the permitted forms. Assertions that CD-1 reports (`any`) are not repeated here.
|
|
20
|
+
- Permitted: `as unknown`, `as const`, `as <name>` where the name is imported by name from `zod` (including `zod/...`), `<expr>.value as Array<...>` or `ReadonlyArray<...>`, and `as Tool["inputSchema"]`.
|
|
21
|
+
- The permitted list is fixed in the check and is not configurable. Further sites are handled as exceptions.
|
|
22
|
+
|
|
23
|
+
## Example violation
|
|
24
|
+
```ts
|
|
25
|
+
const user = response as User;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## How to fix
|
|
29
|
+
```ts
|
|
30
|
+
const user = userSchema.parse(response);
|
|
31
|
+
```
|
|
32
|
+
Parse or narrow the value so the type follows from a check rather than from an assertion.
|
|
33
|
+
|
|
34
|
+
## Exceptions
|
|
35
|
+
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file sits on an external boundary that forces an assertion, such as an adapter. 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-2#cast-expressions", "file": "src/adapters/row-reader.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.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"id": "CD-2",
|
|
4
|
+
"clauses": [
|
|
5
|
+
{
|
|
6
|
+
"kind": "mechanical",
|
|
7
|
+
"id": "cast-expressions",
|
|
8
|
+
"summary": "Closed enumerated list of permitted cast sites",
|
|
9
|
+
"mechanisms": [
|
|
10
|
+
"audit"
|
|
11
|
+
],
|
|
12
|
+
"anchor": {
|
|
13
|
+
"kind": "file"
|
|
14
|
+
},
|
|
15
|
+
"cases": {
|
|
16
|
+
"flag": [
|
|
17
|
+
{
|
|
18
|
+
"name": "assertion to a domain type",
|
|
19
|
+
"fileName": "bad-cast.ts",
|
|
20
|
+
"source": "type Category = \"inbox\" | \"today\";\nexport const forceCategory = (rawText: string): Category => {\n return rawText as Category;\n};\n",
|
|
21
|
+
"expectedLines": [
|
|
22
|
+
3
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "assertion on a parsed json body",
|
|
27
|
+
"fileName": "bad-json-cast.ts",
|
|
28
|
+
"source": "export const parseResponseUnsafely = async <T>(response: Response): Promise<T> => {\n const parsed = await response.json();\n return parsed as T;\n};\n",
|
|
29
|
+
"expectedLines": [
|
|
30
|
+
3
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"name": "angle-bracket assertion",
|
|
35
|
+
"fileName": "angle.ts",
|
|
36
|
+
"source": "interface User { readonly id: string }\ndeclare const raw: unknown;\nexport const user = <User>raw;\n",
|
|
37
|
+
"expectedLines": [
|
|
38
|
+
3
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"allow": [
|
|
43
|
+
{
|
|
44
|
+
"name": "as unknown",
|
|
45
|
+
"fileName": "unknown.ts",
|
|
46
|
+
"source": "export const parsed = JSON.parse(text) as unknown;\n",
|
|
47
|
+
"expectedLines": []
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "as const",
|
|
51
|
+
"fileName": "const-assertion.ts",
|
|
52
|
+
"source": "export const PERMITTED_LITERAL = \"permitted\" as const;\n",
|
|
53
|
+
"expectedLines": []
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "as a name imported from zod",
|
|
57
|
+
"fileName": "zod-cast.ts",
|
|
58
|
+
"source": "import { z } from \"zod\";\ndeclare const raw: unknown;\nexport const schema = raw as z;\n",
|
|
59
|
+
"expectedLines": []
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|