@hailstails/hone 0.1.0-pre.4 → 0.1.0-pre.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ADOPTING.md +172 -38
- package/MIGRATING.md +58 -7
- package/README.md +117 -35
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/api/audit.d.ts +3 -2
- package/api/rule-set.d.ts +2 -4
- package/chunks/chunk-3HFJHJDO.js +53 -0
- package/chunks/chunk-5LCLBXP7.js +76 -0
- package/chunks/{chunk-BX6QHLSZ.js → chunk-ET5EBSJX.js} +61 -6
- package/chunks/chunk-LDQUT742.js +15 -0
- package/chunks/{chunk-RZA3OVOO.js → chunk-LOYT2AGY.js} +10 -9
- package/chunks/chunk-MVK5KFJI.js +421 -0
- package/chunks/{chunk-FOAGAYXM.js → chunk-NCDYOPHG.js} +7224 -2361
- package/chunks/chunk-WPRR2MPJ.js +22 -0
- package/chunks/{chunk-EYCRDEXX.js → chunk-XB4PCY3Q.js} +2 -13
- package/core/check/tool-command.js +1130 -230
- package/core/mechanism-port/piece-failure-types.d.ts +14 -0
- package/core/mechanism-port/runner-module-types.d.ts +5 -0
- package/core/rule-set-reader/authored-rule-set-types.d.ts +48 -0
- package/core/values/json-value.d.ts +3 -0
- package/docs/adding-a-discipline-or-mechanism.md +29 -13
- package/docs/extending.md +358 -0
- package/docs/output-contract.md +326 -0
- package/mechanisms/audit/CD-1/any-cast.js +9 -37
- package/mechanisms/audit/CD-19/import-boundaries.js +79 -68
- package/mechanisms/audit/CD-19/piece.json +5 -0
- package/mechanisms/audit/CD-2/cast-expressions.js +14 -37
- package/mechanisms/audit/CD-2/piece.json +6 -1
- package/mechanisms/audit/CD-5/comments-directives.js +121 -55
- package/mechanisms/audit/CD-5/piece.json +7 -0
- package/mechanisms/audit/runner/README.md +4 -2
- package/mechanisms/audit/runner/runner.js +102 -36
- package/mechanisms/audit/runner/typescript-parse.d.ts +6 -0
- package/mechanisms/audit/runner/walker-piece.d.ts +5 -5
- package/mechanisms/eslint/CD-2/README.md +12 -0
- package/mechanisms/eslint/CD-2/cd2/cd2.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-2/piece.json +25 -0
- package/mechanisms/eslint/runner/README.md +12 -5
- package/mechanisms/eslint/runner/runner.js +940 -232
- package/methods/README.md +2 -0
- package/methods/assessment-template.md +35 -0
- package/methods/lenses/clean-architecture.md +2 -2
- package/methods/lenses/decomposition.md +2 -2
- package/methods/lenses/defended-on-intent.md +7 -7
- package/methods/lenses/di-discipline.md +38 -26
- package/methods/lenses/errors-as-data.md +2 -2
- package/methods/lenses/function-first.md +2 -2
- package/methods/lenses/naming.md +2 -2
- package/methods/lenses/test-discipline.md +15 -13
- package/methods/lenses/type-soundness.md +2 -2
- package/methods/lenses/zod-boundary.md +2 -2
- package/package.json +5 -4
- package/rules/CD-1/CHECKS.md +37 -0
- package/rules/CD-1/README.md +17 -32
- package/rules/CD-1/discipline.json +16 -6
- package/rules/CD-10/CHECKS.md +49 -0
- package/rules/CD-10/README.md +21 -49
- package/rules/CD-11/CHECKS.md +13 -0
- package/rules/CD-11/README.md +14 -8
- package/rules/CD-12/CHECKS.md +13 -0
- package/rules/CD-12/README.md +14 -8
- package/rules/CD-13/CHECKS.md +13 -0
- package/rules/CD-13/README.md +14 -8
- package/rules/CD-14/CHECKS.md +49 -0
- package/rules/CD-14/README.md +22 -48
- package/rules/CD-15/CHECKS.md +40 -0
- package/rules/CD-15/README.md +22 -40
- package/rules/CD-16/CHECKS.md +7 -0
- package/rules/CD-16/README.md +3 -5
- package/rules/CD-17/CHECKS.md +37 -0
- package/rules/CD-17/README.md +17 -31
- package/rules/CD-18/CHECKS.md +13 -0
- package/rules/CD-18/README.md +15 -9
- package/rules/CD-19/CHECKS.md +49 -0
- package/rules/CD-19/README.md +18 -34
- package/rules/CD-19/discipline.json +6 -8
- package/rules/CD-2/CHECKS.md +56 -0
- package/rules/CD-2/README.md +19 -32
- package/rules/CD-2/discipline.json +93 -7
- package/rules/CD-20/CHECKS.md +7 -0
- package/rules/CD-20/README.md +3 -5
- package/rules/CD-21/CHECKS.md +13 -0
- package/rules/CD-21/README.md +14 -9
- package/rules/CD-22/CHECKS.md +13 -0
- package/rules/CD-22/README.md +13 -8
- package/rules/CD-23/CHECKS.md +35 -0
- package/rules/CD-23/README.md +14 -29
- package/rules/CD-24/CHECKS.md +7 -0
- package/rules/CD-24/README.md +3 -5
- package/rules/CD-25/CHECKS.md +38 -0
- package/rules/CD-25/README.md +20 -32
- package/rules/CD-26/CHECKS.md +36 -0
- package/rules/CD-26/README.md +18 -31
- package/rules/CD-27/CHECKS.md +45 -0
- package/rules/CD-27/README.md +18 -40
- package/rules/CD-28/CHECKS.md +13 -0
- package/rules/CD-28/README.md +14 -8
- package/rules/CD-29/CHECKS.md +13 -0
- package/rules/CD-29/README.md +12 -8
- package/rules/CD-3/CHECKS.md +42 -0
- package/rules/CD-3/README.md +20 -42
- package/rules/CD-30/CHECKS.md +13 -0
- package/rules/CD-30/README.md +13 -8
- package/rules/CD-31/CHECKS.md +13 -0
- package/rules/CD-31/README.md +12 -8
- package/rules/CD-32/CHECKS.md +13 -0
- package/rules/CD-32/README.md +13 -8
- package/rules/CD-33/CHECKS.md +13 -0
- package/rules/CD-33/README.md +13 -8
- package/rules/CD-34/CHECKS.md +13 -0
- package/rules/CD-34/README.md +12 -8
- package/rules/CD-39/CHECKS.md +13 -0
- package/rules/CD-39/README.md +13 -8
- package/rules/CD-4/CHECKS.md +13 -0
- package/rules/CD-4/README.md +15 -8
- package/rules/CD-40/CHECKS.md +39 -0
- package/rules/CD-40/README.md +17 -33
- package/rules/CD-41/CHECKS.md +54 -0
- package/rules/CD-41/README.md +23 -54
- package/rules/CD-42/CHECKS.md +47 -0
- package/rules/CD-42/README.md +19 -47
- package/rules/CD-43/CHECKS.md +37 -0
- package/rules/CD-43/README.md +15 -31
- package/rules/CD-44/CHECKS.md +48 -0
- package/rules/CD-44/README.md +20 -48
- package/rules/CD-45/CHECKS.md +13 -0
- package/rules/CD-45/README.md +14 -8
- package/rules/CD-46/CHECKS.md +7 -0
- package/rules/CD-46/README.md +16 -4
- package/rules/CD-47/CHECKS.md +37 -0
- package/rules/CD-47/README.md +16 -32
- package/rules/CD-5/CHECKS.md +52 -0
- package/rules/CD-5/README.md +22 -40
- package/rules/CD-5/discipline.json +66 -0
- package/rules/CD-6/CHECKS.md +51 -0
- package/rules/CD-6/README.md +22 -51
- package/rules/CD-7/CHECKS.md +46 -0
- package/rules/CD-7/README.md +23 -46
- package/rules/CD-7a/CHECKS.md +38 -0
- package/rules/CD-7a/README.md +14 -32
- package/rules/CD-8/CHECKS.md +42 -0
- package/rules/CD-8/README.md +20 -42
- package/rules/CD-9/CHECKS.md +13 -0
- package/rules/CD-9/README.md +15 -8
- package/rules/README.md +5 -3
- package/rules/SPIRIT.md +50 -0
- package/core/mechanism-port/runner-failure-types.d.ts +0 -38
- package/core/rule-set-reader/rule-set-types.d.ts +0 -41
- /package/api/{audit.js → audit.mjs} +0 -0
- /package/api/{rule-set.js → rule-set.mjs} +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RepoPath } from "../values/repo-path-types.js";
|
|
2
|
+
export type PieceFailure = {
|
|
3
|
+
readonly kind: "piece-invalid";
|
|
4
|
+
readonly pieceRoot: string;
|
|
5
|
+
readonly detail: string;
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: "file-unreadable";
|
|
8
|
+
readonly file: RepoPath;
|
|
9
|
+
readonly detail: string;
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: "file-unparseable";
|
|
12
|
+
readonly file: RepoPath;
|
|
13
|
+
readonly detail: string;
|
|
14
|
+
};
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { AnchorKind } from "../values/anchor.js";
|
|
2
2
|
import type { ClauseAddress } from "../values/clause-address-types.js";
|
|
3
|
+
import type { ReadonlyJsonValue } from "../values/json-value.js";
|
|
4
|
+
export type ClauseSettingValues = {
|
|
5
|
+
readonly [key: string]: ReadonlyJsonValue;
|
|
6
|
+
};
|
|
3
7
|
export type RunnerClause = {
|
|
4
8
|
readonly address: ClauseAddress;
|
|
5
9
|
readonly anchor: AnchorKind;
|
|
6
10
|
readonly pieceRoot: string;
|
|
7
11
|
readonly settings: unknown;
|
|
12
|
+
readonly clauseSettings: ClauseSettingValues;
|
|
8
13
|
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AnchorKind } from "../values/anchor.js";
|
|
2
|
+
import type { ReadonlyJsonValue } from "../values/json-value.js";
|
|
3
|
+
export type ClauseExceptions = "allowed" | "refused";
|
|
4
|
+
export type AuthoredSourceCase = {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly fileName: string;
|
|
7
|
+
readonly source: string;
|
|
8
|
+
readonly expectedLines: readonly number[];
|
|
9
|
+
};
|
|
10
|
+
export type AuthoredClauseDefinition = {
|
|
11
|
+
readonly kind: "mechanical";
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly summary: string;
|
|
14
|
+
readonly mechanisms: readonly string[];
|
|
15
|
+
readonly anchor: AnchorKind;
|
|
16
|
+
readonly exceptions?: ClauseExceptions;
|
|
17
|
+
readonly cases: {
|
|
18
|
+
readonly flag: readonly AuthoredSourceCase[];
|
|
19
|
+
readonly allow: readonly AuthoredSourceCase[];
|
|
20
|
+
};
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: "judgement";
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly summary: string;
|
|
25
|
+
readonly enforcedBy: "review";
|
|
26
|
+
};
|
|
27
|
+
export type AuthoredDisciplineFile = {
|
|
28
|
+
readonly version: 1;
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly clauses: readonly AuthoredClauseDefinition[];
|
|
31
|
+
};
|
|
32
|
+
export type ClauseSettingDeclaration = {
|
|
33
|
+
readonly default: ReadonlyJsonValue;
|
|
34
|
+
readonly choices?: readonly ReadonlyJsonValue[];
|
|
35
|
+
};
|
|
36
|
+
export type ClauseSettingDeclarations = {
|
|
37
|
+
readonly [key: string]: ClauseSettingDeclaration;
|
|
38
|
+
};
|
|
39
|
+
export type AuthoredPieceFile = {
|
|
40
|
+
readonly version: 1;
|
|
41
|
+
readonly discipline: string;
|
|
42
|
+
readonly mechanism: string;
|
|
43
|
+
readonly clauses: readonly {
|
|
44
|
+
readonly clause: string;
|
|
45
|
+
readonly settings: unknown;
|
|
46
|
+
readonly clauseSettings?: ClauseSettingDeclarations;
|
|
47
|
+
}[];
|
|
48
|
+
};
|
|
@@ -31,6 +31,20 @@ Each clause is either mechanical or judgement:
|
|
|
31
31
|
|
|
32
32
|
Clause ids are lower-case words joined by hyphens, and are unique within the discipline.
|
|
33
33
|
|
|
34
|
+
### 1a. The rule pages
|
|
35
|
+
|
|
36
|
+
Each discipline has two pages beside its `discipline.json`, so a reader meets the rule's intent before any detail of how it is checked.
|
|
37
|
+
|
|
38
|
+
`rules/<DisciplineId>/README.md` holds the rule and its spirit, and ends on the spirit:
|
|
39
|
+
|
|
40
|
+
- `# <ID>: <title>`, then `## Rule` with the rule text.
|
|
41
|
+
- One line that starts `Review lens:` and links the lens (the lenses find their pages by this line), then links `CHECKS.md` and [the spirit of the rules](../rules/SPIRIT.md).
|
|
42
|
+
- `## Spirit`, in five fixed parts, each a bold lead: **What the friction is for**; **What a finding points at**, a short list of usual causes, each with the direction it points; **Where to go**, the forward goal; **Reactions to distrust**, each common reaction with what it usually hides; **Principles behind it**, established principles named with one line each on how they apply, attributed only where the attribution is certain.
|
|
43
|
+
|
|
44
|
+
The Spirit section does not talk about syntax, detectors or linting. [rules/SPIRIT.md](../rules/SPIRIT.md) gives the approach for the whole set.
|
|
45
|
+
|
|
46
|
+
`rules/<DisciplineId>/CHECKS.md` holds the mechanics. It opens by pointing back to the rule page, then gives the Clauses table, what each check flags and misses, any settings, a violation and its fix, and how to record an exception.
|
|
47
|
+
|
|
34
48
|
### 2. The shared cases
|
|
35
49
|
|
|
36
50
|
A mechanical clause's `cases` hold `flag` and `allow` lists. Each case is `{ "name", "fileName", "source", "expectedLines" }`: a flag case lists the lines that must be flagged (at least one), and an allow case lists none. `fileName` is a repository path and may be a declaration file such as `x.d.ts`. There must be at least one of each.
|
|
@@ -55,6 +69,8 @@ For each mechanism in a clause's `mechanisms` list, add a piece folder `mechanis
|
|
|
55
69
|
- **audit:** `{ "module": "<file>.ts" }`, a path inside the piece folder; a `.js` module is accepted too, which is what the built package's pieces name. The module exports `check`, typed with `import type { WalkerPiece }` from `mechanisms/audit/runner/walker-piece.ts`. See `mechanisms/audit/runner/README.md`.
|
|
56
70
|
- **eslint:** `{ "pluginNamespace", "pluginModule", "rule" }`. `pluginModule` is a `.ts` or `.js` path inside the piece folder whose default export is an ESLint plugin; `rule` must be a key of its `rules`. The rule id is `<pluginNamespace>/<rule>`. The namespace `hone-core` is reserved for Hone's own machinery. The namespaces `hone` and `hone-*` belong to Hone's own rule set. A team rule set's pieces must use its rule-set name or `<ruleSet>-<name>`. Two selected clauses may not share a rule id, or a namespace with different plugin modules. CD-14's piece is `mechanisms/eslint/CD-14/piece.json`, pointing at the rule `no-class-authoring` in `cd14/cd14.eslint-plugin.ts` under the namespace `hone`.
|
|
57
71
|
|
|
72
|
+
A clause entry may also declare the settings a repository may tune, beside `settings`: `"clauseSettings": { "<key>": { "default": <JSON>, "choices": [<JSON>, ...] } }`. `choices` is optional; when given, every choice is the default's JSON kind and the default is one of them. Core reads these declarations itself, checks a repository's values from its `disciplines.json` against them when the check loads, and hands the piece the settled values, defaults included, as `clauseSettings` on each clause, typed `ClauseSettingValues`, apart from the mechanism's own `settings`. The `audit` and `rule-set` type entries carry no code, so a team's piece checks the shape of its `clauseSettings` itself, for example with its own schema, and returns `piece-invalid` when they do not match. No eslint piece declares `clauseSettings` yet, so a repository's settings for an eslint clause are refused when the check loads.
|
|
73
|
+
|
|
58
74
|
A runner reports a bad `settings` value, a module that fails to load or does not match its schema, or a missing rule as `piece-invalid`.
|
|
59
75
|
|
|
60
76
|
### 4. Tests
|
|
@@ -92,7 +108,7 @@ A repository selects it by naming the rule set and the clause:
|
|
|
92
108
|
|
|
93
109
|
### 1. The runner
|
|
94
110
|
|
|
95
|
-
Create `mechanisms/<MechanismId>/runner/runner.ts`. The id is lower-case words joined by hyphens. The module has one named export, `runner`, built by a factory in its own file so the runner's tests can call the factory with
|
|
111
|
+
Create `mechanisms/<MechanismId>/runner/runner.ts`. The id is lower-case words joined by hyphens, and never `not-run` or `not-adopted`, which `disciplines.json` reserves for a clause adopted with its mechanism not run and a clause a repository does not adopt. The module has one named export, `runner`, built by a factory in its own file so the runner's tests can call the factory with test doubles. The ESLint runner's `runner.ts`:
|
|
96
112
|
|
|
97
113
|
```ts
|
|
98
114
|
export const runner = toolchainBoundEmbeddedRunner({
|
|
@@ -118,7 +134,7 @@ Use core's ports (`core/platform-ports/`) for files, module loading and paths, a
|
|
|
118
134
|
|
|
119
135
|
A runner declares `exceptionPath`, which tells core how the tool's own exception formats are handled.
|
|
120
136
|
|
|
121
|
-
- **Standalone** (`"standalone"`): the tool has no exception format of its own, or none the repository can write to. The runner implements `run`, which returns raw hits for the selected clauses with no exception applied, and `conform`, which runs a clause over its shared cases without reading any repository file. Core applies `discipline-exceptions.json` itself. The audit mechanism is standalone. The author's contract is `StandaloneRunner` in `core/mechanism-port/runner-module-schema.ts`.
|
|
137
|
+
- **Standalone** (`"standalone"`): the tool has no exception format of its own, or none the repository can write to. The runner implements `run`, which returns raw hits for the selected clauses with no exception applied, and the `inline-disable` native exceptions it found, and `conform`, which runs a clause over its shared cases without reading any repository file. Core applies `discipline-exceptions.json` itself. The audit mechanism is standalone. The author's contract is `StandaloneRunner` in `core/mechanism-port/runner-module-schema.ts`.
|
|
122
138
|
- **Embedded** (`"embedded"`): the tool has its own ignore, override, suppression or inline formats, which the team's own run of the tool honours. The runner reports every native channel that touches a selected clause, and writes a projection so the team's run honours the recorded exceptions. ESLint is embedded. The author's contract is `EmbeddedRunner` in `core/mechanism-port/embedded-runner-module-schema.ts`; see "Embedded mechanisms" below.
|
|
123
139
|
|
|
124
140
|
Core knows only these two paths. A mechanism that fits neither would need a change to core.
|
|
@@ -151,14 +167,14 @@ These hold for every discipline and mechanism. Tests under `core/check/` check t
|
|
|
151
167
|
An embedded runner has the same `run` and `conform` as a standalone one, plus:
|
|
152
168
|
|
|
153
169
|
- `projectedKinds`: the native exception kinds its own projection writes. Only these kinds can be matched by a record.
|
|
154
|
-
- `run` also receives the repository's exception records for that mechanism, so it can regenerate the projection and compare it. It returns hits, the native exceptions it found, and the projection's state: `current`, `out-of-date`, `missing` or `not-included`. A projection that is missing or not included means the mechanism did not run: core lists `mechanism-not-run` and the check fails. An out-of-date one is a projection problem and also fails.
|
|
155
|
-
- `project`: writes the projection
|
|
170
|
+
- `run` also receives the repository's exception records for that mechanism, so it can regenerate the projection and compare it. It returns hits, the native exceptions it found, and the projection's state: `current`, `out-of-date`, `missing` or `not-included`. A projection that is missing or not included means the mechanism did not run: core lists `mechanism-not-run` and the check fails. An out-of-date one is a projection problem and also fails. It may also return `slices`, each a projection file other than the root one with its state, `missing`, `out-of-date`, `not-applied`, `unconfigured` or `nested-configuration`; a runner reports `nested-configuration` only beside a `not-included` projection, for a folder holding its own `disciplines.json` whose own config left the projection out of effect, and core names that folder on the `mechanism-not-run` entry; core lists each other state as a projection problem naming the file. A runner that returns none has none.
|
|
171
|
+
- `project`: writes the projection files and returns each path with `written`, `unchanged`, `removed` or `left-in-place`. `hone project` calls it.
|
|
156
172
|
|
|
157
|
-
Core passes every record for the mechanism to both calls, forfeited or not, and never passes the touched set. A forfeited file carve-out therefore stays in the projection
|
|
173
|
+
Core passes every record for the mechanism to both calls, forfeited or not, and never passes the touched set. A forfeited file carve-out therefore stays in the projection; core's check reports it as `forfeited`, no longer counts it as holding any native exception, so each one it held is listed under `unrecorded`, and fails the run. Keep it that way: a runner must not compute forfeiture or read the touched set itself, so that whether a forfeited carve-out stays pushed down remains core's decision. No test checks this; it is a rule for review.
|
|
158
174
|
|
|
159
175
|
### Native channels
|
|
160
176
|
|
|
161
|
-
Writing an embedded mechanism means listing every native channel the tool has and mapping each one to an exception kind core understands (`nativeExceptionSchema` in `core/mechanism-port/embedded-run-report-schema.ts`). A native exception is accepted only when its kind is in the runner's `projectedKinds` and a record in `discipline-exceptions.json` covers it; every other native exception is reported as unrecorded and fails the run, whether or not it currently hides a finding.
|
|
177
|
+
Writing an embedded mechanism means listing every native channel the tool has and mapping each one to an exception kind core understands (`nativeExceptionSchema` in `core/mechanism-port/embedded-run-report-schema.ts`). A native exception is accepted only when its kind is in the runner's `projectedKinds` and a record in `discipline-exceptions.json` covers it; every other native exception is reported as unrecorded and fails the run, whether or not it currently hides a finding. A standalone run can always have its `inline-disable` exceptions covered. An `inline-disable` is debt on its clause in its file, so only an `authorised-location` or `file-carve-out` on that clause and file covers it, never a `clause-wide-carve-out`; editing a carved file forfeits the carve-out as for any other file carve-out. A `command-line-option` is never covered: it changes the whole run of its script, so no record can hold it.
|
|
162
178
|
|
|
163
179
|
The ESLint runner's map. "Checked file" means a tracked `.ts`, `.tsx`, `.mts` or `.cts` file; "selected rule" means the rule id of a selected clause's ESLint piece.
|
|
164
180
|
|
|
@@ -167,18 +183,18 @@ The ESLint runner's map. "Checked file" means a tracked `.ts`, `.tsx`, `.mts` or
|
|
|
167
183
|
| a checked file the team's configuration ignores (for example a global `ignores` block); reported for every selected clause | `ignore` | no |
|
|
168
184
|
| a checked file on which the team's resolved configuration leaves a selected rule below `"error"` (`"warn"`, `"off"` or not set) | `config-override` | yes |
|
|
169
185
|
| an entry for a selected rule in any tracked file named `eslint-suppressions.json`, or in a file named by `--suppressions-location` in a tracked `package.json` script | `suppression-entry` | no |
|
|
170
|
-
| an `eslint-disable`, `eslint-disable-line` or `eslint-disable-next-line` comment naming a selected rule, or naming no rule | `inline-disable` |
|
|
186
|
+
| an `eslint-disable`, `eslint-disable-line` or `eslint-disable-next-line` comment naming a selected rule, or naming no rule, which escapes every selected clause and is reported once for each | `inline-disable` | yes, by a file record on its clause and file |
|
|
171
187
|
| an `/* eslint ... */` comment configuring a selected rule, or one that cannot be parsed | `inline-rule-config` | no |
|
|
172
|
-
| an option in an ESLint invocation in a tracked `package.json` script that weakens or replaces a selected rule's configuration: `--rule` or `--suppress-rule` naming it, or `--suppress-all`, `--
|
|
188
|
+
| an option in an ESLint invocation in a tracked `package.json` script that weakens or replaces a selected rule's configuration: `--rule` or `--suppress-rule` naming it, or `--suppress-all`, `--no-config-lookup`, `--parser`, `--parser-options` or `--plugin`; `-c`/`--config` or `--ignore-pattern`, unless the script's own folder settles that it changes nothing | `command-line-option` | no |
|
|
173
189
|
|
|
174
|
-
The ESLint runner declares `projectedKinds: ["config-override"]
|
|
190
|
+
The ESLint runner declares `projectedKinds: ["config-override", "inline-disable"]`, because a file record's projection block turns the rule off for that file whatever its comments say. A record covers a `config-override` on its own file (authorised location or file carve-out) or on every file (clause-wide carve-out), and an `inline-disable` on its own file only.
|
|
175
191
|
|
|
176
192
|
How the runner finds each channel (`mechanisms/eslint/runner/`):
|
|
177
193
|
|
|
178
|
-
- `ignore` and `config-override` come from a query instance of ESLint on the team's own configuration (`eslint-instance.ts`): `isPathIgnored` and `calculateConfigForFile` per checked file. A configuration that fails to load is `team-config-unloadable
|
|
194
|
+
- `ignore` and `config-override` come from a query instance of ESLint on the team's own configuration (`eslint-instance.ts`): `isPathIgnored` and `calculateConfigForFile` per checked file. A configuration that fails to load is `team-config-unloadable`, whose detail names the config through ESLint's `findConfigFile` and the checked file it applies to. Before failing, `governing-config.ts` asks the config governing the broken config's folder, and each one above it up to the repository root, whether it ignores that folder and then the file. Each question is `governingConfigIgnores`: ESLint built on that one config from its folder, with a files-only override block matching the asked path, so `isPathIgnored` answers true only for a real ignore and never for a path no `files` block matches; a folder is asked through a probe file directly inside it. A yes for both makes the file `ignore`, because the team's ESLint never enters that folder. A configuration that registers a different module under a selected piece's namespace is `plugin-conflict`.
|
|
179
195
|
- `inline-disable` and `inline-rule-config` come from a reserved rule, `<reservedNamespace>/inline-config` (currently `hone-core/inline-config`), that runs in core's governance lint and reads each file's inline configuration comments with `@eslint/plugin-kit` (`inline-config-parser.ts`). `eslint-enable` and other directives such as `/* global */` are not reported.
|
|
180
196
|
- `suppression-entry` comes from `suppressions-scanner.ts`. Keys in a tracked `eslint-suppressions.json` are read relative to its folder; keys in a file named by `--suppressions-location` are read relative to the `package.json` that names it.
|
|
181
|
-
- `command-line-option` comes from `package-script-scanner.ts`, which parses every tracked `package.json` and splits each script into commands. A command is an ESLint invocation when a token is `eslint`, starts `eslint@`, or ends `/eslint` or `/eslint.js`. A script with an unterminated quote is `tool-failed`.
|
|
197
|
+
- `command-line-option` comes from `package-script-scanner.ts`, which parses every tracked `package.json` and splits each script into commands. A command is an ESLint invocation when a token is `eslint`, starts `eslint@`, or ends `/eslint` or `/eslint.js`. A script with an unterminated quote is `tool-failed`. `script-option-effect.ts` clears only two cases, judged on the checked files under the `package.json` folder: `-c` or `--config` naming, from that folder, the config the query instance finds for each of those files, and `--ignore-pattern` that ESLint, built from that folder on that pattern alone with a files block matching each asked file, ignores none of them with. Anything it cannot settle weakens the run: no checked file under the folder, or any token after `eslint` that the shell expands (an unquoted `*`, `?`, `[`, `]`, `{`, `}`, `~`, `$` or backtick, or a `$` or backtick in double quotes) or that holds `..`, `$` or a backtick or starts with `/`, `~` or a drive letter. An invocation that is not plain is reported with its reason instead, as the cause `wrapped` naming the first token before `eslint` that is neither a package runner (`npx`, `pnpm`, `yarn`, `npm`, `bunx`, `exec`, `--`), a literal `NAME=value` assignment, nor `cross-env` followed only by `NAME=value` assignments; or, failing that, as the cause `after-another-command` when another command comes before it in the script, carrying its whole command as the suggested script. Every other option weakens the run.
|
|
182
198
|
|
|
183
199
|
Hits come from a separate governance instance that uses only the runner's configuration: the selected rules and the inline-config rule at `"error"` on `**/*.{ts,tsx,mts,cts}`, parsed with `@typescript-eslint/parser`, with the team's configuration file, ignores, suppressions and inline configuration all off. No native channel can change core's findings.
|
|
184
200
|
|
|
@@ -186,10 +202,10 @@ Options passed outside a `package.json` script (a CI step, an editor setting, a
|
|
|
186
202
|
|
|
187
203
|
### The ESLint projection
|
|
188
204
|
|
|
189
|
-
`projection.ts` writes `disciplines.eslint.mjs` at the repository root. It imports each piece's plugin module by a path relative to the
|
|
205
|
+
`projection.ts` writes `disciplines.eslint.mjs` at the repository root, and one slice of it beside each package config the team's ESLint loads (see the runner's README). It imports each piece's plugin module by a path relative to the slice's folder, then exports, in order: one block per plugin namespace enabling its selected rules at `"error"` on `**/*.{ts,tsx,mts,cts}`; one block per distinct set of clauses that authorised locations and file carve-outs except files from, listing those files (each path escaped as a glob) and turning the set's rules `"off"` for them, so the block count follows the clause combinations in use rather than the number of records; and one block per clause-wide carve-out turning them `"off"` everywhere. Block names start with `reservedNamespace` (currently `hone-core/`). The output is sorted, so the same selection and records always produce the same text.
|
|
190
206
|
|
|
191
207
|
The team spreads its default export last in its flat config; the projection is the only supported way to adopt the rules. On each check the runner first compares the file with what it would write now (`missing`, or `out-of-date` if it differs). It then checks the projection's effect through the query instance, in two directions. Every selected rule must be set, at any severity, on at least one checked file that is not ignored, when there is one. Every record whose file is checked must leave its rules at severity `0` on that file, or on every checked file for a clause-wide carve-out. If either fails, the result is `not-included` with no hits. The second direction catches a team that enables a rule another way, for example through a piece's own fragment such as `mechanisms/eslint/CD-14/cd14.eslint.ts`, without importing the projection.
|
|
192
208
|
|
|
193
209
|
### Runtime
|
|
194
210
|
|
|
195
|
-
The ESLint mechanism runs on the repository's own toolchain, declared as optional peers: `eslint` `^9.
|
|
211
|
+
The ESLint mechanism runs on the repository's own toolchain, declared as optional peers: `eslint` `^9.28.0 || ^10.0.0`, and `@typescript-eslint/parser` and `@typescript-eslint/eslint-plugin` `^8.56.0` (the latter for the pieces that reuse its rules). TypeScript is the parser's peer and the audit mechanism's, at `>=4.8.4 <7.0.0`. `@eslint/plugin-kit` is core's own dependency, imported directly because a transitive copy does not resolve under strict package managers. The development pins are `eslint` 10.11.0 and, as `eslint-9`, 9.39.5, with typescript-eslint 8.71.2, and each range's floor under a `-floor` alias; the integration suite runs on all four lines, against the consumer repositories in `mechanisms/eslint/runner/test-fixtures/`.
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
# Extending Hone with your own rule set
|
|
2
|
+
|
|
3
|
+
A team can add its own disciplines beside the ones Hone ships, without forking Hone. They live in the team's repository as a **rule set**: a folder of discipline files and the pieces that check them. `hone check` loads them from the repository, runs them, reports them and applies exceptions to them the same way as Hone's own; the differences are listed under [What is stable](#what-is-stable).
|
|
4
|
+
|
|
5
|
+
This guide follows one tested example. `install-proof` installs the packed package into a small repository, stored in Hone's source repository under `tests/test-fixtures/consumer-proof/team/`, type-checks its rule set and runs `hone project` and `hone check` against it. Its rule set is `acme`, with two disciplines: `ACME-1` checked by ESLint and `ACME-2` checked by the audit mechanism. Every file sample below is a file of that repository, apart from the rule pages, the per-package ESLint config, the settings samples and the exception record, which are described rather than tested there.
|
|
6
|
+
|
|
7
|
+
Read [ADOPTING.md](../ADOPTING.md) first: this guide assumes Hone is installed and `disciplines.json` exists.
|
|
8
|
+
|
|
9
|
+
## Which mechanism
|
|
10
|
+
|
|
11
|
+
- **ESLint** for anything about code syntax. The piece is an ordinary ESLint plugin, typed with ESLint's own types, and the team's editor and lint run report it too.
|
|
12
|
+
- **Audit** for what ESLint cannot see: which files exist, file names, and files that are not TypeScript. An audit piece is offered every tracked file in the repository, Markdown and JSON included.
|
|
13
|
+
|
|
14
|
+
## Where the files go
|
|
15
|
+
|
|
16
|
+
```text
|
|
17
|
+
disciplines.json
|
|
18
|
+
eslint.config.mjs
|
|
19
|
+
disciplines.eslint.mjs
|
|
20
|
+
tools/disciplines/acme/
|
|
21
|
+
package.json
|
|
22
|
+
tsconfig.pieces.json
|
|
23
|
+
rules/ACME-1/discipline.json
|
|
24
|
+
rules/ACME-1/README.md
|
|
25
|
+
rules/ACME-2/discipline.json
|
|
26
|
+
rules/ACME-2/README.md
|
|
27
|
+
mechanisms/eslint/ACME-1/piece.json
|
|
28
|
+
mechanisms/eslint/ACME-1/acme.eslint-plugin.ts
|
|
29
|
+
mechanisms/eslint/ACME-1/piece-settings.ts
|
|
30
|
+
mechanisms/audit/ACME-2/piece.json
|
|
31
|
+
mechanisms/audit/ACME-2/scratch-files.ts
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The rule set may sit anywhere inside the repository. Hone reads `rules/<ID>/discipline.json` and `mechanisms/<mechanism>/<ID>/piece.json` under it, and loads the modules the pieces name. Everything else in the folder is yours.
|
|
35
|
+
|
|
36
|
+
## Declare the rule set
|
|
37
|
+
|
|
38
|
+
Name the folder in `disciplines.json` under `ruleSets`, then select its clauses with the rule set's name in front:
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"version": 1,
|
|
43
|
+
"ruleSets": { "acme": "tools/disciplines/acme" },
|
|
44
|
+
"clauses": {
|
|
45
|
+
"acme/ACME-1#console-calls": "eslint",
|
|
46
|
+
"acme/ACME-2#scratch-files": "audit"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- The path is relative to the repository root and must stay inside it.
|
|
52
|
+
- `hone` is Hone's own rule set, and its clauses can be selected beside the team's. `hone/CD-15#loops` and `CD-15#loops` are the same clause, and the report prints the short form.
|
|
53
|
+
- A rule set may not be called `hone` or start with `hone-`, and no declared name may be another declared name plus `-<suffix>`.
|
|
54
|
+
- Discipline IDs only need to be unique inside one rule set: `acme/CD-1` and `CD-1` can both exist.
|
|
55
|
+
|
|
56
|
+
The report names team clauses with their rule set:
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
findings (2)
|
|
60
|
+
acme/ACME-1#console-calls eslint src/start-banner.ts:1:0 console.log("web started");
|
|
61
|
+
acme/ACME-2#scratch-files audit notes.scratch.md:1:0 notes.scratch.md
|
|
62
|
+
verdict: fail
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Write the discipline
|
|
66
|
+
|
|
67
|
+
`rules/ACME-1/discipline.json`:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"version": 1,
|
|
72
|
+
"id": "ACME-1",
|
|
73
|
+
"clauses": [
|
|
74
|
+
{
|
|
75
|
+
"kind": "mechanical",
|
|
76
|
+
"id": "console-calls",
|
|
77
|
+
"summary": "no direct console output in source",
|
|
78
|
+
"mechanisms": ["eslint"],
|
|
79
|
+
"anchor": { "kind": "keyword", "keyword": "console" },
|
|
80
|
+
"cases": {
|
|
81
|
+
"flag": [
|
|
82
|
+
{ "name": "console.log", "fileName": "src/a.ts", "source": "console.log(1);\n", "expectedLines": [1] }
|
|
83
|
+
],
|
|
84
|
+
"allow": [
|
|
85
|
+
{ "name": "no console", "fileName": "src/b.ts", "source": "export const b = 1;\n", "expectedLines": [] }
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- `id` matches the folder name. IDs are two to four capital letters, a dash and a number, with an optional lower-case letter after it.
|
|
94
|
+
- Each clause lists the mechanisms that can check it. Selecting one clause adopts the whole discipline, so its other mechanical clauses must be selected too.
|
|
95
|
+
- `anchor` is `{ "kind": "keyword", "keyword": "..." }` or `{ "kind": "file" }`.
|
|
96
|
+
- `cases` say what the clause must flag and what it must leave alone. They are the clause's contract. `hone check` does not run them against a team's pieces today, and will: see [What is stable](#what-is-stable).
|
|
97
|
+
- A clause with `"kind": "judgement"`, a `summary` and `"enforcedBy": "review"` is applied in review and cannot be selected.
|
|
98
|
+
- `"exceptions": "refused"` on a clause stops any exception record from exempting it.
|
|
99
|
+
|
|
100
|
+
`rules/ACME-1/README.md` is the rule's page: why the rule exists, one example that honours it and one that breaks it. Write it for the people and agents who apply the rule, not about how the check matches. It is optional today and will be required. Hone's own rule pages follow a fixed shape, a Rule and its Spirit on `README.md` with the mechanics in a sibling `CHECKS.md`; [adding a discipline](adding-a-discipline-or-mechanism.md#1a-the-rule-pages) describes it.
|
|
101
|
+
|
|
102
|
+
## An ESLint piece
|
|
103
|
+
|
|
104
|
+
`mechanisms/eslint/ACME-1/piece.json`:
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"version": 1,
|
|
109
|
+
"discipline": "ACME-1",
|
|
110
|
+
"mechanism": "eslint",
|
|
111
|
+
"clauses": [
|
|
112
|
+
{
|
|
113
|
+
"clause": "console-calls",
|
|
114
|
+
"settings": { "pluginNamespace": "acme", "pluginModule": "acme.eslint-plugin.ts", "rule": "no-console-calls" }
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`mechanisms/eslint/ACME-1/acme.eslint-plugin.ts`:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import type { ESLint, Rule } from "eslint";
|
|
124
|
+
|
|
125
|
+
export const noConsoleCalls: Rule.RuleModule = {
|
|
126
|
+
meta: {
|
|
127
|
+
type: "problem",
|
|
128
|
+
schema: [],
|
|
129
|
+
messages: { console: "Write through the logger port, not console." },
|
|
130
|
+
},
|
|
131
|
+
create: (context) => ({
|
|
132
|
+
"MemberExpression[object.name='console']": (node: Rule.Node) => {
|
|
133
|
+
context.report({ node, messageId: "console" });
|
|
134
|
+
},
|
|
135
|
+
}),
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const plugin: ESLint.Plugin = { rules: { "no-console-calls": noConsoleCalls } };
|
|
139
|
+
|
|
140
|
+
export default plugin;
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
- `pluginModule` is a path inside the piece folder. Its default export is the plugin, and `rule` is a key of its `rules`.
|
|
144
|
+
- `pluginNamespace` must be the rule set's name or start with it and a dash: `acme` or `acme-console`. `hone`, `hone-*` and `hone-core` belong to Hone.
|
|
145
|
+
- `options`, optional, is the rule's options array, passed to ESLint as written.
|
|
146
|
+
|
|
147
|
+
Then run `hone project`. It writes `disciplines.eslint.mjs`, which imports the plugin by a path relative to the repository root:
|
|
148
|
+
|
|
149
|
+
```js
|
|
150
|
+
import piece0 from "./tools/disciplines/acme/mechanisms/eslint/ACME-1/acme.eslint-plugin.ts";
|
|
151
|
+
|
|
152
|
+
export default [
|
|
153
|
+
{
|
|
154
|
+
name: "hone-core/piece/acme",
|
|
155
|
+
files: ["**/*.{ts,tsx,mts,cts}"],
|
|
156
|
+
plugins: { "acme": piece0 },
|
|
157
|
+
rules: { "acme/no-console-calls": "error" },
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Every `eslint.config.*` that applies to checked files spreads the projection last. The projection sets rules only, so the config also sets the typescript-eslint parser, as [ADOPTING.md](../ADOPTING.md#4a-set-up-eslint-for-eslint-clauses) step 4a explains. The example's `eslint.config.mjs`:
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
import typescriptParser from "@typescript-eslint/parser";
|
|
166
|
+
import projection from "./disciplines.eslint.mjs";
|
|
167
|
+
|
|
168
|
+
export default [
|
|
169
|
+
{ files: ["**/*.{ts,tsx,mts,cts}"], languageOptions: { parser: typescriptParser } },
|
|
170
|
+
...projection,
|
|
171
|
+
];
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
In a monorepo each package's own config does the same, importing the projection by its relative path, such as `../../disciplines.eslint.mjs`. A package config that leaves the projection out fails the check, listing each of its files under `unrecorded` as `acme/ACME-1#console-calls eslint config-override <file>`. [ADOPTING.md](../ADOPTING.md#4a-set-up-eslint-for-eslint-clauses) step 4a says which config ESLint applies to a file and how to state it in `disciplines.json` when detection cannot tell.
|
|
175
|
+
|
|
176
|
+
## An audit piece
|
|
177
|
+
|
|
178
|
+
`mechanisms/audit/ACME-2/piece.json`:
|
|
179
|
+
|
|
180
|
+
```json
|
|
181
|
+
{
|
|
182
|
+
"version": 1,
|
|
183
|
+
"discipline": "ACME-2",
|
|
184
|
+
"mechanism": "audit",
|
|
185
|
+
"clauses": [
|
|
186
|
+
{
|
|
187
|
+
"clause": "scratch-files",
|
|
188
|
+
"settings": { "module": "scratch-files.ts" }
|
|
189
|
+
}
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
`mechanisms/audit/ACME-2/scratch-files.ts`:
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import type { PieceHit, RunnerClause, WalkerPiece } from "@hailstails/hone/audit";
|
|
198
|
+
|
|
199
|
+
const SCRATCH_MARKER = ".scratch.";
|
|
200
|
+
|
|
201
|
+
const scratchHits = (request: { readonly clauses: readonly RunnerClause[]; readonly file: string }): readonly PieceHit[] =>
|
|
202
|
+
request.file.includes(SCRATCH_MARKER)
|
|
203
|
+
? request.clauses.map((clause) => ({ clause: clause.address, anchor: { line: 1, column: 0 }, snippet: request.file }))
|
|
204
|
+
: [];
|
|
205
|
+
|
|
206
|
+
export const check: WalkerPiece = {
|
|
207
|
+
prepare: ({ clauses }) => ({
|
|
208
|
+
outcome: "ok",
|
|
209
|
+
value: {
|
|
210
|
+
prepareFile: ({ file }) => ({ outcome: "ok", value: { kind: "complete", hits: scratchHits({ clauses, file }) } }),
|
|
211
|
+
finish: () => ({ outcome: "ok", value: [] }),
|
|
212
|
+
},
|
|
213
|
+
}),
|
|
214
|
+
};
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
- `module` is a path inside the piece folder, and the module exports `check`.
|
|
218
|
+
- `prepare` runs once with the selected clauses, the repository's file list and TypeScript's syntax API. `prepareFile` runs once per tracked file and returns `skipped`, `complete` with its hits, or `syntax` with observers that walk the file's syntax tree. `finish` returns hits that need the whole repository.
|
|
219
|
+
- A hit passes back the clause's `address` unchanged, a 1-based line and 0-based column, and a short snippet.
|
|
220
|
+
- When the piece cannot run, for example on settings it does not accept, return a failed result whose error is a `PieceFailure`: `kind` `piece-invalid`, the clause's `pieceRoot` and a `detail`. `hone check` then stops with a load failure naming the piece folder.
|
|
221
|
+
|
|
222
|
+
### Settings a repository can change
|
|
223
|
+
|
|
224
|
+
The example's marker is fixed. To let a repository change it, a clause entry in `piece.json` declares `clauseSettings`: each key with its `default`, and optionally `choices`, a list of the values allowed. For a `marker` setting with default `".scratch."`, the clause entry would read:
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
{
|
|
228
|
+
"clause": "scratch-files",
|
|
229
|
+
"settings": { "module": "scratch-files.ts" },
|
|
230
|
+
"clauseSettings": { "marker": { "default": ".scratch." } }
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
A repository that selects the clause can then override it in `disciplines.json`, keyed by the clause's address:
|
|
235
|
+
|
|
236
|
+
```json
|
|
237
|
+
"clauseSettings": {
|
|
238
|
+
"acme/ACME-2#scratch-files": { "marker": ".scratch.md" }
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Hone refuses a value under an undeclared key, of another JSON kind than the default, or outside the `choices`, before any piece runs. The piece reads the value, the override or else the default, from `clause.clauseSettings` on each `RunnerClause`, in place of the fixed `SCRATCH_MARKER`. The value is typed as any JSON value, so the piece narrows it, for example with `typeof marker === "string"`, and returns a `piece-invalid` failure when it is not what it accepts. Name the settings on the discipline's page under a Settings heading. This section is described, not run by the example: Hone's unit tests cover reading, refusing and overriding settings.
|
|
243
|
+
|
|
244
|
+
## TypeScript pieces under Node
|
|
245
|
+
|
|
246
|
+
Hone loads piece modules with Node, which strips the types from a `.ts` file as it loads it. Node 22.18 or later does this without flags.
|
|
247
|
+
|
|
248
|
+
- A piece module ends in `.ts` or `.js`. `.mts` and `.mjs` are refused.
|
|
249
|
+
- Node decides whether a `.ts` file is an ES module from the nearest `package.json`:
|
|
250
|
+
- `"type": "module"`: it loads, silently.
|
|
251
|
+
- No `"type"` field: it still loads, because Node sees the `export` syntax, but every run prints a `[MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///… is not specified` block per piece module before the report.
|
|
252
|
+
- `"type": "commonjs"`: it fails to load, with the `Failed to load the ES module` warning and load failure shown under [Common refusals](#common-refusals).
|
|
253
|
+
|
|
254
|
+
The example repository says `"type": "commonjs"` at its root, the hard case, so its rule set has its own `package.json`:
|
|
255
|
+
|
|
256
|
+
```json
|
|
257
|
+
{
|
|
258
|
+
"private": true,
|
|
259
|
+
"type": "module"
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
These three behaviours were checked by hand on Node 22.22.2; `install-proof` checks the first on every Node it runs.
|
|
264
|
+
- Use only syntax Node can erase, spell the `.ts` extension in relative imports, and use `import type` for types. [ADOPTING.md](../ADOPTING.md#1-check-the-prerequisites) step 1 lists the limits.
|
|
265
|
+
- Node does not strip types under `node_modules`. A rule set kept in an installed package is named by its repository path, for example `"acme": "node_modules/@acme/disciplines"`, and must ship `.js` piece modules; a `.ts` one fails with `Stripping types is currently unsupported for files under node_modules`.
|
|
266
|
+
|
|
267
|
+
## Type-check the rule set
|
|
268
|
+
|
|
269
|
+
`@hailstails/hone/rule-set` and `@hailstails/hone/audit` hold types only. Import them with `import type`. A `tsconfig` for the rule set that matches how Node runs it, `tools/disciplines/acme/tsconfig.pieces.json`:
|
|
270
|
+
|
|
271
|
+
```json
|
|
272
|
+
{
|
|
273
|
+
"compilerOptions": {
|
|
274
|
+
"target": "es2022",
|
|
275
|
+
"module": "nodenext",
|
|
276
|
+
"moduleResolution": "nodenext",
|
|
277
|
+
"strict": true,
|
|
278
|
+
"noEmit": true,
|
|
279
|
+
"allowImportingTsExtensions": true,
|
|
280
|
+
"erasableSyntaxOnly": true,
|
|
281
|
+
"verbatimModuleSyntax": true,
|
|
282
|
+
"resolveJsonModule": true,
|
|
283
|
+
"skipLibCheck": false,
|
|
284
|
+
"types": []
|
|
285
|
+
},
|
|
286
|
+
"include": ["**/*.ts"]
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Run it with the repository's own compiler, for example `tsc --noEmit -p tools/disciplines/acme/tsconfig.pieces.json`. `erasableSyntaxOnly` needs TypeScript 5.8 or later; leave it out on older versions.
|
|
291
|
+
|
|
292
|
+
The ESLint piece's `settings` can be checked against `EslintPieceSettings` from the JSON file itself. `mechanisms/eslint/ACME-1/piece-settings.ts`:
|
|
293
|
+
|
|
294
|
+
```ts
|
|
295
|
+
import type { EslintPieceSettings } from "@hailstails/hone/rule-set";
|
|
296
|
+
import piece from "./piece.json" with { type: "json" };
|
|
297
|
+
|
|
298
|
+
type Settled<Settings extends EslintPieceSettings> = Settings;
|
|
299
|
+
|
|
300
|
+
export type PieceSettings = Settled<(typeof piece)["clauses"][number]["settings"]>;
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
A wrong field then fails the type check, for example `Type 'number' is not assignable to type 'string'` for a numeric `rule`; `install-proof` checks this on TypeScript 4.8.4 and 6.0.3 with the same `Settled` type over settings typed as a JSON file types them. TypeScript reads string values in a JSON file as `string`, so this works for `settings` but not for `discipline.json` or the rest of `piece.json`, whose types name exact values such as `"mechanical"`. Hone checks those files when it reads them.
|
|
304
|
+
|
|
305
|
+
## Test a piece
|
|
306
|
+
|
|
307
|
+
Test an ESLint rule with ESLint's own `RuleTester`, importing the rule the plugin exports, such as `noConsoleCalls`, and giving it the clause's `flag` cases as `invalid` and its `allow` cases as `valid`. Run on its own with `node`, `RuleTester` prints nothing when the cases hold and throws on the first that does not; under a test runner that defines `describe` and `it`, it reports each case as a test.
|
|
308
|
+
|
|
309
|
+
Test an audit piece end to end: commit a file that breaks the rule, run `hone check` and expect its finding, then remove the file and expect a pass. A unit test of `check` itself is harder today: clause addresses and file paths are types that only Hone creates, so a test cannot build them without a cast, and CD-2 flags that cast in a test file as anywhere else.
|
|
310
|
+
|
|
311
|
+
## Exceptions
|
|
312
|
+
|
|
313
|
+
Exception records in `discipline-exceptions.json` name team clauses by their full address and work exactly as for Hone's own clauses. This entry, with `"fileExceptionWhyChains": "optional"` in `disciplines.json`, moves the finding to `exempted` and, after `hone project`, turns the rule off for that file in the team's own ESLint run:
|
|
314
|
+
|
|
315
|
+
```json
|
|
316
|
+
{
|
|
317
|
+
"kind": "authorised-location",
|
|
318
|
+
"clause": "acme/ACME-1#console-calls",
|
|
319
|
+
"file": "src/start-banner.ts",
|
|
320
|
+
"reason": "The start banner is the one place that writes to the terminal."
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Without that setting the entry also needs a `whyChain`, and without one it is refused as `evidence-refused`. [README.md](../README.md#discipline-exceptionsjson) describes the record kinds and the why-chain each needs.
|
|
325
|
+
|
|
326
|
+
## What is stable
|
|
327
|
+
|
|
328
|
+
Three requirements are decided and not yet built. Each will make some rule sets that pass today fail:
|
|
329
|
+
|
|
330
|
+
- **Cases are enforced.** `hone check` will run each selected team clause's `cases` against its piece, and fail the run as `nonconforming` when the piece misses a `flag` case or flags an `allow` case.
|
|
331
|
+
- **A rule page is required.** A selected team discipline without `rules/<ID>/README.md` will fail to load.
|
|
332
|
+
- **Pieces keep to import boundaries.** A team piece will be refused if it imports from anywhere but its own piece folder, its discipline's `rules/<ID>` folder, `@hailstails/hone/rule-set`, `@hailstails/hone/audit` and its mechanism's toolchain package (`eslint` or `typescript`), with values only from its own piece folder.
|
|
333
|
+
|
|
334
|
+
To be ready now: give every mechanical clause cases that its piece meets, write each discipline's `README.md`, and import nothing from Hone but its two public type entries.
|
|
335
|
+
|
|
336
|
+
| Part | Status |
|
|
337
|
+
| --- | --- |
|
|
338
|
+
| `ruleSets`, the address `[<ruleSet>/]<ID>#<clause>`, `hone` reserved | Stable |
|
|
339
|
+
| The folder layout `rules/<ID>/` and `mechanisms/<mechanism>/<ID>/` | Stable, with `rules/<ID>/README.md` becoming required |
|
|
340
|
+
| `discipline.json` and `piece.json` version 1, and the ESLint piece `settings` with the namespace rule | Stable file formats; `cases` becoming enforced |
|
|
341
|
+
| `@hailstails/hone/rule-set` | Stable |
|
|
342
|
+
| Exception records for team clauses | Stable |
|
|
343
|
+
| `@hailstails/hone/audit` and the walker piece contract | Experimental: may change in a minor release |
|
|
344
|
+
| A rule set named by a package name, such as `"acme": "@acme/disciplines"` | Not supported: name its repository path instead, as under [TypeScript pieces under Node](#typescript-pieces-under-node) |
|
|
345
|
+
| A new mechanism from outside Hone | Not supported |
|
|
346
|
+
|
|
347
|
+
## Common refusals
|
|
348
|
+
|
|
349
|
+
| Output | Cause |
|
|
350
|
+
| --- | --- |
|
|
351
|
+
| `load failure: reserved-rule-set-name hone` | A rule set is declared as `hone`. Pick the team's own name. |
|
|
352
|
+
| `load failure: unknown-rule-set beta` | A clause names a rule set that `ruleSets` does not declare. |
|
|
353
|
+
| `load failure: runner-failed eslint piece-invalid <piece folder> the plugin namespace hone belongs to Hone; the rule set acme must use acme or acme-<name>` | The ESLint piece uses one of Hone's namespaces. |
|
|
354
|
+
| `load failure: runner-failed eslint piece-invalid <piece folder> the plugin namespace lint is not owned by the rule set acme; use acme or acme-<name>` | The namespace does not start with the rule set's name. |
|
|
355
|
+
| `load failure: runner-failed eslint piece-invalid <piece folder> ✖ not a path inside the piece folder ending in .ts, or .js in a built install\n → at pluginModule` | The ESLint piece's `pluginModule` is outside the piece folder or ends in neither `.ts` nor `.js`. The `\n` is printed as written, not as a line break. |
|
|
356
|
+
| `load failure: runner-failed audit piece-invalid <piece folder> [\n {\n "code": "custom",\n "path": [\n "module"\n ],\n "message": "the module is not a path inside the piece folder ending .ts, or .js in a built install"\n }\n]` | The audit piece's `module` is outside the piece folder or ends in neither `.ts` nor `.js`. The whole message is one line, each `\n` printed as written. |
|
|
357
|
+
| `(node:<pid>) Warning: Failed to load the ES module: <piece module>. Make sure to set "type": "module" in the nearest package.json file or use the .mjs extension.` and ``(Use `node --trace-warnings ...` to show where the warning was created)``, then `load failure: runner-failed eslint piece-invalid <piece folder> Unexpected token 'export'` | The nearest `package.json` says `"type": "commonjs"`, so Node read the `.ts` piece as CommonJS. Node prints its warning for each `.ts` piece module it tried; the load failure names one mechanism whose piece failed. Give the rule set a `package.json` with `"type": "module"`. |
|
|
358
|
+
| `<clause> eslint config-override <file>` under `unrecorded` | An `eslint.config.*` that applies to the file does not spread the projection. |
|