@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.
Files changed (150) hide show
  1. package/ADOPTING.md +172 -38
  2. package/MIGRATING.md +58 -7
  3. package/README.md +117 -35
  4. package/THIRD-PARTY-NOTICES.md +1 -1
  5. package/api/audit.d.ts +3 -2
  6. package/api/rule-set.d.ts +2 -4
  7. package/chunks/chunk-3HFJHJDO.js +53 -0
  8. package/chunks/chunk-5LCLBXP7.js +76 -0
  9. package/chunks/{chunk-BX6QHLSZ.js → chunk-ET5EBSJX.js} +61 -6
  10. package/chunks/chunk-LDQUT742.js +15 -0
  11. package/chunks/{chunk-RZA3OVOO.js → chunk-LOYT2AGY.js} +10 -9
  12. package/chunks/chunk-MVK5KFJI.js +421 -0
  13. package/chunks/{chunk-FOAGAYXM.js → chunk-NCDYOPHG.js} +7224 -2361
  14. package/chunks/chunk-WPRR2MPJ.js +22 -0
  15. package/chunks/{chunk-EYCRDEXX.js → chunk-XB4PCY3Q.js} +2 -13
  16. package/core/check/tool-command.js +1130 -230
  17. package/core/mechanism-port/piece-failure-types.d.ts +14 -0
  18. package/core/mechanism-port/runner-module-types.d.ts +5 -0
  19. package/core/rule-set-reader/authored-rule-set-types.d.ts +48 -0
  20. package/core/values/json-value.d.ts +3 -0
  21. package/docs/adding-a-discipline-or-mechanism.md +29 -13
  22. package/docs/extending.md +358 -0
  23. package/docs/output-contract.md +326 -0
  24. package/mechanisms/audit/CD-1/any-cast.js +9 -37
  25. package/mechanisms/audit/CD-19/import-boundaries.js +79 -68
  26. package/mechanisms/audit/CD-19/piece.json +5 -0
  27. package/mechanisms/audit/CD-2/cast-expressions.js +14 -37
  28. package/mechanisms/audit/CD-2/piece.json +6 -1
  29. package/mechanisms/audit/CD-5/comments-directives.js +121 -55
  30. package/mechanisms/audit/CD-5/piece.json +7 -0
  31. package/mechanisms/audit/runner/README.md +4 -2
  32. package/mechanisms/audit/runner/runner.js +102 -36
  33. package/mechanisms/audit/runner/typescript-parse.d.ts +6 -0
  34. package/mechanisms/audit/runner/walker-piece.d.ts +5 -5
  35. package/mechanisms/eslint/CD-2/README.md +12 -0
  36. package/mechanisms/eslint/CD-2/cd2/cd2.eslint-plugin.js +16 -0
  37. package/mechanisms/eslint/CD-2/piece.json +25 -0
  38. package/mechanisms/eslint/runner/README.md +12 -5
  39. package/mechanisms/eslint/runner/runner.js +940 -232
  40. package/methods/README.md +2 -0
  41. package/methods/assessment-template.md +35 -0
  42. package/methods/lenses/clean-architecture.md +2 -2
  43. package/methods/lenses/decomposition.md +2 -2
  44. package/methods/lenses/defended-on-intent.md +7 -7
  45. package/methods/lenses/di-discipline.md +38 -26
  46. package/methods/lenses/errors-as-data.md +2 -2
  47. package/methods/lenses/function-first.md +2 -2
  48. package/methods/lenses/naming.md +2 -2
  49. package/methods/lenses/test-discipline.md +15 -13
  50. package/methods/lenses/type-soundness.md +2 -2
  51. package/methods/lenses/zod-boundary.md +2 -2
  52. package/package.json +5 -4
  53. package/rules/CD-1/CHECKS.md +37 -0
  54. package/rules/CD-1/README.md +17 -32
  55. package/rules/CD-1/discipline.json +16 -6
  56. package/rules/CD-10/CHECKS.md +49 -0
  57. package/rules/CD-10/README.md +21 -49
  58. package/rules/CD-11/CHECKS.md +13 -0
  59. package/rules/CD-11/README.md +14 -8
  60. package/rules/CD-12/CHECKS.md +13 -0
  61. package/rules/CD-12/README.md +14 -8
  62. package/rules/CD-13/CHECKS.md +13 -0
  63. package/rules/CD-13/README.md +14 -8
  64. package/rules/CD-14/CHECKS.md +49 -0
  65. package/rules/CD-14/README.md +22 -48
  66. package/rules/CD-15/CHECKS.md +40 -0
  67. package/rules/CD-15/README.md +22 -40
  68. package/rules/CD-16/CHECKS.md +7 -0
  69. package/rules/CD-16/README.md +3 -5
  70. package/rules/CD-17/CHECKS.md +37 -0
  71. package/rules/CD-17/README.md +17 -31
  72. package/rules/CD-18/CHECKS.md +13 -0
  73. package/rules/CD-18/README.md +15 -9
  74. package/rules/CD-19/CHECKS.md +49 -0
  75. package/rules/CD-19/README.md +18 -34
  76. package/rules/CD-19/discipline.json +6 -8
  77. package/rules/CD-2/CHECKS.md +56 -0
  78. package/rules/CD-2/README.md +19 -32
  79. package/rules/CD-2/discipline.json +93 -7
  80. package/rules/CD-20/CHECKS.md +7 -0
  81. package/rules/CD-20/README.md +3 -5
  82. package/rules/CD-21/CHECKS.md +13 -0
  83. package/rules/CD-21/README.md +14 -9
  84. package/rules/CD-22/CHECKS.md +13 -0
  85. package/rules/CD-22/README.md +13 -8
  86. package/rules/CD-23/CHECKS.md +35 -0
  87. package/rules/CD-23/README.md +14 -29
  88. package/rules/CD-24/CHECKS.md +7 -0
  89. package/rules/CD-24/README.md +3 -5
  90. package/rules/CD-25/CHECKS.md +38 -0
  91. package/rules/CD-25/README.md +20 -32
  92. package/rules/CD-26/CHECKS.md +36 -0
  93. package/rules/CD-26/README.md +18 -31
  94. package/rules/CD-27/CHECKS.md +45 -0
  95. package/rules/CD-27/README.md +18 -40
  96. package/rules/CD-28/CHECKS.md +13 -0
  97. package/rules/CD-28/README.md +14 -8
  98. package/rules/CD-29/CHECKS.md +13 -0
  99. package/rules/CD-29/README.md +12 -8
  100. package/rules/CD-3/CHECKS.md +42 -0
  101. package/rules/CD-3/README.md +20 -42
  102. package/rules/CD-30/CHECKS.md +13 -0
  103. package/rules/CD-30/README.md +13 -8
  104. package/rules/CD-31/CHECKS.md +13 -0
  105. package/rules/CD-31/README.md +12 -8
  106. package/rules/CD-32/CHECKS.md +13 -0
  107. package/rules/CD-32/README.md +13 -8
  108. package/rules/CD-33/CHECKS.md +13 -0
  109. package/rules/CD-33/README.md +13 -8
  110. package/rules/CD-34/CHECKS.md +13 -0
  111. package/rules/CD-34/README.md +12 -8
  112. package/rules/CD-39/CHECKS.md +13 -0
  113. package/rules/CD-39/README.md +13 -8
  114. package/rules/CD-4/CHECKS.md +13 -0
  115. package/rules/CD-4/README.md +15 -8
  116. package/rules/CD-40/CHECKS.md +39 -0
  117. package/rules/CD-40/README.md +17 -33
  118. package/rules/CD-41/CHECKS.md +54 -0
  119. package/rules/CD-41/README.md +23 -54
  120. package/rules/CD-42/CHECKS.md +47 -0
  121. package/rules/CD-42/README.md +19 -47
  122. package/rules/CD-43/CHECKS.md +37 -0
  123. package/rules/CD-43/README.md +15 -31
  124. package/rules/CD-44/CHECKS.md +48 -0
  125. package/rules/CD-44/README.md +20 -48
  126. package/rules/CD-45/CHECKS.md +13 -0
  127. package/rules/CD-45/README.md +14 -8
  128. package/rules/CD-46/CHECKS.md +7 -0
  129. package/rules/CD-46/README.md +16 -4
  130. package/rules/CD-47/CHECKS.md +37 -0
  131. package/rules/CD-47/README.md +16 -32
  132. package/rules/CD-5/CHECKS.md +52 -0
  133. package/rules/CD-5/README.md +22 -40
  134. package/rules/CD-5/discipline.json +66 -0
  135. package/rules/CD-6/CHECKS.md +51 -0
  136. package/rules/CD-6/README.md +22 -51
  137. package/rules/CD-7/CHECKS.md +46 -0
  138. package/rules/CD-7/README.md +23 -46
  139. package/rules/CD-7a/CHECKS.md +38 -0
  140. package/rules/CD-7a/README.md +14 -32
  141. package/rules/CD-8/CHECKS.md +42 -0
  142. package/rules/CD-8/README.md +20 -42
  143. package/rules/CD-9/CHECKS.md +13 -0
  144. package/rules/CD-9/README.md +15 -8
  145. package/rules/README.md +5 -3
  146. package/rules/SPIRIT.md +50 -0
  147. package/core/mechanism-port/runner-failure-types.d.ts +0 -38
  148. package/core/rule-set-reader/rule-set-types.d.ts +0 -41
  149. /package/api/{audit.js → audit.mjs} +0 -0
  150. /package/api/{rule-set.js → rule-set.mjs} +0 -0
@@ -4,44 +4,28 @@
4
4
 
5
5
  A test may not touch its environment or cause any real side effect on anything real. "Anything real" is everything the test did not itself create and does not itself dispose: the developer's repository, their user configuration and home directory, any network or live service, shared filesystem paths, the system clock, and the ambient process environment.
6
6
 
7
- A test fakes the real subsystem. Spawning it is permitted in exactly one closed case: the subsystem's own observable behaviour is the assertion's subject and no fake can stand in for it. Setup, realism and convenience never qualify; state which assertion cannot be written against a fake, and if that sentence cannot be written, the test does not qualify. A qualifying test brings its own instance in a location it created and removes it afterwards; it never borrows the machine's.
7
+ A test replaces the real subsystem with a test double. Spawning it is permitted in exactly one closed case: the subsystem's own observable behaviour is the assertion's subject and no test double can stand in for it. Setup, realism and convenience never qualify; state which assertion cannot be written against a test double, and if that sentence cannot be written, the test does not qualify. A qualifying test brings its own instance in a location it created and removes it afterwards; it never borrows the machine's.
8
8
 
9
9
  Real git is the mechanically checked class: a test that spawns a real `git` subprocess passes an explicit hermetic environment at that call site, and never inherits the ambient one.
10
10
 
11
- The sections below describe what the audit check covers.
11
+ Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags. What each check flags, how to fix a flagged site, and how to record an exception: [CHECKS.md](CHECKS.md). The thinking behind every rule: [the spirit of the rules](../SPIRIT.md).
12
12
 
13
- ## Clauses
13
+ ## Spirit
14
14
 
15
- | Clause | Mechanism | Checks |
16
- | --- | --- | --- |
17
- | `CD-47#hermetic-git-spawns` | audit | a git spawn in a test without a hermetic `env` |
15
+ **What the friction is for.** A test that touches real things can damage them, and can pass or fail depending on the machine. The friction makes replacing the subsystem with a test double the easy path, so tests are safe to run anywhere and give the same answer every time.
18
16
 
19
- Review lens: [test-discipline](../../methods/lenses/test-discipline.md). The lens reviews the whole rule, including what no check flags.
17
+ **What a finding points at.** Match the sites against these causes.
18
+ - *A subsystem reached directly.* The code under test calls the real process, network, or filesystem. Inject a port and pass a test double.
19
+ - *Environment inherited by accident.* A spawned process picks up the developer's settings. Pass an explicit, created environment, or replace the process with a test double.
20
+ - *Setup that borrows the machine.* The test uses shared paths, home configuration, or the system clock. Create what it needs and remove it afterwards, or use a test double.
21
+ - *A real call used for convenience.* Realism or setup speed is the reason. Those never qualify; use a test double.
20
22
 
21
- ## What the check flags
22
- - Test files: `*.test.ts`, `*.test.tsx`, `*.test.mjs`, `*.test.js`, `*.spec.ts`, `*.spec.mjs`. Generated folders (`node_modules`, `dist`, `build`, `coverage`, `.git`, root `vendor`) are skipped; any other folder can be left out with `exclude` in disciplines.json.
23
- - A line calling `spawnSync`, `spawn`, `execFileSync`, `execFile`, `execSync`, `exec`, `execa` or `execaSync` with `"git"` (or `'git'`, or a template literal) as the first argument.
24
- - Allowed when, within that line and the next seven, an `env:` names `hermeticGitEnvironment`, `withoutInheritedGitBindings` or `environment`, and no nearby `env:` uses `process.env`. The helper is yours to provide.
25
- - Not detected: a command string such as `execSync("git status")`, a split call, or a non-literal command. Whether the spawn is warranted at all is left to review.
23
+ **Where to go.** Tests replace every real subsystem with a test double. The rare test whose subject is a subsystem's own behaviour brings its own instance and removes it.
26
24
 
27
- ## Example violation
28
- ```ts
29
- spawnSync("git", ["init"], { cwd: directory });
30
- ```
25
+ **Reactions to distrust.**
26
+ - "It works on my machine." That is the problem: it depends on your machine.
27
+ - "A test double is more work." Once per subsystem, against every developer's environment being at risk.
31
28
 
32
- ## How to fix
33
- ```ts
34
- spawnSync("git", ["init"], { cwd: directory, env: hermeticGitEnvironment() });
35
- ```
36
- Build the environment without inherited git variables or the user's configuration, and run in a temporary directory.
37
-
38
- ## Exceptions
39
- Record exemptions only in `discipline-exceptions.json` at the repository root; core reads no other allowance file. Use `authorised-location` when a test file legitimately builds its environment another way. 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).
40
-
41
- ```json
42
- { "version": 1, "exceptions": [
43
- { "kind": "authorised-location", "clause": "CD-47#hermetic-git-spawns", "file": "test/git-fixture.test.ts", "reason": "..." }
44
- ] }
45
- ```
46
-
47
- 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.
29
+ **Principles behind it.**
30
+ - *Hermetic tests.* A test depends only on what it creates, so its result is the same on every machine.
31
+ - *Erratic Test* (a test smell in Gerard Meszaros, *xUnit Test Patterns*). Tests that share or leak real resources pass or fail by circumstance.
@@ -0,0 +1,52 @@
1
+ # CD-5 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: what each check flags and misses, how to fix a flagged site, and how to record an exception.
4
+
5
+ ## Clauses
6
+
7
+ | Clause | Mechanism | Checks |
8
+ | --- | --- | --- |
9
+ | `CD-5#comments-directives` | audit | TODOs, linter directives and `@ts-expect-error` without a tracker |
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
+ - `// TODO` not followed, after optional spaces, by a tracked reference, for example `// TODO(#42) ...`.
14
+ - A comment starting with `biome-ignore`, `eslint-disable`, `eslint-enable`, `eslint-disable-line`, `eslint-disable-next-line`, an `oxlint-` equivalent or `eslint <config>`, unless the comment carries a tracked reference.
15
+ - A TypeScript directive without a tracked reference after it, in each form the compiler honours: `@ts-expect-error` or `@ts-ignore` opening a `//` or `///` comment, or opening the last line of a block comment after any `/` and `*`; and `@ts-nocheck`, in any letter case, opening a `//` or `///` comment among the comments that start the file. As in the compiler, `@ts-ignore` and `@ts-expect-error` are matched as written, so `@ts-ignored` counts and `@Ts-Ignore` does not. Forms the compiler ignores, such as `/* @ts-nocheck */`, a directive above a block comment's closing line, or `////`, are not flagged. `@ts-check` turns checking on and is not flagged.
16
+ - A tracked reference is a parenthesised token with no spaces that contains a digit, such as `(#42)`, `(PROJ-7)`, `(spec-42)` or `(https://tracker.example/issues/42)`. `()`, `(legacy)` and `(issue 42)` are not tracked references.
17
+ - TODO is matched on raw lines, so the same text inside a string is flagged too; linter and type directives are read from comments only.
18
+ - Ordinary explanatory comments and JSDoc are not flagged; keeping them out is left to review.
19
+
20
+ ## Settings
21
+ `trackerPatterns` narrows which tracked references count, for example to your own tracker's format. Each entry is a regular expression, as JavaScript source text, tested against each tracked reference with its parentheses; a reference counts when any entry matches. The test is an unanchored search unless the pattern anchors itself with `^` and `$`. The default, `["^\\(\\S+\\)$"]`, lets every tracked reference count.
22
+
23
+ ```json
24
+ "clauseSettings": {
25
+ "CD-5#comments-directives": { "trackerPatterns": ["^\\(spec-\\d+\\)$", "^\\(#\\d+\\)$"] }
26
+ }
27
+ ```
28
+
29
+ The patterns only narrow: a reference must still be a parenthesised token with no spaces that contains a digit, so a pattern such as `.*` cannot make `(legacy)` count. The same measure applies to TODO, where the reference must come right after `TODO`. Each entry must be a non-empty string that compiles as a regular expression; otherwise the check stops with a piece-invalid failure naming the clause and the entry.
30
+
31
+ ## Example violation
32
+ ```ts
33
+ // biome-ignore lint/style/noNonNullAssertion: legacy
34
+ const first = items[0]!;
35
+ ```
36
+
37
+ ## How to fix
38
+ ```ts
39
+ const first = items[0];
40
+ ```
41
+ Remove the need for the directive. If it must stay, add a tracked reference to the work that removes it: `// biome-ignore lint/style/noNonNullAssertion: until items is typed as a non-empty tuple (#42)`. The reference satisfies this clause only. A directive that escapes a selected clause, such as an `eslint-disable` naming a selected rule or a `@ts-expect-error` under `CD-2#cast-expressions`, still needs a file record on that clause, and that record does not satisfy this clause.
42
+
43
+ ## Exceptions
44
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file legitimately carries untracked directives, such as generated code. 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).
45
+
46
+ ```json
47
+ { "version": 1, "exceptions": [
48
+ { "kind": "authorised-location", "clause": "CD-5#comments-directives", "file": "src/generated/schema.ts", "reason": "..." }
49
+ ] }
50
+ ```
51
+
52
+ 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.
@@ -4,43 +4,25 @@
4
4
 
5
5
  Code is self-documenting: the names, types, and schemas carry the meaning. A prose comment is almost always there to excuse an unclear name or a convoluted expression — so the fix is to clarify the code, not annotate it. The only permitted annotations are machine-meaningful directives that carry a tracked reference; explanatory comments and doc-comments are not.
6
6
 
7
- The sections below describe what the audit check covers.
8
-
9
- ## Clauses
10
-
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-5#comments-directives` | audit | TODOs, linter directives and `@ts-expect-error` without a tracker |
14
-
15
- Review lens: [naming](../../methods/lenses/naming.md). The lens reviews the whole rule, including what no check flags.
16
-
17
- ## What the check flags
18
- - `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
19
- - `// TODO` not followed by `(`. Any parenthesised text is accepted, for example `// TODO(spec-42) ...`.
20
- - A comment starting with `biome-ignore`, `eslint-disable`, `eslint-enable`, `eslint-disable-line`, `eslint-disable-next-line`, an `oxlint-` equivalent or `eslint <config>`, unless the comment contains `(spec-<number>)`.
21
- - `// @ts-expect-error` on a line without `(spec-<number>)`.
22
- - TODO and `@ts-expect-error` are matched on raw lines, so the same text inside a string is flagged too.
23
- - Ordinary explanatory comments and JSDoc are not flagged; keeping them out is left to review.
24
-
25
- ## Example violation
26
- ```ts
27
- // biome-ignore lint/style/noNonNullAssertion: legacy
28
- const first = items[0]!;
29
- ```
30
-
31
- ## How to fix
32
- ```ts
33
- const first = items[0];
34
- ```
35
- Remove the need for the directive. If it must stay, add the tracker: `// biome-ignore lint/style/noNonNullAssertion: legacy (spec-42)`.
36
-
37
- ## Exceptions
38
- Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file legitimately carries untracked directives, such as generated code. 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).
39
-
40
- ```json
41
- { "version": 1, "exceptions": [
42
- { "kind": "authorised-location", "clause": "CD-5#comments-directives", "file": "src/generated/schema.ts", "reason": "..." }
43
- ] }
44
- ```
45
-
46
- 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: [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).
8
+
9
+ ## Spirit
10
+
11
+ **What the friction is for.** Prose beside code drifts from the code, and nothing checks it. The friction makes a clear name the cheap fix, and makes every "the checker is wrong here" marker point at the work that removes it.
12
+
13
+ **What a finding points at.** Match the sites against these causes.
14
+ - *A name that says too little.* The comment explains what the name should. Rename, or extract a named function.
15
+ - *A rule the types do not hold.* The comment states an invariant. Move it into a type, a union or a schema, where it is checked.
16
+ - *A suppression standing in for a fix.* The directive silences another rule. That rule's finding is the real one; read its Spirit section.
17
+ - *A promise nobody holds.* An untracked TODO. Track it or do it.
18
+
19
+ **Where to go.** Names, types and schemas carry the meaning, with no prose beside them. Each directive that remains carries a tracked reference to the work that retires it, so the count of directives falls over time rather than settling.
20
+
21
+ **Reactions to distrust.**
22
+ - "This needs explaining." Then the code is not yet clear. The explanation is the brief for a better name.
23
+ - "Add a tracked reference and move on." A reference that excuses the escape instead of retiring it is the same hole with a label.
24
+ - "It's generated." Then that file is a boundary. Authorise it, and keep hand-written code clean.
25
+
26
+ **Principles behind it.**
27
+ - *Intention-revealing names* (Robert C. Martin, *Clean Code*). Clean Code treats a comment as compensating for code that failed to express its intent; the fix is in the code.
28
+ - *Make illegal states unrepresentable* (Yaron Minsky). An invariant stated in a type is checked on every change; the same invariant in a comment is checked by nobody.
@@ -37,6 +37,54 @@
37
37
  "expectedLines": [
38
38
  1
39
39
  ]
40
+ },
41
+ {
42
+ "name": "eslint-disable with blank parentheses",
43
+ "fileName": "blank-tracker.ts",
44
+ "source": "// eslint-disable-next-line no-console ( )\nconsole.log(1);\n",
45
+ "expectedLines": [
46
+ 1
47
+ ]
48
+ },
49
+ {
50
+ "name": "biome-ignore with a word in parentheses",
51
+ "fileName": "word-tracker.ts",
52
+ "source": "// biome-ignore lint/style/noMagicNumbers: literal port (legacy)\nexport const portNumber = 8080;\n",
53
+ "expectedLines": [
54
+ 1
55
+ ]
56
+ },
57
+ {
58
+ "name": "todo with empty parentheses",
59
+ "fileName": "empty-todo.ts",
60
+ "source": "// TODO() rename this\nexport const someValue = 1;\n",
61
+ "expectedLines": [
62
+ 1
63
+ ]
64
+ },
65
+ {
66
+ "name": "ts-ignore without tracker",
67
+ "fileName": "ts-ignore.ts",
68
+ "source": "// @ts-ignore\nexport const broken: number = \"text\";\n",
69
+ "expectedLines": [
70
+ 1
71
+ ]
72
+ },
73
+ {
74
+ "name": "ts-nocheck in a triple-slash comment without tracker",
75
+ "fileName": "ts-nocheck.ts",
76
+ "source": "/// @ts-nocheck\nexport const broken: number = \"text\";\n",
77
+ "expectedLines": [
78
+ 1
79
+ ]
80
+ },
81
+ {
82
+ "name": "ts-ignore on the last line of a block comment without tracker",
83
+ "fileName": "block-ts-ignore.ts",
84
+ "source": "/*\n * legacy shape\n * @ts-ignore */\nexport const broken: number = \"text\";\n",
85
+ "expectedLines": [
86
+ 1
87
+ ]
40
88
  }
41
89
  ],
42
90
  "allow": [
@@ -52,6 +100,24 @@
52
100
  "source": "// biome-ignore lint/style/noMagicNumbers: literal port (spec-7)\nexport const portNumber = 8080;\n",
53
101
  "expectedLines": []
54
102
  },
103
+ {
104
+ "name": "biome-ignore with issue reference",
105
+ "fileName": "issue-ignore.ts",
106
+ "source": "// biome-ignore lint/style/noMagicNumbers: literal port (#42)\nexport const portNumber = 8080;\n",
107
+ "expectedLines": []
108
+ },
109
+ {
110
+ "name": "ts-expect-error with ticket reference",
111
+ "fileName": "tracked-expect-error.ts",
112
+ "source": "// @ts-expect-error legacy shape (PROJ-7)\nexport const broken: number = \"text\";\n",
113
+ "expectedLines": []
114
+ },
115
+ {
116
+ "name": "ts-nocheck in a block comment, which TypeScript does not honour",
117
+ "fileName": "block-ts-nocheck.ts",
118
+ "source": "/* @ts-nocheck */\nexport const checked: number = 1;\n",
119
+ "expectedLines": []
120
+ },
55
121
  {
56
122
  "name": "ordinary comment is left to review",
57
123
  "fileName": "plain.ts",
@@ -0,0 +1,51 @@
1
+ # CD-6 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: what each check flags and misses, how to fix a flagged site, and how to record an exception.
4
+
5
+ ## Clauses
6
+
7
+ | Clause | Mechanism | Checks |
8
+ | --- | --- | --- |
9
+ | `CD-6#identifier-names` | audit | a binding named from a fixed shorthand or filler list |
10
+ | `CD-6#naming-convention` | eslint | a name that breaks the naming convention for its kind |
11
+
12
+ ## What the check flags
13
+ - `.ts` and `.tsx` files, including tests; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
14
+ - The declared name of a variable, a parameter, a named function declaration or a destructured binding, when the whole name is exactly one of these (case-sensitive):
15
+ - shorthand: `c op s cb fn tx e ev acc item k v el arr i j n obj val res req tmp temp`
16
+ - filler: `object obj args arguments details extra extras data info params parameters props payload body value result stuff things misc metadata`
17
+ - Allowed: longer names that contain these words (`accountData`), names starting with `_`, property keys and property accesses.
18
+ - Other poor names (`manager`, `handler`, vague nouns) are left to review.
19
+
20
+ ## What the ESLint check flags
21
+ Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-6/README.md).
22
+ - `hone-cd6/naming-convention` is typescript-eslint's `naming-convention` with the option list in the piece's `piece.json`.
23
+ - Enum members are CONSTANT_CASE. `const` bindings are CONSTANT_CASE, camelCase or PascalCase.
24
+ - Object literal properties are camelCase. Type properties are camelCase or PascalCase.
25
+ - Other variables, functions and parameters are camelCase or PascalCase; a leading or trailing `_` or `$` is allowed.
26
+ - Types are PascalCase. Class members are camelCase, and static ones may also be CONSTANT_CASE.
27
+ - Consecutive capitals are allowed (`agentID`, `HTTPServer`).
28
+ - Ignored: names that need quotes, destructured bindings, imports and unused bindings whose name starts with `_`.
29
+ - Not checked, unlike Biome: the local name of a renamed named import (`import { a as b }`) and a `catch` parameter. typescript-eslint has no selector for either; review covers them.
30
+
31
+ ## Example violation
32
+ ```ts
33
+ const data = await loadAccount(id);
34
+ ```
35
+
36
+ ## How to fix
37
+ ```ts
38
+ const account = await loadAccount(id);
39
+ ```
40
+ Name the value for what it is in the domain.
41
+
42
+ ## Exceptions
43
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file must keep a name fixed by an external contract. 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).
44
+
45
+ ```json
46
+ { "version": 1, "exceptions": [
47
+ { "kind": "authorised-location", "clause": "CD-6#identifier-names", "file": "src/adapters/legacy-feed.ts", "reason": "..." }
48
+ ] }
49
+ ```
50
+
51
+ 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.
@@ -4,54 +4,25 @@
4
4
 
5
5
  A name states the concept the value represents, not its shape or its category. Shorthand (single letters, truncations) and filler words (data, info, value, result, manager, handler) force the reader to reconstruct meaning the name should have carried — at every scope, including callback parameters and destructures. The name is the documentation.
6
6
 
7
- The sections below describe what the audit and ESLint checks cover.
8
-
9
- ## Clauses
10
-
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-6#identifier-names` | audit | a binding named from a fixed shorthand or filler list |
14
- | `CD-6#naming-convention` | eslint | a name that breaks the naming convention for its kind |
15
-
16
- Review lens: [naming](../../methods/lenses/naming.md). The lens reviews the whole rule, including what no check flags.
17
-
18
- ## What the check flags
19
- - `.ts` and `.tsx` files, including tests; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
20
- - The declared name of a variable, a parameter, a named function declaration or a destructured binding, when the whole name is exactly one of these (case-sensitive):
21
- - shorthand: `c op s cb fn tx e ev acc item k v el arr i j n obj val res req tmp temp`
22
- - filler: `object obj args arguments details extra extras data info params parameters props payload body value result stuff things misc metadata`
23
- - Allowed: longer names that contain these words (`accountData`), names starting with `_`, property keys and property accesses.
24
- - Other poor names (`manager`, `handler`, vague nouns) are left to review.
25
-
26
- ## What the ESLint check flags
27
- Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-6/README.md).
28
- - `hone-cd6/naming-convention` is typescript-eslint's `naming-convention` with the option list in the piece's `piece.json`.
29
- - Enum members are CONSTANT_CASE. `const` bindings are CONSTANT_CASE, camelCase or PascalCase.
30
- - Object literal properties are camelCase. Type properties are camelCase or PascalCase.
31
- - Other variables, functions and parameters are camelCase or PascalCase; a leading or trailing `_` or `$` is allowed.
32
- - Types are PascalCase. Class members are camelCase, and static ones may also be CONSTANT_CASE.
33
- - Consecutive capitals are allowed (`agentID`, `HTTPServer`).
34
- - Ignored: names that need quotes, destructured bindings, imports and unused bindings whose name starts with `_`.
35
- - Not checked, unlike Biome: the local name of a renamed named import (`import { a as b }`) and a `catch` parameter. typescript-eslint has no selector for either; review covers them.
36
-
37
- ## Example violation
38
- ```ts
39
- const data = await loadAccount(id);
40
- ```
41
-
42
- ## How to fix
43
- ```ts
44
- const account = await loadAccount(id);
45
- ```
46
- Name the value for what it is in the domain.
47
-
48
- ## Exceptions
49
- Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a file must keep a name fixed by an external contract. 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).
50
-
51
- ```json
52
- { "version": 1, "exceptions": [
53
- { "kind": "authorised-location", "clause": "CD-6#identifier-names", "file": "src/adapters/legacy-feed.ts", "reason": "..." }
54
- ] }
55
- ```
56
-
57
- 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: [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).
8
+
9
+ ## Spirit
10
+
11
+ **What the friction is for.** A reader meets a name far more often than its definition. The friction makes stating the concept the easy path, so meaning lives where it is read.
12
+
13
+ **What a finding points at.** Match the sites against these causes.
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.
20
+
21
+ **Reactions to distrust.**
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.
25
+
26
+ **Principles behind it.**
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.
@@ -0,0 +1,46 @@
1
+ # CD-7 checks
2
+
3
+ Read [the rule and its spirit](README.md) first. This page is the mechanics: what each check flags and misses, how to fix a flagged site, and how to record an exception.
4
+
5
+ ## Clauses
6
+
7
+ | Clause | Mechanism | Checks |
8
+ | --- | --- | --- |
9
+ | `CD-7#categorical-paths` | audit | a forbidden file name or folder name in a path |
10
+ | `CD-7#filename-case` | eslint | a file name that is not kebab-case or PascalCase |
11
+
12
+ ## What the check flags
13
+ - `.ts` and `.tsx` files only, judged by path; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
14
+ - File names, exactly and in lower case, with a `.ts` extension: `types.ts interfaces.ts models.ts enums.ts utils.ts util.ts helpers.ts helper.ts common.ts lib.ts misc.ts shared.ts`.
15
+ - Any folder in the path named `utils`, `helpers`, `common`, `lib`, `misc` or `shared`. Each file under such a folder is reported once for the folder.
16
+ - Allowed: `account-types.ts`, `Types.ts` and `types.tsx`, which are not exact matches.
17
+
18
+ ## What the ESLint check flags
19
+ Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-7/README.md).
20
+ - `hone-cd7/filename-case` checks the file name before its first dot, after trimming edge `_`: it must be kebab-case or PascalCase. Each later dot segment must be kebab-case, PascalCase or lowercase.
21
+ - One leading `.`, `+` or `$` is ignored.
22
+ - Route names such as `[slug].ts` and `(group).ts` pass.
23
+ - A bad name is reported at line 1.
24
+
25
+ ## Example violation
26
+ ```text
27
+ src/helpers.ts
28
+ src/utils/format-price.ts
29
+ ```
30
+
31
+ ## How to fix
32
+ ```text
33
+ src/price-formatting.ts
34
+ ```
35
+ Rename the file or folder for what it contains, or split it into files that each hold one thing.
36
+
37
+ ## Exceptions
38
+ Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a path name is fixed by a framework or external convention. 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).
39
+
40
+ ```json
41
+ { "version": 1, "exceptions": [
42
+ { "kind": "authorised-location", "clause": "CD-7#categorical-paths", "file": "utils/format-price.ts", "reason": "Nuxt auto-imports from the utils directory, so the folder name is fixed by the framework" }
43
+ ] }
44
+ ```
45
+
46
+ 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.
@@ -4,49 +4,26 @@
4
4
 
5
5
  A file or folder is named for the abstraction it holds, not for a category of things. A junk-drawer name (utils, helpers, common, shared, types, misc) signals a missing primitive: the code inside wants a real home named for what it does. Category names accrete unrelated code because anything can be justified into them.
6
6
 
7
- The sections below describe what the audit and ESLint checks cover.
8
-
9
- ## Clauses
10
-
11
- | Clause | Mechanism | Checks |
12
- | --- | --- | --- |
13
- | `CD-7#categorical-paths` | audit | a forbidden file name or folder name in a path |
14
- | `CD-7#filename-case` | eslint | a file name that is not kebab-case or PascalCase |
15
-
16
- Review lens: [naming](../../methods/lenses/naming.md). The lens reviews the whole rule, including what no check flags.
17
-
18
- ## What the check flags
19
- - `.ts` and `.tsx` files only, judged by path; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
20
- - File names, exactly and in lower case, with a `.ts` extension: `types.ts interfaces.ts models.ts enums.ts utils.ts util.ts helpers.ts helper.ts common.ts lib.ts misc.ts shared.ts`.
21
- - Any folder in the path named `utils`, `helpers`, `common`, `lib`, `misc` or `shared`. Each file under such a folder is reported once for the folder.
22
- - Allowed: `account-types.ts`, `Types.ts` and `types.tsx`, which are not exact matches.
23
-
24
- ## What the ESLint check flags
25
- Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-7/README.md).
26
- - `hone-cd7/filename-case` checks the file name before its first dot, after trimming edge `_`: it must be kebab-case or PascalCase. Each later dot segment must be kebab-case, PascalCase or lowercase.
27
- - One leading `.`, `+` or `$` is ignored.
28
- - Route names such as `[slug].ts` and `(group).ts` pass.
29
- - A bad name is reported at line 1.
30
-
31
- ## Example violation
32
- ```text
33
- src/helpers.ts
34
- src/utils/format-price.ts
35
- ```
36
-
37
- ## How to fix
38
- ```text
39
- src/price-formatting.ts
40
- ```
41
- Rename the file or folder for what it contains, or split it into files that each hold one thing.
42
-
43
- ## Exceptions
44
- Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a path name is fixed by a framework or external convention. 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).
45
-
46
- ```json
47
- { "version": 1, "exceptions": [
48
- { "kind": "authorised-location", "clause": "CD-7#categorical-paths", "file": "src/shared/index.ts", "reason": "..." }
49
- ] }
50
- ```
51
-
52
- 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: [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).
8
+
9
+ ## Spirit
10
+
11
+ **What the friction is for.** A name is the first design decision a reader meets. A category name accepts anything, so code drifts into it without anyone deciding where it belongs. The friction forces the question "what is this?" at the moment it is cheapest to answer.
12
+
13
+ **What a finding points at.** Match the paths against these causes.
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.
20
+
21
+ **Reactions to distrust.**
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.
25
+
26
+ **Principles behind it.**
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.
@@ -0,0 +1,38 @@
1
+ # CD-7a 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-7a#factory-return-types` | audit | a line containing `ReturnType<typeof` |
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
+ - Any line matching `ReturnType<typeof`, one finding per line. This includes `Awaited<ReturnType<typeof ...>>` and matches inside strings.
14
+ - Lines starting with `//`, `/*` or `*` are ignored. A `ReturnType<` and `typeof` split across lines are not seen.
15
+ - The source rule's carve-out, an external library symbol with no exported return type, is not detected; record it as an exception.
16
+
17
+ ## Example violation
18
+ ```ts
19
+ type Client = ReturnType<typeof createClient>;
20
+ ```
21
+
22
+ ## How to fix
23
+ ```ts
24
+ export type Client = { readonly send: (message: string) => void };
25
+ const createClient = (): Client => ({ send: () => undefined });
26
+ ```
27
+ Declare and export the type, then annotate the factory with it.
28
+
29
+ ## Exceptions
30
+ 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).
31
+
32
+ ```json
33
+ { "version": 1, "exceptions": [
34
+ { "kind": "authorised-location", "clause": "CD-7a#factory-return-types", "file": "src/adapters/vendor-client.ts", "reason": "..." }
35
+ ] }
36
+ ```
37
+
38
+ 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.