@milkenjoyer/toolchain 0.21.0 → 0.22.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/README.md +2 -0
- package/TESTING.md +26 -0
- package/dist/{effect-plugin-BiskbKO9.mjs → effect-plugin-roghk4W1.mjs} +0 -1
- package/dist/effect-plugin.mjs +1 -1
- package/dist/exceptions-D0yZUk8P.mjs +145 -0
- package/dist/exceptions.mjs +1 -1
- package/dist/{guard-CAm90ZGy.mjs → guard-n0LC_buo.mjs} +2 -2
- package/dist/guard.mjs +1 -1
- package/dist/{lint-CiO5Etue.mjs → lint-Bx4NP_kA.mjs} +4 -4
- package/dist/lint.mjs +1 -1
- package/dist/{plugin-DwQM07Ih.mjs → plugin-DUUAfi92.mjs} +324 -28
- package/dist/plugin.d.mts +5 -0
- package/dist/plugin.mjs +1 -1
- package/dist/{rules-vHmNoAU0.mjs → rules-5qwzfDWJ.mjs} +3 -1
- package/dist/rules.d.mts +2 -0
- package/dist/rules.mjs +1 -1
- package/dist/standard.mjs +1 -1
- package/package.json +2 -1
- package/src/effect-plugin.ts +0 -1
- package/src/exceptions.ts +132 -0
- package/src/plugin.ts +10 -0
- package/src/rules/no-mock-call-mirrors.ts +121 -0
- package/src/rules/no-test-internal-imports.ts +102 -0
- package/src/rules/no-test-timeouts.ts +83 -0
- package/src/rules/no-test-waits.ts +113 -0
- package/src/rules/require-test-quarantine.ts +36 -0
- package/src/rules/test-api.ts +57 -0
- package/src/rules/test-hygiene.test.ts +241 -0
- package/src/rules/test-package.ts +32 -0
- package/src/rules.ts +2 -0
- package/src/shared/member-path.ts +7 -0
- package/dist/exceptions-Dybl9xpc.mjs +0 -11
|
@@ -108,10 +108,12 @@ const staticRules = {
|
|
|
108
108
|
"unicorn/prefer-module": "error",
|
|
109
109
|
"unicorn/prefer-number-properties": "error",
|
|
110
110
|
"vitest/expect-expect": "off",
|
|
111
|
+
"vitest/no-disabled-tests": "off",
|
|
111
112
|
"vitest/no-identical-title": "error",
|
|
112
113
|
"vitest/no-import-node-test": "error",
|
|
113
114
|
"vitest/no-standalone-expect": "off",
|
|
114
115
|
"vitest/valid-expect": ["error", { maxArgs: 2 }],
|
|
115
|
-
"vitest/valid-title": ["error", { allowArguments: true }]
|
|
116
|
+
"vitest/valid-title": ["error", { allowArguments: true }],
|
|
117
|
+
"vitest/warn-todo": "off"
|
|
116
118
|
};
|
|
117
119
|
export { staticRules as t };
|
package/dist/rules.d.mts
CHANGED
|
@@ -103,6 +103,7 @@ export declare const staticRules: {
|
|
|
103
103
|
"unicorn/prefer-module": "error";
|
|
104
104
|
"unicorn/prefer-number-properties": "error";
|
|
105
105
|
"vitest/expect-expect": "off";
|
|
106
|
+
"vitest/no-disabled-tests": "off";
|
|
106
107
|
"vitest/no-identical-title": "error";
|
|
107
108
|
"vitest/no-import-node-test": "error";
|
|
108
109
|
"vitest/no-standalone-expect": "off";
|
|
@@ -112,4 +113,5 @@ export declare const staticRules: {
|
|
|
112
113
|
"vitest/valid-title": ["error", {
|
|
113
114
|
allowArguments: boolean;
|
|
114
115
|
}];
|
|
116
|
+
"vitest/warn-todo": "off";
|
|
115
117
|
};
|
package/dist/rules.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as staticRules } from "./rules-
|
|
1
|
+
export { t as staticRules } from "./rules-5qwzfDWJ.mjs";
|
package/dist/standard.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { f as versionOf } from "./versions-KbYa8kbF.mjs";
|
|
3
|
-
import { a as ruleFindings, c as exactFindings, l as manifestRanges, s as PLAIN, u as resolveCatalog } from "./guard-
|
|
3
|
+
import { a as ruleFindings, c as exactFindings, l as manifestRanges, s as PLAIN, u as resolveCatalog } from "./guard-n0LC_buo.mjs";
|
|
4
4
|
import { t as fmt } from "./fmt-C6autuPP.mjs";
|
|
5
5
|
import { n as criticalFindings, t as decode } from "./specs-file-Ck9ZOt46.mjs";
|
|
6
6
|
import * as Console from "effect/Console";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkenjoyer/toolchain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/birbprophet/agent-kit.git",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|
|
20
20
|
"STARTS.md",
|
|
21
|
+
"TESTING.md",
|
|
21
22
|
"formal-tools/tla2tools-1.8.0.jar",
|
|
22
23
|
"licenses",
|
|
23
24
|
"node-version",
|
package/src/effect-plugin.ts
CHANGED
package/src/exceptions.ts
CHANGED
|
@@ -5,6 +5,138 @@ export type Exception = {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
export const exceptions: ReadonlyArray<Exception> = [
|
|
8
|
+
{
|
|
9
|
+
files: [
|
|
10
|
+
"packages/toolchain/tests/renovate-ci.test.ts",
|
|
11
|
+
"packages/toolchain/tests/standard-fixture.ts",
|
|
12
|
+
"plugins/agent-kit/tests/board.test.ts",
|
|
13
|
+
"plugins/agent-kit/tests/codex-usage.test.ts",
|
|
14
|
+
"plugins/agent-kit/tests/kept-clock.test.ts",
|
|
15
|
+
"plugins/agent-kit/tests/kept-clock.ts",
|
|
16
|
+
"plugins/agent-kit/tests/kept-fake.ts",
|
|
17
|
+
"plugins/agent-kit/tests/kept-fixes.test.ts",
|
|
18
|
+
"plugins/agent-kit/tests/kept-plan.test.ts",
|
|
19
|
+
"plugins/agent-kit/tests/kept-relocation.test.ts",
|
|
20
|
+
"plugins/agent-kit/tests/kept-runner.test.ts",
|
|
21
|
+
"plugins/agent-kit/tests/kept.test.ts",
|
|
22
|
+
"plugins/agent-kit/tests/pool-quota.test.ts",
|
|
23
|
+
"plugins/agent-kit/tests/request-ready.test.ts",
|
|
24
|
+
"plugins/agent-kit/tests/wait-ready.test.ts",
|
|
25
|
+
"tests/ready-request.test.ts",
|
|
26
|
+
"tests/repo-guard/check.test.ts",
|
|
27
|
+
],
|
|
28
|
+
rules: ["birbprophet/no-test-waits"],
|
|
29
|
+
issue: "https://github.com/birbprophet/agent-kit/issues/532",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
files: [
|
|
33
|
+
"packages/toolchain/tests/bins-packed.test.ts",
|
|
34
|
+
"packages/toolchain/tests/build.test.ts",
|
|
35
|
+
"packages/toolchain/tests/false-positives.test.ts",
|
|
36
|
+
"packages/toolchain/tests/formal-arithmetic.test.ts",
|
|
37
|
+
"packages/toolchain/tests/formal-proofs.test.ts",
|
|
38
|
+
"packages/toolchain/tests/formal.test.ts",
|
|
39
|
+
"packages/toolchain/tests/hooks.test.ts",
|
|
40
|
+
"packages/toolchain/tests/knip.test.ts",
|
|
41
|
+
"packages/toolchain/tests/rules.test.ts",
|
|
42
|
+
"packages/toolchain/tests/standard-aggregate-ids.test.ts",
|
|
43
|
+
"packages/toolchain/tests/standard-config.test.ts",
|
|
44
|
+
"packages/toolchain/tests/standard-domain-layout.test.ts",
|
|
45
|
+
"packages/toolchain/tests/standard-domain.test.ts",
|
|
46
|
+
"packages/toolchain/tests/standard-infra.test.ts",
|
|
47
|
+
"packages/toolchain/tests/standard-pins.test.ts",
|
|
48
|
+
"packages/toolchain/tests/standard-rules.test.ts",
|
|
49
|
+
"plugins/agent-kit/tests/codex-launch.test.ts",
|
|
50
|
+
"plugins/agent-kit/tests/kept-admission.test.ts",
|
|
51
|
+
"plugins/agent-kit/tests/kept-fixes.test.ts",
|
|
52
|
+
"plugins/agent-kit/tests/kept-relocation.test.ts",
|
|
53
|
+
"plugins/agent-kit/tests/kept-runner.test.ts",
|
|
54
|
+
"plugins/agent-kit/tests/kept.test.ts",
|
|
55
|
+
"tests/no-comments.test.ts",
|
|
56
|
+
"tests/repo-guard/check.test.ts",
|
|
57
|
+
"tests/spawned-commands.test.ts",
|
|
58
|
+
],
|
|
59
|
+
rules: ["birbprophet/no-test-timeouts"],
|
|
60
|
+
issue: "https://github.com/birbprophet/agent-kit/issues/532",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
files: [
|
|
64
|
+
"packages/toolchain/tests/catalog.test.ts",
|
|
65
|
+
"packages/toolchain/tests/ci-budget.test.ts",
|
|
66
|
+
"packages/toolchain/tests/fixtures/formal/formal/counter.conformance.ts",
|
|
67
|
+
"packages/toolchain/tests/fixtures/proofs/formal/add32.proof.ts",
|
|
68
|
+
"packages/toolchain/tests/fixtures/proofs/formal/credits.proof.ts",
|
|
69
|
+
"packages/toolchain/tests/fixtures/proofs/formal/next-below.proof.ts",
|
|
70
|
+
"packages/toolchain/tests/fixtures/proofs/formal/used-percent.proof.ts",
|
|
71
|
+
"packages/toolchain/tests/foldkit-vite.test.ts",
|
|
72
|
+
"packages/toolchain/tests/formal-traces.test.ts",
|
|
73
|
+
"packages/toolchain/tests/hooks-fixture.ts",
|
|
74
|
+
"packages/toolchain/tests/hooks.test.ts",
|
|
75
|
+
"packages/toolchain/tests/renovate-ci.test.ts",
|
|
76
|
+
"packages/toolchain/tests/renovate.test.ts",
|
|
77
|
+
"packages/toolchain/tests/rules.test.ts",
|
|
78
|
+
"packages/toolchain/tests/rules/no-comments.test.ts",
|
|
79
|
+
"packages/toolchain/tests/rules/no-process-env.test.ts",
|
|
80
|
+
"packages/toolchain/tests/rules/prefer-accessible-scene-locators.test.ts",
|
|
81
|
+
"packages/toolchain/tests/rules/require-command-answer-names.test.ts",
|
|
82
|
+
"packages/toolchain/tests/rules/require-past-tense-messages.test.ts",
|
|
83
|
+
"packages/toolchain/tests/rules/use-temp-file-scoped.test.ts",
|
|
84
|
+
"packages/toolchain/tests/solver.test.ts",
|
|
85
|
+
"packages/toolchain/tests/standard-domain.test.ts",
|
|
86
|
+
"packages/toolchain/tests/standard-infra.test.ts",
|
|
87
|
+
"packages/toolchain/tests/standard-pins.test.ts",
|
|
88
|
+
"packages/toolchain/tests/standard.test.ts",
|
|
89
|
+
"packages/toolchain/tests/starts-policy.test.ts",
|
|
90
|
+
"packages/toolchain/tests/verdict.test.ts",
|
|
91
|
+
"packages/toolchain/tests/verification.test.ts",
|
|
92
|
+
"plugins/agent-kit/tests/board.test.ts",
|
|
93
|
+
"plugins/agent-kit/tests/boat-cost.test.ts",
|
|
94
|
+
"plugins/agent-kit/tests/boat-paid.test.ts",
|
|
95
|
+
"plugins/agent-kit/tests/cleanup.test.ts",
|
|
96
|
+
"plugins/agent-kit/tests/codex-launch.test.ts",
|
|
97
|
+
"plugins/agent-kit/tests/codex-usage.test.ts",
|
|
98
|
+
"plugins/agent-kit/tests/disk-policy.test.ts",
|
|
99
|
+
"plugins/agent-kit/tests/fixed-model-quota.test.ts",
|
|
100
|
+
"plugins/agent-kit/tests/free-resets.test.ts",
|
|
101
|
+
"plugins/agent-kit/tests/kept-admission.test.ts",
|
|
102
|
+
"plugins/agent-kit/tests/kept-cli.test.ts",
|
|
103
|
+
"plugins/agent-kit/tests/kept-clock.test.ts",
|
|
104
|
+
"plugins/agent-kit/tests/kept-fake.ts",
|
|
105
|
+
"plugins/agent-kit/tests/kept-fixes.test.ts",
|
|
106
|
+
"plugins/agent-kit/tests/kept-hydration.test.ts",
|
|
107
|
+
"plugins/agent-kit/tests/kept-observation.test.ts",
|
|
108
|
+
"plugins/agent-kit/tests/kept-plan.test.ts",
|
|
109
|
+
"plugins/agent-kit/tests/kept-relocation.test.ts",
|
|
110
|
+
"plugins/agent-kit/tests/kept-runner.test.ts",
|
|
111
|
+
"plugins/agent-kit/tests/kept.test.ts",
|
|
112
|
+
"plugins/agent-kit/tests/pool-order.test.ts",
|
|
113
|
+
"plugins/agent-kit/tests/pool-quota.test.ts",
|
|
114
|
+
"plugins/agent-kit/tests/provider-slots.test.ts",
|
|
115
|
+
"plugins/agent-kit/tests/proxy-quota.test.ts",
|
|
116
|
+
"plugins/agent-kit/tests/queue-fixture.ts",
|
|
117
|
+
"plugins/agent-kit/tests/queue-members.test.ts",
|
|
118
|
+
"plugins/agent-kit/tests/queue-plan.test.ts",
|
|
119
|
+
"plugins/agent-kit/tests/queue-resets.test.ts",
|
|
120
|
+
"plugins/agent-kit/tests/queue-unread.test.ts",
|
|
121
|
+
"plugins/agent-kit/tests/queue-upkeep.test.ts",
|
|
122
|
+
"plugins/agent-kit/tests/queue-usage.test.ts",
|
|
123
|
+
"plugins/agent-kit/tests/queue.test.ts",
|
|
124
|
+
"plugins/agent-kit/tests/request-ready.test.ts",
|
|
125
|
+
"plugins/agent-kit/tests/trust-hooks.test.ts",
|
|
126
|
+
"plugins/agent-kit/tests/unbound-census.test.ts",
|
|
127
|
+
"plugins/agent-kit/tests/wait-ready.test.ts",
|
|
128
|
+
"tests/exact-versions.test.ts",
|
|
129
|
+
"tests/ready-main.test.ts",
|
|
130
|
+
"tests/ready-request.test.ts",
|
|
131
|
+
"tests/spawned-commands.test.ts",
|
|
132
|
+
"tests/standard-plugin-skills.test.ts",
|
|
133
|
+
"tests/toolchain-adoption.test.ts",
|
|
134
|
+
"tests/workflow-policy.test.ts",
|
|
135
|
+
"tests/workflow-shell.test.ts",
|
|
136
|
+
],
|
|
137
|
+
rules: ["birbprophet/no-test-internal-imports"],
|
|
138
|
+
issue: "https://github.com/birbprophet/agent-kit/issues/532",
|
|
139
|
+
},
|
|
8
140
|
{
|
|
9
141
|
files: ["packages/toolchain/src/conformance.ts"],
|
|
10
142
|
rules: [
|
package/src/plugin.ts
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import { Plugin } from "effect-oxlint";
|
|
2
2
|
|
|
3
3
|
import { noCommentsRule } from "./rules/no-comments.ts";
|
|
4
|
+
import { noMockCallMirrorsRule } from "./rules/no-mock-call-mirrors.ts";
|
|
4
5
|
import { noProcessEnvRule } from "./rules/no-process-env.ts";
|
|
6
|
+
import { noTestInternalImportsRule } from "./rules/no-test-internal-imports.ts";
|
|
7
|
+
import { noTestTimeoutsRule } from "./rules/no-test-timeouts.ts";
|
|
8
|
+
import { noTestWaitsRule } from "./rules/no-test-waits.ts";
|
|
5
9
|
import { preferAccessibleSceneLocatorsRule } from "./rules/prefer-accessible-scene-locators.ts";
|
|
6
10
|
import { requireCommandAnswerNamesRule } from "./rules/require-command-answer-names.ts";
|
|
7
11
|
import { requirePastTenseMessagesRule } from "./rules/require-past-tense-messages.ts";
|
|
12
|
+
import { requireTestQuarantineRule } from "./rules/require-test-quarantine.ts";
|
|
8
13
|
|
|
9
14
|
const plugin = Plugin.define({
|
|
10
15
|
name: "birbprophet",
|
|
11
16
|
rules: {
|
|
17
|
+
"no-test-internal-imports": noTestInternalImportsRule,
|
|
18
|
+
"no-mock-call-mirrors": noMockCallMirrorsRule,
|
|
19
|
+
"require-test-quarantine": requireTestQuarantineRule,
|
|
20
|
+
"no-test-waits": noTestWaitsRule,
|
|
21
|
+
"no-test-timeouts": noTestTimeoutsRule,
|
|
12
22
|
"no-comments": noCommentsRule,
|
|
13
23
|
"no-process-env": noProcessEnvRule,
|
|
14
24
|
"prefer-accessible-scene-locators": preferAccessibleSceneLocatorsRule,
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { Diagnostic, Rule, RuleContext } from "effect-oxlint";
|
|
5
|
+
import type { ESTree } from "effect-oxlint";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Option from "effect/Option";
|
|
8
|
+
|
|
9
|
+
import { importedPath, lastName } from "../shared/member-path.ts";
|
|
10
|
+
import {
|
|
11
|
+
isStringLiteral,
|
|
12
|
+
memberPropertyName,
|
|
13
|
+
unwrapExpression,
|
|
14
|
+
} from "../shared/syntax.ts";
|
|
15
|
+
import { isTestFile, testPath } from "./test-api.ts";
|
|
16
|
+
import { packageAt } from "./test-package.ts";
|
|
17
|
+
|
|
18
|
+
export const noMockCallMirrorsRule = Rule.define({
|
|
19
|
+
*create() {
|
|
20
|
+
const context = yield* RuleContext;
|
|
21
|
+
if (!isTestFile(context.filename)) return {};
|
|
22
|
+
const own = packageAt(dirname(context.filename));
|
|
23
|
+
const require = createRequire(context.filename);
|
|
24
|
+
const local = (source: string): boolean => {
|
|
25
|
+
if (
|
|
26
|
+
/^(?:\.|#)/u.test(source) ||
|
|
27
|
+
Option.exists(
|
|
28
|
+
own,
|
|
29
|
+
({ manifest }) =>
|
|
30
|
+
manifest.name !== undefined &&
|
|
31
|
+
(source === manifest.name || source.startsWith(`${manifest.name}/`))
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
return true;
|
|
35
|
+
try {
|
|
36
|
+
const resolved = require.resolve(source);
|
|
37
|
+
return resolved.startsWith("/") && !resolved.includes("/node_modules/");
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const mocked = new Set<string>();
|
|
43
|
+
const assertions: Array<{
|
|
44
|
+
readonly node: ESTree.Node;
|
|
45
|
+
readonly source: string;
|
|
46
|
+
}> = [];
|
|
47
|
+
const sourceOf = (node: ESTree.Node): Option.Option<string> => {
|
|
48
|
+
const value = unwrapExpression(node);
|
|
49
|
+
if (
|
|
50
|
+
value.type === "CallExpression" &&
|
|
51
|
+
["mocked", "expect"].includes(
|
|
52
|
+
Option.getOrElse(lastName(value.callee), () => "")
|
|
53
|
+
)
|
|
54
|
+
) {
|
|
55
|
+
const [first] = value.arguments;
|
|
56
|
+
return first === undefined ? Option.none() : sourceOf(first);
|
|
57
|
+
}
|
|
58
|
+
return Option.map(
|
|
59
|
+
importedPath(context.sourceCode, value),
|
|
60
|
+
({ source }) => source
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
CallExpression: (node: ESTree.Node) => {
|
|
65
|
+
if (node.type !== "CallExpression") return Effect.void;
|
|
66
|
+
const path = testPath(context.sourceCode, node.callee);
|
|
67
|
+
const [first] = node.arguments;
|
|
68
|
+
if (
|
|
69
|
+
["vi", "vitest"].includes(path[0] ?? "") &&
|
|
70
|
+
["mock", "doMock"].includes(path[1] ?? "") &&
|
|
71
|
+
first !== undefined &&
|
|
72
|
+
isStringLiteral(first)
|
|
73
|
+
) {
|
|
74
|
+
mocked.add(first.value);
|
|
75
|
+
}
|
|
76
|
+
const callee = unwrapExpression(node.callee);
|
|
77
|
+
if (
|
|
78
|
+
callee.type === "MemberExpression" &&
|
|
79
|
+
Option.getOrElse(memberPropertyName(callee), () => "").startsWith(
|
|
80
|
+
"toHaveBeenCalled"
|
|
81
|
+
)
|
|
82
|
+
) {
|
|
83
|
+
let object = unwrapExpression(callee.object);
|
|
84
|
+
while (object.type === "MemberExpression")
|
|
85
|
+
object = unwrapExpression(object.object);
|
|
86
|
+
if (
|
|
87
|
+
object.type === "CallExpression" &&
|
|
88
|
+
testPath(context.sourceCode, object.callee)[0] === "expect"
|
|
89
|
+
) {
|
|
90
|
+
const [subject] = object.arguments;
|
|
91
|
+
if (subject !== undefined)
|
|
92
|
+
Option.match(sourceOf(subject), {
|
|
93
|
+
onNone: () => undefined,
|
|
94
|
+
onSome: (source) => assertions.push({ node, source }),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return Effect.void;
|
|
99
|
+
},
|
|
100
|
+
"Program:exit": () =>
|
|
101
|
+
Effect.forEach(
|
|
102
|
+
assertions.filter(
|
|
103
|
+
({ source }) => mocked.has(source) && local(source)
|
|
104
|
+
),
|
|
105
|
+
({ node }) =>
|
|
106
|
+
context.report(Diagnostic.fromId({ node, messageId: "behavior" })),
|
|
107
|
+
{ discard: true, concurrency: 1 }
|
|
108
|
+
),
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
meta: Rule.meta({
|
|
112
|
+
description:
|
|
113
|
+
"Local module mocks are not asserted through their call history",
|
|
114
|
+
messages: {
|
|
115
|
+
behavior:
|
|
116
|
+
"Run the real local module and assert its observable result. Delete the local vi.mock and the toHaveBeenCalled mirror.",
|
|
117
|
+
},
|
|
118
|
+
type: "problem",
|
|
119
|
+
}),
|
|
120
|
+
name: "no-mock-call-mirrors",
|
|
121
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { dirname, join, resolve } from "node:path";
|
|
2
|
+
|
|
3
|
+
import { Diagnostic, Rule, RuleContext } from "effect-oxlint";
|
|
4
|
+
import type { ESTree } from "effect-oxlint";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Option from "effect/Option";
|
|
7
|
+
|
|
8
|
+
import { isStringLiteral } from "../shared/syntax.ts";
|
|
9
|
+
import { isTestFile } from "./test-api.ts";
|
|
10
|
+
import { manifestAt, packageAt } from "./test-package.ts";
|
|
11
|
+
|
|
12
|
+
const publicSubpath = (exports: unknown, subpath: string): boolean => {
|
|
13
|
+
if (exports === undefined) return subpath === ".";
|
|
14
|
+
if (typeof exports === "string" || exports === null || Array.isArray(exports))
|
|
15
|
+
return subpath === "." && exports !== null;
|
|
16
|
+
if (typeof exports !== "object") return false;
|
|
17
|
+
const keys = Object.keys(exports);
|
|
18
|
+
if (!keys.some((key) => key.startsWith("."))) return subpath === ".";
|
|
19
|
+
const entries = Object.entries(exports);
|
|
20
|
+
const exact = entries.find(([key]) => key === subpath);
|
|
21
|
+
if (exact !== undefined) return exact[1] !== null;
|
|
22
|
+
const patterns = entries
|
|
23
|
+
.filter(([key]) => key.includes("*"))
|
|
24
|
+
.toSorted(([a], [b]) => {
|
|
25
|
+
const prefix = b.indexOf("*") - a.indexOf("*");
|
|
26
|
+
return prefix === 0 ? b.length - a.length : prefix;
|
|
27
|
+
});
|
|
28
|
+
const matched = patterns.find(([key]) => {
|
|
29
|
+
const [prefix, suffix] = key.split("*");
|
|
30
|
+
return subpath.startsWith(prefix ?? "") && subpath.endsWith(suffix ?? "");
|
|
31
|
+
});
|
|
32
|
+
return matched !== undefined && matched[1] !== null;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const noTestInternalImportsRule = Rule.define({
|
|
36
|
+
*create() {
|
|
37
|
+
const context = yield* RuleContext;
|
|
38
|
+
if (!isTestFile(context.filename)) return {};
|
|
39
|
+
const folder = dirname(context.filename);
|
|
40
|
+
const own = packageAt(folder);
|
|
41
|
+
const internal = (source: string): boolean => {
|
|
42
|
+
if (source.startsWith(".")) {
|
|
43
|
+
const target = resolve(folder, source);
|
|
44
|
+
if (
|
|
45
|
+
dirname(target) === folder ||
|
|
46
|
+
/\/(?:tests?|__tests__)\//u.test(target)
|
|
47
|
+
)
|
|
48
|
+
return false;
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
const parts = source.split("/");
|
|
52
|
+
const name = source.startsWith("@")
|
|
53
|
+
? parts.slice(0, 2).join("/")
|
|
54
|
+
: (parts[0] ?? "");
|
|
55
|
+
const subpath = source === name ? "." : `.${source.slice(name.length)}`;
|
|
56
|
+
if (source.startsWith("#")) return true;
|
|
57
|
+
if (
|
|
58
|
+
Option.exists(
|
|
59
|
+
own,
|
|
60
|
+
({ manifest }) =>
|
|
61
|
+
manifest.name === name && !publicSubpath(manifest.exports, subpath)
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
return true;
|
|
65
|
+
let directory = folder;
|
|
66
|
+
while (dirname(directory) !== directory) {
|
|
67
|
+
const dependency = manifestAt(join(directory, "node_modules", name));
|
|
68
|
+
if (Option.isSome(dependency))
|
|
69
|
+
return !publicSubpath(dependency.value.exports, subpath);
|
|
70
|
+
directory = dirname(directory);
|
|
71
|
+
}
|
|
72
|
+
return /(?:^|\/)(?:src|internal)\//u.test(source);
|
|
73
|
+
};
|
|
74
|
+
const check = (node: ESTree.Node) =>
|
|
75
|
+
isStringLiteral(node) && internal(node.value)
|
|
76
|
+
? context.report(Diagnostic.fromId({ node, messageId: "public" }))
|
|
77
|
+
: Effect.void;
|
|
78
|
+
return {
|
|
79
|
+
ImportDeclaration: (node: ESTree.Node) =>
|
|
80
|
+
node.type === "ImportDeclaration" ? check(node.source) : Effect.void,
|
|
81
|
+
ImportExpression: (node: ESTree.Node) =>
|
|
82
|
+
node.type === "ImportExpression" ? check(node.source) : Effect.void,
|
|
83
|
+
CallExpression: (node: ESTree.Node) =>
|
|
84
|
+
node.type === "CallExpression" &&
|
|
85
|
+
node.callee.type === "Identifier" &&
|
|
86
|
+
node.callee.name === "require" &&
|
|
87
|
+
node.arguments[0] !== undefined
|
|
88
|
+
? check(node.arguments[0])
|
|
89
|
+
: Effect.void,
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
meta: Rule.meta({
|
|
93
|
+
description:
|
|
94
|
+
"Tests use public package exports unless colocated with their subject",
|
|
95
|
+
messages: {
|
|
96
|
+
public:
|
|
97
|
+
"Import the package's public entry point or exported subpath. Move this test beside its subject if it needs internal files.",
|
|
98
|
+
},
|
|
99
|
+
type: "problem",
|
|
100
|
+
}),
|
|
101
|
+
name: "no-test-internal-imports",
|
|
102
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { dirname } from "node:path";
|
|
2
|
+
|
|
3
|
+
import { Diagnostic, Rule, RuleContext } from "effect-oxlint";
|
|
4
|
+
import type { ESTree } from "effect-oxlint";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Option from "effect/Option";
|
|
7
|
+
|
|
8
|
+
import { propertyName } from "../shared/syntax.ts";
|
|
9
|
+
import { isTestCall, isTestFile, testPath } from "./test-api.ts";
|
|
10
|
+
import { packageAt } from "./test-package.ts";
|
|
11
|
+
|
|
12
|
+
export const noTestTimeoutsRule = Rule.define({
|
|
13
|
+
*create() {
|
|
14
|
+
const context = yield* RuleContext;
|
|
15
|
+
const test = isTestFile(context.filename);
|
|
16
|
+
const config = /(?:vitest|vite)\.config\.[cm]?[jt]s$/u.test(
|
|
17
|
+
context.filename
|
|
18
|
+
);
|
|
19
|
+
const report = (node: ESTree.Node) =>
|
|
20
|
+
context.report(Diagnostic.fromId({ node, messageId: "remove" }));
|
|
21
|
+
return {
|
|
22
|
+
Program: (node: ESTree.Node) =>
|
|
23
|
+
(test || config) &&
|
|
24
|
+
Option.exists(packageAt(dirname(context.filename)), ({ manifest }) =>
|
|
25
|
+
Object.values(manifest.scripts ?? {}).some((command) =>
|
|
26
|
+
/(?:^|\s)--retry(?:[=\s]|$)/u.test(command)
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
? report(node)
|
|
30
|
+
: Effect.void,
|
|
31
|
+
CallExpression: (node: ESTree.Node) => {
|
|
32
|
+
if (!test || node.type !== "CallExpression") return Effect.void;
|
|
33
|
+
const path = testPath(context.sourceCode, node.callee);
|
|
34
|
+
const overrides = node.arguments.some(
|
|
35
|
+
(argument) =>
|
|
36
|
+
argument.type === "ObjectExpression" &&
|
|
37
|
+
argument.properties.some(
|
|
38
|
+
(property) =>
|
|
39
|
+
property.type === "Property" &&
|
|
40
|
+
["timeout", "testTimeout", "hookTimeout", "retry"].some(
|
|
41
|
+
(name) => Option.contains(propertyName(property), name)
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
return (isTestCall(context.sourceCode, node.callee) &&
|
|
46
|
+
(node.arguments.length > 2 || path.includes("retry") || overrides)) ||
|
|
47
|
+
path.includes("setTimeout") ||
|
|
48
|
+
(path.includes("setConfig") && overrides)
|
|
49
|
+
? report(node)
|
|
50
|
+
: Effect.void;
|
|
51
|
+
},
|
|
52
|
+
Property: (node: ESTree.Node) =>
|
|
53
|
+
config &&
|
|
54
|
+
node.type === "Property" &&
|
|
55
|
+
["timeout", "testTimeout", "hookTimeout", "retry"].some((name) =>
|
|
56
|
+
Option.contains(propertyName(node), name)
|
|
57
|
+
)
|
|
58
|
+
? report(node)
|
|
59
|
+
: Effect.void,
|
|
60
|
+
Literal: (node: ESTree.Node) =>
|
|
61
|
+
(test || config) &&
|
|
62
|
+
node.type === "Literal" &&
|
|
63
|
+
typeof node.value === "string" &&
|
|
64
|
+
!(
|
|
65
|
+
node.parent.type === "Property" &&
|
|
66
|
+
Option.contains(propertyName(node.parent), "code")
|
|
67
|
+
) &&
|
|
68
|
+
/(?:^|\s)--retry(?:[=\s]|$)/u.test(node.value)
|
|
69
|
+
? report(node)
|
|
70
|
+
: Effect.void,
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
meta: Rule.meta({
|
|
74
|
+
description:
|
|
75
|
+
"Tests use runner defaults without retries or timeout overrides",
|
|
76
|
+
messages: {
|
|
77
|
+
remove:
|
|
78
|
+
"Remove the test timeout or retry override. Fix the slow or flaky test and use the runner defaults.",
|
|
79
|
+
},
|
|
80
|
+
type: "problem",
|
|
81
|
+
}),
|
|
82
|
+
name: "no-test-timeouts",
|
|
83
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Diagnostic, Rule, RuleContext } from "effect-oxlint";
|
|
2
|
+
import type { ESTree } from "effect-oxlint";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
|
|
6
|
+
import { importedPath, lastName } from "../shared/member-path.ts";
|
|
7
|
+
import { memberPropertyName, unwrapExpression } from "../shared/syntax.ts";
|
|
8
|
+
import { isTestFile, testPath } from "./test-api.ts";
|
|
9
|
+
|
|
10
|
+
const wallClock =
|
|
11
|
+
/^(?:(?:globalThis\.)?(?:Date|performance)\s*(?:\.now|\[\s*["']now["']\s*\])|process\.hrtime(?:\.bigint)?)$/u;
|
|
12
|
+
|
|
13
|
+
const waits =
|
|
14
|
+
/^(?:sleep|delay|setTimeout|setInterval|waitFor|waitUntil|waitForTimeout|waitForFunction|waitForNextUpdate|requestAnimationFrame|nextFrame|waitForFrame|poll|eventually|repeat|retry)$/u;
|
|
15
|
+
|
|
16
|
+
export const noTestWaitsRule = Rule.define({
|
|
17
|
+
*create() {
|
|
18
|
+
const context = yield* RuleContext;
|
|
19
|
+
const report = (node: ESTree.Node) =>
|
|
20
|
+
context.report(Diagnostic.fromId({ node, messageId: "synchronize" }));
|
|
21
|
+
if (!isTestFile(context.filename)) return {};
|
|
22
|
+
return {
|
|
23
|
+
CallExpression: (node: ESTree.Node) => {
|
|
24
|
+
if (node.type !== "CallExpression") return Effect.void;
|
|
25
|
+
const callee = unwrapExpression(node.callee);
|
|
26
|
+
const name = Option.getOrElse(
|
|
27
|
+
callee.type === "MemberExpression"
|
|
28
|
+
? memberPropertyName(callee)
|
|
29
|
+
: lastName(callee),
|
|
30
|
+
() => ""
|
|
31
|
+
);
|
|
32
|
+
const imported = importedPath(context.sourceCode, node.callee);
|
|
33
|
+
const path = testPath(context.sourceCode, node.callee);
|
|
34
|
+
const clock = context.sourceCode.getText(node.callee);
|
|
35
|
+
return waits.test(name) ||
|
|
36
|
+
path.includes("poll") ||
|
|
37
|
+
wallClock.test(clock) ||
|
|
38
|
+
Option.exists(
|
|
39
|
+
imported,
|
|
40
|
+
({ source, members }) =>
|
|
41
|
+
(source === "node:perf_hooks" && members.includes("now")) ||
|
|
42
|
+
(source === "node:process" && members.includes("hrtime")) ||
|
|
43
|
+
waits.test(members.at(-1) ?? "") ||
|
|
44
|
+
members.includes("currentTimeMillis") ||
|
|
45
|
+
members.includes("currentTimeNanos")
|
|
46
|
+
)
|
|
47
|
+
? report(node)
|
|
48
|
+
: Effect.void;
|
|
49
|
+
},
|
|
50
|
+
MemberExpression: (node: ESTree.Node) =>
|
|
51
|
+
Option.exists(
|
|
52
|
+
importedPath(context.sourceCode, node),
|
|
53
|
+
({ members }) =>
|
|
54
|
+
members.includes("currentTimeMillis") ||
|
|
55
|
+
members.includes("currentTimeNanos")
|
|
56
|
+
)
|
|
57
|
+
? report(node)
|
|
58
|
+
: Effect.void,
|
|
59
|
+
Identifier: (node: ESTree.Node) =>
|
|
60
|
+
node.type === "Identifier" &&
|
|
61
|
+
node.parent.type !== "ImportSpecifier" &&
|
|
62
|
+
Option.exists(
|
|
63
|
+
importedPath(context.sourceCode, node),
|
|
64
|
+
({ members }) =>
|
|
65
|
+
members.includes("currentTimeMillis") ||
|
|
66
|
+
members.includes("currentTimeNanos")
|
|
67
|
+
)
|
|
68
|
+
? report(node)
|
|
69
|
+
: Effect.void,
|
|
70
|
+
NewExpression: (node: ESTree.Node) =>
|
|
71
|
+
node.type === "NewExpression" &&
|
|
72
|
+
((node.callee.type === "Identifier" &&
|
|
73
|
+
node.callee.name === "Date" &&
|
|
74
|
+
node.arguments.length === 0) ||
|
|
75
|
+
node.arguments.some((argument) =>
|
|
76
|
+
Option.exists(lastName(argument), (name) => waits.test(name))
|
|
77
|
+
))
|
|
78
|
+
? report(node)
|
|
79
|
+
: Effect.void,
|
|
80
|
+
WhileStatement: (node: ESTree.Node) =>
|
|
81
|
+
node.type === "WhileStatement" &&
|
|
82
|
+
(node.test.type === "CallExpression" ||
|
|
83
|
+
node.test.type === "UnaryExpression" ||
|
|
84
|
+
node.test.type === "Literal" ||
|
|
85
|
+
/\bawait\b/u.test(context.sourceCode.getText(node.body)))
|
|
86
|
+
? report(node)
|
|
87
|
+
: Effect.void,
|
|
88
|
+
DoWhileStatement: (node: ESTree.Node) =>
|
|
89
|
+
node.type === "DoWhileStatement" &&
|
|
90
|
+
(node.test.type === "CallExpression" ||
|
|
91
|
+
/\bawait\b/u.test(context.sourceCode.getText(node.body)))
|
|
92
|
+
? report(node)
|
|
93
|
+
: Effect.void,
|
|
94
|
+
ForStatement: (node: ESTree.Node) =>
|
|
95
|
+
node.type === "ForStatement" &&
|
|
96
|
+
/\b(?:await|sleep|poll|retry|waitFor)\b/u.test(
|
|
97
|
+
context.sourceCode.getText(node.body)
|
|
98
|
+
)
|
|
99
|
+
? report(node)
|
|
100
|
+
: Effect.void,
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
meta: Rule.meta({
|
|
104
|
+
description:
|
|
105
|
+
"Tests synchronize on observable completion rather than time or polling",
|
|
106
|
+
messages: {
|
|
107
|
+
synchronize:
|
|
108
|
+
"Remove the sleep, polling loop, wall-clock measurement or frame wait. Await the operation's completion or drive a controlled test clock.",
|
|
109
|
+
},
|
|
110
|
+
type: "problem",
|
|
111
|
+
}),
|
|
112
|
+
name: "no-test-waits",
|
|
113
|
+
});
|