@milkenjoyer/toolchain 0.20.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.
Files changed (71) hide show
  1. package/README.md +2 -0
  2. package/TESTING.md +26 -0
  3. package/dist/ci-budget-B2AuZ3xa.mjs +80 -0
  4. package/dist/ci-budget-cli.d.mts +2 -0
  5. package/dist/ci-budget-cli.mjs +31 -0
  6. package/dist/ci-budget.d.mts +22 -0
  7. package/dist/ci-budget.mjs +1 -0
  8. package/dist/ci-result.d.mts +1 -0
  9. package/dist/ci-result.mjs +12 -0
  10. package/dist/{compatible-DIYO9MZf.d.mts → compatible-BKEJ_p20.d.mts} +1 -1
  11. package/dist/{compatible-D54mCSlT.mjs → compatible-CRaMYpBM.mjs} +2 -2
  12. package/dist/compatible.d.mts +1 -1
  13. package/dist/compatible.mjs +1 -1
  14. package/dist/conformance.mjs +1 -1
  15. package/dist/{effect-plugin-BsrW5_nI.mjs → effect-plugin-roghk4W1.mjs} +2 -3
  16. package/dist/effect-plugin.mjs +1 -1
  17. package/dist/exceptions-D0yZUk8P.mjs +145 -0
  18. package/dist/exceptions.mjs +1 -1
  19. package/dist/foldkit-plugin.mjs +2 -2
  20. package/dist/formal.d.mts +1 -1
  21. package/dist/formal.mjs +5 -5
  22. package/dist/{guard-fFg_0NIp.mjs → guard-n0LC_buo.mjs} +6 -6
  23. package/dist/guard.d.mts +1 -1
  24. package/dist/guard.mjs +1 -1
  25. package/dist/hooks.d.mts +1 -1
  26. package/dist/hooks.mjs +2 -2
  27. package/dist/{lint-BJ6SmGk1.mjs → lint-Bx4NP_kA.mjs} +5 -5
  28. package/dist/lint.mjs +1 -1
  29. package/dist/{plugin-CwxhPtui.mjs → plugin-DUUAfi92.mjs} +326 -30
  30. package/dist/plugin.d.mts +5 -0
  31. package/dist/plugin.mjs +1 -1
  32. package/dist/proof.mjs +3 -3
  33. package/dist/renovate-ci-BdVmECgm.mjs +73 -0
  34. package/dist/renovate-ci.d.mts +10 -0
  35. package/dist/renovate-ci.mjs +1 -0
  36. package/dist/{rules-vHmNoAU0.mjs → rules-5qwzfDWJ.mjs} +3 -1
  37. package/dist/rules.d.mts +2 -0
  38. package/dist/rules.mjs +1 -1
  39. package/dist/standard.mjs +6 -6
  40. package/dist/starts.mjs +4 -2
  41. package/dist/verdict.d.mts +1 -1
  42. package/dist/verdict.mjs +2 -2
  43. package/dist/{verification-FgQFU1YN.d.mts → verification-fnhfrxmy.d.mts} +1 -1
  44. package/dist/verification.d.mts +1 -1
  45. package/dist/verification.mjs +1 -1
  46. package/dist/versions.mjs +1 -1
  47. package/package.json +13 -1
  48. package/renovate.json +29 -3
  49. package/src/ci-budget-cli.ts +39 -0
  50. package/src/ci-budget.ts +116 -0
  51. package/src/ci-result.ts +12 -0
  52. package/src/effect-plugin.ts +0 -1
  53. package/src/exceptions.ts +132 -0
  54. package/src/plugin.ts +10 -0
  55. package/src/renovate-ci.ts +96 -0
  56. package/src/rules/no-mock-call-mirrors.ts +121 -0
  57. package/src/rules/no-test-internal-imports.ts +102 -0
  58. package/src/rules/no-test-timeouts.ts +83 -0
  59. package/src/rules/no-test-waits.ts +113 -0
  60. package/src/rules/require-test-quarantine.ts +36 -0
  61. package/src/rules/test-api.ts +57 -0
  62. package/src/rules/test-hygiene.test.ts +241 -0
  63. package/src/rules/test-package.ts +32 -0
  64. package/src/rules.ts +2 -0
  65. package/src/shared/member-path.ts +7 -0
  66. package/src/starts/policy.ts +5 -1
  67. package/dist/exceptions-Dybl9xpc.mjs +0 -11
  68. package/dist/{specs-file-NsQF4V7X.mjs → specs-file-Ck9ZOt46.mjs} +1 -1
  69. package/dist/{syntax-CGEOffZK.mjs → syntax-B3n7lDYJ.mjs} +1 -1
  70. package/dist/{verification-oAc1Q6I9.mjs → verification-D4Sn2fh5.mjs} +4 -4
  71. package/dist/{versions-DpRzgSR_.mjs → versions-KbYa8kbF.mjs} +1 -1
@@ -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
+ });
@@ -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"];