@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
package/rules/CD-15/README.md
CHANGED
|
@@ -2,29 +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
|
-
**
|
|
7
|
+
**Verdict.** Cases of [No hidden effects](../principles.md#no-hidden-effects).
|
|
8
|
+
|
|
9
|
+
**Read.** [No hidden effects](../principles.md#no-hidden-effects), Makes a new value from what it has ([cases](../cases.md#no-hidden-effects)) and [Functional iteration](../typescript/recipes.md#functional-iteration).
|
|
8
10
|
|
|
9
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).
|
|
10
12
|
|
|
11
13
|
## Spirit
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
**What a finding points at.** Match the sites against these causes.
|
|
16
|
-
- *A transformation hidden in control flow.* The body builds one result from each element. Express it as a map, filter or reduce.
|
|
17
|
-
- *Several jobs in one pass.* One loop filters, reshapes and records. Split it into named steps.
|
|
18
|
-
- *Effects mixed with computation.* The loop computes and writes at once. Compute the result first, then perform the effects at the edge.
|
|
19
|
-
- *A stream being drained.* Consuming an async stream is a limit of the language, not debt. Record the site as an authorised location; it is fully compliant.
|
|
20
|
-
|
|
21
|
-
**Where to go.** Iteration reads as data flowing through named transformations, with effects at the end.
|
|
22
|
-
|
|
23
|
-
**Reactions to distrust.**
|
|
24
|
-
- "Loops are faster." Usually unmeasured, and the rule makes no performance carve-out. Measure before arguing it.
|
|
25
|
-
- "It's just tests." A loop in a test is several cases in one. Use one parameterised test over the rows (CD-27).
|
|
26
|
-
- "A loop is clearer here." Clearer to the writer, who knows what it builds. Name what it builds.
|
|
27
|
-
|
|
28
|
-
**Principles behind it.**
|
|
29
|
-
- *Replace Loop with Pipeline* (Martin Fowler, *Refactoring*, second edition). A collection pipeline names each step of the processing.
|
|
30
|
-
- *Functional core, imperative shell* (Gary Bernhardt). The transformation is pure; effects run at the edge on its result.
|
|
15
|
+
Start from the symptom a finding names: [Loop keyword](../typescript/symptoms.md#loop-keyword). 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).
|
package/rules/CD-16/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-16 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.
|
|
4
6
|
|
|
5
7
|
## How it is checked
|
|
6
8
|
|
package/rules/CD-16/README.md
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Rule
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
|
|
7
|
+
**Verdict.** Merges with CD-15.
|
|
8
|
+
|
|
9
|
+
**Read.** [No hidden effects](../principles.md#no-hidden-effects) and [Functional iteration](../typescript/recipes.md#functional-iteration).
|
|
10
10
|
|
|
11
11
|
Review lens: [function-first](../../methods/lenses/function-first.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).
|
|
12
12
|
|
|
13
13
|
## Spirit
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Start from the symptom a finding names: [Loop keyword](../typescript/symptoms.md#loop-keyword). 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).
|
package/rules/CD-17/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-17 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptom: [Date used directly](../typescript/symptoms.md#date-used-directly).
|
|
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-17/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.** Cases under Handed what it uses and One reason per module.
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Handed what it uses](../rules.md#handed-what-it-uses), [One reason per module](../rules.md#one-reason-per-module), Needs the current time, a random value, a new id or an outside ordering ([cases](../cases.md#external-behaviour-sits-at-a-boundary)) and [World values through a port](../typescript/recipes.md#world-values-through-a-port).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *Decisions that read the clock.* Business logic asks for the current time in the middle of a calculation. Pass the instant in, or inject the clock.
|
|
15
|
-
- *Time stamped in many places.* Many sites stamp records or events. One clock port at the edge; the instant travels inward as data.
|
|
16
|
-
- *Tests that wait or depend on wall time.* Flaky or slow tests point at a missing clock port. Inject a fake clock and advance it.
|
|
17
|
-
- *Tests that build their own instants.* A test making dates for itself is choosing time outside the clock. Take instants from the fake clock.
|
|
18
|
-
|
|
19
|
-
**Where to go.** One clock abstraction reads real time. Everything else receives an instant or the clock. Tests set the time they need.
|
|
11
|
+
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. 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 a log timestamp." It is still output nobody can pin in a test. Read it through the clock.
|
|
23
|
-
- "It's just tests." The rule covers tests. A test that reads real time cannot be repeated exactly.
|
|
24
|
-
- "Exclude that folder." Then that folder's behaviour depends on the hour it runs. Find the clock port it is missing.
|
|
13
|
+
## Spirit
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
- *Dependency Inversion Principle* (Robert C. Martin, SOLID). Time is a detail; the logic depends on a clock abstraction it is given.
|
|
28
|
-
- *Functional core, imperative shell* (Gary Bernhardt). Reading the clock is an effect at the shell. The core receives the instant as a value and stays pure.
|
|
15
|
+
Start from the symptom a finding names: [Date used directly](../typescript/symptoms.md#date-used-directly). 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), [One place decides](../principles.md#one-place-decides) and [Tests are ours](../principles.md#tests-are-ours).
|
package/rules/CD-18/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-18 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptom: [Process global used in place](../typescript/symptoms.md#process-global-used-in-place).
|
|
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-18/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.** Cases under [Ports declared inside](../rules.md#ports-declared-inside).
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Ports declared inside](../rules.md#ports-declared-inside) and [World values through a port](../typescript/recipes.md#world-values-through-a-port).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *Exit called deep inside.* A function ends the process instead of returning. Return the outcome; let the entry point decide to exit.
|
|
15
|
-
- *Signal handling scattered.* Several modules register handlers. Gather lifecycle in one port wired at startup.
|
|
16
|
-
- *Timing read from the process.* Code measures time through the process global. Inject it.
|
|
17
|
-
|
|
18
|
-
**Where to go.** Lifecycle operations arrive through one injected port. Only the composition root touches the real process.
|
|
11
|
+
Review lens: [di-discipline](../../methods/lenses/di-discipline.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 a CLI, exit is normal." Exit at the entry point. Everywhere else, return.
|
|
13
|
+
## Spirit
|
|
22
14
|
|
|
23
|
-
|
|
24
|
-
- *Dependency Inversion Principle* (Robert C. Martin, SOLID). Code depends on a lifecycle abstraction, not the runtime global.
|
|
25
|
-
- *Functional core, imperative shell* (Gary Bernhardt). The decision to stop is a value; stopping happens at the shell.
|
|
15
|
+
Start from the symptom a finding names: [Process global used in place](../typescript/symptoms.md#process-global-used-in-place). 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-19/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-19 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptom: [Outside import past a boundary](../typescript/symptoms.md#outside-import-past-a-boundary).
|
|
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
|
|
|
@@ -15,7 +17,7 @@ Read [the rule and its spirit](README.md) first. This page is the mechanics: wha
|
|
|
15
17
|
- The source rule covers every third-party dependency; the check covers only the listed packages. The rest is left to review.
|
|
16
18
|
|
|
17
19
|
## Settings
|
|
18
|
-
List each
|
|
20
|
+
List each outside dependency the repository confines to its adapter in `disciplines.json`, then record each adapter file as an `authorised-location`:
|
|
19
21
|
|
|
20
22
|
```json
|
|
21
23
|
"clauseSettings": {
|
|
@@ -32,13 +34,13 @@ import { v4 } from "uuid";
|
|
|
32
34
|
|
|
33
35
|
## How to fix
|
|
34
36
|
```ts
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
+
import type { FileReader } from "./file-reader.ts";
|
|
38
|
+
import type { IdGenerator } from "./id-generator.ts";
|
|
37
39
|
```
|
|
38
|
-
Import your own port. Only the
|
|
40
|
+
Import your own port and take it in the unit's argument. Only the adapter for that outside party imports the library.
|
|
39
41
|
|
|
40
42
|
## Exceptions
|
|
41
|
-
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` for the file that is the
|
|
43
|
+
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` for the file that is the adapter for that outside dependency. 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).
|
|
42
44
|
|
|
43
45
|
```json
|
|
44
46
|
{ "version": 1, "exceptions": [
|
package/rules/CD-19/README.md
CHANGED
|
@@ -2,28 +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: Outside dependencies stay at boundaries; Ports declared inside; construction and ids cases.
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Outside dependencies stay at boundaries](../rules.md#outside-dependencies-stay-at-boundaries), [Ports declared inside](../rules.md#ports-declared-inside), Builds the real implementations ([cases](../cases.md#one-place-decides)), Needs the current time, a random value, a new id or an outside ordering ([cases](../cases.md#external-behaviour-sits-at-a-boundary)), [World values through a port](../typescript/recipes.md#world-values-through-a-port) and [Adapter per outside party](../typescript/recipes.md#adapter-per-outside-party).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *A capability with no name.* Many files import the same library or runtime module. Name the capability, wrap it once, inject it.
|
|
15
|
-
- *A port that leaks.* A wrapper exists but passes vendor types or objects through, so callers import the vendor anyway. Make the port speak your types.
|
|
16
|
-
- *Decisions doing I/O.* A runtime call sits in the middle of business logic. Separate the decision from the effect; the effect arrives through a port.
|
|
17
|
-
- *Construction spread everywhere.* Each module builds its own dependencies. Move construction to one composition root that passes ports in.
|
|
18
|
-
|
|
19
|
-
**Where to go.** Each external capability has one wrapping file, recorded as its authorised location. Everything else imports your port. Opening a new wrapper is a recorded decision, not an inline one.
|
|
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
|
-
- "It's only the standard library." The same reasons apply: it cannot be replaced in a test and it ties logic to a platform. The rule makes no stdlib carve-out.
|
|
23
|
-
- "Wrapping is boilerplate." One small file per capability, against the whole codebase knowing a vendor's surface.
|
|
24
|
-
- "Exclude that folder." An excluded folder is a boundary nobody designed. Design it, then authorise the one file.
|
|
13
|
+
## Spirit
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
- *Dependency Inversion Principle* (Robert C. Martin, SOLID). Your code depends on an abstraction you own; the vendor detail depends on it, not the other way round.
|
|
28
|
-
- *Ports and adapters* (Alistair Cockburn, hexagonal architecture). The application talks through ports; one adapter per outside system translates. Swapping the system means swapping the adapter.
|
|
29
|
-
- *Functional core, imperative shell* (Gary Bernhardt). Decisions stay pure; effects live at the edge and arrive through ports.
|
|
15
|
+
Start from the symptom a finding names: [Outside import past a boundary](../typescript/symptoms.md#outside-import-past-a-boundary) and [Outside type in a signature](../typescript/symptoms.md#outside-type-in-a-signature). 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-2/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-2 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptom: [Claimed type](../typescript/symptoms.md#claimed-type).
|
|
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
|
|
|
@@ -36,9 +38,11 @@ const name = user.name!;
|
|
|
36
38
|
## How to fix
|
|
37
39
|
```ts
|
|
38
40
|
const user = userSchema.parse(response);
|
|
39
|
-
const name = user.name
|
|
41
|
+
const name = user.name;
|
|
40
42
|
```
|
|
41
|
-
Parse or narrow the value so the type follows from a check rather than from an assertion. For a value that may be absent, handle the absent case with a check
|
|
43
|
+
Parse or narrow the value so the type follows from a check rather than from an assertion. For a value that may be absent, handle the absent case with a check or an early return; for a binding assigned later, initialise it where it is declared or make it a `const` built from what it needs.
|
|
44
|
+
|
|
45
|
+
In a test file, `CD-27#test-body-logic` flags an `if` check at either edition, and its edition 2 flags the `??` fallback: there, `assert.isDefined` a value that may be missing before reading it, as [CD-27's allowed forms](../CD-27/CHECKS.md#a-short-circuit) show.
|
|
42
46
|
|
|
43
47
|
When handing a value across a boundary truly forces a cast, such as a library that types its schemas loosely or a database driver that returns unparsed rows, put the cast in the one adapter file at that boundary and record that file as an `authorised-location` with a why-chain. With clean boundaries that is one file and one record; casts scattered across many files are the sign the boundary is missing.
|
|
44
48
|
|
package/rules/CD-2/README.md
CHANGED
|
@@ -2,29 +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: [Declared, not asserted](../rules.md#declared-not-asserted).
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Declared, not asserted](../rules.md#declared-not-asserted) and [Fix the declaration, not the value](../typescript/recipes.md#fix-the-declaration-not-the-value).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *Parsing skipped at a boundary.* Raw input is asserted into shape instead of checked. Parse it once where it enters and the type follows.
|
|
15
|
-
- *A declared type that is wrong.* The code builds something its type does not describe. Fix the declaration and the cast goes.
|
|
16
|
-
- *A boundary that is missing.* Casts cluster around one library or data source across many files. Make one wrapping file the boundary and keep the rest cast-free.
|
|
17
|
-
- *A return type wider than its use.* A function returns a broad type and every caller narrows it. Return the narrow type.
|
|
18
|
-
- *A parameter type wider than its use.* A function asks for a whole record but reads two fields. It shows in tests, where someone casts a two-field object through to the full type rather than build it all. The function asks for more than it needs. Accept only the fields it uses; the test then builds those two fields honestly.
|
|
19
|
-
|
|
20
|
-
**Where to go.** Casts live only in a few named boundary files, each recorded as an authorised location. Clean boundaries make that cheap; that is what authorised locations are for. Everywhere else the type follows from a check.
|
|
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).
|
|
21
12
|
|
|
22
|
-
|
|
23
|
-
- "It's just tests." Tests are violations too. A test that casts is building a value its type does not allow. Either build it properly, or the unit asks for more than it uses.
|
|
24
|
-
- "Add a permission for this shape." Measure first. A permission can hide a real defect, such as database rows that were never parsed.
|
|
25
|
-
- "The library forces it." It forces one site. Put that site in the wrapping file.
|
|
13
|
+
## Spirit
|
|
26
14
|
|
|
27
|
-
|
|
28
|
-
- *Parse, don't validate* (Alexis King). A parse produces the type; a cast only claims it. Parse once at the boundary and the claim is never needed.
|
|
29
|
-
- *Interface Segregation Principle* (Robert C. Martin, SOLID). Depend only on what you use. A parameter that asks for exactly the fields it reads needs no cast to satisfy, in production or in tests.
|
|
30
|
-
- *Ports and adapters* (Alistair Cockburn, hexagonal architecture). The adapter at the edge is where outside shapes are translated, so it is the one place an unavoidable assertion belongs.
|
|
15
|
+
Start from the symptom a finding names: [Claimed type](../typescript/symptoms.md#claimed-type). 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-20/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-20 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptom: [Outside import past a boundary](../typescript/symptoms.md#outside-import-past-a-boundary).
|
|
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
|
## How it is checked
|
|
6
8
|
|
package/rules/CD-20/README.md
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Rule
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
|
|
7
|
+
**Verdict.** Merges with CD-19.
|
|
8
|
+
|
|
9
|
+
**Read.** [Outside dependencies stay at boundaries](../rules.md#outside-dependencies-stay-at-boundaries), [Ports declared inside](../rules.md#ports-declared-inside) and [Adapter per outside party](../typescript/recipes.md#adapter-per-outside-party).
|
|
10
10
|
|
|
11
11
|
Review lens: [di-discipline](../../methods/lenses/di-discipline.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).
|
|
12
12
|
|
|
13
13
|
## Spirit
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Start from the symptom a finding names: [Outside import past a boundary](../typescript/symptoms.md#outside-import-past-a-boundary). 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-21/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-21 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Recipe: [Composition root](../typescript/recipes.md#composition-root). The outcome it protects is seen by [Adapter built outside the root](../typescript/symptoms.md#adapter-built-outside-the-root).
|
|
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-21/README.md
CHANGED
|
@@ -2,23 +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.** Cases: built at the entry point.
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** Builds the real implementations ([cases](../cases.md#one-place-decides)) and [Composition root](../typescript/recipes.md#composition-root).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *Construction scattered.* Several places build the real implementation differently. Move it into a default factory beside the port.
|
|
15
|
-
- *A port invented only for tests.* It has test doubles but no real implementation. Either give it a default or question whether it is a port.
|
|
16
|
-
|
|
17
|
-
**Where to go.** Each port's module exports its default production factory. Production wires the default; tests pass test doubles.
|
|
11
|
+
Review lens: [di-discipline](../../methods/lenses/di-discipline.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).
|
|
18
12
|
|
|
19
|
-
|
|
20
|
-
- "The composition root builds it." It still calls one canonical factory, not its own construction.
|
|
13
|
+
## Spirit
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
- *Composition root.* All wiring happens in one place, from canonical factories.
|
|
24
|
-
- *Dependency Inversion Principle* (Robert C. Martin, SOLID). Callers depend on the port; the default is one implementation of it.
|
|
15
|
+
Start from the symptom a finding names: [Adapter built outside the root](../typescript/symptoms.md#adapter-built-outside-the-root). Each symptom names the cases it may indicate and the rules they point at. The why is on [One place decides](../principles.md#one-place-decides).
|
package/rules/CD-22/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-22 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Recipe: [Bounded context generic](../typescript/recipes.md#bounded-context-generic). The outcome it protects is seen by [Default for a required value](../typescript/symptoms.md#default-for-a-required-value).
|
|
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-22/README.md
CHANGED
|
@@ -2,23 +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 [Declared, not asserted](../rules.md#declared-not-asserted).
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Declared, not asserted](../rules.md#declared-not-asserted) and [Bounded context generic](../typescript/recipes.md#bounded-context-generic).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *Context read defensively.* Middleware checks or defaults a field like the clock or logger. Constrain its context type so the field must exist.
|
|
15
|
-
- *Layers that add capabilities untyped.* Earlier layers add fields the type never records. Widen the generic at each layer.
|
|
16
|
-
|
|
17
|
-
**Where to go.** Each middleware declares the context it needs through a constrained generic. A missing capability is a compile error.
|
|
11
|
+
Review lens: [di-discipline](../../methods/lenses/di-discipline.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).
|
|
18
12
|
|
|
19
|
-
|
|
20
|
-
- "A default is safer." A default hides wiring mistakes until they matter.
|
|
13
|
+
## Spirit
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
- *Make illegal states unrepresentable* (Yaron Minsky). A context type that requires the field cannot be built without it.
|
|
24
|
-
- *Explicit dependencies.* A unit states what it needs in its signature, not by reaching into a shared bag.
|
|
15
|
+
Start from the symptom a finding names: [Default for a required value](../typescript/symptoms.md#default-for-a-required-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-23/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-23 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptom: [Unit without a running test](../typescript/symptoms.md#unit-without-a-running-test).
|
|
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
|
|
|
@@ -24,11 +26,11 @@ This is `src/price.ts` with no `src/price.test.ts` beside it.
|
|
|
24
26
|
Add `src/price.test.ts` next to the file, with at least one test of its behaviour.
|
|
25
27
|
|
|
26
28
|
## Exceptions
|
|
27
|
-
Add an entry to `discipline-exceptions.json` at the repository root. Use `
|
|
29
|
+
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 a unit that only wires has a test of its wiring, and a reviewer refuses one. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|
|
28
30
|
|
|
29
31
|
```json
|
|
30
32
|
{ "version": 1, "exceptions": [
|
|
31
|
-
{ "kind": "
|
|
33
|
+
{ "kind": "file-carve-out", "clause": "CD-23#export-test-sibling", "file": "src/legacy/report.ts" }
|
|
32
34
|
] }
|
|
33
35
|
```
|
|
34
36
|
|
package/rules/CD-23/README.md
CHANGED
|
@@ -2,25 +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: [Tested where it's owned](../rules.md#tested-where-its-owned).
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Tested where it's owned](../rules.md#tested-where-its-owned) and [Companion test file](../typescript/recipes.md#companion-test-file).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *A unit too tangled to test.* The test was skipped because the unit reaches its dependencies directly. Inject them, and the unit can be tested alone.
|
|
15
|
-
- *A file that is not a unit.* It holds loose pieces with no single purpose. Split it into units that each have one.
|
|
16
|
-
- *Tests in a parallel tree.* The tests exist but live elsewhere and drift. Move each beside its unit.
|
|
17
|
-
- *Tested only through something bigger.* The unit is covered only by an integration test. Give it its own.
|
|
18
|
-
|
|
19
|
-
**Where to go.** Every unit has a sibling test that states what it is for, and the two are edited together.
|
|
11
|
+
Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags. What each check flags, how to fix a flagged site, and how to record an exception: [CHECKS.md](CHECKS.md). The thinking behind every rule: [the spirit of the rules](../SPIRIT.md).
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
- "It's covered by the integration tests." Covered is not specified. A failure there does not say which unit broke.
|
|
23
|
-
- "It's too simple to test." Then the test is short. It still states the purpose.
|
|
13
|
+
## Spirit
|
|
24
14
|
|
|
25
|
-
|
|
26
|
-
- *Listen to the tests* (Steve Freeman and Nat Pryce, *Growing Object-Oriented Software, Guided by Tests*). Difficulty testing a unit is feedback about its design.
|
|
15
|
+
Start from the symptom a finding names: [Unit without a running test](../typescript/symptoms.md#unit-without-a-running-test). Each symptom names the cases it may indicate and the rules they point at. The why is on [Tests are ours](../principles.md#tests-are-ours).
|
package/rules/CD-24/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-24 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptom: [Unit without a running test](../typescript/symptoms.md#unit-without-a-running-test).
|
|
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
|
## How it is checked
|
|
6
8
|
|
package/rules/CD-24/README.md
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Rule
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
|
|
7
|
+
**Verdict.** Merges with CD-23.
|
|
8
|
+
|
|
9
|
+
**Read.** [Tested where it's owned](../rules.md#tested-where-its-owned) and [Companion test file](../typescript/recipes.md#companion-test-file).
|
|
10
10
|
|
|
11
11
|
Review lens: [test-discipline](../../methods/lenses/test-discipline.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).
|
|
12
12
|
|
|
13
13
|
## Spirit
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Start from the symptom a finding names: [Unit without a running test](../typescript/symptoms.md#unit-without-a-running-test). Each symptom names the cases it may indicate and the rules they point at. The why is on [Tests are ours](../principles.md#tests-are-ours).
|
package/rules/CD-25/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-25 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptom: [Double with a body](../typescript/symptoms.md#double-with-a-body).
|
|
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
|
|
|
@@ -24,10 +26,10 @@ const clock = { now: vi.fn(() => 1) };
|
|
|
24
26
|
```ts
|
|
25
27
|
const clock = { now: vi.fn().mockReturnValue(1) };
|
|
26
28
|
```
|
|
27
|
-
Return a canned value: that double is a stub. If the double needs logic, the seam is probably too wide
|
|
29
|
+
Return a canned value: that double is a stub. If the double needs logic, the seam is probably too wide.
|
|
28
30
|
|
|
29
31
|
## Exceptions
|
|
30
|
-
|
|
32
|
+
For debt in one file, add a `file-carve-out` entry to `discipline-exceptions.json` at the repository root: it is forfeited once the file is touched, and needs no `whyChain`. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|
|
31
33
|
|
|
32
34
|
```json
|
|
33
35
|
{ "version": 1, "exceptions": [
|