@hailstails/hone 1.4.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 +14 -0
- package/MIGRATING.md +17 -0
- package/README.md +10 -10
- package/api/testing.js +2 -2
- package/chunks/{chunk-FEWCJU7H.js → chunk-2O46EB4E.js} +6 -0
- package/chunks/{chunk-6SM3HKWO.js → chunk-5U4VTFD5.js} +88 -51
- package/core/check/tool-command.js +379 -56
- package/core/mechanism-port/runner-result-types.d.ts +4 -0
- package/docs/adding-a-discipline-or-mechanism.md +2 -0
- package/docs/extending.md +1 -0
- package/docs/output-contract.md +17 -6
- package/mechanisms/audit/CD-27/test-body-logic.js +5 -2
- package/mechanisms/audit/runner/runner.js +5 -3
- package/mechanisms/eslint/runner/runner.js +7 -3
- 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 +10 -13
- package/methods/lenses/function-first.md +16 -18
- package/package.json +1 -1
- package/rules/CD-1/CHECKS.md +4 -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 +3 -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 +5 -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 +3 -1
- 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 +16 -7
- package/rules/CD-27/README.md +6 -20
- 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 +4 -2
- package/rules/CD-41/README.md +6 -22
- 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/rules/CD-6/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.** Keeps: [One word everywhere](../rules.md#one-word-everywhere); casing a check.
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [One word everywhere](../rules.md#one-word-everywhere) and [Whole words](../typescript/recipes.md#whole-words).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *A concept not yet understood.* `data` or `result` because the writer did not know what the value was. Find out, then name it.
|
|
15
|
-
- *A function returning a mix.* `result` is the only honest name because the function returns several things. Split it.
|
|
16
|
-
- *No shared vocabulary.* The team has no agreed words for the domain, so names fall back to shapes. Agree the terms and use them in code.
|
|
17
|
-
- *A framework's habit copied inward.* `req`, `res`, `e` from library examples. Name it for what it is in your code.
|
|
18
|
-
|
|
19
|
-
**Where to go.** Every name states the concept, in the domain's words, at every scope.
|
|
11
|
+
Review lens: [naming](../../methods/lenses/naming.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
|
-
- "Everyone knows what `i` means." They know it is an index, not an index of what.
|
|
23
|
-
- "Short scopes don't need long names." The rule covers every scope. The reader of a short scope still has to reconstruct the meaning.
|
|
24
|
-
- "It's the library's convention." Conventions belong at the boundary. Inside, use your words.
|
|
13
|
+
## Spirit
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
- *Intention-revealing names* (Robert C. Martin, *Clean Code*). A name should say why the thing exists and what it does, so no comment is needed.
|
|
28
|
-
- *Ubiquitous language* (Eric Evans, *Domain-Driven Design*). The code uses the same words as the people who know the domain.
|
|
15
|
+
Start from the symptom a finding names: [Shorthand name](../typescript/symptoms.md#shorthand-name) and [Name off its casing](../typescript/symptoms.md#name-off-its-casing). Each symptom names the cases it may indicate and the rules they point at. The why is on [Our code reads in the common language](../principles.md#our-code-reads-in-the-common-language).
|
package/rules/CD-7/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-7 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptoms: [Drawer path](../typescript/symptoms.md#drawer-path) and [Name off its casing](../typescript/symptoms.md#name-off-its-casing).
|
|
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-7/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: One reason per module; One word everywhere; filename case a check.
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [One reason per module](../rules.md#one-reason-per-module), [One word everywhere](../rules.md#one-word-everywhere) and [Screaming folders](../typescript/recipes.md#screaming-folders).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *A concept nobody named.* The drawer holds functions that all serve one idea the codebase never named, such as money, dates or identifiers. Name the idea and give it a module.
|
|
15
|
-
- *Shared by accident.* Code moved to a common place because two callers needed it. Decide whether it belongs to one of them or is a concept of its own.
|
|
16
|
-
- *Shapes separated from their owners.* A types file holds shapes far from the code that uses them. Put each shape beside the code it describes.
|
|
17
|
-
- *Folders sorted by kind.* The tree groups things by what they are, not by what they do. Group by capability.
|
|
18
|
-
|
|
19
|
-
**Where to go.** Every file and folder name says what it holds, so a reader finds code by asking what it does. The rename is the small part; finding the concept behind it is the work.
|
|
11
|
+
Review lens: [naming](../../methods/lenses/naming.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 name." The name is where the missing concept shows. A synonym such as "core" or "base" keeps the drawer.
|
|
23
|
-
- "The framework requires that path." Then authorise that path. What you add under it still needs a real home.
|
|
24
|
-
- "We'll sort it later." Category folders only grow.
|
|
13
|
+
## Spirit
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
- *Screaming architecture* (Robert C. Martin). The folder structure should tell a reader what the system does, not which kinds of file it contains.
|
|
28
|
-
- *Single Responsibility Principle* (Robert C. Martin, SOLID). A module has one reason to change. A drawer of unrelated helpers has as many reasons as it has helpers.
|
|
29
|
-
- *Primitive Obsession* (a code smell in Fowler's *Refactoring*). Helpers that all handle one raw value, such as an amount or a date string, usually mark a domain type nobody created.
|
|
15
|
+
Start from the symptom a finding names: [Drawer path](../typescript/symptoms.md#drawer-path) and [Name off its casing](../typescript/symptoms.md#name-off-its-casing). 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) and [Our code reads in the common language](../principles.md#our-code-reads-in-the-common-language).
|
package/rules/CD-7a/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-7a checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptom: [Type derived from code](../typescript/symptoms.md#type-derived-from-code).
|
|
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
|
|
package/rules/CD-7a/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.** Symptom of [Outside dependencies stay at boundaries](../rules.md#outside-dependencies-stay-at-boundaries).
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Outside dependencies stay at boundaries](../rules.md#outside-dependencies-stay-at-boundaries) and [Named, exported type](../typescript/recipes.md#named-exported-type).
|
|
12
10
|
|
|
13
|
-
|
|
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.
|
|
17
|
-
|
|
18
|
-
**Where to go.** Every type the code produces has a name, and callers use the name.
|
|
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).
|
|
19
12
|
|
|
20
|
-
|
|
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.
|
|
13
|
+
## Spirit
|
|
23
14
|
|
|
24
|
-
|
|
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.
|
|
15
|
+
Start from the symptom a finding names: [Type derived from code](../typescript/symptoms.md#type-derived-from-code). 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) and [The type checker proves it](../principles.md#the-type-checker-proves-it).
|
package/rules/CD-8/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-8 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Symptom: [Default on a closed union](../typescript/symptoms.md#default-on-a-closed-union).
|
|
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
|
|
package/rules/CD-8/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.** Symptom of [Kinds are named](../rules.md#kinds-are-named).
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Kinds are named](../rules.md#kinds-are-named) and [Tagged union and exhaustive switch](../typescript/recipes.md#tagged-union-and-exhaustive-switch).
|
|
12
10
|
|
|
13
|
-
|
|
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.
|
|
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).
|
|
19
12
|
|
|
20
|
-
|
|
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.
|
|
13
|
+
## Spirit
|
|
23
14
|
|
|
24
|
-
|
|
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.
|
|
15
|
+
Start from the symptom a finding names: [Default on a closed union](../typescript/symptoms.md#default-on-a-closed-union). 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-9/CHECKS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# CD-9 checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Recipe: [Result union](../typescript/recipes.md#result-union). The outcome it protects is seen by [Throw between our units](../typescript/symptoms.md#throw-between-our-units).
|
|
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-9/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: [Failures are values](../rules.md#failures-are-values).
|
|
10
8
|
|
|
11
|
-
**
|
|
9
|
+
**Read.** [Failures are values](../rules.md#failures-are-values) and [Result union](../typescript/recipes.md#result-union).
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- *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.
|
|
18
|
-
|
|
19
|
-
**Where to go.** Every operation that can fail returns a result with a tagged error union, and callers dispatch on it.
|
|
11
|
+
Review lens: [errors-as-data](../../methods/lenses/errors-as-data.md). The lens reviews the whole rule, including what no check flags. How it is checked: [CHECKS.md](CHECKS.md). The thinking behind every rule: [the spirit of the rules](../SPIRIT.md).
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
- "Exceptions are simpler." Simpler to write, because they skip the handling. The handling is the point.
|
|
13
|
+
## Spirit
|
|
23
14
|
|
|
24
|
-
|
|
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.
|
|
15
|
+
Start from the symptom a finding names: [Throw between our units](../typescript/symptoms.md#throw-between-our-units) and [Failure shaped as success](../typescript/symptoms.md#failure-shaped-as-success). 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/README.md
CHANGED
|
@@ -1,54 +1,71 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
|
18
|
-
|
|
19
|
-
| [
|
|
20
|
-
| [
|
|
21
|
-
| [
|
|
22
|
-
| [
|
|
23
|
-
| [
|
|
24
|
-
| [
|
|
25
|
-
| [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
# How to read the rules
|
|
2
|
+
|
|
3
|
+
A finding names a symptom. Read it along the chain:
|
|
4
|
+
|
|
5
|
+
**symptom → case → why → reason to change**
|
|
6
|
+
|
|
7
|
+
A [symptom](typescript/symptoms.md) is what was seen in the code. It points at the [cases](cases.md) it may indicate: what the code was trying to do. Each case owes one or more whys, its [principles](principles.md), and each principle names its reason to change. The [rules](rules.md) under a principle say what must hold, and the [recipes](typescript/recipes.md) are the known methods that make a rule hold.
|
|
8
|
+
|
|
9
|
+
## Why these rules are strict
|
|
10
|
+
|
|
11
|
+
"my rules are stricter than most because leaving any trade off or judgement based calls to llm leads to the easiest option locally. Which is almost never the better choice."
|
|
12
|
+
|
|
13
|
+
So no principle or rule leaves a trade-off or a judgement call to the reader. It states what must hold. The room for a correct exception is a record, never softness in the text. Being stricter than a cited source is intended.
|
|
14
|
+
|
|
15
|
+
## The model
|
|
16
|
+
|
|
17
|
+
| Kind | What it is | Industry name |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| [Principle](principles.md) | A why. What it protects and its reason to change. | Rationale |
|
|
20
|
+
| [Case](cases.md) | What the code is trying to do ("this needs the current time"). Where the why is owed. | Problem in context |
|
|
21
|
+
| [Rule](rules.md) | What must hold. Carries no exceptions. | Requirement |
|
|
22
|
+
| [Recipe](typescript/recipes.md) | A known method that makes a rule hold, with the reason it was chosen. "It's as binding as it's reasoning. The proof of burden is on the deviation to show that the reason it was chosen no longer holds." | Acceptable means of compliance; pattern |
|
|
23
|
+
| [Symptom](typescript/symptoms.md) | Something seen in code. Suspect by default. May point at several rules. | Code smell |
|
|
24
|
+
| [Check](typescript/checks.md) | How a symptom is found. Imperfect by design. | Enforcement; fitness function |
|
|
25
|
+
| [Record](records.md) | A thought-through use, known debt, or a design decision. | Deviation record; ADR |
|
|
26
|
+
|
|
27
|
+
"Reasons to change" is not on the list. It is the test used to place a boundary and to decide whether two things are one.
|
|
28
|
+
|
|
29
|
+
## The language boundary
|
|
30
|
+
|
|
31
|
+
Principles, cases and rules are cross-language. Recipes, symptoms and checks are written for one language; TypeScript is the one today, under [typescript](typescript/symptoms.md).
|
|
32
|
+
|
|
33
|
+
Two tests for a rule:
|
|
34
|
+
1. It names no language feature. If it only makes sense because of a quirk of the language, it is a symptom or a recipe for that language.
|
|
35
|
+
2. The other rules together do not already give it. If they do, it is a case.
|
|
36
|
+
|
|
37
|
+
## Names, not numbers
|
|
38
|
+
|
|
39
|
+
Rules, principles, cases, recipes and symptoms are named, not numbered. A name's id is the name, hyphenated. [Every CD](numbers.md) maps each old number to its new names. Selections, records and findings still use the numbered clause addresses, and each numbered folder still holds its discipline's `CHECKS.md`.
|
|
40
|
+
|
|
41
|
+
The numbered `README.md` pages are the earlier form of these rules. Where they differ, the pages here govern. Findings still link to the numbered pages until they are replaced; [Every CD](numbers.md#every-numbered-discipline) lists each one with its title, clauses, files checked and review lens.
|
|
42
|
+
|
|
43
|
+
## Words used the same way everywhere
|
|
44
|
+
|
|
45
|
+
- **Business logic:** all code outside a recorded boundary.
|
|
46
|
+
- **Unit:** one function.
|
|
47
|
+
- **Port:** an interface of ours that business logic is handed.
|
|
48
|
+
- **Adapter:** a unit inside a recorded boundary that fulfils a port.
|
|
49
|
+
- **Passed in:** given as an argument or to the factory that built the unit. Never imported.
|
|
50
|
+
- **One decision:** one reason to change.
|
|
51
|
+
- **Outside dependency:** what was called a package. An internal package is our own code.
|
|
52
|
+
|
|
53
|
+
## The pages
|
|
54
|
+
|
|
55
|
+
| Page | What it holds |
|
|
56
|
+
|---|---|
|
|
57
|
+
| [principles.md](principles.md) | The principles, each with what must hold, what it protects, its reason to change and where a breach sits |
|
|
58
|
+
| [cases.md](cases.md) | The cases under each principle, the whys each owes, and what to do |
|
|
59
|
+
| [rules.md](rules.md) | The named rules |
|
|
60
|
+
| [records.md](records.md) | The record kinds, and today's record formats beside them |
|
|
61
|
+
| [sources.md](sources.md) | The sources behind each principle, rule, recipe and record kind |
|
|
62
|
+
| [typescript/recipes.md](typescript/recipes.md) | The recipes for TypeScript |
|
|
63
|
+
| [typescript/symptoms.md](typescript/symptoms.md) | The symptoms in TypeScript, and how near today's checks come |
|
|
64
|
+
| [typescript/checks.md](typescript/checks.md) | Each check, its margin and its settings |
|
|
65
|
+
| [numbers.md](numbers.md) | Every CD number and its new names |
|
|
66
|
+
|
|
67
|
+
## Selecting checks
|
|
68
|
+
|
|
69
|
+
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. Review clauses 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.
|
|
70
|
+
|
|
71
|
+
Exceptions are recorded in `discipline-exceptions.json`; see [the package README](../README.md#discipline-exceptionsjson). [The spirit of the rules](SPIRIT.md) explains what the friction is for.
|
package/rules/SPIRIT.md
CHANGED
|
@@ -13,7 +13,7 @@ A finding is rarely about the line it names. It is a signal about the design aro
|
|
|
13
13
|
Take this chain, in order.
|
|
14
14
|
|
|
15
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
|
|
16
|
+
2. **Ask what each group points at.** Read the symptom's "May indicate" and "Breach usually sits" lines on [the symptoms page](typescript/symptoms.md) and match each group against them. Most groups share one cause.
|
|
17
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
18
|
|
|
19
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.
|
|
@@ -43,8 +43,8 @@ Tests are not exempt. A test that needs a cast, a test double with logic, a modu
|
|
|
43
43
|
|
|
44
44
|
## Older than these rules
|
|
45
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.
|
|
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. [The sources page](sources.md) names the source behind each principle, rule and recipe, and how the item relates to it. Read them to learn the pattern and the reasoning, not only the rule.
|
|
47
47
|
|
|
48
48
|
## Who does what
|
|
49
49
|
|
|
50
|
-
Each
|
|
50
|
+
Each symptom on [the symptoms page](typescript/symptoms.md) names the cases it may indicate and where the breach usually sits, 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.
|
package/rules/cases.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Cases
|
|
2
|
+
|
|
3
|
+
A case is what the code is trying to do. It is where the why is owed. A case may owe more than one why. "Owes" lists principles by short name; the first one decides what to do.
|
|
4
|
+
|
|
5
|
+
Short names: Tests ([Tests are ours](principles.md#tests-are-ours)), One place ([One place decides](principles.md#one-place-decides)), Effects ([No hidden effects](principles.md#no-hidden-effects)), Boundary ([External behaviour sits at a boundary](principles.md#external-behaviour-sits-at-a-boundary)), Leak ([No leak across a boundary](principles.md#no-leak-across-a-boundary)), Checker ([The type checker proves it](principles.md#the-type-checker-proves-it)), Language ([Our code reads in the common language](principles.md#our-code-reads-in-the-common-language)), Outside risk ([Outside risk is carried on purpose](principles.md#outside-risk-is-carried-on-purpose)).
|
|
6
|
+
|
|
7
|
+
Cases name no language, tool or library.
|
|
8
|
+
|
|
9
|
+
## Tests are ours
|
|
10
|
+
|
|
11
|
+
| Case | Owes | What to do |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| Uses what a collaborator gives back | Tests; One place | Every collaborator whose result it uses, our own units included, is passed in. The test stubs it with a written-out value and asserts only what the unit returns and calls. A stub that needs logic means the port or the collaborator holds too much: fix that. |
|
|
14
|
+
| States what the unit gives back, for one case or several | Tests; One place | Each test is one complete, distinct case. The expected value is written out, never worked out. Several cases are each written out; nothing in the test builds or picks them. No throw or catch in a test. |
|
|
15
|
+
| Checks a value that may be one of several outcomes | Tests; Checker | An assertion proves which outcome it is, so the type narrows; then the test reads it plainly. No condition, optional read or cast. |
|
|
16
|
+
| Gives each unit its test | Tests; One place | Every unit has its own test in the companion file, and it runs. A unit that only wires has a test of its wiring. No coverage figure stands in. |
|
|
17
|
+
| Tests across units or against a real system | Tests; One place | Each behaviour is tested at the level that owns it. An integration test checks only a binding to the outside, or that units join. It is the only place a file on disk or a real subsystem belongs, and only the one its binding needs. It inherits nothing from the machine. |
|
|
18
|
+
|
|
19
|
+
## One place decides
|
|
20
|
+
|
|
21
|
+
| Case | Owes | What to do |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| Coordinates other units | One place; Tests | It picks which of our units run, in what order, and passes their results on. Branching, computing or reshaping between calls is its own unit. A unit that only forwards one call decides nothing: fold it in. A test suite's body is a list of cases, not a coordinator. |
|
|
24
|
+
| Does one job | One place; Checker | One decision. It calls no other unit of business logic; it may call ports passed in to it. A second question, a mode picked by a true-or-false argument, or a mix of results is a second unit. |
|
|
25
|
+
| Checks conditions before its work | One place; Checker | Each condition that ends the work returns at once, at one level. The work is the last return, never nested in a condition. |
|
|
26
|
+
| Builds the real implementations | One place; Boundary | One place, at start-up, builds every real implementation and passes it in. Nothing else builds one. |
|
|
27
|
+
| Reuses behaviour from another unit or type | One place; Language | Two callers share a unit only when it is one decision for both. Shared behaviour is a call to that unit, never inheritance. |
|
|
28
|
+
| Puts code in a file or folder | One place; Language | A module holds what changes for one reason, named for that domain concept. A domain type lives with its logic; a file of types alone holds only port declarations. A drawer of unrelated pieces, test helpers included, has no home. |
|
|
29
|
+
|
|
30
|
+
## No hidden effects
|
|
31
|
+
|
|
32
|
+
| Case | Owes | What to do |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| Makes a new value from what it has | Effects; One place | It returns a new value. Nothing it was given or already made changes after it is made. A stream is drained only in its source's adapter, at a recorded site. |
|
|
35
|
+
| Causes an effect (writes, logs, sends, exits) | Effects; Boundary, One place | The effect is a call on a port passed in, and its test checks that call. |
|
|
36
|
+
| Keeps state or settings across calls | Effects; Checker | Settings are passed in when the unit is built. State that changes between calls lives only in an adapter, behind a port. |
|
|
37
|
+
|
|
38
|
+
## External behaviour sits at a boundary
|
|
39
|
+
|
|
40
|
+
| Case | Owes | What to do |
|
|
41
|
+
|---|---|---|
|
|
42
|
+
| Needs the current time, a random value, a new id or an outside ordering | Boundary; One place, Tests | One unit makes the value and does nothing else. Every other unit is passed the value, not its source. The source is a port; its stub returns a written-out value. |
|
|
43
|
+
| Uses a system or service outside the program | Boundary; Leak, One place | Business logic is handed a port named for the capability, not the mechanism, speaking only our types. One implementation per capability touches it and may fill several narrow ports. The protocol is its own adapter. Each adapter is a recorded boundary. |
|
|
44
|
+
|
|
45
|
+
## No leak across a boundary
|
|
46
|
+
|
|
47
|
+
| Case | Owes | What to do |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| Reads data from outside (request, file, environment, stored row, response) | Leak; Boundary, Checker | The reader for whoever produced it parses it once, at the boundary, into a type of our own. A required value that is missing is a failure, never a default. A test never sets the environment. Past the reader, units and their tests use objects, never text. |
|
|
50
|
+
| Sends data out of the program | Leak; One place | Business logic hands the adapter our own value. Only the adapter maps it to the receiver's form. |
|
|
51
|
+
|
|
52
|
+
## The type checker proves it
|
|
53
|
+
|
|
54
|
+
| Case | Owes | What to do |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| An operation can fail | Checker; Boundary | Every way it fails is a named variant in its return type. Nothing is thrown, ends the process, becomes true or false, or is swapped for a default or an empty value. Callers handle each variant. |
|
|
57
|
+
| A value is one of several kinds or states | Checker; Language | A closed union of our own, a name per kind, no catch-all. Absence or a true-or-false that stands for a state is a named kind. |
|
|
58
|
+
| Gives a value its type (declares it, or needs it narrower) | Checker; One place, Leak | It admits exactly what the code relies on, named, never derived from an implementation. To narrow it, fix the declaration or the parse; nothing asserts over it, tests included. A doer takes only the fields it reads. |
|
|
59
|
+
| Sets how strictly the checker works | Checker | One setting, the strictest, for every unit. None weakens it. |
|
|
60
|
+
|
|
61
|
+
## Our code reads in the common language
|
|
62
|
+
|
|
63
|
+
| Case | Owes | What to do |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| Names something | Language; One place | The domain's word, the same everywhere, at every scope. Values that travel together are named fields, never a position. If only a generic word fits, split it. An outside contract's names stay in its boundary. |
|
|
66
|
+
| Explains something in prose | Language; Checker | The meaning goes in a name or a type. The only annotations are a pointer to a tracked issue and a tool directive. |
|
|
67
|
+
| Writes basic logic (branching, matching, transforming, results) | Language; Outside risk | In the language's own constructs. No outside dependency's vocabulary stands in for it. |
|
|
68
|
+
|
|
69
|
+
Meaning by name, never by position: a unit whose signature is ours takes one argument; a callback shaped by an outside API takes what that API passes.
|
|
70
|
+
|
|
71
|
+
## Outside risk is carried on purpose
|
|
72
|
+
|
|
73
|
+
| Case | Owes | What to do |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| Takes an outside dependency | Outside risk; Language, Boundary, One place | A record names the native way weighed and why it was not enough. It is used only inside the recorded boundary that needs it, with no wrapper, and its types and vocabulary never reach business logic. It never makes one of our decisions. |
|
|
76
|
+
|
|
77
|
+
Outside dependency: what was called a package. An internal package is our own code. An internal package falls under One place decides and the layering, not this case.
|
|
78
|
+
|
|
79
|
+
### Proposed cases
|
|
80
|
+
|
|
81
|
+
Proposed, not accepted.
|
|
82
|
+
|
|
83
|
+
| Case | Owes | What to do |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| Ships code for others | Outside risk | What we ship is visible to an adopter's scanner. It is the case of the proposed rule [Shipped risk declared](rules.md#shipped-risk-declared). |
|
|
86
|
+
| An adopter is not handed our risk | Outside risk | A case under [Outside dependencies justified](rules.md#outside-dependencies-justified). A peer dependency is a direct dependency of ours, so it needs a record. The risk it weighs is carried by whoever runs it, the adopter included. |
|
|
87
|
+
|
|
88
|
+
## Outside the cases
|
|
89
|
+
|
|
90
|
+
- **Sensitive data:** safety is their why; no principle forces them.
|
|
91
|
+
- **Records and debt:** see [records](records.md).
|
|
92
|
+
- **A named ban:** no record makes it correct. Existing use is still held as debt, like any symptom.
|
|
93
|
+
- **How rules and checks are written:** spirit pure, strict wording, checks imperfect by design.
|
|
94
|
+
- **Process:** root cause over a guard, no deferring, no ask-me exits, no parallel machinery.
|