@hailstails/hone 0.1.0-pre.4 → 0.1.0-pre.5
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 +37 -12
- package/MIGRATING.md +4 -4
- package/README.md +35 -16
- package/api/audit.d.ts +3 -2
- package/api/rule-set.d.ts +2 -4
- package/chunks/chunk-3HFJHJDO.js +53 -0
- package/chunks/chunk-7OVV6NEU.js +22 -0
- package/chunks/chunk-7PVPPH4C.js +13 -0
- package/chunks/chunk-HVABJ7T4.js +361 -0
- package/chunks/{chunk-BX6QHLSZ.js → chunk-IIMK5BCL.js} +57 -4
- package/chunks/{chunk-FOAGAYXM.js → chunk-SWPCKTJV.js} +44 -397
- package/chunks/{chunk-RZA3OVOO.js → chunk-VUG3DJHN.js} +5 -3
- package/chunks/{chunk-EYCRDEXX.js → chunk-YBWVUDIG.js} +2 -13
- package/core/check/tool-command.js +356 -81
- package/core/mechanism-port/piece-failure-types.d.ts +14 -0
- package/core/mechanism-port/runner-module-types.d.ts +5 -0
- package/core/rule-set-reader/authored-rule-set-types.d.ts +48 -0
- package/core/values/json-value.d.ts +3 -0
- package/docs/adding-a-discipline-or-mechanism.md +6 -3
- package/docs/extending.md +357 -0
- package/mechanisms/audit/CD-1/any-cast.js +9 -37
- package/mechanisms/audit/CD-19/import-boundaries.js +79 -68
- package/mechanisms/audit/CD-19/piece.json +5 -0
- package/mechanisms/audit/CD-2/cast-expressions.js +14 -37
- package/mechanisms/audit/CD-5/comments-directives.js +137 -55
- package/mechanisms/audit/CD-5/piece.json +7 -0
- package/mechanisms/audit/runner/README.md +1 -0
- package/mechanisms/audit/runner/runner.js +10 -6
- package/mechanisms/audit/runner/typescript-parse.d.ts +6 -0
- package/mechanisms/audit/runner/walker-piece.d.ts +5 -5
- package/mechanisms/eslint/runner/README.md +1 -1
- package/mechanisms/eslint/runner/runner.js +85 -35
- package/package.json +4 -4
- package/rules/CD-1/README.md +5 -5
- package/rules/CD-1/discipline.json +16 -6
- package/rules/CD-19/README.md +13 -3
- package/rules/CD-19/discipline.json +6 -8
- package/rules/CD-2/README.md +8 -4
- package/rules/CD-2/discipline.json +25 -7
- package/rules/CD-5/README.md +17 -5
- package/rules/CD-5/discipline.json +66 -0
- package/core/mechanism-port/runner-failure-types.d.ts +0 -38
- package/core/rule-set-reader/rule-set-types.d.ts +0 -41
- /package/api/{audit.js → audit.mjs} +0 -0
- /package/api/{rule-set.js → rule-set.mjs} +0 -0
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
stringListClauseSettings
|
|
3
|
+
} from "../../../chunks/chunk-7OVV6NEU.js";
|
|
4
|
+
import {
|
|
5
|
+
gatheredOutcomes
|
|
6
|
+
} from "../../../chunks/chunk-7PVPPH4C.js";
|
|
7
|
+
import "../../../chunks/chunk-SWPCKTJV.js";
|
|
1
8
|
import {
|
|
2
9
|
folderScope
|
|
3
10
|
} from "../../../chunks/chunk-QWA6OVLC.js";
|
|
@@ -9,79 +16,83 @@ var sourceEligibility = (request) => {
|
|
|
9
16
|
if (folderScope({ file: request.file }) === "generated") return "excluded";
|
|
10
17
|
return "eligible";
|
|
11
18
|
};
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"hono/utils/http-status",
|
|
24
|
-
"jose",
|
|
25
|
-
"@modelcontextprotocol/sdk",
|
|
26
|
-
"zod-to-json-schema",
|
|
27
|
-
"uuid"
|
|
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 [];
|
|
19
|
+
var escapedPackage = (request) => request.packageName.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
20
|
+
var confinedImportPattern = (request) => new RegExp(
|
|
21
|
+
`from\\s+["']((?:${request.packageNames.map((packageName) => escapedPackage({ packageName })).join("|")})(?:/[^"']*)?)["']`
|
|
22
|
+
);
|
|
23
|
+
var confinedClauseOf = (request) => ({
|
|
24
|
+
clause: request.clause,
|
|
25
|
+
anywhere: request.packageNames.length === 0 ? void 0 : confinedImportPattern({ packageNames: request.packageNames }),
|
|
26
|
+
patterns: request.packageNames.map((packageName) => ({ pattern: confinedImportPattern({ packageNames: [packageName] }) }))
|
|
27
|
+
});
|
|
28
|
+
var confinedImportsIn = (request) => {
|
|
29
|
+
if (request.confined.anywhere === void 0 || !request.confined.anywhere.test(request.text)) return [];
|
|
35
30
|
return request.text.split("\n").flatMap(
|
|
36
|
-
(text, index) =>
|
|
31
|
+
(text, index) => request.confined.patterns.flatMap(({ pattern }) => {
|
|
32
|
+
const specifier = pattern.exec(text)?.[1];
|
|
33
|
+
return specifier === void 0 ? [] : [{ line: index + 1, specifier }];
|
|
34
|
+
})
|
|
37
35
|
);
|
|
38
36
|
};
|
|
37
|
+
var confinedImportHits = (request) => request.confined.flatMap(
|
|
38
|
+
(confined) => confinedImportsIn({ text: request.text, confined }).map(({ line, specifier }) => ({
|
|
39
|
+
clause: confined.clause.address,
|
|
40
|
+
anchor: { line, column: 0 },
|
|
41
|
+
snippet: `banned third-party import: ${specifier} \u2014 use its recorded wrapping boundary`
|
|
42
|
+
}))
|
|
43
|
+
);
|
|
44
|
+
var confinedClausesOf = (request) => gatheredOutcomes({
|
|
45
|
+
outcomes: request.clauses.map((clause) => {
|
|
46
|
+
const settings = stringListClauseSettings({ clause, keys: ["confinedPackages"] });
|
|
47
|
+
if (settings.outcome === "failed") return settings;
|
|
48
|
+
return { outcome: "ok", value: [confinedClauseOf({ clause, packageNames: settings.value.confinedPackages })] };
|
|
49
|
+
})
|
|
50
|
+
});
|
|
39
51
|
var check = {
|
|
40
|
-
prepare: ({ clauses, syntaxApi }) =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
};
|
|
52
|
+
prepare: ({ clauses, syntaxApi }) => {
|
|
53
|
+
const settled = confinedClausesOf({ clauses });
|
|
54
|
+
if (settled.outcome === "failed") return settled;
|
|
55
|
+
const confined = settled.value;
|
|
56
|
+
return {
|
|
57
|
+
outcome: "ok",
|
|
58
|
+
value: {
|
|
59
|
+
prepareFile: ({ file }) => {
|
|
60
|
+
if (sourceEligibility({ file }) === "excluded") return { outcome: "ok", value: { kind: "skipped" } };
|
|
61
|
+
return {
|
|
62
|
+
outcome: "ok",
|
|
63
|
+
value: {
|
|
64
|
+
kind: "syntax",
|
|
65
|
+
begin: ({ sourceFile, anchorAt }) => {
|
|
66
|
+
const rawHits = confinedImportHits({ text: sourceFile.text, confined });
|
|
67
|
+
const nodeHits = [];
|
|
68
|
+
const record = (specifier) => {
|
|
69
|
+
if (specifier === void 0 || !syntaxApi.isStringLiteralLike(specifier) || !specifier.text.startsWith("node:")) return;
|
|
70
|
+
const anchor = anchorAt({ position: specifier.getStart(sourceFile) });
|
|
71
|
+
const snippet = `bare node: stdlib import - use the kernel port package: ${specifier.text}`;
|
|
72
|
+
nodeHits.push(...clauses.map((clause) => ({ clause: clause.address, anchor, snippet })));
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
enter: ({ node }) => {
|
|
76
|
+
if (syntaxApi.isImportDeclaration(node) || syntaxApi.isExportDeclaration(node)) {
|
|
77
|
+
record(node.moduleSpecifier);
|
|
78
|
+
} else if (syntaxApi.isImportTypeNode(node) && syntaxApi.isLiteralTypeNode(node.argument)) {
|
|
79
|
+
record(node.argument.literal);
|
|
80
|
+
} else if (syntaxApi.isImportEqualsDeclaration(node) && syntaxApi.isExternalModuleReference(node.moduleReference)) {
|
|
81
|
+
record(node.moduleReference.expression);
|
|
82
|
+
} else if (syntaxApi.isCallExpression(node) && (node.expression.kind === syntaxApi.SyntaxKind.ImportKeyword || syntaxApi.isIdentifier(node.expression) && node.expression.text === "require")) {
|
|
83
|
+
record(node.arguments[0]);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
finish: () => [...rawHits, ...nodeHits]
|
|
87
|
+
};
|
|
88
|
+
}
|
|
78
89
|
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
}
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
finish: () => ({ outcome: "ok", value: [] })
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
85
96
|
};
|
|
86
97
|
export {
|
|
87
98
|
check
|
|
@@ -1,46 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
anyBearingOf,
|
|
3
|
+
assertionOf,
|
|
4
|
+
castShapeOf,
|
|
5
|
+
castSnippetAt
|
|
6
|
+
} from "../../../chunks/chunk-3HFJHJDO.js";
|
|
1
7
|
import {
|
|
2
8
|
folderScope
|
|
3
9
|
} from "../../../chunks/chunk-QWA6OVLC.js";
|
|
4
10
|
import "../../../chunks/chunk-NZLE2WMY.js";
|
|
5
11
|
|
|
6
12
|
// mechanisms/audit/CD-2/cast-expressions.ts
|
|
7
|
-
var
|
|
8
|
-
var ZOD_MODULE_SPECIFIER_PATTERN = /^zod(\/.*)?$/;
|
|
9
|
-
var CD1_ANY_PATTERN = /\bas\s+any\b|:\s*any\b|<any>/;
|
|
13
|
+
var THROUGH_UNKNOWN_MESSAGE = "cast through unknown \u2014 check the value's shape at runtime instead";
|
|
10
14
|
var sourceEligibility = (request) => {
|
|
11
15
|
if (!request.file.endsWith(".ts") && !request.file.endsWith(".tsx")) return "excluded";
|
|
12
16
|
if (folderScope({ file: request.file }) === "generated") return "excluded";
|
|
13
17
|
return "eligible";
|
|
14
18
|
};
|
|
15
|
-
var
|
|
16
|
-
request.sourceFile.statements.flatMap((statement) => {
|
|
17
|
-
if (!request.syntaxApi.isImportDeclaration(statement)) return [];
|
|
18
|
-
if (!request.syntaxApi.isStringLiteral(statement.moduleSpecifier)) return [];
|
|
19
|
-
if (!ZOD_MODULE_SPECIFIER_PATTERN.test(statement.moduleSpecifier.text)) return [];
|
|
20
|
-
const namedBindings = statement.importClause?.namedBindings;
|
|
21
|
-
if (namedBindings === void 0 || !request.syntaxApi.isNamedImports(namedBindings)) return [];
|
|
22
|
-
return namedBindings.elements.map((element) => element.name.text);
|
|
23
|
-
})
|
|
24
|
-
);
|
|
25
|
-
var castPermission = (request) => {
|
|
26
|
-
if (!request.syntaxApi.isAsExpression(request.node)) return "forbidden";
|
|
27
|
-
const typeNode = request.node.type;
|
|
28
|
-
if (typeNode.kind === request.syntaxApi.SyntaxKind.UnknownKeyword) return "permitted";
|
|
29
|
-
if (request.syntaxApi.isTypeReferenceNode(typeNode) && request.syntaxApi.isIdentifier(typeNode.typeName)) {
|
|
30
|
-
const typeName = typeNode.typeName.text;
|
|
31
|
-
if (typeName === "const" || request.zodImportedNames.has(typeName)) return "permitted";
|
|
32
|
-
if (request.syntaxApi.isPropertyAccessExpression(request.node.expression) && request.node.expression.name.text === "value" && (typeName === "ReadonlyArray" || typeName === "Array")) return "permitted";
|
|
33
|
-
}
|
|
34
|
-
if (!request.syntaxApi.isIndexedAccessTypeNode(typeNode)) return "forbidden";
|
|
35
|
-
const objectType = typeNode.objectType;
|
|
36
|
-
const indexType = typeNode.indexType;
|
|
37
|
-
if (request.syntaxApi.isTypeReferenceNode(objectType) && request.syntaxApi.isIdentifier(objectType.typeName) && objectType.typeName.text === "Tool" && request.syntaxApi.isLiteralTypeNode(indexType) && request.syntaxApi.isStringLiteral(indexType.literal) && indexType.literal.text === "inputSchema") return "permitted";
|
|
38
|
-
return "forbidden";
|
|
39
|
-
};
|
|
40
|
-
var snippetAt = (request) => {
|
|
41
|
-
const snippet = request.sourceFile.text.slice(request.position, request.position + SNIPPET_MAX_LENGTH).replace(/\n/g, " ");
|
|
42
|
-
return snippet.length === SNIPPET_MAX_LENGTH ? `${snippet}\u2026` : snippet;
|
|
43
|
-
};
|
|
19
|
+
var reportedSnippet = (request) => request.shape === "through-unknown" ? `${THROUGH_UNKNOWN_MESSAGE}: ${request.snippet}` : request.snippet;
|
|
44
20
|
var check = {
|
|
45
21
|
prepare: ({ clauses, syntaxApi }) => ({
|
|
46
22
|
outcome: "ok",
|
|
@@ -54,15 +30,16 @@ var check = {
|
|
|
54
30
|
value: {
|
|
55
31
|
kind: "syntax",
|
|
56
32
|
begin: ({ sourceFile, anchorAt }) => {
|
|
57
|
-
const zodImportedNames = namesImportedFromZod({ sourceFile, syntaxApi });
|
|
58
33
|
const hits = [];
|
|
59
34
|
return {
|
|
60
35
|
enter: ({ node }) => {
|
|
61
|
-
|
|
62
|
-
if (
|
|
36
|
+
const assertion = assertionOf({ node, syntaxApi });
|
|
37
|
+
if (assertion === void 0) return;
|
|
38
|
+
if (anyBearingOf({ typeNode: assertion.type, syntaxApi }) === "any-bearing") return;
|
|
39
|
+
const shape = castShapeOf({ assertion, syntaxApi });
|
|
40
|
+
if (shape === "const-assertion") return;
|
|
63
41
|
const position = node.getStart(sourceFile);
|
|
64
|
-
const snippet =
|
|
65
|
-
if (CD1_ANY_PATTERN.test(snippet)) return;
|
|
42
|
+
const snippet = reportedSnippet({ shape, snippet: castSnippetAt({ sourceFile, position }) });
|
|
66
43
|
const anchor = anchorAt({ position });
|
|
67
44
|
hits.push(...clauses.map((clause) => ({ clause: clause.address, anchor, snippet })));
|
|
68
45
|
},
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
stringListClauseSettings
|
|
3
|
+
} from "../../../chunks/chunk-7OVV6NEU.js";
|
|
4
|
+
import {
|
|
5
|
+
gatheredOutcomes
|
|
6
|
+
} from "../../../chunks/chunk-7PVPPH4C.js";
|
|
7
|
+
import {
|
|
8
|
+
clauseAddressText
|
|
9
|
+
} from "../../../chunks/chunk-SWPCKTJV.js";
|
|
1
10
|
import {
|
|
2
11
|
folderScope
|
|
3
12
|
} from "../../../chunks/chunk-QWA6OVLC.js";
|
|
@@ -9,64 +18,137 @@ var sourceEligibility = (request) => {
|
|
|
9
18
|
if (folderScope({ file: request.file }) === "generated") return "excluded";
|
|
10
19
|
return "eligible";
|
|
11
20
|
};
|
|
12
|
-
var
|
|
13
|
-
var
|
|
21
|
+
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;
|
|
14
25
|
var LINTER_DIRECTIVE_PATTERN = /^(?:\/\/|\/\*)\s*((?:biome-ignore(?:-all|-start|-end)?|(?:eslint|oxlint)-(?:disable(?:-line|-next-line)?|enable)|eslint(?=\s)))\b/;
|
|
26
|
+
var TRACKED_REFERENCE_PATTERN = /\([^()\s]*\d[^()\s]*\)/g;
|
|
27
|
+
var LEADING_TRACKED_REFERENCE_PATTERN = /^\s*(\([^()\s]*\d[^()\s]*\))/;
|
|
28
|
+
var compiledTracker = (request) => {
|
|
29
|
+
try {
|
|
30
|
+
return { outcome: "ok", value: [new RegExp(request.source)] };
|
|
31
|
+
} catch (thrown) {
|
|
32
|
+
return {
|
|
33
|
+
outcome: "failed",
|
|
34
|
+
error: {
|
|
35
|
+
kind: "piece-invalid",
|
|
36
|
+
pieceRoot: request.clause.pieceRoot,
|
|
37
|
+
detail: `the clauseSettings of ${clauseAddressText({ address: request.clause.address })} are malformed: trackerPatterns entry ${JSON.stringify(request.source)} is not a regular expression: ${thrown instanceof Error ? thrown.message : String(thrown)}`
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var trackedClauseOf = (request) => {
|
|
43
|
+
const settings = stringListClauseSettings({ clause: request.clause, keys: ["trackerPatterns"] });
|
|
44
|
+
if (settings.outcome === "failed") return settings;
|
|
45
|
+
const trackers = gatheredOutcomes({
|
|
46
|
+
outcomes: settings.value.trackerPatterns.map((source) => compiledTracker({ clause: request.clause, source }))
|
|
47
|
+
});
|
|
48
|
+
if (trackers.outcome === "failed") return trackers;
|
|
49
|
+
return { outcome: "ok", value: [{ clause: request.clause, trackers: trackers.value }] };
|
|
50
|
+
};
|
|
51
|
+
var trackedClausesOf = (request) => gatheredOutcomes({ outcomes: request.clauses.map((clause) => trackedClauseOf({ clause })) });
|
|
52
|
+
var chosenReference = (request) => request.references.some((reference) => request.tracked.trackers.some((tracker) => tracker.test(reference))) ? "tracked" : "untracked";
|
|
53
|
+
var trackingAnywhere = (request) => chosenReference({
|
|
54
|
+
references: Array.from(request.text.matchAll(TRACKED_REFERENCE_PATTERN), (match) => match[0]),
|
|
55
|
+
tracked: request.tracked
|
|
56
|
+
});
|
|
57
|
+
var trackingAtStart = (request) => {
|
|
58
|
+
const reference = LEADING_TRACKED_REFERENCE_PATTERN.exec(request.text)?.[1];
|
|
59
|
+
return chosenReference({ references: reference === void 0 ? [] : [reference], tracked: request.tracked });
|
|
60
|
+
};
|
|
61
|
+
var textAfter = (request) => {
|
|
62
|
+
const marker = request.pattern.exec(request.text);
|
|
63
|
+
return marker === null ? void 0 : request.text.slice(marker.index + marker[0].length);
|
|
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
|
+
var untrackedClauses = (request) => request.trackedClauses.filter((tracked) => request.tracking({ text: request.text, tracked }) === "untracked");
|
|
75
|
+
var hitsFor = (request) => {
|
|
76
|
+
if (request.untracked.length === 0) return [];
|
|
77
|
+
const anchor = request.anchorAt({ position: request.position });
|
|
78
|
+
return request.untracked.map((tracked) => ({ clause: tracked.clause.address, anchor, snippet: request.snippet }));
|
|
79
|
+
};
|
|
80
|
+
var taskHits = (request) => {
|
|
81
|
+
let lineStart = 0;
|
|
82
|
+
return request.sourceFile.text.split("\n").flatMap((line) => {
|
|
83
|
+
const position = lineStart;
|
|
84
|
+
lineStart += line.length + 1;
|
|
85
|
+
const afterTodo = textAfter({ pattern: TODO_PATTERN, text: line });
|
|
86
|
+
if (afterTodo === void 0) return [];
|
|
87
|
+
return hitsFor({
|
|
88
|
+
untracked: untrackedClauses({ trackedClauses: request.trackedClauses, text: afterTodo, tracking: trackingAtStart }),
|
|
89
|
+
anchorAt: request.anchorAt,
|
|
90
|
+
position,
|
|
91
|
+
snippet: line.trim()
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
};
|
|
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
|
+
var sourceObserversFor = (request) => {
|
|
100
|
+
const { sourceFile, anchorAt, trackedClauses, syntaxApi } = request;
|
|
101
|
+
const fileHeaderPositions = new Set(
|
|
102
|
+
(syntaxApi.getLeadingCommentRanges(sourceFile.text, 0) ?? []).map((headerRange) => headerRange.pos)
|
|
103
|
+
);
|
|
104
|
+
const todoHits = taskHits(request);
|
|
105
|
+
const directiveHits = [];
|
|
106
|
+
const typeDirectiveHits = [];
|
|
107
|
+
const commentHits = (comment) => hitsFor({
|
|
108
|
+
untracked: untrackedClauses({ trackedClauses, text: comment.text, tracking: trackingAnywhere }),
|
|
109
|
+
anchorAt,
|
|
110
|
+
position: comment.position,
|
|
111
|
+
snippet: comment.whole.trim()
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
comment: ({ range }) => {
|
|
115
|
+
const whole = sourceFile.text.slice(range.pos, range.end);
|
|
116
|
+
const placement = commentPlacementOf({ range, fileHeaderPositions, syntaxApi });
|
|
117
|
+
const afterTypeDirective = typeDirectiveTail({ comment: whole, placement });
|
|
118
|
+
if (afterTypeDirective !== void 0) {
|
|
119
|
+
typeDirectiveHits.push(...commentHits({ text: afterTypeDirective, whole, position: range.pos }));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (LINTER_DIRECTIVE_PATTERN.exec(whole)?.[1] === void 0) return;
|
|
123
|
+
directiveHits.push(...commentHits({ text: whole, whole, position: range.pos }));
|
|
124
|
+
},
|
|
125
|
+
finish: () => [...todoHits, ...directiveHits, ...typeDirectiveHits]
|
|
126
|
+
};
|
|
127
|
+
};
|
|
15
128
|
var check = {
|
|
16
|
-
prepare: ({ clauses }) =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
kind: "syntax",
|
|
27
|
-
begin: ({ sourceFile, anchorAt }) => {
|
|
28
|
-
const todoHits = [];
|
|
29
|
-
const directiveHits = [];
|
|
30
|
-
const expectationHits = [];
|
|
31
|
-
const lineHits = (request) => {
|
|
32
|
-
const anchor = anchorAt({ position: request.position });
|
|
33
|
-
return clauses.map((clause) => ({
|
|
34
|
-
clause: clause.address,
|
|
35
|
-
anchor,
|
|
36
|
-
snippet: request.line.trim()
|
|
37
|
-
}));
|
|
38
|
-
};
|
|
39
|
-
let linePosition = 0;
|
|
40
|
-
sourceFile.text.split("\n").forEach((line) => {
|
|
41
|
-
if (BARE_TODO_PATTERN.test(line)) {
|
|
42
|
-
todoHits.push(...lineHits({ line, position: linePosition }));
|
|
43
|
-
}
|
|
44
|
-
if (BARE_TS_EXPECT_ERROR_PATTERN.test(line)) {
|
|
45
|
-
expectationHits.push(...lineHits({ line, position: linePosition }));
|
|
46
|
-
}
|
|
47
|
-
linePosition += line.length + 1;
|
|
48
|
-
});
|
|
49
|
-
return {
|
|
50
|
-
comment: ({ range }) => {
|
|
51
|
-
const comment = sourceFile.text.slice(range.pos, range.end);
|
|
52
|
-
if (LINTER_DIRECTIVE_PATTERN.exec(comment)?.[1] === void 0) return;
|
|
53
|
-
if (/\(spec-\d+\)/.test(comment)) return;
|
|
54
|
-
const anchor = anchorAt({ position: range.pos });
|
|
55
|
-
directiveHits.push(...clauses.map((clause) => ({
|
|
56
|
-
clause: clause.address,
|
|
57
|
-
anchor,
|
|
58
|
-
snippet: comment.trim()
|
|
59
|
-
})));
|
|
60
|
-
},
|
|
61
|
-
finish: () => [...todoHits, ...directiveHits, ...expectationHits]
|
|
62
|
-
};
|
|
63
|
-
}
|
|
129
|
+
prepare: ({ clauses, syntaxApi }) => {
|
|
130
|
+
const settled = trackedClausesOf({ clauses });
|
|
131
|
+
if (settled.outcome === "failed") return settled;
|
|
132
|
+
const trackedClauses = settled.value;
|
|
133
|
+
return {
|
|
134
|
+
outcome: "ok",
|
|
135
|
+
value: {
|
|
136
|
+
prepareFile: ({ file }) => {
|
|
137
|
+
if (sourceEligibility({ file }) === "excluded") {
|
|
138
|
+
return { outcome: "ok", value: { kind: "skipped" } };
|
|
64
139
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
140
|
+
return {
|
|
141
|
+
outcome: "ok",
|
|
142
|
+
value: {
|
|
143
|
+
kind: "syntax",
|
|
144
|
+
begin: ({ sourceFile, anchorAt }) => sourceObserversFor({ sourceFile, anchorAt, trackedClauses, syntaxApi })
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
finish: () => ({ outcome: "ok", value: [] })
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
70
152
|
};
|
|
71
153
|
export {
|
|
72
154
|
check
|
|
@@ -13,6 +13,7 @@ The audit runner is Hone's standalone mechanism for checks that read a project's
|
|
|
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
15
|
- `walker-check-schema.ts` holds the schema for a clause's settings: `module`, a path inside the piece folder ending `.ts`.
|
|
16
|
+
- `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`.
|
|
16
17
|
- `prepare-walker-pieces.ts` loads each selected module once and prepares it with every selected clause that names it.
|
|
17
18
|
- `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.
|
|
18
19
|
- `create-walker-runner.ts` builds the runner from its ports: file text, module loading, paths and parsing.
|
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
hitSchema,
|
|
3
3
|
runnerResultSchema
|
|
4
|
-
} from "../../../chunks/chunk-
|
|
4
|
+
} from "../../../chunks/chunk-VUG3DJHN.js";
|
|
5
5
|
import {
|
|
6
6
|
createDefaultPackageLocationPort,
|
|
7
|
-
gatheredOutcomes,
|
|
8
7
|
installRootOfRunnerEntry,
|
|
9
8
|
toolchainBoundStandaloneRunner
|
|
10
|
-
} from "../../../chunks/chunk-
|
|
9
|
+
} from "../../../chunks/chunk-YBWVUDIG.js";
|
|
10
|
+
import {
|
|
11
|
+
gatheredOutcomes
|
|
12
|
+
} from "../../../chunks/chunk-7PVPPH4C.js";
|
|
11
13
|
import {
|
|
12
14
|
createDefaultFileTextPort,
|
|
13
15
|
createDefaultModuleLoaderPort,
|
|
14
16
|
createDefaultPathPort,
|
|
15
|
-
external_exports,
|
|
16
17
|
installFormOf,
|
|
17
18
|
isRepoPathText,
|
|
18
19
|
loadedPeer,
|
|
19
20
|
moduleExtensionOf,
|
|
20
|
-
moduleFileForm
|
|
21
|
+
moduleFileForm
|
|
22
|
+
} from "../../../chunks/chunk-HVABJ7T4.js";
|
|
23
|
+
import {
|
|
24
|
+
external_exports,
|
|
21
25
|
sameClauseAddress
|
|
22
|
-
} from "../../../chunks/chunk-
|
|
26
|
+
} from "../../../chunks/chunk-SWPCKTJV.js";
|
|
23
27
|
import "../../../chunks/chunk-NZLE2WMY.js";
|
|
24
28
|
|
|
25
29
|
// mechanisms/audit/runner/observe-walker-file.ts
|
|
@@ -3,6 +3,12 @@ export type SyntaxApi = typeof typescript;
|
|
|
3
3
|
export type SyntaxTree = typescript.SourceFile;
|
|
4
4
|
export type SyntaxNode = typescript.Node;
|
|
5
5
|
export type CommentRange = typescript.CommentRange;
|
|
6
|
+
export type Statement = typescript.Statement;
|
|
7
|
+
export type ImportDeclaration = typescript.ImportDeclaration;
|
|
8
|
+
export type ExportDeclaration = typescript.ExportDeclaration;
|
|
9
|
+
export type Diagnostic = typescript.Diagnostic;
|
|
10
|
+
export type CompilerOptions = typescript.CompilerOptions;
|
|
11
|
+
export type CustomTransformers = typescript.CustomTransformers;
|
|
6
12
|
export type TypeScriptParsePort = {
|
|
7
13
|
readonly syntaxApi: SyntaxApi;
|
|
8
14
|
readonly parse: (request: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PieceFailure } from "../../../core/mechanism-port/piece-failure-types.js";
|
|
2
2
|
import type { RunnerClause } from "../../../core/mechanism-port/runner-module-types.js";
|
|
3
3
|
import type { Hit } from "../../../core/mechanism-port/runner-result-types.js";
|
|
4
4
|
import type { Anchor } from "../../../core/values/anchor.js";
|
|
@@ -13,7 +13,7 @@ export type PieceHit = {
|
|
|
13
13
|
};
|
|
14
14
|
export type WalkerFile = {
|
|
15
15
|
readonly file: RepoPath;
|
|
16
|
-
readonly readText: () => Result<string,
|
|
16
|
+
readonly readText: () => Result<string, PieceFailure>;
|
|
17
17
|
};
|
|
18
18
|
export type SourceObservers = {
|
|
19
19
|
readonly enter?: (request: {
|
|
@@ -42,8 +42,8 @@ export type PreparedFileCheck = {
|
|
|
42
42
|
}) => SourceObservers;
|
|
43
43
|
};
|
|
44
44
|
export type PreparedWalkerCheck = {
|
|
45
|
-
readonly prepareFile: (request: WalkerFile) => Result<PreparedFileCheck,
|
|
46
|
-
readonly finish: () => Result<readonly Hit[],
|
|
45
|
+
readonly prepareFile: (request: WalkerFile) => Result<PreparedFileCheck, PieceFailure>;
|
|
46
|
+
readonly finish: () => Result<readonly Hit[], PieceFailure>;
|
|
47
47
|
};
|
|
48
48
|
export type WalkerRepository = {
|
|
49
49
|
readonly files: readonly RepoPath[];
|
|
@@ -56,5 +56,5 @@ export type WalkerPiece = {
|
|
|
56
56
|
readonly clauses: readonly RunnerClause[];
|
|
57
57
|
readonly repository: WalkerRepository;
|
|
58
58
|
readonly syntaxApi: SyntaxApi;
|
|
59
|
-
}) => Result<PreparedWalkerCheck,
|
|
59
|
+
}) => Result<PreparedWalkerCheck, PieceFailure>;
|
|
60
60
|
};
|
|
@@ -11,7 +11,7 @@ The check compares the committed projection byte for byte with what the runner w
|
|
|
11
11
|
- From source, Node 22.18.0 or later, which runs the `.ts` modules directly by stripping types. The built package is plain JavaScript.
|
|
12
12
|
- `zod`, for the piece settings, the loaded plugin, ESLint's resolved configuration and the files the runner reads. A dependency of core.
|
|
13
13
|
- `@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.
|
|
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 them once, when it is loaded, and answers every call with `toolchain-unavailable` naming the first 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
15
|
|
|
16
16
|
## Files
|
|
17
17
|
|