@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.
- package/CHANGELOG.md +23 -0
- package/README.md +20 -4
- 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/manifestsExportsShape.d.ts.map +1 -1
- package/dist/rules/manifestsExportsShape.js +20 -11
- package/dist/rules/manifestsExportsShape.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/manifestsExportsShape.ts +20 -11
- 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,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 [
|