@hailstails/hone 0.0.0-stage → 0.1.0-pre.3
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 +314 -0
- package/LICENSE +17 -0
- package/MIGRATING.md +238 -0
- package/README.md +219 -2
- package/THIRD-PARTY-NOTICES.md +354 -0
- package/chunks/chunk-233U4FBA.js +42 -0
- package/chunks/chunk-7ZJZZBSS.js +14909 -0
- package/chunks/chunk-HBY4ZWSP.js +79 -0
- package/chunks/chunk-HJA4CX7C.js +24 -0
- package/chunks/chunk-NZLE2WMY.js +35 -0
- package/chunks/chunk-QWA6OVLC.js +11 -0
- package/chunks/chunk-TRCB27ET.js +202 -0
- package/core/check/tool-command.js +2305 -0
- package/docs/adding-a-discipline-or-mechanism.md +195 -0
- package/docs/why-chain-contract.md +78 -0
- package/mechanisms/audit/CD-1/any-cast.js +81 -0
- package/mechanisms/audit/CD-1/piece.json +13 -0
- package/mechanisms/audit/CD-10/piece.json +13 -0
- package/mechanisms/audit/CD-10/throws-in-tests.js +49 -0
- package/mechanisms/audit/CD-14/class-syntax.js +70 -0
- package/mechanisms/audit/CD-14/piece.json +13 -0
- package/mechanisms/audit/CD-15/loops.js +40 -0
- package/mechanisms/audit/CD-15/piece.json +13 -0
- package/mechanisms/audit/CD-17/clock-sources.js +29 -0
- package/mechanisms/audit/CD-17/piece.json +13 -0
- package/mechanisms/audit/CD-19/import-boundaries.js +80 -0
- package/mechanisms/audit/CD-19/piece.json +13 -0
- package/mechanisms/audit/CD-2/cast-expressions.js +81 -0
- package/mechanisms/audit/CD-2/piece.json +13 -0
- package/mechanisms/audit/CD-23/export-test-sibling.js +56 -0
- package/mechanisms/audit/CD-23/piece.json +13 -0
- package/mechanisms/audit/CD-25/dependency-isolation.js +53 -0
- package/mechanisms/audit/CD-25/piece.json +13 -0
- package/mechanisms/audit/CD-26/module-mocking.js +51 -0
- package/mechanisms/audit/CD-26/piece.json +13 -0
- package/mechanisms/audit/CD-27/piece.json +13 -0
- package/mechanisms/audit/CD-27/test-body-logic.js +107 -0
- package/mechanisms/audit/CD-3/compiler-overrides.js +955 -0
- package/mechanisms/audit/CD-3/piece.json +49 -0
- package/mechanisms/audit/CD-43/boolean-signatures.js +55 -0
- package/mechanisms/audit/CD-43/piece.json +13 -0
- package/mechanisms/audit/CD-44/parameter-mutation.js +92 -0
- package/mechanisms/audit/CD-44/piece.json +13 -0
- package/mechanisms/audit/CD-47/hermetic-git-spawns.js +44 -0
- package/mechanisms/audit/CD-47/piece.json +13 -0
- package/mechanisms/audit/CD-5/comments-directives.js +73 -0
- package/mechanisms/audit/CD-5/piece.json +13 -0
- package/mechanisms/audit/CD-6/identifier-names.js +132 -0
- package/mechanisms/audit/CD-6/piece.json +13 -0
- package/mechanisms/audit/CD-7/categorical-paths.js +55 -0
- package/mechanisms/audit/CD-7/piece.json +13 -0
- package/mechanisms/audit/CD-7a/factory-return-types.js +42 -0
- package/mechanisms/audit/CD-7a/piece.json +13 -0
- package/mechanisms/audit/CD-8/piece.json +13 -0
- package/mechanisms/audit/CD-8/switch-defaults.js +43 -0
- package/mechanisms/audit/runner/README.md +38 -0
- package/mechanisms/audit/runner/runner.js +546 -0
- package/mechanisms/eslint/CD-1/README.md +12 -0
- package/mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js +50 -0
- package/mechanisms/eslint/CD-1/piece.json +23 -0
- package/mechanisms/eslint/CD-10/README.md +9 -0
- package/mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js +55 -0
- package/mechanisms/eslint/CD-10/piece.json +15 -0
- package/mechanisms/eslint/CD-14/README.md +11 -0
- package/mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.js +88 -0
- package/mechanisms/eslint/CD-14/piece.json +31 -0
- package/mechanisms/eslint/CD-27/README.md +12 -0
- package/mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.js +83 -0
- package/mechanisms/eslint/CD-27/piece.json +23 -0
- package/mechanisms/eslint/CD-40/README.md +7 -0
- package/mechanisms/eslint/CD-40/cd40/cd40.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-40/piece.json +21 -0
- package/mechanisms/eslint/CD-41/README.md +12 -0
- package/mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.js +228 -0
- package/mechanisms/eslint/CD-41/piece.json +23 -0
- package/mechanisms/eslint/CD-42/README.md +9 -0
- package/mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.js +75 -0
- package/mechanisms/eslint/CD-42/piece.json +15 -0
- package/mechanisms/eslint/CD-44/README.md +7 -0
- package/mechanisms/eslint/CD-44/cd44/cd44.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-44/piece.json +20 -0
- package/mechanisms/eslint/CD-6/README.md +9 -0
- package/mechanisms/eslint/CD-6/cd6/cd6.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-6/piece.json +217 -0
- package/mechanisms/eslint/CD-7/README.md +9 -0
- package/mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.js +52 -0
- package/mechanisms/eslint/CD-7/piece.json +15 -0
- package/mechanisms/eslint/runner/README.md +43 -0
- package/mechanisms/eslint/runner/runner.js +4248 -0
- package/methods/README.md +18 -0
- package/methods/lenses/clean-architecture.md +167 -0
- package/methods/lenses/decomposition.md +159 -0
- package/methods/lenses/defended-on-intent.md +178 -0
- package/methods/lenses/di-discipline.md +156 -0
- package/methods/lenses/errors-as-data.md +88 -0
- package/methods/lenses/function-first.md +193 -0
- package/methods/lenses/naming.md +127 -0
- package/methods/lenses/test-discipline.md +166 -0
- package/methods/lenses/type-soundness.md +135 -0
- package/methods/lenses/zod-boundary.md +158 -0
- package/package.json +65 -4
- package/rules/CD-1/README.md +43 -0
- package/rules/CD-1/discipline.json +185 -0
- package/rules/CD-10/README.md +55 -0
- package/rules/CD-10/discipline.json +133 -0
- package/rules/CD-11/README.md +19 -0
- package/rules/CD-11/discipline.json +12 -0
- package/rules/CD-12/README.md +19 -0
- package/rules/CD-12/discipline.json +12 -0
- package/rules/CD-13/README.md +19 -0
- package/rules/CD-13/discipline.json +12 -0
- package/rules/CD-14/README.md +54 -0
- package/rules/CD-14/discipline.json +173 -0
- package/rules/CD-15/README.md +48 -0
- package/rules/CD-15/discipline.json +73 -0
- package/rules/CD-16/README.md +17 -0
- package/rules/CD-17/README.md +42 -0
- package/rules/CD-17/discipline.json +51 -0
- package/rules/CD-18/README.md +19 -0
- package/rules/CD-18/discipline.json +12 -0
- package/rules/CD-19/README.md +45 -0
- package/rules/CD-19/discipline.json +65 -0
- package/rules/CD-2/README.md +43 -0
- package/rules/CD-2/discipline.json +65 -0
- package/rules/CD-20/README.md +17 -0
- package/rules/CD-21/README.md +19 -0
- package/rules/CD-21/discipline.json +12 -0
- package/rules/CD-22/README.md +19 -0
- package/rules/CD-22/discipline.json +12 -0
- package/rules/CD-23/README.md +41 -0
- package/rules/CD-23/discipline.json +57 -0
- package/rules/CD-24/README.md +17 -0
- package/rules/CD-25/README.md +43 -0
- package/rules/CD-25/discipline.json +57 -0
- package/rules/CD-26/README.md +42 -0
- package/rules/CD-26/discipline.json +57 -0
- package/rules/CD-27/README.md +51 -0
- package/rules/CD-27/discipline.json +233 -0
- package/rules/CD-28/README.md +19 -0
- package/rules/CD-28/discipline.json +12 -0
- package/rules/CD-29/README.md +19 -0
- package/rules/CD-29/discipline.json +12 -0
- package/rules/CD-3/README.md +48 -0
- package/rules/CD-3/discipline.json +363 -0
- package/rules/CD-30/README.md +19 -0
- package/rules/CD-30/discipline.json +12 -0
- package/rules/CD-31/README.md +19 -0
- package/rules/CD-31/discipline.json +12 -0
- package/rules/CD-32/README.md +19 -0
- package/rules/CD-32/discipline.json +12 -0
- package/rules/CD-33/README.md +19 -0
- package/rules/CD-33/discipline.json +12 -0
- package/rules/CD-34/README.md +19 -0
- package/rules/CD-34/discipline.json +12 -0
- package/rules/CD-39/README.md +19 -0
- package/rules/CD-39/discipline.json +12 -0
- package/rules/CD-4/README.md +19 -0
- package/rules/CD-4/discipline.json +12 -0
- package/rules/CD-40/README.md +45 -0
- package/rules/CD-40/discipline.json +58 -0
- package/rules/CD-41/README.md +60 -0
- package/rules/CD-41/discipline.json +124 -0
- package/rules/CD-42/README.md +53 -0
- package/rules/CD-42/discipline.json +61 -0
- package/rules/CD-43/README.md +43 -0
- package/rules/CD-43/discipline.json +65 -0
- package/rules/CD-44/README.md +54 -0
- package/rules/CD-44/discipline.json +111 -0
- package/rules/CD-45/README.md +19 -0
- package/rules/CD-45/discipline.json +12 -0
- package/rules/CD-46/README.md +13 -0
- package/rules/CD-47/README.md +47 -0
- package/rules/CD-47/discipline.json +57 -0
- package/rules/CD-5/README.md +46 -0
- package/rules/CD-5/discipline.json +65 -0
- package/rules/CD-6/README.md +57 -0
- package/rules/CD-6/discipline.json +165 -0
- package/rules/CD-7/README.md +52 -0
- package/rules/CD-7/discipline.json +142 -0
- package/rules/CD-7a/README.md +44 -0
- package/rules/CD-7a/discipline.json +57 -0
- package/rules/CD-8/README.md +48 -0
- package/rules/CD-8/discipline.json +57 -0
- package/rules/CD-9/README.md +19 -0
- package/rules/CD-9/discipline.json +12 -0
- package/rules/README.md +52 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Test-discipline lens
|
|
2
|
+
|
|
3
|
+
A reusable audit method, not a ruleset. The rules it enforces are **data**: load
|
|
4
|
+
every rule page whose `Review lens` line names `test-discipline`
|
|
5
|
+
from the codebase under review and treat their text as authoritative. This file
|
|
6
|
+
describes only *how* the lens reads code — the concept, the inspection
|
|
7
|
+
procedure, and the output shape. It names no specific rule numbers, file paths,
|
|
8
|
+
type names, or library names; those live in the loaded rules and differ per
|
|
9
|
+
codebase.
|
|
10
|
+
|
|
11
|
+
## Concept
|
|
12
|
+
|
|
13
|
+
This lens defends **structural test discipline** as a load-bearing floor — the
|
|
14
|
+
shape of the test suite, not the truth of any domain assertion. Six strands
|
|
15
|
+
recur across codebases under different names:
|
|
16
|
+
|
|
17
|
+
- **Co-location + every-file floor.** Each authored unit ships with a test next
|
|
18
|
+
to it. The floor is binary (a sibling exists or it does not) and is the real
|
|
19
|
+
coverage guarantee — distinct from, and preferred over, any numeric coverage
|
|
20
|
+
threshold.
|
|
21
|
+
- **Zero-everything tests.** A test body is a straight line: arrange → act →
|
|
22
|
+
assert. No control flow, no loops, no branches, no mutated capture, no
|
|
23
|
+
unpredictability. N cases means N tests. Uniform cases, such as the rows of a table, are one parameterised test over the rows (the framework's `each`), never a loop inside a test body, and never one hand-written test per row. Variability is supplied by injected fakes, never computed inside the test.
|
|
24
|
+
- **Assert only the unit's own responsibility.** A test inspects what its unit
|
|
25
|
+
produces and how it calls its collaborators — never the internal logic of a
|
|
26
|
+
delegate reached transitively.
|
|
27
|
+
- **Pyramid scope.** Many isolated unit tests at the base; a thin band of
|
|
28
|
+
composition tests with real backings in the middle; a smoke layer at the top.
|
|
29
|
+
Composition tests are the minimum, not the bulk, and catch *only* composition
|
|
30
|
+
bugs — a unit-localisable bug surfacing there means a unit test is missing.
|
|
31
|
+
- **The test's act.** The single line that invokes the subject-under-test must
|
|
32
|
+
invoke *our* code. A test whose act is a third-party library call, with no
|
|
33
|
+
authored code between act and assertion, tests the library, not the unit.
|
|
34
|
+
- **A test earns its place.** Each test is one complete behavioural case of the unit, with a reason to exist. A test that restates what the compiler or a dependency already guarantees tests nothing of ours: a declaration's shape pinned at type level, a constant compared with itself, a dependency's own constraint re-asserted. The one type-level assertion that earns its place guards a published external contract that a runtime comparison cannot see.
|
|
35
|
+
|
|
36
|
+
The loaded rules tell you this codebase's exact shape: the sibling-naming
|
|
37
|
+
convention, the closed list of banned test-body constructs, the matcher idioms,
|
|
38
|
+
and which backings count as "real" at the integration layer. Read them first;
|
|
39
|
+
they override any default intuition.
|
|
40
|
+
|
|
41
|
+
## Loading the ruleset
|
|
42
|
+
|
|
43
|
+
1. Resolve the rule pages: `rules/*/README.md` in the Hone install (the folder holding `core/` and `rules/`), and in each rule set the repository's `disciplines.json` names under `ruleSets`.
|
|
44
|
+
2. Keep the pages whose `Review lens` line names `test-discipline`. **If no rule pages can be read at all, STOP and return CANNOT-REVIEW naming the rule-page paths you resolved** — an unloadable ruleset is never a codebase without discipline, and reviewing zero rules would emit a PASS that means nothing.
|
|
45
|
+
3. Read each kept page in full, including its `## Exceptions` section, any in-body exception clause, and the repository's `discipline-exceptions.json` entries for that discipline: those recorded exceptions (authorised locations and carve-outs) are the closed exception list — anything outside them is a finding. If a rule names exact allowed constructs, idioms, or excluded file kinds, those are the only ones permitted.
|
|
46
|
+
4. If zero rule pages name this lens in their `Review lens` line, report that the codebase declares no test-discipline rules and produce an empty finding set — do not invent rules.
|
|
47
|
+
|
|
48
|
+
## Inspection procedure
|
|
49
|
+
|
|
50
|
+
Walk the test files and the authored files in the diff. The strands below are
|
|
51
|
+
the generic detection insight; each maps to a loaded rule, which you cite by the
|
|
52
|
+
discipline id and clause address on the rule page (for example `CD-9#result-failures`).
|
|
53
|
+
|
|
54
|
+
### Sibling floor
|
|
55
|
+
|
|
56
|
+
Enumerate the authored production files in the diff (the loaded rule defines the
|
|
57
|
+
in-scope set — typically source files, with re-export barrels, type-only
|
|
58
|
+
declaration files, and generator-marked files excluded). For each, confirm a
|
|
59
|
+
co-located test sibling exists with the *exact* naming the rule mandates. Common
|
|
60
|
+
non-compliant shapes: a different test suffix, a test parked under a
|
|
61
|
+
forbidden test directory, an extension mismatch against its unit, or one
|
|
62
|
+
directory-level test standing in for many per-file units. A missing or
|
|
63
|
+
mis-named sibling is a finding. If the codebase ships an audit that already
|
|
64
|
+
emits a co-location section, seed findings from it rather than re-deriving by
|
|
65
|
+
hand.
|
|
66
|
+
|
|
67
|
+
### Zero-everything test bodies
|
|
68
|
+
|
|
69
|
+
Scan every test-body source for the constructs the rule bans (typically `if`,
|
|
70
|
+
`try`/`catch`, ternary, short-circuit side-effect gating, `throw`, loops or
|
|
71
|
+
iteration over assertions, and reassigned-binding capture). Each match is a
|
|
72
|
+
finding citing the construct. Know the rule's *allowed* patterns so you do not
|
|
73
|
+
false-positive: an inline narrowing assertion that the rule blesses is not a
|
|
74
|
+
branch; full-envelope matchers replace try/catch around thrown errors; `const`
|
|
75
|
+
destructuring with defaults is not a branch; data fixtures living outside the
|
|
76
|
+
test-file source are out of scope. The fix for a banned construct is almost
|
|
77
|
+
always "split into N linear tests" or "use the matcher the framework already
|
|
78
|
+
provides" — name that in the finding.
|
|
79
|
+
|
|
80
|
+
### Vague-matcher-as-implicit-branch
|
|
81
|
+
|
|
82
|
+
The rule on zero-everything bans branches; a loose matcher over a *structured*
|
|
83
|
+
value is a branch in disguise ("anything truthy passes" is the shape of
|
|
84
|
+
`if (value) pass`). For every assertion on a value that has shape, ask: **what
|
|
85
|
+
would this matcher accept that the precise matcher would reject?** A truthy/
|
|
86
|
+
falsy/defined/not-null check over an envelope, object, array, or tuple accepts
|
|
87
|
+
malformed shapes the unit should never produce — that is a finding; replace with
|
|
88
|
+
a full-envelope equality or structural match against the exact expected value. A
|
|
89
|
+
bare call-occurrence assertion where the call *arguments* carry the unit's
|
|
90
|
+
correctness is the same defect on a fake — replace with an exact-argument match.
|
|
91
|
+
If the honest answer to "what would it accept that it shouldn't?" is "nothing
|
|
92
|
+
meaningful" (e.g. a boolean-returning predicate asserted with a boolean literal),
|
|
93
|
+
the matcher is not vague. The lens is not "always demand the strictest matcher";
|
|
94
|
+
it is "do not accept assertions that lose shape on values that have shape".
|
|
95
|
+
|
|
96
|
+
### Delegation leak
|
|
97
|
+
|
|
98
|
+
A test must assert the unit's own output and the *call shape* it makes on its
|
|
99
|
+
collaborators — never the internal result of a delegate. Flag assertions that
|
|
100
|
+
reach into a fake's configured return value (asserting on what arrange already
|
|
101
|
+
set), that drill into a delegate's nested return shape, that exercise a partial
|
|
102
|
+
fake which itself runs real delegate logic, or that assert a value the unit
|
|
103
|
+
merely passed through from a fake. The wanted shape is an exact-argument call
|
|
104
|
+
assertion on the fake plus an equality on the unit's *own* computed output.
|
|
105
|
+
|
|
106
|
+
### Pyramid mis-scope
|
|
107
|
+
|
|
108
|
+
Check each test sits at the right layer. **Mis-scoped down:** an integration-
|
|
109
|
+
suffixed test built entirely from fakes (a unit test wearing the wrong suffix),
|
|
110
|
+
or one that spins up a real backing the unit never touches (decorative
|
|
111
|
+
ceremony) — move it to the unit layer. **Mis-scoped up:** a unit-suffixed test
|
|
112
|
+
that wires several units together with no fakes between them and asserts on the
|
|
113
|
+
cross-unit output — that belongs at the integration layer; the unit layer should
|
|
114
|
+
fake each cross-boundary collaborator. **Missing-unit signal:** an integration
|
|
115
|
+
test failing on a bug localisable to one unit's body — the bug should have failed
|
|
116
|
+
a unit test first; the finding is the missing unit test, not the integration
|
|
117
|
+
test.
|
|
118
|
+
|
|
119
|
+
### Test-act subject
|
|
120
|
+
|
|
121
|
+
For each test, name its **act** — the call whose result the assertions inspect —
|
|
122
|
+
and identify the act's callee owner. If the callee is a third-party library
|
|
123
|
+
function (a codec call, a bare schema parse, a library constructor) and **no code
|
|
124
|
+
we authored sits between the act and the assertion**, the test exercises the
|
|
125
|
+
*library*, not the unit. It satisfies the letter of "a test exists" while testing
|
|
126
|
+
a file we do not author, and it re-asserts a guarantee the dependency's own suite
|
|
127
|
+
already owns. This is a finding. Name where the invariant belongs instead — the
|
|
128
|
+
usual answer is a **compile-time bound** upstream (a parameter type that makes the
|
|
129
|
+
property true-by-construction, which deletes the test), not another assertion. If
|
|
130
|
+
authored code *does* transform the result before the assertion, the library call
|
|
131
|
+
is mere fixture setup and the test exercises our transform — not a finding.
|
|
132
|
+
|
|
133
|
+
### Test value
|
|
134
|
+
|
|
135
|
+
For each test, state the behavioural case it proves in one line. If the case is a declaration's type, a constant's own value, or a guarantee the compiler or a dependency already enforces, the test has no value: a finding, fixed by deleting it. If several hand-written tests differ only in their inputs and expected values, they are one case written N times: a finding, fixed by one parameterised test over the rows.
|
|
136
|
+
|
|
137
|
+
For each candidate across all strands, decide finding vs non-finding strictly
|
|
138
|
+
against the loaded rules and their carve-outs — never against this file's prose
|
|
139
|
+
or a remembered version of some other codebase's rule.
|
|
140
|
+
|
|
141
|
+
## Letter-vs-intent
|
|
142
|
+
|
|
143
|
+
The lens's catch-rate lives in tests that read clean but defeat the rule's
|
|
144
|
+
intent. A test whose constructs and matchers are spotless can still test nothing
|
|
145
|
+
of ours — only naming its **act** reveals it exercises a library. A matcher that
|
|
146
|
+
is technically valid (`toBeTruthy`) can implicitly branch over a structured
|
|
147
|
+
value, accepting shapes the unit must never emit. An integration test can wear
|
|
148
|
+
the right suffix yet assert a pure-unit property with no real backing in play. A
|
|
149
|
+
finding here must explain *how the test reads correct yet the rule is defeated*,
|
|
150
|
+
grounded in the specific loaded rule — and, for an act or pyramid finding, name
|
|
151
|
+
where the invariant or the test belongs instead. Vague phrasings ("test looks
|
|
152
|
+
weak", "could be better") are the lens's own failure mode. The act-check in
|
|
153
|
+
particular is detective, not generative: state it explicitly per test, because a
|
|
154
|
+
tautological-act test can reach a merge candidate while passing every
|
|
155
|
+
construct-and-matcher check.
|
|
156
|
+
|
|
157
|
+
## Output shape
|
|
158
|
+
|
|
159
|
+
Produce the counts the review asks for (e.g. production files
|
|
160
|
+
inspected, siblings present vs missing, test files inspected, zero-logic
|
|
161
|
+
construct violations, vague-matcher assertions, delegation leaks, mis-scoped
|
|
162
|
+
tests by direction, tautological-act tests, valueless tests, uniform cases written out by hand). Every finding is
|
|
163
|
+
`file:line | quoted code | <rule-id> | defect-named`, citing the loaded rule by
|
|
164
|
+
the discipline id and clause address on the rule page (for example `CD-9#result-failures`), and — for a mis-scope, delegation, or act
|
|
165
|
+
finding — naming what fixes it (the layer to move to, the call-shape assertion
|
|
166
|
+
to use, or the upstream bound that deletes the test). State the rule-page paths you resolved and which rule ids you loaded under this lens.
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Type-soundness lens
|
|
2
|
+
|
|
3
|
+
A reusable audit method, not a ruleset. The rules it enforces are **data**: load
|
|
4
|
+
every rule page whose `Review lens` line names `type-soundness`
|
|
5
|
+
from the codebase under review and treat their text as authoritative. This file
|
|
6
|
+
describes only *how* the lens reads code — the concept, the inspection
|
|
7
|
+
procedure, and the output shape. It names no specific rule numbers, file paths,
|
|
8
|
+
type names, or library names; those live in the loaded rules and differ per
|
|
9
|
+
codebase.
|
|
10
|
+
|
|
11
|
+
## Concept
|
|
12
|
+
|
|
13
|
+
This lens defends **the integrity of the type system as a source of truth**: the
|
|
14
|
+
type the compiler sees must be the type the value actually has, and the type
|
|
15
|
+
must declare state rather than make the reader evaluate it. The unifying defect
|
|
16
|
+
is *lying to the type system* — telling the compiler something it cannot verify
|
|
17
|
+
and would otherwise reject. The lies take several forms:
|
|
18
|
+
|
|
19
|
+
- **Casts** — asserting a value is some type the compiler cannot confirm
|
|
20
|
+
(`as`-style coercions, double-coercions through the top type, bottom-type
|
|
21
|
+
assertions).
|
|
22
|
+
- **The absent type** — the escape-hatch top type that disables checking
|
|
23
|
+
(`any`-style) and propagates that absence silently through every consumer.
|
|
24
|
+
- **Non-null assertions** — asserting presence the compiler cannot see.
|
|
25
|
+
- **Strict-flag overrides** — weakening the inherited compiler-strictness
|
|
26
|
+
configuration so a whole package stops catching a class of error.
|
|
27
|
+
- **Return-type-of-own-symbol** — deriving a type via the language's
|
|
28
|
+
"type of what this function returns" operator over a symbol the codebase
|
|
29
|
+
itself authored, in place of the named export that already exists.
|
|
30
|
+
- **`default:` on a closed-union switch** — telling the compiler the
|
|
31
|
+
discriminator "could be anything", masking the exhaustiveness failure the
|
|
32
|
+
compiler would otherwise raise when a new variant lands.
|
|
33
|
+
- **Declarative booleans** — a `boolean`-typed field/parameter/return forces the
|
|
34
|
+
reader to evaluate what `true` versus `false` means here, where a string-literal
|
|
35
|
+
or discriminated union would declare the state directly at the type layer.
|
|
36
|
+
|
|
37
|
+
Across codebases the concept recurs under different names (a "no casts" rule, a
|
|
38
|
+
"no `any`" rule, "make illegal states unrepresentable", "parse, don't validate",
|
|
39
|
+
strict-compiler-config discipline). The loaded rules tell you this codebase's
|
|
40
|
+
exact shape: the closed list of permitted cast contexts and their exact sites,
|
|
41
|
+
which strict flags are inherited, the boolean carve-outs, and the
|
|
42
|
+
return-type carve-out. Read them first; they override any default intuition.
|
|
43
|
+
|
|
44
|
+
## Loading the ruleset
|
|
45
|
+
|
|
46
|
+
1. Resolve the rule pages: `rules/*/README.md` in the Hone install (the folder holding `core/` and `rules/`), and in each rule set the repository's `disciplines.json` names under `ruleSets`.
|
|
47
|
+
2. Keep the pages whose `Review lens` line names `type-soundness`. **If no rule pages can be read at all, STOP and return CANNOT-REVIEW naming the rule-page paths you resolved** — an unloadable ruleset is never a codebase without discipline, and reviewing zero rules would emit a PASS that means nothing.
|
|
48
|
+
3. Read each kept page in full, including its `## Exceptions` section and the repository's `discipline-exceptions.json` entries for that discipline: those recorded exceptions (authorised locations and carve-outs) are the closed exception list — anything outside them is a finding. Where a rule names exact permitted sites (file paths, cast shapes, predicate forms, flag names), those are the only permitted sites, and a site matching the *kind* but not the exact named location is still a finding.
|
|
49
|
+
4. If zero rule pages name this lens in their `Review lens` line, report that the codebase declares no type-soundness discipline and produce an empty finding set — do not invent rules.
|
|
50
|
+
|
|
51
|
+
## Inspection procedure
|
|
52
|
+
|
|
53
|
+
Walk every changed type-bearing source file, plus every compiler-config file in
|
|
54
|
+
the diff. For each construct the lens asks: does this assert to the compiler
|
|
55
|
+
something it cannot verify, or does it make the type stop declaring state?
|
|
56
|
+
|
|
57
|
+
- **Cast sites.** For every coercion (`as <T>`, double-coercion through the top
|
|
58
|
+
type, bottom-type assertion, non-null assertion), check the file path and the
|
|
59
|
+
cast *shape* against the closed list the rules declare. A cast is permitted
|
|
60
|
+
only when BOTH the site (exact file) and the form match a listed context;
|
|
61
|
+
either mismatch is a finding. "We're at a boundary" is not a justification —
|
|
62
|
+
only the named boundaries qualify. Watch specifically for the
|
|
63
|
+
collapse-keys-to-`string` standard-library constructor whose output a cast
|
|
64
|
+
then re-narrows: the rules typically forbid it because the cast is either a
|
|
65
|
+
soundness assertion or a width-narrow admitting drift.
|
|
66
|
+
- **The absent type.** Every occurrence of the escape-hatch top type in authored
|
|
67
|
+
source is a candidate — bare, in generic positions (`Array<…>`,
|
|
68
|
+
`Record<string, …>`, `Promise<…>`, `Map<…>`), and the implicit-widening form a
|
|
69
|
+
`let` with no annotation acquires. A match inside a string literal or comment
|
|
70
|
+
is not a finding. The rules typically grant this zero carve-outs; an inline
|
|
71
|
+
suppression annotation records the escape but does not cure the underlying
|
|
72
|
+
finding.
|
|
73
|
+
- **Strict-flag config.** For every per-package compiler-config file in the diff,
|
|
74
|
+
check whether it sets any inherited strict flag to off, or omits/overrides one
|
|
75
|
+
the base sets on, or weakens it transitively (a sub-flag turned off while the
|
|
76
|
+
umbrella flag is inherited on). Either is a finding. The remediation is "remove
|
|
77
|
+
the override and fix the type errors it was masking" — those masked errors are
|
|
78
|
+
the load-bearing finding; the config line is only the surface.
|
|
79
|
+
- **Return-type-of-own-symbol.** For every "type of what this returns" operator
|
|
80
|
+
over a `typeof`-referenced symbol, determine whether the symbol is authored in
|
|
81
|
+
this codebase. If yes → finding (the named export already exists; use it). If
|
|
82
|
+
the symbol is external AND the library exports the named return type → finding
|
|
83
|
+
(use the named type). Only an external symbol whose library exports no named
|
|
84
|
+
return type is the carve-out, and the report must cite the library and confirm
|
|
85
|
+
the absence; unresolved uncertainty about origin is itself the finding.
|
|
86
|
+
- **`default:` on a closed-union switch.** For every switch, find the
|
|
87
|
+
discriminator's static type. If it is a closed union (string-literal union,
|
|
88
|
+
`{ kind: … }` discriminated union, or finite enum) AND the body carries a
|
|
89
|
+
`default:` arm → finding. The function-first replacement is an
|
|
90
|
+
exhaustiveness checkpoint at the fall-through position (a bottom-type
|
|
91
|
+
assignment) so a future unmatched variant fails the build. A `default:` is
|
|
92
|
+
legitimate only when the discriminator's source is genuinely *open* (a parsed
|
|
93
|
+
external string, an untyped storage row) — in which case the open shape, not a
|
|
94
|
+
closed-union `default:`, is the correct model.
|
|
95
|
+
- **Declarative booleans.** For every `boolean`-typed annotation — parameters at
|
|
96
|
+
any depth (bare, destructured, nested in a parameter-object type), type/interface
|
|
97
|
+
fields, return types, explicit variable-type annotations — check it against the
|
|
98
|
+
closed boolean carve-out list (typically: a type-predicate/asserts return form;
|
|
99
|
+
a single bridge line reading/writing an external library's mandated boolean with
|
|
100
|
+
every surrounding type using a union; a local `const` consumed inline and never
|
|
101
|
+
escaping). Anything else is a finding; remediation is always a string-literal or
|
|
102
|
+
discriminated union. Note especially the *discriminator consequence*: a
|
|
103
|
+
result/outcome shape that discriminates on a boolean field rather than a string
|
|
104
|
+
field, and *port-output* booleans that re-contaminate every downstream consumer.
|
|
105
|
+
|
|
106
|
+
For each candidate, decide finding vs non-finding strictly against the loaded
|
|
107
|
+
rules and their carve-outs — never against this file's prose or a remembered
|
|
108
|
+
version of some other codebase's rule.
|
|
109
|
+
|
|
110
|
+
## Letter-vs-intent
|
|
111
|
+
|
|
112
|
+
The lens's catch-rate lives where the code type-checks cleanly yet the type is
|
|
113
|
+
defeated: a cast that compiles because it asserts away the very mismatch that
|
|
114
|
+
matters; a `default:` arm that keeps a switch compiling while hiding the
|
|
115
|
+
exhaustiveness check that would have flagged a new variant; a `boolean` field
|
|
116
|
+
that is syntactically fine but forces every reader to evaluate its meaning; a
|
|
117
|
+
strict-flag override that makes a whole package compile by *not* checking. A
|
|
118
|
+
suppression annotation pointing at a tracker records the escape but never cures
|
|
119
|
+
the finding — the underlying violation stays load-bearing, and the tracker must
|
|
120
|
+
point at the spec that *retires* the escape, not one that *excuses* it. A finding
|
|
121
|
+
here must explain *how the code reads correct yet the type is defeated*, grounded
|
|
122
|
+
in the specific loaded rule. Vague phrasings ("looks unsafe", "casting is bad")
|
|
123
|
+
are the lens's own failure mode.
|
|
124
|
+
|
|
125
|
+
## Output shape
|
|
126
|
+
|
|
127
|
+
Produce the counts the review asks for (e.g. cast sites by
|
|
128
|
+
permitted/violation, absent-top-type occurrences, strict-flag overrides,
|
|
129
|
+
return-type-of-own-symbol sites, closed-union `default:` arms, declarative-boolean
|
|
130
|
+
sites by carve-out invoked). Record the compiler version / config you read where
|
|
131
|
+
the rules call for it. Every finding is
|
|
132
|
+
`file:line | quoted code | <rule-id> | defect-named`, citing the loaded rule by
|
|
133
|
+
the discipline id and clause address on the rule page (for example `CD-9#result-failures`); where a carve-out was invoked, state which one
|
|
134
|
+
and why it does not apply. State the rule-page paths you resolved and which
|
|
135
|
+
rule ids you loaded under this lens.
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Zod-boundary lens
|
|
2
|
+
|
|
3
|
+
A reusable audit method, not a ruleset. The rules it enforces are **data**: load
|
|
4
|
+
every rule page whose `Review lens` line names `zod-boundary`
|
|
5
|
+
from the codebase under review and treat their text as authoritative. This file
|
|
6
|
+
describes only *how* the lens reads code — the concept, the inspection
|
|
7
|
+
procedure, and the output shape. It names no specific rule numbers, file paths,
|
|
8
|
+
type names, or library names; those live in the loaded rules and differ per
|
|
9
|
+
codebase.
|
|
10
|
+
|
|
11
|
+
## Concept
|
|
12
|
+
|
|
13
|
+
This lens defends **boundary validation discipline**: external, typeless input
|
|
14
|
+
is validated exactly once, at the seam where it enters the system, then mapped
|
|
15
|
+
to a plain internal shape that the rest of the code trusts by construction. The
|
|
16
|
+
validation library lives only at that seam — never leaking inward into the
|
|
17
|
+
application or domain layers. Two halves, one rule:
|
|
18
|
+
|
|
19
|
+
- **At the boundary, validate** — every crossing where input arrives from
|
|
20
|
+
outside the system's type guarantees (a transport payload, an
|
|
21
|
+
external-system adapter input, a config/env read, a file/DB driver row, a
|
|
22
|
+
typeless library return) must run its input through a schema parse before any
|
|
23
|
+
internal code touches it. "Trust the caller" for external input is the
|
|
24
|
+
failure.
|
|
25
|
+
- **Inside the boundary, don't** — once parsed, the shape is plain, statically
|
|
26
|
+
typed, and trusted. Re-validating it internally is redundant cost and a
|
|
27
|
+
category error: it reads the boundary as "anywhere untrusted data might be"
|
|
28
|
+
rather than "the single seam where external typeless input enters". A schema
|
|
29
|
+
import inside an inner layer is the symptom.
|
|
30
|
+
|
|
31
|
+
Across codebases the concept recurs under different names (a Zod/io-ts/valibot
|
|
32
|
+
parse-at-the-edge, a "parse, don't validate" DTO mapping, a schema-at-the-port
|
|
33
|
+
rule). The loaded rules tell you this codebase's exact shape: which validation
|
|
34
|
+
library, the closed list of boundary-only sites, and which inner layers forbid
|
|
35
|
+
the library. Read them first; they override any default intuition.
|
|
36
|
+
|
|
37
|
+
## Loading the ruleset
|
|
38
|
+
|
|
39
|
+
1. Resolve the rule pages: `rules/*/README.md` in the Hone install (the folder holding `core/` and `rules/`), and in each rule set the repository's `disciplines.json` names under `ruleSets`.
|
|
40
|
+
2. Keep the pages whose `Review lens` line names `zod-boundary`. **If no rule pages can be read at all, STOP and return CANNOT-REVIEW naming the rule-page paths you resolved** — an unloadable ruleset is never a codebase without discipline, and reviewing zero rules would emit a PASS that means nothing.
|
|
41
|
+
3. Read each kept page in full, including its `## Exceptions` section and the repository's `discipline-exceptions.json` entries for that discipline: those recorded exceptions (authorised locations and carve-outs) are the closed exception list — anything outside them is a finding. If a rule names the exact closed list of boundary-only sites, those are the only places the validation library may run; if it names the inner layers where the library is forbidden, those are the only places a schema import is an automatic finding.
|
|
42
|
+
4. If zero rule pages name this lens in their `Review lens` line, report that the codebase declares no boundary-validation discipline and produce an empty finding set — do not invent rules.
|
|
43
|
+
|
|
44
|
+
## Inspection procedure
|
|
45
|
+
|
|
46
|
+
Two passes: walk the boundaries (is validation present?), then walk the inner
|
|
47
|
+
layers (is the library absent?).
|
|
48
|
+
|
|
49
|
+
### Boundary inventory walk
|
|
50
|
+
|
|
51
|
+
First enumerate the boundaries in the diff. A boundary is **the seam where
|
|
52
|
+
typeless external input enters the system**. The loaded rules name the closed
|
|
53
|
+
list; the recurring categories are:
|
|
54
|
+
|
|
55
|
+
- **Transport handlers** — the body of any handler whose input is wire-shaped
|
|
56
|
+
(JSON over HTTP, an RPC/tool payload, an IPC message). The parse sits at the
|
|
57
|
+
handler body's entry, before any orchestration.
|
|
58
|
+
- **Adapter inputs from external systems** — anywhere an adapter receives a
|
|
59
|
+
payload from a system the codebase does not control (third-party APIs,
|
|
60
|
+
webhooks, subprocess stdout interpreted as data, message-bus reads).
|
|
61
|
+
- **Config / env readers** — the single factory that owns the config schema.
|
|
62
|
+
Config is a *capability*; the environment is merely the substrate it reads
|
|
63
|
+
from. An inline environment read outside that factory bypasses the seam and is
|
|
64
|
+
a finding.
|
|
65
|
+
- **File / DB driver row contracts** — driver row returns are typeless; the
|
|
66
|
+
driver wrapping factory must parse each row through a schema before handing
|
|
67
|
+
typed rows upward. File reads (frontmatter parses, JSON files, raw text
|
|
68
|
+
interpreted as data) are the same shape.
|
|
69
|
+
- **Library wrapping factories that bridge typeless returns** — any library
|
|
70
|
+
whose published types are the language's top/opaque type, a wide
|
|
71
|
+
string-keyed record, or an over-wide supplied type the code must narrow. The
|
|
72
|
+
wrapping file is both the closed import site for that library *and* the
|
|
73
|
+
validation gate.
|
|
74
|
+
|
|
75
|
+
What is **not** a boundary: inter-module calls inside the same app;
|
|
76
|
+
helper-to-helper composition inside an orchestrator; test fixtures; and any data
|
|
77
|
+
already parsed at a boundary and propagated inward through fully static types.
|
|
78
|
+
|
|
79
|
+
For each boundary in the diff, ask the two questions:
|
|
80
|
+
|
|
81
|
+
1. **Is the typeless input parsed by a schema before any internal code uses
|
|
82
|
+
it?** Trace from the point input arrives to the first internal consumer. A
|
|
83
|
+
schema parse must sit on that path.
|
|
84
|
+
2. **Does the parse produce the plain internal shape that flows inward** — not a
|
|
85
|
+
re-export of the raw library type?
|
|
86
|
+
|
|
87
|
+
### The cast equivalence (cross-reference, do not own)
|
|
88
|
+
|
|
89
|
+
The **missing-schema-at-a-boundary** case usually surfaces as a different
|
|
90
|
+
lens's finding, and recognising the equivalence is this lens's sharpest
|
|
91
|
+
heuristic. When typeless input crosses a boundary without a schema, it has no
|
|
92
|
+
typed surface, so the code must **cast** to type it — an `as`, an
|
|
93
|
+
`as unknown as`, or an inline type annotation on a destructure (a cast in
|
|
94
|
+
disguise). That cast is owned by the type-soundness lens, not this one. But the
|
|
95
|
+
cast *is* the missing schema: a reviewer reading the boundary rule in isolation
|
|
96
|
+
hunts "is there a schema somewhere"; a reviewer reading the cast rule in
|
|
97
|
+
isolation hunts "is there a cast that shouldn't be"; each misses half. Read both
|
|
98
|
+
at once. When you see a cast in a boundary file, name it as the **observable
|
|
99
|
+
symptom** of the missing schema (cite this lens's boundary rule for the missing
|
|
100
|
+
schema; note the cast is the type-soundness lens's finding — do not re-tag or
|
|
101
|
+
claim the cast rule yourself). The four recurring symptom shapes:
|
|
102
|
+
|
|
103
|
+
- **Bare parse-then-assert** — a raw deserialization (`JSON.parse` and kin)
|
|
104
|
+
whose result is assigned a type by annotation or `as` instead of handed to a
|
|
105
|
+
schema's parse.
|
|
106
|
+
- **Face-value library return** — a library return typed `unknown`/`any`/wide
|
|
107
|
+
record consumed via a hand-written inline annotation on the elements instead
|
|
108
|
+
of a per-row/per-item schema parse.
|
|
109
|
+
- **Environment read outside the config factory** — any direct environment
|
|
110
|
+
access outside the file that owns the config schema.
|
|
111
|
+
- **Cast as schema substitute** — a transport/adapter/wrapping-factory input
|
|
112
|
+
cast directly to its expected shape. The cast asserts the shape; the
|
|
113
|
+
boundary's job is to *verify* it.
|
|
114
|
+
|
|
115
|
+
### Internal-import walk
|
|
116
|
+
|
|
117
|
+
Then walk the inner layers the rules name as schema-forbidden (the application
|
|
118
|
+
and domain layers, by whatever path segments the codebase uses — match the layer
|
|
119
|
+
*name* anywhere in the path, since folder depth varies across apps). A
|
|
120
|
+
validation-library import inside those layers is a finding: it means data is
|
|
121
|
+
being re-validated after the boundary already guaranteed its shape, or the
|
|
122
|
+
boundary was drawn in the wrong place. This pass needs a real import search — the
|
|
123
|
+
cast equivalence does not surface it, because re-validating already-typed data
|
|
124
|
+
needs no cast.
|
|
125
|
+
|
|
126
|
+
### Seam ambiguity
|
|
127
|
+
|
|
128
|
+
If you cannot tell whether a crossing is a boundary (e.g. an adapter that both
|
|
129
|
+
receives external payloads and is called internally, or a module whose layer is
|
|
130
|
+
unclear), that ambiguity is itself a finding: name the **upstream architectural
|
|
131
|
+
cause** (the seam is mis-drawn, the layer is unlabelled, an adapter conflates
|
|
132
|
+
external and internal entry) rather than guessing present/absent.
|
|
133
|
+
|
|
134
|
+
## Letter-vs-intent
|
|
135
|
+
|
|
136
|
+
The lens's catch-rate lives where the type reads correct but the rule is
|
|
137
|
+
defeated: a handler that "has types" because every field was hand-asserted past
|
|
138
|
+
a missing schema; a domain module that ships its schema alongside its type so
|
|
139
|
+
the validation library has quietly leaked inward; an environment read tucked
|
|
140
|
+
into a module that is not the config factory. A finding here must explain *how
|
|
141
|
+
the code reads typed yet the boundary rule is defeated*, grounded in the specific
|
|
142
|
+
loaded rule — "name the boundary, write the schema, parse at the seam, map to
|
|
143
|
+
plain internal shape, propagate inward" is the remedy; "just type it" is the
|
|
144
|
+
smell. Vague phrasings ("validation looks weak", "should probably parse this")
|
|
145
|
+
are the lens's own failure mode.
|
|
146
|
+
|
|
147
|
+
## Output shape
|
|
148
|
+
|
|
149
|
+
Produce the counts the review asks for. The boundary inventory walk
|
|
150
|
+
is mandatory and so are the counts it yields: crossings inspected / validated /
|
|
151
|
+
typeless; library returns inspected / validated / accepted-at-face-value;
|
|
152
|
+
internal validation-library imports; seam ambiguities. Every finding is
|
|
153
|
+
`file:line | quoted code | <rule-id> | defect-named`, citing the loaded rule by
|
|
154
|
+
the discipline id and clause address on the rule page (for example `CD-9#result-failures`). For any missing-schema finding whose observable
|
|
155
|
+
symptom is a cast, name the cast as the symptom and the missing schema as the
|
|
156
|
+
defect (the cast itself belongs to the type-soundness lens). For any seam
|
|
157
|
+
ambiguity, name the upstream architectural cause. State the code-discipline path
|
|
158
|
+
you resolved and which rule ids you loaded under this lens.
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hailstails/hone",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-pre.3",
|
|
4
|
+
"description": "Checks a repository against the disciplines it selects, applies its recorded exceptions and prints one verdict.",
|
|
5
|
+
"license": "MIT-0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/HailsTails/hone.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/HailsTails/hone#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/HailsTails/hone/issues"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"bin": {
|
|
19
|
+
"hone": "core/check/tool-command.js"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
"./package.json": "./package.json",
|
|
23
|
+
"./mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js": "./mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js",
|
|
24
|
+
"./mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js": "./mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js",
|
|
25
|
+
"./mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.js": "./mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.js",
|
|
26
|
+
"./mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.js": "./mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.js",
|
|
27
|
+
"./mechanisms/eslint/CD-40/cd40/cd40.eslint-plugin.js": "./mechanisms/eslint/CD-40/cd40/cd40.eslint-plugin.js",
|
|
28
|
+
"./mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.js": "./mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.js",
|
|
29
|
+
"./mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.js": "./mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.js",
|
|
30
|
+
"./mechanisms/eslint/CD-44/cd44/cd44.eslint-plugin.js": "./mechanisms/eslint/CD-44/cd44/cd44.eslint-plugin.js",
|
|
31
|
+
"./mechanisms/eslint/CD-6/cd6/cd6.eslint-plugin.js": "./mechanisms/eslint/CD-6/cd6/cd6.eslint-plugin.js",
|
|
32
|
+
"./mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.js": "./mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.js"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"ADOPTING.md",
|
|
36
|
+
"LICENSE",
|
|
37
|
+
"MIGRATING.md",
|
|
38
|
+
"README.md",
|
|
39
|
+
"THIRD-PARTY-NOTICES.md",
|
|
40
|
+
"chunks",
|
|
41
|
+
"core",
|
|
42
|
+
"docs",
|
|
43
|
+
"mechanisms",
|
|
44
|
+
"methods",
|
|
45
|
+
"rules"
|
|
46
|
+
],
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": "^22.13.0 || >=24"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^8.56.0",
|
|
52
|
+
"@typescript-eslint/parser": "^8.56.0",
|
|
53
|
+
"eslint": "^9.12.0 || ^10.0.0",
|
|
54
|
+
"typescript": ">=4.8.4 <7.0.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"@typescript-eslint/eslint-plugin": {
|
|
58
|
+
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"@typescript-eslint/parser": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"eslint": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# CD-1: No any, ever
|
|
2
|
+
|
|
3
|
+
## Rule
|
|
4
|
+
|
|
5
|
+
`any` is the absence of a type: it tells the compiler to stop checking, and that hole propagates silently through every call site that consumes the value. The whole reason a type system exists — catching shape errors before runtime — is forfeited at each `any`. Reach for `unknown` and narrow at the read site, or a precise union. There are no carve-outs: every `any` is a violation regardless of stated reason.
|
|
6
|
+
|
|
7
|
+
The sections below describe what the audit and ESLint checks cover.
|
|
8
|
+
|
|
9
|
+
## Clauses
|
|
10
|
+
|
|
11
|
+
| Clause | Mechanism | Checks |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| `CD-1#any-cast` | audit | a type assertion whose text contains `any` |
|
|
14
|
+
| `CD-1#explicit-any` | eslint | an `any` type anywhere in a type position |
|
|
15
|
+
| `CD-1#implicit-any-let` | eslint | a `let` or `var` with neither a type annotation nor an initialiser |
|
|
16
|
+
|
|
17
|
+
Review lens: [type-soundness](../../methods/lenses/type-soundness.md). The lens reviews the whole rule, including what no check flags.
|
|
18
|
+
|
|
19
|
+
## What the check flags
|
|
20
|
+
- `.ts` and `.tsx` files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
21
|
+
- A type assertion (`x as T` or `<T>x`) where the first 80 characters from the start of the assertion match `as any`, `: any` or `<any>`.
|
|
22
|
+
- Allowed: `as unknown`. Other casts are reported by CD-2 instead.
|
|
23
|
+
- A multi-argument generic such as `Map<string, any>` does not match and falls to CD-2. A bare annotation such as `let value: any` is not flagged; that part is left to review.
|
|
24
|
+
|
|
25
|
+
## What the ESLint check flags
|
|
26
|
+
Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-1/README.md).
|
|
27
|
+
- `hone-cd1/no-explicit-any` is typescript-eslint's `no-explicit-any` with default options. It flags every `any` type: annotations, type arguments such as `Map<string, any>`, and `as any`.
|
|
28
|
+
- `hone-cd1/implicit-any-let` flags a `let` or `var` declaration in a `.ts` or `.tsx` file that has neither a type annotation nor an initialiser, one report per declaration at its first such binding. Declaration files (`.d.ts`), `const`, and `for-in` and `for-of` heads are not flagged.
|
|
29
|
+
- Allowed: `unknown`, `let total = 0` and `let total: number`.
|
|
30
|
+
|
|
31
|
+
## Example violation
|
|
32
|
+
```ts
|
|
33
|
+
const parsed = JSON.parse(text) as any;
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## How to fix
|
|
37
|
+
```ts
|
|
38
|
+
const parsed: unknown = JSON.parse(text);
|
|
39
|
+
```
|
|
40
|
+
Narrow `unknown` with a schema or a type guard at the point of use.
|
|
41
|
+
|
|
42
|
+
## Exceptions
|
|
43
|
+
CD-1 is exempted like any other discipline: record an `authorised-location`, a `file-carve-out` for existing debt, or a clause-wide carve-out in `discipline-exceptions.json`. A carved or authorised file keeps its existing `any`; an `any` anywhere else still fails. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
|