The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 00:30 UTC
feat(lint): require Effect functions for reusable generator wrappers (#22000)
Julius Marminge committed
Oct 19, 2026 at 18:31 UTC
cfb602acaa2a413b151213a8ac63cd8d940965ba
5 files changed
+348
-1
oxlint-plugin-t3code/index.ts
+2
@@ -19,6 +19,7 @@ import noTestInLoop from "./rules/no-test-in-loop.ts";
19
import noRpcPermissionBypass from "./rules/no-rpc-permission-bypass.ts";
20
import noUnscopedHas from "./rules/no-unscoped-has.ts";
21
import preferCatchTags from "./rules/prefer-catch-tags.ts";
22
+import preferEffectFn from "./rules/prefer-effect-fn.ts";
23
import requireCenteredScrollGutter from "./rules/require-centered-scroll-gutter.ts";
24
import requireSuppressionReason from "./rules/require-suppression-reason.ts";
25
@@ -46,6 +47,7 @@ export default definePlugin({
47
"no-rpc-permission-bypass": noRpcPermissionBypass,
48
"no-unscoped-has": noUnscopedHas,
49
"prefer-catch-tags": preferCatchTags,
50
+ "prefer-effect-fn": preferEffectFn,
51
"require-centered-scroll-gutter": requireCenteredScrollGutter,
52
"require-suppression-reason": requireSuppressionReason,
53
},
oxlint-plugin-t3code/rules/prefer-effect-fn.test.ts
new
+202
@@ -0,0 +1,202 @@
1
+import { assert, describe } from "@effect/vitest";
2
+
3
+import { createOxlintRuleHarness } from "../test/utils.ts";
4
+
5
+const rule = createOxlintRuleHarness("t3code/prefer-effect-fn");
6
+
7
+describe("t3code/prefer-effect-fn", () => {
8
+ rule.valid(
9
+ "allows inline programs and layer construction",
10
+ `
11
+ import * as Effect from "effect/Effect";
12
+ import * as Layer from "effect/Layer";
13
+ export const program = Effect.gen(function* () { yield* Effect.void; });
14
+ export const layer = Layer.effectDiscard(Effect.gen(function* () { yield* Effect.void; }));
15
+ `,
16
+ );
17
+
18
+ rule.valid(
19
+ "allows named functions and deliberate untraced functions",
20
+ `
21
+ import * as Effect from "effect/Effect";
22
+ export const read = Effect.fn("Files.read")(function* () { yield* Effect.void; });
23
+ export const chunk = Effect.fnUntraced(function* () { yield* Effect.void; });
24
+ `,
25
+ );
26
+
27
+ rule.valid(
28
+ "allows inline combinator callbacks",
29
+ `
30
+ import * as Effect from "effect/Effect";
31
+ export const program = Effect.void.pipe(Effect.flatMap(() => Effect.gen(function* () {
32
+ yield* Effect.void;
33
+ })));
34
+ `,
35
+ );
36
+
37
+ rule.valid(
38
+ "allows inline option and error callbacks",
39
+ `
40
+ import * as Effect from "effect/Effect";
41
+ import * as Option from "effect/Option";
42
+ export const program = Option.match(Option.none(), {
43
+ onNone: () => Effect.gen(function* () { yield* Effect.void; }),
44
+ onSome: () => Effect.void,
45
+ });
46
+ export const recovered = Effect.fail({ _tag: "Failed" }).pipe(Effect.catchTags({
47
+ Failed: () => Effect.gen(function* () { yield* Effect.void; }),
48
+ }));
49
+ `,
50
+ );
51
+
52
+ rule.valid(
53
+ "allows reference default-value callbacks",
54
+ `
55
+ import * as Context from "effect/Context";
56
+ import * as Effect from "effect/Effect";
57
+ export const Default = Context.Reference("Default", {
58
+ defaultValue: () => Effect.gen(function* () { yield* Effect.void; }),
59
+ });
60
+ `,
61
+ );
62
+
63
+ for (const name of ["onSome", "onNone", "onSuccess", "onFailure", "defaultValue"]) {
64
+ rule.invalid(
65
+ `reports service members named ${name}`,
66
+ `
67
+ import * as Effect from "effect/Effect";
68
+ export const service = Service.of({
69
+ ${name}: () => Effect.gen(function* () { yield* Effect.void; }),
70
+ });
71
+ `,
72
+ );
73
+ }
74
+
75
+ rule.valid(
76
+ "does not mistake other namespaces or shadowed locals for Effect",
77
+ `
78
+ import * as Effect from "effect/Effect";
79
+ const Other = { gen: (body: () => unknown) => body() };
80
+ export const other = () => Other.gen(function* () {});
81
+ export function scoped(Effect: typeof Other) {
82
+ return Effect.gen(function* () {});
83
+ }
84
+ export const effect = Effect.void;
85
+ `,
86
+ );
87
+
88
+ rule.valid(
89
+ "leaves functions with synchronous setup for manual review",
90
+ `
91
+ import * as Effect from "effect/Effect";
92
+ export const read = () => {
93
+ const state = new Map();
94
+ return Effect.gen(function* () { yield* Effect.void; return state; });
95
+ };
96
+ `,
97
+ );
98
+
99
+ rule.invalid(
100
+ "reports a named arrow wrapper",
101
+ `
102
+ import * as Effect from "effect/Effect";
103
+ export const read = (path: string) => Effect.gen(function* () {
104
+ yield* Effect.void;
105
+ return path;
106
+ });
107
+ `,
108
+ (output) => {
109
+ assert.match(output, /Effect\.fn/);
110
+ assert.match(output, /documented hot paths/);
111
+ },
112
+ );
113
+
114
+ rule.invalid(
115
+ "reports a block-bodied wrapper",
116
+ `
117
+ import * as Effect from "effect/Effect";
118
+ export const read = () => { return Effect.gen(function* () { yield* Effect.void; }); };
119
+ `,
120
+ );
121
+
122
+ rule.invalid(
123
+ "reports a declaration with pipe transforms",
124
+ `
125
+ import * as Effect from "effect/Effect";
126
+ export function read() {
127
+ return Effect.gen(function* () { yield* Effect.void; }).pipe(Effect.asVoid);
128
+ }
129
+ `,
130
+ );
131
+
132
+ rule.invalid(
133
+ "reports a function expression",
134
+ `
135
+ import * as Effect from "effect/Effect";
136
+ export const read = function() { return Effect.gen(function* () { yield* Effect.void; }); };
137
+ `,
138
+ );
139
+
140
+ rule.invalid(
141
+ "reports service members",
142
+ `
143
+ import * as Effect from "effect/Effect";
144
+ export const service = {
145
+ read: () => Effect.gen(function* () { yield* Effect.void; }),
146
+ };
147
+ `,
148
+ );
149
+
150
+ rule.invalid(
151
+ "reports class fields",
152
+ `
153
+ import * as Effect from "effect/Effect";
154
+ export class Service {
155
+ read = () => Effect.gen(function* () { yield* Effect.void; });
156
+ }
157
+ `,
158
+ );
159
+
160
+ rule.invalid(
161
+ "recognizes namespace aliases",
162
+ `
163
+ import * as Eff from "effect/Effect";
164
+ export const read = () => Eff.gen(function* () { yield* Eff.void; });
165
+ `,
166
+ );
167
+
168
+ rule.invalid(
169
+ "recognizes bare-package Effect imports",
170
+ `
171
+ import { Effect } from "effect";
172
+ export const read = () => Effect.gen(function* () { yield* Effect.void; });
173
+ `,
174
+ );
175
+
176
+ rule.invalid(
177
+ "recognizes a direct gen import",
178
+ `
179
+ import { gen, void as noop } from "effect/Effect";
180
+ export const read = () => gen(function* () { yield* noop; });
181
+ `,
182
+ );
183
+ rule.invalid(
184
+ "reports class methods",
185
+ `
186
+ import * as Effect from "effect/Effect";
187
+ export class Service {
188
+ read() { return Effect.gen(function* () { yield* Effect.void; }); }
189
+ }
190
+ `,
191
+ );
192
+
193
+ rule.valid(
194
+ "allows getters that expose an effect value",
195
+ `
196
+ import * as Effect from "effect/Effect";
197
+ export class Service {
198
+ get read() { return Effect.gen(function* () { yield* Effect.void; }); }
199
+ }
200
+ `,
201
+ );
202
+});
oxlint-plugin-t3code/rules/prefer-effect-fn.ts
new
+116
@@ -0,0 +1,116 @@
1
+import { defineRule, type ESTree } from "@oxlint/plugins";
2
+
3
+export default defineRule({
4
+ meta: {
5
+ type: "suggestion",
6
+ docs: {
7
+ description: "Use Effect.fn for reusable generator-based Effect functions.",
8
+ },
9
+ },
10
+ create(context) {
11
+ const isEffectImport = (identifier: ESTree.IdentifierReference, member: string) => {
12
+ let scope = context.sourceCode.getScope(identifier);
13
+ while (true) {
14
+ const variable = scope.set.get(identifier.name);
15
+ if (variable !== undefined) {
16
+ return variable.defs.some((def) => {
17
+ if (def.type !== "ImportBinding" || def.parent?.type !== "ImportDeclaration") {
18
+ return false;
19
+ }
20
+ const source = def.parent.source.value;
21
+ if (source === "effect/Effect") {
22
+ if (member === "") {
23
+ return (
24
+ def.node.type === "ImportSpecifier" &&
25
+ (def.node.imported.type === "Identifier"
26
+ ? def.node.imported.name
27
+ : def.node.imported.value) === "gen"
28
+ );
29
+ }
30
+ return def.node.type === "ImportNamespaceSpecifier";
31
+ }
32
+ return (
33
+ source === "effect" &&
34
+ def.node.type === "ImportSpecifier" &&
35
+ (def.node.imported.type === "Identifier"
36
+ ? def.node.imported.name
37
+ : def.node.imported.value) === "Effect"
38
+ );
39
+ });
40
+ }
41
+ if (scope.upper === null) return false;
42
+ scope = scope.upper;
43
+ }
44
+ };
45
+
46
+ const isGeneratorCall = (expression: ESTree.Expression): boolean => {
47
+ if (expression.type !== "CallExpression") return false;
48
+ const callee = expression.callee;
49
+ if (callee.type === "Identifier") return isEffectImport(callee, "");
50
+ if (callee.type !== "MemberExpression" || callee.computed) return false;
51
+ if (callee.property.type !== "Identifier") return false;
52
+ if (callee.property.name === "pipe") return isGeneratorCall(callee.object);
53
+ return (
54
+ callee.property.name === "gen" &&
55
+ callee.object.type === "Identifier" &&
56
+ isEffectImport(callee.object, "gen")
57
+ );
58
+ };
59
+
60
+ const check = (node: ESTree.ArrowFunctionExpression | ESTree.Function) => {
61
+ if (node.async || node.generator) return;
62
+ const parent = node.parent;
63
+ if (node.type !== "FunctionDeclaration") {
64
+ if (parent.type === "MethodDefinition") {
65
+ if (parent.kind !== "method") return;
66
+ } else if (parent.type === "Property") {
67
+ if (parent.kind !== "init") return;
68
+ const name =
69
+ parent.key.type === "Identifier"
70
+ ? parent.key.name
71
+ : parent.key.type === "Literal"
72
+ ? parent.key.value
73
+ : undefined;
74
+ const call = parent.parent.parent;
75
+ if (call?.type === "CallExpression") {
76
+ let callee = call.callee;
77
+ while (callee.type === "CallExpression") callee = callee.callee;
78
+ if (callee.type === "MemberExpression" && callee.property.type === "Identifier") {
79
+ if (
80
+ ["catchTags", "match", "matchEffect", "matchCauseEffect"].includes(
81
+ callee.property.name,
82
+ ) ||
83
+ (name === "defaultValue" && callee.property.name === "Reference")
84
+ ) {
85
+ return;
86
+ }
87
+ }
88
+ }
89
+ } else if (parent.type !== "VariableDeclarator" && parent.type !== "PropertyDefinition") {
90
+ return;
91
+ }
92
+ }
93
+ const body = node.body;
94
+ if (body === null) return;
95
+ let expression: ESTree.Expression | null;
96
+ if (body.type === "BlockStatement") {
97
+ if (body.body.length !== 1 || body.body[0]?.type !== "ReturnStatement") return;
98
+ expression = body.body[0].argument;
99
+ } else {
100
+ expression = body;
101
+ }
102
+ if (expression === null || !isGeneratorCall(expression)) return;
103
+ context.report({
104
+ node,
105
+ message:
106
+ 'Use Effect.fn("Service.operation") for reusable Effect functions. Reserve Effect.fnUntraced for documented hot paths or an existing span; keep Effect.gen for inline programs.',
107
+ });
108
+ };
109
+
110
+ return {
111
+ ArrowFunctionExpression: check,
112
+ FunctionExpression: check,
113
+ FunctionDeclaration: check,
114
+ };
115
+ },
116
+});
tsconfig.base.json
+19
-1
@@ -22,7 +22,9 @@
22
{
23
"name": "@effect/language-service",
24
"namespaceImportPackages": ["@effect/platform-node", "effect"],
25
+ "effectFn": ["span", "inferred-span", "suggested-span"],
26
"diagnosticSeverity": {
27
+ "effectFnOpportunity": "suggestion",
28
"anyUnknownInErrorContext": "error",
29
"unsafeEffectTypeAssertion": "error",
30
"instanceOfSchema": "error",
@@ -59,7 +61,23 @@
61
"overrides": [
62
{
63
"include": ["**/*.test.ts", "**/*.test.tsx"],
62
- "options": { "diagnosticSeverity": { "preferSchemaOverJson": "off" } }
64
+ "options": {
65
+ "diagnosticSeverity": {
66
+ "preferSchemaOverJson": "off",
67
+ "effectFnOpportunity": "off"
68
+ }
69
+ }
70
+ },
71
+ {
72
+ "include": [
73
+ "**/*.spec.ts",
74
+ "**/*.spec.tsx",
75
+ "**/*.testkit.ts",
76
+ "**/*.testkit.tsx",
77
+ "**/{test,tests,testkit,testing,fixtures,integration}/**",
78
+ "packages/provider-testing/**"
79
+ ],
80
+ "options": { "diagnosticSeverity": { "effectFnOpportunity": "off" } }
81
}
82
]
83
}
vite.config.ts
+9
@@ -172,10 +172,19 @@ export default defineConfig({
172
"t3code/no-unscoped-has": "error",
173
"t3code/namespace-node-imports": "error",
174
"t3code/prefer-catch-tags": "error",
175
+ "t3code/prefer-effect-fn": "error",
176
"t3code/require-centered-scroll-gutter": "error",
177
"t3code/require-suppression-reason": "error",
178
},
179
overrides: [
180
+ {
181
+ files: [
182
+ "**/*.{test,spec,testkit}.{ts,tsx}",
183
+ "**/{test,tests,testkit,testing,fixtures,integration}/**",
184
+ "packages/provider-testing/**",
185
+ ],
186
+ rules: { "t3code/prefer-effect-fn": "off" },
187
+ },
188
{
189
files: ["apps/**/src/**", "packages/**/src/**"],
190
excludeFiles: DOM_TEST_ENVIRONMENT_ALLOWLIST,