@hailstails/hone 0.0.0-stage → 0.1.0-pre.2
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 +314 -0
- package/LICENSE +17 -0
- package/MIGRATING.md +238 -0
- package/README.md +216 -2
- package/THIRD-PARTY-NOTICES.md +354 -0
- package/chunks/chunk-233U4FBA.js +42 -0
- package/chunks/chunk-7ZJZZBSS.js +14909 -0
- package/chunks/chunk-HBY4ZWSP.js +79 -0
- package/chunks/chunk-HJA4CX7C.js +24 -0
- package/chunks/chunk-NZLE2WMY.js +35 -0
- package/chunks/chunk-QWA6OVLC.js +11 -0
- package/chunks/chunk-TRCB27ET.js +202 -0
- package/core/check/tool-command.js +2305 -0
- package/docs/adding-a-discipline-or-mechanism.md +195 -0
- package/docs/why-chain-contract.md +78 -0
- package/mechanisms/audit/CD-1/any-cast.js +81 -0
- package/mechanisms/audit/CD-1/piece.json +13 -0
- package/mechanisms/audit/CD-10/piece.json +13 -0
- package/mechanisms/audit/CD-10/throws-in-tests.js +49 -0
- package/mechanisms/audit/CD-14/class-syntax.js +70 -0
- package/mechanisms/audit/CD-14/piece.json +13 -0
- package/mechanisms/audit/CD-15/loops.js +40 -0
- package/mechanisms/audit/CD-15/piece.json +13 -0
- package/mechanisms/audit/CD-17/clock-sources.js +29 -0
- package/mechanisms/audit/CD-17/piece.json +13 -0
- package/mechanisms/audit/CD-19/import-boundaries.js +80 -0
- package/mechanisms/audit/CD-19/piece.json +13 -0
- package/mechanisms/audit/CD-2/cast-expressions.js +81 -0
- package/mechanisms/audit/CD-2/piece.json +13 -0
- package/mechanisms/audit/CD-23/export-test-sibling.js +56 -0
- package/mechanisms/audit/CD-23/piece.json +13 -0
- package/mechanisms/audit/CD-25/dependency-isolation.js +53 -0
- package/mechanisms/audit/CD-25/piece.json +13 -0
- package/mechanisms/audit/CD-26/module-mocking.js +51 -0
- package/mechanisms/audit/CD-26/piece.json +13 -0
- package/mechanisms/audit/CD-27/piece.json +13 -0
- package/mechanisms/audit/CD-27/test-body-logic.js +107 -0
- package/mechanisms/audit/CD-3/compiler-overrides.js +955 -0
- package/mechanisms/audit/CD-3/piece.json +49 -0
- package/mechanisms/audit/CD-43/boolean-signatures.js +55 -0
- package/mechanisms/audit/CD-43/piece.json +13 -0
- package/mechanisms/audit/CD-44/parameter-mutation.js +92 -0
- package/mechanisms/audit/CD-44/piece.json +13 -0
- package/mechanisms/audit/CD-47/hermetic-git-spawns.js +44 -0
- package/mechanisms/audit/CD-47/piece.json +13 -0
- package/mechanisms/audit/CD-5/comments-directives.js +73 -0
- package/mechanisms/audit/CD-5/piece.json +13 -0
- package/mechanisms/audit/CD-6/identifier-names.js +132 -0
- package/mechanisms/audit/CD-6/piece.json +13 -0
- package/mechanisms/audit/CD-7/categorical-paths.js +55 -0
- package/mechanisms/audit/CD-7/piece.json +13 -0
- package/mechanisms/audit/CD-7a/factory-return-types.js +42 -0
- package/mechanisms/audit/CD-7a/piece.json +13 -0
- package/mechanisms/audit/CD-8/piece.json +13 -0
- package/mechanisms/audit/CD-8/switch-defaults.js +43 -0
- package/mechanisms/audit/runner/README.md +38 -0
- package/mechanisms/audit/runner/runner.js +546 -0
- package/mechanisms/eslint/CD-1/README.md +12 -0
- package/mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js +50 -0
- package/mechanisms/eslint/CD-1/piece.json +23 -0
- package/mechanisms/eslint/CD-10/README.md +9 -0
- package/mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js +55 -0
- package/mechanisms/eslint/CD-10/piece.json +15 -0
- package/mechanisms/eslint/CD-14/README.md +11 -0
- package/mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.js +88 -0
- package/mechanisms/eslint/CD-14/piece.json +31 -0
- package/mechanisms/eslint/CD-27/README.md +12 -0
- package/mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.js +83 -0
- package/mechanisms/eslint/CD-27/piece.json +23 -0
- package/mechanisms/eslint/CD-40/README.md +7 -0
- package/mechanisms/eslint/CD-40/cd40/cd40.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-40/piece.json +21 -0
- package/mechanisms/eslint/CD-41/README.md +12 -0
- package/mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.js +228 -0
- package/mechanisms/eslint/CD-41/piece.json +23 -0
- package/mechanisms/eslint/CD-42/README.md +9 -0
- package/mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.js +75 -0
- package/mechanisms/eslint/CD-42/piece.json +15 -0
- package/mechanisms/eslint/CD-44/README.md +7 -0
- package/mechanisms/eslint/CD-44/cd44/cd44.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-44/piece.json +20 -0
- package/mechanisms/eslint/CD-6/README.md +9 -0
- package/mechanisms/eslint/CD-6/cd6/cd6.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-6/piece.json +217 -0
- package/mechanisms/eslint/CD-7/README.md +9 -0
- package/mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.js +52 -0
- package/mechanisms/eslint/CD-7/piece.json +15 -0
- package/mechanisms/eslint/runner/README.md +43 -0
- package/mechanisms/eslint/runner/runner.js +4248 -0
- package/methods/README.md +18 -0
- package/methods/lenses/clean-architecture.md +167 -0
- package/methods/lenses/decomposition.md +159 -0
- package/methods/lenses/defended-on-intent.md +178 -0
- package/methods/lenses/di-discipline.md +156 -0
- package/methods/lenses/errors-as-data.md +88 -0
- package/methods/lenses/function-first.md +193 -0
- package/methods/lenses/naming.md +127 -0
- package/methods/lenses/test-discipline.md +166 -0
- package/methods/lenses/type-soundness.md +135 -0
- package/methods/lenses/zod-boundary.md +158 -0
- package/package.json +65 -4
- package/rules/CD-1/README.md +43 -0
- package/rules/CD-1/discipline.json +185 -0
- package/rules/CD-10/README.md +55 -0
- package/rules/CD-10/discipline.json +133 -0
- package/rules/CD-11/README.md +19 -0
- package/rules/CD-11/discipline.json +12 -0
- package/rules/CD-12/README.md +19 -0
- package/rules/CD-12/discipline.json +12 -0
- package/rules/CD-13/README.md +19 -0
- package/rules/CD-13/discipline.json +12 -0
- package/rules/CD-14/README.md +54 -0
- package/rules/CD-14/discipline.json +173 -0
- package/rules/CD-15/README.md +48 -0
- package/rules/CD-15/discipline.json +73 -0
- package/rules/CD-16/README.md +17 -0
- package/rules/CD-17/README.md +42 -0
- package/rules/CD-17/discipline.json +51 -0
- package/rules/CD-18/README.md +19 -0
- package/rules/CD-18/discipline.json +12 -0
- package/rules/CD-19/README.md +45 -0
- package/rules/CD-19/discipline.json +65 -0
- package/rules/CD-2/README.md +43 -0
- package/rules/CD-2/discipline.json +65 -0
- package/rules/CD-20/README.md +17 -0
- package/rules/CD-21/README.md +19 -0
- package/rules/CD-21/discipline.json +12 -0
- package/rules/CD-22/README.md +19 -0
- package/rules/CD-22/discipline.json +12 -0
- package/rules/CD-23/README.md +41 -0
- package/rules/CD-23/discipline.json +57 -0
- package/rules/CD-24/README.md +17 -0
- package/rules/CD-25/README.md +43 -0
- package/rules/CD-25/discipline.json +57 -0
- package/rules/CD-26/README.md +42 -0
- package/rules/CD-26/discipline.json +57 -0
- package/rules/CD-27/README.md +51 -0
- package/rules/CD-27/discipline.json +233 -0
- package/rules/CD-28/README.md +19 -0
- package/rules/CD-28/discipline.json +12 -0
- package/rules/CD-29/README.md +19 -0
- package/rules/CD-29/discipline.json +12 -0
- package/rules/CD-3/README.md +48 -0
- package/rules/CD-3/discipline.json +363 -0
- package/rules/CD-30/README.md +19 -0
- package/rules/CD-30/discipline.json +12 -0
- package/rules/CD-31/README.md +19 -0
- package/rules/CD-31/discipline.json +12 -0
- package/rules/CD-32/README.md +19 -0
- package/rules/CD-32/discipline.json +12 -0
- package/rules/CD-33/README.md +19 -0
- package/rules/CD-33/discipline.json +12 -0
- package/rules/CD-34/README.md +19 -0
- package/rules/CD-34/discipline.json +12 -0
- package/rules/CD-39/README.md +19 -0
- package/rules/CD-39/discipline.json +12 -0
- package/rules/CD-4/README.md +19 -0
- package/rules/CD-4/discipline.json +12 -0
- package/rules/CD-40/README.md +45 -0
- package/rules/CD-40/discipline.json +58 -0
- package/rules/CD-41/README.md +60 -0
- package/rules/CD-41/discipline.json +124 -0
- package/rules/CD-42/README.md +53 -0
- package/rules/CD-42/discipline.json +61 -0
- package/rules/CD-43/README.md +43 -0
- package/rules/CD-43/discipline.json +65 -0
- package/rules/CD-44/README.md +54 -0
- package/rules/CD-44/discipline.json +111 -0
- package/rules/CD-45/README.md +19 -0
- package/rules/CD-45/discipline.json +12 -0
- package/rules/CD-46/README.md +13 -0
- package/rules/CD-47/README.md +47 -0
- package/rules/CD-47/discipline.json +57 -0
- package/rules/CD-5/README.md +46 -0
- package/rules/CD-5/discipline.json +65 -0
- package/rules/CD-6/README.md +57 -0
- package/rules/CD-6/discipline.json +165 -0
- package/rules/CD-7/README.md +52 -0
- package/rules/CD-7/discipline.json +142 -0
- package/rules/CD-7a/README.md +44 -0
- package/rules/CD-7a/discipline.json +57 -0
- package/rules/CD-8/README.md +48 -0
- package/rules/CD-8/discipline.json +57 -0
- package/rules/CD-9/README.md +19 -0
- package/rules/CD-9/discipline.json +12 -0
- package/rules/README.md +52 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
folderScope
|
|
3
|
+
} from "../../../chunks/chunk-QWA6OVLC.js";
|
|
4
|
+
import "../../../chunks/chunk-NZLE2WMY.js";
|
|
5
|
+
|
|
6
|
+
// mechanisms/audit/CD-19/import-boundaries.ts
|
|
7
|
+
var sourceEligibility = (request) => {
|
|
8
|
+
if (!request.file.endsWith(".ts") && !request.file.endsWith(".tsx")) return "excluded";
|
|
9
|
+
if (folderScope({ file: request.file }) === "generated") return "excluded";
|
|
10
|
+
return "eligible";
|
|
11
|
+
};
|
|
12
|
+
var BANNED_THIRD_PARTY_IMPORTS = [
|
|
13
|
+
"eslint",
|
|
14
|
+
"winston",
|
|
15
|
+
"winston-transport",
|
|
16
|
+
"better-sqlite3",
|
|
17
|
+
"pino",
|
|
18
|
+
"hono",
|
|
19
|
+
"@hono/node-server",
|
|
20
|
+
"hono/cors",
|
|
21
|
+
"hono/cookie",
|
|
22
|
+
"hono/types",
|
|
23
|
+
"hono/utils/http-status",
|
|
24
|
+
"jose",
|
|
25
|
+
"@modelcontextprotocol/sdk",
|
|
26
|
+
"zod-to-json-schema",
|
|
27
|
+
"uuid"
|
|
28
|
+
];
|
|
29
|
+
var check = {
|
|
30
|
+
prepare: ({ clauses, syntaxApi }) => ({
|
|
31
|
+
outcome: "ok",
|
|
32
|
+
value: {
|
|
33
|
+
prepareFile: ({ file }) => {
|
|
34
|
+
if (sourceEligibility({ file }) === "excluded") return { outcome: "ok", value: { kind: "skipped" } };
|
|
35
|
+
return {
|
|
36
|
+
outcome: "ok",
|
|
37
|
+
value: {
|
|
38
|
+
kind: "syntax",
|
|
39
|
+
begin: ({ sourceFile, anchorAt }) => {
|
|
40
|
+
const rawHits = sourceFile.text.split("\n").flatMap(
|
|
41
|
+
(line, index) => BANNED_THIRD_PARTY_IMPORTS.filter(
|
|
42
|
+
(specifier) => new RegExp(`from\\s+["']${specifier.replace(/[/.]/g, "\\$&")}["']`).test(line)
|
|
43
|
+
).flatMap((specifier) => clauses.map((clause) => ({
|
|
44
|
+
clause: clause.address,
|
|
45
|
+
anchor: { line: index + 1, column: 0 },
|
|
46
|
+
snippet: `banned third-party import: ${specifier} \u2014 use its recorded wrapping boundary`
|
|
47
|
+
})))
|
|
48
|
+
);
|
|
49
|
+
const nodeHits = [];
|
|
50
|
+
const record = (specifier) => {
|
|
51
|
+
if (specifier === void 0 || !syntaxApi.isStringLiteralLike(specifier) || !specifier.text.startsWith("node:")) return;
|
|
52
|
+
const anchor = anchorAt({ position: specifier.getStart(sourceFile) });
|
|
53
|
+
const snippet = `bare node: stdlib import - use the kernel port package: ${specifier.text}`;
|
|
54
|
+
nodeHits.push(...clauses.map((clause) => ({ clause: clause.address, anchor, snippet })));
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
enter: ({ node }) => {
|
|
58
|
+
if (syntaxApi.isImportDeclaration(node) || syntaxApi.isExportDeclaration(node)) {
|
|
59
|
+
record(node.moduleSpecifier);
|
|
60
|
+
} else if (syntaxApi.isImportTypeNode(node) && syntaxApi.isLiteralTypeNode(node.argument)) {
|
|
61
|
+
record(node.argument.literal);
|
|
62
|
+
} else if (syntaxApi.isImportEqualsDeclaration(node) && syntaxApi.isExternalModuleReference(node.moduleReference)) {
|
|
63
|
+
record(node.moduleReference.expression);
|
|
64
|
+
} else if (syntaxApi.isCallExpression(node) && (node.expression.kind === syntaxApi.SyntaxKind.ImportKeyword || syntaxApi.isIdentifier(node.expression) && node.expression.text === "require")) {
|
|
65
|
+
record(node.arguments[0]);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
finish: () => [...rawHits, ...nodeHits]
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
finish: () => ({ outcome: "ok", value: [] })
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
};
|
|
78
|
+
export {
|
|
79
|
+
check
|
|
80
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
folderScope
|
|
3
|
+
} from "../../../chunks/chunk-QWA6OVLC.js";
|
|
4
|
+
import "../../../chunks/chunk-NZLE2WMY.js";
|
|
5
|
+
|
|
6
|
+
// mechanisms/audit/CD-2/cast-expressions.ts
|
|
7
|
+
var SNIPPET_MAX_LENGTH = 80;
|
|
8
|
+
var ZOD_MODULE_SPECIFIER_PATTERN = /^zod(\/.*)?$/;
|
|
9
|
+
var CD1_ANY_PATTERN = /\bas\s+any\b|:\s*any\b|<any>/;
|
|
10
|
+
var sourceEligibility = (request) => {
|
|
11
|
+
if (!request.file.endsWith(".ts") && !request.file.endsWith(".tsx")) return "excluded";
|
|
12
|
+
if (folderScope({ file: request.file }) === "generated") return "excluded";
|
|
13
|
+
return "eligible";
|
|
14
|
+
};
|
|
15
|
+
var namesImportedFromZod = (request) => new Set(
|
|
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
|
+
};
|
|
44
|
+
var check = {
|
|
45
|
+
prepare: ({ clauses, syntaxApi }) => ({
|
|
46
|
+
outcome: "ok",
|
|
47
|
+
value: {
|
|
48
|
+
prepareFile: ({ file }) => {
|
|
49
|
+
if (sourceEligibility({ file }) === "excluded") {
|
|
50
|
+
return { outcome: "ok", value: { kind: "skipped" } };
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
outcome: "ok",
|
|
54
|
+
value: {
|
|
55
|
+
kind: "syntax",
|
|
56
|
+
begin: ({ sourceFile, anchorAt }) => {
|
|
57
|
+
const zodImportedNames = namesImportedFromZod({ sourceFile, syntaxApi });
|
|
58
|
+
const hits = [];
|
|
59
|
+
return {
|
|
60
|
+
enter: ({ node }) => {
|
|
61
|
+
if (!syntaxApi.isAsExpression(node) && !syntaxApi.isTypeAssertionExpression(node)) return;
|
|
62
|
+
if (castPermission({ node, syntaxApi, zodImportedNames }) === "permitted") return;
|
|
63
|
+
const position = node.getStart(sourceFile);
|
|
64
|
+
const snippet = snippetAt({ sourceFile, position });
|
|
65
|
+
if (CD1_ANY_PATTERN.test(snippet)) return;
|
|
66
|
+
const anchor = anchorAt({ position });
|
|
67
|
+
hits.push(...clauses.map((clause) => ({ clause: clause.address, anchor, snippet })));
|
|
68
|
+
},
|
|
69
|
+
finish: () => hits
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
finish: () => ({ outcome: "ok", value: [] })
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
};
|
|
79
|
+
export {
|
|
80
|
+
check
|
|
81
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
folderScope
|
|
3
|
+
} from "../../../chunks/chunk-QWA6OVLC.js";
|
|
4
|
+
import "../../../chunks/chunk-NZLE2WMY.js";
|
|
5
|
+
|
|
6
|
+
// mechanisms/audit/CD-23/export-test-sibling.ts
|
|
7
|
+
var productionFileEligibility = (request) => {
|
|
8
|
+
const directories = request.file.split("/").slice(0, -1);
|
|
9
|
+
if (!request.file.endsWith(".ts") && !request.file.endsWith(".tsx") || request.file.endsWith(".test.ts") || request.file.endsWith(".test.tsx") || request.file.endsWith(".d.ts") || directories.includes("__tests__") || folderScope({ file: request.file }) === "generated") return "skipped";
|
|
10
|
+
return "eligible";
|
|
11
|
+
};
|
|
12
|
+
var testSiblingOf = (request) => request.file.endsWith(".tsx") ? request.file.replace(/\.tsx$/, ".test.tsx") : request.file.replace(/\.ts$/, ".test.ts");
|
|
13
|
+
var check = {
|
|
14
|
+
prepare: ({ clauses, repository, syntaxApi }) => ({
|
|
15
|
+
outcome: "ok",
|
|
16
|
+
value: {
|
|
17
|
+
prepareFile: ({ file }) => {
|
|
18
|
+
if (productionFileEligibility({ file }) === "skipped") {
|
|
19
|
+
return { outcome: "ok", value: { kind: "skipped" } };
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
outcome: "ok",
|
|
23
|
+
value: {
|
|
24
|
+
kind: "syntax",
|
|
25
|
+
begin: ({ sourceFile, anchorAt }) => {
|
|
26
|
+
const hasRuntimeExport = sourceFile.statements.some((statement) => {
|
|
27
|
+
if (syntaxApi.isExportAssignment(statement)) return true;
|
|
28
|
+
const modifierKinds = (syntaxApi.canHaveModifiers(statement) ? syntaxApi.getModifiers(statement) ?? [] : []).map((modifier) => modifier.kind);
|
|
29
|
+
if ([
|
|
30
|
+
syntaxApi.SyntaxKind.VariableStatement,
|
|
31
|
+
syntaxApi.SyntaxKind.FunctionDeclaration,
|
|
32
|
+
syntaxApi.SyntaxKind.ClassDeclaration,
|
|
33
|
+
syntaxApi.SyntaxKind.EnumDeclaration
|
|
34
|
+
].includes(statement.kind) && modifierKinds.includes(syntaxApi.SyntaxKind.ExportKeyword) && !modifierKinds.includes(syntaxApi.SyntaxKind.DeclareKeyword)) return true;
|
|
35
|
+
return syntaxApi.isExportDeclaration(statement) && !statement.isTypeOnly && statement.exportClause !== void 0 && syntaxApi.isNamedExports(statement.exportClause) && statement.exportClause.elements.some((specifier) => !specifier.isTypeOnly);
|
|
36
|
+
});
|
|
37
|
+
const sibling = testSiblingOf({ file });
|
|
38
|
+
const hasSibling = repository.files.some((candidate) => candidate === sibling);
|
|
39
|
+
return {
|
|
40
|
+
finish: () => hasRuntimeExport && !hasSibling ? clauses.map((clause) => ({
|
|
41
|
+
clause: clause.address,
|
|
42
|
+
anchor: anchorAt({ position: 0 }),
|
|
43
|
+
snippet: "missing co-located *.test.ts(x) sibling"
|
|
44
|
+
})) : []
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
finish: () => ({ outcome: "ok", value: [] })
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
check
|
|
56
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
folderScope
|
|
3
|
+
} from "../../../chunks/chunk-QWA6OVLC.js";
|
|
4
|
+
import "../../../chunks/chunk-NZLE2WMY.js";
|
|
5
|
+
|
|
6
|
+
// mechanisms/audit/CD-25/dependency-isolation.ts
|
|
7
|
+
var testFileEligibility = (request) => {
|
|
8
|
+
if (folderScope({ file: request.file }) === "generated") return "skipped";
|
|
9
|
+
return request.file.endsWith(".test.ts") || request.file.endsWith(".test.tsx") ? "eligible" : "skipped";
|
|
10
|
+
};
|
|
11
|
+
var snippetAt = (request) => {
|
|
12
|
+
const snippet = request.source.slice(request.position, request.position + 80).replace(/\n/g, " ");
|
|
13
|
+
return snippet.length === 80 ? `${snippet}\u2026` : snippet;
|
|
14
|
+
};
|
|
15
|
+
var check = {
|
|
16
|
+
prepare: ({ clauses, syntaxApi }) => ({
|
|
17
|
+
outcome: "ok",
|
|
18
|
+
value: {
|
|
19
|
+
prepareFile: ({ file }) => {
|
|
20
|
+
if (testFileEligibility({ file }) === "skipped") {
|
|
21
|
+
return { outcome: "ok", value: { kind: "skipped" } };
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
outcome: "ok",
|
|
25
|
+
value: {
|
|
26
|
+
kind: "syntax",
|
|
27
|
+
begin: ({ sourceFile, anchorAt }) => {
|
|
28
|
+
const hits = [];
|
|
29
|
+
return {
|
|
30
|
+
enter: ({ node }) => {
|
|
31
|
+
if (!syntaxApi.isCallExpression(node)) return;
|
|
32
|
+
const callee = node.expression;
|
|
33
|
+
if (!syntaxApi.isPropertyAccessExpression(callee)) return;
|
|
34
|
+
const isImplementationArgument = callee.name.text === "fn" && syntaxApi.isIdentifier(callee.expression) && callee.expression.text === "vi" && node.arguments.length > 0;
|
|
35
|
+
if (!isImplementationArgument && callee.name.text !== "mockImplementation") return;
|
|
36
|
+
const position = node.getStart(sourceFile);
|
|
37
|
+
const anchor = anchorAt({ position });
|
|
38
|
+
const snippet = snippetAt({ source: sourceFile.text, position });
|
|
39
|
+
hits.push(...clauses.map((clause) => ({ clause: clause.address, anchor, snippet })));
|
|
40
|
+
},
|
|
41
|
+
finish: () => hits
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
finish: () => ({ outcome: "ok", value: [] })
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
};
|
|
51
|
+
export {
|
|
52
|
+
check
|
|
53
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
folderScope
|
|
3
|
+
} from "../../../chunks/chunk-QWA6OVLC.js";
|
|
4
|
+
import "../../../chunks/chunk-NZLE2WMY.js";
|
|
5
|
+
|
|
6
|
+
// mechanisms/audit/CD-26/module-mocking.ts
|
|
7
|
+
var testFileEligibility = (request) => {
|
|
8
|
+
if (folderScope({ file: request.file }) === "generated") return "skipped";
|
|
9
|
+
return request.file.endsWith(".test.ts") || request.file.endsWith(".test.tsx") ? "eligible" : "skipped";
|
|
10
|
+
};
|
|
11
|
+
var snippetAt = (request) => {
|
|
12
|
+
const snippet = request.source.slice(request.position, request.position + 80).replace(/\n/g, " ");
|
|
13
|
+
return snippet.length === 80 ? `${snippet}\u2026` : snippet;
|
|
14
|
+
};
|
|
15
|
+
var check = {
|
|
16
|
+
prepare: ({ clauses, syntaxApi }) => ({
|
|
17
|
+
outcome: "ok",
|
|
18
|
+
value: {
|
|
19
|
+
prepareFile: ({ file }) => {
|
|
20
|
+
if (testFileEligibility({ file }) === "skipped") {
|
|
21
|
+
return { outcome: "ok", value: { kind: "skipped" } };
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
outcome: "ok",
|
|
25
|
+
value: {
|
|
26
|
+
kind: "syntax",
|
|
27
|
+
begin: ({ sourceFile, anchorAt }) => {
|
|
28
|
+
const hits = [];
|
|
29
|
+
return {
|
|
30
|
+
enter: ({ node }) => {
|
|
31
|
+
if (!syntaxApi.isCallExpression(node)) return;
|
|
32
|
+
const callee = node.expression;
|
|
33
|
+
if (!syntaxApi.isPropertyAccessExpression(callee) || callee.name.text !== "mock" || !syntaxApi.isIdentifier(callee.expression) || callee.expression.text !== "vi") return;
|
|
34
|
+
const position = node.getStart(sourceFile);
|
|
35
|
+
const anchor = anchorAt({ position });
|
|
36
|
+
const snippet = snippetAt({ source: sourceFile.text, position });
|
|
37
|
+
hits.push(...clauses.map((clause) => ({ clause: clause.address, anchor, snippet })));
|
|
38
|
+
},
|
|
39
|
+
finish: () => hits
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
finish: () => ({ outcome: "ok", value: [] })
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
check
|
|
51
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
folderScope
|
|
3
|
+
} from "../../../chunks/chunk-QWA6OVLC.js";
|
|
4
|
+
import "../../../chunks/chunk-NZLE2WMY.js";
|
|
5
|
+
|
|
6
|
+
// mechanisms/audit/CD-27/test-body-logic.ts
|
|
7
|
+
var testFileEligibility = (request) => {
|
|
8
|
+
if (folderScope({ file: request.file }) === "generated") return "skipped";
|
|
9
|
+
return request.file.endsWith(".test.ts") || request.file.endsWith(".test.tsx") ? "eligible" : "skipped";
|
|
10
|
+
};
|
|
11
|
+
var BANNED_DYNAMIC_METHODS = [
|
|
12
|
+
"at",
|
|
13
|
+
"charAt",
|
|
14
|
+
"charCodeAt",
|
|
15
|
+
"codePointAt",
|
|
16
|
+
"concat",
|
|
17
|
+
"endsWith",
|
|
18
|
+
"entries",
|
|
19
|
+
"every",
|
|
20
|
+
"filter",
|
|
21
|
+
"find",
|
|
22
|
+
"findIndex",
|
|
23
|
+
"findLast",
|
|
24
|
+
"findLastIndex",
|
|
25
|
+
"flat",
|
|
26
|
+
"flatMap",
|
|
27
|
+
"forEach",
|
|
28
|
+
"includes",
|
|
29
|
+
"indexOf",
|
|
30
|
+
"join",
|
|
31
|
+
"keys",
|
|
32
|
+
"lastIndexOf",
|
|
33
|
+
"localeCompare",
|
|
34
|
+
"map",
|
|
35
|
+
"match",
|
|
36
|
+
"matchAll",
|
|
37
|
+
"normalize",
|
|
38
|
+
"padEnd",
|
|
39
|
+
"padStart",
|
|
40
|
+
"reduce",
|
|
41
|
+
"reduceRight",
|
|
42
|
+
"repeat",
|
|
43
|
+
"replace",
|
|
44
|
+
"replaceAll",
|
|
45
|
+
"search",
|
|
46
|
+
"slice",
|
|
47
|
+
"some",
|
|
48
|
+
"sort",
|
|
49
|
+
"split",
|
|
50
|
+
"startsWith",
|
|
51
|
+
"substr",
|
|
52
|
+
"substring",
|
|
53
|
+
"toLocaleLowerCase",
|
|
54
|
+
"toLocaleUpperCase",
|
|
55
|
+
"toLowerCase",
|
|
56
|
+
"toReversed",
|
|
57
|
+
"toSorted",
|
|
58
|
+
"toSpliced",
|
|
59
|
+
"toUpperCase",
|
|
60
|
+
"trim",
|
|
61
|
+
"trimEnd",
|
|
62
|
+
"trimStart",
|
|
63
|
+
"values",
|
|
64
|
+
"with"
|
|
65
|
+
];
|
|
66
|
+
var BANNED_MUTATION_METHODS = ["copyWithin", "fill", "pop", "push", "reverse", "shift", "splice", "unshift"];
|
|
67
|
+
var snippetAt = (request) => {
|
|
68
|
+
const snippet = request.source.slice(request.position, request.position + 80).replace(/\n/g, " ");
|
|
69
|
+
return snippet.length === 80 ? `${snippet}\u2026` : snippet;
|
|
70
|
+
};
|
|
71
|
+
var check = {
|
|
72
|
+
prepare: ({ clauses, syntaxApi }) => ({
|
|
73
|
+
outcome: "ok",
|
|
74
|
+
value: {
|
|
75
|
+
prepareFile: ({ file }) => {
|
|
76
|
+
if (testFileEligibility({ file }) === "skipped") {
|
|
77
|
+
return { outcome: "ok", value: { kind: "skipped" } };
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
outcome: "ok",
|
|
81
|
+
value: {
|
|
82
|
+
kind: "syntax",
|
|
83
|
+
begin: ({ sourceFile, anchorAt }) => {
|
|
84
|
+
const hits = [];
|
|
85
|
+
return {
|
|
86
|
+
enter: ({ node }) => {
|
|
87
|
+
const isStructural = syntaxApi.isIfStatement(node) || syntaxApi.isTryStatement(node) || syntaxApi.isConditionalExpression(node) || syntaxApi.isVariableStatement(node) && (node.declarationList.flags & syntaxApi.NodeFlags.Let) === syntaxApi.NodeFlags.Let;
|
|
88
|
+
const methodName = syntaxApi.isCallExpression(node) && syntaxApi.isPropertyAccessExpression(node.expression) ? node.expression.name.text : void 0;
|
|
89
|
+
if (!isStructural && (methodName === void 0 || !BANNED_DYNAMIC_METHODS.includes(methodName) && !BANNED_MUTATION_METHODS.includes(methodName))) return;
|
|
90
|
+
const position = node.getStart(sourceFile);
|
|
91
|
+
const anchor = anchorAt({ position });
|
|
92
|
+
const snippet = snippetAt({ source: sourceFile.text, position });
|
|
93
|
+
hits.push(...clauses.map((clause) => ({ clause: clause.address, anchor, snippet })));
|
|
94
|
+
},
|
|
95
|
+
finish: () => hits
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
finish: () => ({ outcome: "ok", value: [] })
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
};
|
|
105
|
+
export {
|
|
106
|
+
check
|
|
107
|
+
};
|