@shivaedev/quality 0.62.0 → 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.
Files changed (107) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +20 -4
  3. package/dist/adapters/biome/run.d.ts.map +1 -1
  4. package/dist/adapters/biome/run.js +6 -2
  5. package/dist/adapters/biome/run.js.map +1 -1
  6. package/dist/adapters/databaseUrlFindings.d.ts +11 -0
  7. package/dist/adapters/databaseUrlFindings.d.ts.map +1 -0
  8. package/dist/adapters/databaseUrlFindings.js +20 -0
  9. package/dist/adapters/databaseUrlFindings.js.map +1 -0
  10. package/dist/adapters/databaseUrlReads.d.ts +3 -0
  11. package/dist/adapters/databaseUrlReads.d.ts.map +1 -0
  12. package/dist/adapters/databaseUrlReads.js +107 -0
  13. package/dist/adapters/databaseUrlReads.js.map +1 -0
  14. package/dist/adapters/imports/resolve.js +1 -1
  15. package/dist/adapters/imports/resolve.js.map +1 -1
  16. package/dist/adapters/knip/report.d.ts +3 -0
  17. package/dist/adapters/knip/report.d.ts.map +1 -0
  18. package/dist/adapters/knip/report.js +22 -0
  19. package/dist/adapters/knip/report.js.map +1 -0
  20. package/dist/adapters/knip/run.d.ts +1 -1
  21. package/dist/adapters/knip/run.d.ts.map +1 -1
  22. package/dist/adapters/knip/run.js +3 -5
  23. package/dist/adapters/knip/run.js.map +1 -1
  24. package/dist/adapters/outsideImportFindings.d.ts.map +1 -1
  25. package/dist/adapters/outsideImportFindings.js +2 -30
  26. package/dist/adapters/outsideImportFindings.js.map +1 -1
  27. package/dist/adapters/units/runtime.d.ts +6 -0
  28. package/dist/adapters/units/runtime.d.ts.map +1 -0
  29. package/dist/adapters/units/runtime.js +46 -0
  30. package/dist/adapters/units/runtime.js.map +1 -0
  31. package/dist/adapters/units/runtimeImports.d.ts +10 -0
  32. package/dist/adapters/units/runtimeImports.d.ts.map +1 -0
  33. package/dist/adapters/units/runtimeImports.js +51 -0
  34. package/dist/adapters/units/runtimeImports.js.map +1 -0
  35. package/dist/adapters/units/runtimeOrigins.d.ts +4 -0
  36. package/dist/adapters/units/runtimeOrigins.d.ts.map +1 -0
  37. package/dist/adapters/units/runtimeOrigins.js +85 -0
  38. package/dist/adapters/units/runtimeOrigins.js.map +1 -0
  39. package/dist/adapters/units/runtimeUse.d.ts +8 -0
  40. package/dist/adapters/units/runtimeUse.d.ts.map +1 -0
  41. package/dist/adapters/units/runtimeUse.js +60 -0
  42. package/dist/adapters/units/runtimeUse.js.map +1 -0
  43. package/dist/imports/extract.d.ts.map +1 -1
  44. package/dist/imports/extract.js +13 -2
  45. package/dist/imports/extract.js.map +1 -1
  46. package/dist/inventory/collect.d.ts.map +1 -1
  47. package/dist/inventory/collect.js +3 -0
  48. package/dist/inventory/collect.js.map +1 -1
  49. package/dist/inventory/skillCopies.d.ts +7 -0
  50. package/dist/inventory/skillCopies.d.ts.map +1 -0
  51. package/dist/inventory/skillCopies.js +25 -0
  52. package/dist/inventory/skillCopies.js.map +1 -0
  53. package/dist/manifests/sorted.d.ts +1 -1
  54. package/dist/manifests/sorted.d.ts.map +1 -1
  55. package/dist/manifests/sorted.js +7 -4
  56. package/dist/manifests/sorted.js.map +1 -1
  57. package/dist/rules/builtIn.d.ts +2 -2
  58. package/dist/rules/builtIn.d.ts.map +1 -1
  59. package/dist/rules/builtIn.js +4 -0
  60. package/dist/rules/builtIn.js.map +1 -1
  61. package/dist/rules/effect/adapterImports.js +1 -1
  62. package/dist/rules/effect/adapterImports.js.map +1 -1
  63. package/dist/rules/manifestsExportsShape.d.ts.map +1 -1
  64. package/dist/rules/manifestsExportsShape.js +20 -11
  65. package/dist/rules/manifestsExportsShape.js.map +1 -1
  66. package/dist/rules/manifestsNoTestKits.d.ts +2 -0
  67. package/dist/rules/manifestsNoTestKits.d.ts.map +1 -0
  68. package/dist/rules/manifestsNoTestKits.js +59 -0
  69. package/dist/rules/manifestsNoTestKits.js.map +1 -0
  70. package/dist/rules/stories/databaseUrl.d.ts +2 -0
  71. package/dist/rules/stories/databaseUrl.d.ts.map +1 -0
  72. package/dist/rules/stories/databaseUrl.js +8 -0
  73. package/dist/rules/stories/databaseUrl.js.map +1 -0
  74. package/dist/rules/stories/engineOf.d.ts.map +1 -1
  75. package/dist/rules/stories/engineOf.js +1 -0
  76. package/dist/rules/stories/engineOf.js.map +1 -1
  77. package/dist/rules/stories/specs.d.ts.map +1 -1
  78. package/dist/rules/stories/specs.js +2 -1
  79. package/dist/rules/stories/specs.js.map +1 -1
  80. package/dist/rules/stories/unitTests.d.ts +2 -2
  81. package/dist/rules/stories/unitTests.d.ts.map +1 -1
  82. package/dist/rules/stories/unitTests.js +6 -2
  83. package/dist/rules/stories/unitTests.js.map +1 -1
  84. package/package.json +5 -5
  85. package/src/adapters/biome/run.ts +6 -2
  86. package/src/adapters/databaseUrlFindings.ts +23 -0
  87. package/src/adapters/databaseUrlReads.ts +119 -0
  88. package/src/adapters/imports/resolve.ts +1 -1
  89. package/src/adapters/knip/report.ts +22 -0
  90. package/src/adapters/knip/run.ts +3 -7
  91. package/src/adapters/outsideImportFindings.ts +2 -34
  92. package/src/adapters/units/runtime.ts +53 -0
  93. package/src/adapters/units/runtimeImports.ts +60 -0
  94. package/src/adapters/units/runtimeOrigins.ts +96 -0
  95. package/src/adapters/units/runtimeUse.ts +72 -0
  96. package/src/imports/extract.ts +16 -2
  97. package/src/inventory/collect.ts +3 -0
  98. package/src/inventory/skillCopies.ts +30 -0
  99. package/src/manifests/sorted.ts +9 -8
  100. package/src/rules/builtIn.ts +4 -0
  101. package/src/rules/effect/adapterImports.ts +1 -1
  102. package/src/rules/manifestsExportsShape.ts +20 -11
  103. package/src/rules/manifestsNoTestKits.ts +73 -0
  104. package/src/rules/stories/databaseUrl.ts +8 -0
  105. package/src/rules/stories/engineOf.ts +1 -0
  106. package/src/rules/stories/specs.ts +2 -1
  107. package/src/rules/stories/unitTests.ts +10 -2
@@ -0,0 +1,22 @@
1
+ import type { Findings } from "#rule.ts";
2
+ import { knipFindings } from "./findings.ts";
3
+
4
+ export function knipReport(stdout: string, stderr: string, code: number): Findings {
5
+ let report: Findings;
6
+ let failure: string;
7
+ try {
8
+ report = knipFindings(stdout);
9
+ if (code === (report.length > 0 ? 1 : 0)) {
10
+ return report;
11
+ }
12
+ failure = `knip exited ${code} inconsistently with its report:\n${stderr || stdout}`;
13
+ } catch {
14
+ failure = `knip exited ${code} without a valid report:\n${stderr || stdout || "No output."}`;
15
+ }
16
+ return [
17
+ {
18
+ file: "package.json",
19
+ message: `Unused-code analysis did not complete. Repair the tool configuration or command failure and rerun quality lint. ${failure}`,
20
+ },
21
+ ];
22
+ }
@@ -9,7 +9,8 @@ import { shadcnFolders } from "#inventory/shadcnFolders.ts";
9
9
  import type { RuleInputs } from "#rule.ts";
10
10
  import { knipConfiguration } from "./configuration.ts";
11
11
  import { entryPointFindings } from "./entryPointFindings.ts";
12
- import { KNIP_ISSUES, knipFindings } from "./findings.ts";
12
+ import { KNIP_ISSUES } from "./findings.ts";
13
+ import { knipReport } from "./report.ts";
13
14
  import { sourceConfig } from "./sourceConfig.ts";
14
15
 
15
16
  const API = createRequire(import.meta.url).resolve("knip");
@@ -65,12 +66,7 @@ export const runKnip = Effect.fn("Knip.runKnip")(function* (inputs: RuleInputs)
65
66
  [Stream.mkString(Stream.decodeText(child.stdout)), Stream.mkString(Stream.decodeText(child.stderr)), child.exitCode],
66
67
  { concurrency: "unbounded" },
67
68
  );
68
- const report = yield* Effect.try(() => knipFindings(stdout)).pipe(
69
- Effect.mapError(() => new Error(`knip exited ${code} without a valid report:\n${stderr || stdout || "No output."}`)),
70
- );
71
- if (Number(code) !== (report.length > 0 ? 1 : 0)) {
72
- return yield* Effect.fail(new Error(`knip exited ${code} inconsistently with its report:\n${stderr || stdout}`));
73
- }
69
+ const report = knipReport(stdout, stderr, Number(code));
74
70
  return report.filter((finding) => checked.has(finding.file));
75
71
  }),
76
72
  );
@@ -1,46 +1,16 @@
1
1
  import { Effect } from "effect";
2
- import ts from "typescript";
3
2
  import type { ImportAnalysisFailure } from "#adapters/ImportAnalysisFailure.ts";
4
3
  import { readPackageManifest } from "#adapters/manifestInventory.ts";
5
4
  import { importGraph } from "#imports/graph.ts";
6
5
  import { packageNameOf } from "#imports/packageName.ts";
7
6
  import { packageOf } from "#imports/workspace.ts";
7
+ import { testName } from "#naming/testName.ts";
8
8
  import type { Finding, RuleInputs } from "#rule.ts";
9
- import { parse } from "#rules/parse.ts";
10
-
11
- function onlyInlineTypes(statement: ts.Statement): boolean {
12
- if (ts.isImportDeclaration(statement)) {
13
- const clause = statement.importClause;
14
- const bindings = clause?.namedBindings;
15
- return (
16
- clause?.name === undefined
17
- && bindings !== undefined
18
- && ts.isNamedImports(bindings)
19
- && bindings.elements.length > 0
20
- && bindings.elements.every((item) => item.isTypeOnly)
21
- );
22
- }
23
- const exports = ts.isExportDeclaration(statement) ? statement.exportClause : undefined;
24
- return exports !== undefined && ts.isNamedExports(exports) && exports.elements.length > 0 && exports.elements.every((item) => item.isTypeOnly);
25
- }
26
-
27
- function inlineTypes(inputs: RuleInputs): ReadonlySet<string> {
28
- const sites = new Set<string>();
29
- for (const file of inputs.sources) {
30
- const source = parse(file);
31
- if (source === undefined) {
32
- continue;
33
- }
34
- for (const statement of source.statements.filter(onlyInlineTypes)) {
35
- sites.add(`${file.path}:${source.getLineAndCharacterOfPosition(statement.getStart(source)).line + 1}`);
36
- }
37
- }
38
- return sites;
39
- }
40
9
 
41
10
  function exempt(path: string, name: string): boolean {
42
11
  return (
43
12
  /(?:^|\/)(?:adapters|test-support)\//u.test(path)
13
+ || (name === "vitest" && testName(path)?.modifiers.includes("unit") === true)
44
14
  || name === "effect"
45
15
  || name.startsWith("@effect/")
46
16
  || name.startsWith("@shivaedev/")
@@ -67,7 +37,6 @@ export const outsideImportFindings = Effect.fn("Imports.outsideImportFindings")(
67
37
  { concurrency: "unbounded" },
68
38
  ),
69
39
  );
70
- const types = inlineTypes(inputs);
71
40
  const workspace = new Set(graph.packages.map((owner) => owner.name));
72
41
  const sites = [
73
42
  ...graph.edges.flatMap((edge) => (edge.to.kind === "external" ? [{ ...edge, name: edge.to.package }] : [])),
@@ -81,7 +50,6 @@ export const outsideImportFindings = Effect.fn("Imports.outsideImportFindings")(
81
50
  workspace.has(site.name)
82
51
  || site.type
83
52
  || site.kind !== "import"
84
- || types.has(`${site.from}:${site.line}`)
85
53
  || exempt(site.from, site.name)
86
54
  || !(site.name.startsWith("node:") || runtime.get(directory)?.has(site.name))
87
55
  ) {
@@ -0,0 +1,53 @@
1
+ import type ts from "typescript";
2
+ import { type Trail, walkFrom } from "#imports/fences/reach.ts";
3
+ import type { ImportEdge } from "#imports/graph.ts";
4
+ import type { Finding } from "#rule.ts";
5
+ import { runtimeOrigins } from "./runtimeOrigins.ts";
6
+ import { firstRuntimeUse, type RuntimeUse } from "./runtimeUse.ts";
7
+
8
+ export const PURE_REPAIR = "Exercise the Effect behaviour through the package story kit, or test an existing pure API without the runner.";
9
+
10
+ export function runtime(checker: ts.TypeChecker, source: (path: string) => ts.SourceFile | undefined) {
11
+ const origin = runtimeOrigins(checker);
12
+ const known = new Map<string, RuntimeUse | undefined>();
13
+
14
+ function runtimeUse(module: string): RuntimeUse | undefined {
15
+ if (known.has(module)) {
16
+ return known.get(module);
17
+ }
18
+ const syntax = source(module);
19
+ const first = syntax === undefined ? undefined : firstRuntimeUse(syntax, origin);
20
+ known.set(module, first);
21
+ return first;
22
+ }
23
+
24
+ function findings(file: string, visited: ReadonlyMap<string, Trail>): readonly Finding[] {
25
+ const found: Finding[] = [];
26
+ for (const [module, trail] of visited) {
27
+ const use = runtimeUse(module);
28
+ if (use === undefined) {
29
+ continue;
30
+ }
31
+ const chain = [...trail.path.slice(1, -1), `${module}:${use.line}`].join(" -> ");
32
+ found.push({
33
+ file,
34
+ line: module === file ? use.line : trail.line,
35
+ message: `This \`.unit\` test reaches \`${use.what}\` through \`${chain}\`. ${PURE_REPAIR}`,
36
+ });
37
+ }
38
+ return found;
39
+ }
40
+
41
+ return (file: string, edgesFrom: ReadonlyMap<string, readonly ImportEdge[]>): Finding | undefined => {
42
+ const own = findings(file, new Map([[file, { line: 0, path: [file] }]]));
43
+ const imported = (edgesFrom.get(file) ?? []).flatMap((edge) => {
44
+ if (edge.to.kind !== "file") {
45
+ return [];
46
+ }
47
+ const visited = walkFrom(edge.to.path, edgesFrom, () => undefined).visited;
48
+ const trails = new Map([...visited].map(([module, trail]) => [module, { line: edge.line, path: [file, ...trail.path] }]));
49
+ return findings(file, trails);
50
+ });
51
+ return [...own, ...imported].sort((a, b) => (a.line ?? 0) - (b.line ?? 0))[0];
52
+ };
53
+ }
@@ -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
+ }
@@ -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 { kind: "import", node: statement.moduleSpecifier, type: statement.importClause?.isTypeOnly === true };
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 };
@@ -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
+ });
@@ -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 function manifestsIn(root: string): Effect.Effect<readonly string[], FilesystemFailure | SetupFailure, RuleServices> {
15
- return Effect.map(walk(root), (paths) =>
16
- paths
17
- .filter((path) => basename(path) === "package.json")
18
- .map((path) => posix(relative(root, path)))
19
- .sort(),
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);
@@ -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
  });
@@ -12,11 +12,17 @@ function isMap(value: unknown): value is Readonly<Record<string, unknown>> {
12
12
  return typeof value === "object" && value !== null && !Array.isArray(value);
13
13
  }
14
14
 
15
- function standardPattern(key: string, value: unknown): boolean {
16
- if (!(key.startsWith("./") && key.endsWith(".ts")) || key.split("*").length !== 2 || !isMap(value)) {
15
+ function standardPattern(key: string, value: unknown, sourceOnly = false): boolean {
16
+ if (!(key.startsWith("./") && key.endsWith(".ts")) || key.split("*").length !== 2) {
17
17
  return false;
18
18
  }
19
19
  const subpath = key.slice("./".length);
20
+ if (sourceOnly && value === `./src/${subpath}`) {
21
+ return true;
22
+ }
23
+ if (!isMap(value)) {
24
+ return false;
25
+ }
20
26
  const stem = subpath.slice(0, -".ts".length);
21
27
  const source = "@shivaedev/source" in value ? "@shivaedev/source" : "source";
22
28
  const conditions = { default: `./dist/${stem}.js`, [source]: `./src/${subpath}`, types: `./dist/${stem}.d.ts` };
@@ -31,20 +37,21 @@ function exactAsset(key: string, value: unknown): boolean {
31
37
  return key.startsWith("./") && !key.includes("*") && value === key && extension !== "" && !CODE_EXTENSIONS.has(extension);
32
38
  }
33
39
 
34
- function finding(file: string, subject: string, reason: string): Finding {
40
+ function finding(file: string, subject: string, reason: string, isPrivate: boolean): Finding {
41
+ const sourceOnly = isPrivate ? ' For a private package, mapping "./*.ts" directly to "./src/*.ts" is also accepted.' : "";
35
42
  return {
36
43
  file,
37
- message: `${reason} Import the module at its file path through the single "${PATTERN}" wildcard (for example, "./server/better-auth/mount.ts" for "./src/server/better-auth/mount.ts"). Map it to source "./src/*.ts", types "./dist/*.d.ts" and default "./dist/*.js"; remove aliases and per-file module exports. Non-code assets must use their exact file paths.`,
44
+ message: `${reason} Import the module at its file path through the single "${PATTERN}" wildcard (for example, "./server/better-auth/mount.ts" for "./src/server/better-auth/mount.ts"). Map it to source "./src/*.ts", types "./dist/*.d.ts" and default "./dist/*.js"; remove aliases and per-file module exports. Non-code assets must use their exact file paths.${sourceOnly}`,
38
45
  subject,
39
46
  };
40
47
  }
41
48
 
42
- function findingsIn(file: string, exports: unknown): readonly Finding[] {
49
+ function findingsIn(file: string, exports: unknown, isPrivate: boolean): readonly Finding[] {
43
50
  if (exports === undefined) {
44
51
  return [];
45
52
  }
46
53
  if (!isMap(exports)) {
47
- return [finding(file, "exports", "The exports field must be a subpath map.")];
54
+ return [finding(file, "exports", "The exports field must be a subpath map.", isPrivate)];
48
55
  }
49
56
  const entries = Object.entries(exports);
50
57
  const patterns = entries.filter(([key, value]) => key.includes("*") && value !== null);
@@ -52,16 +59,18 @@ function findingsIn(file: string, exports: unknown): readonly Finding[] {
52
59
  const count =
53
60
  patterns.length === 1 || (patterns.length === 0 && !exportsModules)
54
61
  ? []
55
- : [finding(file, "exports", `The exports field needs exactly one non-null wildcard; found ${patterns.length}.`)];
62
+ : [finding(file, "exports", `The exports field needs exactly one non-null wildcard; found ${patterns.length}.`, isPrivate)];
56
63
  return [
57
64
  ...count,
58
65
  ...entries.flatMap(([key, value]) => {
59
66
  if (value === null) {
60
- return [finding(file, key, `Export "${key}" blocks module imports with null. Remove the null entry so callers can import each module.`)];
67
+ return [
68
+ finding(file, key, `Export "${key}" blocks module imports with null. Remove the null entry so callers can import each module.`, isPrivate),
69
+ ];
61
70
  }
62
- return key === "." || exactAsset(key, value) || standardPattern(key, value)
71
+ return key === "." || exactAsset(key, value) || standardPattern(key, value, isPrivate)
63
72
  ? []
64
- : [finding(file, key, `Export "${key}" does not preserve the module's file path.`)];
73
+ : [finding(file, key, `Export "${key}" does not preserve the module's file path.`, isPrivate)];
65
74
  }),
66
75
  ];
67
76
  }
@@ -104,7 +113,7 @@ export const manifestsExportsShape = defineRule({
104
113
  if (file === "package.json" && manifest === undefined) {
105
114
  return [];
106
115
  }
107
- return [...findingsIn(file, manifest?.exports), ...importFindings(file, manifest?.imports)];
116
+ return [...findingsIn(file, manifest?.exports, manifest?.private === true), ...importFindings(file, manifest?.imports)];
108
117
  }),
109
118
  { concurrency: "unbounded" },
110
119
  );