@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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Diagnostic, Rule, RuleContext } from "effect-oxlint";
|
|
2
|
+
import type { ESTree } from "effect-oxlint";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
|
|
5
|
+
import { isTestFile, testPath } from "./test-api.ts";
|
|
6
|
+
|
|
7
|
+
export const requireTestQuarantineRule = Rule.define({
|
|
8
|
+
*create() {
|
|
9
|
+
const context = yield* RuleContext;
|
|
10
|
+
if (!isTestFile(context.filename)) return {};
|
|
11
|
+
const lines = context.sourceCode.text.split(/\r?\n/u);
|
|
12
|
+
return {
|
|
13
|
+
CallExpression: (node: ESTree.Node) => {
|
|
14
|
+
if (node.type !== "CallExpression") return Effect.void;
|
|
15
|
+
const path = testPath(context.sourceCode, node.callee);
|
|
16
|
+
const skipped =
|
|
17
|
+
["it", "test", "describe"].includes(path[0] ?? "") &&
|
|
18
|
+
path.some((name) => ["skip", "todo"].includes(name));
|
|
19
|
+
const line = node.loc.start.line;
|
|
20
|
+
return skipped &&
|
|
21
|
+
!/\bquarantine: #[1-9]\d*\b/u.test(lines[line - 2] ?? "")
|
|
22
|
+
? context.report(Diagnostic.fromId({ node, messageId: "link" }))
|
|
23
|
+
: Effect.void;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
meta: Rule.meta({
|
|
28
|
+
description:
|
|
29
|
+
"Skipped tests name their quarantine issue on the preceding line",
|
|
30
|
+
messages: {
|
|
31
|
+
link: 'Restore this test or put a void "quarantine: #N" statement on the line immediately above it, linking the issue that owns its repair.',
|
|
32
|
+
},
|
|
33
|
+
type: "problem",
|
|
34
|
+
}),
|
|
35
|
+
name: "require-test-quarantine",
|
|
36
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ESTree, OxlintSourceCode } from "effect-oxlint";
|
|
2
|
+
import * as Option from "effect/Option";
|
|
3
|
+
|
|
4
|
+
import { importedPath } from "../shared/member-path.ts";
|
|
5
|
+
|
|
6
|
+
export const isTestFile = (filename: string): boolean =>
|
|
7
|
+
/(?:\.(?:test|spec|fake)\.[cm]?[jt]sx?$|\/(?:tests?|__tests__)\/)/u.test(
|
|
8
|
+
filename
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export const testPath = (
|
|
12
|
+
source: OxlintSourceCode,
|
|
13
|
+
node: ESTree.Node
|
|
14
|
+
): ReadonlyArray<string> =>
|
|
15
|
+
Option.match(importedPath(source, node), {
|
|
16
|
+
onNone: () => {
|
|
17
|
+
const names = source.getText(node).split(".");
|
|
18
|
+
return [
|
|
19
|
+
"it",
|
|
20
|
+
"test",
|
|
21
|
+
"describe",
|
|
22
|
+
"beforeEach",
|
|
23
|
+
"afterEach",
|
|
24
|
+
"beforeAll",
|
|
25
|
+
"afterAll",
|
|
26
|
+
"vi",
|
|
27
|
+
"vitest",
|
|
28
|
+
"expect",
|
|
29
|
+
].includes(names[0] ?? "")
|
|
30
|
+
? names
|
|
31
|
+
: [];
|
|
32
|
+
},
|
|
33
|
+
onSome: ({ source: module, members }) =>
|
|
34
|
+
[
|
|
35
|
+
"@effect/vitest",
|
|
36
|
+
"vitest",
|
|
37
|
+
"vite-plus/test",
|
|
38
|
+
"bun:test",
|
|
39
|
+
"node:test",
|
|
40
|
+
].includes(module)
|
|
41
|
+
? members
|
|
42
|
+
: [],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export const isTestCall = (
|
|
46
|
+
source: OxlintSourceCode,
|
|
47
|
+
node: ESTree.Node
|
|
48
|
+
): boolean =>
|
|
49
|
+
[
|
|
50
|
+
"it",
|
|
51
|
+
"test",
|
|
52
|
+
"describe",
|
|
53
|
+
"beforeEach",
|
|
54
|
+
"afterEach",
|
|
55
|
+
"beforeAll",
|
|
56
|
+
"afterAll",
|
|
57
|
+
].includes(testPath(source, node)[0] ?? "");
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { ruleTester } from "../../tests/rules/rule-tester.ts";
|
|
2
|
+
import { noMockCallMirrorsRule } from "./no-mock-call-mirrors.ts";
|
|
3
|
+
import { noTestInternalImportsRule } from "./no-test-internal-imports.ts";
|
|
4
|
+
import { noTestTimeoutsRule } from "./no-test-timeouts.ts";
|
|
5
|
+
import { noTestWaitsRule } from "./no-test-waits.ts";
|
|
6
|
+
import { requireTestQuarantineRule } from "./require-test-quarantine.ts";
|
|
7
|
+
|
|
8
|
+
const filename = "/project/tests/behavior.test.ts";
|
|
9
|
+
const exportedPackageTest = `${import.meta.dirname}/../../tests/fixtures/test-hygiene/exports.test.ts`;
|
|
10
|
+
|
|
11
|
+
ruleTester.run("no-test-timeouts", noTestTimeoutsRule, {
|
|
12
|
+
valid: [
|
|
13
|
+
{
|
|
14
|
+
filename,
|
|
15
|
+
code: 'import { vi } from "@effect/vitest"; vi.setConfig({ restoreMocks: true });',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
filename,
|
|
19
|
+
code: 'import { it } from "@effect/vitest"; it("finishes", () => {});',
|
|
20
|
+
},
|
|
21
|
+
{ filename, code: "const request = { timeout: 500 };" },
|
|
22
|
+
{
|
|
23
|
+
filename: "/project/src/client.ts",
|
|
24
|
+
code: "const request = { retry: 2 };",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
invalid: [
|
|
28
|
+
{
|
|
29
|
+
filename: `${import.meta.dirname}/../../tests/fixtures/test-hygiene/vite.config.ts`,
|
|
30
|
+
code: "export default {};",
|
|
31
|
+
errors: [{ messageId: "remove" }],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
filename,
|
|
35
|
+
code: 'import { it as check } from "@effect/vitest"; check("finishes", () => {}, 30000);',
|
|
36
|
+
errors: [{ messageId: "remove" }],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
filename,
|
|
40
|
+
code: 'it.effect("finishes", () => effect, 30000);',
|
|
41
|
+
errors: [{ messageId: "remove" }],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
filename,
|
|
45
|
+
code: 'it("finishes", { retry: 2 }, () => {});',
|
|
46
|
+
errors: [{ messageId: "remove" }],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
filename,
|
|
50
|
+
code: 'it("finishes", { timeout: 30000 }, () => {});',
|
|
51
|
+
errors: [{ messageId: "remove" }],
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
filename: "/project/vite.config.ts",
|
|
55
|
+
code: "export default { test: { retry: 2 } };",
|
|
56
|
+
errors: [{ messageId: "remove" }],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
filename,
|
|
60
|
+
code: 'const command = "vp test --retry=2";',
|
|
61
|
+
errors: [{ messageId: "remove" }],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
ruleTester.run("no-test-waits", noTestWaitsRule, {
|
|
67
|
+
valid: [
|
|
68
|
+
{ filename, code: "let i = 0; while (i < 10) i++;" },
|
|
69
|
+
{
|
|
70
|
+
filename,
|
|
71
|
+
code: "await operation.completed; const result = calculate(42);",
|
|
72
|
+
},
|
|
73
|
+
{ filename, code: "for (const input of cases) verify(input);" },
|
|
74
|
+
{ filename: "/project/src/client.ts", code: "await sleep(100);" },
|
|
75
|
+
{
|
|
76
|
+
filename,
|
|
77
|
+
code: 'import * as TestClock from "effect/testing/TestClock"; TestClock.adjust("1 second");',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
invalid: [
|
|
81
|
+
"await sleep(100);",
|
|
82
|
+
"await new Promise(resolve => setTimeout(resolve, 100));",
|
|
83
|
+
"await page.waitForTimeout(100);",
|
|
84
|
+
"const start = Date.now();",
|
|
85
|
+
"const start = performance.now();",
|
|
86
|
+
"requestAnimationFrame(done);",
|
|
87
|
+
"await new Promise(requestAnimationFrame);",
|
|
88
|
+
"new Date();",
|
|
89
|
+
'import { performance as timer } from "node:perf_hooks"; timer.now();',
|
|
90
|
+
'import * as Clock from "effect/Clock"; const start = Clock.currentTimeMillis;',
|
|
91
|
+
'import { currentTimeMillis as now } from "effect/Clock"; const start = now;',
|
|
92
|
+
"while (!done) inspect();",
|
|
93
|
+
"for (let i = 0; i < 10; i++) { await probe(); }",
|
|
94
|
+
'import * as Effect from "effect/Effect"; Effect.retry(task, policy);',
|
|
95
|
+
'import { sleep as pause } from "effect/Effect"; pause("1 second");',
|
|
96
|
+
'import { expect } from "@effect/vitest"; expect.poll(read).toBe(1);',
|
|
97
|
+
].map((code) => ({
|
|
98
|
+
filename,
|
|
99
|
+
code,
|
|
100
|
+
errors: [{ messageId: "synchronize" }],
|
|
101
|
+
})),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
ruleTester.run("require-test-quarantine", requireTestQuarantineRule, {
|
|
105
|
+
valid: [
|
|
106
|
+
{
|
|
107
|
+
filename,
|
|
108
|
+
code: 'import { it } from "@effect/vitest"; it("works", () => {});',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
filename,
|
|
112
|
+
code: 'import { it } from "@effect/vitest";\nvoid "quarantine: #534";\nit.skip("repair", () => {});',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
filename,
|
|
116
|
+
code: 'import { describe as suite } from "@effect/vitest";\nvoid "quarantine: #534";\nsuite.todo("repair");',
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
invalid: [
|
|
120
|
+
{
|
|
121
|
+
filename,
|
|
122
|
+
code: 'import { it } from "@effect/vitest"; it.skip("repair", () => {});',
|
|
123
|
+
errors: [{ messageId: "link" }],
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
filename,
|
|
127
|
+
code: 'describe.todo("repair");',
|
|
128
|
+
errors: [{ messageId: "link" }],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
filename,
|
|
132
|
+
code: 'void "quarantine: #0";\nit.skip("repair", () => {});',
|
|
133
|
+
errors: [{ messageId: "link" }],
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
filename,
|
|
137
|
+
code: 'void "quarantine: #534";\n\nit.todo("repair");',
|
|
138
|
+
errors: [{ messageId: "link" }],
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
ruleTester.run("no-mock-call-mirrors", noMockCallMirrorsRule, {
|
|
144
|
+
valid: [
|
|
145
|
+
{
|
|
146
|
+
filename,
|
|
147
|
+
code: 'import { vi, expect } from "@effect/vitest"; import { save } from "./store"; vi.mock("./store"); expect(save()).toEqual({ saved: true });',
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
filename,
|
|
151
|
+
code: 'import { vi, expect } from "@effect/vitest"; import { send } from "external-sdk"; vi.mock("external-sdk"); expect(send).toHaveBeenCalled();',
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
filename,
|
|
155
|
+
code: 'import { expect } from "@effect/vitest"; import { save } from "./store"; expect(save).toHaveBeenCalled();',
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
invalid: [
|
|
159
|
+
{
|
|
160
|
+
filename,
|
|
161
|
+
code: 'import { vi, expect } from "@effect/vitest"; import save from "./store"; vi.mock("./store"); expect(save).toHaveBeenCalled();',
|
|
162
|
+
errors: [{ messageId: "behavior" }],
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
filename,
|
|
166
|
+
code: 'import { vi, expect } from "@effect/vitest"; import { save } from "./store"; vi.mock("./store"); expect(save).toHaveBeenCalledWith("x");',
|
|
167
|
+
errors: [{ messageId: "behavior" }],
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
filename,
|
|
171
|
+
code: 'import { vi as mocker, expect as check } from "@effect/vitest"; import * as store from "../src/store"; mocker.mock("../src/store"); check(store.save).not.toHaveBeenCalled();',
|
|
172
|
+
errors: [{ messageId: "behavior" }],
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
filename,
|
|
176
|
+
code: 'import { vi, expect } from "@effect/vitest"; import { save as persist } from "./store"; expect(vi.mocked(persist)).toHaveBeenCalledTimes(1); vi.mock("./store");',
|
|
177
|
+
errors: [{ messageId: "behavior" }],
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
ruleTester.run("no-test-internal-imports", noTestInternalImportsRule, {
|
|
183
|
+
valid: [
|
|
184
|
+
{
|
|
185
|
+
filename: exportedPackageTest,
|
|
186
|
+
code: 'import { save } from "test-hygiene-fixture/public/save";',
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
filename: exportedPackageTest,
|
|
190
|
+
code: 'import { save } from "test-hygiene-fixture";',
|
|
191
|
+
},
|
|
192
|
+
{ filename, code: 'import { save } from "store";' },
|
|
193
|
+
{ filename, code: 'import { save } from "store/public";' },
|
|
194
|
+
{
|
|
195
|
+
filename: "/project/src/store.test.ts",
|
|
196
|
+
code: 'import { save } from "./store";',
|
|
197
|
+
},
|
|
198
|
+
{ filename, code: 'import { fixture } from "./fixture";' },
|
|
199
|
+
{
|
|
200
|
+
filename: "/project/src/client.ts",
|
|
201
|
+
code: 'import { save } from "./internal/store";',
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
invalid: [
|
|
205
|
+
{
|
|
206
|
+
filename: exportedPackageTest,
|
|
207
|
+
code: 'import { save } from "test-hygiene-fixture/public/internal/save";',
|
|
208
|
+
errors: [{ messageId: "public" }],
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
filename: exportedPackageTest,
|
|
212
|
+
code: 'import { save } from "test-hygiene-fixture/hidden";',
|
|
213
|
+
errors: [{ messageId: "public" }],
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
filename,
|
|
217
|
+
code: 'import { save } from "../src/store";',
|
|
218
|
+
errors: [{ messageId: "public" }],
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
filename,
|
|
222
|
+
code: 'import { save } from "store/src/store";',
|
|
223
|
+
errors: [{ messageId: "public" }],
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
filename,
|
|
227
|
+
code: 'const store = await import("../src/store");',
|
|
228
|
+
errors: [{ messageId: "public" }],
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
filename,
|
|
232
|
+
code: 'const store = require("store/internal/store");',
|
|
233
|
+
errors: [{ messageId: "public" }],
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
filename,
|
|
237
|
+
code: 'import { save } from "#internal/store";',
|
|
238
|
+
errors: [{ messageId: "public" }],
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
|
|
7
|
+
const Manifest = Schema.fromJsonString(
|
|
8
|
+
Schema.Struct({
|
|
9
|
+
name: Schema.optionalKey(Schema.String),
|
|
10
|
+
scripts: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
|
|
11
|
+
exports: Schema.optionalKey(Schema.Unknown),
|
|
12
|
+
})
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const manifestAt = (folder: string) => {
|
|
16
|
+
const file = join(folder, "package.json");
|
|
17
|
+
if (!existsSync(file)) return Option.none();
|
|
18
|
+
return Schema.decodeOption(Manifest)(readFileSync(file, "utf8"));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const packageAt = (
|
|
22
|
+
folder: string
|
|
23
|
+
): Option.Option<{
|
|
24
|
+
readonly root: string;
|
|
25
|
+
readonly manifest: Schema.Schema.Type<typeof Manifest>;
|
|
26
|
+
}> => {
|
|
27
|
+
const manifest = manifestAt(folder);
|
|
28
|
+
if (Option.isSome(manifest))
|
|
29
|
+
return Option.some({ root: folder, manifest: manifest.value });
|
|
30
|
+
const parent = dirname(folder);
|
|
31
|
+
return parent === folder ? Option.none() : packageAt(parent);
|
|
32
|
+
};
|
package/src/rules.ts
CHANGED
|
@@ -113,9 +113,11 @@ export const staticRules = {
|
|
|
113
113
|
"unicorn/prefer-module": "error",
|
|
114
114
|
"unicorn/prefer-number-properties": "error",
|
|
115
115
|
"vitest/expect-expect": "off",
|
|
116
|
+
"vitest/no-disabled-tests": "off",
|
|
116
117
|
"vitest/no-identical-title": "error",
|
|
117
118
|
"vitest/no-import-node-test": "error",
|
|
118
119
|
"vitest/no-standalone-expect": "off",
|
|
119
120
|
"vitest/valid-expect": ["error", { maxArgs: 2 }],
|
|
120
121
|
"vitest/valid-title": ["error", { allowArguments: true }],
|
|
122
|
+
"vitest/warn-todo": "off",
|
|
121
123
|
} satisfies OxlintConfig["rules"];
|
|
@@ -89,6 +89,13 @@ export const importedPath: {
|
|
|
89
89
|
return { source: declaration.source.value, members: path.members };
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
if (specifier.type === "ImportDefaultSpecifier") {
|
|
93
|
+
return {
|
|
94
|
+
source: declaration.source.value,
|
|
95
|
+
members: ["default", ...path.members],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
92
99
|
if (specifier.type !== "ImportSpecifier") {
|
|
93
100
|
return yield* Option.none();
|
|
94
101
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// src/exceptions.ts
|
|
2
|
-
const exceptions = [{
|
|
3
|
-
files: ["packages/toolchain/src/conformance.ts"],
|
|
4
|
-
rules: [
|
|
5
|
-
"eslint/no-restricted-imports",
|
|
6
|
-
"vitest/no-disabled-tests",
|
|
7
|
-
"vitest/no-conditional-tests"
|
|
8
|
-
],
|
|
9
|
-
issue: "https://github.com/birbprophet/agent-kit/issues/278"
|
|
10
|
-
}];
|
|
11
|
-
export { exceptions as t };
|