@shivaedev/quality 0.54.0 → 0.56.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 +33 -0
- package/README.md +19 -17
- package/dist/adapters/ImportCompiler.d.ts +21 -0
- package/dist/adapters/ImportCompiler.d.ts.map +1 -0
- package/dist/adapters/ImportCompiler.js +22 -0
- package/dist/adapters/ImportCompiler.js.map +1 -0
- package/dist/adapters/compileCache.config.d.ts +2 -0
- package/dist/adapters/compileCache.config.d.ts.map +1 -0
- package/dist/adapters/compileCache.config.js +3 -0
- package/dist/adapters/compileCache.config.js.map +1 -0
- package/dist/adapters/imports/browserChecker.d.ts +3 -0
- package/dist/adapters/imports/browserChecker.d.ts.map +1 -0
- package/dist/adapters/imports/browserChecker.js +8 -0
- package/dist/adapters/imports/browserChecker.js.map +1 -0
- package/dist/adapters/imports/departures.d.ts +5 -0
- package/dist/adapters/imports/departures.d.ts.map +1 -0
- package/dist/adapters/imports/departures.js +61 -0
- package/dist/adapters/imports/departures.js.map +1 -0
- package/dist/adapters/imports/graph.d.ts +4 -0
- package/dist/adapters/imports/graph.d.ts.map +1 -0
- package/dist/adapters/imports/graph.js +44 -0
- package/dist/adapters/imports/graph.js.map +1 -0
- package/dist/{imports → adapters/imports}/projects.d.ts +4 -1
- package/dist/adapters/imports/projects.d.ts.map +1 -0
- package/dist/{imports → adapters/imports}/projects.js +42 -17
- package/dist/adapters/imports/projects.js.map +1 -0
- package/dist/{imports → adapters/imports}/resolve.d.ts +3 -10
- package/dist/adapters/imports/resolve.d.ts.map +1 -0
- package/dist/{imports → adapters/imports}/resolve.js +6 -4
- package/dist/adapters/imports/resolve.js.map +1 -0
- package/dist/adapters/knip/entryPointFindings.d.ts +2 -1
- package/dist/adapters/knip/entryPointFindings.d.ts.map +1 -1
- package/dist/adapters/knip/entryPointFindings.js +7 -6
- package/dist/adapters/knip/entryPointFindings.js.map +1 -1
- 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 +1 -1
- package/dist/adapters/knip/run.js.map +1 -1
- package/dist/adapters/manifestInventory.d.ts.map +1 -1
- package/dist/adapters/manifestInventory.js +3 -1
- package/dist/adapters/manifestInventory.js.map +1 -1
- package/dist/adapters/manifestReader.d.ts +2 -2
- package/dist/adapters/manifestReader.d.ts.map +1 -1
- package/dist/adapters/manifestReader.js +2 -1
- package/dist/adapters/manifestReader.js.map +1 -1
- package/dist/adapters/rule.d.ts +9 -0
- package/dist/adapters/rule.d.ts.map +1 -0
- package/dist/adapters/rule.js +35 -0
- package/dist/adapters/rule.js.map +1 -0
- package/dist/adapters/standardSchema.d.ts.map +1 -0
- package/dist/adapters/standardSchema.js.map +1 -0
- package/dist/adapters/testProjects.d.ts.map +1 -1
- package/dist/adapters/testProjects.js +1 -0
- package/dist/adapters/testProjects.js.map +1 -1
- package/dist/biome/report.d.ts +2 -1
- package/dist/biome/report.d.ts.map +1 -1
- package/dist/biome/report.js +11 -5
- package/dist/biome/report.js.map +1 -1
- package/dist/cli/lint.d.ts.map +1 -1
- package/dist/cli/lint.js +3 -1
- package/dist/cli/lint.js.map +1 -1
- package/dist/config/decode.d.ts +2 -2
- package/dist/config/decode.d.ts.map +1 -1
- package/dist/config/decode.js +3 -2
- package/dist/config/decode.js.map +1 -1
- package/dist/config/resolve.d.ts +2 -2
- package/dist/config/resolve.d.ts.map +1 -1
- package/dist/config/resolve.js +2 -1
- package/dist/config/resolve.js.map +1 -1
- package/dist/config.d.ts +5 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/decoded.d.ts.map +1 -1
- package/dist/decoded.js +1 -1
- package/dist/decoded.js.map +1 -1
- package/dist/engine/runRules.d.ts.map +1 -1
- package/dist/engine/runRules.js +29 -6
- package/dist/engine/runRules.js.map +1 -1
- package/dist/engine/session.d.ts +3 -2
- package/dist/engine/session.d.ts.map +1 -1
- package/dist/engine/session.js +9 -6
- package/dist/engine/session.js.map +1 -1
- package/dist/exceptions/biomeFindings.d.ts +3 -0
- package/dist/exceptions/biomeFindings.d.ts.map +1 -1
- package/dist/exceptions/biomeFindings.js +21 -0
- package/dist/exceptions/biomeFindings.js.map +1 -1
- package/dist/hooks/preCommit.js +1 -1
- package/dist/hooks/preCommit.js.map +1 -1
- package/dist/imports/Endpoint.d.ts +9 -0
- package/dist/imports/Endpoint.d.ts.map +1 -0
- package/dist/imports/Endpoint.js +2 -0
- package/dist/imports/Endpoint.js.map +1 -0
- package/dist/imports/browserGlobals.d.ts +2 -1
- package/dist/imports/browserGlobals.d.ts.map +1 -1
- package/dist/imports/browserGlobals.js +6 -9
- package/dist/imports/browserGlobals.js.map +1 -1
- package/dist/imports/departures.d.ts +3 -2
- package/dist/imports/departures.d.ts.map +1 -1
- package/dist/imports/departures.js +8 -61
- package/dist/imports/departures.js.map +1 -1
- package/dist/imports/extract.d.ts +2 -1
- package/dist/imports/extract.d.ts.map +1 -1
- package/dist/imports/extract.js +11 -10
- package/dist/imports/extract.js.map +1 -1
- package/dist/imports/fences/check.d.ts +3 -2
- package/dist/imports/fences/check.d.ts.map +1 -1
- package/dist/imports/fences/check.js +5 -4
- package/dist/imports/fences/check.js.map +1 -1
- package/dist/imports/fences/compilePolicy.js.map +1 -1
- package/dist/imports/fences/match.d.ts +1 -1
- package/dist/imports/fences/match.d.ts.map +1 -1
- package/dist/imports/fences/match.js.map +1 -1
- package/dist/imports/fences/reach.d.ts +1 -1
- package/dist/imports/fences/reach.d.ts.map +1 -1
- package/dist/imports/fences/vocabulary.d.ts +1 -1
- package/dist/imports/fences/vocabulary.d.ts.map +1 -1
- package/dist/imports/graph.d.ts +6 -4
- package/dist/imports/graph.d.ts.map +1 -1
- package/dist/imports/graph.js +17 -53
- package/dist/imports/graph.js.map +1 -1
- package/dist/manifests/sorted.d.ts.map +1 -1
- package/dist/manifests/sorted.js +1 -1
- package/dist/manifests/sorted.js.map +1 -1
- package/dist/rule.d.ts +12 -8
- package/dist/rule.d.ts.map +1 -1
- package/dist/rule.js +8 -31
- package/dist/rule.js.map +1 -1
- package/dist/rules/builtIn.d.ts +1 -1
- package/dist/rules/builtIn.d.ts.map +1 -1
- package/dist/rules/builtIn.js +2 -0
- package/dist/rules/builtIn.js.map +1 -1
- package/dist/rules/effect/program.js +1 -1
- package/dist/rules/effect/program.js.map +1 -1
- package/dist/rules/imports/adminPaths.js +1 -1
- package/dist/rules/imports/adminPaths.js.map +1 -1
- package/dist/rules/imports/aliased.d.ts.map +1 -1
- package/dist/rules/imports/aliased.js +3 -2
- package/dist/rules/imports/aliased.js.map +1 -1
- package/dist/rules/imports/cycles.d.ts.map +1 -1
- package/dist/rules/imports/cycles.js +4 -3
- package/dist/rules/imports/cycles.js.map +1 -1
- package/dist/rules/imports/manifest.d.ts.map +1 -1
- package/dist/rules/imports/manifest.js +6 -5
- package/dist/rules/imports/manifest.js.map +1 -1
- package/dist/rules/imports/noTestCode.d.ts.map +1 -1
- package/dist/rules/imports/noTestCode.js +3 -2
- package/dist/rules/imports/noTestCode.js.map +1 -1
- package/dist/rules/imports/resolvable.d.ts.map +1 -1
- package/dist/rules/imports/resolvable.js +10 -7
- package/dist/rules/imports/resolvable.js.map +1 -1
- package/dist/rules/imports/runtime.d.ts.map +1 -1
- package/dist/rules/imports/runtime.js +3 -2
- package/dist/rules/imports/runtime.js.map +1 -1
- package/dist/rules/stories/collectionOrigins.d.ts +1 -1
- package/dist/rules/stories/collectionOrigins.d.ts.map +1 -1
- package/dist/rules/stories/collectionOrigins.js.map +1 -1
- package/dist/rules/stories/engine.d.ts.map +1 -1
- package/dist/rules/stories/engine.js +5 -4
- package/dist/rules/stories/engine.js.map +1 -1
- package/dist/rules/stories/engineOf.d.ts +1 -1
- package/dist/rules/stories/engineOf.d.ts.map +1 -1
- package/dist/rules/stories/globalRetries.d.ts +2 -0
- package/dist/rules/stories/globalRetries.d.ts.map +1 -0
- package/dist/rules/stories/globalRetries.js +45 -0
- package/dist/rules/stories/globalRetries.js.map +1 -0
- package/dist/rules/stories/importOrigin.d.ts +3 -1
- package/dist/rules/stories/importOrigin.d.ts.map +1 -1
- package/dist/rules/stories/importOrigin.js +15 -0
- package/dist/rules/stories/importOrigin.js.map +1 -1
- package/dist/rules/stories/noExpect.d.ts.map +1 -1
- package/dist/rules/stories/noExpect.js +4 -3
- package/dist/rules/stories/noExpect.js.map +1 -1
- package/dist/rules/stories/origins.d.ts.map +1 -1
- package/dist/rules/stories/origins.js +14 -12
- package/dist/rules/stories/origins.js.map +1 -1
- package/dist/rules/stories/retryOption.d.ts +3 -0
- package/dist/rules/stories/retryOption.d.ts.map +1 -0
- package/dist/rules/stories/retryOption.js +37 -0
- package/dist/rules/stories/retryOption.js.map +1 -0
- package/dist/rules/stories/sources.d.ts +1 -1
- package/dist/rules/stories/sources.d.ts.map +1 -1
- package/dist/rules/stories/sources.js +1 -1
- package/dist/rules/stories/sources.js.map +1 -1
- package/dist/rules/stories/specs.d.ts.map +1 -1
- package/dist/rules/stories/specs.js +5 -4
- package/dist/rules/stories/specs.js.map +1 -1
- package/package.json +5 -5
- package/src/adapters/ImportCompiler.ts +30 -0
- package/src/adapters/compileCache.config.ts +3 -0
- package/src/adapters/imports/browserChecker.ts +8 -0
- package/src/adapters/imports/departures.ts +82 -0
- package/src/adapters/imports/graph.ts +48 -0
- package/src/{imports → adapters/imports}/projects.ts +61 -27
- package/src/{imports → adapters/imports}/resolve.ts +9 -10
- package/src/adapters/knip/entryPointFindings.ts +12 -9
- package/src/adapters/knip/run.ts +1 -1
- package/src/adapters/manifestInventory.ts +3 -1
- package/src/adapters/manifestReader.ts +4 -3
- package/src/adapters/rule.ts +53 -0
- package/src/adapters/testProjects.ts +1 -0
- package/src/biome/report.ts +11 -5
- package/src/cli/lint.ts +3 -0
- package/src/config/decode.ts +5 -4
- package/src/config/resolve.ts +7 -6
- package/src/config.ts +7 -5
- package/src/decoded.ts +1 -1
- package/src/engine/runRules.ts +31 -11
- package/src/engine/session.ts +14 -13
- package/src/exceptions/biomeFindings.ts +29 -0
- package/src/hooks/preCommit.ts +1 -1
- package/src/imports/Endpoint.ts +3 -0
- package/src/imports/browserGlobals.ts +6 -10
- package/src/imports/departures.ts +9 -80
- package/src/imports/extract.ts +12 -10
- package/src/imports/fences/check.ts +6 -5
- package/src/imports/fences/compilePolicy.ts +1 -1
- package/src/imports/fences/match.ts +1 -1
- package/src/imports/fences/reach.ts +1 -1
- package/src/imports/fences/vocabulary.ts +1 -1
- package/src/imports/graph.ts +27 -60
- package/src/manifests/sorted.ts +3 -3
- package/src/rule.ts +20 -52
- package/src/rules/builtIn.ts +2 -0
- package/src/rules/effect/program.ts +1 -1
- package/src/rules/imports/adminPaths.ts +1 -1
- package/src/rules/imports/aliased.ts +10 -7
- package/src/rules/imports/cycles.ts +4 -3
- package/src/rules/imports/manifest.ts +8 -5
- package/src/rules/imports/noTestCode.ts +12 -9
- package/src/rules/imports/resolvable.ts +10 -7
- package/src/rules/imports/runtime.ts +3 -2
- package/src/rules/stories/collectionOrigins.ts +13 -1
- package/src/rules/stories/engine.ts +5 -4
- package/src/rules/stories/engineOf.ts +1 -1
- package/src/rules/stories/globalRetries.ts +50 -0
- package/src/rules/stories/importOrigin.ts +17 -0
- package/src/rules/stories/noExpect.ts +4 -3
- package/src/rules/stories/origins.ts +14 -13
- package/src/rules/stories/retryOption.ts +41 -0
- package/src/rules/stories/sources.ts +1 -1
- package/src/rules/stories/specs.ts +5 -4
- package/dist/imports/projects.d.ts.map +0 -1
- package/dist/imports/projects.js.map +0 -1
- package/dist/imports/resolve.d.ts.map +0 -1
- package/dist/imports/resolve.js.map +0 -1
- package/dist/standardSchema.d.ts.map +0 -1
- package/dist/standardSchema.js.map +0 -1
- /package/dist/{standardSchema.d.ts → adapters/standardSchema.d.ts} +0 -0
- /package/dist/{standardSchema.js → adapters/standardSchema.js} +0 -0
- /package/src/{standardSchema.ts → adapters/standardSchema.ts} +0 -0
package/src/imports/graph.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import type { RuleInputs, SourceFile } from "#rule.ts";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { type ImportKind, type ImportRequest, importsOf } from "./extract.ts";
|
|
7
|
-
import { type Project, projectsFor } from "./projects.ts";
|
|
8
|
-
import { type Endpoint, isDeclarationFile, presumedTarget, resolveImport } from "./resolve.ts";
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { ImportCompiler } from "#adapters/ImportCompiler.ts";
|
|
3
|
+
import type { Findings, RuleInputs, SourceFile } from "#rule.ts";
|
|
4
|
+
import type { Endpoint } from "./Endpoint.ts";
|
|
5
|
+
import type { ImportKind } from "./extract.ts";
|
|
9
6
|
import { type WorkspacePackage, workspacePackages } from "./workspace.ts";
|
|
10
7
|
|
|
11
8
|
export interface ImportEdge {
|
|
@@ -20,66 +17,36 @@ export interface ImportEdge {
|
|
|
20
17
|
export type UnresolvedImport = Omit<ImportEdge, "to"> & { readonly missing: string | undefined };
|
|
21
18
|
|
|
22
19
|
export interface ImportGraph {
|
|
20
|
+
readonly configFindings: Findings;
|
|
23
21
|
readonly edges: readonly ImportEdge[];
|
|
24
22
|
readonly modules: readonly string[];
|
|
25
23
|
readonly packages: readonly WorkspacePackage[];
|
|
26
24
|
readonly unresolved: readonly UnresolvedImport[];
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
"the import graph covers no modules: the sources hold no TypeScript or JavaScript module. Point `sources` at the TypeScript or JavaScript code.";
|
|
33
|
-
|
|
34
|
-
function relativeTarget(from: string, request: ImportRequest): string | undefined {
|
|
35
|
-
const relative = request.kind === "path-reference" || request.specifier.startsWith("./") || request.specifier.startsWith("../");
|
|
36
|
-
return relative ? posix.join(posix.dirname(from), request.specifier.replace(QUERY, "")) : undefined;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// A relative import or a package import of a missing file still names a path, so fences see it before its generator writes it.
|
|
40
|
-
function missingTarget(root: string, from: string, request: ImportRequest, project: Project): string | undefined {
|
|
41
|
-
const target = presumedTarget(root, request, join(root, from), project) ?? relativeTarget(from, request);
|
|
42
|
-
return target === undefined || target.startsWith("../") ? undefined : target;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function walk(inputs: RuleInputs, root: string): Pick<ImportGraph, "edges" | "modules" | "unresolved"> {
|
|
46
|
-
const projectOf = projectsFor(root);
|
|
47
|
-
const parsed = inputs.sources.flatMap((file) => {
|
|
48
|
-
const syntax = parse(file);
|
|
49
|
-
return syntax === undefined ? [] : [{ file, path: join(root, file.path), syntax }];
|
|
50
|
-
});
|
|
51
|
-
const ambient = ambientModules(parsed);
|
|
52
|
-
const edges: ImportEdge[] = [];
|
|
53
|
-
const unresolved: UnresolvedImport[] = [];
|
|
54
|
-
for (const { file, path, syntax } of parsed) {
|
|
55
|
-
const project = projectOf(path);
|
|
56
|
-
for (const request of importsOf(syntax, isDeclarationFile(file.path))) {
|
|
57
|
-
const to = resolveImport(root, ambient, request, path, project);
|
|
58
|
-
if (to === undefined) {
|
|
59
|
-
const missing = missingTarget(root, file.path, request, project);
|
|
60
|
-
unresolved.push({ ...request, from: file.path, missing });
|
|
61
|
-
edges.push(...(missing === undefined ? [] : [{ ...request, from: file.path, to: { kind: "file" as const, path: missing } }]));
|
|
62
|
-
} else {
|
|
63
|
-
edges.push({ ...request, from: file.path, to });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return { edges, modules: parsed.map(({ file }) => file.path), unresolved };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function build(inputs: RuleInputs): Promise<ImportGraph> {
|
|
71
|
-
const walked = walk(inputs, realpathSync(inputs.root));
|
|
27
|
+
const build = Effect.fn("Imports.build")(function* (inputs: RuleInputs) {
|
|
28
|
+
const compiler = yield* ImportCompiler;
|
|
29
|
+
const walked = yield* compiler.graph(inputs);
|
|
72
30
|
if (walked.modules.length === 0) {
|
|
73
|
-
|
|
31
|
+
return yield* Effect.die(
|
|
32
|
+
new Error(
|
|
33
|
+
"the import graph covers no modules: the sources hold no TypeScript or JavaScript module. Point `sources` at the TypeScript or JavaScript code.",
|
|
34
|
+
),
|
|
35
|
+
);
|
|
74
36
|
}
|
|
75
|
-
return { ...walked, packages:
|
|
76
|
-
}
|
|
37
|
+
return { ...walked, packages: yield* Effect.promise(() => workspacePackages(inputs)) };
|
|
38
|
+
});
|
|
77
39
|
|
|
78
|
-
|
|
40
|
+
type Graph = ReturnType<typeof build>;
|
|
41
|
+
const graphs = new WeakMap<readonly SourceFile[], Effect.Effect<ImportGraph, Effect.Error<Graph>>>();
|
|
79
42
|
|
|
80
43
|
// Import rules run on one scan, so they share the graph built from its sources.
|
|
81
|
-
export
|
|
82
|
-
const known = graphs.get(inputs.sources)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
44
|
+
export const importGraph = Effect.fn("Imports.importGraph")(function* (inputs: RuleInputs) {
|
|
45
|
+
const known = graphs.get(inputs.sources);
|
|
46
|
+
if (known !== undefined) {
|
|
47
|
+
return yield* known;
|
|
48
|
+
}
|
|
49
|
+
const graph = yield* Effect.cached(build(inputs).pipe(Effect.provide(ImportCompiler.layer)));
|
|
50
|
+
graphs.set(inputs.sources, graph);
|
|
51
|
+
return yield* graph;
|
|
52
|
+
});
|
package/src/manifests/sorted.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { basename, join, relative } from "node:path";
|
|
2
|
-
import { Effect, FileSystem } from "effect";
|
|
2
|
+
import { Effect, FileSystem, type Scope } from "effect";
|
|
3
3
|
import { sortPackageJson } from "sort-package-json";
|
|
4
4
|
import { ManifestFailure, manifestEntry } from "#adapters/manifestInventory.ts";
|
|
5
5
|
import { manifestReader } from "#adapters/manifestReader.ts";
|
|
@@ -27,7 +27,7 @@ export function sortingOf(text: string): Sorting {
|
|
|
27
27
|
|
|
28
28
|
export const sortManifests = Effect.fn("Manifests.sortManifests")(function* (
|
|
29
29
|
root: string,
|
|
30
|
-
): Effect.fn.Return<number, FilesystemFailure | ManifestFailure | SetupFailure, RuleServices> {
|
|
30
|
+
): Effect.fn.Return<number, FilesystemFailure | ManifestFailure | SetupFailure, RuleServices | Scope.Scope> {
|
|
31
31
|
const fs = yield* FileSystem.FileSystem;
|
|
32
32
|
const manifests = yield* manifestsIn(root);
|
|
33
33
|
const readText = yield* manifestReader(root);
|
|
@@ -57,4 +57,4 @@ export const sortManifests = Effect.fn("Manifests.sortManifests")(function* (
|
|
|
57
57
|
),
|
|
58
58
|
);
|
|
59
59
|
return written.filter(Boolean).length;
|
|
60
|
-
});
|
|
60
|
+
}, Effect.scoped);
|
package/src/rule.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Effect,
|
|
1
|
+
import type { Effect, FileSystem } from "effect";
|
|
2
2
|
import type { ChildProcessSpawner } from "effect/process";
|
|
3
|
-
import type
|
|
4
|
-
import {
|
|
3
|
+
import { configureWith, noOptions, type RuleCheckResult, ruleConfiguration } from "#adapters/rule.ts";
|
|
4
|
+
import type { StandardSchemaV1 } from "#adapters/standardSchema.ts";
|
|
5
5
|
import type { ExceptionDeclaration } from "#exceptions/declaration.ts";
|
|
6
|
-
import { describeIssue, type StandardSchemaV1 } from "./standardSchema.ts";
|
|
7
6
|
|
|
8
7
|
export interface Finding {
|
|
9
8
|
readonly count?: number | undefined;
|
|
@@ -44,21 +43,25 @@ export type Configured<TServices = RuleServices> =
|
|
|
44
43
|
| { readonly _tag: "Invalid"; readonly issues: readonly string[] }
|
|
45
44
|
| { readonly _tag: "Ready"; readonly check: RuleCheck<TServices> };
|
|
46
45
|
|
|
47
|
-
export interface
|
|
48
|
-
// Bivariance keeps rules with different options in one list; configure validates its input at runtime.
|
|
49
|
-
configure: Bivariant<(options: TInput | undefined) => Promise<Configured<TServices>>>;
|
|
46
|
+
export interface RegisteredRule<TServices = RuleServices> {
|
|
50
47
|
readonly description: string;
|
|
51
48
|
readonly family?: boolean;
|
|
52
|
-
readonly id:
|
|
49
|
+
readonly id: string;
|
|
53
50
|
readonly registrable?: boolean;
|
|
51
|
+
readonly [ruleConfiguration]: (options: unknown) => Promise<Configured<TServices>>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface Rule<TId extends string = string, TInput = unknown, TServices = RuleServices> extends RegisteredRule<TServices> {
|
|
55
|
+
readonly configure: (options: TInput | undefined) => Promise<Configured<TServices>>;
|
|
56
|
+
readonly id: TId;
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
interface RuleDefinition<TId extends string, TOptions, TServices> {
|
|
57
|
-
readonly check: (context: RuleContext<TOptions
|
|
60
|
+
readonly check: (context: RuleContext<NoInfer<TOptions>>) => RuleCheckResult<TServices>;
|
|
58
61
|
readonly description: string;
|
|
59
62
|
readonly id: TId;
|
|
60
63
|
readonly registrable?: false;
|
|
61
|
-
readonly validate?: (context: RuleContext<TOptions
|
|
64
|
+
readonly validate?: (context: RuleContext<NoInfer<TOptions>>) => readonly string[];
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
interface RuleDefinitionWithOptions<TId extends string, TInput, TOptions, TServices> extends RuleDefinition<TId, TOptions, TServices> {
|
|
@@ -69,47 +72,6 @@ interface RuleDefinitionWithoutOptions<TId extends string, TServices> extends Ru
|
|
|
69
72
|
readonly options?: undefined;
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
const noOptions: StandardSchemaV1<undefined, undefined> = {
|
|
73
|
-
"~standard": {
|
|
74
|
-
validate: (value) => (value === undefined ? { value: undefined } : { issues: [{ message: "this rule takes no options" }] }),
|
|
75
|
-
vendor: "@shivaedev/quality",
|
|
76
|
-
version: 1,
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
function configureWith<TInput, TOptions, TServices>(
|
|
81
|
-
schema: StandardSchemaV1<TInput, TOptions>,
|
|
82
|
-
check: RuleDefinition<string, TOptions, TServices>["check"],
|
|
83
|
-
id: string,
|
|
84
|
-
absent: unknown,
|
|
85
|
-
validate?: RuleDefinition<string, TOptions, TServices>["validate"],
|
|
86
|
-
) {
|
|
87
|
-
return async (options: unknown): Promise<Configured<TServices>> => {
|
|
88
|
-
const result = await schema["~standard"].validate(options ?? absent);
|
|
89
|
-
if (result.issues !== undefined) {
|
|
90
|
-
return { _tag: "Invalid", issues: result.issues.map(describeIssue) };
|
|
91
|
-
}
|
|
92
|
-
const value = result.value;
|
|
93
|
-
return {
|
|
94
|
-
_tag: "Ready",
|
|
95
|
-
check: (inputs) =>
|
|
96
|
-
Effect.scoped(
|
|
97
|
-
Effect.gen(function* () {
|
|
98
|
-
const context = { ...inputs, options: value };
|
|
99
|
-
const issues = validate?.(context).map((issue) => `rules.${id}.options: ${issue}`) ?? [];
|
|
100
|
-
yield* validOrFail(
|
|
101
|
-
inputs.configFile ?? "quality.config.ts",
|
|
102
|
-
issues.length === 0 ? { _tag: "Valid", value: undefined } : { _tag: "Invalid", issues },
|
|
103
|
-
);
|
|
104
|
-
const signal = yield* Effect.abortSignal;
|
|
105
|
-
const checked = check({ ...inputs, options: value, signal });
|
|
106
|
-
return yield* Effect.isEffect(checked) ? checked : Effect.promise(() => Promise.resolve(checked));
|
|
107
|
-
}),
|
|
108
|
-
),
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
75
|
export function defineRule<const TId extends string, TInput, TOptions, TServices = never>(
|
|
114
76
|
definition: RuleDefinitionWithOptions<TId, TInput, TOptions, TServices>,
|
|
115
77
|
): Rule<TId, TInput, TServices>;
|
|
@@ -123,5 +85,11 @@ export function defineRule<const TId extends string, TInput, TOptions, TServices
|
|
|
123
85
|
definition.options === undefined
|
|
124
86
|
? configureWith(noOptions, definition.check, definition.id, undefined, definition.validate)
|
|
125
87
|
: configureWith(definition.options, definition.check, definition.id, {}, definition.validate);
|
|
126
|
-
return {
|
|
88
|
+
return {
|
|
89
|
+
[ruleConfiguration]: configure,
|
|
90
|
+
configure,
|
|
91
|
+
description: definition.description,
|
|
92
|
+
id: definition.id,
|
|
93
|
+
registrable: definition.registrable ?? true,
|
|
94
|
+
};
|
|
127
95
|
}
|
package/src/rules/builtIn.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { jsxConditionals } from "#rules/react/jsxConditionals.ts";
|
|
|
26
26
|
import { authSql } from "#rules/stories/authSql.ts";
|
|
27
27
|
import { domainOutcomes } from "#rules/stories/domainOutcomes.ts";
|
|
28
28
|
import { storyEngine } from "#rules/stories/engine.ts";
|
|
29
|
+
import { globalRetries } from "#rules/stories/globalRetries.ts";
|
|
29
30
|
import { groupedOutcomes } from "#rules/stories/groupedOutcomes.ts";
|
|
30
31
|
import { httpStatus } from "#rules/stories/httpStatus.ts";
|
|
31
32
|
import { namedValues } from "#rules/stories/namedValues.ts";
|
|
@@ -99,6 +100,7 @@ export const builtInRules = [
|
|
|
99
100
|
testsColocated,
|
|
100
101
|
storySetup,
|
|
101
102
|
storySpecs,
|
|
103
|
+
globalRetries,
|
|
102
104
|
storyEngine,
|
|
103
105
|
queueSql,
|
|
104
106
|
authSql,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import { projectsFor } from "#imports/projects.ts";
|
|
3
|
+
import { projectsFor } from "#adapters/imports/projects.ts";
|
|
4
4
|
import type { RuleInputs } from "#rule.ts";
|
|
5
5
|
|
|
6
6
|
export function effectProgram(inputs: RuleInputs, externalTypes = true): ts.Program {
|
|
@@ -4,7 +4,7 @@ import { importGraph } from "#imports/graph.ts";
|
|
|
4
4
|
import { defineRule } from "#rule.ts";
|
|
5
5
|
|
|
6
6
|
export const adminPaths = defineRule({
|
|
7
|
-
check: (inputs) =>
|
|
7
|
+
check: (inputs) => importGraph(inputs).pipe(Effect.map((graph) => adminFindings(graph, inputs.sources))),
|
|
8
8
|
description:
|
|
9
9
|
"Admin-only source files live under an admin/ segment; member code cannot reach admin/ implementations. Registration and module composition may import admin registrations and declarations. Move the file to the folder named by the finding.",
|
|
10
10
|
id: "imports/admin-paths",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
1
2
|
import { type Departure, departures } from "#imports/departures.ts";
|
|
2
3
|
import { defineRule } from "#rule.ts";
|
|
3
4
|
|
|
@@ -13,13 +14,15 @@ function messageOf({ installed, specifier, workspace }: Departure): string {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export const importsAliased = defineRule({
|
|
16
|
-
check:
|
|
17
|
-
(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
check: (inputs) =>
|
|
18
|
+
Effect.map(departures(inputs), (found) =>
|
|
19
|
+
found.map((departure) => ({
|
|
20
|
+
file: departure.file,
|
|
21
|
+
line: departure.line,
|
|
22
|
+
message: messageOf(departure),
|
|
23
|
+
subject: departure.specifier,
|
|
24
|
+
})),
|
|
25
|
+
),
|
|
23
26
|
description:
|
|
24
27
|
"A relative import names only a file in its own folder, except a module's client or server registration may import its own ./admin/ subtree. Every other import goes through an alias: the package.json `imports` of its package or another workspace package's name.",
|
|
25
28
|
id: "imports/aliased",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
1
2
|
import { cyclicComponents } from "#imports/cyclicComponents.ts";
|
|
2
3
|
import { type ImportEdge, importGraph } from "#imports/graph.ts";
|
|
3
4
|
import { shortestPath } from "#imports/shortestPath.ts";
|
|
@@ -33,11 +34,11 @@ function findingOf(edges: readonly RuntimeEdge[], adjacency: ReadonlyMap<string,
|
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
export const importCycles = defineRule({
|
|
36
|
-
check:
|
|
37
|
-
const edges = (
|
|
37
|
+
check: Effect.fn("Imports.check")(function* (inputs) {
|
|
38
|
+
const edges = (yield* importGraph(inputs)).edges.filter(isRuntime);
|
|
38
39
|
const adjacency = runtimeAdjacency(edges);
|
|
39
40
|
return cyclicComponents(adjacency).map((component) => findingOf(edges, adjacency, component));
|
|
40
|
-
},
|
|
41
|
+
}),
|
|
41
42
|
description: "Modules never import each other in a loop at runtime. A group of modules that reach one another counts once for each module in it.",
|
|
42
43
|
id: "imports/cycles",
|
|
43
44
|
registrable: false,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
|
+
import { Effect } from "effect";
|
|
2
3
|
import { readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
3
4
|
import { type ImportGraph, importGraph } from "#imports/graph.ts";
|
|
4
5
|
import { isTooling } from "#imports/isTooling.ts";
|
|
@@ -85,14 +86,16 @@ function undeclared(owner: WorkspacePackage, policy: ManifestDependencies | unde
|
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
export const importsManifest = defineRule({
|
|
88
|
-
check:
|
|
89
|
-
const graph =
|
|
89
|
+
check: Effect.fn("Imports.check")(function* (inputs) {
|
|
90
|
+
const graph = yield* importGraph(inputs);
|
|
90
91
|
const root: WorkspacePackage | undefined =
|
|
91
|
-
(
|
|
92
|
+
(yield* Effect.promise(() => readPackageManifest(inputs.readText, "package.json"))) === undefined ? undefined : { directory: ".", name: "." };
|
|
92
93
|
const owners = [...graph.packages, ...(root === undefined ? [] : [root])];
|
|
93
94
|
const workspace = new Map(graph.packages.map((owner) => [owner.name, owner.directory]));
|
|
94
95
|
const policies = new Map(
|
|
95
|
-
|
|
96
|
+
yield* Effect.promise(() =>
|
|
97
|
+
Promise.all(owners.map(async (owner) => [owner, await manifestDependencies(inputs, owner, graph, workspace)] as const)),
|
|
98
|
+
),
|
|
96
99
|
);
|
|
97
100
|
const runtime = new Set([...policies.values()].flatMap((policy) => [...policy.runtime]));
|
|
98
101
|
const named = new Map(graph.packages.map((owner) => [owner.name, owner]));
|
|
@@ -112,7 +115,7 @@ export const importsManifest = defineRule({
|
|
|
112
115
|
}
|
|
113
116
|
return [{ file: request.from, line: request.line, message: undeclared(owner, policy, target.name, development), subject: target.name }];
|
|
114
117
|
});
|
|
115
|
-
},
|
|
118
|
+
}),
|
|
116
119
|
description:
|
|
117
120
|
"Workspace imports follow the importing package's manifest; devDependencies are available only outside runtime code, including export-blocked bundle inputs, and an application also reaches the dependencies of the entry points it declares: @shivaedev/platform for any code and @shivaedev/test-story for test code.",
|
|
118
121
|
id: "imports/manifest",
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
1
2
|
import { importGraph } from "#imports/graph.ts";
|
|
2
3
|
import { isTestCode } from "#naming/testName.ts";
|
|
3
4
|
import { defineRule } from "#rule.ts";
|
|
4
5
|
|
|
5
6
|
export const noTestCode = defineRule({
|
|
6
|
-
check:
|
|
7
|
-
(
|
|
8
|
-
.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
check: (inputs) =>
|
|
8
|
+
Effect.map(importGraph(inputs), (graph) =>
|
|
9
|
+
graph.edges
|
|
10
|
+
.filter((edge) => !isTestCode(edge.from) && edge.to.kind === "file" && isTestCode(edge.to.path))
|
|
11
|
+
.map((edge) => ({
|
|
12
|
+
file: edge.from,
|
|
13
|
+
line: edge.line,
|
|
14
|
+
message: `Imports test code through "${edge.specifier}". Move the shared code into a production module and import it from both production and tests.`,
|
|
15
|
+
subject: edge.specifier,
|
|
16
|
+
})),
|
|
17
|
+
),
|
|
15
18
|
description: "Production modules import production code. Move shared code out of test files and test-support/ into a production module.",
|
|
16
19
|
id: "imports/no-test-code",
|
|
17
20
|
registrable: false,
|
|
@@ -9,14 +9,17 @@ const ResolvableOptions = Schema.Struct({
|
|
|
9
9
|
|
|
10
10
|
export const importsResolvable = defineRule({
|
|
11
11
|
check: Effect.fn("Imports.check")(function* ({ options, ...inputs }) {
|
|
12
|
-
const graph = yield*
|
|
12
|
+
const graph = yield* importGraph(inputs);
|
|
13
13
|
const unresolved = yield* withoutGenerated(inputs, graph, options.generated);
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
return [
|
|
15
|
+
...graph.configFindings,
|
|
16
|
+
...unresolved.map((request) => ({
|
|
17
|
+
file: request.from,
|
|
18
|
+
line: request.line,
|
|
19
|
+
message: `Cannot resolve "${request.specifier}". Fix the path, install or declare the package, or declare the module in a .d.ts file among the sources.`,
|
|
20
|
+
subject: request.specifier,
|
|
21
|
+
})),
|
|
22
|
+
];
|
|
20
23
|
}),
|
|
21
24
|
description: "Every import resolves to a file, a package or a declared module, so no edge of the import graph goes unchecked.",
|
|
22
25
|
id: "imports/resolvable",
|
|
@@ -38,7 +38,7 @@ function runtimeFindings(graph: ImportGraph, runtime: (path: string) => Runtime
|
|
|
38
38
|
export const importsRuntime = defineRule({
|
|
39
39
|
check: (inputs) =>
|
|
40
40
|
Effect.gen(function* () {
|
|
41
|
-
const graph = yield*
|
|
41
|
+
const graph = yield* importGraph(inputs);
|
|
42
42
|
const runtime = yield* runtimeOf(inputs, graph.packages);
|
|
43
43
|
const imports = [...runtimeFindings(graph, runtime), ...inputs.sources.flatMap(nodePlatformBarrels)];
|
|
44
44
|
const declarations = (yield* runtimeDeclarationProblems(inputs, graph.packages)).map(({ directory, message }) => ({
|
|
@@ -52,7 +52,8 @@ export const importsRuntime = defineRule({
|
|
|
52
52
|
return [...imports, ...declarations];
|
|
53
53
|
}
|
|
54
54
|
const { browserGlobals } = yield* Effect.promise(() => import("#imports/browserGlobals.ts"));
|
|
55
|
-
|
|
55
|
+
const globals = yield* Effect.forEach(shared, browserGlobals);
|
|
56
|
+
return [...imports, ...declarations, ...globals.flat()];
|
|
56
57
|
}),
|
|
57
58
|
description:
|
|
58
59
|
"Runtime folders define client, server and shared code. A manifest's quality.runtime declares a single-runtime package whole; executable packages without runtime folders and package-root tooling are server code. Production imports use @effect/platform-node module subpaths so its barrel does not load optional integrations.",
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
-
export type Origin =
|
|
3
|
+
export type Origin =
|
|
4
|
+
| "factory"
|
|
5
|
+
| "kit"
|
|
6
|
+
| "story"
|
|
7
|
+
| "plain"
|
|
8
|
+
| "suite"
|
|
9
|
+
| "vitest"
|
|
10
|
+
| "stories"
|
|
11
|
+
| "effectFactory"
|
|
12
|
+
| "effectKit"
|
|
13
|
+
| "function"
|
|
14
|
+
| readonly Origin[]
|
|
15
|
+
| undefined;
|
|
4
16
|
|
|
5
17
|
export function commonOrigin(values: readonly Origin[]): Origin {
|
|
6
18
|
const first = values[0];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
1
2
|
import ts from "typescript";
|
|
2
3
|
import { importGraph } from "#imports/graph.ts";
|
|
3
4
|
import { packageOf } from "#imports/workspace.ts";
|
|
@@ -21,9 +22,9 @@ function ignoresEngine(call: ts.CallExpression, checker: ts.TypeChecker): boolea
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export const storyEngine = defineRule({
|
|
24
|
-
check:
|
|
25
|
-
const graph =
|
|
26
|
-
const exempt =
|
|
25
|
+
check: Effect.fn("Stories.check")(function* (inputs) {
|
|
26
|
+
const graph = yield* importGraph(inputs);
|
|
27
|
+
const exempt = yield* Effect.promise(() => storyPrerequisites(inputs, graph.packages));
|
|
27
28
|
const origins = storyOrigins(inputs, graph);
|
|
28
29
|
return inputs.sources.flatMap((file) => {
|
|
29
30
|
const name = testName(file.path);
|
|
@@ -49,7 +50,7 @@ export const storyEngine = defineRule({
|
|
|
49
50
|
message: `Declares a story without traits whose body never references its verbs, its story or its test context. Drive the engine through one of the kit's verbs or traits. If the code under test is pure, move the test to ${name.stem}.unit.${name.kind}${name.extension}, which reaches no engine and mocks nothing. See https://github.com/ShivaeDev/platform/tree/main/packages/quality#story-tests.`,
|
|
50
51
|
}));
|
|
51
52
|
});
|
|
52
|
-
},
|
|
53
|
+
}),
|
|
53
54
|
description:
|
|
54
55
|
"A story without traits references its kit's verbs, its story or its test context; pure tests belong in .unit files that reach no engine and mock nothing.",
|
|
55
56
|
id: "tests/story-engine",
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { importGraph } from "#imports/graph.ts";
|
|
4
|
+
import { defineRule } from "#rule.ts";
|
|
5
|
+
import type { Origin } from "./collectionOrigins.ts";
|
|
6
|
+
import { storyOrigins } from "./origins.ts";
|
|
7
|
+
import { retryOption } from "./retryOption.ts";
|
|
8
|
+
import { memberName, nodesWhere } from "./syntax.ts";
|
|
9
|
+
|
|
10
|
+
const BUILDERS = new Set(["each", "for", "extend", "runIf", "skipIf", "layer"]);
|
|
11
|
+
const MESSAGE =
|
|
12
|
+
"Declares a test or suite retry. Remove the retry option: retries are global only and recorded by vitest-rerun, so flakes stay visible.";
|
|
13
|
+
|
|
14
|
+
function optionsOf(call: ts.CallExpression, origin: Origin): readonly ts.Expression[] {
|
|
15
|
+
if (origin === "story") {
|
|
16
|
+
return call.arguments.slice(3, 4);
|
|
17
|
+
}
|
|
18
|
+
return origin === "plain" || origin === "suite" ? call.arguments.slice(1, 3) : [];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const globalRetries = defineRule({
|
|
22
|
+
check: (inputs) =>
|
|
23
|
+
Effect.gen(function* () {
|
|
24
|
+
const graph = yield* importGraph(inputs);
|
|
25
|
+
const origins = storyOrigins(inputs, graph);
|
|
26
|
+
const retry = retryOption(origins.checker);
|
|
27
|
+
return inputs.sources.flatMap((file) => {
|
|
28
|
+
const source = origins.source(file.path);
|
|
29
|
+
if (source === undefined) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
const findings = nodesWhere(source, (node) => {
|
|
33
|
+
if (!ts.isCallExpression(node) || BUILDERS.has(memberName(node.expression) ?? "")) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (!node.arguments.slice(1, 4).some((argument) => retry(argument))) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return optionsOf(node, origins.origin(node.expression)).some((argument) => retry(argument));
|
|
40
|
+
});
|
|
41
|
+
return findings.map((node) => ({
|
|
42
|
+
file: file.path,
|
|
43
|
+
line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1,
|
|
44
|
+
message: MESSAGE,
|
|
45
|
+
}));
|
|
46
|
+
});
|
|
47
|
+
}),
|
|
48
|
+
description: "Test, suite and story retries are global only and recorded by vitest-rerun; registrations declare no retry option.",
|
|
49
|
+
id: "tests/global-retries",
|
|
50
|
+
});
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export function importFrom(node: ts.Node): string | undefined {
|
|
4
|
+
for (let current: ts.Node | undefined = node; current !== undefined; current = current.parent) {
|
|
5
|
+
if (ts.isImportDeclaration(current) && ts.isStringLiteral(current.moduleSpecifier)) {
|
|
6
|
+
return current.moduleSpecifier.text;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
1
12
|
function moduleOrigin(from: string | undefined) {
|
|
2
13
|
if (from === "vitest" || from === "@effect/vitest") {
|
|
3
14
|
return "vitest";
|
|
@@ -6,6 +17,12 @@ function moduleOrigin(from: string | undefined) {
|
|
|
6
17
|
}
|
|
7
18
|
|
|
8
19
|
export function importOrigin(from: string | undefined, name?: string) {
|
|
20
|
+
if (from === "@shivaedev/test/makeEffectIt.ts" && name === "makeEffectIt") {
|
|
21
|
+
return "effectFactory";
|
|
22
|
+
}
|
|
23
|
+
if (from === "@shivaedev/test/it.ts" && name === "it") {
|
|
24
|
+
return "plain";
|
|
25
|
+
}
|
|
9
26
|
const namespace = moduleOrigin(from);
|
|
10
27
|
if (name === undefined) {
|
|
11
28
|
return namespace;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
1
2
|
import ts from "typescript";
|
|
2
3
|
import { importGraph } from "#imports/graph.ts";
|
|
3
4
|
import { isTestSupport } from "#naming/testName.ts";
|
|
@@ -35,17 +36,17 @@ function assertionsIn(source: ts.SourceFile): readonly ts.Node[] {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export const noExpect = defineRule({
|
|
38
|
-
check:
|
|
39
|
+
check: Effect.fn("Stories.check")(function* (inputs) {
|
|
39
40
|
const support = inputs.sources.filter((file) => isTestSupport(file.path));
|
|
40
41
|
if (support.length === 0) {
|
|
41
42
|
return [];
|
|
42
43
|
}
|
|
43
|
-
const graph =
|
|
44
|
+
const graph = yield* importGraph(inputs);
|
|
44
45
|
const imported = new Set(graph.edges.flatMap((edge) => (edge.kind === "import" && edge.to.kind === "file" ? [edge.to.path] : [])));
|
|
45
46
|
return support.flatMap((file) =>
|
|
46
47
|
syntaxFindings(file, (source) => (!imported.has(file.path) && registersTests(source) ? [] : assertionsIn(source)), MESSAGE),
|
|
47
48
|
);
|
|
48
|
-
},
|
|
49
|
+
}),
|
|
49
50
|
description: "Test-support performs actions and exposes observations; specs own expectations.",
|
|
50
51
|
id: "tests/no-expect-in-support",
|
|
51
52
|
});
|