@hailstails/hone 0.1.0-pre.5 → 0.1.0-pre.7
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 +151 -42
- package/MIGRATING.md +55 -4
- package/README.md +120 -43
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/api/audit.d.ts +3 -0
- package/api/audit.js +10 -0
- package/api/rule-set.js +0 -0
- package/api/testing.d.ts +5 -0
- package/api/testing.js +211 -0
- package/chunks/chunk-3LCKBX5T.js +2134 -0
- package/chunks/chunk-5LCLBXP7.js +76 -0
- package/chunks/{chunk-7PVPPH4C.js → chunk-LDQUT742.js} +3 -1
- package/chunks/{chunk-VUG3DJHN.js → chunk-MYX7GAVM.js} +9 -9
- package/chunks/{chunk-SWPCKTJV.js → chunk-NCDYOPHG.js} +7340 -2124
- package/chunks/{chunk-HVABJ7T4.js → chunk-NRXSM7BY.js} +73 -12
- package/chunks/{chunk-YBWVUDIG.js → chunk-P3NLETF5.js} +1 -1
- package/chunks/{chunk-IIMK5BCL.js → chunk-POZL7G62.js} +15 -13
- package/chunks/{chunk-7OVV6NEU.js → chunk-WPRR2MPJ.js} +1 -1
- package/core/check/tool-command.js +531 -1967
- package/core/conformance/conformance-testing-types.d.ts +28 -0
- package/core/conformance/conformance-types.d.ts +7 -0
- package/docs/adding-a-discipline-or-mechanism.md +27 -14
- package/docs/extending.md +22 -11
- package/docs/output-contract.md +326 -0
- package/mechanisms/audit/CD-19/import-boundaries.js +3 -3
- package/mechanisms/audit/CD-2/piece.json +6 -1
- package/mechanisms/audit/CD-5/comments-directives.js +10 -26
- package/mechanisms/audit/runner/README.md +3 -2
- package/mechanisms/audit/runner/runner.js +97 -35
- 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 +900 -242
- 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 +8 -3
- package/rules/CD-1/CHECKS.md +37 -0
- package/rules/CD-1/README.md +17 -32
- 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 -44
- package/rules/CD-2/CHECKS.md +56 -0
- package/rules/CD-2/README.md +18 -35
- package/rules/CD-2/discipline.json +68 -0
- 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 -52
- 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/api/audit.mjs +0 -1
- package/api/rule-set.mjs +0 -1
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
stringListClauseSettings
|
|
3
|
-
} from "../../../chunks/chunk-
|
|
3
|
+
} from "../../../chunks/chunk-WPRR2MPJ.js";
|
|
4
|
+
import {
|
|
5
|
+
typeDirectiveReaderFor
|
|
6
|
+
} from "../../../chunks/chunk-5LCLBXP7.js";
|
|
4
7
|
import {
|
|
5
8
|
gatheredOutcomes
|
|
6
|
-
} from "../../../chunks/chunk-
|
|
9
|
+
} from "../../../chunks/chunk-LDQUT742.js";
|
|
7
10
|
import {
|
|
8
11
|
clauseAddressText
|
|
9
|
-
} from "../../../chunks/chunk-
|
|
12
|
+
} from "../../../chunks/chunk-NCDYOPHG.js";
|
|
10
13
|
import {
|
|
11
14
|
folderScope
|
|
12
15
|
} from "../../../chunks/chunk-QWA6OVLC.js";
|
|
@@ -19,9 +22,6 @@ var sourceEligibility = (request) => {
|
|
|
19
22
|
return "eligible";
|
|
20
23
|
};
|
|
21
24
|
var TODO_PATTERN = /\/\/\s*TODO\b/;
|
|
22
|
-
var LINE_SUPPRESSION_PATTERN = /^\/\/\/?\s*@ts-(?:expect-error|ignore)/;
|
|
23
|
-
var BLOCK_SUPPRESSION_PATTERN = /^\s*[/*]*\s*@ts-(?:expect-error|ignore)/;
|
|
24
|
-
var FILE_SUPPRESSION_PATTERN = /^\/\/\/?\s*@ts-nocheck(?=[\s:]|$)/i;
|
|
25
25
|
var LINTER_DIRECTIVE_PATTERN = /^(?:\/\/|\/\*)\s*((?:biome-ignore(?:-all|-start|-end)?|(?:eslint|oxlint)-(?:disable(?:-line|-next-line)?|enable)|eslint(?=\s)))\b/;
|
|
26
26
|
var TRACKED_REFERENCE_PATTERN = /\([^()\s]*\d[^()\s]*\)/g;
|
|
27
27
|
var LEADING_TRACKED_REFERENCE_PATTERN = /^\s*(\([^()\s]*\d[^()\s]*\))/;
|
|
@@ -62,15 +62,6 @@ var textAfter = (request) => {
|
|
|
62
62
|
const marker = request.pattern.exec(request.text);
|
|
63
63
|
return marker === null ? void 0 : request.text.slice(marker.index + marker[0].length);
|
|
64
64
|
};
|
|
65
|
-
var typeDirectiveTail = (request) => {
|
|
66
|
-
const { comment, placement } = request;
|
|
67
|
-
if (placement.form === "block") {
|
|
68
|
-
return textAfter({ pattern: BLOCK_SUPPRESSION_PATTERN, text: comment.slice(comment.lastIndexOf("\n") + 1) });
|
|
69
|
-
}
|
|
70
|
-
const suppression = textAfter({ pattern: LINE_SUPPRESSION_PATTERN, text: comment });
|
|
71
|
-
if (suppression !== void 0 || placement.region === "body") return suppression;
|
|
72
|
-
return textAfter({ pattern: FILE_SUPPRESSION_PATTERN, text: comment });
|
|
73
|
-
};
|
|
74
65
|
var untrackedClauses = (request) => request.trackedClauses.filter((tracked) => request.tracking({ text: request.text, tracked }) === "untracked");
|
|
75
66
|
var hitsFor = (request) => {
|
|
76
67
|
if (request.untracked.length === 0) return [];
|
|
@@ -92,15 +83,9 @@ var taskHits = (request) => {
|
|
|
92
83
|
});
|
|
93
84
|
});
|
|
94
85
|
};
|
|
95
|
-
var commentPlacementOf = (request) => ({
|
|
96
|
-
form: request.range.kind === request.syntaxApi.SyntaxKind.MultiLineCommentTrivia ? "block" : "line",
|
|
97
|
-
region: request.fileHeaderPositions.has(request.range.pos) ? "file-header" : "body"
|
|
98
|
-
});
|
|
99
86
|
var sourceObserversFor = (request) => {
|
|
100
87
|
const { sourceFile, anchorAt, trackedClauses, syntaxApi } = request;
|
|
101
|
-
const
|
|
102
|
-
(syntaxApi.getLeadingCommentRanges(sourceFile.text, 0) ?? []).map((headerRange) => headerRange.pos)
|
|
103
|
-
);
|
|
88
|
+
const typeDirectiveOf = typeDirectiveReaderFor({ sourceFile, syntaxApi });
|
|
104
89
|
const todoHits = taskHits(request);
|
|
105
90
|
const directiveHits = [];
|
|
106
91
|
const typeDirectiveHits = [];
|
|
@@ -113,10 +98,9 @@ var sourceObserversFor = (request) => {
|
|
|
113
98
|
return {
|
|
114
99
|
comment: ({ range }) => {
|
|
115
100
|
const whole = sourceFile.text.slice(range.pos, range.end);
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
typeDirectiveHits.push(...commentHits({ text: afterTypeDirective, whole, position: range.pos }));
|
|
101
|
+
const typeDirective = typeDirectiveOf({ range });
|
|
102
|
+
if (typeDirective !== void 0) {
|
|
103
|
+
typeDirectiveHits.push(...commentHits({ text: typeDirective.tail, whole, position: range.pos }));
|
|
120
104
|
return;
|
|
121
105
|
}
|
|
122
106
|
if (LINTER_DIRECTIVE_PATTERN.exec(whole)?.[1] === void 0) return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Audit runner
|
|
2
2
|
|
|
3
|
-
The audit runner is Hone's standalone mechanism for checks that read a project's TypeScript source directly. Core hands it the selected clauses and the files to check; it loads each clause's piece module, parses each file once, visits every node of the syntax tree, and reports a hit wherever a piece's check finds one.
|
|
3
|
+
The audit runner is Hone's standalone mechanism for checks that read a project's TypeScript source directly. Core hands it the selected clauses and the files to check; it loads each clause's piece module, parses each file once, visits every node of the syntax tree, and reports a hit wherever a piece's check finds one. Its `exceptionPath` is `standalone`: the audit mechanism has no suppression format of its own. The one native channel it reports is a TypeScript directive, `@ts-expect-error`, `@ts-ignore` or `@ts-nocheck`, in a file the clause's piece reads, for each clause whose `piece.json` settings list that directive in `escapingDirectives`; each is an `inline-disable` of that clause, which only a file record on that clause and file covers.
|
|
4
4
|
|
|
5
5
|
## Runtime
|
|
6
6
|
|
|
@@ -12,7 +12,8 @@ The audit runner is Hone's standalone mechanism for checks that read a project's
|
|
|
12
12
|
|
|
13
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`.
|
|
14
14
|
- `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
|
-
- `walker-check-schema.ts` holds the schema for a clause's settings: `module`, a path inside the piece folder ending `.ts
|
|
15
|
+
- `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
|
+
- `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.
|
|
16
17
|
- `piece-clause-settings.ts` reads the string lists a Hone piece declares under `clauseSettings` from the settled values core hands it on each clause, and reports a malformed value as `piece-invalid`.
|
|
17
18
|
- `prepare-walker-pieces.ts` loads each selected module once and prepares it with every selected clause that names it.
|
|
18
19
|
- `observe-walker-file.ts` offers one file to every prepared piece, parses it once if any piece asks for syntax, walks it, and collects the hits.
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TYPE_DIRECTIVES,
|
|
3
|
+
directiveEscapesIn,
|
|
4
|
+
escapesOf
|
|
5
|
+
} from "../../../chunks/chunk-5LCLBXP7.js";
|
|
1
6
|
import {
|
|
2
7
|
hitSchema,
|
|
3
8
|
runnerResultSchema
|
|
4
|
-
} from "../../../chunks/chunk-
|
|
9
|
+
} from "../../../chunks/chunk-MYX7GAVM.js";
|
|
5
10
|
import {
|
|
6
11
|
createDefaultPackageLocationPort,
|
|
7
12
|
installRootOfRunnerEntry,
|
|
8
13
|
toolchainBoundStandaloneRunner
|
|
9
|
-
} from "../../../chunks/chunk-
|
|
14
|
+
} from "../../../chunks/chunk-P3NLETF5.js";
|
|
10
15
|
import {
|
|
11
16
|
gatheredOutcomes
|
|
12
|
-
} from "../../../chunks/chunk-
|
|
17
|
+
} from "../../../chunks/chunk-LDQUT742.js";
|
|
13
18
|
import {
|
|
14
19
|
createDefaultFileTextPort,
|
|
15
20
|
createDefaultModuleLoaderPort,
|
|
@@ -19,11 +24,11 @@ import {
|
|
|
19
24
|
loadedPeer,
|
|
20
25
|
moduleExtensionOf,
|
|
21
26
|
moduleFileForm
|
|
22
|
-
} from "../../../chunks/chunk-
|
|
27
|
+
} from "../../../chunks/chunk-NRXSM7BY.js";
|
|
23
28
|
import {
|
|
24
29
|
external_exports,
|
|
25
30
|
sameClauseAddress
|
|
26
|
-
} from "../../../chunks/chunk-
|
|
31
|
+
} from "../../../chunks/chunk-NCDYOPHG.js";
|
|
27
32
|
import "../../../chunks/chunk-NZLE2WMY.js";
|
|
28
33
|
|
|
29
34
|
// mechanisms/audit/runner/observe-walker-file.ts
|
|
@@ -125,6 +130,7 @@ var beginFile = (request) => {
|
|
|
125
130
|
};
|
|
126
131
|
var observeSource = (request) => {
|
|
127
132
|
const seenComments = /* @__PURE__ */ new Set();
|
|
133
|
+
const comments = [];
|
|
128
134
|
const emptyMembership = /* @__PURE__ */ new Set();
|
|
129
135
|
let failure;
|
|
130
136
|
const invoke = (call) => {
|
|
@@ -138,6 +144,7 @@ var observeSource = (request) => {
|
|
|
138
144
|
const comment = (range) => {
|
|
139
145
|
if (seenComments.has(range.pos)) return;
|
|
140
146
|
seenComments.add(range.pos);
|
|
147
|
+
comments.push(range);
|
|
141
148
|
request.sources.forEach((source) => {
|
|
142
149
|
invoke({ source, notify: () => source.observers.comment?.({ range }) });
|
|
143
150
|
});
|
|
@@ -174,7 +181,7 @@ var observeSource = (request) => {
|
|
|
174
181
|
};
|
|
175
182
|
}
|
|
176
183
|
if (failure !== void 0) return { outcome: "failed", error: failure };
|
|
177
|
-
return { outcome: "ok", value:
|
|
184
|
+
return { outcome: "ok", value: comments };
|
|
178
185
|
};
|
|
179
186
|
var attributedHits = (request) => {
|
|
180
187
|
if (request.hits.some((hit) => !request.piece.clauses.some(
|
|
@@ -206,10 +213,14 @@ var completedFile = (request) => {
|
|
|
206
213
|
outcome: "ok",
|
|
207
214
|
value: {
|
|
208
215
|
hits: finished.value.flatMap((hits) => hits.map((hit) => ({ ...hit, file: request.file.file }))),
|
|
216
|
+
nativeExceptions: request.nativeExceptions,
|
|
209
217
|
applicable: request.active.flatMap((active) => active.piece.clauses.map((clause) => clause.address))
|
|
210
218
|
}
|
|
211
219
|
};
|
|
212
220
|
};
|
|
221
|
+
var syntaxClausesOf = (request) => request.active.flatMap(
|
|
222
|
+
(active) => active.completion.kind === "syntax" ? active.piece.clauses.map((clause) => clause.address) : []
|
|
223
|
+
);
|
|
213
224
|
var observeWalkerFile = (request) => {
|
|
214
225
|
const cache = cachedFile(request);
|
|
215
226
|
const file = cache.file;
|
|
@@ -223,7 +234,8 @@ var observeWalkerFile = (request) => {
|
|
|
223
234
|
file,
|
|
224
235
|
active: applicable.flatMap(
|
|
225
236
|
(selected) => selected.check.kind === "complete" ? [{ piece: selected.piece, completion: selected.check }] : []
|
|
226
|
-
)
|
|
237
|
+
),
|
|
238
|
+
nativeExceptions: []
|
|
227
239
|
});
|
|
228
240
|
}
|
|
229
241
|
const parsed = parsedSource({ file, parse: request.parse });
|
|
@@ -239,7 +251,18 @@ var observeWalkerFile = (request) => {
|
|
|
239
251
|
)
|
|
240
252
|
});
|
|
241
253
|
if (observed.outcome === "failed") return observed;
|
|
242
|
-
return completedFile({
|
|
254
|
+
return completedFile({
|
|
255
|
+
file,
|
|
256
|
+
active: active.value,
|
|
257
|
+
nativeExceptions: directiveEscapesIn({
|
|
258
|
+
sourceFile: parsed.value,
|
|
259
|
+
syntaxApi: request.parse.syntaxApi,
|
|
260
|
+
file: file.file,
|
|
261
|
+
comments: observed.value,
|
|
262
|
+
escapes: escapesOf({ escapes: request.escapes, clauses: syntaxClausesOf({ active: active.value }) }),
|
|
263
|
+
anchorAt: ({ position }) => anchorAt({ tree: parsed.value, position })
|
|
264
|
+
})
|
|
265
|
+
});
|
|
243
266
|
};
|
|
244
267
|
|
|
245
268
|
// mechanisms/audit/runner/prepare-walker-pieces.ts
|
|
@@ -356,7 +379,8 @@ var walkerPieceSettingsSchema = external_exports.object({
|
|
|
356
379
|
module: external_exports.string().refine(
|
|
357
380
|
(text) => moduleFileForm({ text }) === "module-file" && isRepoPathText({ text }) === "repo-path",
|
|
358
381
|
"the module is not a path inside the piece folder ending .ts, or .js in a built install"
|
|
359
|
-
)
|
|
382
|
+
),
|
|
383
|
+
escapingDirectives: external_exports.array(external_exports.enum(TYPE_DIRECTIVES)).readonly().optional()
|
|
360
384
|
}).readonly();
|
|
361
385
|
|
|
362
386
|
// mechanisms/audit/runner/create-walker-runner.ts
|
|
@@ -366,7 +390,7 @@ var pieceInvalid3 = (request) => ({
|
|
|
366
390
|
error: { kind: "piece-invalid", pieceRoot: request.pieceRoot, detail: request.detail }
|
|
367
391
|
});
|
|
368
392
|
var thrownDetail2 = (request) => request.thrown instanceof Error ? request.thrown.message : String(request.thrown);
|
|
369
|
-
var
|
|
393
|
+
var settledClause = (request) => {
|
|
370
394
|
const settings = walkerPieceSettingsSchema.safeParse(request.clause.settings);
|
|
371
395
|
if (!settings.success) {
|
|
372
396
|
return pieceInvalid3({ pieceRoot: request.clause.pieceRoot, detail: settings.error.message });
|
|
@@ -375,22 +399,39 @@ var selectedClause = (request) => {
|
|
|
375
399
|
outcome: "ok",
|
|
376
400
|
value: [
|
|
377
401
|
{
|
|
378
|
-
|
|
379
|
-
|
|
402
|
+
selected: [
|
|
403
|
+
{
|
|
404
|
+
clause: request.clause,
|
|
405
|
+
modulePath: request.path.join({ segments: [request.clause.pieceRoot, settings.data.module] })
|
|
406
|
+
}
|
|
407
|
+
],
|
|
408
|
+
escapes: [{ clause: request.clause.address, directives: settings.data.escapingDirectives ?? [] }]
|
|
380
409
|
}
|
|
381
410
|
]
|
|
382
411
|
};
|
|
383
412
|
};
|
|
384
|
-
var
|
|
413
|
+
var settledClauses = (request) => {
|
|
414
|
+
const settled = gatheredOutcomes({ outcomes: request.clauses.map((clause) => settledClause({ clause, path: request.path })) });
|
|
415
|
+
if (settled.outcome === "failed") return settled;
|
|
416
|
+
return {
|
|
417
|
+
outcome: "ok",
|
|
418
|
+
value: {
|
|
419
|
+
selected: settled.value.flatMap((entry) => entry.selected),
|
|
420
|
+
escapes: settled.value.flatMap((entry) => entry.escapes).filter((directiveEscape) => directiveEscape.directives.length > 0)
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
};
|
|
385
424
|
var preparedPieces = (request) => {
|
|
386
|
-
const
|
|
387
|
-
if (
|
|
425
|
+
const settled = settledClauses({ clauses: request.clauses, path: request.ports.path });
|
|
426
|
+
if (settled.outcome === "failed") return Promise.resolve(settled);
|
|
388
427
|
return prepareWalkerPieces({
|
|
389
|
-
selected:
|
|
428
|
+
selected: settled.value.selected,
|
|
390
429
|
repository: request.repository,
|
|
391
430
|
syntaxApi: request.ports.parse.syntaxApi,
|
|
392
431
|
modules: request.ports.modules
|
|
393
|
-
})
|
|
432
|
+
}).then(
|
|
433
|
+
(pieces) => pieces.outcome === "failed" ? pieces : { outcome: "ok", value: { pieces: pieces.value, escapes: settled.value.escapes } }
|
|
434
|
+
);
|
|
394
435
|
};
|
|
395
436
|
var clauseRank = (request) => request.clauses.findIndex(
|
|
396
437
|
(clause) => sameClauseAddress({ left: clause.address, right: request.hit.clause }) === "same"
|
|
@@ -398,10 +439,23 @@ var clauseRank = (request) => request.clauses.findIndex(
|
|
|
398
439
|
var inSourceOrder = (request) => [...request.hits].sort(
|
|
399
440
|
(left, right) => left.anchor.line - right.anchor.line || left.anchor.column - right.anchor.column || clauseRank({ clauses: request.clauses, hit: left }) - clauseRank({ clauses: request.clauses, hit: right })
|
|
400
441
|
);
|
|
401
|
-
var
|
|
402
|
-
const observed = observeWalkerFile({
|
|
442
|
+
var observedReport = (request) => {
|
|
443
|
+
const observed = observeWalkerFile({
|
|
444
|
+
file: request.file,
|
|
445
|
+
pieces: request.prepared.pieces,
|
|
446
|
+
parse: request.ports.parse,
|
|
447
|
+
escapes: request.prepared.escapes
|
|
448
|
+
});
|
|
403
449
|
if (observed.outcome === "failed") return observed;
|
|
404
|
-
return {
|
|
450
|
+
return {
|
|
451
|
+
outcome: "ok",
|
|
452
|
+
value: [
|
|
453
|
+
{
|
|
454
|
+
hits: inSourceOrder({ clauses: request.clauses, hits: observed.value.hits }),
|
|
455
|
+
nativeExceptions: observed.value.nativeExceptions
|
|
456
|
+
}
|
|
457
|
+
]
|
|
458
|
+
};
|
|
405
459
|
};
|
|
406
460
|
var finishedPiece = (request) => {
|
|
407
461
|
const pieceRoot = request.piece.clauses[0]?.pieceRoot ?? request.piece.modulePath;
|
|
@@ -413,16 +467,24 @@ var finishedPiece = (request) => {
|
|
|
413
467
|
return pieceInvalid3({ pieceRoot, detail: thrownDetail2({ thrown }) });
|
|
414
468
|
}
|
|
415
469
|
};
|
|
416
|
-
var
|
|
470
|
+
var walkedReport = (request) => {
|
|
417
471
|
const observed = [];
|
|
418
472
|
request.files.some((file) => {
|
|
419
|
-
const
|
|
420
|
-
observed.push(
|
|
421
|
-
return
|
|
473
|
+
const fileReport = observedReport({ ...request, file });
|
|
474
|
+
observed.push(fileReport);
|
|
475
|
+
return fileReport.outcome === "failed";
|
|
422
476
|
});
|
|
423
477
|
const fromFiles = gatheredOutcomes({ outcomes: observed });
|
|
424
478
|
if (fromFiles.outcome === "failed") return fromFiles;
|
|
425
|
-
|
|
479
|
+
const finished = gatheredOutcomes({ outcomes: request.prepared.pieces.map((piece) => finishedPiece({ piece })) });
|
|
480
|
+
if (finished.outcome === "failed") return finished;
|
|
481
|
+
return {
|
|
482
|
+
outcome: "ok",
|
|
483
|
+
value: {
|
|
484
|
+
hits: [...fromFiles.value.flatMap((report) => report.hits), ...finished.value],
|
|
485
|
+
nativeExceptions: fromFiles.value.flatMap((report) => report.nativeExceptions)
|
|
486
|
+
}
|
|
487
|
+
};
|
|
426
488
|
};
|
|
427
489
|
var repositoryFile = (request) => ({
|
|
428
490
|
file: request.file,
|
|
@@ -443,11 +505,11 @@ var runOverRepository = (request) => {
|
|
|
443
505
|
path: request.ports.path.join({ segments: [request.run.repoRoot, file] })
|
|
444
506
|
})
|
|
445
507
|
};
|
|
446
|
-
return preparedPieces({ ports: request.ports, clauses: request.run.clauses, repository }).then((
|
|
447
|
-
if (
|
|
448
|
-
return
|
|
508
|
+
return preparedPieces({ ports: request.ports, clauses: request.run.clauses, repository }).then((prepared) => {
|
|
509
|
+
if (prepared.outcome === "failed") return prepared;
|
|
510
|
+
return walkedReport({
|
|
449
511
|
ports: request.ports,
|
|
450
|
-
|
|
512
|
+
prepared: prepared.value,
|
|
451
513
|
clauses: request.run.clauses,
|
|
452
514
|
files: request.run.trackedPaths.map(
|
|
453
515
|
(file) => repositoryFile({ ports: request.ports, repoRoot: request.run.repoRoot, file })
|
|
@@ -464,21 +526,21 @@ var caseVerdict = (request) => {
|
|
|
464
526
|
files: [request.sourceCase.fileName],
|
|
465
527
|
exists: ({ file }) => file === request.sourceCase.fileName ? "present" : "absent"
|
|
466
528
|
};
|
|
467
|
-
return preparedPieces({ ports: request.ports, clauses: [request.clause], repository }).then((
|
|
468
|
-
if (
|
|
469
|
-
const
|
|
529
|
+
return preparedPieces({ ports: request.ports, clauses: [request.clause], repository }).then((prepared) => {
|
|
530
|
+
if (prepared.outcome === "failed") return prepared;
|
|
531
|
+
const report = walkedReport({
|
|
470
532
|
ports: request.ports,
|
|
471
|
-
|
|
533
|
+
prepared: prepared.value,
|
|
472
534
|
clauses: [request.clause],
|
|
473
535
|
files: [caseFile(request)]
|
|
474
536
|
});
|
|
475
|
-
if (
|
|
537
|
+
if (report.outcome === "failed") return report;
|
|
476
538
|
return {
|
|
477
539
|
outcome: "ok",
|
|
478
540
|
value: [
|
|
479
541
|
{
|
|
480
542
|
caseName: request.sourceCase.name,
|
|
481
|
-
flaggedLines: [...new Set(
|
|
543
|
+
flaggedLines: [...new Set(report.value.hits.map((hit) => hit.anchor.line))]
|
|
482
544
|
}
|
|
483
545
|
]
|
|
484
546
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# CD-2 ESLint piece
|
|
2
|
+
|
|
3
|
+
This piece enforces CD-2's `non-null-assertions` clause through ESLint. It is one rule, `no-restricted-syntax`, in the plugin `cd2/cd2.eslint-plugin.ts` under the namespace `hone-cd2`. It reuses ESLint's `no-restricted-syntax` with two selectors carried as `options` in `piece.json`:
|
|
4
|
+
|
|
5
|
+
- `TSNonNullExpression` flags every non-null assertion, `x!`, the same node typescript-eslint's `no-non-null-assertion` reports.
|
|
6
|
+
- `[definite=true]` flags every definite assignment assertion, `let x!: T` and `field!: T`, which no typescript-eslint rule reports.
|
|
7
|
+
|
|
8
|
+
One rule carries both forms, so the clause has one rule id.
|
|
9
|
+
|
|
10
|
+
## Adopting the rule
|
|
11
|
+
|
|
12
|
+
The projection is the only supported way to adopt the rule. Run core's project command for your repository; it writes `disciplines.eslint.mjs` at the repository root, which enables every selected rule and carries your recorded exceptions. Spread its default export last in your flat config. Core's governance run checks that the projection's effect is in force, so enabling the rule some other way is not supported and fails the run as `not-included` once any exception is recorded for it.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultNativeRuleSources,
|
|
3
|
+
eslintCoreRules
|
|
4
|
+
} from "../../../../chunks/chunk-HJA4CX7C.js";
|
|
5
|
+
import "../../../../chunks/chunk-NZLE2WMY.js";
|
|
6
|
+
|
|
7
|
+
// mechanisms/eslint/CD-2/cd2/cd2.eslint-plugin.ts
|
|
8
|
+
var createPlugin = (sources) => ({
|
|
9
|
+
meta: { name: "hone-cd2", version: "0.0.0-local" },
|
|
10
|
+
rules: eslintCoreRules({ names: ["no-restricted-syntax"], sources })
|
|
11
|
+
});
|
|
12
|
+
var cd2_eslint_plugin_default = createPlugin(defaultNativeRuleSources);
|
|
13
|
+
export {
|
|
14
|
+
createPlugin,
|
|
15
|
+
cd2_eslint_plugin_default as default
|
|
16
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"discipline": "CD-2",
|
|
4
|
+
"mechanism": "eslint",
|
|
5
|
+
"clauses": [
|
|
6
|
+
{
|
|
7
|
+
"clause": "non-null-assertions",
|
|
8
|
+
"settings": {
|
|
9
|
+
"pluginNamespace": "hone-cd2",
|
|
10
|
+
"pluginModule": "cd2/cd2.eslint-plugin.js",
|
|
11
|
+
"rule": "no-restricted-syntax",
|
|
12
|
+
"options": [
|
|
13
|
+
{
|
|
14
|
+
"selector": "TSNonNullExpression",
|
|
15
|
+
"message": "CD-2: a non-null assertion claims a value the compiler cannot see; narrow it with a check instead."
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"selector": "[definite=true]",
|
|
19
|
+
"message": "CD-2: a definite assignment assertion claims an assignment the compiler cannot see; initialise the binding instead."
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
# ESLint runner
|
|
2
2
|
|
|
3
|
-
The ESLint runner is Hone's embedded mechanism: each selected clause runs as an ESLint rule inside the team's own ESLint setup. Its `exceptionPath` is `embedded`. Core hands it the selected clauses, the files to check, the repository's tracked paths and the exception records for this mechanism. The runner lints the files with its own configuration to find hits, reports every native channel in the team's setup that weakens a selected rule, and writes and checks the projection `disciplines.eslint.mjs
|
|
3
|
+
The ESLint runner is Hone's embedded mechanism: each selected clause runs as an ESLint rule inside the team's own ESLint setup. Its `exceptionPath` is `embedded`. Core hands it the selected clauses, the files to check, the repository's tracked paths and the exception records for this mechanism. The runner lints the files with its own configuration to find hits, reports every native channel in the team's setup that weakens a selected rule, and writes and checks the projection `disciplines.eslint.mjs`, one slice per config root, that carries the records into the team's own run. Its `projectedKinds` is `["config-override", "inline-disable"]`, so a record can cover only those kinds, and an `inline-disable` only by a file record on its clause and file.
|
|
4
4
|
|
|
5
5
|
The native channels, the exception kind each maps to, and how the projection is adopted and checked are in [the guide](../../../docs/adding-a-discipline-or-mechanism.md#embedded-mechanisms).
|
|
6
6
|
|
|
7
|
-
The check compares the committed projection byte for byte with what the runner would write now. Built core is the installed package: the runner reads the package's `package.json` for its name, and the projection imports each piece inside it by package name, `<name>/mechanisms/eslint/...`, which resolves wherever the package is installed. A `package.json` that cannot be read or names no package is a `tool-failed` failure. Core run from source, as in its own tests, imports each piece by its path relative to the
|
|
7
|
+
The check compares the committed projection byte for byte with what the runner would write now. Built core is the installed package: the runner reads the package's `package.json` for its name, and the projection imports each piece inside it by package name, `<name>/mechanisms/eslint/...`, which resolves wherever the package is installed. A `package.json` that cannot be read or names no package is a `tool-failed` failure. Core run from source, as in its own tests, imports each piece by its path relative to the folder the slice is written in. A piece outside the install, in the repository's own rule set, is always imported by relative path, and a piece on another drive from a slice's folder fails as `piece-invalid`.
|
|
8
|
+
|
|
9
|
+
The config roots are the repository root, every folder holding a tracked `eslint.config.*` when the team's lookup is nearest-to-file, and every folder core passes as a declared config root, less any folder at or under a folder with a tracked `disciplines.json`, because nested Hone configurations are not supported yet ([#72](https://github.com/HailsTails/hone/issues/72)). Under the nearest-to-file lookup, when the projection is not in effect, `run` names each outermost such folder holding files under check whose own config leaves a record of this repository out of effect, or the selected rule off, as a `nested-configuration` slice; core names the folder on the `mechanism-not-run` entry it explains, not as a projection problem. Core reads and validates `eslintConfigRoots` from `disciplines.json` and passes the folders in the request as `declaredConfigRoots`; the runner never reads them itself. Each root's slice is `disciplines.eslint.mjs` in that folder. The root slice holds every record; a package slice holds the records for files under its folder, re-pathed relative to it and glob-escaped as in the root, and every clause-wide carve-out. A file belongs to the deepest root containing it. `project` writes every slice, then, for each tracked `disciplines.eslint.mjs` in a folder that is no longer a root, regenerates the slice that folder would get and removes the file only when its bytes match that text, so it never deletes a file it did not write; otherwise it reports `left-in-place`. `project` renders and reads every slice and orphan before it writes or removes anything, so a failure part-way changes nothing. `run` reports each package slice that is `missing` or `out-of-date`, each declared root with no `eslint.config.*` on disk as `unconfigured`, and, under the nearest-to-file lookup when the projection is not in effect, each package root whose own recorded files under check are not excepted as `not-applied`, grouping the checked files by their governing root once. Every config root gets and keeps its slice whatever a config above it ignores: a lint run from that folder loads its own config and never reads the ignores of the configs above it, so `project` writes the same slices from the same inputs every time. `not-applied` judges each recorded file through the same per-file query as every other judgement, which resolves the file from its nearest config, the one a lint run from its package loads. A root-only repository's projection is unchanged.
|
|
8
10
|
|
|
9
11
|
## Runtime
|
|
10
12
|
|
|
11
13
|
- From source, Node 22.18.0 or later, which runs the `.ts` modules directly by stripping types. The built package is plain JavaScript.
|
|
12
14
|
- `zod`, for the piece settings, the loaded plugin, ESLint's resolved configuration and the files the runner reads. A dependency of core.
|
|
13
15
|
- `@eslint/plugin-kit`, for parsing inline configuration comments. A dependency of core, pinned at 0.7.3, because a transitive copy does not resolve under strict package managers.
|
|
14
|
-
- The repository's own toolchain, as optional peers: `eslint` `^9.28.0 || ^10.0.0`, and `@typescript-eslint/parser` and `@typescript-eslint/eslint-plugin` `^8.56.0`, the first typescript-eslint release whose peer range accepts both ESLint majors. TypeScript is the parser's own peer, so the runner does not check it. The runner loads
|
|
16
|
+
- The repository's own toolchain, as optional peers: `eslint` `^9.28.0 || ^10.0.0`, and `@typescript-eslint/parser` and `@typescript-eslint/eslint-plugin` `^8.56.0`, the first typescript-eslint release whose peer range accepts both ESLint majors. TypeScript is the parser's own peer, so the runner does not check it. The runner loads all three once, when it is loaded, and answers every call with `toolchain-unavailable` naming each that is missing, cannot load or is out of range, or with `toolchain-shadowed` when one resolves from inside the installed core package, before it loads any piece. The suite runs on four lines: ESLint 9.28.0 and 10.0.0 with typescript-eslint 8.56.0, and ESLint 9.39.5 and 10.11.0 with 8.71.2.
|
|
15
17
|
|
|
16
18
|
## Files
|
|
17
19
|
|
|
18
|
-
- `create-eslint-runner.ts` builds the runner from its ports: file text, module loading, paths and ESLint. It implements `run`, `conform` and `project`.
|
|
20
|
+
- `create-eslint-runner.ts` builds the runner from its ports: file text, file removal, module loading, paths and ESLint. It implements `run`, `conform` and `project`.
|
|
19
21
|
- `eslint-toolchain.ts` loads the toolchain for core's own ESLint run by dynamic imports of `eslint`, `@typescript-eslint/parser` and `@typescript-eslint/eslint-plugin`, so a missing one becomes a named failure. It first asks where each resolves and fails as `toolchain-shadowed` for a copy inside the installed core package, then checks each version against its range, and hands the loaded `ESLint` class to `eslint-instance.ts`, which builds `createEslint` for that version. Core passes only options every supported release accepts: on ESLint 9 it asks for the nearest-to-file configuration lookup with the flag that release names, `unstable_config_lookup_from_file` before 9.30.0 and `v10_config_lookup_from_file` from 9.30.0, and ESLint 10 looks up that way by default. It never passes `applySuppressions`, which ESLint 9 and 10.0.0 refuse and which 10.11.0 accepts with a default of off.
|
|
20
22
|
- `eslint-instance.ts` is the port over a loaded toolchain, and takes only types from `eslint` and `@typescript-eslint/parser`. It builds `createEslint` on the loaded `ESLint` class and maps ESLint's results into the runner's own types. It builds a query instance on the team's own configuration, a governance instance on the runner's configuration only, and `lintSourceCases` for conformance. It also defines the reserved rule `<reservedNamespace>/inline-config`. `reservedNamespace` is the `reservedEslintNamespace` field of `core/values/tool-identity.ts`, currently `hone-core`, Hone's own namespace, distinct from every piece's `hone` and `hone-cd<N>` and independent of the package name; the reserved rule, the governance configuration and the projection's block names all take it from there.
|
|
23
|
+
- `governing-config.ts` decides, when a nested `eslint.config.*` fails to load, whether the team's own ESLint would ever enter its folder. It asks the config governing that folder, then each config above it up to the repository root, whether it ignores that folder and then the file. `governingConfigIgnores` answers one such question, for a file or a folder, telling a real ignore from a path no `files` block matches; `cachedGoverningIgnores` asks each config about each path once, only when first needed.
|
|
21
24
|
- `inline-config-parser.ts` is the wrapping factory for `@eslint/plugin-kit`, the only file that imports it.
|
|
22
25
|
- `native-rules.ts` re-exports the ESLint core rules (`eslintCoreRules`) and the typescript-eslint rules (`typescriptEslintRules`) that pieces reuse. It is the only file that imports them, and it imports `eslint/use-at-your-own-risk` and `@typescript-eslint/eslint-plugin` statically, resolved upward from the install like the toolchain.
|
|
23
|
-
- `projection.ts`
|
|
26
|
+
- `projection.ts` renders a projection's text, and writes and compares one projection file.
|
|
27
|
+
- `projection-slices.ts` finds the config roots for a lookup, names each root's slice, picks and re-paths each slice's records, finds the package root governing a file, and finds tracked slices outside every root.
|
|
28
|
+
- `sliced-projection.ts` renders each root's slice, reports stale package slices, and plans then writes, removes or leaves slices for `project`.
|
|
29
|
+
- `config-lookup.ts` reads `eslintConfigLookup` from `disciplines.json`, and decides which config the team's ESLint run applies.
|
|
24
30
|
- `package-script-scanner.ts` finds ESLint invocations in tracked `package.json` scripts, and the options and `--suppressions-location` values they carry.
|
|
31
|
+
- `script-option-effect.ts` judges whether a `-c`, `--config` or `--ignore-pattern` option changes what ESLint does to the checked files under its script's folder. Only one that the folder settles as changing nothing is not reported. An invocation settles only when it is plain: the first command of its script, with nothing before `eslint` but a package runner, `NAME=value` assignments, or `cross-env` followed only by `NAME=value` assignments, and no token after it that the shell expands or that reaches outside the folder. Anything else is reported.
|
|
25
32
|
- `suppressions-scanner.ts` reads suppression entries from `eslint-suppressions.json` files and from files named by `--suppressions-location`.
|
|
26
33
|
- `eslint-piece-settings-schema.ts`, `eslint-plugin-schema.ts`, `eslint-config-schema.ts` and `eslint-file-schemas.ts` hold the schemas for a piece's settings, a loaded plugin module, ESLint's resolved configuration, and `package.json` and suppressions files.
|
|
27
34
|
- `runner.ts` is the runner core loads: the default ports, bound to the toolchain loaded from the install's own resolution.
|