@shivaedev/quality 0.60.0 → 0.61.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 +11 -0
- package/README.md +36 -15
- package/dist/adapters/biome/relocateConfig.d.ts +1 -1
- package/dist/adapters/biome/relocateConfig.d.ts.map +1 -1
- package/dist/adapters/biome/relocateConfig.js +6 -5
- package/dist/adapters/biome/relocateConfig.js.map +1 -1
- package/dist/adapters/biome/run.d.ts +1 -1
- package/dist/adapters/biome/run.d.ts.map +1 -1
- package/dist/adapters/biome/run.js +2 -2
- package/dist/adapters/biome/run.js.map +1 -1
- package/dist/adapters/biome/withExceptionConfig.d.ts +1 -1
- package/dist/adapters/biome/withExceptionConfig.d.ts.map +1 -1
- package/dist/adapters/biome/withExceptionConfig.js +3 -3
- package/dist/adapters/biome/withExceptionConfig.js.map +1 -1
- package/dist/biome/nonEffectPlugins.d.ts +7 -0
- package/dist/biome/nonEffectPlugins.d.ts.map +1 -0
- package/dist/biome/nonEffectPlugins.js +24 -0
- package/dist/biome/nonEffectPlugins.js.map +1 -0
- package/dist/biome/report.d.ts +1 -1
- package/dist/biome/report.d.ts.map +1 -1
- package/dist/biome/report.js +5 -5
- package/dist/biome/report.js.map +1 -1
- package/dist/cli/baseline.d.ts.map +1 -1
- package/dist/cli/baseline.js +0 -6
- package/dist/cli/baseline.js.map +1 -1
- package/dist/cli/fix.d.ts.map +1 -1
- package/dist/cli/fix.js +7 -7
- package/dist/cli/fix.js.map +1 -1
- package/dist/cli/messages.d.ts +1 -1
- package/dist/cli/messages.d.ts.map +1 -1
- package/dist/cli/messages.js +1 -1
- package/dist/config/decode.d.ts +1 -0
- package/dist/config/decode.d.ts.map +1 -1
- package/dist/config/decode.js +2 -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/nonEffectFolders.d.ts +5 -0
- package/dist/config/nonEffectFolders.d.ts.map +1 -0
- package/dist/config/nonEffectFolders.js +17 -0
- package/dist/config/nonEffectFolders.js.map +1 -0
- 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/runRules.d.ts.map +1 -1
- package/dist/engine/runRules.js +4 -1
- package/dist/engine/runRules.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/rules/biome.js +2 -2
- package/dist/rules/biome.js.map +1 -1
- package/dist/rules/effect/boundary.js +1 -1
- package/dist/rules/effect/boundary.js.map +1 -1
- package/dist/rules/effect/serviceParameters.js +1 -1
- package/dist/rules/effect/serviceParameters.js.map +1 -1
- package/dist/rules/stories/sources.d.ts +1 -0
- package/dist/rules/stories/sources.d.ts.map +1 -1
- package/dist/rules/stories/sources.js +17 -0
- package/dist/rules/stories/sources.js.map +1 -1
- package/dist/rules/stories/waitOnEvents.d.ts.map +1 -1
- package/dist/rules/stories/waitOnEvents.js +74 -10
- package/dist/rules/stories/waitOnEvents.js.map +1 -1
- package/dist/testing/ruleStory.d.ts +1 -0
- package/dist/testing/ruleStory.d.ts.map +1 -1
- package/dist/testing/ruleStory.js +4 -0
- package/dist/testing/ruleStory.js.map +1 -1
- package/docs/debt-and-hooks.md +1 -1
- package/package.json +3 -3
- package/src/adapters/biome/relocateConfig.ts +6 -4
- package/src/adapters/biome/run.ts +17 -12
- package/src/adapters/biome/withExceptionConfig.ts +3 -2
- package/src/biome/nonEffectPlugins.ts +27 -0
- package/src/biome/report.ts +5 -3
- package/src/cli/baseline.ts +0 -6
- package/src/cli/fix.ts +13 -5
- package/src/cli/messages.ts +1 -1
- package/src/config/decode.ts +2 -0
- package/src/config/load.ts +2 -0
- package/src/config/nonEffectFolders.ts +26 -0
- package/src/config.ts +1 -0
- package/src/engine/runRules.ts +9 -1
- package/src/engine/session.ts +1 -0
- package/src/rule.ts +1 -0
- package/src/rules/biome.ts +2 -2
- package/src/rules/effect/boundary.ts +1 -1
- package/src/rules/effect/serviceParameters.ts +1 -1
- package/src/rules/stories/sources.ts +18 -0
- package/src/rules/stories/waitOnEvents.ts +89 -10
- package/src/testing/ruleStory.ts +7 -0
|
@@ -1,17 +1,93 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
+
import { isTestSupport } from "#naming/testName.ts";
|
|
3
4
|
import { defineRule } from "#rule.ts";
|
|
4
5
|
import { bindsModule, type ImportBinding, importBindings } from "./importBindings.ts";
|
|
5
|
-
import {
|
|
6
|
+
import { storyWaitSources } from "./sources.ts";
|
|
6
7
|
import { memberName, syntaxFindings, unwrapped } from "./syntax.ts";
|
|
7
8
|
|
|
8
9
|
const MESSAGE =
|
|
9
|
-
"Waits on time in a story: a sleep, a timer, polling with eventually or waitFor, fake timers or a
|
|
10
|
+
"Waits on time in a story or reachable test-support: a sleep, a timer, polling with eventually or waitFor, fake timers or a clock adjustment in the spec. Settle on the engine's own signal through a kit verb, such as a Deferred the engine completes, story.runUntil or screenDriver's settle(). A deadline bounds a failure but does not prove completion; reaching it must fail the story. When time passing is the behaviour, name it in a kit verb that advances TestClock.";
|
|
10
11
|
|
|
11
12
|
const TIMERS = new Set(["setInterval", "setTimeout"]);
|
|
12
13
|
const VI_TIMING = /^(?:useFakeTimers|advanceTimers\w*|runAllTimers\w*|runOnlyPendingTimers\w*|runAllTicks|setSystemTime|waitFor|waitUntil)$/u;
|
|
13
14
|
const CLOCK_CHANGES = new Set(["adjust", "setTime"]);
|
|
14
15
|
|
|
16
|
+
function terminal(body: ts.ConciseBody): ts.Expression | undefined {
|
|
17
|
+
if (!ts.isBlock(body)) {
|
|
18
|
+
return unwrapped(body);
|
|
19
|
+
}
|
|
20
|
+
const last = body.statements.at(-1);
|
|
21
|
+
return last !== undefined && (ts.isReturnStatement(last) || ts.isExpressionStatement(last)) ? last.expression : undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function fails(expression: ts.Expression, bindings: ReadonlyMap<string, ImportBinding>): boolean {
|
|
25
|
+
const value = unwrapped(expression);
|
|
26
|
+
if (ts.isArrowFunction(value) || ts.isFunctionExpression(value)) {
|
|
27
|
+
const result = terminal(value.body);
|
|
28
|
+
return result !== undefined && fails(result, bindings);
|
|
29
|
+
}
|
|
30
|
+
if (!(ts.isCallExpression(value) && ts.isPropertyAccessExpression(value.expression))) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const receiver = value.expression.expression;
|
|
34
|
+
return (
|
|
35
|
+
ts.isIdentifier(receiver)
|
|
36
|
+
&& bindsModule(bindings.get(receiver.text), "Effect", ["effect"])
|
|
37
|
+
&& ["die", "fail"].includes(value.expression.name.text)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function failingSleep(call: ts.CallExpression, bindings: ReadonlyMap<string, ImportBinding>): boolean {
|
|
42
|
+
const access = call.parent;
|
|
43
|
+
const pipe = access.parent;
|
|
44
|
+
if (!(ts.isPropertyAccessExpression(access) && access.name.text === "pipe" && ts.isCallExpression(pipe) && pipe.arguments.length === 1)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const step = pipe.arguments[0];
|
|
48
|
+
if (step === undefined || !ts.isCallExpression(step) || memberName(step.expression) !== "andThen") {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const receiver = ts.isPropertyAccessExpression(step.expression) ? step.expression.expression : undefined;
|
|
52
|
+
return (
|
|
53
|
+
receiver !== undefined
|
|
54
|
+
&& ts.isIdentifier(receiver)
|
|
55
|
+
&& bindsModule(bindings.get(receiver.text), "Effect", ["effect"])
|
|
56
|
+
&& step.arguments.length === 1
|
|
57
|
+
&& step.arguments[0] !== undefined
|
|
58
|
+
&& fails(step.arguments[0], bindings)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function rejectionName(call: ts.CallExpression): string | undefined {
|
|
63
|
+
for (let node: ts.Node | undefined = call.parent; node !== undefined; node = node.parent) {
|
|
64
|
+
if (
|
|
65
|
+
(ts.isArrowFunction(node) || ts.isFunctionExpression(node))
|
|
66
|
+
&& ts.isNewExpression(node.parent)
|
|
67
|
+
&& ts.isIdentifier(node.parent.expression)
|
|
68
|
+
&& node.parent.expression.text === "Promise"
|
|
69
|
+
) {
|
|
70
|
+
const name = node.parameters[1]?.name;
|
|
71
|
+
return name !== undefined && ts.isIdentifier(name) ? name.text : undefined;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function rejectingTimer(call: ts.CallExpression): boolean {
|
|
78
|
+
const reject = rejectionName(call);
|
|
79
|
+
const callback = call.arguments[0];
|
|
80
|
+
if (reject === undefined || callback === undefined) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const body = ts.isArrowFunction(callback) || ts.isFunctionExpression(callback) ? terminal(callback.body) : callback;
|
|
84
|
+
return (
|
|
85
|
+
body !== undefined
|
|
86
|
+
&& ((ts.isIdentifier(body) && body.text === reject)
|
|
87
|
+
|| (ts.isCallExpression(body) && ts.isIdentifier(body.expression) && body.expression.text === reject))
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
15
91
|
function receiverOf(callee: ts.Expression): ts.Identifier | undefined {
|
|
16
92
|
const receiver = ts.isPropertyAccessExpression(callee) ? unwrapped(callee.expression) : undefined;
|
|
17
93
|
return receiver !== undefined && ts.isIdentifier(receiver) ? receiver : undefined;
|
|
@@ -22,10 +98,12 @@ function vitestTiming(receiver: ts.Identifier, bindings: ReadonlyMap<string, Imp
|
|
|
22
98
|
return binding === undefined ? receiver.text === "vi" : bindsModule(binding, "vi", ["vitest", "@effect/vitest"]);
|
|
23
99
|
}
|
|
24
100
|
|
|
25
|
-
function timedWait(call: ts.CallExpression, bindings: ReadonlyMap<string, ImportBinding
|
|
101
|
+
function timedWait(call: ts.CallExpression, bindings: ReadonlyMap<string, ImportBinding>, support: boolean): boolean {
|
|
26
102
|
const callee = unwrapped(call.expression);
|
|
27
103
|
if (ts.isIdentifier(callee)) {
|
|
28
|
-
return
|
|
104
|
+
return (
|
|
105
|
+
(TIMERS.has(callee.text) && !(callee.text === "setTimeout" && rejectingTimer(call))) || bindings.get(callee.text)?.imported === "eventually"
|
|
106
|
+
);
|
|
29
107
|
}
|
|
30
108
|
const member = memberName(callee) ?? "";
|
|
31
109
|
const receiver = receiverOf(callee);
|
|
@@ -34,18 +112,19 @@ function timedWait(call: ts.CallExpression, bindings: ReadonlyMap<string, Import
|
|
|
34
112
|
}
|
|
35
113
|
const binding = bindings.get(receiver.text);
|
|
36
114
|
return (
|
|
37
|
-
(member === "sleep" && bindsModule(binding, "Effect", ["effect"]))
|
|
115
|
+
(member === "sleep" && bindsModule(binding, "Effect", ["effect"]) && !failingSleep(call, bindings))
|
|
38
116
|
|| (VI_TIMING.test(member) && vitestTiming(receiver, bindings))
|
|
39
|
-
|| (CLOCK_CHANGES.has(member) && bindsModule(binding, "TestClock", ["effect/testing"]))
|
|
40
|
-
|| (TIMERS.has(member) && receiver.text === "globalThis")
|
|
117
|
+
|| (!support && CLOCK_CHANGES.has(member) && bindsModule(binding, "TestClock", ["effect/testing"]))
|
|
118
|
+
|| (TIMERS.has(member) && receiver.text === "globalThis" && !(member === "setTimeout" && rejectingTimer(call)))
|
|
41
119
|
);
|
|
42
120
|
}
|
|
43
121
|
|
|
44
122
|
function timedWaits(source: ts.SourceFile): readonly ts.Node[] {
|
|
45
123
|
const bindings = importBindings(source);
|
|
124
|
+
const support = isTestSupport(source.fileName);
|
|
46
125
|
const found: ts.Node[] = [];
|
|
47
126
|
function visit(node: ts.Node): void {
|
|
48
|
-
if (ts.isCallExpression(node) && timedWait(node, bindings)) {
|
|
127
|
+
if (ts.isCallExpression(node) && timedWait(node, bindings, support)) {
|
|
49
128
|
found.push(node);
|
|
50
129
|
}
|
|
51
130
|
ts.forEachChild(node, visit);
|
|
@@ -55,7 +134,7 @@ function timedWaits(source: ts.SourceFile): readonly ts.Node[] {
|
|
|
55
134
|
}
|
|
56
135
|
|
|
57
136
|
export const waitOnEvents = defineRule({
|
|
58
|
-
check: (inputs) => Effect.map(
|
|
59
|
-
description: "Stories settle on the engine's own signals
|
|
137
|
+
check: (inputs) => Effect.map(storyWaitSources(inputs), (sources) => sources.flatMap((file) => syntaxFindings(file, timedWaits, MESSAGE))),
|
|
138
|
+
description: "Stories and reachable test-support settle on the engine's own signals; controlled clock advances belong in kit verbs.",
|
|
60
139
|
id: "tests/wait-on-events",
|
|
61
140
|
});
|
package/src/testing/ruleStory.ts
CHANGED
|
@@ -90,6 +90,13 @@ export function makeRuleStory() {
|
|
|
90
90
|
}),
|
|
91
91
|
gateOutcome: () => Effect.map(answered(engine), outcomeOf),
|
|
92
92
|
gateReport: () => Effect.map(answered(engine), (answer) => answer.stdout + answer.stderr),
|
|
93
|
+
gateReports: (prefix: string) =>
|
|
94
|
+
Effect.map(answered(engine), (answer) =>
|
|
95
|
+
answer.stdout
|
|
96
|
+
.split("\n\n")
|
|
97
|
+
.filter((section) => section.startsWith(`error ${prefix}`))
|
|
98
|
+
.join("\n\n"),
|
|
99
|
+
),
|
|
93
100
|
locations: () => Effect.map(checked(engine), (findings) => findings.map(locationOf)),
|
|
94
101
|
messages: () => Effect.map(checked(engine), (findings) => findings.map((finding) => finding.message)),
|
|
95
102
|
optionIssues: Effect.fn("RuleStory.optionIssues")(function* (rule: RegisteredRule, options: unknown) {
|