Skip to content

Commit 2e01e6b

Browse files
fix(lint): limit Effect callback exemptions to option objects
1 parent 28377ef commit 2e01e6b

2 files changed

Lines changed: 36 additions & 12 deletions

File tree

‎oxlint-plugin-t3code/rules/prefer-effect-fn.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,29 @@ describe("t3code/prefer-effect-fn", () => {
4949
`,
5050
);
5151

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+
5275
rule.valid(
5376
"does not mistake other namespaces or shadowed locals for Effect",
5477
`

‎oxlint-plugin-t3code/rules/prefer-effect-fn.ts‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { defineRule, type ESTree } from "@oxlint/plugins";
22

3-
const CALLBACK_NAMES = new Set(["onSome", "onNone", "onSuccess", "onFailure", "defaultValue"]);
4-
53
export default defineRule({
64
meta: {
75
type: "suggestion",
@@ -73,17 +71,20 @@ export default defineRule({
7371
: parent.key.type === "Literal"
7472
? parent.key.value
7573
: undefined;
76-
if (typeof name === "string" && CALLBACK_NAMES.has(name)) return;
7774
const call = parent.parent.parent;
78-
if (
79-
call?.type === "CallExpression" &&
80-
call.callee.type === "MemberExpression" &&
81-
call.callee.property.type === "Identifier" &&
82-
["catchTags", "match", "matchEffect", "matchCauseEffect"].includes(
83-
call.callee.property.name,
84-
)
85-
) {
86-
return;
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+
}
8788
}
8889
} else if (parent.type !== "VariableDeclarator" && parent.type !== "PropertyDefinition") {
8990
return;

0 commit comments

Comments
 (0)