@hailstails/hone 0.1.0-pre.2 → 0.1.0-pre.4
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 +17 -17
- package/MIGRATING.md +1 -1
- package/README.md +66 -17
- package/api/audit.d.ts +10 -0
- package/api/audit.js +1 -0
- package/api/rule-set.d.ts +6 -0
- package/api/rule-set.js +1 -0
- package/chunks/{chunk-TRCB27ET.js → chunk-BX6QHLSZ.js} +1 -13
- package/chunks/{chunk-233U4FBA.js → chunk-EYCRDEXX.js} +13 -2
- package/chunks/{chunk-7ZJZZBSS.js → chunk-FOAGAYXM.js} +73 -13
- package/chunks/{chunk-HBY4ZWSP.js → chunk-RZA3OVOO.js} +3 -11
- package/core/check/tool-command.js +74 -42
- package/core/mechanism-port/runner-failure-types.d.ts +38 -0
- package/core/mechanism-port/runner-module-types.d.ts +8 -0
- package/core/mechanism-port/runner-result-types.d.ts +9 -0
- package/core/rule-set-reader/rule-set-types.d.ts +41 -0
- package/core/values/anchor.d.ts +10 -0
- package/core/values/branded.d.ts +5 -0
- package/core/values/clause-address-types.d.ts +9 -0
- package/core/values/identifier-types.d.ts +5 -0
- package/core/values/json-value.d.ts +3 -0
- package/core/values/repo-path-types.d.ts +2 -0
- package/core/values/result.d.ts +7 -0
- package/docs/adding-a-discipline-or-mechanism.md +2 -2
- package/mechanisms/audit/CD-19/import-boundaries.js +14 -6
- package/mechanisms/audit/runner/runner.js +33 -31
- package/mechanisms/audit/runner/typescript-parse.d.ts +20 -0
- package/mechanisms/audit/runner/walker-piece.d.ts +60 -0
- package/mechanisms/eslint/runner/eslint-piece-settings-types.d.ts +8 -0
- package/mechanisms/eslint/runner/runner.js +58 -42
- package/package.json +19 -2
|
@@ -3,12 +3,9 @@ import {
|
|
|
3
3
|
hitSchema,
|
|
4
4
|
nativeExceptionKindSchema,
|
|
5
5
|
projectionWriteSchema,
|
|
6
|
-
rejectedCall,
|
|
7
|
-
runnerInvalidOutput,
|
|
8
6
|
runnerResultSchema
|
|
9
|
-
} from "../../chunks/chunk-
|
|
7
|
+
} from "../../chunks/chunk-RZA3OVOO.js";
|
|
10
8
|
import {
|
|
11
|
-
TOOL_IDENTITY,
|
|
12
9
|
disciplineFilePath,
|
|
13
10
|
eslintConfigLookupSchema,
|
|
14
11
|
parsedJson,
|
|
@@ -16,9 +13,12 @@ import {
|
|
|
16
13
|
readDisciplineFile,
|
|
17
14
|
readPieceFile,
|
|
18
15
|
readVersionOneJson
|
|
19
|
-
} from "../../chunks/chunk-
|
|
16
|
+
} from "../../chunks/chunk-BX6QHLSZ.js";
|
|
20
17
|
import {
|
|
21
18
|
NOT_INSTALLED,
|
|
19
|
+
TOOL_IDENTITY,
|
|
20
|
+
TOOL_RULE_SET,
|
|
21
|
+
brandedRepoPathSchema,
|
|
22
22
|
clauseAddressObjectSchema,
|
|
23
23
|
clauseAddressSchema,
|
|
24
24
|
clauseAddressText,
|
|
@@ -30,10 +30,11 @@ import {
|
|
|
30
30
|
mechanismIdSchema,
|
|
31
31
|
moduleExtensionOf,
|
|
32
32
|
repoPathSchema,
|
|
33
|
+
repoPathTextSchema,
|
|
33
34
|
ruleSetNameSchema,
|
|
34
35
|
runnerModuleSegmentsOf,
|
|
35
36
|
sameClauseAddress
|
|
36
|
-
} from "../../chunks/chunk-
|
|
37
|
+
} from "../../chunks/chunk-FOAGAYXM.js";
|
|
37
38
|
import "../../chunks/chunk-NZLE2WMY.js";
|
|
38
39
|
|
|
39
40
|
// core/platform-ports/execution-port.ts
|
|
@@ -179,19 +180,14 @@ var GIT_EXECUTION_POLICY = {
|
|
|
179
180
|
timeoutMilliseconds: void 0,
|
|
180
181
|
maximumOutputBytes: LARGEST_GIT_OUTPUT_BYTES
|
|
181
182
|
};
|
|
182
|
-
var parsedRepoPaths = (request) =>
|
|
183
|
-
(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
return { outcome: "ok", value: [...parsedSoFar.value, parsed.data] };
|
|
192
|
-
},
|
|
193
|
-
{ outcome: "ok", value: [] }
|
|
194
|
-
);
|
|
183
|
+
var parsedRepoPaths = (request) => {
|
|
184
|
+
const parsed = request.listed.map((text) => ({ text, result: repoPathSchema.safeParse(text) }));
|
|
185
|
+
const refused = parsed.find((entry) => !entry.result.success);
|
|
186
|
+
if (refused !== void 0) {
|
|
187
|
+
return { outcome: "failed", error: refused.text };
|
|
188
|
+
}
|
|
189
|
+
return { outcome: "ok", value: parsed.flatMap((entry) => entry.result.success ? [entry.result.data] : []) };
|
|
190
|
+
};
|
|
195
191
|
var gitOutput = (request) => {
|
|
196
192
|
const fullArguments = ["-C", request.repoRoot, ...request.gitArguments];
|
|
197
193
|
const command = `git ${fullArguments.join(" ")}`;
|
|
@@ -329,22 +325,20 @@ var createGitPort = (options) => {
|
|
|
329
325
|
textInBase: (request) => fileTextInBase({ ...request, spawn: options.spawn, environment })
|
|
330
326
|
};
|
|
331
327
|
};
|
|
332
|
-
var
|
|
328
|
+
var defaultGitSpawn = (_options) => {
|
|
333
329
|
const execution = createDefaultExecutionPort({ policy: GIT_EXECUTION_POLICY });
|
|
334
|
-
return
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
},
|
|
345
|
-
ambientEnvironment: {}
|
|
346
|
-
});
|
|
330
|
+
return (request) => {
|
|
331
|
+
const executed = execution.run({ arguments: request.arguments });
|
|
332
|
+
if (executed.outcome === "failed") {
|
|
333
|
+
return {
|
|
334
|
+
outcome: "errored",
|
|
335
|
+
detail: executed.error.kind === "terminated" ? `git was ended by signal ${executed.error.signal}` : executed.error.detail
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
return { outcome: "exited", ...executed.value };
|
|
339
|
+
};
|
|
347
340
|
};
|
|
341
|
+
var createDefaultGitPort = (_options) => createGitPort({ spawn: defaultGitSpawn({}), ambientEnvironment: {} });
|
|
348
342
|
|
|
349
343
|
// core/platform-ports/process-port.ts
|
|
350
344
|
var ARGUMENTS_BEFORE_SCRIPT_ARGUMENTS = 2;
|
|
@@ -1326,6 +1320,10 @@ var loadFailureFields = (request) => {
|
|
|
1326
1320
|
case "reserved-rule-set-name":
|
|
1327
1321
|
case "unknown-rule-set":
|
|
1328
1322
|
return [request.failure.name];
|
|
1323
|
+
case "duplicate-clause":
|
|
1324
|
+
return [request.failure.address, request.failure.prefixedAddress];
|
|
1325
|
+
case "rule-set-name-collision":
|
|
1326
|
+
return [request.failure.name, request.failure.other];
|
|
1329
1327
|
case "unknown-discipline":
|
|
1330
1328
|
case "unknown-clause":
|
|
1331
1329
|
case "judgement-clause-selected":
|
|
@@ -1370,7 +1368,8 @@ var projectCommandOutcome = (request) => {
|
|
|
1370
1368
|
var fileExceptionWhyChainsSchema = external_exports.enum(["required", "optional"]);
|
|
1371
1369
|
|
|
1372
1370
|
// core/consumer-selection/consumer-selection.ts
|
|
1373
|
-
var
|
|
1371
|
+
var RULE_SET_SUFFIX_SEPARATOR = "-";
|
|
1372
|
+
var CLAUSE_ADDRESS_RULE_SET_SEPARATOR = "/";
|
|
1374
1373
|
var LEADING_CURRENT_DIRECTORY = "./";
|
|
1375
1374
|
var ruleSetLocationSchema = external_exports.union([
|
|
1376
1375
|
external_exports.enum([".", LEADING_CURRENT_DIRECTORY]).transform(() => ({ location: "repo-root" })),
|
|
@@ -1383,8 +1382,10 @@ var consumerSelectionFileSchema = external_exports.strictObject({
|
|
|
1383
1382
|
ruleSets: external_exports.record(ruleSetNameSchema, external_exports.string()).transform((ruleSets) => Object.entries(ruleSets)).pipe(external_exports.array(external_exports.tuple([ruleSetNameSchema, ruleSetLocationSchema]))),
|
|
1384
1383
|
clauses: external_exports.record(external_exports.string(), external_exports.string()).transform((clauses) => Object.entries(clauses)).pipe(external_exports.array(external_exports.tuple([clauseAddressSchema, mechanismIdSchema]))),
|
|
1385
1384
|
exclude: external_exports.array(
|
|
1386
|
-
|
|
1387
|
-
|
|
1385
|
+
brandedRepoPathSchema({
|
|
1386
|
+
text: repoPathTextSchema.refine((excludedPath) => !excludedPath.includes("*"), {
|
|
1387
|
+
error: "an exclude entry is a repository path, not a glob"
|
|
1388
|
+
})
|
|
1388
1389
|
})
|
|
1389
1390
|
).default([]),
|
|
1390
1391
|
eslintConfigLookup: eslintConfigLookupSchema.optional(),
|
|
@@ -1397,7 +1398,7 @@ var failed = (error) => ({
|
|
|
1397
1398
|
});
|
|
1398
1399
|
var ruleSetRootOf = (request) => {
|
|
1399
1400
|
const ruleSet = request.ruleSet;
|
|
1400
|
-
if (ruleSet ===
|
|
1401
|
+
if (ruleSet === TOOL_RULE_SET) {
|
|
1401
1402
|
return { outcome: "ok", value: request.installRoot };
|
|
1402
1403
|
}
|
|
1403
1404
|
const declared = Object.entries(request.ruleSets).find(([name]) => name === ruleSet.name);
|
|
@@ -1568,12 +1569,34 @@ var parsedSelectionFile = (request) => {
|
|
|
1568
1569
|
if (!parsed.success) {
|
|
1569
1570
|
return failed({ kind: "file-malformed", path: request.path, detail: external_exports.prettifyError(parsed.error) });
|
|
1570
1571
|
}
|
|
1571
|
-
const
|
|
1572
|
-
|
|
1573
|
-
|
|
1572
|
+
const refusal = selectionFileRefusalOf({ file: parsed.data });
|
|
1573
|
+
return refusal === void 0 ? { outcome: "ok", value: parsed.data } : failed(refusal);
|
|
1574
|
+
};
|
|
1575
|
+
var reservedRuleSetNameRefusalOf = (request) => {
|
|
1576
|
+
const reserved = request.file.ruleSets.find(
|
|
1577
|
+
([name]) => name === TOOL_RULE_SET || name.startsWith(`${TOOL_RULE_SET}${RULE_SET_SUFFIX_SEPARATOR}`)
|
|
1578
|
+
);
|
|
1579
|
+
return reserved === void 0 ? void 0 : { kind: "reserved-rule-set-name", name: reserved[0] };
|
|
1580
|
+
};
|
|
1581
|
+
var ruleSetNameCollisionRefusalOf = (request) => {
|
|
1582
|
+
const names = request.file.ruleSets.map(([name]) => name);
|
|
1583
|
+
const collisions = names.flatMap(
|
|
1584
|
+
(name) => names.filter((candidate) => candidate.startsWith(`${name}${RULE_SET_SUFFIX_SEPARATOR}`)).map((other) => ({ kind: "rule-set-name-collision", name, other }))
|
|
1585
|
+
);
|
|
1586
|
+
return collisions[0];
|
|
1587
|
+
};
|
|
1588
|
+
var duplicateClauseRefusalOf = (request) => {
|
|
1589
|
+
const addresses = request.file.clauses.map(([address2]) => address2);
|
|
1590
|
+
const repeated = addresses.find(
|
|
1591
|
+
(address2, index) => addresses.slice(0, index).some((earlier) => sameClauseAddress({ left: earlier, right: address2 }) === "same")
|
|
1592
|
+
);
|
|
1593
|
+
if (repeated === void 0) {
|
|
1594
|
+
return void 0;
|
|
1574
1595
|
}
|
|
1575
|
-
|
|
1596
|
+
const address = clauseAddressText({ address: repeated });
|
|
1597
|
+
return { kind: "duplicate-clause", address, prefixedAddress: `${TOOL_RULE_SET}${CLAUSE_ADDRESS_RULE_SET_SEPARATOR}${address}` };
|
|
1576
1598
|
};
|
|
1599
|
+
var selectionFileRefusalOf = (request) => reservedRuleSetNameRefusalOf(request) ?? ruleSetNameCollisionRefusalOf(request) ?? duplicateClauseRefusalOf(request);
|
|
1577
1600
|
var selectionReadingOf = (request) => ({
|
|
1578
1601
|
selection: {
|
|
1579
1602
|
selected: request.resolved.map(({ binding, exceptions }) => ({
|
|
@@ -1814,6 +1837,14 @@ var embeddedRunReportSchema = external_exports.object({
|
|
|
1814
1837
|
projection: external_exports.enum(["current", "out-of-date", "missing", "not-included"])
|
|
1815
1838
|
}).readonly();
|
|
1816
1839
|
|
|
1840
|
+
// core/mechanism-port/runner-failure.ts
|
|
1841
|
+
var runnerInvalidOutput = (request) => ({
|
|
1842
|
+
outcome: "failed",
|
|
1843
|
+
error: { kind: "runner-invalid-output", detail: request.detail }
|
|
1844
|
+
});
|
|
1845
|
+
var thrownMessage = (request) => request.thrown instanceof Error ? request.thrown.message : String(request.thrown);
|
|
1846
|
+
var rejectedCall = (request) => runnerInvalidOutput({ detail: `the runner call threw or rejected: ${thrownMessage(request)}` });
|
|
1847
|
+
|
|
1817
1848
|
// core/check/mechanism-dispatch.ts
|
|
1818
1849
|
var hitsResultSchema = runnerResultSchema({ value: external_exports.array(hitSchema).readonly() });
|
|
1819
1850
|
var unrequestedHit = (request) => request.hits.find(
|
|
@@ -2028,6 +2059,7 @@ var loadInputs = async (request) => {
|
|
|
2028
2059
|
};
|
|
2029
2060
|
var recordsOf = (request) => request.records.filter((record) => record.mechanism === request.mechanism);
|
|
2030
2061
|
var forfeitureUnmeasured = (request) => request.touched.measured === "no" && request.records.some((record) => record.kind === "file-carve-out") ? [{ kind: "forfeiture-unmeasured" }] : [];
|
|
2062
|
+
var touchedSetFor = (request) => request.records.some((record) => record.kind === "file-carve-out") ? computeTouchedSet(request.check) : { measured: "yes", paths: /* @__PURE__ */ new Set() };
|
|
2031
2063
|
var importedRecords = (request) => request.records.some((record) => recordImportOf({ record }).imported === "yes") ? "present" : "absent";
|
|
2032
2064
|
var legacyChainRecords = (request) => request.records.some((record) => whyChainFormOf({ chain: record.whyChain }) === "legacy") ? "present" : "absent";
|
|
2033
2065
|
var legacyChainUnmeasured = (request) => request.exceptionBaseline.measured === "no" && legacyChainRecords({ records: request.records }) === "present" ? [{ kind: "legacy-chain-unmeasured" }] : [];
|
|
@@ -2165,7 +2197,7 @@ var runCheck = async (request) => {
|
|
|
2165
2197
|
value: checkReportOf({
|
|
2166
2198
|
inputs: inputs.value,
|
|
2167
2199
|
runs: runs.value,
|
|
2168
|
-
touched:
|
|
2200
|
+
touched: touchedSetFor({ check: request, records: inputs.value.records })
|
|
2169
2201
|
})
|
|
2170
2202
|
};
|
|
2171
2203
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { RepoPath } from "../values/repo-path-types.js";
|
|
2
|
+
export type PeerKind = "required" | "optional";
|
|
3
|
+
export type RunnerFailure = {
|
|
4
|
+
readonly kind: "piece-invalid";
|
|
5
|
+
readonly pieceRoot: string;
|
|
6
|
+
readonly detail: string;
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: "tool-failed";
|
|
9
|
+
readonly detail: string;
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: "file-unreadable";
|
|
12
|
+
readonly file: RepoPath;
|
|
13
|
+
readonly detail: string;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: "plugin-conflict";
|
|
16
|
+
readonly detail: string;
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: "team-config-unloadable";
|
|
19
|
+
readonly detail: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: "runner-invalid-output";
|
|
22
|
+
readonly detail: string;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: "file-unparseable";
|
|
25
|
+
readonly file: RepoPath;
|
|
26
|
+
readonly detail: string;
|
|
27
|
+
} | {
|
|
28
|
+
readonly kind: "toolchain-unavailable";
|
|
29
|
+
readonly packageName: string;
|
|
30
|
+
readonly peer: PeerKind;
|
|
31
|
+
readonly supported: string;
|
|
32
|
+
readonly found: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly kind: "toolchain-shadowed";
|
|
35
|
+
readonly packageName: string;
|
|
36
|
+
readonly location: string;
|
|
37
|
+
readonly installRoot: string;
|
|
38
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AnchorKind } from "../values/anchor.js";
|
|
2
|
+
import type { ClauseAddress } from "../values/clause-address-types.js";
|
|
3
|
+
export type RunnerClause = {
|
|
4
|
+
readonly address: ClauseAddress;
|
|
5
|
+
readonly anchor: AnchorKind;
|
|
6
|
+
readonly pieceRoot: string;
|
|
7
|
+
readonly settings: unknown;
|
|
8
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Anchor } from "../values/anchor.js";
|
|
2
|
+
import type { ClauseAddress } from "../values/clause-address-types.js";
|
|
3
|
+
import type { RepoPath } from "../values/repo-path-types.js";
|
|
4
|
+
export type Hit = {
|
|
5
|
+
readonly clause: ClauseAddress;
|
|
6
|
+
readonly file: RepoPath;
|
|
7
|
+
readonly anchor: Anchor;
|
|
8
|
+
readonly snippet: string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AnchorKind } from "../values/anchor.js";
|
|
2
|
+
import type { ClauseId, DisciplineId, MechanismId } from "../values/identifier-types.js";
|
|
3
|
+
import type { RepoPath } from "../values/repo-path-types.js";
|
|
4
|
+
export type SourceCase = {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly fileName: RepoPath;
|
|
7
|
+
readonly source: string;
|
|
8
|
+
readonly expectedLines: readonly number[];
|
|
9
|
+
};
|
|
10
|
+
export type ClauseExceptions = "allowed" | "refused";
|
|
11
|
+
export type ClauseDefinition = {
|
|
12
|
+
readonly kind: "mechanical";
|
|
13
|
+
readonly id: ClauseId;
|
|
14
|
+
readonly summary: string;
|
|
15
|
+
readonly mechanisms: readonly MechanismId[];
|
|
16
|
+
readonly anchor: AnchorKind;
|
|
17
|
+
readonly exceptions: ClauseExceptions;
|
|
18
|
+
readonly cases: {
|
|
19
|
+
readonly flag: readonly SourceCase[];
|
|
20
|
+
readonly allow: readonly SourceCase[];
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: "judgement";
|
|
24
|
+
readonly id: ClauseId;
|
|
25
|
+
readonly summary: string;
|
|
26
|
+
readonly enforcedBy: "review";
|
|
27
|
+
};
|
|
28
|
+
export type DisciplineFile = {
|
|
29
|
+
readonly version: 1;
|
|
30
|
+
readonly id: DisciplineId;
|
|
31
|
+
readonly clauses: readonly ClauseDefinition[];
|
|
32
|
+
};
|
|
33
|
+
export type PieceFile = {
|
|
34
|
+
readonly version: 1;
|
|
35
|
+
readonly discipline: DisciplineId;
|
|
36
|
+
readonly mechanism: MechanismId;
|
|
37
|
+
readonly clauses: readonly {
|
|
38
|
+
readonly clause: ClauseId;
|
|
39
|
+
readonly settings: unknown;
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ClauseId, DisciplineId, RuleSetName } from "./identifier-types.js";
|
|
2
|
+
export type ToolRuleSet = "hone";
|
|
3
|
+
export type ClauseAddress = {
|
|
4
|
+
readonly ruleSet: ToolRuleSet | {
|
|
5
|
+
readonly name: RuleSetName;
|
|
6
|
+
};
|
|
7
|
+
readonly discipline: DisciplineId;
|
|
8
|
+
readonly clause: ClauseId;
|
|
9
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Branded } from "./branded.js";
|
|
2
|
+
export type RuleSetName = Branded<string, "RuleSetName">;
|
|
3
|
+
export type DisciplineId = Branded<string, "DisciplineId">;
|
|
4
|
+
export type ClauseId = Branded<string, "ClauseId">;
|
|
5
|
+
export type MechanismId = Branded<string, "MechanismId">;
|
|
@@ -7,7 +7,7 @@ Terms used below:
|
|
|
7
7
|
- A **discipline** is a rule a repository can adopt, with an id such as `CD-14`, made of one or more **clauses**.
|
|
8
8
|
- A **mechanism** is a tool that checks clauses, such as the TypeScript `audit` or `eslint`. Each mechanism has one **runner**.
|
|
9
9
|
- A **piece** is one discipline's code for one mechanism, written in that mechanism's own extension format.
|
|
10
|
-
- A **rule set** is a directory holding `rules/` and `mechanisms/` folders. The rule set shipped with
|
|
10
|
+
- A **rule set** is a directory holding `rules/` and `mechanisms/` folders. The rule set shipped with the tool is `hone`, which a bare address also names, so no rule-set name may be `hone` or start with `hone-`, and no declared name may be another declared name plus `-<suffix>`; a repository can add its own and name them in `disciplines.json`.
|
|
11
11
|
- A **native channel** is a way the tool itself lets a team exempt or weaken a rule, outside core's exception records.
|
|
12
12
|
|
|
13
13
|
## Adding a discipline
|
|
@@ -53,7 +53,7 @@ For each mechanism in a clause's `mechanisms` list, add a piece folder `mechanis
|
|
|
53
53
|
`discipline` and `mechanism` must match the folder names, every `clause` must exist in the discipline, and no clause may appear twice. Core reads only this envelope. `settings` belongs to the runner, which parses it with its own schema:
|
|
54
54
|
|
|
55
55
|
- **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
|
-
- **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
|
|
56
|
+
- **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
57
|
|
|
58
58
|
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
59
|
|
|
@@ -26,6 +26,16 @@ var BANNED_THIRD_PARTY_IMPORTS = [
|
|
|
26
26
|
"zod-to-json-schema",
|
|
27
27
|
"uuid"
|
|
28
28
|
];
|
|
29
|
+
var escapedSpecifier = (request) => request.specifier.replace(/[/.]/g, "\\$&");
|
|
30
|
+
var bannedImportPattern = (request) => new RegExp(`from\\s+["'](?:${request.specifiers.map((specifier) => escapedSpecifier({ specifier })).join("|")})["']`);
|
|
31
|
+
var BANNED_IMPORT_ANYWHERE = bannedImportPattern({ specifiers: BANNED_THIRD_PARTY_IMPORTS });
|
|
32
|
+
var BANNED_IMPORT_PATTERNS = BANNED_THIRD_PARTY_IMPORTS.map((specifier) => ({ specifier, pattern: bannedImportPattern({ specifiers: [specifier] }) }));
|
|
33
|
+
var bannedImportsIn = (request) => {
|
|
34
|
+
if (!BANNED_IMPORT_ANYWHERE.test(request.text)) return [];
|
|
35
|
+
return request.text.split("\n").flatMap(
|
|
36
|
+
(text, index) => BANNED_IMPORT_PATTERNS.filter(({ pattern }) => pattern.test(text)).map(({ specifier }) => ({ line: index + 1, specifier }))
|
|
37
|
+
);
|
|
38
|
+
};
|
|
29
39
|
var check = {
|
|
30
40
|
prepare: ({ clauses, syntaxApi }) => ({
|
|
31
41
|
outcome: "ok",
|
|
@@ -37,14 +47,12 @@ var check = {
|
|
|
37
47
|
value: {
|
|
38
48
|
kind: "syntax",
|
|
39
49
|
begin: ({ sourceFile, anchorAt }) => {
|
|
40
|
-
const rawHits = sourceFile.text
|
|
41
|
-
(line,
|
|
42
|
-
(specifier) => new RegExp(`from\\s+["']${specifier.replace(/[/.]/g, "\\$&")}["']`).test(line)
|
|
43
|
-
).flatMap((specifier) => clauses.map((clause) => ({
|
|
50
|
+
const rawHits = bannedImportsIn({ text: sourceFile.text }).flatMap(
|
|
51
|
+
({ line, specifier }) => clauses.map((clause) => ({
|
|
44
52
|
clause: clause.address,
|
|
45
|
-
anchor: { line
|
|
53
|
+
anchor: { line, column: 0 },
|
|
46
54
|
snippet: `banned third-party import: ${specifier} \u2014 use its recorded wrapping boundary`
|
|
47
|
-
}))
|
|
55
|
+
}))
|
|
48
56
|
);
|
|
49
57
|
const nodeHits = [];
|
|
50
58
|
const record = (specifier) => {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
hitSchema,
|
|
3
3
|
runnerResultSchema
|
|
4
|
-
} from "../../../chunks/chunk-
|
|
4
|
+
} from "../../../chunks/chunk-RZA3OVOO.js";
|
|
5
5
|
import {
|
|
6
6
|
createDefaultPackageLocationPort,
|
|
7
|
+
gatheredOutcomes,
|
|
7
8
|
installRootOfRunnerEntry,
|
|
8
9
|
toolchainBoundStandaloneRunner
|
|
9
|
-
} from "../../../chunks/chunk-
|
|
10
|
+
} from "../../../chunks/chunk-EYCRDEXX.js";
|
|
10
11
|
import {
|
|
11
12
|
createDefaultFileTextPort,
|
|
12
13
|
createDefaultModuleLoaderPort,
|
|
@@ -18,13 +19,17 @@ import {
|
|
|
18
19
|
moduleExtensionOf,
|
|
19
20
|
moduleFileForm,
|
|
20
21
|
sameClauseAddress
|
|
21
|
-
} from "../../../chunks/chunk-
|
|
22
|
+
} from "../../../chunks/chunk-FOAGAYXM.js";
|
|
22
23
|
import "../../../chunks/chunk-NZLE2WMY.js";
|
|
23
24
|
|
|
24
25
|
// mechanisms/audit/runner/observe-walker-file.ts
|
|
25
26
|
var pieceHitsSchema = external_exports.array(hitSchema.unwrap().omit({ file: true }).readonly());
|
|
26
27
|
var callSchema = external_exports.function({ input: [external_exports.unknown()], output: external_exports.unknown() });
|
|
27
|
-
var
|
|
28
|
+
var functionSchema = () => external_exports.custom().superRefine((candidate, refinement) => {
|
|
29
|
+
if (typeof candidate !== "function") {
|
|
30
|
+
refinement.addIssue({ code: "invalid_type", expected: "function", input: candidate });
|
|
31
|
+
}
|
|
32
|
+
});
|
|
28
33
|
var fileCheckSchema = external_exports.discriminatedUnion("kind", [
|
|
29
34
|
external_exports.object({ kind: external_exports.literal("skipped") }),
|
|
30
35
|
external_exports.object({ kind: external_exports.literal("complete"), hits: pieceHitsSchema }),
|
|
@@ -32,10 +37,10 @@ var fileCheckSchema = external_exports.discriminatedUnion("kind", [
|
|
|
32
37
|
]);
|
|
33
38
|
var filePreparationSchema = runnerResultSchema({ value: fileCheckSchema });
|
|
34
39
|
var sourceObserversSchema = external_exports.object({
|
|
35
|
-
enter:
|
|
36
|
-
leave:
|
|
37
|
-
comment:
|
|
38
|
-
finish:
|
|
40
|
+
enter: functionSchema().optional(),
|
|
41
|
+
leave: functionSchema().optional(),
|
|
42
|
+
comment: functionSchema().optional(),
|
|
43
|
+
finish: functionSchema()
|
|
39
44
|
});
|
|
40
45
|
var thrownDetail = (request) => request.thrown instanceof Error ? request.thrown.message : String(request.thrown);
|
|
41
46
|
var pieceInvalid = (request) => ({
|
|
@@ -47,10 +52,10 @@ var pieceInvalid = (request) => ({
|
|
|
47
52
|
}
|
|
48
53
|
});
|
|
49
54
|
var collect = (request) => request.outcomes.reduce(
|
|
50
|
-
(
|
|
51
|
-
if (
|
|
55
|
+
(gathered, next) => {
|
|
56
|
+
if (gathered.outcome === "failed") return gathered;
|
|
52
57
|
if (next.outcome === "failed") return next;
|
|
53
|
-
return { outcome: "ok", value: [...
|
|
58
|
+
return { outcome: "ok", value: [...gathered.value, next.value] };
|
|
54
59
|
},
|
|
55
60
|
{ outcome: "ok", value: [] }
|
|
56
61
|
);
|
|
@@ -327,14 +332,14 @@ var loadModule = (request) => {
|
|
|
327
332
|
);
|
|
328
333
|
};
|
|
329
334
|
var collectPreparations = (request) => request.preparations.reduce(
|
|
330
|
-
(
|
|
331
|
-
if (
|
|
332
|
-
return
|
|
335
|
+
(gathered, next) => {
|
|
336
|
+
if (gathered.outcome === "failed") {
|
|
337
|
+
return gathered;
|
|
333
338
|
}
|
|
334
339
|
if (next.outcome === "failed") {
|
|
335
340
|
return next;
|
|
336
341
|
}
|
|
337
|
-
return { outcome: "ok", value: [...
|
|
342
|
+
return { outcome: "ok", value: [...gathered.value, next.value] };
|
|
338
343
|
},
|
|
339
344
|
{ outcome: "ok", value: [] }
|
|
340
345
|
);
|
|
@@ -357,14 +362,6 @@ var pieceInvalid3 = (request) => ({
|
|
|
357
362
|
error: { kind: "piece-invalid", pieceRoot: request.pieceRoot, detail: request.detail }
|
|
358
363
|
});
|
|
359
364
|
var thrownDetail2 = (request) => request.thrown instanceof Error ? request.thrown.message : String(request.thrown);
|
|
360
|
-
var gathered = (request) => request.outcomes.reduce(
|
|
361
|
-
(collected, next) => {
|
|
362
|
-
if (collected.outcome === "failed") return collected;
|
|
363
|
-
if (next.outcome === "failed") return next;
|
|
364
|
-
return { outcome: "ok", value: [...collected.value, ...next.value] };
|
|
365
|
-
},
|
|
366
|
-
{ outcome: "ok", value: [] }
|
|
367
|
-
);
|
|
368
365
|
var selectedClause = (request) => {
|
|
369
366
|
const settings = walkerPieceSettingsSchema.safeParse(request.clause.settings);
|
|
370
367
|
if (!settings.success) {
|
|
@@ -380,7 +377,7 @@ var selectedClause = (request) => {
|
|
|
380
377
|
]
|
|
381
378
|
};
|
|
382
379
|
};
|
|
383
|
-
var selectedClauses = (request) =>
|
|
380
|
+
var selectedClauses = (request) => gatheredOutcomes({ outcomes: request.clauses.map((clause) => selectedClause({ clause, path: request.path })) });
|
|
384
381
|
var preparedPieces = (request) => {
|
|
385
382
|
const selected = selectedClauses({ clauses: request.clauses, path: request.ports.path });
|
|
386
383
|
if (selected.outcome === "failed") return Promise.resolve(selected);
|
|
@@ -413,12 +410,15 @@ var finishedPiece = (request) => {
|
|
|
413
410
|
}
|
|
414
411
|
};
|
|
415
412
|
var walkedHits = (request) => {
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
{
|
|
419
|
-
|
|
413
|
+
const observed = [];
|
|
414
|
+
request.files.some((file) => {
|
|
415
|
+
const fileHits = observedHits({ ...request, file });
|
|
416
|
+
observed.push(fileHits);
|
|
417
|
+
return fileHits.outcome === "failed";
|
|
418
|
+
});
|
|
419
|
+
const fromFiles = gatheredOutcomes({ outcomes: observed });
|
|
420
420
|
if (fromFiles.outcome === "failed") return fromFiles;
|
|
421
|
-
return
|
|
421
|
+
return gatheredOutcomes({ outcomes: [fromFiles, ...request.pieces.map((piece) => finishedPiece({ piece }))] });
|
|
422
422
|
};
|
|
423
423
|
var repositoryFile = (request) => ({
|
|
424
424
|
file: request.file,
|
|
@@ -483,7 +483,7 @@ var caseVerdict = (request) => {
|
|
|
483
483
|
var conformCases = (request) => request.cases.reduce(
|
|
484
484
|
(pending, sourceCase) => pending.then(
|
|
485
485
|
(collected) => collected.outcome === "failed" ? collected : caseVerdict({ ports: request.ports, clause: request.clause, sourceCase }).then(
|
|
486
|
-
(next) =>
|
|
486
|
+
(next) => gatheredOutcomes({ outcomes: [collected, next] })
|
|
487
487
|
)
|
|
488
488
|
),
|
|
489
489
|
Promise.resolve({ outcome: "ok", value: [] })
|
|
@@ -495,12 +495,14 @@ var createWalkerRunner = (ports) => ({
|
|
|
495
495
|
});
|
|
496
496
|
|
|
497
497
|
// mechanisms/audit/runner/typescript-parse.ts
|
|
498
|
+
var defaultTypeScriptModules = { typescript: () => import("typescript") };
|
|
499
|
+
|
|
500
|
+
// mechanisms/audit/runner/typescript-toolchain.ts
|
|
498
501
|
var TYPESCRIPT_REQUIREMENT = {
|
|
499
502
|
packageName: "typescript",
|
|
500
503
|
peer: "required",
|
|
501
504
|
lines: [{ floor: "4.8.4", below: "7.0.0" }]
|
|
502
505
|
};
|
|
503
|
-
var defaultTypeScriptModules = { typescript: () => import("typescript") };
|
|
504
506
|
var defaultTypeScriptPeers = (options) => ({
|
|
505
507
|
location: createDefaultPackageLocationPort(options),
|
|
506
508
|
modules: defaultTypeScriptModules
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type typescript from "typescript";
|
|
2
|
+
export type SyntaxApi = typeof typescript;
|
|
3
|
+
export type SyntaxTree = typescript.SourceFile;
|
|
4
|
+
export type SyntaxNode = typescript.Node;
|
|
5
|
+
export type CommentRange = typescript.CommentRange;
|
|
6
|
+
export type TypeScriptParsePort = {
|
|
7
|
+
readonly syntaxApi: SyntaxApi;
|
|
8
|
+
readonly parse: (request: {
|
|
9
|
+
readonly fileName: string;
|
|
10
|
+
readonly source: string;
|
|
11
|
+
}) => SyntaxTree;
|
|
12
|
+
readonly children: (request: {
|
|
13
|
+
readonly node: SyntaxNode;
|
|
14
|
+
}) => readonly SyntaxNode[];
|
|
15
|
+
};
|
|
16
|
+
export type TypeScriptModules = {
|
|
17
|
+
readonly typescript: () => Promise<{
|
|
18
|
+
readonly default: SyntaxApi;
|
|
19
|
+
}>;
|
|
20
|
+
};
|