@hailstails/hone 0.1.0-pre.5 → 0.1.0-pre.7
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 +151 -42
- package/MIGRATING.md +55 -4
- package/README.md +120 -43
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/api/audit.d.ts +3 -0
- package/api/audit.js +10 -0
- package/api/rule-set.js +0 -0
- package/api/testing.d.ts +5 -0
- package/api/testing.js +211 -0
- package/chunks/chunk-3LCKBX5T.js +2134 -0
- package/chunks/chunk-5LCLBXP7.js +76 -0
- package/chunks/{chunk-7PVPPH4C.js → chunk-LDQUT742.js} +3 -1
- package/chunks/{chunk-VUG3DJHN.js → chunk-MYX7GAVM.js} +9 -9
- package/chunks/{chunk-SWPCKTJV.js → chunk-NCDYOPHG.js} +7340 -2124
- package/chunks/{chunk-HVABJ7T4.js → chunk-NRXSM7BY.js} +73 -12
- package/chunks/{chunk-YBWVUDIG.js → chunk-P3NLETF5.js} +1 -1
- package/chunks/{chunk-IIMK5BCL.js → chunk-POZL7G62.js} +15 -13
- package/chunks/{chunk-7OVV6NEU.js → chunk-WPRR2MPJ.js} +1 -1
- package/core/check/tool-command.js +531 -1967
- package/core/conformance/conformance-testing-types.d.ts +28 -0
- package/core/conformance/conformance-types.d.ts +7 -0
- package/docs/adding-a-discipline-or-mechanism.md +27 -14
- package/docs/extending.md +22 -11
- package/docs/output-contract.md +326 -0
- package/mechanisms/audit/CD-19/import-boundaries.js +3 -3
- package/mechanisms/audit/CD-2/piece.json +6 -1
- package/mechanisms/audit/CD-5/comments-directives.js +10 -26
- package/mechanisms/audit/runner/README.md +3 -2
- package/mechanisms/audit/runner/runner.js +97 -35
- package/mechanisms/eslint/CD-2/README.md +12 -0
- package/mechanisms/eslint/CD-2/cd2/cd2.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-2/piece.json +25 -0
- package/mechanisms/eslint/runner/README.md +12 -5
- package/mechanisms/eslint/runner/runner.js +900 -242
- package/methods/README.md +2 -0
- package/methods/assessment-template.md +35 -0
- package/methods/lenses/clean-architecture.md +2 -2
- package/methods/lenses/decomposition.md +2 -2
- package/methods/lenses/defended-on-intent.md +7 -7
- package/methods/lenses/di-discipline.md +38 -26
- package/methods/lenses/errors-as-data.md +2 -2
- package/methods/lenses/function-first.md +2 -2
- package/methods/lenses/naming.md +2 -2
- package/methods/lenses/test-discipline.md +15 -13
- package/methods/lenses/type-soundness.md +2 -2
- package/methods/lenses/zod-boundary.md +2 -2
- package/package.json +8 -3
- package/rules/CD-1/CHECKS.md +37 -0
- package/rules/CD-1/README.md +17 -32
- package/rules/CD-10/CHECKS.md +49 -0
- package/rules/CD-10/README.md +21 -49
- package/rules/CD-11/CHECKS.md +13 -0
- package/rules/CD-11/README.md +14 -8
- package/rules/CD-12/CHECKS.md +13 -0
- package/rules/CD-12/README.md +14 -8
- package/rules/CD-13/CHECKS.md +13 -0
- package/rules/CD-13/README.md +14 -8
- package/rules/CD-14/CHECKS.md +49 -0
- package/rules/CD-14/README.md +22 -48
- package/rules/CD-15/CHECKS.md +40 -0
- package/rules/CD-15/README.md +22 -40
- package/rules/CD-16/CHECKS.md +7 -0
- package/rules/CD-16/README.md +3 -5
- package/rules/CD-17/CHECKS.md +37 -0
- package/rules/CD-17/README.md +17 -31
- package/rules/CD-18/CHECKS.md +13 -0
- package/rules/CD-18/README.md +15 -9
- package/rules/CD-19/CHECKS.md +49 -0
- package/rules/CD-19/README.md +18 -44
- package/rules/CD-2/CHECKS.md +56 -0
- package/rules/CD-2/README.md +18 -35
- package/rules/CD-2/discipline.json +68 -0
- package/rules/CD-20/CHECKS.md +7 -0
- package/rules/CD-20/README.md +3 -5
- package/rules/CD-21/CHECKS.md +13 -0
- package/rules/CD-21/README.md +14 -9
- package/rules/CD-22/CHECKS.md +13 -0
- package/rules/CD-22/README.md +13 -8
- package/rules/CD-23/CHECKS.md +35 -0
- package/rules/CD-23/README.md +14 -29
- package/rules/CD-24/CHECKS.md +7 -0
- package/rules/CD-24/README.md +3 -5
- package/rules/CD-25/CHECKS.md +38 -0
- package/rules/CD-25/README.md +20 -32
- package/rules/CD-26/CHECKS.md +36 -0
- package/rules/CD-26/README.md +18 -31
- package/rules/CD-27/CHECKS.md +45 -0
- package/rules/CD-27/README.md +18 -40
- package/rules/CD-28/CHECKS.md +13 -0
- package/rules/CD-28/README.md +14 -8
- package/rules/CD-29/CHECKS.md +13 -0
- package/rules/CD-29/README.md +12 -8
- package/rules/CD-3/CHECKS.md +42 -0
- package/rules/CD-3/README.md +20 -42
- package/rules/CD-30/CHECKS.md +13 -0
- package/rules/CD-30/README.md +13 -8
- package/rules/CD-31/CHECKS.md +13 -0
- package/rules/CD-31/README.md +12 -8
- package/rules/CD-32/CHECKS.md +13 -0
- package/rules/CD-32/README.md +13 -8
- package/rules/CD-33/CHECKS.md +13 -0
- package/rules/CD-33/README.md +13 -8
- package/rules/CD-34/CHECKS.md +13 -0
- package/rules/CD-34/README.md +12 -8
- package/rules/CD-39/CHECKS.md +13 -0
- package/rules/CD-39/README.md +13 -8
- package/rules/CD-4/CHECKS.md +13 -0
- package/rules/CD-4/README.md +15 -8
- package/rules/CD-40/CHECKS.md +39 -0
- package/rules/CD-40/README.md +17 -33
- package/rules/CD-41/CHECKS.md +54 -0
- package/rules/CD-41/README.md +23 -54
- package/rules/CD-42/CHECKS.md +47 -0
- package/rules/CD-42/README.md +19 -47
- package/rules/CD-43/CHECKS.md +37 -0
- package/rules/CD-43/README.md +15 -31
- package/rules/CD-44/CHECKS.md +48 -0
- package/rules/CD-44/README.md +20 -48
- package/rules/CD-45/CHECKS.md +13 -0
- package/rules/CD-45/README.md +14 -8
- package/rules/CD-46/CHECKS.md +7 -0
- package/rules/CD-46/README.md +16 -4
- package/rules/CD-47/CHECKS.md +37 -0
- package/rules/CD-47/README.md +16 -32
- package/rules/CD-5/CHECKS.md +52 -0
- package/rules/CD-5/README.md +22 -52
- package/rules/CD-6/CHECKS.md +51 -0
- package/rules/CD-6/README.md +22 -51
- package/rules/CD-7/CHECKS.md +46 -0
- package/rules/CD-7/README.md +23 -46
- package/rules/CD-7a/CHECKS.md +38 -0
- package/rules/CD-7a/README.md +14 -32
- package/rules/CD-8/CHECKS.md +42 -0
- package/rules/CD-8/README.md +20 -42
- package/rules/CD-9/CHECKS.md +13 -0
- package/rules/CD-9/README.md +15 -8
- package/rules/README.md +5 -3
- package/rules/SPIRIT.md +50 -0
- package/api/audit.mjs +0 -1
- package/api/rule-set.mjs +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# CD-10 checks
|
|
2
|
+
|
|
3
|
+
Read [the rule and its spirit](README.md) first. This page is the mechanics: how the rule is checked, and how to record an exception where the rule allows one.
|
|
4
|
+
|
|
5
|
+
## Clauses
|
|
6
|
+
|
|
7
|
+
| Clause | Mechanism | Checks |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `CD-10#throws-in-tests` | audit | a `throw` statement in a test file |
|
|
10
|
+
| `CD-10#throw-only-error` | eslint | a `throw` of something that is not an error object |
|
|
11
|
+
|
|
12
|
+
## What the check flags
|
|
13
|
+
- Test files only: `*.test.ts` and `*.test.tsx`. `*.spec.ts` and `.js` tests are not read. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
14
|
+
- Every `throw` statement, wherever it sits in the file.
|
|
15
|
+
- Allowed: assertion calls such as `expect(...)`.
|
|
16
|
+
- The source rule also confines throwing in production code to a closed list of contexts. The check does not look at production files; that part is left to review.
|
|
17
|
+
|
|
18
|
+
## What the ESLint check flags
|
|
19
|
+
Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-10/README.md).
|
|
20
|
+
- `hone-cd10/throw-only-error` flags a `throw` of a literal, an object literal, a binary expression, a template or tagged template, or `undefined`. It follows the thrown value through `a ? b : c`, `a || b`, assignment and sequence expressions.
|
|
21
|
+
- Allowed: `new Error(...)`, identifiers, calls and member access.
|
|
22
|
+
- This clause applies to every file the ESLint run includes, not only tests.
|
|
23
|
+
|
|
24
|
+
## Example violation
|
|
25
|
+
```ts
|
|
26
|
+
it("loads the account", () => {
|
|
27
|
+
const result = load("a1");
|
|
28
|
+
if (result.outcome === "failed") throw new Error("load failed");
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## How to fix
|
|
33
|
+
```ts
|
|
34
|
+
it("loads the account", () => {
|
|
35
|
+
expect(load("a1")).toEqual({ outcome: "ok", value: account });
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
Assert on the whole result. Branching in tests is also reported by CD-27.
|
|
39
|
+
|
|
40
|
+
## Exceptions
|
|
41
|
+
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a test file legitimately needs a throw, such as a shared test harness. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{ "version": 1, "exceptions": [
|
|
45
|
+
{ "kind": "authorised-location", "clause": "CD-10#throws-in-tests", "file": "src/legacy/harness.test.ts", "reason": "..." }
|
|
46
|
+
] }
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
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.
|
package/rules/CD-10/README.md
CHANGED
|
@@ -4,52 +4,24 @@
|
|
|
4
4
|
|
|
5
5
|
Throwing is confined to a closed, named set of contexts: a startup-invariant check that fails at boot, and a branch made unreachable by exhaustive type narrowing. Defensive throws — "this should never happen", "guard against impossible state" — are forbidden: if you can name the state, you can model it as a result variant. A library that throws is caught at the boundary and converted to a result. Tests carry no exemption; they surface failures through assertions, not by throwing.
|
|
6
6
|
|
|
7
|
-
The
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
- This clause applies to every file the ESLint run includes, not only tests.
|
|
29
|
-
|
|
30
|
-
## Example violation
|
|
31
|
-
```ts
|
|
32
|
-
it("loads the account", () => {
|
|
33
|
-
const result = load("a1");
|
|
34
|
-
if (result.outcome === "failed") throw new Error("load failed");
|
|
35
|
-
});
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## How to fix
|
|
39
|
-
```ts
|
|
40
|
-
it("loads the account", () => {
|
|
41
|
-
expect(load("a1")).toEqual({ outcome: "ok", value: account });
|
|
42
|
-
});
|
|
43
|
-
```
|
|
44
|
-
Assert on the whole result. Branching in tests is also reported by CD-27.
|
|
45
|
-
|
|
46
|
-
## Exceptions
|
|
47
|
-
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a test file legitimately needs a throw, such as a shared test harness. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|
|
48
|
-
|
|
49
|
-
```json
|
|
50
|
-
{ "version": 1, "exceptions": [
|
|
51
|
-
{ "kind": "authorised-location", "clause": "CD-10#throws-in-tests", "file": "src/legacy/harness.test.ts", "reason": "..." }
|
|
52
|
-
] }
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
|
|
7
|
+
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).
|
|
8
|
+
|
|
9
|
+
## Spirit
|
|
10
|
+
|
|
11
|
+
**What the friction is for.** A throw is a failure the type does not mention. The friction makes returning the failure as a value the easy path, so every caller sees what can go wrong and must decide what to do.
|
|
12
|
+
|
|
13
|
+
**What a finding points at.** Match the sites against these causes.
|
|
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.
|
|
20
|
+
|
|
21
|
+
**Reactions to distrust.**
|
|
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.
|
|
24
|
+
|
|
25
|
+
**Principles behind it.**
|
|
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.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# CD-11 checks
|
|
2
|
+
|
|
3
|
+
Read [the rule and its spirit](README.md) first. This page is the mechanics: how the rule is checked, and how to record an exception where the rule allows one.
|
|
4
|
+
|
|
5
|
+
## Clauses
|
|
6
|
+
|
|
7
|
+
| Clause | Mechanism | Checks |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `CD-11#error-envelopes` | review | operational errors are tagged data built by a factory and dispatched on their tag |
|
|
10
|
+
|
|
11
|
+
## How it is checked
|
|
12
|
+
|
|
13
|
+
Every clause of this discipline is a judgement clause. It cannot be selected in `disciplines.json` and no mechanism checks it; a reviewer applies [the rule](README.md) with its review lens, as [ADOPTING.md](../../ADOPTING.md#9-apply-the-judgement-rules) describes. Selecting no clause of this discipline leaves nothing uncovered.
|
package/rules/CD-11/README.md
CHANGED
|
@@ -4,16 +4,22 @@
|
|
|
4
4
|
|
|
5
5
|
Operational error envelopes are plain, tagged data — constructed by a factory, inspected by a type guard, dispatched by an exhaustive switch on the tag — never authored classes extending the runtime's error type. Data-shaped errors compose, narrow, and serialise; class hierarchies for operational failure do not. The only authored error class is the single startup-invariant one the throw rule permits.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
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).
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Spirit
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
| --- | --- | --- |
|
|
13
|
-
| `CD-11#error-envelopes` | review | operational errors are tagged data built by a factory and dispatched on their tag |
|
|
11
|
+
**What the friction is for.** Errors are values the code passes, narrows and serialises. The friction makes plain tagged data the easy shape, so errors compose like any other data.
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
**What a finding points at.** Match the sites against these causes.
|
|
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.
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
**Where to go.** Each error is plain data with a tag, built by a factory and dispatched by an exhaustive switch.
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
**Reactions to distrust.**
|
|
21
|
+
- "Stack traces need the error class." Operational failures are expected outcomes, not bugs; they need context, not a trace.
|
|
22
|
+
|
|
23
|
+
**Principles behind it.**
|
|
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.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# CD-12 checks
|
|
2
|
+
|
|
3
|
+
Read [the rule and its spirit](README.md) first. This page is the mechanics: how the rule is checked, and how to record an exception where the rule allows one.
|
|
4
|
+
|
|
5
|
+
## Clauses
|
|
6
|
+
|
|
7
|
+
| Clause | Mechanism | Checks |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `CD-12#repository-ports` | review | storage sits behind a repository port and domain code never imports a storage driver |
|
|
10
|
+
|
|
11
|
+
## How it is checked
|
|
12
|
+
|
|
13
|
+
Every clause of this discipline is a judgement clause. It cannot be selected in `disciplines.json` and no mechanism checks it; a reviewer applies [the rule](README.md) with its review lens, as [ADOPTING.md](../../ADOPTING.md#9-apply-the-judgement-rules) describes. Selecting no clause of this discipline leaves nothing uncovered.
|
package/rules/CD-12/README.md
CHANGED
|
@@ -4,16 +4,22 @@
|
|
|
4
4
|
|
|
5
5
|
Storage sits behind a repository port. Domain code talks to the port; an adapter composes the raw storage-driver primitives behind it. The domain never imports the storage driver or a filesystem primitive directly — so the storage technology can change without the domain knowing.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
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).
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Spirit
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
| --- | --- | --- |
|
|
13
|
-
| `CD-12#repository-ports` | review | storage sits behind a repository port and domain code never imports a storage driver |
|
|
11
|
+
**What the friction is for.** Storage technology changes more often than the domain. The friction keeps the domain talking to a repository port, so storage can change without the domain knowing.
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
**What a finding points at.** Match the sites against these causes.
|
|
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.
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
**Where to go.** The domain depends on repository ports. Adapters compose the driver behind them.
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
**Reactions to distrust.**
|
|
21
|
+
- "We'll never change the database." The port is also what lets tests use an in-memory fake of storage.
|
|
22
|
+
|
|
23
|
+
**Principles behind it.**
|
|
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.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# CD-13 checks
|
|
2
|
+
|
|
3
|
+
Read [the rule and its spirit](README.md) first. This page is the mechanics: how the rule is checked, and how to record an exception where the rule allows one.
|
|
4
|
+
|
|
5
|
+
## Clauses
|
|
6
|
+
|
|
7
|
+
| Clause | Mechanism | Checks |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `CD-13#layer-boundaries` | review | dependencies point inward and an inner layer never imports an outer one |
|
|
10
|
+
|
|
11
|
+
## How it is checked
|
|
12
|
+
|
|
13
|
+
Every clause of this discipline is a judgement clause. It cannot be selected in `disciplines.json` and no mechanism checks it; a reviewer applies [the rule](README.md) with its review lens, as [ADOPTING.md](../../ADOPTING.md#9-apply-the-judgement-rules) describes. Selecting no clause of this discipline leaves nothing uncovered.
|
package/rules/CD-13/README.md
CHANGED
|
@@ -4,16 +4,22 @@
|
|
|
4
4
|
|
|
5
5
|
Dependencies point inward and only inward: the domain depends on nothing, the application layer orchestrates the domain, adapters implement the ports the inner layers declare, and transports are leaves at the edge. An inner layer importing an outer one is the violation — it is what inverts the dependency direction the architecture exists to protect.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
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).
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Spirit
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
| --- | --- | --- |
|
|
13
|
-
| `CD-13#layer-boundaries` | review | dependencies point inward and an inner layer never imports an outer one |
|
|
11
|
+
**What the friction is for.** When inner code depends on outer code, a change at the edge breaks the core. The friction keeps dependencies pointing inward, so the core can be understood, tested and kept without its delivery details.
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
**What a finding points at.** Match the imports against these causes.
|
|
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.
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
**Where to go.** The domain depends on nothing. The application orchestrates the domain. Adapters implement inner ports. Transports sit at the edge.
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
**Reactions to distrust.**
|
|
21
|
+
- "It's just one import." It is the direction that matters; one import is how it reverses.
|
|
22
|
+
|
|
23
|
+
**Principles behind it.**
|
|
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.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# CD-14 checks
|
|
2
|
+
|
|
3
|
+
Read [the rule and its spirit](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
|
+
|
|
5
|
+
## Clauses
|
|
6
|
+
|
|
7
|
+
| Clause | Mechanism | Checks |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `CD-14#class-syntax` | audit or eslint | a class declaration or expression outside ambient code |
|
|
10
|
+
| `CD-14#static-only-class` | eslint | a class whose members are all static |
|
|
11
|
+
| `CD-14#library-construction` | review | library classes are built only in wrapping factories and never re-exported |
|
|
12
|
+
|
|
13
|
+
## What the check flags
|
|
14
|
+
- TypeScript source files; declaration files (`.d.ts`) are skipped. Generated folders (`node_modules`, `dist`, `build`, `coverage`, `.git`, root `vendor`) are skipped by the audit mechanism. The ESLint piece lints whatever files the team's ESLint run includes.
|
|
15
|
+
- Any class declaration, class expression, `abstract class`, nested class, or class inside a runtime `namespace`, reported at the `class` keyword.
|
|
16
|
+
- Allowed: `declare class`, classes inside `declare module`, `declare global` or `declare namespace`, and `new Client()` on a class imported from a library.
|
|
17
|
+
- `library-construction` is a judgement clause. It cannot be selected and is enforced by review.
|
|
18
|
+
- Other generated code can be left out of the audit mechanism's scope with `exclude` in disciplines.json. Hand-written classes are not out of scope.
|
|
19
|
+
|
|
20
|
+
## What the ESLint check flags
|
|
21
|
+
Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-14/README.md).
|
|
22
|
+
- `hone/no-extraneous-class` is typescript-eslint's `no-extraneous-class` with `allowConstructorOnly: true`, `allowEmpty: true`, `allowStaticOnly: false` and `allowWithDecorator: true`.
|
|
23
|
+
- It flags a class whose members are all static.
|
|
24
|
+
- Allowed: empty classes, decorated classes and classes that extend another class.
|
|
25
|
+
|
|
26
|
+
## Example violation
|
|
27
|
+
```ts
|
|
28
|
+
export class Counter {}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## How to fix
|
|
32
|
+
```ts
|
|
33
|
+
export const createCounter = () => {
|
|
34
|
+
let count = 0;
|
|
35
|
+
return { increment: () => (count += 1) };
|
|
36
|
+
};
|
|
37
|
+
```
|
|
38
|
+
Return an object of functions from a factory that closes over its state.
|
|
39
|
+
|
|
40
|
+
## Exceptions
|
|
41
|
+
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a class is required, such as an adapter extending a library base class. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{ "version": 1, "exceptions": [
|
|
45
|
+
{ "kind": "authorised-location", "clause": "CD-14#class-syntax", "file": "src/adapters/vendor-client.ts", "reason": "..." }
|
|
46
|
+
] }
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
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.
|
package/rules/CD-14/README.md
CHANGED
|
@@ -4,51 +4,25 @@
|
|
|
4
4
|
|
|
5
5
|
Behaviour is composed from functions and closures, not authored classes — state lives in a factory that closes over it. A class appears only where an external library's API demands `new` at the call site; that instance is created inside the wrapping factory and held internally, never re-exported as a class. The rule is per-declaration, not per-export: even a non-exported authored class is a violation.
|
|
6
6
|
|
|
7
|
-
The
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
- Allowed: empty classes, decorated classes and classes that extend another class.
|
|
30
|
-
|
|
31
|
-
## Example violation
|
|
32
|
-
```ts
|
|
33
|
-
export class Counter {}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## How to fix
|
|
37
|
-
```ts
|
|
38
|
-
export const createCounter = () => {
|
|
39
|
-
let count = 0;
|
|
40
|
-
return { increment: () => (count += 1) };
|
|
41
|
-
};
|
|
42
|
-
```
|
|
43
|
-
Return an object of functions from a factory that closes over its state.
|
|
44
|
-
|
|
45
|
-
## Exceptions
|
|
46
|
-
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a class is required, such as an adapter extending a library base class. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|
|
47
|
-
|
|
48
|
-
```json
|
|
49
|
-
{ "version": 1, "exceptions": [
|
|
50
|
-
{ "kind": "authorised-location", "clause": "CD-14#class-syntax", "file": "src/adapters/vendor-client.ts", "reason": "..." }
|
|
51
|
-
] }
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
|
|
7
|
+
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).
|
|
8
|
+
|
|
9
|
+
## Spirit
|
|
10
|
+
|
|
11
|
+
**What the friction is for.** A class bundles state, behaviour and identity, and invites inheritance as a way to share code. The friction makes a factory closing over its state the easy shape, so state is private by construction and behaviour is plain functions.
|
|
12
|
+
|
|
13
|
+
**What a finding points at.** Match the sites against these causes.
|
|
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.
|
|
20
|
+
|
|
21
|
+
**Reactions to distrust.**
|
|
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).
|
|
25
|
+
|
|
26
|
+
**Principles behind it.**
|
|
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.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# CD-15 checks
|
|
2
|
+
|
|
3
|
+
Read [the rule and its spirit](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
|
+
|
|
5
|
+
## Clauses
|
|
6
|
+
|
|
7
|
+
| Clause | Mechanism | Checks |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `CD-15#loops` | audit | `for...of`, `for await`, counted `for` and `while` loops |
|
|
10
|
+
|
|
11
|
+
## What the check flags
|
|
12
|
+
- `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
13
|
+
- 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.
|
|
14
|
+
- 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.
|
|
15
|
+
- The source rule names element and counted iteration; the check also flags `while`.
|
|
16
|
+
- Draining an `AsyncIterable` with `for await` is allowed by the rule at declared sites; record it as an `authorised-location`.
|
|
17
|
+
|
|
18
|
+
## Example violation
|
|
19
|
+
```ts
|
|
20
|
+
for (const order of orders) {
|
|
21
|
+
totals.push(order.total);
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## How to fix
|
|
26
|
+
```ts
|
|
27
|
+
const totals = orders.map((order) => order.total);
|
|
28
|
+
```
|
|
29
|
+
Replace a counted loop with `Array.from({ length }, (_, position) => ...)`.
|
|
30
|
+
|
|
31
|
+
## Exceptions
|
|
32
|
+
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).
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{ "version": 1, "exceptions": [
|
|
36
|
+
{ "kind": "authorised-location", "clause": "CD-15#loops", "file": "src/streams/drain.ts", "reason": "..." }
|
|
37
|
+
] }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
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.
|
package/rules/CD-15/README.md
CHANGED
|
@@ -6,43 +6,25 @@ Iteration is a transformation, expressed with `map`, `reduce`, `flatMap`, `filte
|
|
|
6
6
|
|
|
7
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
8
|
|
|
9
|
-
The
|
|
10
|
-
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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.
|
|
9
|
+
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
|
+
|
|
11
|
+
## Spirit
|
|
12
|
+
|
|
13
|
+
**What the friction is for.** A loop says how to step; a transformation says what is produced. The friction makes naming the transformation the easy path, and removes counters that drift and accumulators changed in place.
|
|
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.
|
package/rules/CD-16/README.md
CHANGED
|
@@ -8,10 +8,8 @@ transformation, not imperative looping). CD-15 now carries both. This id is
|
|
|
8
8
|
retained as a redirect so existing citations resolve; it is not independently
|
|
9
9
|
enforced.
|
|
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
|
-
|
|
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.
|
|
15
|
+
See [CD-15's Spirit section](../CD-15/README.md#spirit). A counted loop is the same signal as any other loop, plus a manual index that can drift out of bounds.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# CD-17 checks
|
|
2
|
+
|
|
3
|
+
Read [the rule and its spirit](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
|
+
|
|
5
|
+
## Clauses
|
|
6
|
+
|
|
7
|
+
| Clause | Mechanism | Checks |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `CD-17#clock-sources` | audit | `Date.now()` and `new Date` |
|
|
10
|
+
|
|
11
|
+
## What the check flags
|
|
12
|
+
- `.ts` and `.tsx` files, including tests. Generated folders (`node_modules`, `dist`, `build`, `coverage`, `.git`, root `vendor`) are skipped.
|
|
13
|
+
- Any line containing `Date.now()` or `new Date`, one finding per line. Comments and strings are matched too.
|
|
14
|
+
- Other time sources (`performance.now`, timers) are not checked; they are left to review.
|
|
15
|
+
- Other generated code can be left out of the check's scope with `exclude` in disciplines.json. Hand-written code that reads the time is not out of scope; it needs the clock port.
|
|
16
|
+
|
|
17
|
+
## Example violation
|
|
18
|
+
```ts
|
|
19
|
+
const startedAt = Date.now();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## How to fix
|
|
23
|
+
```ts
|
|
24
|
+
const startedAt = clock.now();
|
|
25
|
+
```
|
|
26
|
+
Accept a clock as a dependency and read time only through it. The one real implementation lives in an adapter.
|
|
27
|
+
|
|
28
|
+
## Exceptions
|
|
29
|
+
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).
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{ "version": 1, "exceptions": [
|
|
33
|
+
{ "kind": "authorised-location", "clause": "CD-17#clock-sources", "file": "src/adapters/system-clock.ts", "reason": "..." }
|
|
34
|
+
] }
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
|