@hailstails/hone 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ADOPTING.md +8 -8
- package/CHANGELOG.md +36 -0
- package/MIGRATING.md +40 -0
- package/README.md +28 -7
- package/api/audit.d.ts +1 -1
- package/api/testing.js +3 -3
- package/chunks/{chunk-H4V72FCW.js → chunk-2O46EB4E.js} +15 -1
- package/chunks/chunk-335ITLPO.js +7 -0
- package/chunks/{chunk-YSN46EB3.js → chunk-5U4VTFD5.js} +347 -664
- package/chunks/{chunk-PL2PNPAR.js → chunk-E6VR3VRV.js} +1 -6
- package/chunks/chunk-WF3PPYRR.js +27 -0
- package/core/check/tool-command.js +1120 -105
- package/core/mechanism-port/runner-result-types.d.ts +10 -0
- package/docs/adding-a-discipline-or-mechanism.md +5 -3
- package/docs/extending.md +2 -0
- package/docs/output-contract.md +64 -11
- package/mechanisms/audit/CD-27/test-body-logic.js +397 -46
- package/mechanisms/audit/runner/runner.js +5 -3
- package/mechanisms/audit/runner/typescript-parse.d.ts +2 -0
- package/mechanisms/audit/runner/walker-piece.d.ts +2 -1
- package/mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js +7 -4
- package/mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js +21 -11
- package/mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.js +15 -5
- package/mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.js +7 -3
- package/mechanisms/eslint/CD-41/README.md +1 -1
- package/mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.js +100 -28
- package/mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.js +8 -4
- package/mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.js +8 -4
- package/mechanisms/eslint/runner/README.md +9 -2
- package/mechanisms/eslint/runner/runner.js +1410 -1384
- package/methods/assessment-template.md +2 -2
- package/methods/lenses/clean-architecture.md +7 -8
- package/methods/lenses/defended-on-intent.md +2 -2
- package/methods/lenses/di-discipline.md +14 -18
- package/methods/lenses/function-first.md +16 -18
- package/methods/lenses/test-discipline.md +1 -1
- package/package.json +1 -1
- package/rules/CD-1/CHECKS.md +6 -2
- package/rules/CD-1/README.md +6 -19
- package/rules/CD-10/CHECKS.md +5 -3
- package/rules/CD-10/README.md +6 -18
- package/rules/CD-11/CHECKS.md +4 -2
- package/rules/CD-11/README.md +6 -16
- package/rules/CD-12/CHECKS.md +4 -2
- package/rules/CD-12/README.md +6 -16
- package/rules/CD-13/CHECKS.md +4 -2
- package/rules/CD-13/README.md +6 -16
- package/rules/CD-14/CHECKS.md +3 -1
- package/rules/CD-14/README.md +6 -19
- package/rules/CD-15/CHECKS.md +5 -1
- package/rules/CD-15/README.md +5 -20
- package/rules/CD-16/CHECKS.md +3 -1
- package/rules/CD-16/README.md +6 -6
- package/rules/CD-17/CHECKS.md +3 -1
- package/rules/CD-17/README.md +6 -19
- package/rules/CD-18/CHECKS.md +4 -2
- package/rules/CD-18/README.md +6 -16
- package/rules/CD-19/CHECKS.md +8 -6
- package/rules/CD-19/README.md +6 -20
- package/rules/CD-2/CHECKS.md +7 -3
- package/rules/CD-2/README.md +6 -21
- package/rules/CD-20/CHECKS.md +3 -1
- package/rules/CD-20/README.md +6 -6
- package/rules/CD-21/CHECKS.md +4 -2
- package/rules/CD-21/README.md +6 -15
- package/rules/CD-22/CHECKS.md +4 -2
- package/rules/CD-22/README.md +6 -15
- package/rules/CD-23/CHECKS.md +5 -3
- package/rules/CD-23/README.md +6 -17
- package/rules/CD-24/CHECKS.md +3 -1
- package/rules/CD-24/README.md +6 -6
- package/rules/CD-25/CHECKS.md +5 -3
- package/rules/CD-25/README.md +5 -21
- package/rules/CD-26/CHECKS.md +5 -3
- package/rules/CD-26/README.md +6 -20
- package/rules/CD-27/CHECKS.md +394 -9
- package/rules/CD-27/README.md +6 -20
- package/rules/CD-27/discipline.json +130 -0
- package/rules/CD-28/CHECKS.md +4 -2
- package/rules/CD-28/README.md +6 -16
- package/rules/CD-29/CHECKS.md +4 -2
- package/rules/CD-29/README.md +6 -14
- package/rules/CD-3/CHECKS.md +3 -1
- package/rules/CD-3/README.md +6 -17
- package/rules/CD-30/CHECKS.md +4 -2
- package/rules/CD-30/README.md +6 -15
- package/rules/CD-31/CHECKS.md +4 -2
- package/rules/CD-31/README.md +6 -14
- package/rules/CD-32/CHECKS.md +3 -1
- package/rules/CD-32/README.md +2 -0
- package/rules/CD-33/CHECKS.md +3 -1
- package/rules/CD-33/README.md +2 -0
- package/rules/CD-34/CHECKS.md +3 -1
- package/rules/CD-34/README.md +2 -0
- package/rules/CD-39/CHECKS.md +3 -1
- package/rules/CD-39/README.md +2 -0
- package/rules/CD-4/CHECKS.md +4 -2
- package/rules/CD-4/README.md +6 -17
- package/rules/CD-40/CHECKS.md +3 -1
- package/rules/CD-40/README.md +6 -20
- package/rules/CD-41/CHECKS.md +14 -2
- package/rules/CD-41/README.md +6 -20
- package/rules/CD-41/discipline.json +14 -0
- package/rules/CD-42/CHECKS.md +3 -1
- package/rules/CD-42/README.md +6 -16
- package/rules/CD-43/CHECKS.md +3 -1
- package/rules/CD-43/README.md +6 -18
- package/rules/CD-44/CHECKS.md +3 -1
- package/rules/CD-44/README.md +6 -17
- package/rules/CD-45/CHECKS.md +4 -2
- package/rules/CD-45/README.md +6 -16
- package/rules/CD-46/CHECKS.md +3 -1
- package/rules/CD-46/README.md +2 -0
- package/rules/CD-47/CHECKS.md +4 -2
- package/rules/CD-47/README.md +4 -20
- package/rules/CD-5/CHECKS.md +4 -2
- package/rules/CD-5/README.md +6 -19
- package/rules/CD-6/CHECKS.md +3 -1
- package/rules/CD-6/README.md +6 -19
- package/rules/CD-7/CHECKS.md +3 -1
- package/rules/CD-7/README.md +6 -20
- package/rules/CD-7a/CHECKS.md +3 -1
- package/rules/CD-7a/README.md +6 -17
- package/rules/CD-8/CHECKS.md +3 -1
- package/rules/CD-8/README.md +6 -17
- package/rules/CD-9/CHECKS.md +4 -2
- package/rules/CD-9/README.md +6 -17
- package/rules/README.md +71 -54
- package/rules/SPIRIT.md +3 -3
- package/rules/cases.md +94 -0
- package/rules/numbers.md +155 -0
- package/rules/principles.md +89 -0
- package/rules/records.md +150 -0
- package/rules/rules.md +149 -0
- package/rules/sources.md +142 -0
- package/rules/typescript/checks.md +219 -0
- package/rules/typescript/recipes.md +361 -0
- package/rules/typescript/symptoms.json +1005 -0
- package/rules/typescript/symptoms.md +612 -0
- package/chunks/chunk-YLZ73C7O.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Disciplines assessment
|
|
2
2
|
|
|
3
|
-
What this repository's checks are telling us, and where the code is going. Each clause section sharpens
|
|
3
|
+
What this repository's checks are telling us, and where the code is going. Each clause section sharpens what the symptoms page says for this codebase; it does not repeat the rule. Read a clause's section before changing code to make its check pass.
|
|
4
4
|
|
|
5
5
|
## Rules adopted
|
|
6
6
|
|
|
@@ -26,7 +26,7 @@ Applied in review with the lens each rule page names.
|
|
|
26
26
|
|
|
27
27
|
## <clause address>
|
|
28
28
|
|
|
29
|
-
- **Cause here:** <a
|
|
29
|
+
- **Cause here:** <a case or breach site from the symptom's "May indicate" or "Breach usually sits", named as the symptoms page names it>. <How it shows in this codebase.>
|
|
30
30
|
- **Sites:** <count> at <commit>, in <folders or files>. For example <file:line>, <file:line>.
|
|
31
31
|
- **Forward goal:** <the cleaner design, in this codebase's terms>.
|
|
32
32
|
- **Steps:** 1. <the step that unlocks the rest> 2. <the next step>
|
|
@@ -70,9 +70,9 @@ outer layer?*
|
|
|
70
70
|
- **Inner code importing a storage/driver primitive.** Inner layers (domain,
|
|
71
71
|
application) importing a database driver, a filesystem module, or any raw
|
|
72
72
|
storage primitive is a finding against the repository-port rule: the inner code
|
|
73
|
-
reached around the port. The correct shape is a port
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
reached around the port. The correct shape is a port declared in the domain,
|
|
74
|
+
in a module of its own, an adapter that fulfils it, and one entry-point module
|
|
75
|
+
that builds the adapter and passes it in.
|
|
76
76
|
- **Type-only does not escape.** A type-only import still couples the consumer to
|
|
77
77
|
the outer world's type shape; if the rules say type-only follows the same rule,
|
|
78
78
|
read it the same way as a runtime import.
|
|
@@ -147,11 +147,10 @@ re-tagging the rule another lens owns):
|
|
|
147
147
|
the boundary observation rather than inventing a layering rule that doesn't carry
|
|
148
148
|
this lens tag. The wrapping-factory file *is* the permitted seam; the boundary
|
|
149
149
|
violation is only the import that skips it.
|
|
150
|
-
- **
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
clean-architecture finding of its own.
|
|
150
|
+
- **Adapter built outside the root.** One entry-point module builds every
|
|
151
|
+
adapter and passes each one in; the *internal shape* of the port (capability
|
|
152
|
+
naming, generic binding) is the DI lens's lane. Note an adapter built anywhere
|
|
153
|
+
else as a sibling observation, not as a clean-architecture finding of its own.
|
|
155
154
|
|
|
156
155
|
Vague phrasings ("this coupling feels wrong", "might leak data") are the lens's own
|
|
157
156
|
failure mode — every finding names the specific boundary and the rule that draws it.
|
|
@@ -132,8 +132,8 @@ principle (e.g. "every dependency outside the unit boundary is replaced by a tes
|
|
|
132
132
|
dependency injection, never reached around") — is "no substitution outside DI". The
|
|
133
133
|
unlisted mechanism *is* substitution outside DI; it passes the letter and fails the
|
|
134
134
|
intent. The structural reframing: the unit consumes the dependency as an
|
|
135
|
-
injected port through its argument seam, production
|
|
136
|
-
implementation
|
|
135
|
+
injected port through its argument seam, production builds the real
|
|
136
|
+
implementation at the entry point and passes it in, the test injects a test double directly;
|
|
137
137
|
the PASS retracts and becomes a DI/testing VIOLATION on the owning lens.
|
|
138
138
|
|
|
139
139
|
The three properties that make a finding sound — and that an author can
|
|
@@ -15,9 +15,9 @@ the code: every technical binding a unit needs — wall-clock time, process and
|
|
|
15
15
|
signal lifecycle, standard-library capabilities (filesystem, crypto, path, net),
|
|
16
16
|
and third-party services — arrives through a named port the unit receives as a
|
|
17
17
|
constructor parameter or function argument, never reached for through a global,
|
|
18
|
-
an ambient import, or the module system.
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
an ambient import, or the module system. The port's interface is declared in
|
|
19
|
+
the domain, in a module of its own; one entry-point module builds every
|
|
20
|
+
adapter and passes each one in, and tests inject a test double of the same shape. The test face is the
|
|
21
21
|
mirror image: a unit test replaces *everything* outside the unit's boundary with a
|
|
22
22
|
test double, and it delivers those doubles the same way production delivers the
|
|
23
23
|
real ones — through the
|
|
@@ -72,18 +72,15 @@ reached for through the module system). Walk the diff for both.
|
|
|
72
72
|
violation-in-waiting even if it currently delegates to a helper that itself
|
|
73
73
|
holds the raw call. The composition pathway must terminate at an injected port,
|
|
74
74
|
not at a buried global.
|
|
75
|
-
- **
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
downstream — flag the absence preemptively. Conversely, consumers that
|
|
80
|
-
construct an ad-hoc object literal matching the port shape outside test code,
|
|
81
|
-
instead of importing the default factory, are reaching around the port.
|
|
75
|
+
- **Adapter built outside the root.** One entry-point module builds every
|
|
76
|
+
adapter and passes each one in. A call to an adapter's factory anywhere but
|
|
77
|
+
the entry point is a finding: the calling unit builds what it should be
|
|
78
|
+
passed. No port is declared in an adapter's module or in its consumer's.
|
|
82
79
|
- **Composition-root threading.** The boot path (the service-run entrypoint, the
|
|
83
|
-
app start module, the kernel composition) must
|
|
80
|
+
app start module, the kernel composition) must build each adapter and
|
|
84
81
|
pass the port into the unit that declared it. A unit that *declares* a port
|
|
85
82
|
parameter but is never wired to one in the boot path is a threading violation;
|
|
86
|
-
a boot path that
|
|
83
|
+
a unit outside the boot path that builds an adapter itself is
|
|
87
84
|
the same gap from the other end.
|
|
88
85
|
- **Type-level context constraint.** Where the rules require context-consuming
|
|
89
86
|
middleware (or any generic that reads kernel-shipped context fields) to bind
|
|
@@ -117,10 +114,9 @@ reached for through the module system). Walk the diff for both.
|
|
|
117
114
|
attached to**: a DI-delivered test double (permitted) or an imported binding
|
|
118
115
|
(violation).
|
|
119
116
|
- **Test doubles through the seam are not module interception.** A test that
|
|
120
|
-
constructs a stub or spy as an object literal, a factory-built stub, a
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
channels toward — not a finding. In common speech "mock" covers both a double
|
|
117
|
+
constructs a stub or spy as an object literal, a factory-built stub, or a
|
|
118
|
+
recording spy function, and delivers it through the unit's constructor or
|
|
119
|
+
argument, is the exact pattern the discipline channels toward — not a finding. In common speech "mock" covers both a double
|
|
124
120
|
passed through the seam and module interception. In the taxonomy a mock is only
|
|
125
121
|
a double that verifies expectations set on it, and module interception is not a
|
|
126
122
|
double at all: the rules permit doubles through the seam and forbid
|
|
@@ -149,7 +145,7 @@ raw global call on a "convenience" path; a default factory present but the boot
|
|
|
149
145
|
path constructing the port inline beside it; a middleware generic that compiles
|
|
150
146
|
because its context happens to carry the field, yet is unbound so a different
|
|
151
147
|
pipeline would crash; a spy that looks like clean observation but is attached to
|
|
152
|
-
an imported module;
|
|
148
|
+
an imported module; a stub that is actually wired through module
|
|
153
149
|
interception rather than the seam. A finding here must explain *how the code reads
|
|
154
150
|
DI-clean yet the dependency is still reached for ambiently*, grounded in the
|
|
155
151
|
specific loaded rule. Vague phrasings ("tight coupling", "hard to test") are the
|
|
@@ -158,7 +154,7 @@ lens's own failure mode.
|
|
|
158
154
|
## Output shape
|
|
159
155
|
|
|
160
156
|
Report **two-sided** counts the review asks for: a production-side
|
|
161
|
-
block (ambient-binding violations by capability,
|
|
157
|
+
block (ambient-binding violations by capability, adapters built outside the root,
|
|
162
158
|
threading gaps, unbound context generics) and a test-side block
|
|
163
159
|
(module-interception violations by mechanism, spy classifications, structural
|
|
164
160
|
boundary gaps). Every finding is
|
|
@@ -31,13 +31,11 @@ Four facets of the same stance:
|
|
|
31
31
|
the transformation as data. Counted loops name a counter where the operation
|
|
32
32
|
is what matters. Side-effect-only iteration is the one place an imperative
|
|
33
33
|
shape survives, and even then under a `void`-returning callback.
|
|
34
|
-
- **
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
`new X(...)` and the raw import are quarantined behind a function-shaped
|
|
40
|
-
surface.
|
|
34
|
+
- **Outside dependencies confined to their adapter.** An outside dependency or
|
|
35
|
+
runtime module is imported only in the adapter file for the party it reaches
|
|
36
|
+
(runtime *and* type-only). That adapter fulfils a port and returns our types.
|
|
37
|
+
Nothing re-exports the outside dependency. A library's class is built only in
|
|
38
|
+
its adapter.
|
|
41
39
|
- **Single-object-argument functions.** Every authored function takes exactly
|
|
42
40
|
one parameter; multiple values pass as named fields on an object. Positional
|
|
43
41
|
multi-argument signatures are forbidden except for callbacks whose signature is
|
|
@@ -73,9 +71,9 @@ per-declaration not per-export — is suspect until classified. For each, decide
|
|
|
73
71
|
one of three buckets:
|
|
74
72
|
|
|
75
73
|
- **justified.** The declaration is the single permitted authored class at its
|
|
76
|
-
named site, OR it is a `new X(...)` for an external-library class
|
|
77
|
-
|
|
78
|
-
closure and never re-exported as a class. Cite the carve-out; no replacement.
|
|
74
|
+
named site, OR it is a `new X(...)` for an external-library class in
|
|
75
|
+
the adapter for the party it reaches, with a boundary record, AND the instance
|
|
76
|
+
is held inside the closure and never re-exported as a class. Cite the carve-out; no replacement.
|
|
79
77
|
- **closure-candidate.** The class carries genuine instance state that is
|
|
80
78
|
*mutated* across method calls (counters, caches, accumulating buffers,
|
|
81
79
|
subscription registries, in-flight tracking). Replacement: a factory closing
|
|
@@ -135,15 +133,15 @@ counter-shaped `for`, not a direction. An async-iterator loop has no source-side
|
|
|
135
133
|
carve-out unless the rules grant one — lift it into a Promise-reduce pipeline or
|
|
136
134
|
an event `forEach` handler by shape.
|
|
137
135
|
|
|
138
|
-
###
|
|
136
|
+
### Adapter pass
|
|
139
137
|
|
|
140
|
-
Every raw
|
|
141
|
-
an external-library class is a candidate. For each: is the importing
|
|
142
|
-
file
|
|
143
|
-
yes → justified. If the
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
138
|
+
Every raw outside-dependency import (runtime *or* type-only) and every `new X(...)`
|
|
139
|
+
for an external-library class is a candidate. For each: is the importing or
|
|
140
|
+
instantiating file the adapter for the party it reaches, with a boundary record?
|
|
141
|
+
If yes → justified. If not, the import is in the wrong place — a function-first
|
|
142
|
+
finding with a DI/port cross-reference (the raw import escaping its adapter is
|
|
143
|
+
both a structural and a boundary-discipline defect; name the boundary lens as the
|
|
144
|
+
cross-reference). A
|
|
147
145
|
`new X(...)` for a class the codebase itself authored is a finding twice over —
|
|
148
146
|
the class should not have been authored, and the instantiation is the symptom.
|
|
149
147
|
|
|
@@ -20,7 +20,7 @@ recur across codebases under different names:
|
|
|
20
20
|
threshold.
|
|
21
21
|
- **Zero-everything tests.** A test body is a straight line: arrange → act →
|
|
22
22
|
assert. No control flow, no loops, no branches, no mutated capture, no
|
|
23
|
-
unpredictability. N cases means N tests. Uniform cases, such as the rows of a table, are one parameterised test over the rows (the framework's `each`), never a loop inside a test body, and never one hand-written test per row. Variability is supplied by injected test doubles (stubs with canned answers
|
|
23
|
+
unpredictability. N cases means N tests. Uniform cases, such as the rows of a table, are one parameterised test over the rows (the framework's `each`), never a loop inside a test body, and never one hand-written test per row. Variability is supplied by injected test doubles (stubs with canned answers), never computed inside the test.
|
|
24
24
|
- **Assert only the unit's own responsibility.** A test inspects what its unit
|
|
25
25
|
produces and how it calls its collaborators — never the internal logic of a
|
|
26
26
|
delegate reached transitively.
|
package/package.json
CHANGED
package/rules/CD-1/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-1 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptoms: [Claimed type](../typescript/symptoms.md#claimed-type) and [Untyped value](../typescript/symptoms.md#untyped-value).
|
|
4
|
+
|
|
5
|
+
Read [the verdict and the named pages it points at](README.md) first. This page is the mechanics: what each check flags and misses, how to fix a flagged site, and how to record an exception.
|
|
4
6
|
|
|
5
7
|
## Clauses
|
|
6
8
|
|
|
@@ -31,7 +33,9 @@ const parsed = JSON.parse(text) as any;
|
|
|
31
33
|
```ts
|
|
32
34
|
const order = orderSchema.parse(JSON.parse(text));
|
|
33
35
|
```
|
|
34
|
-
Give it a concrete type where it enters: parse it with a schema
|
|
36
|
+
Give it a concrete type where it enters: parse it once with a schema in the adapter for whoever produced it, checked at runtime.
|
|
37
|
+
|
|
38
|
+
In a test file, edition 2 of `CD-27#test-body-logic` flags `JSON.parse`; edition 1, the default, does not.
|
|
35
39
|
|
|
36
40
|
## Exceptions
|
|
37
41
|
CD-1 is exempted like any other discipline: record an `authorised-location`, a `file-carve-out` for existing debt, or a clause-wide carve-out in `discipline-exceptions.json`. A carved or authorised file keeps its existing `any`; an `any` anywhere else still fails. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|
package/rules/CD-1/README.md
CHANGED
|
@@ -2,27 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Rule
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This numbered page is the earlier form of this rule. The [named pages](../README.md) govern where they differ, and [Every CD](../numbers.md) maps each number to its names.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Spirit
|
|
7
|
+
**Verdict.** Symptom of [Declared, not asserted](../rules.md#declared-not-asserted).
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Declared, not asserted](../rules.md#declared-not-asserted).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *Input never typed where it entered.* A request, file, parse or database row crossed in and nobody said what it is. Give it a concrete type at that boundary, checked at runtime.
|
|
15
|
-
- *A shape nobody named.* The value has a shape that was never declared. Declare it as a type or a union.
|
|
16
|
-
- *A library kept at arm's length.* The vendor's types were awkward, so they were dropped. Wrap the library once and hand the rest of the code your own type.
|
|
17
|
-
- *One function serving many shapes.* It takes anything because its callers differ. Split it, or make the variants an explicit union.
|
|
18
|
-
|
|
19
|
-
**Where to go.** Every value inside the codebase has a known type. Unknown data becomes concrete where it arrives, not somewhere further in. A high count is usually one or two boundaries that were never built; build those first and most sites go with them.
|
|
11
|
+
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).
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
- "It's just tests." A test that needs an untyped value builds its input the wrong way. Build the real type.
|
|
23
|
-
- "The library forces it." It forces it at one call. One wrapping file holds that.
|
|
24
|
-
- "Swap it for unknown." Unknown carried inward is the same debt, deferred. Very few values should stay unknown past the boundary.
|
|
13
|
+
## Spirit
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
- *Parse, don't validate* (Alexis King). Turn untyped input into a typed value once, where it arrives, so everything after it can rely on the type.
|
|
28
|
-
- *Make illegal states unrepresentable* (Yaron Minsky). A precise type or union rules out shapes the code cannot handle; an untyped value rules out nothing.
|
|
15
|
+
Start from the symptom a finding names: [Claimed type](../typescript/symptoms.md#claimed-type) and [Untyped value](../typescript/symptoms.md#untyped-value). Each symptom names the cases it may indicate and the rules they point at. The why is on [The type checker proves it](../principles.md#the-type-checker-proves-it).
|
package/rules/CD-10/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-10 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptoms: [Throw or catch in a test](../typescript/symptoms.md#throw-or-catch-in-a-test) and [Thrown non-error](../typescript/symptoms.md#thrown-non-error).
|
|
4
|
+
|
|
5
|
+
Read [the verdict and the named pages it points at](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
6
|
|
|
5
7
|
## Clauses
|
|
6
8
|
|
|
@@ -38,11 +40,11 @@ it("loads the account", () => {
|
|
|
38
40
|
Assert on the whole result. Branching in tests is also reported by CD-27.
|
|
39
41
|
|
|
40
42
|
## Exceptions
|
|
41
|
-
Add an entry to `discipline-exceptions.json` at the repository root. Use `
|
|
43
|
+
Add an entry to `discipline-exceptions.json` at the repository root. Use `file-carve-out` for debt in one file: it is forfeited once the file is touched, and needs no `whyChain`. The form accepts an `authorised-location` for this clause, as for any; in spirit [Throw or catch in a test](../typescript/symptoms.md#throw-or-catch-in-a-test) has no correct use, and a reviewer refuses one. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|
|
42
44
|
|
|
43
45
|
```json
|
|
44
46
|
{ "version": 1, "exceptions": [
|
|
45
|
-
{ "kind": "
|
|
47
|
+
{ "kind": "file-carve-out", "clause": "CD-10#throws-in-tests", "file": "src/legacy/charge.test.ts" }
|
|
46
48
|
] }
|
|
47
49
|
```
|
|
48
50
|
|
package/rules/CD-10/README.md
CHANGED
|
@@ -2,26 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Rule
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This numbered page is the earlier form of this rule. The [named pages](../README.md) govern where they differ, and [Every CD](../numbers.md) maps each number to its names.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Spirit
|
|
7
|
+
**Verdict.** Splits: Failures are values; Straight-through tests; throw-only-error a check.
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Failures are values](../rules.md#failures-are-values), [Straight-through tests](../rules.md#straight-through-tests), [Failure asserted as a value](../typescript/recipes.md#failure-asserted-as-a-value) and [Failure mapping at the adapter](../typescript/recipes.md#failure-mapping-at-the-adapter).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *A defensive "can't happen".* A throw guards a state the code believes impossible. If you can name the state, model it as a result variant or rule it out with a type.
|
|
15
|
-
- *A library that throws, caught too late.* Exceptions escape into the core. Catch at the wrapping boundary and return a result.
|
|
16
|
-
- *Tests that throw to fail.* A test throws instead of asserting. Assert on the result; the assertion is the failure.
|
|
17
|
-
- *Failure modes nobody listed.* Errors are thrown because no error type exists yet. List the ways the operation fails.
|
|
18
|
-
|
|
19
|
-
**Where to go.** Throws exist only for a failed startup invariant and a branch the types prove unreachable. Everything else returns its failure.
|
|
11
|
+
Review lens: [errors-as-data](../../methods/lenses/errors-as-data.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).
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
- "It really can't happen." Then the type can say so, and the throw is unnecessary.
|
|
23
|
-
- "Results are verbose." They are the failure paths written down. A throw hides the same paths.
|
|
13
|
+
## Spirit
|
|
24
14
|
|
|
25
|
-
|
|
26
|
-
- *Railway oriented programming* (Scott Wlaschin). Success and failure travel as two tracks of one value, so failure is handled, not escaped.
|
|
27
|
-
- *Fail fast.* A broken startup invariant stops the program at once; that is the one place a throw is the clearest signal.
|
|
15
|
+
Start from the symptom a finding names: [Throw or catch in a test](../typescript/symptoms.md#throw-or-catch-in-a-test) and [Thrown non-error](../typescript/symptoms.md#thrown-non-error). Each symptom names the cases it may indicate and the rules they point at. The why is on [The type checker proves it](../principles.md#the-type-checker-proves-it) and [Tests are ours](../principles.md#tests-are-ours).
|
package/rules/CD-11/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-11 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Recipe: [Result union](../typescript/recipes.md#result-union). The outcome it protects is seen by [Failure shaped as success](../typescript/symptoms.md#failure-shaped-as-success).
|
|
4
|
+
|
|
5
|
+
Read [the verdict and the named pages it points at](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
6
|
|
|
5
7
|
## Clauses
|
|
6
8
|
|
|
@@ -10,4 +12,4 @@ Read [the rule and its spirit](README.md) first. This page is the mechanics: how
|
|
|
10
12
|
|
|
11
13
|
## How it is checked
|
|
12
14
|
|
|
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
|
|
15
|
+
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 named rules](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.
|
package/rules/CD-11/README.md
CHANGED
|
@@ -2,24 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Rule
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This numbered page is the earlier form of this rule. The [named pages](../README.md) govern where they differ, and [Every CD](../numbers.md) maps each number to its names.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Spirit
|
|
7
|
+
**Verdict.** Recipe for [Failures are values](../rules.md#failures-are-values).
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Failures are values](../rules.md#failures-are-values) and [Result union](../typescript/recipes.md#result-union).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *Error hierarchies built by inheritance.* Error kinds are subclasses. Make them variants of one tagged union.
|
|
15
|
-
- *Errors carrying behaviour.* Error objects have methods. Move the behaviour into functions that take the error.
|
|
16
|
-
- *Errors that cannot cross a boundary.* Class instances lose their type when serialised. Plain data survives.
|
|
17
|
-
|
|
18
|
-
**Where to go.** Each error is plain data with a tag, built by a factory and dispatched by an exhaustive switch.
|
|
11
|
+
Review lens: [errors-as-data](../../methods/lenses/errors-as-data.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).
|
|
19
12
|
|
|
20
|
-
|
|
21
|
-
- "Stack traces need the error class." Operational failures are expected outcomes, not bugs; they need context, not a trace.
|
|
13
|
+
## Spirit
|
|
22
14
|
|
|
23
|
-
|
|
24
|
-
- *Make illegal states unrepresentable* (Yaron Minsky). A closed union lists exactly the failures that exist; an open class hierarchy admits any subclass.
|
|
25
|
-
- *Algebraic data types.* A tagged union of error variants is checked for exhaustiveness wherever it is handled.
|
|
15
|
+
Start from the symptom a finding names: [Failure shaped as success](../typescript/symptoms.md#failure-shaped-as-success) and [Catch-all failure kind](../typescript/symptoms.md#catch-all-failure-kind). Each symptom names the cases it may indicate and the rules they point at. The why is on [The type checker proves it](../principles.md#the-type-checker-proves-it).
|
package/rules/CD-12/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-12 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Recipe: [Port in the domain](../typescript/recipes.md#port-in-the-domain). The outcome it protects is seen by [Port outside the domain](../typescript/symptoms.md#port-outside-the-domain).
|
|
4
|
+
|
|
5
|
+
Read [the verdict and the named pages it points at](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
6
|
|
|
5
7
|
## Clauses
|
|
6
8
|
|
|
@@ -10,4 +12,4 @@ Read [the rule and its spirit](README.md) first. This page is the mechanics: how
|
|
|
10
12
|
|
|
11
13
|
## How it is checked
|
|
12
14
|
|
|
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
|
|
15
|
+
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 named rules](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.
|
package/rules/CD-12/README.md
CHANGED
|
@@ -2,24 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Rule
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This numbered page is the earlier form of this rule. The [named pages](../README.md) govern where they differ, and [Every CD](../numbers.md) maps each number to its names.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Spirit
|
|
7
|
+
**Verdict.** Recipe for [Ports declared inside](../rules.md#ports-declared-inside).
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Ports declared inside](../rules.md#ports-declared-inside) and [Port in the domain](../typescript/recipes.md#port-in-the-domain).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *Queries written in domain code.* Domain functions call the driver directly. Move the query behind a repository method named for what the domain needs.
|
|
15
|
-
- *A repository that leaks its driver.* The port returns driver rows or types. Return domain shapes.
|
|
16
|
-
- *Files used as storage directly.* Filesystem calls sit in domain logic. Put them behind a repository too.
|
|
17
|
-
|
|
18
|
-
**Where to go.** The domain depends on repository ports. Adapters compose the driver behind them.
|
|
11
|
+
Review lens: [clean-architecture](../../methods/lenses/clean-architecture.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).
|
|
19
12
|
|
|
20
|
-
|
|
21
|
-
- "We'll never change the database." The port is also what lets tests use an in-memory fake of storage.
|
|
13
|
+
## Spirit
|
|
22
14
|
|
|
23
|
-
|
|
24
|
-
- *Repository* (Martin Fowler, *Patterns of Enterprise Application Architecture*). A collection-like interface between the domain and data mapping.
|
|
25
|
-
- *Dependency Inversion Principle* (Robert C. Martin, SOLID). The domain defines what it needs; storage implements it.
|
|
15
|
+
Start from the symptom a finding names: [Port outside the domain](../typescript/symptoms.md#port-outside-the-domain). Each symptom names the cases it may indicate and the rules they point at. The why is on [External behaviour sits at a boundary](../principles.md#external-behaviour-sits-at-a-boundary).
|
package/rules/CD-13/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-13 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptom: [Inner layer imports outer](../typescript/symptoms.md#inner-layer-imports-outer).
|
|
4
|
+
|
|
5
|
+
Read [the verdict and the named pages it points at](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
6
|
|
|
5
7
|
## Clauses
|
|
6
8
|
|
|
@@ -10,4 +12,4 @@ Read [the rule and its spirit](README.md) first. This page is the mechanics: how
|
|
|
10
12
|
|
|
11
13
|
## How it is checked
|
|
12
14
|
|
|
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
|
|
15
|
+
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 named rules](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.
|
package/rules/CD-13/README.md
CHANGED
|
@@ -2,24 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Rule
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This numbered page is the earlier form of this rule. The [named pages](../README.md) govern where they differ, and [Every CD](../numbers.md) maps each number to its names.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Spirit
|
|
7
|
+
**Verdict.** Keeps: [Ports declared inside](../rules.md#ports-declared-inside).
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Ports declared inside](../rules.md#ports-declared-inside) and [Port in the domain](../typescript/recipes.md#port-in-the-domain).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *The domain reaching for infrastructure.* Domain code imports an adapter or transport. Declare a port in the inner layer and implement it outside.
|
|
15
|
-
- *Layers not named.* Code is not sorted into layers, so direction cannot be seen. Name the layers and place each module.
|
|
16
|
-
- *Shared types living outside.* Inner code imports outer code only for a type. Move the type inward.
|
|
17
|
-
|
|
18
|
-
**Where to go.** The domain depends on nothing. The application orchestrates the domain. Adapters implement inner ports. Transports sit at the edge.
|
|
11
|
+
Review lens: [clean-architecture](../../methods/lenses/clean-architecture.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).
|
|
19
12
|
|
|
20
|
-
|
|
21
|
-
- "It's just one import." It is the direction that matters; one import is how it reverses.
|
|
13
|
+
## Spirit
|
|
22
14
|
|
|
23
|
-
|
|
24
|
-
- *The Dependency Rule* (Robert C. Martin, *Clean Architecture*). Source dependencies point only inward.
|
|
25
|
-
- *Ports and adapters* (Alistair Cockburn, hexagonal architecture). The core declares ports; the outside implements them.
|
|
15
|
+
Start from the symptom a finding names: [Inner layer imports outer](../typescript/symptoms.md#inner-layer-imports-outer). Each symptom names the cases it may indicate and the rules they point at. The why is on [External behaviour sits at a boundary](../principles.md#external-behaviour-sits-at-a-boundary).
|
package/rules/CD-14/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-14 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptoms: [Authored class or this](../typescript/symptoms.md#authored-class-or-this) and [Library class built in place](../typescript/symptoms.md#library-class-built-in-place).
|
|
4
|
+
|
|
5
|
+
Read [the verdict and the named pages it points at](README.md) first. This page is the mechanics: what each check flags and misses, how to fix a flagged site, and how to record an exception.
|
|
4
6
|
|
|
5
7
|
## Clauses
|
|
6
8
|
|
package/rules/CD-14/README.md
CHANGED
|
@@ -2,27 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Rule
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This numbered page is the earlier form of this rule. The [named pages](../README.md) govern where they differ, and [Every CD](../numbers.md) maps each number to its names.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Spirit
|
|
7
|
+
**Verdict.** Splits: no-class recipe; Outside dependencies stay at boundaries; state a case.
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Closure factory](../typescript/recipes.md#closure-factory), [Outside dependencies stay at boundaries](../rules.md#outside-dependencies-stay-at-boundaries) and Keeps state or settings across calls ([cases](../cases.md#no-hidden-effects)).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *State that changes between calls.* The class holds counters, caches or buffers. Replace it with a factory that keeps them in private bindings and returns functions.
|
|
15
|
-
- *A namespace with a constructor.* The methods only read configuration, or the members are all static. Make them plain functions that take that configuration as an argument.
|
|
16
|
-
- *Inheritance used for reuse.* A base class shares behaviour. Compose functions instead.
|
|
17
|
-
- *A library class spreading.* A library's class is built in many places or handed out. Build it once inside its wrapping factory and expose functions.
|
|
18
|
-
|
|
19
|
-
**Where to go.** No authored classes. A library class is built only in its wrapping factory and never leaves it as a class.
|
|
11
|
+
Review lens: [function-first](../../methods/lenses/function-first.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).
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
- "Classes are just syntax." The concern is state hidden behind a shared reference and reuse by inheritance, not the keyword.
|
|
23
|
-
- "The library needs `new`." The rule allows that, inside the wrapping factory.
|
|
24
|
-
- "Errors need classes." Operational failures are plain data returned as results (CD-9, CD-11).
|
|
13
|
+
## Spirit
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
- *Favour composition over inheritance* (Gamma, Helm, Johnson and Vlissides, *Design Patterns*). Behaviour assembled from parts changes more safely than behaviour inherited from a base.
|
|
28
|
-
- *Ports and adapters* (Alistair Cockburn, hexagonal architecture). A library's class belongs inside its adapter, behind your own functions.
|
|
15
|
+
Start from the symptom a finding names: [Authored class or this](../typescript/symptoms.md#authored-class-or-this) and [Library class built in place](../typescript/symptoms.md#library-class-built-in-place). Each symptom names the cases it may indicate and the rules they point at. The why is on [No hidden effects](../principles.md#no-hidden-effects) and [External behaviour sits at a boundary](../principles.md#external-behaviour-sits-at-a-boundary).
|
package/rules/CD-15/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-15 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptom: [Loop keyword](../typescript/symptoms.md#loop-keyword).
|
|
4
|
+
|
|
5
|
+
Read [the verdict and the named pages it points at](README.md) first. This page is the mechanics: what each check flags and misses, how to fix a flagged site, and how to record an exception.
|
|
4
6
|
|
|
5
7
|
## Clauses
|
|
6
8
|
|
|
@@ -28,6 +30,8 @@ const totals = orders.map((order) => order.total);
|
|
|
28
30
|
```
|
|
29
31
|
Replace a counted loop with `Array.from({ length }, (_, position) => ...)`.
|
|
30
32
|
|
|
33
|
+
In a test file, `CD-27#test-body-logic` flags `map` at either edition, and its edition 2 flags `Array.from`: write the values out instead, as [CD-27's allowed forms](../CD-27/CHECKS.md#allowed-forms-in-a-test) show.
|
|
34
|
+
|
|
31
35
|
## Exceptions
|
|
32
36
|
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 is forfeited once the file is touched, and needs no `whyChain`. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|
|
33
37
|
|