@hailstails/hone 0.1.0-pre.4 → 0.1.0-pre.6
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 +172 -38
- package/MIGRATING.md +58 -7
- package/README.md +117 -35
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/api/audit.d.ts +3 -2
- package/api/rule-set.d.ts +2 -4
- package/chunks/chunk-3HFJHJDO.js +53 -0
- package/chunks/chunk-5LCLBXP7.js +76 -0
- package/chunks/{chunk-BX6QHLSZ.js → chunk-ET5EBSJX.js} +61 -6
- package/chunks/chunk-LDQUT742.js +15 -0
- package/chunks/{chunk-RZA3OVOO.js → chunk-LOYT2AGY.js} +10 -9
- package/chunks/chunk-MVK5KFJI.js +421 -0
- package/chunks/{chunk-FOAGAYXM.js → chunk-NCDYOPHG.js} +7224 -2361
- package/chunks/chunk-WPRR2MPJ.js +22 -0
- package/chunks/{chunk-EYCRDEXX.js → chunk-XB4PCY3Q.js} +2 -13
- package/core/check/tool-command.js +1130 -230
- package/core/mechanism-port/piece-failure-types.d.ts +14 -0
- package/core/mechanism-port/runner-module-types.d.ts +5 -0
- package/core/rule-set-reader/authored-rule-set-types.d.ts +48 -0
- package/core/values/json-value.d.ts +3 -0
- package/docs/adding-a-discipline-or-mechanism.md +29 -13
- package/docs/extending.md +358 -0
- package/docs/output-contract.md +326 -0
- package/mechanisms/audit/CD-1/any-cast.js +9 -37
- package/mechanisms/audit/CD-19/import-boundaries.js +79 -68
- package/mechanisms/audit/CD-19/piece.json +5 -0
- package/mechanisms/audit/CD-2/cast-expressions.js +14 -37
- package/mechanisms/audit/CD-2/piece.json +6 -1
- package/mechanisms/audit/CD-5/comments-directives.js +121 -55
- package/mechanisms/audit/CD-5/piece.json +7 -0
- package/mechanisms/audit/runner/README.md +4 -2
- package/mechanisms/audit/runner/runner.js +102 -36
- package/mechanisms/audit/runner/typescript-parse.d.ts +6 -0
- package/mechanisms/audit/runner/walker-piece.d.ts +5 -5
- 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 +940 -232
- 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 +5 -4
- package/rules/CD-1/CHECKS.md +37 -0
- package/rules/CD-1/README.md +17 -32
- package/rules/CD-1/discipline.json +16 -6
- 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 -34
- package/rules/CD-19/discipline.json +6 -8
- package/rules/CD-2/CHECKS.md +56 -0
- package/rules/CD-2/README.md +19 -32
- package/rules/CD-2/discipline.json +93 -7
- 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 -40
- package/rules/CD-5/discipline.json +66 -0
- 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/core/mechanism-port/runner-failure-types.d.ts +0 -38
- package/core/rule-set-reader/rule-set-types.d.ts +0 -41
- /package/api/{audit.js → audit.mjs} +0 -0
- /package/api/{rule-set.js → rule-set.mjs} +0 -0
package/rules/CD-7a/README.md
CHANGED
|
@@ -4,41 +4,23 @@
|
|
|
4
4
|
|
|
5
5
|
Every type the code produces is named and exported, and callers use that named type. Deriving a type from a factory's inferred return couples the type to the implementation, hides it from find-usages, and breaks the moment the factory's internals shift. The single carve-out is an external library symbol whose package exports no named return type.
|
|
6
6
|
|
|
7
|
-
The
|
|
7
|
+
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).
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Spirit
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
| --- | --- | --- |
|
|
13
|
-
| `CD-7a#factory-return-types` | audit | a line containing `ReturnType<typeof` |
|
|
11
|
+
**What the friction is for.** A type derived from what a function happens to return changes whenever the implementation does. The friction makes naming the type the easy path, so the contract is declared, findable, and stable.
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
**What a finding points at.** Match the sites against these causes.
|
|
14
|
+
- *A contract nobody wrote down.* The factory's output was never named, so callers derive it. Name and export the type, and let the factory declare it returns that.
|
|
15
|
+
- *Implementation details leaking out.* The derived type exposes everything the factory builds. Declare only what callers should rely on.
|
|
16
|
+
- *A library with a named type you missed.* The package exports the type already. Use it.
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
- `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
19
|
-
- Any line matching `ReturnType<typeof`, one finding per line. This includes `Awaited<ReturnType<typeof ...>>` and matches inside strings.
|
|
20
|
-
- Lines starting with `//`, `/*` or `*` are ignored. A `ReturnType<` and `typeof` split across lines are not seen.
|
|
21
|
-
- The source rule's carve-out, an external library symbol with no exported return type, is not detected; record it as an exception.
|
|
18
|
+
**Where to go.** Every type the code produces has a name, and callers use the name.
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
```
|
|
20
|
+
**Reactions to distrust.**
|
|
21
|
+
- "Deriving keeps it in sync." It keeps it in sync with whatever the implementation does, including mistakes.
|
|
22
|
+
- "Naming it is duplication." The name is the contract; the implementation is one way to meet it.
|
|
27
23
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const createClient = (): Client => ({ send: () => undefined });
|
|
32
|
-
```
|
|
33
|
-
Declare and export the type, then annotate the factory with it.
|
|
34
|
-
|
|
35
|
-
## Exceptions
|
|
36
|
-
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when the type comes from a library whose package exports no named return type. 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).
|
|
37
|
-
|
|
38
|
-
```json
|
|
39
|
-
{ "version": 1, "exceptions": [
|
|
40
|
-
{ "kind": "authorised-location", "clause": "CD-7a#factory-return-types", "file": "src/adapters/vendor-client.ts", "reason": "..." }
|
|
41
|
-
] }
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
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.
|
|
24
|
+
**Principles behind it.**
|
|
25
|
+
- *Program to an interface, not an implementation* (Gamma, Helm, Johnson and Vlissides, *Design Patterns*). Callers depend on a declared contract, not on the shape the implementation produces.
|
|
26
|
+
- *Intention-revealing names* (Robert C. Martin, *Clean Code*). A named type says what the value is for.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# CD-8 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-8#switch-defaults` | audit | a `default:` arm inside a `switch` |
|
|
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
|
+
- A line matching `default:` while inside a `switch (`, tracked line by line by counting braces. One finding per line; comment lines are ignored.
|
|
14
|
+
- Every `default:` is flagged. The check cannot tell whether the switch is over a closed union, so a switch over an open set (a plain string) needs an exception. Other `default:` text inside a switch, such as an object key, is flagged too.
|
|
15
|
+
|
|
16
|
+
## Example violation
|
|
17
|
+
```ts
|
|
18
|
+
switch (event.kind) {
|
|
19
|
+
case "opened": return open();
|
|
20
|
+
default: return ignore();
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## How to fix
|
|
25
|
+
```ts
|
|
26
|
+
switch (event.kind) {
|
|
27
|
+
case "opened": return open();
|
|
28
|
+
case "closed": return ignore();
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
Name each remaining variant so the compiler checks exhaustiveness.
|
|
32
|
+
|
|
33
|
+
## Exceptions
|
|
34
|
+
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a switch is over an open set of values and needs a fallback. Use `file-carve-out` for debt in one file: it needs a `whyChain` and is forfeited once the file is touched. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{ "version": 1, "exceptions": [
|
|
38
|
+
{ "kind": "authorised-location", "clause": "CD-8#switch-defaults", "file": "src/parsing/token-reader.ts", "reason": "..." }
|
|
39
|
+
] }
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Every record, `authorised-location` included, also needs a `whyChain` that follows the [why-chain contract](../../docs/why-chain-contract.md): five whys chained cause to cause, a `rootCause`, its `rootCheck`, a `readback` and an `owner`. The one exception is a record imported from an earlier system, which carries `provenance` instead. [The exceptions format](../../README.md#discipline-exceptionsjson) gives both shapes.
|
package/rules/CD-8/README.md
CHANGED
|
@@ -4,45 +4,23 @@
|
|
|
4
4
|
|
|
5
5
|
A switch over a closed discriminated union carries no `default:` arm. Exhaustiveness is the type system's job: with no default, adding a variant surfaces as a compile error at every switch that has not handled it. A `default:` swallows that signal and lets the new variant slip through silently at runtime.
|
|
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
|
-
|
|
30
|
-
## How to fix
|
|
31
|
-
```ts
|
|
32
|
-
switch (event.kind) {
|
|
33
|
-
case "opened": return open();
|
|
34
|
-
case "closed": return ignore();
|
|
35
|
-
}
|
|
36
|
-
```
|
|
37
|
-
Name each remaining variant so the compiler checks exhaustiveness.
|
|
38
|
-
|
|
39
|
-
## Exceptions
|
|
40
|
-
Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a switch is over an open set of values and needs a fallback. 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-8#switch-defaults", "file": "src/parsing/token-reader.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.
|
|
7
|
+
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).
|
|
8
|
+
|
|
9
|
+
## Spirit
|
|
10
|
+
|
|
11
|
+
**What the friction is for.** When a new case is added, every place that must handle it should fail to compile until it does. A catch-all arm switches that off. The friction keeps the compiler finding those places for you.
|
|
12
|
+
|
|
13
|
+
**What a finding points at.** Match the sites against these causes.
|
|
14
|
+
- *A catch-all kept "for safety".* The union is closed, so the arm can only hide future cases. Remove it and let the compiler check exhaustiveness.
|
|
15
|
+
- *Input that was never parsed.* The value might be anything because it came from outside unchecked. Parse it at the boundary into the closed union; then the switch is closed.
|
|
16
|
+
- *Several cases sharing one arm.* Default is used as "everything else does the same". List those cases by name.
|
|
17
|
+
|
|
18
|
+
**Where to go.** Every switch over a closed union names every case. Adding a case lights up every place that must decide what to do with it.
|
|
19
|
+
|
|
20
|
+
**Reactions to distrust.**
|
|
21
|
+
- "What if a value we don't know arrives?" Then the value was not parsed. That is a boundary problem, not a switch problem.
|
|
22
|
+
- "Listing every case is verbose." The list is what the compiler checks.
|
|
23
|
+
|
|
24
|
+
**Principles behind it.**
|
|
25
|
+
- *Exhaustiveness checking.* The compiler proves every case is handled; a catch-all arm withdraws the proof.
|
|
26
|
+
- *Make illegal states unrepresentable* (Yaron Minsky). Once the input is a closed union, an unknown case cannot exist to be defaulted.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# CD-9 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-9#result-failures` | review | expected operational failures are returned as a Result with a tagged error union, not thrown |
|
|
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-9/README.md
CHANGED
|
@@ -4,16 +4,23 @@
|
|
|
4
4
|
|
|
5
5
|
Every expected, operational failure is modelled as data — a result-shaped return carrying a tagged error union that enumerates each way the operation can fail — not raised as an exception. Infrastructure failure is an operational outcome, not an escape into throwing. Callers dispatch on the error as a value, so no failure path is invisible in the type.
|
|
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-9#result-failures` | review | expected operational failures are returned as a Result with a tagged error union, not thrown |
|
|
11
|
+
**What the friction is for.** A failure the type does not mention is a failure the caller will not handle. The friction makes returning failures as values the easy path, so every way an operation can fail is visible and handled.
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
**What a finding points at.** Match the sites against these causes.
|
|
14
|
+
- *Failures thrown because they were never listed.* Name each way the operation fails as a tagged variant.
|
|
15
|
+
- *Infrastructure treated as exceptional.* Timeouts and missing records are thrown. They are ordinary outcomes; return them.
|
|
16
|
+
- *Library exceptions leaking.* Catch at the wrapping boundary and return a result.
|
|
17
|
+
- *Callers that ignore failure.* A result is unwrapped without looking at the error. Handle each variant.
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
**Where to go.** Every operation that can fail returns a result with a tagged error union, and callers dispatch on it.
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
**Reactions to distrust.**
|
|
22
|
+
- "Exceptions are simpler." Simpler to write, because they skip the handling. The handling is the point.
|
|
23
|
+
|
|
24
|
+
**Principles behind it.**
|
|
25
|
+
- *Railway oriented programming* (Scott Wlaschin). Success and failure travel as two tracks of one value.
|
|
26
|
+
- *Make illegal states unrepresentable* (Yaron Minsky). A tagged error union lists exactly the failures that can occur.
|
package/rules/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# Disciplines
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Each discipline has two pages. Its `README.md` holds the rule and its spirit: what the friction is for, what a finding usually points at, the direction to go and the principles behind it. Its `CHECKS.md` holds the mechanics: the clauses, what each check flags, and how to record an exception. Read the rule first. [The spirit of the rules](SPIRIT.md) explains the approach for the whole set.
|
|
4
|
+
|
|
5
|
+
Adopters select clauses in `disciplines.json`. Selecting one clause adopts its discipline, so every mechanical clause of an adopted discipline must be selected, each through a mechanism its CHECKS.md lists, or listed as `"not-adopted"`; the check reports the rest as uncovered. Clauses marked (review) are judgement clauses: they cannot be selected and are applied in review with the discipline's review lens, as [ADOPTING.md](../ADOPTING.md#9-apply-the-judgement-rules) describes.
|
|
4
6
|
|
|
5
7
|
| ID | Title | Clauses | Files checked | Review lens |
|
|
6
8
|
| --- | --- | --- | --- | --- |
|
|
7
9
|
| [CD-1](CD-1/README.md) | No any, ever | `CD-1#any-cast`, `CD-1#explicit-any`, `CD-1#implicit-any-let` | `.ts`, `.tsx` | [type-soundness](../methods/lenses/type-soundness.md) |
|
|
8
|
-
| [CD-2](CD-2/README.md) | Closed enumerated list of permitted cast sites | `CD-2#cast-expressions` | `.ts`, `.tsx` | [type-soundness](../methods/lenses/type-soundness.md) |
|
|
10
|
+
| [CD-2](CD-2/README.md) | Closed enumerated list of permitted cast sites | `CD-2#cast-expressions`, `CD-2#non-null-assertions` | `.ts`, `.tsx` | [type-soundness](../methods/lenses/type-soundness.md) |
|
|
9
11
|
| [CD-3](CD-3/README.md) | Strict mode flags inherited, never overridden | `CD-3#strict`, `#no-unchecked-indexed-access`, `#exact-optional-property-types`, `#no-implicit-override`, `#no-fallthrough-cases-in-switch`, `#no-property-access-from-index-signature`, `#use-unknown-in-catch-variables` | `tsconfig.json` | [type-soundness](../methods/lenses/type-soundness.md) |
|
|
10
12
|
| [CD-4](CD-4/README.md) | Zod at every external boundary | `CD-4#boundary-validation` (review) | — | [zod-boundary](../methods/lenses/zod-boundary.md) |
|
|
11
13
|
| [CD-5](CD-5/README.md) | No comments, no JSDoc | `CD-5#comments-directives` | `.ts`, `.tsx` | [naming](../methods/lenses/naming.md) |
|
|
@@ -29,7 +31,7 @@ Adopters select clauses in `disciplines.json`. Selecting one clause adopts its d
|
|
|
29
31
|
| [CD-22](CD-22/README.md) | Middleware generic context constraint | `CD-22#middleware-context` (review) | — | [di-discipline](../methods/lenses/di-discipline.md) |
|
|
30
32
|
| [CD-23](CD-23/README.md) | Every unit has a co-located test sibling | `CD-23#export-test-sibling` | production `.ts`, `.tsx` | [test-discipline](../methods/lenses/test-discipline.md) |
|
|
31
33
|
| [CD-24](CD-24/README.md) | Every file is unit-tested | see CD-23 | — | [test-discipline](../methods/lenses/test-discipline.md) |
|
|
32
|
-
| [CD-25](CD-25/README.md) | Unit tests
|
|
34
|
+
| [CD-25](CD-25/README.md) | Unit tests replace everything outside the unit with test doubles | `CD-25#dependency-isolation` | `*.test.ts`, `*.test.tsx` | [di-discipline](../methods/lenses/di-discipline.md), [test-discipline](../methods/lenses/test-discipline.md) |
|
|
33
35
|
| [CD-26](CD-26/README.md) | No module-mocking — module-mock means DI is wrong | `CD-26#module-mocking` | `*.test.ts`, `*.test.tsx` | [di-discipline](../methods/lenses/di-discipline.md), [test-discipline](../methods/lenses/test-discipline.md) |
|
|
34
36
|
| [CD-27](CD-27/README.md) | Tests are zero-everything — zero logic, zero branches, zero unpredictability | `CD-27#test-body-logic`, `CD-27#focused-tests`, `CD-27#skipped-tests` | `*.test.ts`, `*.test.tsx` | [test-discipline](../methods/lenses/test-discipline.md) |
|
|
35
37
|
| [CD-28](CD-28/README.md) | Tests assert only what the unit is directly responsible for | `CD-28#unit-responsibility` (review) | — | [test-discipline](../methods/lenses/test-discipline.md) |
|
package/rules/SPIRIT.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# The spirit of the rules
|
|
2
|
+
|
|
3
|
+
## What the friction is for
|
|
4
|
+
|
|
5
|
+
Every rule here is deliberate friction. None of it is arbitrary. Each rule makes the path of least resistance the good one, so the easy outcome and the good outcome are the same outcome. Each rule also holds the present self to account for the future self who inherits the code.
|
|
6
|
+
|
|
7
|
+
The friction is absolute on purpose. An escape inside a rule is a hole, and a hole justifies not thinking the design through. One permitted escape becomes the reason for the next.
|
|
8
|
+
|
|
9
|
+
A finding is rarely about the line it names. It is a signal about the design around that line: a boundary that is missing, an earlier choice that forces the workaround, a port wider than its callers need. Listen to what the friction is telling you. The real problem is almost never the checker.
|
|
10
|
+
|
|
11
|
+
## When the check is red
|
|
12
|
+
|
|
13
|
+
Take this chain, in order.
|
|
14
|
+
|
|
15
|
+
1. **Measure.** Count the sites for the failing clause. Group them by folder, by the value or dependency involved, and by who wrote them when.
|
|
16
|
+
2. **Ask what each group points at.** Read the rule's Spirit section and match each group against its usual causes. Most groups share one cause.
|
|
17
|
+
3. **Then decide.** Name the cause, where it lives, the forward goal, and the first step that unlocks it. Fix the cause and the sites go with it.
|
|
18
|
+
|
|
19
|
+
Exclusions and settings are not the first move. Reaching for one before step 2 hides the signal before anyone has read it. A count that looks like noise is usually one missing boundary seen from many places.
|
|
20
|
+
|
|
21
|
+
## Debt, not noise
|
|
22
|
+
|
|
23
|
+
On first adoption of an existing codebase, a high count is debt made visible. It is not evidence the rule is wrong for the codebase. The useful response is an assessment for each high-count clause: which cause applies here, where, the forward goal, and the steps toward it, written down where the next person to hit the red check will read it ([ADOPTING step 5a](../ADOPTING.md#5a-write-the-assessment)). A file carve-out holds that debt at rest while the steps are taken. Touching the file pays it ([CD-46](CD-46/README.md)).
|
|
24
|
+
|
|
25
|
+
## Boundaries are where exceptions belong
|
|
26
|
+
|
|
27
|
+
Some code has to touch the outside: a library, the runtime, raw input. Those places are boundaries. A clean boundary is the cheap, authorised place for what the rules forbid elsewhere: one file, recorded once, small enough to read whole. The rest of the code then needs no escape. If an exception keeps wanting to spread, the boundary is in the wrong place or does not exist yet.
|
|
28
|
+
|
|
29
|
+
## Not adopted, not run, carved out, escaped
|
|
30
|
+
|
|
31
|
+
A clause can be in one of three declared states. A fourth thing is the hole.
|
|
32
|
+
|
|
33
|
+
1. **Not adopted.** The rule does not apply to this codebase. A tech lead declares that, in the open.
|
|
34
|
+
2. **Adopted, mechanism not run.** The rule binds, but its mechanical check is not a true measure of the rule's intent in this codebase, or cannot work here for a technical reason. The check is set aside; the intent is not. It is still owed, through review.
|
|
35
|
+
3. **Clause-wide carve-out.** The rule binds and its check is sound. There is debt the codebase cannot address right now, recorded with its why-chain and an owner who will pay it down.
|
|
36
|
+
4. **An escape at a site.** The rule is adopted, its check is sound, and one place steps around it. That keeps the rule's name and loses its effect. It is the hole that justifies not thinking the design through.
|
|
37
|
+
|
|
38
|
+
Choose 1, 2 or 3 deliberately, with reasons. Do not do 4.
|
|
39
|
+
|
|
40
|
+
## Tests are code
|
|
41
|
+
|
|
42
|
+
Tests are not exempt. A test that needs a cast, a test double with logic, a module intercept or a branch is reporting on the unit's seams. The test is the unit's first consumer. The fix usually belongs in the unit's design, not in the test.
|
|
43
|
+
|
|
44
|
+
## Older than these rules
|
|
45
|
+
|
|
46
|
+
Each rule encodes lessons programmers learned before us and wrote down under names you can look up: the SOLID principles, ports and adapters, "parse, don't validate", making illegal states unrepresentable, the test pyramid, the kinds of test double, and others. Each rule page names the principles behind it, with one line on how each applies. Read them to learn the pattern and the reasoning, not only the rule.
|
|
47
|
+
|
|
48
|
+
## Who does what
|
|
49
|
+
|
|
50
|
+
Each rule's Spirit section names the usual causes behind its findings and the direction each points, so a reader can tell which one they have. The repository's own assessment then sharpens that to what is specific to the codebase and its intentions: which cause applies, where, the forward goal and the steps. It does not repeat the rule.
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { RepoPath } from "../values/repo-path-types.js";
|
|
2
|
-
export type PeerKind = "required" | "optional";
|
|
3
|
-
export type RunnerFailure = {
|
|
4
|
-
readonly kind: "piece-invalid";
|
|
5
|
-
readonly pieceRoot: string;
|
|
6
|
-
readonly detail: string;
|
|
7
|
-
} | {
|
|
8
|
-
readonly kind: "tool-failed";
|
|
9
|
-
readonly detail: string;
|
|
10
|
-
} | {
|
|
11
|
-
readonly kind: "file-unreadable";
|
|
12
|
-
readonly file: RepoPath;
|
|
13
|
-
readonly detail: string;
|
|
14
|
-
} | {
|
|
15
|
-
readonly kind: "plugin-conflict";
|
|
16
|
-
readonly detail: string;
|
|
17
|
-
} | {
|
|
18
|
-
readonly kind: "team-config-unloadable";
|
|
19
|
-
readonly detail: string;
|
|
20
|
-
} | {
|
|
21
|
-
readonly kind: "runner-invalid-output";
|
|
22
|
-
readonly detail: string;
|
|
23
|
-
} | {
|
|
24
|
-
readonly kind: "file-unparseable";
|
|
25
|
-
readonly file: RepoPath;
|
|
26
|
-
readonly detail: string;
|
|
27
|
-
} | {
|
|
28
|
-
readonly kind: "toolchain-unavailable";
|
|
29
|
-
readonly packageName: string;
|
|
30
|
-
readonly peer: PeerKind;
|
|
31
|
-
readonly supported: string;
|
|
32
|
-
readonly found: string;
|
|
33
|
-
} | {
|
|
34
|
-
readonly kind: "toolchain-shadowed";
|
|
35
|
-
readonly packageName: string;
|
|
36
|
-
readonly location: string;
|
|
37
|
-
readonly installRoot: string;
|
|
38
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { AnchorKind } from "../values/anchor.js";
|
|
2
|
-
import type { ClauseId, DisciplineId, MechanismId } from "../values/identifier-types.js";
|
|
3
|
-
import type { RepoPath } from "../values/repo-path-types.js";
|
|
4
|
-
export type SourceCase = {
|
|
5
|
-
readonly name: string;
|
|
6
|
-
readonly fileName: RepoPath;
|
|
7
|
-
readonly source: string;
|
|
8
|
-
readonly expectedLines: readonly number[];
|
|
9
|
-
};
|
|
10
|
-
export type ClauseExceptions = "allowed" | "refused";
|
|
11
|
-
export type ClauseDefinition = {
|
|
12
|
-
readonly kind: "mechanical";
|
|
13
|
-
readonly id: ClauseId;
|
|
14
|
-
readonly summary: string;
|
|
15
|
-
readonly mechanisms: readonly MechanismId[];
|
|
16
|
-
readonly anchor: AnchorKind;
|
|
17
|
-
readonly exceptions: ClauseExceptions;
|
|
18
|
-
readonly cases: {
|
|
19
|
-
readonly flag: readonly SourceCase[];
|
|
20
|
-
readonly allow: readonly SourceCase[];
|
|
21
|
-
};
|
|
22
|
-
} | {
|
|
23
|
-
readonly kind: "judgement";
|
|
24
|
-
readonly id: ClauseId;
|
|
25
|
-
readonly summary: string;
|
|
26
|
-
readonly enforcedBy: "review";
|
|
27
|
-
};
|
|
28
|
-
export type DisciplineFile = {
|
|
29
|
-
readonly version: 1;
|
|
30
|
-
readonly id: DisciplineId;
|
|
31
|
-
readonly clauses: readonly ClauseDefinition[];
|
|
32
|
-
};
|
|
33
|
-
export type PieceFile = {
|
|
34
|
-
readonly version: 1;
|
|
35
|
-
readonly discipline: DisciplineId;
|
|
36
|
-
readonly mechanism: MechanismId;
|
|
37
|
-
readonly clauses: readonly {
|
|
38
|
-
readonly clause: ClauseId;
|
|
39
|
-
readonly settings: unknown;
|
|
40
|
-
}[];
|
|
41
|
-
};
|
|
File without changes
|
|
File without changes
|