@hailstails/hone 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/ADOPTING.md +33 -7
  2. package/CHANGELOG.md +19 -0
  3. package/MIGRATING.md +31 -6
  4. package/README.md +64 -17
  5. package/api/audit.d.ts +7 -1
  6. package/api/audit.js +9 -1
  7. package/api/testing.js +36 -8
  8. package/chunks/{chunk-XE6RNNZB.js → chunk-5VXHQC4A.js} +1395 -1339
  9. package/chunks/{chunk-5X2BR42Y.js → chunk-FR4FASVM.js} +15 -24
  10. package/chunks/{chunk-RNXPEK2U.js → chunk-H4V72FCW.js} +2 -2
  11. package/chunks/chunk-MXSIQPCV.js +13 -0
  12. package/chunks/chunk-NA5L6PUE.js +15 -0
  13. package/chunks/{chunk-OVEQ37JQ.js → chunk-PL2PNPAR.js} +42 -17
  14. package/chunks/chunk-RWQ4UNKY.js +24 -0
  15. package/chunks/{chunk-OKQHVZLO.js → chunk-T32FOWZA.js} +1 -1
  16. package/chunks/{chunk-LHVFZMXD.js → chunk-Y2KPZDDV.js} +80 -20
  17. package/chunks/{chunk-YL6WR3QW.js → chunk-Y4SMWOD2.js} +1 -1
  18. package/chunks/chunk-YLZ73C7O.js +0 -0
  19. package/chunks/{chunk-NILRE23T.js → chunk-Z4UBS7WI.js} +1 -1
  20. package/core/check/tool-command.js +702 -22
  21. package/core/conformance/conformance-testing-types.d.ts +2 -0
  22. package/core/mechanism-port/runner-module-types.d.ts +2 -0
  23. package/core/rule-set-reader/authored-rule-set-types.d.ts +2 -0
  24. package/core/values/edition-types.d.ts +16 -0
  25. package/docs/extending.md +32 -10
  26. package/docs/output-contract.md +101 -15
  27. package/mechanisms/audit/CD-19/import-boundaries.js +3 -2
  28. package/mechanisms/audit/CD-27/piece.json +5 -1
  29. package/mechanisms/audit/CD-27/test-body-logic.js +55 -4
  30. package/mechanisms/audit/CD-3/compiler-overrides.js +193 -29
  31. package/mechanisms/audit/CD-3/piece.json +35 -7
  32. package/mechanisms/audit/CD-5/comments-directives.js +4 -3
  33. package/mechanisms/audit/runner/README.md +3 -2
  34. package/mechanisms/audit/runner/runner.js +45 -8
  35. package/mechanisms/audit/runner/walker-piece.d.ts +12 -0
  36. package/mechanisms/eslint/runner/runner.js +8 -4
  37. package/package.json +1 -1
  38. package/rules/CD-27/CHECKS.md +31 -1
  39. package/rules/CD-27/discipline.json +74 -0
  40. package/rules/CD-3/CHECKS.md +33 -9
  41. package/rules/CD-3/discipline.json +278 -0
@@ -1,3 +1,10 @@
1
+ import {
2
+ editionSchema
3
+ } from "../../../chunks/chunk-RWQ4UNKY.js";
4
+ import {
5
+ editionReaches
6
+ } from "../../../chunks/chunk-NA5L6PUE.js";
7
+ import "../../../chunks/chunk-MXSIQPCV.js";
1
8
  import {
2
9
  folderScope
3
10
  } from "../../../chunks/chunk-QWA6OVLC.js";
@@ -35,12 +42,107 @@ var createDefaultJsoncParsePort = (options) => createJsoncParsePort({
35
42
  parseProvider: defaultProviderCallOf(options)
36
43
  });
37
44
 
38
- // mechanisms/audit/CD-3/compiler-overrides.ts
39
- var configEligibility = (request) => {
40
- if (request.file.split("/").at(-1) !== "tsconfig.json") return "excluded";
41
- if (folderScope({ file: request.file }) === "generated") return "excluded";
42
- return "eligible";
45
+ // mechanisms/audit/CD-3/typescript-compiler-options.ts
46
+ var FILE_LIST_DIAGNOSTICS = [18002, 18003];
47
+ var STRICT_FAMILY = ["strict", "useUnknownInCatchVariables"];
48
+ var WILDCARD = /[*?]/;
49
+ var recordingHostOf = (request) => {
50
+ const listed = [];
51
+ return {
52
+ host: {
53
+ useCaseSensitiveFileNames: request.syntaxApi.sys.useCaseSensitiveFileNames,
54
+ fileExists: (path) => request.disk.kindAt({ path }) === "file",
55
+ directoryExists: (path) => request.disk.kindAt({ path }) === "directory",
56
+ readFile: (path) => {
57
+ const text = request.disk.textAt({ path });
58
+ return text.outcome === "ok" ? text.value : void 0;
59
+ },
60
+ readDirectory: (...listing) => {
61
+ const [, , , includes] = listing;
62
+ listed.push(...includes);
63
+ return [];
64
+ },
65
+ getCurrentDirectory: () => request.root
66
+ },
67
+ includesListed: () => listed
68
+ };
69
+ };
70
+ var shownPath = (request) => request.path.startsWith(`${request.root}/`) ? request.path.slice(request.root.length + 1) : request.path;
71
+ var shownText = (request) => request.text.split(`${request.root}/`).join("");
72
+ var folderOf = (request) => request.path.slice(0, request.path.lastIndexOf("/"));
73
+ var stateOf = (request) => request.turnedOn === true ? "on" : "off";
74
+ var settingOf = (request) => {
75
+ const setting = Object.entries(request.compilerOptions).find(([key]) => key === request.option)?.[1];
76
+ return typeof setting === "boolean" ? stateOf({ turnedOn: setting }) : "unset";
77
+ };
78
+ var settingsOf = (request) => {
79
+ const config = request.config;
80
+ const compilerOptions = typeof config === "object" && config !== null && "compilerOptions" in config ? config.compilerOptions : void 0;
81
+ const options = typeof compilerOptions === "object" && compilerOptions !== null ? compilerOptions : {};
82
+ return {
83
+ strict: settingOf({ compilerOptions: options, option: "strict" }),
84
+ noUncheckedIndexedAccess: settingOf({ compilerOptions: options, option: "noUncheckedIndexedAccess" }),
85
+ exactOptionalPropertyTypes: settingOf({ compilerOptions: options, option: "exactOptionalPropertyTypes" }),
86
+ noImplicitOverride: settingOf({ compilerOptions: options, option: "noImplicitOverride" }),
87
+ noFallthroughCasesInSwitch: settingOf({ compilerOptions: options, option: "noFallthroughCasesInSwitch" }),
88
+ noPropertyAccessFromIndexSignature: settingOf({ compilerOptions: options, option: "noPropertyAccessFromIndexSignature" }),
89
+ useUnknownInCatchVariables: settingOf({ compilerOptions: options, option: "useUnknownInCatchVariables" })
90
+ };
91
+ };
92
+ var strictFamilyStateOf = (request) => {
93
+ const api = request.syntaxApi;
94
+ if ("getStrictOptionValue" in api && typeof api.getStrictOptionValue === "function") {
95
+ return stateOf({ turnedOn: api.getStrictOptionValue(request.options, request.option) });
96
+ }
97
+ return stateOf({ turnedOn: request.options[request.option] ?? request.options.strict });
98
+ };
99
+ var effectiveValueOf = (request) => STRICT_FAMILY.includes(request.option) ? strictFamilyStateOf(request) : stateOf({ turnedOn: request.options[request.option] });
100
+ var effectiveOf = (request) => ({
101
+ strict: effectiveValueOf({ ...request, option: "strict" }),
102
+ noUncheckedIndexedAccess: effectiveValueOf({ ...request, option: "noUncheckedIndexedAccess" }),
103
+ exactOptionalPropertyTypes: effectiveValueOf({ ...request, option: "exactOptionalPropertyTypes" }),
104
+ noImplicitOverride: effectiveValueOf({ ...request, option: "noImplicitOverride" }),
105
+ noFallthroughCasesInSwitch: effectiveValueOf({ ...request, option: "noFallthroughCasesInSwitch" }),
106
+ noPropertyAccessFromIndexSignature: effectiveValueOf({ ...request, option: "noPropertyAccessFromIndexSignature" }),
107
+ useUnknownInCatchVariables: effectiveValueOf({ ...request, option: "useUnknownInCatchVariables" })
108
+ });
109
+ var baseOf = (request) => ({
110
+ file: shownPath(request),
111
+ settings: settingsOf({ config: request.syntaxApi.readConfigFile(request.path, request.host.readFile).config })
112
+ });
113
+ var unresolvedDetail = (request) => request.diagnostics.map((diagnostic) => `TS${diagnostic.code} ${shownText({ ...request, text: request.syntaxApi.flattenDiagnosticMessageText(diagnostic.messageText, " ") })}`).join("; ");
114
+ var compiledFilesOf = (request) => {
115
+ if (request.parsed.fileNames.length > 0) return "some";
116
+ if (Object.keys(request.parsed.wildcardDirectories ?? {}).length > 0) return "some";
117
+ return request.includesListed.some((include) => !WILDCARD.test(include)) ? "some" : "none";
118
+ };
119
+ var resolvedConfigOf = (request) => {
120
+ const host = request.recording.host;
121
+ const source = request.syntaxApi.readJsonConfigFile(request.path, host.readFile);
122
+ const parsed = request.syntaxApi.parseJsonSourceFileConfigFileContent(source, host, folderOf(request), void 0, request.path);
123
+ const diagnostics = parsed.errors.filter((diagnostic) => !FILE_LIST_DIAGNOSTICS.includes(diagnostic.code));
124
+ if (diagnostics.length > 0) return { kind: "unresolved", detail: unresolvedDetail({ ...request, diagnostics }) };
125
+ if (compiledFilesOf({ parsed, includesListed: request.recording.includesListed() }) === "none") return { kind: "compiles-nothing" };
126
+ return {
127
+ kind: "resolved",
128
+ effective: effectiveOf({ syntaxApi: request.syntaxApi, options: parsed.options }),
129
+ bases: (source.extendedSourceFiles ?? []).map((path) => baseOf({ ...request, host, path }))
130
+ };
43
131
  };
132
+ var typeScriptCompilerOptionsOf = ({ syntaxApi, disk }) => {
133
+ const root = disk.root.split("\\").join("/");
134
+ return {
135
+ resolve: ({ file }) => {
136
+ const recording = recordingHostOf({ syntaxApi, disk, root });
137
+ return resolvedConfigOf({ syntaxApi, recording, root, path: `${root}/${file}` });
138
+ }
139
+ };
140
+ };
141
+
142
+ // mechanisms/audit/CD-3/compiler-overrides.ts
143
+ var RESOLVING_EDITION = editionSchema.parse("2");
144
+ var IMPLIED_BY_STRICT = ["useUnknownInCatchVariables"];
145
+ var FILE_ANCHOR = { line: 1, column: 0 };
44
146
  var STRICT_FLAGS = [
45
147
  { clause: "strict", option: "strict" },
46
148
  { clause: "no-unchecked-indexed-access", option: "noUncheckedIndexedAccess" },
@@ -50,9 +152,85 @@ var STRICT_FLAGS = [
50
152
  { clause: "no-property-access-from-index-signature", option: "noPropertyAccessFromIndexSignature" },
51
153
  { clause: "use-unknown-in-catch-variables", option: "useUnknownInCatchVariables" }
52
154
  ];
155
+ var configEligibility = (request) => {
156
+ if (request.file.split("/").at(-1) !== "tsconfig.json") return "excluded";
157
+ if (folderScope({ file: request.file }) === "generated") return "excluded";
158
+ return "eligible";
159
+ };
160
+ var selectedFlagsOf = (request) => STRICT_FLAGS.flatMap(
161
+ (flag) => request.clauses.filter((clause) => clause.address.discipline === "CD-3" && clause.address.clause === flag.clause).map((clause) => ({
162
+ address: clause.address,
163
+ option: flag.option,
164
+ judges: editionReaches({ edition: clause.edition, introducedIn: RESOLVING_EDITION }) === "reached" ? "resolved-options" : "own-options"
165
+ }))
166
+ );
167
+ var unparseable = (request) => ({
168
+ outcome: "failed",
169
+ error: { kind: "file-unparseable", file: request.file, detail: request.detail }
170
+ });
171
+ var ownOptionsOf = (request) => {
172
+ const config = request.config;
173
+ if (typeof config !== "object" || config === null || Array.isArray(config)) {
174
+ return unparseable({ file: request.file, detail: "configuration root must be an object" });
175
+ }
176
+ if (!("compilerOptions" in config)) return { outcome: "ok", value: [] };
177
+ const compilerOptions = config.compilerOptions;
178
+ if (typeof compilerOptions !== "object" || compilerOptions === null || Array.isArray(compilerOptions)) {
179
+ return unparseable({ file: request.file, detail: "compilerOptions must be an object" });
180
+ }
181
+ return { outcome: "ok", value: Object.entries(compilerOptions) };
182
+ };
183
+ var ownEntryOf = (request) => request.options.find(([key]) => key === request.option);
184
+ var ownSettingsOf = (request) => {
185
+ const strict = ownEntryOf({ options: request.options, option: "strict" })?.[1];
186
+ if (strict === true) return { strict: "on" };
187
+ return { strict: strict === false ? "off" : "unset" };
188
+ };
189
+ var turnsOff = (request) => {
190
+ const own = request.settings[request.option] ?? "unset";
191
+ if (own === "off") return "turns-off";
192
+ return own === "unset" && IMPLIED_BY_STRICT.includes(request.option) && request.settings.strict === "off" ? "turns-off" : "leaves";
193
+ };
194
+ var resolvedSnippet = (request) => {
195
+ const { option, resolved } = request;
196
+ if (resolved.effective[option] === "on") return void 0;
197
+ const thisFileTurnsOff = turnsOff({ settings: ownSettingsOf({ options: request.config.options }), option });
198
+ const offBases = resolved.bases.filter((base) => turnsOff({ settings: base.settings, option }) === "turns-off").map((base) => base.file);
199
+ if (thisFileTurnsOff === "turns-off") return `compilerOptions.${option} = false, turned off in ${[request.config.file, ...offBases].join(", ")}`;
200
+ if (offBases.length > 0) return `compilerOptions.${option} = false, inherited from ${offBases.join(", ")}`;
201
+ if (resolved.bases.length === 0) return `compilerOptions.${option} unset, and this file extends no base`;
202
+ return `compilerOptions.${option} unset here and in ${resolved.bases.map((base) => base.file).join(", ")}`;
203
+ };
204
+ var judgedSnippet = (request) => {
205
+ switch (request.resolved.kind) {
206
+ case "unresolved":
207
+ return `compilerOptions.${request.option} unknown: ${request.resolved.detail}`;
208
+ case "compiles-nothing":
209
+ return void 0;
210
+ case "resolved":
211
+ return resolvedSnippet({ config: request.config, resolved: request.resolved, option: request.option });
212
+ }
213
+ };
214
+ var presenceHit = (request) => ({
215
+ clause: request.flag.address,
216
+ anchor: FILE_ANCHOR,
217
+ snippet: `compilerOptions.${request.flag.option} = ${JSON.stringify(request.value)}`
218
+ });
219
+ var resolutionNeed = (request) => request.flags.some((flag) => flag.judges === "resolved-options" && ownEntryOf({ options: request.config.options, option: flag.option }) === void 0) ? "needed" : "not-needed";
220
+ var hitsOf = (request) => {
221
+ const resolved = resolutionNeed(request) === "needed" ? request.resolution.resolve({ file: request.config.file }) : void 0;
222
+ return request.flags.flatMap((flag) => {
223
+ const own = ownEntryOf({ options: request.config.options, option: flag.option });
224
+ if (own !== void 0) return [presenceHit({ flag, value: own[1] })];
225
+ if (flag.judges === "own-options" || resolved === void 0) return [];
226
+ const snippet = judgedSnippet({ config: request.config, resolved, option: flag.option });
227
+ return snippet === void 0 ? [] : [{ clause: flag.address, anchor: FILE_ANCHOR, snippet }];
228
+ });
229
+ };
53
230
  var createCompilerOverridesCheck = (options) => ({
54
- prepare: ({ clauses }) => {
55
- const selectedFlags = STRICT_FLAGS.flatMap((flag) => clauses.filter((clause) => clause.address.discipline === "CD-3" && clause.address.clause === flag.clause).map((clause) => ({ address: clause.address, option: flag.option })));
231
+ prepare: ({ clauses, repository, syntaxApi }) => {
232
+ const flags = selectedFlagsOf({ clauses });
233
+ const resolution = options.resolutionOf({ syntaxApi, disk: repository.disk });
56
234
  return {
57
235
  outcome: "ok",
58
236
  value: {
@@ -61,27 +239,10 @@ var createCompilerOverridesCheck = (options) => ({
61
239
  const text = readText();
62
240
  if (text.outcome === "failed") return text;
63
241
  const parsed = options.jsonc.parse({ source: text.value });
64
- if (parsed.outcome === "failed") {
65
- return { outcome: "failed", error: { kind: "file-unparseable", file, detail: parsed.error.detail } };
66
- }
67
- const config = parsed.value;
68
- if (typeof config !== "object" || config === null || Array.isArray(config)) {
69
- return { outcome: "failed", error: { kind: "file-unparseable", file, detail: "configuration root must be an object" } };
70
- }
71
- if (!("compilerOptions" in config)) return { outcome: "ok", value: { kind: "complete", hits: [] } };
72
- const compilerOptions = config.compilerOptions;
73
- if (typeof compilerOptions !== "object" || compilerOptions === null || Array.isArray(compilerOptions)) {
74
- return { outcome: "failed", error: { kind: "file-unparseable", file, detail: "compilerOptions must be an object" } };
75
- }
76
- const entries = Object.entries(compilerOptions);
77
- const hits = selectedFlags.flatMap((flag) => {
78
- const entry = entries.find(([key]) => key === flag.option);
79
- return entry === void 0 ? [] : [{
80
- clause: flag.address,
81
- anchor: { line: 1, column: 0 },
82
- snippet: `compilerOptions.${flag.option} = ${JSON.stringify(entry[1])}`
83
- }];
84
- });
242
+ if (parsed.outcome === "failed") return unparseable({ file, detail: parsed.error.detail });
243
+ const own = ownOptionsOf({ file, config: parsed.value });
244
+ if (own.outcome === "failed") return own;
245
+ const hits = hitsOf({ config: { file, options: own.value }, flags, resolution });
85
246
  return { outcome: "ok", value: { kind: "complete", hits } };
86
247
  },
87
248
  finish: () => ({ outcome: "ok", value: [] })
@@ -89,7 +250,10 @@ var createCompilerOverridesCheck = (options) => ({
89
250
  };
90
251
  }
91
252
  });
92
- var check = createCompilerOverridesCheck({ jsonc: createDefaultJsoncParsePort({ trailingCommas: "refused" }) });
253
+ var check = createCompilerOverridesCheck({
254
+ jsonc: createDefaultJsoncParsePort({ trailingCommas: "refused" }),
255
+ resolutionOf: typeScriptCompilerOptionsOf
256
+ });
93
257
  export {
94
258
  check,
95
259
  createCompilerOverridesCheck
@@ -7,43 +7,71 @@
7
7
  "clause": "strict",
8
8
  "settings": {
9
9
  "module": "compiler-overrides.js"
10
- }
10
+ },
11
+ "editions": [
12
+ "1",
13
+ "2"
14
+ ]
11
15
  },
12
16
  {
13
17
  "clause": "no-unchecked-indexed-access",
14
18
  "settings": {
15
19
  "module": "compiler-overrides.js"
16
- }
20
+ },
21
+ "editions": [
22
+ "1",
23
+ "2"
24
+ ]
17
25
  },
18
26
  {
19
27
  "clause": "exact-optional-property-types",
20
28
  "settings": {
21
29
  "module": "compiler-overrides.js"
22
- }
30
+ },
31
+ "editions": [
32
+ "1",
33
+ "2"
34
+ ]
23
35
  },
24
36
  {
25
37
  "clause": "no-implicit-override",
26
38
  "settings": {
27
39
  "module": "compiler-overrides.js"
28
- }
40
+ },
41
+ "editions": [
42
+ "1",
43
+ "2"
44
+ ]
29
45
  },
30
46
  {
31
47
  "clause": "no-fallthrough-cases-in-switch",
32
48
  "settings": {
33
49
  "module": "compiler-overrides.js"
34
- }
50
+ },
51
+ "editions": [
52
+ "1",
53
+ "2"
54
+ ]
35
55
  },
36
56
  {
37
57
  "clause": "no-property-access-from-index-signature",
38
58
  "settings": {
39
59
  "module": "compiler-overrides.js"
40
- }
60
+ },
61
+ "editions": [
62
+ "1",
63
+ "2"
64
+ ]
41
65
  },
42
66
  {
43
67
  "clause": "use-unknown-in-catch-variables",
44
68
  "settings": {
45
69
  "module": "compiler-overrides.js"
46
- }
70
+ },
71
+ "editions": [
72
+ "1",
73
+ "2"
74
+ ]
47
75
  }
48
76
  ]
49
77
  }
@@ -1,15 +1,16 @@
1
1
  import {
2
2
  stringListClauseSettings
3
- } from "../../../chunks/chunk-YL6WR3QW.js";
3
+ } from "../../../chunks/chunk-Y4SMWOD2.js";
4
4
  import {
5
5
  typeDirectiveReaderFor
6
- } from "../../../chunks/chunk-NILRE23T.js";
6
+ } from "../../../chunks/chunk-Z4UBS7WI.js";
7
7
  import {
8
8
  gatheredOutcomes
9
9
  } from "../../../chunks/chunk-LDQUT742.js";
10
10
  import {
11
11
  clauseAddressText
12
- } from "../../../chunks/chunk-5X2BR42Y.js";
12
+ } from "../../../chunks/chunk-FR4FASVM.js";
13
+ import "../../../chunks/chunk-MXSIQPCV.js";
13
14
  import {
14
15
  folderScope
15
16
  } from "../../../chunks/chunk-QWA6OVLC.js";
@@ -10,7 +10,8 @@ The audit runner is Hone's standalone mechanism for checks that read a project's
10
10
 
11
11
  ## Files
12
12
 
13
- - `walker-piece.ts` declares the contract a piece implements, `WalkerPiece`: a `prepare` call that receives the piece's selected clauses, the repository's tracked paths and TypeScript's API, and returns a prepared check with per-file `prepareFile` and a repository-wide `finish`.
13
+ - `walker-piece.ts` declares the contract a piece implements, `WalkerPiece`: a `prepare` call that receives the piece's selected clauses, the repository's tracked paths with a `disk` for reading files around them, such as a base config under `node_modules`, and TypeScript's API, and returns a prepared check with per-file `prepareFile` and a repository-wide `finish`.
14
+ - `walker-disk.ts` builds the `disk` a piece is handed: for a run, the real files under the repository root, untracked ones included, read through the file ports; for a conformance case, the case's texts in memory.
14
15
  - `source-scope.ts` classifies a repository path as `generated` (under `node_modules`, `dist`, `build`, `coverage`, `.git`, or a root `vendor`) or `authored`, so every piece skips generated folders the same way.
15
16
  - `walker-check-schema.ts` holds the schema for a clause's settings: `module`, a path inside the piece folder ending `.ts`, and optionally `escapingDirectives`, the TypeScript directives that escape the clause.
16
17
  - `type-directives.ts` reads a comment as a TypeScript directive only where the compiler honours it, and turns each directive a clause lists into an `inline-disable` of that clause. A piece that judges directives reads them through it too.
@@ -35,6 +36,6 @@ The runner offers the piece every tracked path in the repository, and the piece
35
36
 
36
37
  After every file, the prepared check's `finish` may return repository-wide hits, each naming its file. Every hit names one of the piece's selected clauses and carries a snippet the piece chooses.
37
38
 
38
- `conform` runs each case of a clause's `discipline.json` as a one-file repository holding only that case.
39
+ `conform` runs each case of a clause's `discipline.json` as a one-file repository holding only that case, whose `disk` holds only the case's file under the root `/repository`.
39
40
 
40
41
  A piece that throws, or returns a value outside its schema, makes the run fail as `piece-invalid`. A piece that cannot parse a file returns a failed result whose error is `{ kind: "file-unparseable", file, detail }`, and the check stops with `load failure: runner-failed audit file-unparseable <file> <detail>`.
@@ -2,20 +2,21 @@ import {
2
2
  TYPE_DIRECTIVES,
3
3
  directiveEscapesIn,
4
4
  escapesOf
5
- } from "../../../chunks/chunk-NILRE23T.js";
5
+ } from "../../../chunks/chunk-Z4UBS7WI.js";
6
6
  import {
7
7
  hitSchema,
8
8
  runnerResultSchema
9
- } from "../../../chunks/chunk-RNXPEK2U.js";
9
+ } from "../../../chunks/chunk-H4V72FCW.js";
10
10
  import {
11
11
  createDefaultPackageLocationPort,
12
12
  installRootOfRunnerEntry,
13
13
  toolchainBoundStandaloneRunner
14
- } from "../../../chunks/chunk-OKQHVZLO.js";
14
+ } from "../../../chunks/chunk-T32FOWZA.js";
15
15
  import {
16
16
  gatheredOutcomes
17
17
  } from "../../../chunks/chunk-LDQUT742.js";
18
18
  import {
19
+ createDefaultEntryKindPort,
19
20
  createDefaultFileTextPort,
20
21
  createDefaultModuleLoaderPort,
21
22
  createDefaultPathPort,
@@ -24,10 +25,11 @@ import {
24
25
  loadedPeer,
25
26
  moduleExtensionOf,
26
27
  moduleFileForm
27
- } from "../../../chunks/chunk-LHVFZMXD.js";
28
+ } from "../../../chunks/chunk-Y2KPZDDV.js";
28
29
  import {
29
30
  sameClauseAddress
30
- } from "../../../chunks/chunk-5X2BR42Y.js";
31
+ } from "../../../chunks/chunk-FR4FASVM.js";
32
+ import "../../../chunks/chunk-MXSIQPCV.js";
31
33
 
32
34
  // mechanisms/audit/runner/create-walker-runner.ts
33
35
  import { z as z4 } from "zod";
@@ -387,6 +389,38 @@ var walkerPieceSettingsSchema = z3.object({
387
389
  escapingDirectives: z3.array(z3.enum(TYPE_DIRECTIVES)).readonly().optional()
388
390
  }).readonly();
389
391
 
392
+ // mechanisms/audit/runner/walker-disk.ts
393
+ var CASE_ROOT = "/repository";
394
+ var portsDisk = (request) => ({
395
+ root: request.root,
396
+ kindAt: ({ path }) => request.entryKind.kindOf({ path }),
397
+ textAt: ({ path }) => {
398
+ const text = request.fileText.read({ path });
399
+ return text.outcome === "failed" ? { outcome: "failed", error: { detail: text.error.detail } } : text;
400
+ }
401
+ });
402
+ var foldersHolding = (request) => {
403
+ const segments = request.path.split("/");
404
+ return segments.slice(1, -1).map((_, depth) => segments.slice(0, depth + 2).join("/"));
405
+ };
406
+ var textsDisk = (request) => {
407
+ const files = new Map(Object.entries(request.texts).map(([file, text]) => [`${request.root}/${file}`, text]));
408
+ const folders = /* @__PURE__ */ new Set([request.root, ...[...files.keys()].flatMap((path) => foldersHolding({ path }))]);
409
+ return {
410
+ root: request.root,
411
+ kindAt: ({ path }) => {
412
+ if (files.has(path)) {
413
+ return "file";
414
+ }
415
+ return folders.has(path) ? "directory" : "absent";
416
+ },
417
+ textAt: ({ path }) => {
418
+ const text = files.get(path);
419
+ return text === void 0 ? { outcome: "failed", error: { detail: `${path} is not a file` } } : { outcome: "ok", value: text };
420
+ }
421
+ };
422
+ };
423
+
390
424
  // mechanisms/audit/runner/create-walker-runner.ts
391
425
  var finishedHitsSchema = runnerResultSchema({ value: z4.array(hitSchema).readonly() });
392
426
  var pieceInvalid3 = (request) => ({
@@ -507,7 +541,8 @@ var runOverRepository = (request) => {
507
541
  files: request.run.trackedPaths,
508
542
  exists: ({ file }) => request.ports.fileText.exists({
509
543
  path: request.ports.path.join({ segments: [request.run.repoRoot, file] })
510
- })
544
+ }),
545
+ disk: portsDisk({ root: request.run.repoRoot, entryKind: request.ports.entryKind, fileText: request.ports.fileText })
511
546
  };
512
547
  return preparedPieces({ ports: request.ports, clauses: request.run.clauses, repository }).then((prepared) => {
513
548
  if (prepared.outcome === "failed") return prepared;
@@ -528,7 +563,8 @@ var caseFile = (request) => ({
528
563
  var caseVerdict = (request) => {
529
564
  const repository = {
530
565
  files: [request.sourceCase.fileName],
531
- exists: ({ file }) => file === request.sourceCase.fileName ? "present" : "absent"
566
+ exists: ({ file }) => file === request.sourceCase.fileName ? "present" : "absent",
567
+ disk: textsDisk({ root: CASE_ROOT, texts: { [request.sourceCase.fileName]: request.sourceCase.source } })
532
568
  };
533
569
  return preparedPieces({ ports: request.ports, clauses: [request.clause], repository }).then((prepared) => {
534
570
  if (prepared.outcome === "failed") return prepared;
@@ -610,7 +646,8 @@ var runner = toolchainBoundStandaloneRunner({
610
646
  fileText: createDefaultFileTextPort({}),
611
647
  modules: createDefaultModuleLoaderPort({}),
612
648
  path: createDefaultPathPort({}),
613
- parse
649
+ parse,
650
+ entryKind: createDefaultEntryKindPort({})
614
651
  })
615
652
  });
616
653
  export {
@@ -45,11 +45,23 @@ export type PreparedWalkerCheck = {
45
45
  readonly prepareFile: (request: WalkerFile) => Result<PreparedFileCheck, PieceFailure>;
46
46
  readonly finish: () => Result<readonly Hit[], PieceFailure>;
47
47
  };
48
+ export type WalkerDisk = {
49
+ readonly root: string;
50
+ readonly kindAt: (request: {
51
+ readonly path: string;
52
+ }) => "file" | "directory" | "absent";
53
+ readonly textAt: (request: {
54
+ readonly path: string;
55
+ }) => Result<string, {
56
+ readonly detail: string;
57
+ }>;
58
+ };
48
59
  export type WalkerRepository = {
49
60
  readonly files: readonly RepoPath[];
50
61
  readonly exists: (request: {
51
62
  readonly file: RepoPath;
52
63
  }) => "present" | "absent";
64
+ readonly disk: WalkerDisk;
53
65
  };
54
66
  export type WalkerPiece = {
55
67
  readonly prepare: (request: {
@@ -1,12 +1,15 @@
1
+ import "../../../chunks/chunk-YLZ73C7O.js";
1
2
  import {
2
3
  eslintConfigLookupSchema,
3
4
  parsedJson
4
- } from "../../../chunks/chunk-OVEQ37JQ.js";
5
+ } from "../../../chunks/chunk-PL2PNPAR.js";
6
+ import "../../../chunks/chunk-RWQ4UNKY.js";
7
+ import "../../../chunks/chunk-NA5L6PUE.js";
5
8
  import {
6
9
  createDefaultPackageLocationPort,
7
10
  installRootOfRunnerEntry,
8
11
  toolchainBoundEmbeddedRunner
9
- } from "../../../chunks/chunk-OKQHVZLO.js";
12
+ } from "../../../chunks/chunk-T32FOWZA.js";
10
13
  import {
11
14
  gatheredOutcomes,
12
15
  listedOutcome
@@ -28,12 +31,13 @@ import {
28
31
  moduleFileForm,
29
32
  repoPathSchema,
30
33
  versionSupport
31
- } from "../../../chunks/chunk-LHVFZMXD.js";
34
+ } from "../../../chunks/chunk-Y2KPZDDV.js";
32
35
  import {
33
36
  TOOL_IDENTITY,
34
37
  clauseAddressText,
35
38
  sameClauseAddress
36
- } from "../../../chunks/chunk-5X2BR42Y.js";
39
+ } from "../../../chunks/chunk-FR4FASVM.js";
40
+ import "../../../chunks/chunk-MXSIQPCV.js";
37
41
 
38
42
  // mechanisms/eslint/runner/create-eslint-runner.ts
39
43
  import { z as z9 } from "zod";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hailstails/hone",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Checks a repository against the disciplines it selects, applies its recorded exceptions and prints one verdict.",
5
5
  "keywords": [
6
6
  "disciplines",
@@ -6,22 +6,42 @@ Read [the rule and its spirit](README.md) first. This page is the mechanics: wha
6
6
 
7
7
  | Clause | Mechanism | Checks |
8
8
  | --- | --- | --- |
9
- | `CD-27#test-body-logic` | audit | branching, `let`, and computing methods in a test file |
9
+ | `CD-27#test-body-logic` | audit | branching, `let`, and computing methods in a test file; edition 2 adds short-circuits, optional chaining, `switch` and computing namespace calls |
10
10
  | `CD-27#focused-tests` | eslint | `.only` on a test or suite, or `fdescribe`, `fit`, `ftest`, `fsuite` |
11
11
  | `CD-27#skipped-tests` | eslint | `.skip` or `.fixme` on a test or suite, or `xdescribe`, `xit`, `xtest`, `xsuite` |
12
12
 
13
13
  ## What the check flags
14
+ `CD-27#test-body-logic` has two editions. Edition 1 runs by default. Edition 2 adds the constructs below and becomes the default in the next major release; see [Settings](#settings) to run it now.
15
+
16
+ Edition 1:
14
17
  - Test files only: `*.test.ts` and `*.test.tsx`. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
15
18
  - `if` statements, `try` statements, ternary expressions and `let` declarations.
16
19
  - Any method call with a computing or mutating name, on any receiver: `map`, `filter`, `reduce`, `find`, `forEach`, `join`, `slice`, `split`, `replace`, `includes`, `sort`, `trim`, `keys`, `values`, `push`, `pop`, `splice`, `fill` and similar string and array methods.
17
20
  - Loops are not flagged here; CD-15 covers them. `throw` is CD-10.
18
21
 
22
+ Edition 2 also flags:
23
+ - `??`, `||` and `&&`, and their assignment forms `??=`, `||=` and `&&=`.
24
+ - Optional chaining: `a?.b`, `a?.[key]` and `f?.()`.
25
+ - `switch` statements.
26
+ - Computing calls on a built-in namespace: `JSON.stringify`, `JSON.parse`, `Object.assign`, `Object.fromEntries`, `Array.from` and any `Math` method.
27
+
28
+ Neither edition flags element access such as `calls[0]`, calls to free functions, or a method called through a computed key, such as `rows["map"]`. Helper files that tests import are not checked; only the test files themselves are.
29
+
19
30
  ## What the ESLint check flags
20
31
  Needs ESLint adopted through the projection; see [the ESLint piece](../../mechanisms/eslint/CD-27/README.md).
21
32
  - `hone-cd27/focused-tests` flags `.only` on a `describe`, `it`, `test` or `suite` chain, including `.only.each` and `test.describe.only`, and the bare names `fdescribe`, `fit`, `ftest` and `fsuite`. It reports at the `only` token.
22
33
  - `hone-cd27/skipped-tests` flags `.skip` and `.fixme` on those chains, and the bare names `xdescribe`, `xit`, `xtest` and `xsuite`.
23
34
  - Not flagged: `.todo`, `.concurrent` and `.each`.
24
35
 
36
+ ## Settings
37
+ - `edition`: the edition this clause runs, `"1"` or `"2"`. Without it, the clause runs edition 1, or the latest edition when `checkEditions` in `disciplines.json` is `"latest"`.
38
+
39
+ ```json
40
+ "clauseSettings": {
41
+ "CD-27#test-body-logic": { "edition": "2" }
42
+ }
43
+ ```
44
+
25
45
  ## Example violation
26
46
  ```ts
27
47
  const expected = rows.map((row) => row.id);
@@ -33,6 +53,16 @@ expect(ids).toEqual(["a1", "b2"]);
33
53
  ```
34
54
  Write the expected value out. A method call in the act step is flagged too, so move such logic into the unit under test.
35
55
 
56
+ Under edition 2, write a fallback or an optional call as the value it gives:
57
+
58
+ ```ts
59
+ const expected = given ?? 1;
60
+ ```
61
+
62
+ ```ts
63
+ expect(given).toBe(1);
64
+ ```
65
+
36
66
  ## Exceptions
37
67
  Add an entry to `discipline-exceptions.json` at the repository root. Use `authorised-location` when a test file legitimately needs logic. Use `file-carve-out` for debt in one file: it is forfeited once the file is touched, and needs a `whyChain` as below. See [discipline-exceptions.json](../../README.md#discipline-exceptionsjson).
38
68