@shivaedev/quality 0.62.1 → 0.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +19 -3
- package/dist/adapters/biome/run.d.ts.map +1 -1
- package/dist/adapters/biome/run.js +6 -2
- package/dist/adapters/biome/run.js.map +1 -1
- package/dist/adapters/databaseUrlFindings.d.ts +11 -0
- package/dist/adapters/databaseUrlFindings.d.ts.map +1 -0
- package/dist/adapters/databaseUrlFindings.js +20 -0
- package/dist/adapters/databaseUrlFindings.js.map +1 -0
- package/dist/adapters/databaseUrlReads.d.ts +3 -0
- package/dist/adapters/databaseUrlReads.d.ts.map +1 -0
- package/dist/adapters/databaseUrlReads.js +107 -0
- package/dist/adapters/databaseUrlReads.js.map +1 -0
- package/dist/adapters/imports/resolve.js +1 -1
- package/dist/adapters/imports/resolve.js.map +1 -1
- package/dist/adapters/knip/report.d.ts +3 -0
- package/dist/adapters/knip/report.d.ts.map +1 -0
- package/dist/adapters/knip/report.js +22 -0
- package/dist/adapters/knip/report.js.map +1 -0
- package/dist/adapters/knip/run.d.ts +1 -1
- package/dist/adapters/knip/run.d.ts.map +1 -1
- package/dist/adapters/knip/run.js +3 -5
- package/dist/adapters/knip/run.js.map +1 -1
- package/dist/adapters/outsideImportFindings.d.ts.map +1 -1
- package/dist/adapters/outsideImportFindings.js +2 -30
- package/dist/adapters/outsideImportFindings.js.map +1 -1
- package/dist/adapters/units/runtime.d.ts +6 -0
- package/dist/adapters/units/runtime.d.ts.map +1 -0
- package/dist/adapters/units/runtime.js +46 -0
- package/dist/adapters/units/runtime.js.map +1 -0
- package/dist/adapters/units/runtimeImports.d.ts +10 -0
- package/dist/adapters/units/runtimeImports.d.ts.map +1 -0
- package/dist/adapters/units/runtimeImports.js +51 -0
- package/dist/adapters/units/runtimeImports.js.map +1 -0
- package/dist/adapters/units/runtimeOrigins.d.ts +4 -0
- package/dist/adapters/units/runtimeOrigins.d.ts.map +1 -0
- package/dist/adapters/units/runtimeOrigins.js +85 -0
- package/dist/adapters/units/runtimeOrigins.js.map +1 -0
- package/dist/adapters/units/runtimeUse.d.ts +8 -0
- package/dist/adapters/units/runtimeUse.d.ts.map +1 -0
- package/dist/adapters/units/runtimeUse.js +60 -0
- package/dist/adapters/units/runtimeUse.js.map +1 -0
- package/dist/imports/extract.d.ts.map +1 -1
- package/dist/imports/extract.js +13 -2
- package/dist/imports/extract.js.map +1 -1
- package/dist/inventory/collect.d.ts.map +1 -1
- package/dist/inventory/collect.js +3 -0
- package/dist/inventory/collect.js.map +1 -1
- package/dist/inventory/skillCopies.d.ts +7 -0
- package/dist/inventory/skillCopies.d.ts.map +1 -0
- package/dist/inventory/skillCopies.js +25 -0
- package/dist/inventory/skillCopies.js.map +1 -0
- package/dist/manifests/sorted.d.ts +1 -1
- package/dist/manifests/sorted.d.ts.map +1 -1
- package/dist/manifests/sorted.js +7 -4
- package/dist/manifests/sorted.js.map +1 -1
- package/dist/rules/builtIn.d.ts +2 -2
- package/dist/rules/builtIn.d.ts.map +1 -1
- package/dist/rules/builtIn.js +4 -0
- package/dist/rules/builtIn.js.map +1 -1
- package/dist/rules/effect/adapterImports.js +1 -1
- package/dist/rules/effect/adapterImports.js.map +1 -1
- package/dist/rules/manifestsNoTestKits.d.ts +2 -0
- package/dist/rules/manifestsNoTestKits.d.ts.map +1 -0
- package/dist/rules/manifestsNoTestKits.js +59 -0
- package/dist/rules/manifestsNoTestKits.js.map +1 -0
- package/dist/rules/stories/databaseUrl.d.ts +2 -0
- package/dist/rules/stories/databaseUrl.d.ts.map +1 -0
- package/dist/rules/stories/databaseUrl.js +8 -0
- package/dist/rules/stories/databaseUrl.js.map +1 -0
- package/dist/rules/stories/engineOf.d.ts.map +1 -1
- package/dist/rules/stories/engineOf.js +1 -0
- package/dist/rules/stories/engineOf.js.map +1 -1
- package/dist/rules/stories/specs.d.ts.map +1 -1
- package/dist/rules/stories/specs.js +2 -1
- package/dist/rules/stories/specs.js.map +1 -1
- package/dist/rules/stories/unitTests.d.ts +2 -2
- package/dist/rules/stories/unitTests.d.ts.map +1 -1
- package/dist/rules/stories/unitTests.js +6 -2
- package/dist/rules/stories/unitTests.js.map +1 -1
- package/package.json +5 -5
- package/src/adapters/biome/run.ts +6 -2
- package/src/adapters/databaseUrlFindings.ts +23 -0
- package/src/adapters/databaseUrlReads.ts +119 -0
- package/src/adapters/imports/resolve.ts +1 -1
- package/src/adapters/knip/report.ts +22 -0
- package/src/adapters/knip/run.ts +3 -7
- package/src/adapters/outsideImportFindings.ts +2 -34
- package/src/adapters/units/runtime.ts +53 -0
- package/src/adapters/units/runtimeImports.ts +60 -0
- package/src/adapters/units/runtimeOrigins.ts +96 -0
- package/src/adapters/units/runtimeUse.ts +72 -0
- package/src/imports/extract.ts +16 -2
- package/src/inventory/collect.ts +3 -0
- package/src/inventory/skillCopies.ts +30 -0
- package/src/manifests/sorted.ts +9 -8
- package/src/rules/builtIn.ts +4 -0
- package/src/rules/effect/adapterImports.ts +1 -1
- package/src/rules/manifestsNoTestKits.ts +73 -0
- package/src/rules/stories/databaseUrl.ts +8 -0
- package/src/rules/stories/engineOf.ts +1 -0
- package/src/rules/stories/specs.ts +2 -1
- package/src/rules/stories/unitTests.ts +10 -2
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { importFrom } from "#rules/stories/importOrigin.ts";
|
|
3
|
+
|
|
4
|
+
export interface RuntimeName {
|
|
5
|
+
readonly module: string;
|
|
6
|
+
readonly path: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function runtimeImport(module: string | undefined, path: readonly string[]): RuntimeName | undefined {
|
|
10
|
+
if (module === undefined || !(module === "effect" || module.startsWith("effect/") || module === "@effect/vitest")) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const subpath = /^effect\/(?:testing\/)?(?<name>Effect|Clock|TestClock)$/u.exec(module)?.groups?.name;
|
|
14
|
+
return subpath === undefined ? { module: module === "effect/testing" ? "effect" : module, path } : { module: "effect", path: [subpath, ...path] };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function assignedRuntime(node: ts.ImportEqualsDeclaration): RuntimeName | undefined {
|
|
18
|
+
if (node.isTypeOnly || !ts.isExternalModuleReference(node.moduleReference)) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const module = node.moduleReference.expression;
|
|
22
|
+
return module !== undefined && ts.isStringLiteralLike(module) ? runtimeImport(module.text, []) : undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function importedRuntime(node: ts.Node): RuntimeName | undefined {
|
|
26
|
+
if (ts.isImportSpecifier(node)) {
|
|
27
|
+
return node.isTypeOnly || node.parent.parent.isTypeOnly ? undefined : runtimeImport(importFrom(node), [(node.propertyName ?? node.name).text]);
|
|
28
|
+
}
|
|
29
|
+
if (ts.isNamespaceImport(node)) {
|
|
30
|
+
return node.parent.isTypeOnly ? undefined : runtimeImport(importFrom(node), []);
|
|
31
|
+
}
|
|
32
|
+
return ts.isImportEqualsDeclaration(node) ? assignedRuntime(node) : undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function exportedRuntime(node: ts.ExportSpecifier | ts.NamespaceExport): RuntimeName | undefined {
|
|
36
|
+
const statement = ts.isExportSpecifier(node) ? node.parent.parent : node.parent;
|
|
37
|
+
if (statement.isTypeOnly || (ts.isExportSpecifier(node) && node.isTypeOnly)) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const module = statement.moduleSpecifier;
|
|
41
|
+
return module !== undefined && ts.isStringLiteral(module)
|
|
42
|
+
? runtimeImport(module.text, ts.isExportSpecifier(node) ? [(node.propertyName ?? node.name).text] : [])
|
|
43
|
+
: undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function runtimeOf(name: RuntimeName | undefined): string | undefined {
|
|
47
|
+
if (name?.module === "effect") {
|
|
48
|
+
const [head, property] = name.path;
|
|
49
|
+
if (head === "Clock" || head === "TestClock") {
|
|
50
|
+
return name.path.join(".");
|
|
51
|
+
}
|
|
52
|
+
return head === "Effect" && property?.startsWith("run") === true ? `Effect.${property}` : undefined;
|
|
53
|
+
}
|
|
54
|
+
const [head, property] = name?.path ?? [];
|
|
55
|
+
return name?.module === "@effect/vitest"
|
|
56
|
+
&& (head === "it" || head === "test")
|
|
57
|
+
&& ["effect", "live", "scoped", "scopedLive"].includes(property ?? "")
|
|
58
|
+
? `${head}.${property}`
|
|
59
|
+
: undefined;
|
|
60
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { memberName } from "#rules/stories/syntax.ts";
|
|
3
|
+
import { exportedRuntime, importedRuntime, type RuntimeName, runtimeImport } from "./runtimeImports.ts";
|
|
4
|
+
|
|
5
|
+
function member(receiver: RuntimeName | undefined, name: string): RuntimeName | undefined {
|
|
6
|
+
return receiver === undefined ? undefined : { ...receiver, path: [...receiver.path, name] };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function loadedModule(node: ts.CallExpression): RuntimeName | undefined {
|
|
10
|
+
if (!(node.expression.kind === ts.SyntaxKind.ImportKeyword || (ts.isIdentifier(node.expression) && node.expression.text === "require"))) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const [argument] = node.arguments;
|
|
14
|
+
return argument !== undefined && ts.isStringLiteralLike(argument) ? runtimeImport(argument.text, []) : undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function runtimeOrigins(checker: ts.TypeChecker): (node: ts.Node) => RuntimeName | undefined {
|
|
18
|
+
const known = new Map<ts.Node, RuntimeName | undefined>();
|
|
19
|
+
const visiting = new Set<ts.Node>();
|
|
20
|
+
|
|
21
|
+
function symbol(value: ts.Symbol | undefined): RuntimeName | undefined {
|
|
22
|
+
const direct = value?.declarations?.map(visit).find((name) => name !== undefined);
|
|
23
|
+
return direct ?? (value !== undefined && value.flags & ts.SymbolFlags.Alias ? symbol(checker.getAliasedSymbol(value)) : undefined);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function binding(node: ts.BindingElement): RuntimeName | undefined {
|
|
27
|
+
if (!ts.isObjectBindingPattern(node.parent)) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const name = node.propertyName ?? node.name;
|
|
31
|
+
return ts.isIdentifier(name) || ts.isStringLiteralLike(name) ? member(visit(node.parent.parent), name.text) : undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function declaration(node: ts.Node): RuntimeName | undefined {
|
|
35
|
+
if (ts.isExportSpecifier(node)) {
|
|
36
|
+
return exportedRuntime(node);
|
|
37
|
+
}
|
|
38
|
+
if (ts.isNamespaceExport(node)) {
|
|
39
|
+
return exportedRuntime(node);
|
|
40
|
+
}
|
|
41
|
+
if (ts.isVariableDeclaration(node)) {
|
|
42
|
+
return node.initializer === undefined ? undefined : visit(node.initializer);
|
|
43
|
+
}
|
|
44
|
+
return ts.isBindingElement(node) ? binding(node) : importedRuntime(node);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function nameOf(node: ts.PropertyAccessExpression | ts.ElementAccessExpression): string {
|
|
48
|
+
const name = memberName(node);
|
|
49
|
+
if (name !== undefined || ts.isPropertyAccessExpression(node)) {
|
|
50
|
+
return name ?? "";
|
|
51
|
+
}
|
|
52
|
+
const key = checker.getTypeAtLocation(node.argumentExpression);
|
|
53
|
+
return key.isStringLiteral() ? key.value : "";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function property(node: ts.PropertyAccessExpression | ts.ElementAccessExpression): RuntimeName | undefined {
|
|
57
|
+
const direct = member(visit(node.expression), nameOf(node));
|
|
58
|
+
if (direct !== undefined) {
|
|
59
|
+
return direct;
|
|
60
|
+
}
|
|
61
|
+
const receiver = ts.isIdentifier(node.expression) ? checker.getSymbolAtLocation(node.expression) : undefined;
|
|
62
|
+
const namespace = receiver?.declarations?.some(ts.isNamespaceImport) === true;
|
|
63
|
+
return namespace ? symbol(checker.getSymbolAtLocation(ts.isPropertyAccessExpression(node) ? node.name : node.argumentExpression)) : undefined;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function origin(node: ts.Node): RuntimeName | undefined {
|
|
67
|
+
if (ts.isIdentifier(node)) {
|
|
68
|
+
return symbol(checker.getSymbolAtLocation(node));
|
|
69
|
+
}
|
|
70
|
+
if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) {
|
|
71
|
+
return property(node);
|
|
72
|
+
}
|
|
73
|
+
if (
|
|
74
|
+
ts.isParenthesizedExpression(node)
|
|
75
|
+
|| ts.isAsExpression(node)
|
|
76
|
+
|| ts.isSatisfiesExpression(node)
|
|
77
|
+
|| ts.isNonNullExpression(node)
|
|
78
|
+
|| ts.isAwaitExpression(node)
|
|
79
|
+
) {
|
|
80
|
+
return visit(node.expression);
|
|
81
|
+
}
|
|
82
|
+
return ts.isCallExpression(node) ? loadedModule(node) : declaration(node);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function visit(node: ts.Node): RuntimeName | undefined {
|
|
86
|
+
if (known.has(node) || visiting.has(node)) {
|
|
87
|
+
return known.get(node);
|
|
88
|
+
}
|
|
89
|
+
visiting.add(node);
|
|
90
|
+
const name = origin(node);
|
|
91
|
+
visiting.delete(node);
|
|
92
|
+
known.set(node, name);
|
|
93
|
+
return name;
|
|
94
|
+
}
|
|
95
|
+
return visit;
|
|
96
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { type RuntimeName, runtimeImport, runtimeOf } from "./runtimeImports.ts";
|
|
3
|
+
|
|
4
|
+
function moduleRuntime(node: ts.Node): string | undefined {
|
|
5
|
+
if (ts.isImportDeclaration(node) && node.importClause === undefined && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
6
|
+
return runtimeOf(runtimeImport(node.moduleSpecifier.text, []));
|
|
7
|
+
}
|
|
8
|
+
if (
|
|
9
|
+
!(
|
|
10
|
+
ts.isExportDeclaration(node)
|
|
11
|
+
&& node.exportClause === undefined
|
|
12
|
+
&& node.moduleSpecifier !== undefined
|
|
13
|
+
&& ts.isStringLiteral(node.moduleSpecifier)
|
|
14
|
+
)
|
|
15
|
+
) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const module = node.moduleSpecifier.text;
|
|
19
|
+
if (module === "effect" || module === "effect/Effect") {
|
|
20
|
+
return module === "effect" ? "Clock" : "Effect.run*";
|
|
21
|
+
}
|
|
22
|
+
return runtimeOf(runtimeImport(module, []));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function runtimeAt(node: ts.Node, origin: (node: ts.Node) => RuntimeName | undefined): string | undefined {
|
|
26
|
+
const fromModule = moduleRuntime(node);
|
|
27
|
+
if (fromModule !== undefined) {
|
|
28
|
+
return fromModule;
|
|
29
|
+
}
|
|
30
|
+
if (ts.isCallExpression(node)) {
|
|
31
|
+
return runtimeOf(origin(node.expression)) ?? runtimeOf(origin(node));
|
|
32
|
+
}
|
|
33
|
+
return runtimeOf(origin(node));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface RuntimeUse {
|
|
37
|
+
readonly line: number;
|
|
38
|
+
readonly what: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function typeOnly(node: ts.Node): boolean {
|
|
42
|
+
if (ts.isTypeNode(node)) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return ts.isImportClause(node)
|
|
46
|
+
|| ts.isExportDeclaration(node)
|
|
47
|
+
|| ts.isImportEqualsDeclaration(node)
|
|
48
|
+
|| ts.isImportSpecifier(node)
|
|
49
|
+
|| ts.isExportSpecifier(node)
|
|
50
|
+
? node.isTypeOnly
|
|
51
|
+
: false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function firstRuntimeUse(source: ts.SourceFile, origin: (node: ts.Node) => RuntimeName | undefined): RuntimeUse | undefined {
|
|
55
|
+
let first: RuntimeUse | undefined;
|
|
56
|
+
function visit(node: ts.Node): void {
|
|
57
|
+
if (first !== undefined || typeOnly(node) || (ts.isIdentifier(node) && ts.isImportClause(node.parent))) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const what = runtimeAt(node, origin);
|
|
61
|
+
if (what !== undefined) {
|
|
62
|
+
first = { line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1, what };
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (ts.isImportSpecifier(node) || ts.isNamespaceImport(node) || ts.isImportEqualsDeclaration(node) || ts.isExportSpecifier(node)) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
ts.forEachChild(node, visit);
|
|
69
|
+
}
|
|
70
|
+
visit(source);
|
|
71
|
+
return first;
|
|
72
|
+
}
|
package/src/imports/extract.ts
CHANGED
|
@@ -24,12 +24,26 @@ function lineAt(source: ts.SourceFile, position: number): number {
|
|
|
24
24
|
return source.getLineAndCharacterOfPosition(position).line + 1;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
function typeBindings(bindings: ts.NamedImportBindings | ts.NamedExportBindings | undefined, defaultName?: ts.Identifier): boolean {
|
|
28
|
+
return (
|
|
29
|
+
defaultName === undefined
|
|
30
|
+
&& bindings !== undefined
|
|
31
|
+
&& (ts.isNamedImports(bindings) || ts.isNamedExports(bindings))
|
|
32
|
+
&& bindings.elements.length > 0
|
|
33
|
+
&& bindings.elements.every((element) => element.isTypeOnly)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
27
37
|
function declared(statement: ts.Statement): Found | undefined {
|
|
28
38
|
if (ts.isImportDeclaration(statement)) {
|
|
29
|
-
return {
|
|
39
|
+
return {
|
|
40
|
+
kind: "import",
|
|
41
|
+
node: statement.moduleSpecifier,
|
|
42
|
+
type: statement.importClause?.isTypeOnly === true || typeBindings(statement.importClause?.namedBindings, statement.importClause?.name),
|
|
43
|
+
};
|
|
30
44
|
}
|
|
31
45
|
if (ts.isExportDeclaration(statement)) {
|
|
32
|
-
return { kind: "import", node: statement.moduleSpecifier, type: statement.isTypeOnly };
|
|
46
|
+
return { kind: "import", node: statement.moduleSpecifier, type: statement.isTypeOnly || typeBindings(statement.exportClause) };
|
|
33
47
|
}
|
|
34
48
|
if (ts.isImportEqualsDeclaration(statement) && ts.isExternalModuleReference(statement.moduleReference)) {
|
|
35
49
|
return { kind: "import", node: statement.moduleReference.expression, type: statement.isTypeOnly };
|
package/src/inventory/collect.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { FilesystemFailure, orWhenAbsent, readRequiredText } from "./filesystem.
|
|
|
8
8
|
import { posix } from "./ignoreScope.ts";
|
|
9
9
|
import { linesOf } from "./linesOf.ts";
|
|
10
10
|
import { shadcnFiles } from "./shadcnFiles.ts";
|
|
11
|
+
import { skillCopies } from "./skillCopies.ts";
|
|
11
12
|
import { scopeAbove, walk } from "./walk.ts";
|
|
12
13
|
|
|
13
14
|
export interface InventoryScope {
|
|
@@ -50,11 +51,13 @@ export const collectInventory = Effect.fn("Inventory.collectInventory")(function
|
|
|
50
51
|
): Effect.fn.Return<Inventory, FilesystemFailure | SetupFailure, RuleServices> {
|
|
51
52
|
const excluded = ignorePatterns([...scope.exclude]);
|
|
52
53
|
const toolOwned = new Set(yield* shadcnFiles(root));
|
|
54
|
+
const copies = yield* skillCopies(root);
|
|
53
55
|
const zones = yield* Effect.forEach(scope.sources, (zone) => zoneFiles(root, zone), { concurrency: READ_CONCURRENCY });
|
|
54
56
|
const relativePaths = zones.flat().map((absolute) => posix(relative(root, absolute)));
|
|
55
57
|
const files = [...new Set(relativePaths)]
|
|
56
58
|
.filter((path) => !excluded.ignores(path))
|
|
57
59
|
.filter((path) => !toolOwned.has(path))
|
|
60
|
+
.filter((path) => !copies.owns(join(root, path)))
|
|
58
61
|
.sort((left, right) => {
|
|
59
62
|
if (left === right) {
|
|
60
63
|
return 0;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as NodePath from "@effect/platform-node/NodePath";
|
|
2
|
+
import { Effect, Option, Path } from "effect";
|
|
3
|
+
import { AGENTS_SKILLS, CLAUDE_SKILLS, MANIFEST } from "@shivaedev/skills/layout.ts";
|
|
4
|
+
import { readManifest } from "@shivaedev/skills/manifest.ts";
|
|
5
|
+
import { FilesystemFailure } from "#inventory/filesystem.ts";
|
|
6
|
+
import { posix } from "#inventory/ignoreScope.ts";
|
|
7
|
+
import { walk } from "#inventory/walk.ts";
|
|
8
|
+
|
|
9
|
+
export const skillCopies = Effect.fn("Inventory.skillCopies")(function* (root: string) {
|
|
10
|
+
const { dirname, join, sep } = yield* Path.Path.pipe(Effect.provide(NodePath.layer));
|
|
11
|
+
const paths = yield* walk(root);
|
|
12
|
+
const manifests = paths.filter((path) => posix(path).endsWith(`/${MANIFEST}`));
|
|
13
|
+
const owned = yield* Effect.forEach(manifests, (file) =>
|
|
14
|
+
Effect.gen(function* () {
|
|
15
|
+
const repo = dirname(dirname(dirname(file)));
|
|
16
|
+
const manifest = yield* readManifest(repo).pipe(
|
|
17
|
+
Effect.provide(NodePath.layer),
|
|
18
|
+
Effect.mapError((cause) => new FilesystemFailure({ message: cause.message, path: file })),
|
|
19
|
+
);
|
|
20
|
+
return Option.isNone(manifest)
|
|
21
|
+
? []
|
|
22
|
+
: [file, ...Object.keys(manifest.value.skills).flatMap((name) => [join(repo, AGENTS_SKILLS, name), join(repo, CLAUDE_SKILLS, name)])];
|
|
23
|
+
}),
|
|
24
|
+
);
|
|
25
|
+
const prefixes = owned.flat();
|
|
26
|
+
return {
|
|
27
|
+
owns: (path: string) => prefixes.some((prefix) => path === prefix || path.startsWith(`${prefix}${sep}`)),
|
|
28
|
+
paths: prefixes,
|
|
29
|
+
};
|
|
30
|
+
});
|
package/src/manifests/sorted.ts
CHANGED
|
@@ -6,19 +6,20 @@ import { manifestReader } from "#adapters/manifestReader.ts";
|
|
|
6
6
|
import type { SetupFailure } from "#failure.ts";
|
|
7
7
|
import { FilesystemFailure } from "#inventory/filesystem.ts";
|
|
8
8
|
import { posix } from "#inventory/ignoreScope.ts";
|
|
9
|
+
import { skillCopies } from "#inventory/skillCopies.ts";
|
|
9
10
|
import { walk } from "#inventory/walk.ts";
|
|
10
11
|
import type { RuleServices } from "#rule.ts";
|
|
11
12
|
|
|
12
13
|
export type Sorting = { readonly _tag: "Sorted" } | { readonly _tag: "Unsorted"; readonly sorted: string };
|
|
13
14
|
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
15
|
+
export const manifestsIn = Effect.fn("Manifests.manifestsIn")(function* (root: string) {
|
|
16
|
+
const copies = yield* skillCopies(root);
|
|
17
|
+
return (yield* walk(root))
|
|
18
|
+
.filter((path) => basename(path) === "package.json")
|
|
19
|
+
.filter((path) => !copies.owns(path))
|
|
20
|
+
.map((path) => posix(relative(root, path)))
|
|
21
|
+
.sort();
|
|
22
|
+
});
|
|
22
23
|
|
|
23
24
|
export function sortingOf(text: string): Sorting {
|
|
24
25
|
const sorted = sortPackageJson(text);
|
package/src/rules/builtIn.ts
CHANGED
|
@@ -35,6 +35,7 @@ import { importsRuntime } from "#rules/imports/runtime.ts";
|
|
|
35
35
|
import { jsxConditionals } from "#rules/react/jsxConditionals.ts";
|
|
36
36
|
import { adapterOnlyFakes } from "#rules/stories/adapterOnlyFakes.ts";
|
|
37
37
|
import { authSql } from "#rules/stories/authSql.ts";
|
|
38
|
+
import { databaseUrl } from "#rules/stories/databaseUrl.ts";
|
|
38
39
|
import { domainOutcomes } from "#rules/stories/domainOutcomes.ts";
|
|
39
40
|
import { storyEngine } from "#rules/stories/engine.ts";
|
|
40
41
|
import { globalRetries } from "#rules/stories/globalRetries.ts";
|
|
@@ -62,6 +63,7 @@ import { biome } from "./biome.ts";
|
|
|
62
63
|
import { manifestsApplication } from "./manifestsApplication.ts";
|
|
63
64
|
import { manifestsDependencyPins } from "./manifestsDependencyPins.ts";
|
|
64
65
|
import { manifestsExportsShape } from "./manifestsExportsShape.ts";
|
|
66
|
+
import { manifestsNoTestKits } from "./manifestsNoTestKits.ts";
|
|
65
67
|
import { manifestsSorted } from "./manifestsSorted.ts";
|
|
66
68
|
import { manifestsSourceFirst } from "./manifestsSourceFirst.ts";
|
|
67
69
|
import { manifestsValid } from "./manifestsValid.ts";
|
|
@@ -117,6 +119,7 @@ export const builtInRules = [
|
|
|
117
119
|
manifestsSorted,
|
|
118
120
|
manifestsSourceFirst,
|
|
119
121
|
manifestsExportsShape,
|
|
122
|
+
manifestsNoTestKits,
|
|
120
123
|
manifestsApplication,
|
|
121
124
|
namedAfterExport,
|
|
122
125
|
folderNames,
|
|
@@ -128,6 +131,7 @@ export const builtInRules = [
|
|
|
128
131
|
storySpecs,
|
|
129
132
|
adapterOnlyFakes,
|
|
130
133
|
globalRetries,
|
|
134
|
+
databaseUrl,
|
|
131
135
|
storyEngine,
|
|
132
136
|
queueSql,
|
|
133
137
|
queueReadouts,
|
|
@@ -4,7 +4,7 @@ import { defineRule } from "#rule.ts";
|
|
|
4
4
|
export const adapterImports = defineRule({
|
|
5
5
|
check: outsideImportFindings,
|
|
6
6
|
description:
|
|
7
|
-
"Keep value imports of non-Effect runtime dependencies, peers, optional dependencies and Node builtins in adapters/. Type-only imports, workspace modules, test-support/ kits, Effect and @shivaedev packages and React in client/ folders are accepted. Move integrations into adapters/ and expose Effect values. No config exceptions or inline suppressions; baseline existing debt.",
|
|
7
|
+
"Keep value imports of non-Effect runtime dependencies, peers, optional dependencies and Node builtins in adapters/. Type-only imports, workspace modules, test-support/ kits, Effect and @shivaedev packages and React in client/ folders and Vitest in unit tests are accepted. Move integrations into adapters/ and expose Effect values. No config exceptions or inline suppressions; baseline existing debt.",
|
|
8
8
|
id: "effect/adapter-imports",
|
|
9
9
|
registrable: false,
|
|
10
10
|
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { manifestFiles, readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
3
|
+
import { exportedModule, exportTargets } from "#imports/packageExports.ts";
|
|
4
|
+
import { SHIPPED_FIELDS } from "#manifests/entryPoints.ts";
|
|
5
|
+
import { isTestCode } from "#naming/testName.ts";
|
|
6
|
+
import type { PackageManifest } from "#PackageManifest.ts";
|
|
7
|
+
import { defineRule, type Finding, type RuleInputs } from "#rule.ts";
|
|
8
|
+
|
|
9
|
+
const TEST_PACKAGES = new Set(["@shivaedev/test", "@shivaedev/test-story", "@shivaedev/test-sql", "@shivaedev/test-kits", "vitest"]);
|
|
10
|
+
|
|
11
|
+
const TEST_TOOLING = new Set([...TEST_PACKAGES, "@shivaedev/quality", "@shivaedev/vitest-rerun"]);
|
|
12
|
+
|
|
13
|
+
function testingModule(path: string): boolean {
|
|
14
|
+
return isTestCode(path) || /(?:^|\/)(?:testing|test-support)(?:\/|\.|$)/u.test(path);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function testingExports(exports: unknown): readonly string[] {
|
|
18
|
+
if (typeof exports !== "object" || exports === null || Array.isArray(exports)) {
|
|
19
|
+
return exportTargets(exports).filter(testingModule);
|
|
20
|
+
}
|
|
21
|
+
return Object.entries(exports).flatMap(([key, value]) => {
|
|
22
|
+
const targets = exportTargets(value);
|
|
23
|
+
if (targets.length === 0) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
return testingModule(key) ? [key] : targets.filter(testingModule);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function findingsIn(inputs: RuleInputs, path: string, manifest: PackageManifest): readonly Finding[] {
|
|
31
|
+
if (manifest.private === true || TEST_TOOLING.has(manifest.name ?? "")) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
const directory = path.slice(0, -"package.json".length);
|
|
35
|
+
const modules = inputs.files
|
|
36
|
+
.filter((file) => file.startsWith(directory))
|
|
37
|
+
.map((file) => file.slice(directory.length))
|
|
38
|
+
.filter((file) => /(?:^|\/)testing(?:\/|\.|$)/u.test(file) && exportedModule(manifest.exports, file));
|
|
39
|
+
const main = manifest.main !== undefined && testingModule(manifest.main) ? [manifest.main] : [];
|
|
40
|
+
const exports = [...new Set([...testingExports(manifest.exports), ...main, ...modules])];
|
|
41
|
+
const name = manifest.name ?? path;
|
|
42
|
+
const repair = "Move the helper into @shivaedev/test-kits and keep test dependencies in devDependencies.";
|
|
43
|
+
return [
|
|
44
|
+
...(exports.length === 0
|
|
45
|
+
? []
|
|
46
|
+
: [{ file: path, message: `Runtime package "${name}" publishes testing modules: ${exports.join(", ")}. ${repair}`, subject: "exports" }]),
|
|
47
|
+
...SHIPPED_FIELDS.flatMap((field) =>
|
|
48
|
+
Object.keys(manifest[field] ?? {})
|
|
49
|
+
.filter((dependency) => TEST_PACKAGES.has(dependency))
|
|
50
|
+
.map((dependency) => ({
|
|
51
|
+
file: path,
|
|
52
|
+
message: `Runtime package "${name}" declares test package "${dependency}" in ${field}. ${repair}`,
|
|
53
|
+
subject: `${field}.${dependency}`,
|
|
54
|
+
})),
|
|
55
|
+
),
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const manifestsNoTestKits = defineRule({
|
|
60
|
+
check: (inputs) =>
|
|
61
|
+
Effect.gen(function* () {
|
|
62
|
+
const findings = yield* Effect.forEach(manifestFiles(inputs), (path) =>
|
|
63
|
+
Effect.map(
|
|
64
|
+
Effect.promise(() => readPackageManifest(inputs.readText, path)),
|
|
65
|
+
(manifest) => (manifest === undefined ? [] : findingsIn(inputs, path, manifest)),
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
return findings.flat();
|
|
69
|
+
}),
|
|
70
|
+
description: "Runtime packages publish no testing modules and ship no test-package dependencies or peers. Move reusable helpers into test-kits.",
|
|
71
|
+
id: "manifests/no-test-kits",
|
|
72
|
+
registrable: false,
|
|
73
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { databaseUrlFindings } from "#adapters/databaseUrlFindings.ts";
|
|
2
|
+
import { defineRule } from "#rule.ts";
|
|
3
|
+
|
|
4
|
+
export const databaseUrl = defineRule({
|
|
5
|
+
check: databaseUrlFindings,
|
|
6
|
+
description: "Test-support reads PostgreSQL test URLs through postgresTestUrl so CI cannot silently skip PostgreSQL coverage.",
|
|
7
|
+
id: "tests/database-url",
|
|
8
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Endpoint } from "#imports/Endpoint.ts";
|
|
2
2
|
|
|
3
3
|
const ENGINES: ReadonlyArray<readonly [string, readonly string[]]> = [
|
|
4
|
+
["an Effect test runner", ["@shivaedev/test/adapters/it.ts", "@shivaedev/test/adapters/makeEffectIt.ts"]],
|
|
4
5
|
["the file system", ["node:fs"]],
|
|
5
6
|
[
|
|
6
7
|
"the network",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
+
import { runtime } from "#adapters/units/runtime.ts";
|
|
3
4
|
import { importGraph } from "#imports/graph.ts";
|
|
4
5
|
import { packageOf } from "#imports/workspace.ts";
|
|
5
6
|
import { testName } from "#naming/testName.ts";
|
|
@@ -62,7 +63,7 @@ export const storySpecs = defineRule({
|
|
|
62
63
|
const graph = yield* importGraph(inputs);
|
|
63
64
|
const exempt = yield* Effect.promise(() => storyPrerequisites(inputs, graph.packages));
|
|
64
65
|
const origins = storyOrigins(inputs, graph);
|
|
65
|
-
const unit = unitTests(graph, inputs.sources);
|
|
66
|
+
const unit = unitTests(graph, inputs.sources, runtime(origins.checker, origins.source));
|
|
66
67
|
return inputs.sources.flatMap((file) => {
|
|
67
68
|
const name = testName(file.path);
|
|
68
69
|
if (name?.modifiers.includes("unit") === true) {
|
|
@@ -43,7 +43,7 @@ function reachFinding(file: string, reached: Reached<string>): Finding {
|
|
|
43
43
|
function standMessage(stand: Stand): string {
|
|
44
44
|
return stand.why === "mocks"
|
|
45
45
|
? `mocks with ${stand.what}. A unit test calls real code with real values and stands nothing in for a collaborator.`
|
|
46
|
-
: `provides services with ${stand.what}. A unit test
|
|
46
|
+
: `provides services with ${stand.what}. A unit test uses plain Vitest it and pure APIs without an Effect runner or clock.`;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
function where(file: string, module: string, trail: Trail): string {
|
|
@@ -75,10 +75,18 @@ function syntaxFindings(file: string, module: string, trail: Trail, source: Sour
|
|
|
75
75
|
return [...stands, ...dom];
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
export function unitTests(
|
|
78
|
+
export function unitTests(
|
|
79
|
+
graph: ImportGraph,
|
|
80
|
+
sources: readonly SourceFile[],
|
|
81
|
+
runtime: (file: string, edgesFrom: ReadonlyMap<string, readonly ImportEdge[]>) => Finding | undefined,
|
|
82
|
+
): (file: string) => readonly Finding[] {
|
|
79
83
|
const byPath = new Map(sources.map((source) => [source.path, source]));
|
|
80
84
|
const edgesFrom = runtimeEdges(graph, byPath);
|
|
81
85
|
return (file) => {
|
|
86
|
+
const reachedRuntime = runtime(file, edgesFrom);
|
|
87
|
+
if (reachedRuntime !== undefined) {
|
|
88
|
+
return [reachedRuntime];
|
|
89
|
+
}
|
|
82
90
|
const walked = walkFrom(file, edgesFrom, engineOf);
|
|
83
91
|
const checked = [...walked.visited].filter(([module]) => module === file || isTestSupport(module));
|
|
84
92
|
return [
|