@shivaedev/quality 0.73.3 → 0.74.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 +10 -0
- package/README.md +8 -0
- package/dist/adapters/buildEntryPaths.d.ts +1 -1
- package/dist/adapters/buildEntryPaths.d.ts.map +1 -1
- package/dist/adapters/buildEntryPaths.js +9 -6
- package/dist/adapters/buildEntryPaths.js.map +1 -1
- package/dist/adapters/bundlerEntries.d.ts.map +1 -1
- package/dist/adapters/bundlerEntries.js +6 -6
- package/dist/adapters/bundlerEntries.js.map +1 -1
- package/dist/adapters/knip/configuration.d.ts +2 -1
- package/dist/adapters/knip/configuration.d.ts.map +1 -1
- package/dist/adapters/knip/configuration.js +29 -4
- package/dist/adapters/knip/configuration.js.map +1 -1
- package/dist/adapters/knip/run.d.ts.map +1 -1
- package/dist/adapters/knip/run.js +8 -3
- package/dist/adapters/knip/run.js.map +1 -1
- package/dist/adapters/spawnedEntries.d.ts.map +1 -1
- package/dist/adapters/spawnedEntries.js +4 -5
- package/dist/adapters/spawnedEntries.js.map +1 -1
- package/dist/config/decode.d.ts +1 -0
- package/dist/config/decode.d.ts.map +1 -1
- package/dist/config/decode.js +1 -0
- package/dist/config/decode.js.map +1 -1
- package/dist/config/load.d.ts +1 -0
- package/dist/config/load.d.ts.map +1 -1
- package/dist/config/load.js +1 -0
- package/dist/config/load.js.map +1 -1
- package/dist/config/resolve.d.ts +1 -0
- package/dist/config/resolve.d.ts.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/engine/session.d.ts.map +1 -1
- package/dist/engine/session.js +1 -0
- package/dist/engine/session.js.map +1 -1
- package/dist/rule.d.ts +1 -0
- package/dist/rule.d.ts.map +1 -1
- package/dist/rule.js.map +1 -1
- package/dist/testing/ruleChecks.d.ts +16 -0
- package/dist/testing/ruleChecks.d.ts.map +1 -0
- package/dist/testing/ruleChecks.js +42 -0
- package/dist/testing/ruleChecks.js.map +1 -0
- package/dist/testing/ruleStory.d.ts +7 -11
- package/dist/testing/ruleStory.d.ts.map +1 -1
- package/dist/testing/ruleStory.js +3 -19
- package/dist/testing/ruleStory.js.map +1 -1
- package/package.json +3 -3
- package/src/adapters/buildEntryPaths.ts +10 -6
- package/src/adapters/bundlerEntries.ts +6 -10
- package/src/adapters/knip/configuration.ts +35 -4
- package/src/adapters/knip/run.ts +8 -3
- package/src/adapters/spawnedEntries.ts +4 -5
- package/src/config/decode.ts +1 -0
- package/src/config/load.ts +2 -0
- package/src/config.ts +1 -0
- package/src/engine/session.ts +1 -0
- package/src/rule.ts +1 -0
- package/src/testing/ruleChecks.ts +57 -0
- package/src/testing/ruleStory.ts +4 -26
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Effect, Path } from "effect";
|
|
2
|
+
import type { Findings, RegisteredRule, Rule } from "#rule.ts";
|
|
3
|
+
import type { Run } from "#testing/adapters/cli.ts";
|
|
4
|
+
export interface RuleEngine {
|
|
5
|
+
answer: Run | undefined;
|
|
6
|
+
failure: string | undefined;
|
|
7
|
+
findings: Findings | undefined;
|
|
8
|
+
readonly root: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function ruleChecks(engine: RuleEngine, tell: (line: string) => void): {
|
|
11
|
+
check: <TInput>(rule: Rule<string, TInput, import("#rule.ts").RuleServices>, options?: TInput | undefined, directory?: string | undefined, entries?: readonly string[] | undefined) => Effect.Effect<Findings, unknown, Path.Path | import("#rule.ts").RuleServices>;
|
|
12
|
+
checkOutcome: <TInput>(rule: Rule<string, TInput, import("#rule.ts").RuleServices>, entries: readonly string[]) => Effect.Effect<"failed" | "passed", never, import("#rule.ts").RuleServices>;
|
|
13
|
+
failureMessage: () => Effect.Effect<string, never, never>;
|
|
14
|
+
optionIssues: (rule: RegisteredRule<import("#rule.ts").RuleServices>, options: unknown) => Effect.Effect<readonly string[], never, never>;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=ruleChecks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ruleChecks.d.ts","sourceRoot":"","sources":["../../src/testing/ruleChecks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE7C,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAc,MAAM,UAAU,CAAC;AAC3E,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAGpD,MAAM,WAAW,UAAU;IAC1B,MAAM,EAAE,GAAG,GAAG,SAAS,CAAC;IACxB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI;IAEzE,KAAK,GAA0C,MAAM;IAiBrD,YAAY,GAAiD,MAAM;IAgBnE,cAAc;IAEd,YAAY;EAMb"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Cause, Effect, Path } from "effect";
|
|
2
|
+
import { configureRegistered } from "#adapters/rule.ts";
|
|
3
|
+
import { scanned } from "#testing/adapters/imports.ts";
|
|
4
|
+
export function ruleChecks(engine, tell) {
|
|
5
|
+
return {
|
|
6
|
+
check: Effect.fn("RuleStory.check")(function* (rule, options, directory = ".", entries) {
|
|
7
|
+
tell(options === undefined ? `quality checks ${rule.id}` : `quality checks ${rule.id} with ${JSON.stringify(options)}`);
|
|
8
|
+
const configured = yield* Effect.promise(() => rule.configure(options));
|
|
9
|
+
if (configured._tag === "Invalid") {
|
|
10
|
+
return yield* Effect.die(new Error(`${rule.id} refused its options: ${configured.issues.join("; ")}`));
|
|
11
|
+
}
|
|
12
|
+
const path = yield* Path.Path;
|
|
13
|
+
const scannedInputs = yield* Effect.promise(() => scanned(path.join(engine.root, directory)));
|
|
14
|
+
const inputs = entries === undefined ? scannedInputs : { ...scannedInputs, entries };
|
|
15
|
+
engine.findings = yield* configured.check(inputs);
|
|
16
|
+
return engine.findings;
|
|
17
|
+
}),
|
|
18
|
+
checkOutcome: Effect.fn("RuleStory.checkOutcome")(function* (rule, entries) {
|
|
19
|
+
tell(`quality checks ${rule.id} with declared entries`);
|
|
20
|
+
const configured = yield* Effect.promise(() => rule.configure(undefined));
|
|
21
|
+
if (configured._tag === "Invalid") {
|
|
22
|
+
return yield* Effect.die(new Error(`${rule.id} refused its options: ${configured.issues.join("; ")}`));
|
|
23
|
+
}
|
|
24
|
+
const inputs = yield* Effect.promise(() => scanned(engine.root));
|
|
25
|
+
const result = yield* Effect.exit(configured.check({ ...inputs, entries }));
|
|
26
|
+
if (result._tag === "Failure") {
|
|
27
|
+
engine.failure = Cause.pretty(result.cause);
|
|
28
|
+
return "failed";
|
|
29
|
+
}
|
|
30
|
+
engine.failure = undefined;
|
|
31
|
+
engine.findings = result.value;
|
|
32
|
+
return "passed";
|
|
33
|
+
}),
|
|
34
|
+
failureMessage: () => engine.failure === undefined ? Effect.die(new Error("Run a failed check before reading its failure message")) : Effect.succeed(engine.failure),
|
|
35
|
+
optionIssues: Effect.fn("RuleStory.optionIssues")(function* (rule, options) {
|
|
36
|
+
tell(`quality configures ${rule.id} with ${JSON.stringify(options)}`);
|
|
37
|
+
const configured = yield* Effect.promise(() => configureRegistered(rule, options));
|
|
38
|
+
return configured._tag === "Invalid" ? configured.issues : [];
|
|
39
|
+
}),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=ruleChecks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ruleChecks.js","sourceRoot":"","sources":["../../src/testing/ruleChecks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAA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YAC3B,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC;YAC/B,OAAO,QAAQ,CAAC;QACjB,CAAC,CAAC;QACF,cAAc,EAAE,GAAG,EAAE,CACpB,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;QAC/I,YAAY,EAAE,MAAM,CAAC,EAAE,CAAC,wBAAwB,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAoB,EAAE,OAAgB;YAClG,IAAI,CAAC,sBAAsB,IAAI,CAAC,EAAE,SAAS,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACtE,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;YACnF,OAAO,UAAU,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/D,CAAC,CAAC;KACF,CAAC;AACH,CAAC"}
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import { Effect, FileSystem, Path } from "effect";
|
|
2
|
-
import type { Finding
|
|
3
|
-
import { type Run } from "#testing/adapters/cli.ts";
|
|
2
|
+
import type { Finding } from "#rule.ts";
|
|
4
3
|
import { type SeedFile } from "#testing/adapters/tree.ts";
|
|
5
|
-
|
|
6
|
-
answer: Run | undefined;
|
|
7
|
-
findings: Findings | undefined;
|
|
8
|
-
readonly root: string;
|
|
9
|
-
}
|
|
4
|
+
import { type RuleEngine } from "#testing/ruleChecks.ts";
|
|
10
5
|
export declare function locationOf(finding: Finding): string;
|
|
11
6
|
export declare function makeRuleStory(): import("@shivaedev/test-story/server/storyKit.ts").StoryKit<RuleEngine, "repository", {
|
|
12
|
-
check: <TInput>(rule: Rule<string, TInput, import("#rule.ts").RuleServices>, options?: TInput | undefined, directory?: string | undefined) => Effect.Effect<Findings, unknown, Path.Path | import("#rule.ts").RuleServices>;
|
|
13
|
-
|
|
7
|
+
check: <TInput>(rule: import("#rule.ts").Rule<string, TInput, import("#rule.ts").RuleServices>, options?: TInput | undefined, directory?: string | undefined, entries?: readonly string[] | undefined) => Effect.Effect<import("#rule.ts").Findings, unknown, Path.Path | import("#rule.ts").RuleServices>;
|
|
8
|
+
checkOutcome: <TInput>(rule: import("#rule.ts").Rule<string, TInput, import("#rule.ts").RuleServices>, entries: readonly string[]) => Effect.Effect<"failed" | "passed", never, import("#rule.ts").RuleServices>;
|
|
9
|
+
failureMessage: () => Effect.Effect<string, never, never>;
|
|
10
|
+
optionIssues: (rule: import("#rule.ts").RegisteredRule<import("#rule.ts").RuleServices>, options: unknown) => Effect.Effect<readonly string[], never, never>;
|
|
11
|
+
findings: () => Effect.Effect<import("#rule.ts").Findings, never, never>;
|
|
14
12
|
gate: () => Effect.Effect<void, never, never>;
|
|
15
13
|
gateOutcome: () => Effect.Effect<string, never, never>;
|
|
16
14
|
gateReport: () => Effect.Effect<string, never, never>;
|
|
17
15
|
gateReports: (prefix: string) => Effect.Effect<string, never, never>;
|
|
18
16
|
locations: () => Effect.Effect<string[], never, never>;
|
|
19
17
|
messages: () => Effect.Effect<string[], never, never>;
|
|
20
|
-
optionIssues: (rule: RegisteredRule<import("#rule.ts").RuleServices>, options: unknown) => Effect.Effect<readonly string[], never, never>;
|
|
21
18
|
removes: (path: string) => Effect.Effect<void, import("effect/PlatformError").PlatformError, FileSystem.FileSystem | Path.Path>;
|
|
22
19
|
writes: (...files: readonly SeedFile[]) => Effect.Effect<void, import("effect/PlatformError").PlatformError, FileSystem.FileSystem | Path.Path>;
|
|
23
20
|
}, never, import("effect/process/ChildProcessSpawner").ChildProcessSpawner | FileSystem.FileSystem | Path.Path> & {
|
|
@@ -25,5 +22,4 @@ export declare function makeRuleStory(): import("@shivaedev/test-story/server/st
|
|
|
25
22
|
readonly repositoryHas: (...files: readonly SeedFile[]) => import("@shivaedev/test-story/server/storyKit.ts").Trait<RuleEngine, "repository", FileSystem.FileSystem | Path.Path>;
|
|
26
23
|
readonly repositoryLinks: (path: string, target: string) => import("@shivaedev/test-story/server/storyKit.ts").Trait<RuleEngine, "repository", FileSystem.FileSystem | Path.Path>;
|
|
27
24
|
};
|
|
28
|
-
export {};
|
|
29
25
|
//# sourceMappingURL=ruleStory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ruleStory.d.ts","sourceRoot":"","sources":["../../src/testing/ruleStory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"ruleStory.d.ts","sourceRoot":"","sources":["../../src/testing/ruleStory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,KAAK,UAAU,EAAc,MAAM,wBAAwB,CAAC;AAgBrE,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAEnD;AA6BD,wBAAgB,aAAa;;;;;;;;;0BAsBJ,MAAM;;;;uBAeT,SAAS,QAAQ,EAAE;;;uCAOP,SAAS,QAAQ,EAAE;qCAIrB,MAAM,UAAU,MAAM;EAqBrD"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Effect, FileSystem, Path } from "effect";
|
|
2
2
|
import { storyKit } from "@shivaedev/test-story/server/storyKit.ts";
|
|
3
|
-
import { configureRegistered } from "#adapters/rule.ts";
|
|
4
3
|
import { services } from "#cli/runMain.ts";
|
|
5
4
|
import { runQuality } from "#testing/adapters/cli.ts";
|
|
6
|
-
import { scanned } from "#testing/adapters/imports.ts";
|
|
7
5
|
import { packageRoot } from "#testing/adapters/tree.ts";
|
|
6
|
+
import { ruleChecks } from "#testing/ruleChecks.ts";
|
|
8
7
|
const writeAll = Effect.fn("RuleStory.writeAll")(function* (root, files) {
|
|
9
8
|
const fs = yield* FileSystem.FileSystem;
|
|
10
9
|
const path = yield* Path.Path;
|
|
@@ -49,7 +48,7 @@ export function makeRuleStory() {
|
|
|
49
48
|
create: () => Effect.gen(function* () {
|
|
50
49
|
const fs = yield* FileSystem.FileSystem;
|
|
51
50
|
const root = yield* fs.makeTempDirectoryScoped({ prefix: "quality-rule-" });
|
|
52
|
-
const engine = { answer: undefined, findings: undefined, root };
|
|
51
|
+
const engine = { answer: undefined, failure: undefined, findings: undefined, root };
|
|
53
52
|
return engine;
|
|
54
53
|
}),
|
|
55
54
|
inspect: ({ findings }) => ({ findings }),
|
|
@@ -57,17 +56,7 @@ export function makeRuleStory() {
|
|
|
57
56
|
name: "Quality rule",
|
|
58
57
|
stages: ["repository"],
|
|
59
58
|
verbs: (engine, story) => ({
|
|
60
|
-
|
|
61
|
-
story.tell(options === undefined ? `quality checks ${rule.id}` : `quality checks ${rule.id} with ${JSON.stringify(options)}`);
|
|
62
|
-
const configured = yield* Effect.promise(() => rule.configure(options));
|
|
63
|
-
if (configured._tag === "Invalid") {
|
|
64
|
-
return yield* Effect.die(new Error(`${rule.id} refused its options: ${configured.issues.join("; ")}`));
|
|
65
|
-
}
|
|
66
|
-
const path = yield* Path.Path;
|
|
67
|
-
const inputs = yield* Effect.promise(() => scanned(path.join(engine.root, directory)));
|
|
68
|
-
engine.findings = yield* configured.check(inputs);
|
|
69
|
-
return engine.findings;
|
|
70
|
-
}),
|
|
59
|
+
...ruleChecks(engine, story.tell),
|
|
71
60
|
findings: () => checked(engine),
|
|
72
61
|
gate: Effect.fn("RuleStory.gate")(function* () {
|
|
73
62
|
story.tell("quality runs the repository gate");
|
|
@@ -81,11 +70,6 @@ export function makeRuleStory() {
|
|
|
81
70
|
.join("\n\n")),
|
|
82
71
|
locations: () => Effect.map(checked(engine), (findings) => findings.map(locationOf)),
|
|
83
72
|
messages: () => Effect.map(checked(engine), (findings) => findings.map((finding) => finding.message)),
|
|
84
|
-
optionIssues: Effect.fn("RuleStory.optionIssues")(function* (rule, options) {
|
|
85
|
-
story.tell(`quality configures ${rule.id} with ${JSON.stringify(options)}`);
|
|
86
|
-
const configured = yield* Effect.promise(() => configureRegistered(rule, options));
|
|
87
|
-
return configured._tag === "Invalid" ? configured.issues : [];
|
|
88
|
-
}),
|
|
89
73
|
removes: Effect.fn("RuleStory.removes")(function* (path) {
|
|
90
74
|
story.tell(`the author removes ${path}`);
|
|
91
75
|
const fs = yield* FileSystem.FileSystem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ruleStory.js","sourceRoot":"","sources":["../../src/testing/ruleStory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,0CAA0C,CAAC;AACpE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ruleStory.js","sourceRoot":"","sources":["../../src/testing/ruleStory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,0CAA0C,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAY,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAiB,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAmB,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAErE,MAAM,Q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O,SAAS,CAAC,KAAK,CAAC,YAAY,EAAE,wBAAwB,IAAI,OAAO,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,CAC5F,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YACnB,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;YACxC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YAC/B,KAAK,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC3F,KAAK,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QAC1D,CAAC,CAAC,CACF,CAAC;IACH,CAAC;IAED,SAAS,gBAAgB;QACxB,OAAO,eAAe,CAAC,iCAAiC,EAAE,WAAW,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,OAAO,GAIT,EAAE,GAAG,SAAS,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC;IACvE,OAAO,OAAO,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/quality",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.74.0",
|
|
4
4
|
"description": "Repository quality gate with typed rules, a baseline of existing debt and a registry of reasoned exceptions",
|
|
5
5
|
"homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/quality#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@effect/platform-node": "4.1.1",
|
|
69
69
|
"@effect/platform-node-shared": "4.1.1",
|
|
70
70
|
"@effect/vitest": "4.1.1",
|
|
71
|
-
"@shivaedev/test-story": "0.45.
|
|
71
|
+
"@shivaedev/test-story": "0.45.5",
|
|
72
72
|
"@types/node": "24.19.2",
|
|
73
73
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
74
74
|
"effect": "4.1.1",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"@effect/platform-node": "4.1.1",
|
|
79
79
|
"@effect/platform-node-shared": "4.1.1",
|
|
80
|
-
"@shivaedev/test-story": "0.45.
|
|
80
|
+
"@shivaedev/test-story": "0.45.5",
|
|
81
81
|
"effect": "4.1.1",
|
|
82
82
|
"vitest": "5.0.5"
|
|
83
83
|
},
|
|
@@ -3,10 +3,14 @@ import ts from "typescript";
|
|
|
3
3
|
import { type BuildBindings, buildEntryValue, buildOption } from "#adapters/buildEntryValue.ts";
|
|
4
4
|
import { importedCall } from "#adapters/importedCall.ts";
|
|
5
5
|
|
|
6
|
+
function sourcePath(node: ts.Node, root: string): string {
|
|
7
|
+
return posix.resolve(root, node.getSourceFile().fileName);
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
function pathFromCall(
|
|
7
11
|
node: ts.CallExpression,
|
|
8
12
|
cwd: string,
|
|
9
|
-
|
|
13
|
+
root: string,
|
|
10
14
|
paths: (expression: ts.Expression) => readonly string[],
|
|
11
15
|
): readonly string[] {
|
|
12
16
|
if (node.expression.getText() === "process.cwd" && node.arguments.length === 0) {
|
|
@@ -19,7 +23,7 @@ function pathFromCall(
|
|
|
19
23
|
&& ts.isMetaProperty(argument.expression)
|
|
20
24
|
&& argument.expression.keywordToken === ts.SyntaxKind.ImportKeyword
|
|
21
25
|
&& argument.name.text === "url"
|
|
22
|
-
? [
|
|
26
|
+
? [sourcePath(argument, root)]
|
|
23
27
|
: [];
|
|
24
28
|
}
|
|
25
29
|
if (imported === undefined || !/^(?:node:)?path$/u.test(imported.module) || !["join", "resolve", "dirname"].includes(imported.name)) {
|
|
@@ -53,7 +57,7 @@ function valuesOf(node: ts.Expression): readonly ts.Expression[] {
|
|
|
53
57
|
export function buildEntryPaths(
|
|
54
58
|
expression: ts.Expression,
|
|
55
59
|
cwd: string,
|
|
56
|
-
|
|
60
|
+
root: string,
|
|
57
61
|
active: ReadonlySet<ts.Node> = new Set(),
|
|
58
62
|
bindings: BuildBindings = new Map(),
|
|
59
63
|
): readonly string[] {
|
|
@@ -63,7 +67,7 @@ export function buildEntryPaths(
|
|
|
63
67
|
}
|
|
64
68
|
const visited = new Set([...active, node]);
|
|
65
69
|
function paths(value: ts.Expression) {
|
|
66
|
-
return buildEntryPaths(value, cwd,
|
|
70
|
+
return buildEntryPaths(value, cwd, root, visited, bindings);
|
|
67
71
|
}
|
|
68
72
|
if (ts.isStringLiteralLike(node)) {
|
|
69
73
|
return [node.text];
|
|
@@ -75,7 +79,7 @@ export function buildEntryPaths(
|
|
|
75
79
|
(ts.isIdentifier(node) && node.text === "__dirname")
|
|
76
80
|
|| (ts.isPropertyAccessExpression(node) && node.expression.kind === ts.SyntaxKind.MetaProperty && node.name.text === "dirname")
|
|
77
81
|
) {
|
|
78
|
-
return [posix.dirname(
|
|
82
|
+
return [posix.dirname(sourcePath(node, root))];
|
|
79
83
|
}
|
|
80
|
-
return ts.isCallExpression(node) ? pathFromCall(node, cwd,
|
|
84
|
+
return ts.isCallExpression(node) ? pathFromCall(node, cwd, root, paths) : valuesOf(node).flatMap(paths);
|
|
81
85
|
}
|
|
@@ -28,7 +28,7 @@ function entryOption(call: ts.CallExpression): string | undefined {
|
|
|
28
28
|
return imported?.module === "esbuild" && ESBUILD.has(imported.name) ? "entryPoints" : undefined;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function entriesOf(call: ts.CallExpression,
|
|
31
|
+
function entriesOf(call: ts.CallExpression, cwd: string, root: string, bindings: BuildBindings): readonly string[] {
|
|
32
32
|
const option = entryOption(call);
|
|
33
33
|
const [argument] = call.arguments;
|
|
34
34
|
const options = argument === undefined ? undefined : buildEntryValue(argument, new Set(), bindings);
|
|
@@ -36,21 +36,21 @@ function entriesOf(call: ts.CallExpression, file: string, cwd: string, bindings:
|
|
|
36
36
|
return [];
|
|
37
37
|
}
|
|
38
38
|
const configs = option === "input" && ts.isArrayLiteralExpression(options) ? options.elements : [options];
|
|
39
|
-
return configs.flatMap((config) => configuredEntries(config, option,
|
|
39
|
+
return configs.flatMap((config) => configuredEntries(config, option, cwd, root, bindings));
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
function configuredEntries(value: ts.Expression, option: string,
|
|
42
|
+
function configuredEntries(value: ts.Expression, option: string, cwd: string, root: string, bindings: BuildBindings): readonly string[] {
|
|
43
43
|
const options = buildEntryValue(value, new Set(), bindings);
|
|
44
44
|
if (!ts.isObjectLiteralExpression(options)) {
|
|
45
45
|
return [];
|
|
46
46
|
}
|
|
47
47
|
const directory = buildOption(options, "absWorkingDir");
|
|
48
|
-
const working = directory === undefined ? cwd : buildEntryPaths(directory, cwd,
|
|
48
|
+
const working = directory === undefined ? cwd : buildEntryPaths(directory, cwd, root, new Set(), bindings)[0];
|
|
49
49
|
if (working === undefined) {
|
|
50
50
|
return [];
|
|
51
51
|
}
|
|
52
52
|
const entries = buildOption(options, option);
|
|
53
|
-
return entries === undefined ? [] : buildEntryPaths(entries, cwd,
|
|
53
|
+
return entries === undefined ? [] : buildEntryPaths(entries, cwd, root, new Set(), bindings).map((path) => posix.resolve(cwd, working, path));
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export function bundlerEntries(
|
|
@@ -75,11 +75,7 @@ export function bundlerEntries(
|
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
if (ts.isCallExpression(node)) {
|
|
78
|
-
entries.push(
|
|
79
|
-
...entriesOf(node, posix.join(root, node.getSourceFile().fileName), posix.join(root, directory), bindings).map((path) =>
|
|
80
|
-
posix.relative(root, path),
|
|
81
|
-
),
|
|
82
|
-
);
|
|
78
|
+
entries.push(...entriesOf(node, posix.join(root, directory), root, bindings).map((path) => posix.relative(root, path)));
|
|
83
79
|
const helper = buildHelper(node, sources, bindings);
|
|
84
80
|
if (helper?.body !== undefined && !active.has(helper)) {
|
|
85
81
|
entries.push(posix.relative(root, posix.resolve(root, helper.getSourceFile().fileName)));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { globSync, statSync } from "node:fs";
|
|
2
|
+
import { join, posix } from "node:path";
|
|
2
3
|
import { isToolConfig } from "#adapters/isToolConfig.ts";
|
|
3
4
|
import { KNIP_ISSUES } from "#adapters/knip/findings.ts";
|
|
4
5
|
import { mockEntries } from "#adapters/knip/mockEntries.ts";
|
|
@@ -10,6 +11,16 @@ import type { RuleInputs } from "#rule.ts";
|
|
|
10
11
|
|
|
11
12
|
const ENTRIES = ["**/*.{test,spec,stories,story}.{ts,tsx,mts,cts,js,jsx,mjs,cjs}", "src/test-support/**", "*.config.{ts,mts,cts,js,mjs,cjs}"];
|
|
12
13
|
|
|
14
|
+
export function declaredEntries(inputs: RuleInputs): readonly string[] {
|
|
15
|
+
return (inputs.entries ?? []).flatMap((pattern) => {
|
|
16
|
+
const matches = globSync(pattern, { cwd: inputs.root }).filter((path) => statSync(join(inputs.root, path)).isFile());
|
|
17
|
+
if (matches.length === 0) {
|
|
18
|
+
throw new Error(`quality.config.ts entries pattern "${pattern}" matched no files`);
|
|
19
|
+
}
|
|
20
|
+
return matches;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
13
24
|
function importPaths(imports: Readonly<Record<string, unknown>>) {
|
|
14
25
|
return Object.fromEntries(
|
|
15
26
|
Object.entries(imports).flatMap(([name, target]) => {
|
|
@@ -27,7 +38,12 @@ function importPaths(imports: Readonly<Record<string, unknown>>) {
|
|
|
27
38
|
);
|
|
28
39
|
}
|
|
29
40
|
|
|
30
|
-
export async function knipConfiguration(
|
|
41
|
+
export async function knipConfiguration(
|
|
42
|
+
inputs: RuleInputs,
|
|
43
|
+
toolOwned: readonly string[] = [],
|
|
44
|
+
programmatic: ReadonlySet<string> = new Set(),
|
|
45
|
+
declared: readonly string[] = declaredEntries(inputs),
|
|
46
|
+
) {
|
|
31
47
|
const packages = await workspacePackages(inputs);
|
|
32
48
|
const manifests = await Promise.all(
|
|
33
49
|
[".", ...packages.map(({ directory }) => directory)].map(async (directory) => {
|
|
@@ -52,15 +68,30 @@ export async function knipConfiguration(inputs: RuleInputs, toolOwned: readonly
|
|
|
52
68
|
// Migration runners load these files from their directory, so no import reaches them.
|
|
53
69
|
const migrations = sources.filter((path) => /(?:^|\/)server\/migrations\//u.test(path));
|
|
54
70
|
const ui = toolOwned.filter((file) => (packageOf(packages, file)?.directory ?? ".") === directory).map((file) => posix.relative(directory, file));
|
|
71
|
+
const workspaceEntries = declared
|
|
72
|
+
.filter((file) => (packageOf(packages, file)?.directory ?? ".") === directory)
|
|
73
|
+
.map((file) => posix.relative(directory, file));
|
|
55
74
|
const styles = inputs.files
|
|
56
75
|
.filter((path) => path.endsWith(".css") && (packageOf(packages, path)?.directory ?? ".") === directory)
|
|
57
76
|
.map((path) => posix.relative(directory, path));
|
|
58
77
|
return [
|
|
59
78
|
directory,
|
|
60
79
|
{
|
|
61
|
-
entry: [
|
|
80
|
+
entry: [
|
|
81
|
+
...ENTRIES,
|
|
82
|
+
...publicFiles,
|
|
83
|
+
...configs,
|
|
84
|
+
...migrations,
|
|
85
|
+
...bins,
|
|
86
|
+
...binaries,
|
|
87
|
+
...scriptEntries,
|
|
88
|
+
...bundled,
|
|
89
|
+
...ui,
|
|
90
|
+
...styles,
|
|
91
|
+
...workspaceEntries,
|
|
92
|
+
],
|
|
62
93
|
paths: importPaths(manifest.imports ?? {}),
|
|
63
|
-
project: [...sources, ...ui, ...styles],
|
|
94
|
+
project: [...sources, ...ui, ...styles, ...workspaceEntries],
|
|
64
95
|
vitest: { config: ["vitest*.config.{ts,mts,cts,js,mjs,cjs}", "vitest.{workspace,projects}.{ts,mts,cts,js,mjs,cjs,json}"] },
|
|
65
96
|
},
|
|
66
97
|
] as const;
|
package/src/adapters/knip/run.ts
CHANGED
|
@@ -4,7 +4,7 @@ import process from "node:process";
|
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { Effect, FileSystem, Stream } from "effect";
|
|
6
6
|
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
7
|
-
import { knipConfiguration } from "#adapters/knip/configuration.ts";
|
|
7
|
+
import { declaredEntries, knipConfiguration } from "#adapters/knip/configuration.ts";
|
|
8
8
|
import { entryPointFindings } from "#adapters/knip/entryPointFindings.ts";
|
|
9
9
|
import { KNIP_ISSUES } from "#adapters/knip/findings.ts";
|
|
10
10
|
import { knipReport } from "#adapters/knip/report.ts";
|
|
@@ -28,8 +28,13 @@ export const runKnip = Effect.fn("Knip.runKnip")(function* (inputs: RuleInputs)
|
|
|
28
28
|
}
|
|
29
29
|
const files = yield* toolOwnedFiles(inputs.root);
|
|
30
30
|
const entries = yield* programmaticEntries(inputs);
|
|
31
|
-
const
|
|
32
|
-
const
|
|
31
|
+
const declared = declaredEntries(inputs);
|
|
32
|
+
const configuration = yield* Effect.promise(() => knipConfiguration(inputs, files, entries, declared));
|
|
33
|
+
const checked = new Set([
|
|
34
|
+
...inputs.files,
|
|
35
|
+
...declared,
|
|
36
|
+
...Object.keys(configuration.workspaces).map((directory) => posix.join(directory, "package.json")),
|
|
37
|
+
]);
|
|
33
38
|
const findings = yield* Effect.scoped(
|
|
34
39
|
Effect.gen(function* () {
|
|
35
40
|
const fs = yield* FileSystem.FileSystem;
|
|
@@ -8,15 +8,15 @@ import { parse } from "#rules/parse.ts";
|
|
|
8
8
|
|
|
9
9
|
const COMMANDS = new Set(["spawn", "spawnSync", "execFile", "execFileSync", "fork"]);
|
|
10
10
|
|
|
11
|
-
function entriesOf(call: ts.CallExpression, cwd: string,
|
|
11
|
+
function entriesOf(call: ts.CallExpression, cwd: string, root: string): readonly string[] {
|
|
12
12
|
const imported = importedCall(call);
|
|
13
13
|
if (imported === undefined || !/^(?:node:)?child_process$/u.test(imported.module) || !COMMANDS.has(imported.name)) {
|
|
14
14
|
return [];
|
|
15
15
|
}
|
|
16
16
|
const options = call.arguments[2] === undefined ? undefined : buildEntryValue(call.arguments[2]);
|
|
17
17
|
const working = options !== undefined && ts.isObjectLiteralExpression(options) ? buildOption(options, "cwd") : undefined;
|
|
18
|
-
const directories = working === undefined ? [cwd] : buildEntryPaths(working, cwd,
|
|
19
|
-
const targets = call.arguments.slice(0, 2).flatMap((argument) => buildEntryPaths(argument, cwd,
|
|
18
|
+
const directories = working === undefined ? [cwd] : buildEntryPaths(working, cwd, root);
|
|
19
|
+
const targets = call.arguments.slice(0, 2).flatMap((argument) => buildEntryPaths(argument, cwd, root));
|
|
20
20
|
return targets.flatMap((target) => directories.map((folder) => posix.resolve(cwd, folder, target)));
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -27,10 +27,9 @@ export function spawnedEntries(file: SourceFile, root: string, directory: string
|
|
|
27
27
|
}
|
|
28
28
|
const entries: string[] = [];
|
|
29
29
|
const cwd = posix.join(root, directory);
|
|
30
|
-
const path = posix.join(root, file.path);
|
|
31
30
|
function visit(node: ts.Node): void {
|
|
32
31
|
if (ts.isCallExpression(node)) {
|
|
33
|
-
entries.push(...entriesOf(node, cwd,
|
|
32
|
+
entries.push(...entriesOf(node, cwd, root).map((target) => posix.relative(root, target)));
|
|
34
33
|
}
|
|
35
34
|
ts.forEachChild(node, visit);
|
|
36
35
|
}
|
package/src/config/decode.ts
CHANGED
|
@@ -26,6 +26,7 @@ const LocalRule = Schema.declare(isRule, { expected: "a rule made with defineRul
|
|
|
26
26
|
|
|
27
27
|
const ConfigInput = Schema.Struct({
|
|
28
28
|
baseline: Schema.optionalKey(Schema.String),
|
|
29
|
+
entries: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
29
30
|
exceptions: Schema.optionalKey(Schema.Array(ExceptionDeclaration)),
|
|
30
31
|
extensions: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
31
32
|
local: Schema.optionalKey(Schema.Array(LocalRule)),
|
package/src/config/load.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type { Declaration } from "#rules/suppressions/biome/declarations.ts";
|
|
|
14
14
|
export interface ResolvedConfig extends ResolvedRules, InventoryScope {
|
|
15
15
|
readonly baseline: string;
|
|
16
16
|
readonly biomeDeclarations: readonly Declaration[];
|
|
17
|
+
readonly entries: readonly string[];
|
|
17
18
|
readonly exceptions: readonly ExceptionDeclaration[];
|
|
18
19
|
readonly file: string;
|
|
19
20
|
readonly nonEffectFolders: readonly string[];
|
|
@@ -33,6 +34,7 @@ function resolved(root: string, file: string, config: ConfigInput, rules: Resolv
|
|
|
33
34
|
...rules,
|
|
34
35
|
baseline: config.baseline ?? "quality-baseline.jsonl",
|
|
35
36
|
biomeDeclarations: biomeDeclarations(config),
|
|
37
|
+
entries: config.entries ?? [],
|
|
36
38
|
exceptions: config.exceptions ?? [],
|
|
37
39
|
exclude: [],
|
|
38
40
|
extensions: config.extensions ?? DEFAULT_EXTENSIONS,
|
package/src/config.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type BuiltInRules = typeof builtInRules;
|
|
|
16
16
|
|
|
17
17
|
export interface QualityConfig<TLocal extends readonly RegisteredRule<unknown>[] = readonly RegisteredRule<unknown>[]> {
|
|
18
18
|
readonly baseline?: string;
|
|
19
|
+
readonly entries?: readonly string[];
|
|
19
20
|
readonly exceptions?: readonly ExceptionDeclaration[];
|
|
20
21
|
readonly extensions?: readonly string[];
|
|
21
22
|
readonly local?: TLocal;
|
package/src/engine/session.ts
CHANGED
|
@@ -38,6 +38,7 @@ export const scan = Effect.fn("Engine.scan")(function* (
|
|
|
38
38
|
setManifestFiles(readText, inventory.manifestFiles);
|
|
39
39
|
const inputs = {
|
|
40
40
|
configFile: relative(config.root, config.file),
|
|
41
|
+
entries: config.entries,
|
|
41
42
|
exceptions: config.exceptions,
|
|
42
43
|
files: inventory.files,
|
|
43
44
|
nonEffectFolders: config.nonEffectFolders,
|
package/src/rule.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface SourceFile {
|
|
|
24
24
|
|
|
25
25
|
export interface RuleInputs {
|
|
26
26
|
readonly configFile?: string;
|
|
27
|
+
readonly entries?: readonly string[];
|
|
27
28
|
readonly exceptions?: readonly ExceptionDeclaration[];
|
|
28
29
|
readonly files: readonly string[];
|
|
29
30
|
readonly nonEffectFolders?: readonly string[];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Cause, Effect, Path } from "effect";
|
|
2
|
+
import { configureRegistered } from "#adapters/rule.ts";
|
|
3
|
+
import type { Findings, RegisteredRule, Rule, RuleInputs } from "#rule.ts";
|
|
4
|
+
import type { Run } from "#testing/adapters/cli.ts";
|
|
5
|
+
import { scanned } from "#testing/adapters/imports.ts";
|
|
6
|
+
|
|
7
|
+
export interface RuleEngine {
|
|
8
|
+
answer: Run | undefined;
|
|
9
|
+
failure: string | undefined;
|
|
10
|
+
findings: Findings | undefined;
|
|
11
|
+
readonly root: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function ruleChecks(engine: RuleEngine, tell: (line: string) => void) {
|
|
15
|
+
return {
|
|
16
|
+
check: Effect.fn("RuleStory.check")(function* <TInput>(
|
|
17
|
+
rule: Rule<string, TInput>,
|
|
18
|
+
options?: TInput,
|
|
19
|
+
directory = ".",
|
|
20
|
+
entries?: readonly string[],
|
|
21
|
+
) {
|
|
22
|
+
tell(options === undefined ? `quality checks ${rule.id}` : `quality checks ${rule.id} with ${JSON.stringify(options)}`);
|
|
23
|
+
const configured = yield* Effect.promise(() => rule.configure(options));
|
|
24
|
+
if (configured._tag === "Invalid") {
|
|
25
|
+
return yield* Effect.die(new Error(`${rule.id} refused its options: ${configured.issues.join("; ")}`));
|
|
26
|
+
}
|
|
27
|
+
const path = yield* Path.Path;
|
|
28
|
+
const scannedInputs = yield* Effect.promise(() => scanned(path.join(engine.root, directory)));
|
|
29
|
+
const inputs: RuleInputs = entries === undefined ? scannedInputs : { ...scannedInputs, entries };
|
|
30
|
+
engine.findings = yield* configured.check(inputs);
|
|
31
|
+
return engine.findings;
|
|
32
|
+
}),
|
|
33
|
+
checkOutcome: Effect.fn("RuleStory.checkOutcome")(function* <TInput>(rule: Rule<string, TInput>, entries: readonly string[]) {
|
|
34
|
+
tell(`quality checks ${rule.id} with declared entries`);
|
|
35
|
+
const configured = yield* Effect.promise(() => rule.configure(undefined));
|
|
36
|
+
if (configured._tag === "Invalid") {
|
|
37
|
+
return yield* Effect.die(new Error(`${rule.id} refused its options: ${configured.issues.join("; ")}`));
|
|
38
|
+
}
|
|
39
|
+
const inputs = yield* Effect.promise(() => scanned(engine.root));
|
|
40
|
+
const result = yield* Effect.exit(configured.check({ ...inputs, entries }));
|
|
41
|
+
if (result._tag === "Failure") {
|
|
42
|
+
engine.failure = Cause.pretty(result.cause);
|
|
43
|
+
return "failed";
|
|
44
|
+
}
|
|
45
|
+
engine.failure = undefined;
|
|
46
|
+
engine.findings = result.value;
|
|
47
|
+
return "passed";
|
|
48
|
+
}),
|
|
49
|
+
failureMessage: () =>
|
|
50
|
+
engine.failure === undefined ? Effect.die(new Error("Run a failed check before reading its failure message")) : Effect.succeed(engine.failure),
|
|
51
|
+
optionIssues: Effect.fn("RuleStory.optionIssues")(function* (rule: RegisteredRule, options: unknown) {
|
|
52
|
+
tell(`quality configures ${rule.id} with ${JSON.stringify(options)}`);
|
|
53
|
+
const configured = yield* Effect.promise(() => configureRegistered(rule, options));
|
|
54
|
+
return configured._tag === "Invalid" ? configured.issues : [];
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
}
|
package/src/testing/ruleStory.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import { Effect, FileSystem, Path } from "effect";
|
|
2
2
|
import { storyKit } from "@shivaedev/test-story/server/storyKit.ts";
|
|
3
|
-
import { configureRegistered } from "#adapters/rule.ts";
|
|
4
3
|
import { services } from "#cli/runMain.ts";
|
|
5
|
-
import type { Finding
|
|
4
|
+
import type { Finding } from "#rule.ts";
|
|
6
5
|
import { type Run, runQuality } from "#testing/adapters/cli.ts";
|
|
7
|
-
import { scanned } from "#testing/adapters/imports.ts";
|
|
8
6
|
import { packageRoot, type SeedFile } from "#testing/adapters/tree.ts";
|
|
9
|
-
|
|
10
|
-
interface RuleEngine {
|
|
11
|
-
answer: Run | undefined;
|
|
12
|
-
findings: Findings | undefined;
|
|
13
|
-
readonly root: string;
|
|
14
|
-
}
|
|
7
|
+
import { type RuleEngine, ruleChecks } from "#testing/ruleChecks.ts";
|
|
15
8
|
|
|
16
9
|
const writeAll = Effect.fn("RuleStory.writeAll")(function* (root: string, files: readonly SeedFile[]) {
|
|
17
10
|
const fs = yield* FileSystem.FileSystem;
|
|
@@ -64,7 +57,7 @@ export function makeRuleStory() {
|
|
|
64
57
|
Effect.gen(function* () {
|
|
65
58
|
const fs = yield* FileSystem.FileSystem;
|
|
66
59
|
const root = yield* fs.makeTempDirectoryScoped({ prefix: "quality-rule-" });
|
|
67
|
-
const engine: RuleEngine = { answer: undefined, findings: undefined, root };
|
|
60
|
+
const engine: RuleEngine = { answer: undefined, failure: undefined, findings: undefined, root };
|
|
68
61
|
return engine;
|
|
69
62
|
}),
|
|
70
63
|
inspect: ({ findings }) => ({ findings }),
|
|
@@ -72,17 +65,7 @@ export function makeRuleStory() {
|
|
|
72
65
|
name: "Quality rule",
|
|
73
66
|
stages: ["repository"],
|
|
74
67
|
verbs: (engine, story) => ({
|
|
75
|
-
|
|
76
|
-
story.tell(options === undefined ? `quality checks ${rule.id}` : `quality checks ${rule.id} with ${JSON.stringify(options)}`);
|
|
77
|
-
const configured = yield* Effect.promise(() => rule.configure(options));
|
|
78
|
-
if (configured._tag === "Invalid") {
|
|
79
|
-
return yield* Effect.die(new Error(`${rule.id} refused its options: ${configured.issues.join("; ")}`));
|
|
80
|
-
}
|
|
81
|
-
const path = yield* Path.Path;
|
|
82
|
-
const inputs = yield* Effect.promise(() => scanned(path.join(engine.root, directory)));
|
|
83
|
-
engine.findings = yield* configured.check(inputs);
|
|
84
|
-
return engine.findings;
|
|
85
|
-
}),
|
|
68
|
+
...ruleChecks(engine, story.tell),
|
|
86
69
|
findings: () => checked(engine),
|
|
87
70
|
gate: Effect.fn("RuleStory.gate")(function* () {
|
|
88
71
|
story.tell("quality runs the repository gate");
|
|
@@ -99,11 +82,6 @@ export function makeRuleStory() {
|
|
|
99
82
|
),
|
|
100
83
|
locations: () => Effect.map(checked(engine), (findings) => findings.map(locationOf)),
|
|
101
84
|
messages: () => Effect.map(checked(engine), (findings) => findings.map((finding) => finding.message)),
|
|
102
|
-
optionIssues: Effect.fn("RuleStory.optionIssues")(function* (rule: RegisteredRule, options: unknown) {
|
|
103
|
-
story.tell(`quality configures ${rule.id} with ${JSON.stringify(options)}`);
|
|
104
|
-
const configured = yield* Effect.promise(() => configureRegistered(rule, options));
|
|
105
|
-
return configured._tag === "Invalid" ? configured.issues : [];
|
|
106
|
-
}),
|
|
107
85
|
removes: Effect.fn("RuleStory.removes")(function* (path: string) {
|
|
108
86
|
story.tell(`the author removes ${path}`);
|
|
109
87
|
const fs = yield* FileSystem.FileSystem;
|