@opsydyn/oxlint-effect 0.1.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 +87 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.mjs +1106 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +78 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1106 @@
|
|
|
1
|
+
import { definePlugin, defineRule } from "@oxlint/plugins";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
function isIdentifier(node, name) {
|
|
4
|
+
return typeof node === "object" && node !== null && node.type === "Identifier" && typeof node.name === "string" && (name === void 0 || node.name === name);
|
|
5
|
+
}
|
|
6
|
+
function isMemberExpression(node, objectName, propertyName) {
|
|
7
|
+
if (typeof node !== "object" || node === null) return false;
|
|
8
|
+
const member = node;
|
|
9
|
+
return member.type === "MemberExpression" && member.computed !== true && isIdentifier(member.object, objectName) && isIdentifier(member.property, propertyName);
|
|
10
|
+
}
|
|
11
|
+
function isEffectMemberCall(node) {
|
|
12
|
+
if (typeof node !== "object" || node === null) return false;
|
|
13
|
+
const call = node;
|
|
14
|
+
return call.type === "CallExpression" && Array.isArray(call.arguments) && typeof call.callee === "object" && call.callee !== null && call.callee.type === "MemberExpression" && call.callee.computed !== true && isIdentifier(call.callee.object, "Effect") && isIdentifier(call.callee.property);
|
|
15
|
+
}
|
|
16
|
+
function firstArgument(node) {
|
|
17
|
+
return node.arguments[0];
|
|
18
|
+
}
|
|
19
|
+
function isEffectMemberCallNamed(node, propertyName) {
|
|
20
|
+
if (!isEffectMemberCall(node)) return false;
|
|
21
|
+
const callee = node.callee;
|
|
22
|
+
return isIdentifier(callee.property, propertyName);
|
|
23
|
+
}
|
|
24
|
+
function hasDeepNestedEffectFirstArgument(node) {
|
|
25
|
+
if (!isEffectMemberCall(node)) return false;
|
|
26
|
+
const inner = firstArgument(node);
|
|
27
|
+
if (!isEffectMemberCall(inner)) return false;
|
|
28
|
+
return isEffectMemberCall(firstArgument(inner));
|
|
29
|
+
}
|
|
30
|
+
function hasNestedEffectCallArgument(node) {
|
|
31
|
+
if (!isEffectMemberCall(node)) return false;
|
|
32
|
+
return node.arguments.slice(0, 2).some((argument) => isEffectMemberCall(argument));
|
|
33
|
+
}
|
|
34
|
+
function containsEffectMemberCallNamed(node, propertyName) {
|
|
35
|
+
if (isEffectMemberCallNamed(node, propertyName)) return true;
|
|
36
|
+
if (Array.isArray(node)) return node.some((child) => containsEffectMemberCallNamed(child, propertyName));
|
|
37
|
+
if (typeof node !== "object" || node === null) return false;
|
|
38
|
+
return Object.values(node).some((child) => containsEffectMemberCallNamed(child, propertyName));
|
|
39
|
+
}
|
|
40
|
+
function getFlatMapLadderMessage(node) {
|
|
41
|
+
if (isEffectMemberCallNamed(node, "flatMap") && containsEffectMemberCallNamed(node.arguments, "flatMap")) return "Rule: avoid nested Effect.flatMap. Why: it hides sequencing and pushes laddered control flow. Fix: build context once (Effect.all/Effect.map) and run a single flatMap.";
|
|
42
|
+
if (isEffectMemberCallNamed(node, "flatten") && containsEffectMemberCallNamed(firstArgument(node), "map")) return "Rule: avoid map+flatten ladders. Why: they hide sequencing. Fix: build context once (Effect.all/Effect.map) and run a single flatMap.";
|
|
43
|
+
}
|
|
44
|
+
const orElseSequencingCalls = [
|
|
45
|
+
"flatMap",
|
|
46
|
+
"zipRight",
|
|
47
|
+
"as",
|
|
48
|
+
"tap"
|
|
49
|
+
];
|
|
50
|
+
function hasOrElseSequencingFirstArgument(node) {
|
|
51
|
+
if (!isEffectMemberCallNamed(node, "orElse")) return false;
|
|
52
|
+
const first = firstArgument(node);
|
|
53
|
+
return orElseSequencingCalls.some((propertyName) => containsEffectMemberCallNamed(first, propertyName));
|
|
54
|
+
}
|
|
55
|
+
function isPipeCall(node) {
|
|
56
|
+
if (typeof node !== "object" || node === null) return false;
|
|
57
|
+
const call = node;
|
|
58
|
+
if (call.type !== "CallExpression") return false;
|
|
59
|
+
if (isIdentifier(call.callee, "pipe")) return true;
|
|
60
|
+
const callee = call.callee;
|
|
61
|
+
return typeof callee === "object" && callee !== null && callee.type === "MemberExpression" && callee.computed !== true && isIdentifier(callee.property, "pipe");
|
|
62
|
+
}
|
|
63
|
+
function containsPipeCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
64
|
+
if (isPipeCall(node)) return true;
|
|
65
|
+
if (Array.isArray(node)) return node.some((child) => containsPipeCall(child, seen));
|
|
66
|
+
if (typeof node !== "object" || node === null) return false;
|
|
67
|
+
if (seen.has(node)) return false;
|
|
68
|
+
seen.add(node);
|
|
69
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && containsPipeCall(child, seen));
|
|
70
|
+
}
|
|
71
|
+
function isArrowIifeCall(node) {
|
|
72
|
+
if (typeof node !== "object" || node === null) return false;
|
|
73
|
+
const call = node;
|
|
74
|
+
return call.type === "CallExpression" && Array.isArray(call.arguments) && typeof call.callee === "object" && call.callee !== null && call.callee.type === "ArrowFunctionExpression";
|
|
75
|
+
}
|
|
76
|
+
function isInlineFunctionIifeCall(node) {
|
|
77
|
+
if (typeof node !== "object" || node === null) return false;
|
|
78
|
+
const call = node;
|
|
79
|
+
return call.type === "CallExpression" && Array.isArray(call.arguments) && typeof call.callee === "object" && call.callee !== null && (call.callee.type === "ArrowFunctionExpression" || call.callee.type === "FunctionExpression");
|
|
80
|
+
}
|
|
81
|
+
function findArrowIifeCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
82
|
+
if (isArrowIifeCall(node)) return node;
|
|
83
|
+
if (Array.isArray(node)) {
|
|
84
|
+
for (const child of node) {
|
|
85
|
+
const match = findArrowIifeCall(child, seen);
|
|
86
|
+
if (match) return match;
|
|
87
|
+
}
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (typeof node !== "object" || node === null) return;
|
|
91
|
+
if (seen.has(node)) return;
|
|
92
|
+
seen.add(node);
|
|
93
|
+
for (const [key, child] of Object.entries(node)) {
|
|
94
|
+
if (key === "parent") continue;
|
|
95
|
+
const match = findArrowIifeCall(child, seen);
|
|
96
|
+
if (match) return match;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function findReturnStatements(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
100
|
+
if (Array.isArray(node)) return node.flatMap((child) => findReturnStatements(child, seen));
|
|
101
|
+
if (typeof node !== "object" || node === null) return [];
|
|
102
|
+
if (seen.has(node)) return [];
|
|
103
|
+
seen.add(node);
|
|
104
|
+
if (node.type === "ReturnStatement") return [node];
|
|
105
|
+
return Object.entries(node).flatMap(([key, child]) => key === "parent" ? [] : findReturnStatements(child, seen));
|
|
106
|
+
}
|
|
107
|
+
function isSchemaFilterCall(node) {
|
|
108
|
+
if (typeof node !== "object" || node === null) return false;
|
|
109
|
+
const call = node;
|
|
110
|
+
return call.type === "CallExpression" && (isMemberExpression(call.callee, "S", "filter") || isMemberExpression(call.callee, "Schema", "filter"));
|
|
111
|
+
}
|
|
112
|
+
function directArrowCallbackReturns(node) {
|
|
113
|
+
if (typeof node !== "object" || node === null) return [];
|
|
114
|
+
const call = node;
|
|
115
|
+
if (call.type !== "CallExpression" || !Array.isArray(call.arguments) || isSchemaFilterCall(call)) return [];
|
|
116
|
+
return call.arguments.flatMap((argument) => {
|
|
117
|
+
if (typeof argument !== "object" || argument === null || argument.type !== "ArrowFunctionExpression") return [];
|
|
118
|
+
const body = argument.body;
|
|
119
|
+
if (typeof body !== "object" || body === null || body.type !== "BlockStatement") return [];
|
|
120
|
+
return findReturnStatements(body);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function directFunctionCallbackReturns(node) {
|
|
124
|
+
if (typeof node !== "object" || node === null) return [];
|
|
125
|
+
const call = node;
|
|
126
|
+
if (call.type !== "CallExpression" || !Array.isArray(call.arguments)) return [];
|
|
127
|
+
return call.arguments.flatMap((argument) => {
|
|
128
|
+
if (typeof argument !== "object" || argument === null || argument.type !== "FunctionExpression" || argument.generator === true) return [];
|
|
129
|
+
return findReturnStatements(argument.body);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function isGeneratorFunctionExpression(node) {
|
|
133
|
+
return typeof node === "object" && node !== null && node.type === "FunctionExpression" && node.generator === true;
|
|
134
|
+
}
|
|
135
|
+
function getEffectGeneratorArgument(node, propertyName) {
|
|
136
|
+
if (!isEffectMemberCallNamed(node, propertyName)) return;
|
|
137
|
+
const fn = firstArgument(node);
|
|
138
|
+
return isGeneratorFunctionExpression(fn) ? fn : void 0;
|
|
139
|
+
}
|
|
140
|
+
function isEffectGeneratorCall(node, propertyName) {
|
|
141
|
+
return getEffectGeneratorArgument(node, propertyName) !== void 0;
|
|
142
|
+
}
|
|
143
|
+
function isConsoleCall(node) {
|
|
144
|
+
if (typeof node !== "object" || node === null) return false;
|
|
145
|
+
const call = node;
|
|
146
|
+
return call.type === "CallExpression" && typeof call.callee === "object" && call.callee !== null && call.callee.type === "MemberExpression" && call.callee.computed !== true && isIdentifier(call.callee.object, "console") && isIdentifier(call.callee.property);
|
|
147
|
+
}
|
|
148
|
+
function isIdentifierCall(node, name) {
|
|
149
|
+
if (typeof node !== "object" || node === null) return false;
|
|
150
|
+
const call = node;
|
|
151
|
+
return call.type === "CallExpression" && isIdentifier(call.callee, name);
|
|
152
|
+
}
|
|
153
|
+
function isMemberCall(node, objectName, propertyName) {
|
|
154
|
+
if (typeof node !== "object" || node === null) return false;
|
|
155
|
+
const call = node;
|
|
156
|
+
return call.type === "CallExpression" && typeof call.callee === "object" && call.callee !== null && call.callee.type === "MemberExpression" && call.callee.computed !== true && isIdentifier(call.callee.object, objectName) && isIdentifier(call.callee.property) && (propertyName === void 0 || isIdentifier(call.callee.property, propertyName));
|
|
157
|
+
}
|
|
158
|
+
function isEffectLogCall(node) {
|
|
159
|
+
if (typeof node !== "object" || node === null) return false;
|
|
160
|
+
const call = node;
|
|
161
|
+
if (call.type !== "CallExpression" || typeof call.callee !== "object" || call.callee === null || call.callee.type !== "MemberExpression" || call.callee.computed === true || !isIdentifier(call.callee.object, "Effect") || !isIdentifier(call.callee.property)) return false;
|
|
162
|
+
return call.callee.property.name.startsWith("log");
|
|
163
|
+
}
|
|
164
|
+
function containsConsoleCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
165
|
+
if (isConsoleCall(node)) return true;
|
|
166
|
+
if (Array.isArray(node)) return node.some((child) => containsConsoleCall(child, seen));
|
|
167
|
+
if (typeof node !== "object" || node === null) return false;
|
|
168
|
+
if (seen.has(node)) return false;
|
|
169
|
+
seen.add(node);
|
|
170
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && containsConsoleCall(child, seen));
|
|
171
|
+
}
|
|
172
|
+
function containsWrapperSideEffect(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
173
|
+
if (isIdentifierCall(node, "setState") || isMemberCall(node, "Atom", "set") || isIdentifierCall(node, "invalidate") || isEffectLogCall(node) || isConsoleCall(node)) return true;
|
|
174
|
+
if (Array.isArray(node)) return node.some((child) => containsWrapperSideEffect(child, seen));
|
|
175
|
+
if (typeof node !== "object" || node === null) return false;
|
|
176
|
+
if (seen.has(node)) return false;
|
|
177
|
+
seen.add(node);
|
|
178
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && containsWrapperSideEffect(child, seen));
|
|
179
|
+
}
|
|
180
|
+
function containsAllStepSideEffect(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
181
|
+
if (isMemberCall(node, "Ref", "set") || isMemberCall(node, "Atom", "set") || isMemberCall(node, "SubscriptionRef", "set") || isMemberCall(node, "Reactivity", "invalidate") || isMemberCall(node, "Fiber", "interrupt") || isEffectLogCall(node)) return true;
|
|
182
|
+
if (Array.isArray(node)) return node.some((child) => containsAllStepSideEffect(child, seen));
|
|
183
|
+
if (typeof node !== "object" || node === null) return false;
|
|
184
|
+
if (seen.has(node)) return false;
|
|
185
|
+
seen.add(node);
|
|
186
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && containsAllStepSideEffect(child, seen));
|
|
187
|
+
}
|
|
188
|
+
function hasConcurrencyOne(node) {
|
|
189
|
+
if (typeof node !== "object" || node === null) return false;
|
|
190
|
+
const object = node;
|
|
191
|
+
if (object.type !== "ObjectExpression" || !Array.isArray(object.properties)) return false;
|
|
192
|
+
return object.properties.some((entry) => {
|
|
193
|
+
if (typeof entry !== "object" || entry === null) return false;
|
|
194
|
+
const prop = entry;
|
|
195
|
+
const key = prop.key;
|
|
196
|
+
const value = prop.value;
|
|
197
|
+
return (isIdentifier(key, "concurrency") || typeof key === "object" && key !== null && key.value === "concurrency") && typeof value === "object" && value !== null && (value.type === "Literal" || value.type === "NumericLiteral") && value.value === 1;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function isEffectAsVoidPipeArgument(node) {
|
|
201
|
+
return isMemberExpression(node, "Effect", "asVoid") || isMemberCall(node, "Effect", "asVoid");
|
|
202
|
+
}
|
|
203
|
+
function isEffectAllAsVoidPipe(node) {
|
|
204
|
+
if (typeof node !== "object" || node === null) return false;
|
|
205
|
+
const call = node;
|
|
206
|
+
if (call.type !== "CallExpression" || !Array.isArray(call.arguments) || typeof call.callee !== "object" || call.callee === null || call.callee.type !== "MemberExpression" || call.callee.computed === true || !isIdentifier(call.callee.property, "pipe")) return false;
|
|
207
|
+
return isEffectMemberCallNamed(call.callee.object, "all") && call.arguments.some((argument) => isEffectAsVoidPipeArgument(argument));
|
|
208
|
+
}
|
|
209
|
+
function pipeParts(node) {
|
|
210
|
+
if (typeof node !== "object" || node === null || !isPipeCall(node)) return [];
|
|
211
|
+
const call = node;
|
|
212
|
+
if (isIdentifier(call.callee, "pipe")) return call.arguments;
|
|
213
|
+
return [call.callee.object, ...call.arguments];
|
|
214
|
+
}
|
|
215
|
+
function isPipeStartingWithEffect(node) {
|
|
216
|
+
const [first] = pipeParts(node);
|
|
217
|
+
return first !== void 0 && containsAnyEffectMemberCall(first);
|
|
218
|
+
}
|
|
219
|
+
function isEffectWrapperAliasExpression(node) {
|
|
220
|
+
if (isPipeStartingWithEffect(node)) return true;
|
|
221
|
+
if (typeof node === "object" && node !== null && node.type === "ArrowFunctionExpression") {
|
|
222
|
+
const body = node.body;
|
|
223
|
+
return isEffectMemberCall(body) || isPipeStartingWithEffect(body);
|
|
224
|
+
}
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
function hasEffectWrapperAliasReturn(node) {
|
|
228
|
+
return findReturnStatements(node).some((returnNode) => typeof returnNode === "object" && returnNode !== null && (isEffectWrapperAliasExpression(returnNode.argument) || isEffectMemberCall(returnNode.argument)));
|
|
229
|
+
}
|
|
230
|
+
function isQualifiedTypeReference(node, leftName, rightName) {
|
|
231
|
+
if (typeof node !== "object" || node === null || node.type !== "TSTypeReference") return false;
|
|
232
|
+
const typeName = node.typeName;
|
|
233
|
+
return typeof typeName === "object" && typeName !== null && typeName.type === "TSQualifiedName" && isIdentifier(typeName.left, leftName) && isIdentifier(typeName.right, rightName);
|
|
234
|
+
}
|
|
235
|
+
function containsQualifiedTypeReference(node, leftName, rightName, seen = /* @__PURE__ */ new WeakSet()) {
|
|
236
|
+
if (isQualifiedTypeReference(node, leftName, rightName)) return true;
|
|
237
|
+
if (Array.isArray(node)) return node.some((child) => containsQualifiedTypeReference(child, leftName, rightName, seen));
|
|
238
|
+
if (typeof node !== "object" || node === null) return false;
|
|
239
|
+
if (seen.has(node)) return false;
|
|
240
|
+
seen.add(node);
|
|
241
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && containsQualifiedTypeReference(child, leftName, rightName, seen));
|
|
242
|
+
}
|
|
243
|
+
function containsWrapGraphqlCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
244
|
+
if (isIdentifierCall(node, "wrapGraphqlCall")) return true;
|
|
245
|
+
if (Array.isArray(node)) return node.some((child) => containsWrapGraphqlCall(child, seen));
|
|
246
|
+
if (typeof node !== "object" || node === null) return false;
|
|
247
|
+
if (seen.has(node)) return false;
|
|
248
|
+
seen.add(node);
|
|
249
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && containsWrapGraphqlCall(child, seen));
|
|
250
|
+
}
|
|
251
|
+
function isApplyResponseFlatMap(node) {
|
|
252
|
+
return isEffectMemberCallNamed(node, "flatMap") && isIdentifier(firstArgument(node), "applyResponse");
|
|
253
|
+
}
|
|
254
|
+
function containsApplyResponseFlatMap(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
255
|
+
if (isApplyResponseFlatMap(node)) return true;
|
|
256
|
+
if (Array.isArray(node)) return node.some((child) => containsApplyResponseFlatMap(child, seen));
|
|
257
|
+
if (typeof node !== "object" || node === null) return false;
|
|
258
|
+
if (seen.has(node)) return false;
|
|
259
|
+
seen.add(node);
|
|
260
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && containsApplyResponseFlatMap(child, seen));
|
|
261
|
+
}
|
|
262
|
+
function findEffectCatchAll(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
263
|
+
if (isEffectMemberCallNamed(node, "catchAll")) return node;
|
|
264
|
+
if (Array.isArray(node)) {
|
|
265
|
+
for (const child of node) {
|
|
266
|
+
const match = findEffectCatchAll(child, seen);
|
|
267
|
+
if (match) return match;
|
|
268
|
+
}
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (typeof node !== "object" || node === null) return;
|
|
272
|
+
if (seen.has(node)) return;
|
|
273
|
+
seen.add(node);
|
|
274
|
+
for (const [key, child] of Object.entries(node)) {
|
|
275
|
+
if (key === "parent") continue;
|
|
276
|
+
const match = findEffectCatchAll(child, seen);
|
|
277
|
+
if (match) return match;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function getWrapGraphqlCatchAll(node) {
|
|
281
|
+
const parts = pipeParts(node);
|
|
282
|
+
if (parts.length === 0) return;
|
|
283
|
+
const catchAll = findEffectCatchAll(parts);
|
|
284
|
+
if (!catchAll) return;
|
|
285
|
+
return containsWrapGraphqlCall(parts) || containsApplyResponseFlatMap(parts) ? catchAll : void 0;
|
|
286
|
+
}
|
|
287
|
+
const atomOperationMethods = /* @__PURE__ */ new Set([
|
|
288
|
+
"get",
|
|
289
|
+
"set",
|
|
290
|
+
"update",
|
|
291
|
+
"modify",
|
|
292
|
+
"refresh"
|
|
293
|
+
]);
|
|
294
|
+
function callbackBody(node) {
|
|
295
|
+
if (typeof node !== "object" || node === null) return;
|
|
296
|
+
const callback = node;
|
|
297
|
+
if (callback.type !== "ArrowFunctionExpression" && callback.type !== "FunctionExpression") return;
|
|
298
|
+
return callback.body;
|
|
299
|
+
}
|
|
300
|
+
function isAtomOperationCall(node) {
|
|
301
|
+
if (typeof node !== "object" || node === null) return false;
|
|
302
|
+
const call = node;
|
|
303
|
+
if (call.type !== "CallExpression" || !Array.isArray(call.arguments) || typeof call.callee !== "object" || call.callee === null || call.callee.type !== "MemberExpression" || call.callee.computed === true) return false;
|
|
304
|
+
const callee = call.callee;
|
|
305
|
+
return (isIdentifier(callee.object, "Atom") || isIdentifier(callee.object, "atomRegistry")) && isIdentifier(callee.property) && atomOperationMethods.has(callee.property.name);
|
|
306
|
+
}
|
|
307
|
+
function findAtomOperationCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
308
|
+
if (isAtomOperationCall(node)) return node;
|
|
309
|
+
if (Array.isArray(node)) {
|
|
310
|
+
for (const child of node) {
|
|
311
|
+
const match = findAtomOperationCall(child, seen);
|
|
312
|
+
if (match) return match;
|
|
313
|
+
}
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (typeof node !== "object" || node === null) return;
|
|
317
|
+
if (seen.has(node)) return;
|
|
318
|
+
seen.add(node);
|
|
319
|
+
for (const [key, child] of Object.entries(node)) {
|
|
320
|
+
if (key === "parent") continue;
|
|
321
|
+
const match = findAtomOperationCall(child, seen);
|
|
322
|
+
if (match) return match;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function findAtomOperationInsideEffectSync(node) {
|
|
326
|
+
if (!isEffectMemberCallNamed(node, "sync")) return;
|
|
327
|
+
const body = callbackBody(firstArgument(node));
|
|
328
|
+
return body ? findAtomOperationCall(body) : void 0;
|
|
329
|
+
}
|
|
330
|
+
function isCollectionAtomIdentifier(node) {
|
|
331
|
+
if (!isIdentifier(node)) return false;
|
|
332
|
+
return /(CollectionAtom|ListAtom|Visible.*Atom|ResultsAtom|ReadStateAtom)$/.test(node.name);
|
|
333
|
+
}
|
|
334
|
+
function getCollectionAtomReadTarget(node) {
|
|
335
|
+
if (typeof node !== "object" || node === null) return;
|
|
336
|
+
const call = node;
|
|
337
|
+
if (call.type !== "CallExpression" || !Array.isArray(call.arguments)) return;
|
|
338
|
+
if (!(isIdentifier(call.callee, "get") || isMemberExpression(call.callee, "Atom", "get") || isMemberExpression(call.callee, "get", "get"))) return;
|
|
339
|
+
const [atom] = call.arguments;
|
|
340
|
+
return isCollectionAtomIdentifier(atom) ? atom : void 0;
|
|
341
|
+
}
|
|
342
|
+
function findFamilyCollectionRead(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
343
|
+
const target = getCollectionAtomReadTarget(node);
|
|
344
|
+
if (target) return target;
|
|
345
|
+
if (Array.isArray(node)) {
|
|
346
|
+
for (const child of node) {
|
|
347
|
+
const match = findFamilyCollectionRead(child, seen);
|
|
348
|
+
if (match) return match;
|
|
349
|
+
}
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (typeof node !== "object" || node === null) return;
|
|
353
|
+
if (seen.has(node)) return;
|
|
354
|
+
seen.add(node);
|
|
355
|
+
for (const [key, child] of Object.entries(node)) {
|
|
356
|
+
if (key === "parent") continue;
|
|
357
|
+
const match = findFamilyCollectionRead(child, seen);
|
|
358
|
+
if (match) return match;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function isEffectProvideWithSingleArgument(node) {
|
|
362
|
+
return isEffectMemberCallNamed(node, "provide") && node.arguments.length === 1;
|
|
363
|
+
}
|
|
364
|
+
function findInlineRuntimeProvide(node) {
|
|
365
|
+
if (!isPipeCall(node)) return;
|
|
366
|
+
return pipeParts(node).find((part) => isEffectProvideWithSingleArgument(part));
|
|
367
|
+
}
|
|
368
|
+
function hasObjectSpread(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
369
|
+
if (typeof node === "object" && node !== null && node.type === "SpreadElement") return true;
|
|
370
|
+
if (Array.isArray(node)) return node.some((child) => hasObjectSpread(child, seen));
|
|
371
|
+
if (typeof node !== "object" || node === null) return false;
|
|
372
|
+
if (seen.has(node)) return false;
|
|
373
|
+
seen.add(node);
|
|
374
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && hasObjectSpread(child, seen));
|
|
375
|
+
}
|
|
376
|
+
function isRefStateUpdateWithSpread(node) {
|
|
377
|
+
if (!isMemberCall(node, "Ref", "update") && !isMemberCall(node, "Ref", "modify")) return false;
|
|
378
|
+
const callback = node.arguments[1];
|
|
379
|
+
return hasObjectSpread(callbackBody(callback));
|
|
380
|
+
}
|
|
381
|
+
function isEmptyObjectExpression(node) {
|
|
382
|
+
return typeof node === "object" && node !== null && node.type === "ObjectExpression" && Array.isArray(node.properties) && node.properties.length === 0;
|
|
383
|
+
}
|
|
384
|
+
function containsObjectEntriesCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
385
|
+
if (isMemberCall(node, "Object", "entries")) return true;
|
|
386
|
+
if (Array.isArray(node)) return node.some((child) => containsObjectEntriesCall(child, seen));
|
|
387
|
+
if (typeof node !== "object" || node === null) return false;
|
|
388
|
+
if (seen.has(node)) return false;
|
|
389
|
+
seen.add(node);
|
|
390
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && containsObjectEntriesCall(child, seen));
|
|
391
|
+
}
|
|
392
|
+
function isNakedObjectStateUpdate(node) {
|
|
393
|
+
if (isRefStateUpdateWithSpread(node)) return true;
|
|
394
|
+
if (isMemberCall(node, "Object", "assign")) {
|
|
395
|
+
const args = node.arguments;
|
|
396
|
+
return args.length >= 3 && isEmptyObjectExpression(args[0]);
|
|
397
|
+
}
|
|
398
|
+
if (isMemberCall(node, "Object", "fromEntries")) return containsObjectEntriesCall(node.arguments[0]);
|
|
399
|
+
return isMemberCall(node, "JSON", "stringify") || isMemberCall(node, "JSON", "parse");
|
|
400
|
+
}
|
|
401
|
+
function isEffectSucceedVariableArgument(node) {
|
|
402
|
+
if (isIdentifier(node)) return true;
|
|
403
|
+
return typeof node === "object" && node !== null && node.type === "MemberExpression";
|
|
404
|
+
}
|
|
405
|
+
function isVariableAsAssertion(node) {
|
|
406
|
+
if (typeof node !== "object" || node === null || node.type !== "VariableDeclaration") return false;
|
|
407
|
+
return node.declarations?.some((declaration) => {
|
|
408
|
+
if (typeof declaration !== "object" || declaration === null) return false;
|
|
409
|
+
const init = declaration.init;
|
|
410
|
+
return typeof init === "object" && init !== null && init.type === "TSAsExpression" && typeof init.typeAnnotation === "object" && init.typeAnnotation !== null && init.typeAnnotation.type !== "TSConstKeyword";
|
|
411
|
+
}) ?? false;
|
|
412
|
+
}
|
|
413
|
+
function isTypeofBooleanCheck(node) {
|
|
414
|
+
if (typeof node !== "object" || node === null || node.type !== "BinaryExpression") return false;
|
|
415
|
+
const binary = node;
|
|
416
|
+
if (binary.operator !== "===") return false;
|
|
417
|
+
const left = binary.left;
|
|
418
|
+
const right = binary.right;
|
|
419
|
+
return typeof left === "object" && left !== null && left.type === "UnaryExpression" && left.operator === "typeof" && typeof right === "object" && right !== null && (right.type === "Literal" || right.type === "StringLiteral") && right.value === "boolean";
|
|
420
|
+
}
|
|
421
|
+
function isMatchOrElseNullCall(node) {
|
|
422
|
+
return isMatchBranchCall(node, "orElse") && isNullLiteral(arrowCallbackBody(node.arguments[0]));
|
|
423
|
+
}
|
|
424
|
+
function isStringLiteral(node) {
|
|
425
|
+
return typeof node === "object" && node !== null && (node.type === "Literal" || node.type === "StringLiteral") && typeof node.value === "string";
|
|
426
|
+
}
|
|
427
|
+
function isUndefinedIdentifier(node) {
|
|
428
|
+
return isIdentifier(node, "undefined");
|
|
429
|
+
}
|
|
430
|
+
function isNullishRewrap(node) {
|
|
431
|
+
return typeof node === "object" && node !== null && node.type === "LogicalExpression" && node.operator === "??" && (isNullLiteral(node.right) || isUndefinedIdentifier(node.right));
|
|
432
|
+
}
|
|
433
|
+
function isOptionFromNullableNullishCoalesce(node) {
|
|
434
|
+
return isMemberCall(node, "Option", "fromNullable") && isNullishRewrap(node.arguments[0]);
|
|
435
|
+
}
|
|
436
|
+
function objectPropertyValue(node, keyName) {
|
|
437
|
+
if (typeof node !== "object" || node === null || node.type !== "ObjectExpression") return;
|
|
438
|
+
for (const property of node.properties ?? []) {
|
|
439
|
+
if (typeof property !== "object" || property === null) continue;
|
|
440
|
+
const key = property.key;
|
|
441
|
+
if (isIdentifier(key, keyName)) return property.value;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
function isBooleanTrueComparison(node) {
|
|
445
|
+
if (typeof node !== "object" || node === null || node.type !== "BinaryExpression") return false;
|
|
446
|
+
const binary = node;
|
|
447
|
+
return binary.operator === "===" && (isBooleanLiteral(binary.left, true) || isBooleanLiteral(binary.right, true));
|
|
448
|
+
}
|
|
449
|
+
function isOptionBooleanNormalization(node) {
|
|
450
|
+
if (!isMemberCall(node, "Option", "match")) return false;
|
|
451
|
+
const config = node.arguments[1];
|
|
452
|
+
const onSome = objectPropertyValue(config, "onSome");
|
|
453
|
+
const onNone = objectPropertyValue(config, "onNone");
|
|
454
|
+
return isBooleanTrueComparison(arrowCallbackBody(onSome)) && isBooleanLiteral(arrowCallbackBody(onNone), false);
|
|
455
|
+
}
|
|
456
|
+
function isStringSentinelConst(node) {
|
|
457
|
+
if (typeof node !== "object" || node === null || node.type !== "VariableDeclaration") return false;
|
|
458
|
+
return node.declarations?.some((declaration) => typeof declaration === "object" && declaration !== null && isStringLiteral(declaration.init)) ?? false;
|
|
459
|
+
}
|
|
460
|
+
function isBooleanLiteral(node, value) {
|
|
461
|
+
return typeof node === "object" && node !== null && (node.type === "Literal" || node.type === "BooleanLiteral") && node.value === value;
|
|
462
|
+
}
|
|
463
|
+
function isEffectVoidMember(node) {
|
|
464
|
+
return isMemberExpression(node, "Effect", "void");
|
|
465
|
+
}
|
|
466
|
+
function isMatchBranchCall(node, propertyName) {
|
|
467
|
+
if (typeof node !== "object" || node === null) return false;
|
|
468
|
+
const call = node;
|
|
469
|
+
return call.type === "CallExpression" && Array.isArray(call.arguments) && typeof call.callee === "object" && call.callee !== null && call.callee.type === "MemberExpression" && call.callee.computed !== true && isIdentifier(call.callee.object, "Match") && isIdentifier(call.callee.property) && (propertyName === void 0 || isIdentifier(call.callee.property, propertyName));
|
|
470
|
+
}
|
|
471
|
+
function arrowCallbackBody(node) {
|
|
472
|
+
if (typeof node !== "object" || node === null || node.type !== "ArrowFunctionExpression") return;
|
|
473
|
+
return node.body;
|
|
474
|
+
}
|
|
475
|
+
function isVoidMatchBranch(node) {
|
|
476
|
+
if (!isMatchBranchCall(node)) return false;
|
|
477
|
+
const [first, second] = node.arguments;
|
|
478
|
+
if (isIdentifier(node.callee.property, "when")) return (isBooleanLiteral(first, true) || isBooleanLiteral(first, false)) && isEffectVoidMember(arrowCallbackBody(second));
|
|
479
|
+
return isIdentifier(node.callee.property, "orElse") && isEffectVoidMember(arrowCallbackBody(first));
|
|
480
|
+
}
|
|
481
|
+
const branchSequencingEffectCalls = [
|
|
482
|
+
"flatMap",
|
|
483
|
+
"map",
|
|
484
|
+
"andThen",
|
|
485
|
+
"tap",
|
|
486
|
+
"zipRight"
|
|
487
|
+
];
|
|
488
|
+
function isStreamMemberCall(node) {
|
|
489
|
+
if (typeof node !== "object" || node === null) return false;
|
|
490
|
+
const call = node;
|
|
491
|
+
return call.type === "CallExpression" && typeof call.callee === "object" && call.callee !== null && call.callee.type === "MemberExpression" && call.callee.computed !== true && isIdentifier(call.callee.object, "Stream") && isIdentifier(call.callee.property);
|
|
492
|
+
}
|
|
493
|
+
function containsAnyEffectMemberCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
494
|
+
if (isEffectMemberCall(node)) return true;
|
|
495
|
+
if (Array.isArray(node)) return node.some((child) => containsAnyEffectMemberCall(child, seen));
|
|
496
|
+
if (typeof node !== "object" || node === null) return false;
|
|
497
|
+
if (seen.has(node)) return false;
|
|
498
|
+
seen.add(node);
|
|
499
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && containsAnyEffectMemberCall(child, seen));
|
|
500
|
+
}
|
|
501
|
+
function containsBranchSequencingCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
502
|
+
if (branchSequencingEffectCalls.some((propertyName) => isEffectMemberCallNamed(node, propertyName)) || isPipeCall(node) || isStreamMemberCall(node)) return true;
|
|
503
|
+
if (Array.isArray(node)) return node.some((child) => containsBranchSequencingCall(child, seen));
|
|
504
|
+
if (typeof node !== "object" || node === null) return false;
|
|
505
|
+
if (seen.has(node)) return false;
|
|
506
|
+
seen.add(node);
|
|
507
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && containsBranchSequencingCall(child, seen));
|
|
508
|
+
}
|
|
509
|
+
function isSequencingBranchBody(node) {
|
|
510
|
+
return containsAnyEffectMemberCall(node) && containsBranchSequencingCall(node);
|
|
511
|
+
}
|
|
512
|
+
function containsSequencingMatchBranch(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
513
|
+
if (isMatchBranchCall(node)) {
|
|
514
|
+
if (isSequencingBranchBody(isIdentifier(node.callee.property, "when") ? arrowCallbackBody(node.arguments[1]) : arrowCallbackBody(node.arguments[0]))) return true;
|
|
515
|
+
}
|
|
516
|
+
if (Array.isArray(node)) return node.some((child) => containsSequencingMatchBranch(child, seen));
|
|
517
|
+
if (typeof node !== "object" || node === null) return false;
|
|
518
|
+
if (seen.has(node)) return false;
|
|
519
|
+
seen.add(node);
|
|
520
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && containsSequencingMatchBranch(child, seen));
|
|
521
|
+
}
|
|
522
|
+
function containsMatchBranchCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
523
|
+
if (isMatchBranchCall(node)) return true;
|
|
524
|
+
if (Array.isArray(node)) return node.some((child) => containsMatchBranchCall(child, seen));
|
|
525
|
+
if (typeof node !== "object" || node === null) return false;
|
|
526
|
+
if (seen.has(node)) return false;
|
|
527
|
+
seen.add(node);
|
|
528
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && containsMatchBranchCall(child, seen));
|
|
529
|
+
}
|
|
530
|
+
function isOptionMatchCall(node) {
|
|
531
|
+
return typeof node === "object" && node !== null && node.type === "CallExpression" && Array.isArray(node.arguments) && isMemberExpression(node.callee, "Option", "match");
|
|
532
|
+
}
|
|
533
|
+
function isExpressionBodiedArrowCall(node) {
|
|
534
|
+
const body = arrowCallbackBody(node);
|
|
535
|
+
return typeof body === "object" && body !== null && body.type === "CallExpression";
|
|
536
|
+
}
|
|
537
|
+
function findEffectGenCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
538
|
+
if (isEffectMemberCallNamed(node, "gen")) return node;
|
|
539
|
+
if (Array.isArray(node)) {
|
|
540
|
+
for (const child of node) {
|
|
541
|
+
const match = findEffectGenCall(child, seen);
|
|
542
|
+
if (match) return match;
|
|
543
|
+
}
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
if (typeof node !== "object" || node === null) return;
|
|
547
|
+
if (seen.has(node)) return;
|
|
548
|
+
seen.add(node);
|
|
549
|
+
for (const [key, child] of Object.entries(node)) {
|
|
550
|
+
if (key === "parent") continue;
|
|
551
|
+
const match = findEffectGenCall(child, seen);
|
|
552
|
+
if (match) return match;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
function isMatchValuePipeCall(node) {
|
|
556
|
+
if (!isPipeCall(node) || typeof node !== "object" || node === null) return false;
|
|
557
|
+
const object = node.callee.object;
|
|
558
|
+
return typeof object === "object" && object !== null && object.type === "CallExpression" && isMemberExpression(object.callee, "Match", "value");
|
|
559
|
+
}
|
|
560
|
+
function isObjectBranchCall(node) {
|
|
561
|
+
return isMatchValuePipeCall(node) || typeof node === "object" && node !== null && node.type === "CallExpression" && (isMemberExpression(node.callee, "Option", "match") || isMemberExpression(node.callee, "Either", "match"));
|
|
562
|
+
}
|
|
563
|
+
function containsObjectBranchCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
564
|
+
if (isObjectBranchCall(node)) return true;
|
|
565
|
+
if (Array.isArray(node)) return node.some((child) => containsObjectBranchCall(child, seen));
|
|
566
|
+
if (typeof node !== "object" || node === null) return false;
|
|
567
|
+
if (seen.has(node)) return false;
|
|
568
|
+
seen.add(node);
|
|
569
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && containsObjectBranchCall(child, seen));
|
|
570
|
+
}
|
|
571
|
+
function objectPropertyValues(node) {
|
|
572
|
+
if (typeof node !== "object" || node === null) return [];
|
|
573
|
+
const object = node;
|
|
574
|
+
if (object.type !== "ObjectExpression" || !Array.isArray(object.properties)) return [];
|
|
575
|
+
return object.properties.map((property) => typeof property === "object" && property !== null ? property.value : void 0).filter((value) => value !== void 0);
|
|
576
|
+
}
|
|
577
|
+
function report(context, node, message) {
|
|
578
|
+
context.report({
|
|
579
|
+
message,
|
|
580
|
+
node
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
function isNullLiteral(node) {
|
|
584
|
+
if (typeof node !== "object" || node === null) return false;
|
|
585
|
+
const literal = node;
|
|
586
|
+
return literal.type === "NullLiteral" || literal.type === "Literal" && literal.value === null;
|
|
587
|
+
}
|
|
588
|
+
function getImportSource(node) {
|
|
589
|
+
if (typeof node !== "object" || node === null) return;
|
|
590
|
+
const source = node.source;
|
|
591
|
+
if (typeof source === "string") return source;
|
|
592
|
+
if (typeof source === "object" && source !== null) {
|
|
593
|
+
const value = source.value;
|
|
594
|
+
if (typeof value === "string") return value;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function isEffectEcosystemImport(source) {
|
|
598
|
+
return source === "effect" || source.startsWith("effect/") || source === "@effect-atom/atom-react";
|
|
599
|
+
}
|
|
600
|
+
function createEffectGatedStatementRule(visitorName, message) {
|
|
601
|
+
return defineRule({ create(context) {
|
|
602
|
+
let hasEffectEcosystemImport = false;
|
|
603
|
+
return {
|
|
604
|
+
ImportDeclaration(node) {
|
|
605
|
+
const source = getImportSource(node);
|
|
606
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
607
|
+
},
|
|
608
|
+
[visitorName](node) {
|
|
609
|
+
if (hasEffectEcosystemImport) report(context, node, message);
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
} });
|
|
613
|
+
}
|
|
614
|
+
const reactStateHooks = /* @__PURE__ */ new Set([
|
|
615
|
+
"useState",
|
|
616
|
+
"useReducer",
|
|
617
|
+
"useContext",
|
|
618
|
+
"useCallback",
|
|
619
|
+
"useEffect",
|
|
620
|
+
"useSyncExternalStore"
|
|
621
|
+
]);
|
|
622
|
+
const noReactState = defineRule({ create(context) {
|
|
623
|
+
return { CallExpression(node) {
|
|
624
|
+
const callee = node.callee;
|
|
625
|
+
const hookName = isIdentifier(callee) ? callee.name : typeof callee === "object" && callee !== null && callee.type === "MemberExpression" && isIdentifier(callee.property) ? callee.property.name : void 0;
|
|
626
|
+
if (hookName && reactStateHooks.has(hookName)) report(context, callee, "Rule: avoid React state hooks. Why: they bypass the atom runtime and break reactive flow. Fix: use @effect-atom/atom-react instead.");
|
|
627
|
+
} };
|
|
628
|
+
} });
|
|
629
|
+
const noIfStatement = createEffectGatedStatementRule("IfStatement", "Rule: avoid imperative if branching. Why: Effect code should keep branching explicit and typed. Fix: use Match.value/Match.type or Effect combinators instead.");
|
|
630
|
+
const noSwitchStatement = createEffectGatedStatementRule("SwitchStatement", "Rule: avoid imperative switch branching. Why: Effect code should keep branching explicit and typed. Fix: use Match.value/Match.type instead.");
|
|
631
|
+
const noTernary = createEffectGatedStatementRule("ConditionalExpression", "Rule: avoid ternary expressions. Why: they hide control flow inside expressions. Fix: use Option.match/Either.match/Match.value or data combinators, then run one Effect pipeline.");
|
|
632
|
+
const noReturnNull = defineRule({ create(context) {
|
|
633
|
+
let hasEffectEcosystemImport = false;
|
|
634
|
+
return {
|
|
635
|
+
ImportDeclaration(node) {
|
|
636
|
+
const source = getImportSource(node);
|
|
637
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
638
|
+
},
|
|
639
|
+
ReturnStatement(node) {
|
|
640
|
+
if (hasEffectEcosystemImport && isNullLiteral(node.argument)) report(context, node, "Rule: avoid returning null. Why: null is a sentinel that forces defensive guards. Fix: use Option.none for absence or Effect.fail for errors.");
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
} });
|
|
644
|
+
const noOptionAs = defineRule({ create(context) {
|
|
645
|
+
let hasEffectEcosystemImport = false;
|
|
646
|
+
return {
|
|
647
|
+
ImportDeclaration(node) {
|
|
648
|
+
const source = getImportSource(node);
|
|
649
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
650
|
+
},
|
|
651
|
+
CallExpression(node) {
|
|
652
|
+
if (hasEffectEcosystemImport && isMemberExpression(node.callee, "Option", "as")) report(context, node, "Rule: avoid Option.as. Why: it hides selection and encourages placeholder flows. Fix: use Option.map or Option.match and return the value explicitly.");
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
} });
|
|
656
|
+
const noEffectNever = defineRule({ create(context) {
|
|
657
|
+
let hasEffectEcosystemImport = false;
|
|
658
|
+
return {
|
|
659
|
+
ImportDeclaration(node) {
|
|
660
|
+
const source = getImportSource(node);
|
|
661
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
662
|
+
},
|
|
663
|
+
MemberExpression(node) {
|
|
664
|
+
if (hasEffectEcosystemImport && isMemberExpression(node, "Effect", "never")) report(context, node, "Rule: avoid Effect.never. Why: it hides lifecycle and leaks resources. Fix: use Stream or explicit acquire/release lifecycles with clear teardown.");
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
} });
|
|
668
|
+
const noArrowLadder = defineRule({ create(context) {
|
|
669
|
+
let hasEffectEcosystemImport = false;
|
|
670
|
+
return {
|
|
671
|
+
ImportDeclaration(node) {
|
|
672
|
+
const source = getImportSource(node);
|
|
673
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
674
|
+
},
|
|
675
|
+
CallExpression(node) {
|
|
676
|
+
if (!hasEffectEcosystemImport || !isArrowIifeCall(node)) return;
|
|
677
|
+
const nested = findArrowIifeCall(node.callee.body);
|
|
678
|
+
if (nested) report(context, nested, "Rule: avoid nested IIFEs. Why: they hide sequencing and push wrapper hacks. Fix: bind a named context with const and keep one flat pipeline with a single Match/Option decision.");
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
} });
|
|
682
|
+
const noBranchInObject = defineRule({ create(context) {
|
|
683
|
+
return { ObjectExpression(node) {
|
|
684
|
+
if (objectPropertyValues(node).some((value) => containsObjectBranchCall(value))) report(context, node, "Rule: avoid Match/Option/Either inside object literals. Why: it hides the decision and invites workaround scaffolding. Fix: compute the value first (context), then build the object from named values with one flat decision.");
|
|
685
|
+
} };
|
|
686
|
+
} });
|
|
687
|
+
const noIifeWrapper = defineRule({ create(context) {
|
|
688
|
+
let hasEffectEcosystemImport = false;
|
|
689
|
+
return {
|
|
690
|
+
ImportDeclaration(node) {
|
|
691
|
+
const source = getImportSource(node);
|
|
692
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
693
|
+
},
|
|
694
|
+
CallExpression(node) {
|
|
695
|
+
if (hasEffectEcosystemImport && isInlineFunctionIifeCall(node)) report(context, node, "Rule: avoid immediate invocation of inline functions. Why: it hides decisions and sequencing. Fix: bind a named context with const and keep one Match/Option decision in a flat pipeline.");
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
} });
|
|
699
|
+
const noReturnInArrow = defineRule({ create(context) {
|
|
700
|
+
return { CallExpression(node) {
|
|
701
|
+
for (const returnNode of directArrowCallbackReturns(node)) report(context, returnNode, "Rule: avoid block-bodied arrow callbacks with returns. Why: they hide local control flow. Fix: use expression-only callbacks and move the logic into a single pipeline (pipe/Match/Option/A.map).");
|
|
702
|
+
} };
|
|
703
|
+
} });
|
|
704
|
+
const noReturnInCallback = defineRule({ create(context) {
|
|
705
|
+
return { CallExpression(node) {
|
|
706
|
+
for (const returnNode of directFunctionCallbackReturns(node)) report(context, returnNode, "Rule: avoid returns inside inline callbacks. Why: they hide control flow. Prefer expression-only callbacks, but leaf-level Effect branches with local bindings may use returns when needed.");
|
|
707
|
+
} };
|
|
708
|
+
} });
|
|
709
|
+
const noEffectFnGenerator = defineRule({ create(context) {
|
|
710
|
+
let hasEffectEcosystemImport = false;
|
|
711
|
+
return {
|
|
712
|
+
ImportDeclaration(node) {
|
|
713
|
+
const source = getImportSource(node);
|
|
714
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
715
|
+
},
|
|
716
|
+
CallExpression(node) {
|
|
717
|
+
if (hasEffectEcosystemImport && isEffectGeneratorCall(node, "fn")) report(context, node, "Rule: avoid Effect.fn generator wrappers. Why: they hide sequencing and dodge ladder rules. Fix: keep a single flat pipeline or use one Effect.gen.");
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
} });
|
|
721
|
+
const noEffectSyncConsole = defineRule({ create(context) {
|
|
722
|
+
let hasEffectEcosystemImport = false;
|
|
723
|
+
return {
|
|
724
|
+
ImportDeclaration(node) {
|
|
725
|
+
const source = getImportSource(node);
|
|
726
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
727
|
+
},
|
|
728
|
+
CallExpression(node) {
|
|
729
|
+
if (hasEffectEcosystemImport && isEffectMemberCallNamed(node, "sync") && containsConsoleCall(firstArgument(node))) report(context, node, "Rule: avoid console.* inside Effect.sync. Why: it hides side effects. Fix: replace with Effect.log* or remove the console call.");
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
} });
|
|
733
|
+
const noNestedEffectGen = defineRule({ create(context) {
|
|
734
|
+
let hasEffectEcosystemImport = false;
|
|
735
|
+
return {
|
|
736
|
+
ImportDeclaration(node) {
|
|
737
|
+
const source = getImportSource(node);
|
|
738
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
739
|
+
},
|
|
740
|
+
CallExpression(node) {
|
|
741
|
+
const generator = getEffectGeneratorArgument(node, "gen");
|
|
742
|
+
if (!hasEffectEcosystemImport || !generator) return;
|
|
743
|
+
const nested = findEffectGenCall(generator.body);
|
|
744
|
+
if (nested) report(context, nested, "Rule: avoid nested Effect.gen. Why: nested generators hide sequencing. Fix: flatten to a single Effect.gen per method or a single flat pipeline.");
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
} });
|
|
748
|
+
const noMatchVoidBranch = defineRule({ create(context) {
|
|
749
|
+
let hasEffectEcosystemImport = false;
|
|
750
|
+
return {
|
|
751
|
+
ImportDeclaration(node) {
|
|
752
|
+
const source = getImportSource(node);
|
|
753
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
754
|
+
},
|
|
755
|
+
CallExpression(node) {
|
|
756
|
+
if (hasEffectEcosystemImport && isVoidMatchBranch(node)) report(context, node, "Rule: avoid void Match branches. Why: they hide guard-style control flow. Fix: remove the no-op branch or select a value and run one Effect pipeline outside the Match.");
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
} });
|
|
760
|
+
const noMatchEffectBranch = defineRule({ create(context) {
|
|
761
|
+
return { CallExpression(node) {
|
|
762
|
+
if (isMatchValuePipeCall(node) && containsSequencingMatchBranch(node.arguments)) report(context, node, "Rule: avoid multi-step sequencing inside Match branches. Why: it hides control flow. Fix: select a value in Match, then run one Effect pipeline outside. Avoid data-encoded conditionals (Option.toArray/forEach) that only rewrap the branch.");
|
|
763
|
+
if (isOptionMatchCall(node) && isSequencingBranchBody(node.arguments)) report(context, node, "Rule: avoid multi-step sequencing inside Option.match branches. Why: it hides control flow. Prefer selecting a value in Option.match, then run one Effect pipeline outside. Leaf-level flows with local bindings may keep Option.match but should stay linear.");
|
|
764
|
+
} };
|
|
765
|
+
} });
|
|
766
|
+
const warnEffectSyncWrapper = defineRule({ create(context) {
|
|
767
|
+
let hasEffectEcosystemImport = false;
|
|
768
|
+
return {
|
|
769
|
+
ImportDeclaration(node) {
|
|
770
|
+
const source = getImportSource(node);
|
|
771
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
772
|
+
},
|
|
773
|
+
CallExpression(node) {
|
|
774
|
+
const callback = firstArgument(node);
|
|
775
|
+
const body = arrowCallbackBody(callback);
|
|
776
|
+
if (hasEffectEcosystemImport && isEffectMemberCallNamed(node, "sync") && isExpressionBodiedArrowCall(callback) && !isConsoleCall(body)) report(context, node, "Rule: avoid Effect.sync around side effects. Why: it hides intent. Fix: use Effect.log* or an explicit pipeline step for the side effect.");
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
} });
|
|
780
|
+
const noEffectSideEffectWrapper = defineRule({ create(context) {
|
|
781
|
+
return { CallExpression(node) {
|
|
782
|
+
if (isEffectMemberCallNamed(node, "as") && containsWrapperSideEffect(firstArgument(node))) report(context, node, "Rule: avoid Effect.as for side effects. Why: it hides side effects and turns them into placeholders. Fix: use explicit pipeline steps that return real values with Effect.flatMap, Effect.andThen, or Effect.tap.");
|
|
783
|
+
if (isEffectMemberCallNamed(node, "zipRight") && containsWrapperSideEffect(firstArgument(node))) report(context, node, "Rule: avoid Effect.zipRight for side effects. Why: it hides side effects and discards values. Fix: use explicit pipeline steps that return real values with Effect.flatMap, Effect.andThen, or Effect.tap.");
|
|
784
|
+
} };
|
|
785
|
+
} });
|
|
786
|
+
const noEffectAllStepSequencing = defineRule({ create(context) {
|
|
787
|
+
return { CallExpression(node) {
|
|
788
|
+
if (isEffectMemberCallNamed(node, "all") && containsAllStepSideEffect(node.arguments[0]) && hasConcurrencyOne(node.arguments[1])) report(context, node, "Rule: avoid Effect.all for sequential side-effect steps. Why: it hides imperative sequencing in an array. Fix: use one explicit linear pipeline with Effect.andThen/flatMap and reserve Effect.all for real value aggregation.");
|
|
789
|
+
if (isEffectAllAsVoidPipe(node) && containsAllStepSideEffect(firstArgument(node.callee.object))) report(context, node, "Rule: avoid Effect.all for sequential side-effect steps. Why: it hides imperative sequencing in an array. Fix: use one explicit linear pipeline with Effect.andThen/flatMap and reserve Effect.all for real value aggregation.");
|
|
790
|
+
} };
|
|
791
|
+
} });
|
|
792
|
+
const noTryCatch = defineRule({ create(context) {
|
|
793
|
+
return { TryStatement(node) {
|
|
794
|
+
report(context, node, "Rule: avoid try/catch in Effect files. Why: it bypasses Effect error channels and reintroduces imperative control flow. Fix: model failures in Effect and handle them with typed errors and Effect combinators.");
|
|
795
|
+
} };
|
|
796
|
+
} });
|
|
797
|
+
const noEffectWrapperAlias = defineRule({ create(context) {
|
|
798
|
+
return {
|
|
799
|
+
VariableDeclaration(node) {
|
|
800
|
+
for (const declaration of node.declarations ?? []) if (isEffectWrapperAliasExpression(declaration.init)) report(context, node, "Rule: avoid Effect wrapper aliases (`const x = ...Effect...`). Why: it creates wrapper choreography and bloats consts. Fix: inline the pipeline at the call site or define a real domain function that returns data, not an Effect wrapper.");
|
|
801
|
+
},
|
|
802
|
+
FunctionDeclaration(node) {
|
|
803
|
+
if (hasEffectWrapperAliasReturn(node.body)) report(context, node, "Rule: avoid Effect wrapper aliases (`function x(...) { return Effect... }`). Why: it creates wrapper choreography and bloats consts. Fix: inline the pipeline at the call site or define a real domain function that returns data, not an Effect wrapper.");
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
} });
|
|
807
|
+
const noManualEffectChannels = defineRule({ create(context) {
|
|
808
|
+
return { TSTypeReference(node) {
|
|
809
|
+
if (isQualifiedTypeReference(node, "Effect", "Effect") || isQualifiedTypeReference(node, "Layer", "Layer")) report(context, node, "Rule: avoid manual Effect channel tuples (`Effect.Effect<...>` / `Layer.Layer<...>`). Why: channels compose through the Effect pipeline and services; hand-written tuples desync from the real flow. Fix: drop the generic and let the return type infer from the Effect/Layer you return, or expose a service method that returns the effect directly.");
|
|
810
|
+
} };
|
|
811
|
+
} });
|
|
812
|
+
const noWrapgraphqlCatchall = defineRule({ create(context) {
|
|
813
|
+
let hasEffectEcosystemImport = false;
|
|
814
|
+
return {
|
|
815
|
+
ImportDeclaration(node) {
|
|
816
|
+
const source = getImportSource(node);
|
|
817
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
818
|
+
},
|
|
819
|
+
CallExpression(node) {
|
|
820
|
+
const catchAll = hasEffectEcosystemImport ? getWrapGraphqlCatchAll(node) : void 0;
|
|
821
|
+
if (catchAll) report(context, catchAll, "Rule: avoid catchAll after wrapGraphqlCall/applyResponse. Why: the envelope already surfaces structured errors. Fix: handle errors in the response mapping instead of catchAll.");
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
} });
|
|
825
|
+
const noRenderSideEffects = defineRule({ create(context) {
|
|
826
|
+
let hasEffectEcosystemImport = false;
|
|
827
|
+
return {
|
|
828
|
+
ImportDeclaration(node) {
|
|
829
|
+
const source = getImportSource(node);
|
|
830
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
831
|
+
},
|
|
832
|
+
ExpressionStatement(node) {
|
|
833
|
+
if (hasEffectEcosystemImport && isMatchValuePipeCall(node.expression) && containsMatchBranchCall(node.expression.arguments)) report(context, node.expression, "Rule: avoid Match.value(...).pipe(...) as a statement. Why: it runs side effects during render. Fix: move the side effect into an Effect runtime action or event handler, and keep Match as a pure expression.");
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
} });
|
|
837
|
+
const noAtomRegistryEffectSync = defineRule({ create(context) {
|
|
838
|
+
let hasEffectEcosystemImport = false;
|
|
839
|
+
return {
|
|
840
|
+
ImportDeclaration(node) {
|
|
841
|
+
const source = getImportSource(node);
|
|
842
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
843
|
+
},
|
|
844
|
+
CallExpression(node) {
|
|
845
|
+
const atomOperation = hasEffectEcosystemImport ? findAtomOperationInsideEffectSync(node) : void 0;
|
|
846
|
+
if (atomOperation) report(context, atomOperation, "Rule: do not wrap Atom/atomRegistry ops in Effect.sync. Why: it hides side effects and breaks atom flow. Fix: call Atom.get/Atom.set/Atom.update/Atom.modify/Atom.refresh directly.");
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
} });
|
|
850
|
+
const noFamilyCollectionRead = defineRule({ create(context) {
|
|
851
|
+
return { CallExpression(node) {
|
|
852
|
+
if (!isMemberCall(node, "Atom", "family")) return;
|
|
853
|
+
const collectionAtom = findFamilyCollectionRead(node.arguments);
|
|
854
|
+
if (collectionAtom) report(context, collectionAtom, "Keyed projection atom reads collection atom. Why: Atom.family should project from keyed/source atoms, not broad collection state. Fix: pass the keyed atom into the family or create a keyed source atom before reading.");
|
|
855
|
+
} };
|
|
856
|
+
} });
|
|
857
|
+
const noInlineRuntimeProvide = defineRule({ create(context) {
|
|
858
|
+
let hasEffectEcosystemImport = false;
|
|
859
|
+
return {
|
|
860
|
+
ImportDeclaration(node) {
|
|
861
|
+
const source = getImportSource(node);
|
|
862
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
863
|
+
},
|
|
864
|
+
CallExpression(node) {
|
|
865
|
+
const provide = hasEffectEcosystemImport ? findInlineRuntimeProvide(node) : void 0;
|
|
866
|
+
if (provide) report(context, provide, "Rule: do not inline runtime provisioning inside local helper Effect code. Why: `yield* SomeRuntime.pipe(Effect.provide(SomeRuntimeLive))` and equivalent inline provide chains hide dependency assembly instead of owning it at an Effect.Service boundary or one exported Effect boundary. Fix: declare the live dependency on the owning service or provide it once at the exported boundary, then `yield*` the runtime or service directly inside the body.");
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
} });
|
|
870
|
+
const noNakedObjectStateUpdate = defineRule({ create(context) {
|
|
871
|
+
return { CallExpression(node) {
|
|
872
|
+
if (isNakedObjectStateUpdate(node)) report(context, node, "Rule: avoid naked JS state patching/rebuild and raw JSON shortcuts in Effect transitions. Why: spread/Object.assign/fromEntries and inline JSON parse/stringify hide state intent and bypass explicit model contracts. Fix: use `effect/Record` combinators (`Record.set` / `Record.modify` / `Record.remove`) inside `Struct.evolve`, rebuild with schema constructors (`Schema.make` or field `.make`), and keep serialization at boundaries with schema encode/decode flows. Use `linting.md` guidance when available.");
|
|
873
|
+
} };
|
|
874
|
+
} });
|
|
875
|
+
const noEffectSucceedVariable = defineRule({ create(context) {
|
|
876
|
+
let hasEffectEcosystemImport = false;
|
|
877
|
+
return {
|
|
878
|
+
ImportDeclaration(node) {
|
|
879
|
+
const source = getImportSource(node);
|
|
880
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
881
|
+
},
|
|
882
|
+
CallExpression(node) {
|
|
883
|
+
if (hasEffectEcosystemImport && isEffectMemberCallNamed(node, "succeed") && isEffectSucceedVariableArgument(firstArgument(node))) report(context, node, "Rule: avoid Effect.succeed(variable) as a branch placeholder. Why: it hides a decision and turns data into pseudo-control flow. Fix: select a plain value (Option/Match) and then run one Effect pipeline after the decision; if you already read the state, return it as a value. Avoid Option.toArray/forEach hacks that just re-encode the branch.");
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
} });
|
|
887
|
+
const noEffectTypeAlias = defineRule({ create(context) {
|
|
888
|
+
let hasEffectEcosystemImport = false;
|
|
889
|
+
return {
|
|
890
|
+
ImportDeclaration(node) {
|
|
891
|
+
const source = getImportSource(node);
|
|
892
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
893
|
+
},
|
|
894
|
+
TSTypeAliasDeclaration(node) {
|
|
895
|
+
if (hasEffectEcosystemImport && containsQualifiedTypeReference(node.typeAnnotation, "Effect", "Effect")) report(context, node.typeAnnotation, "Rule: avoid Effect.Effect type aliases. Why: they hide the service surface and make types opaque. Fix: keep Effect types on service methods or inline at the call site.");
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
} });
|
|
899
|
+
const noModelOverlayCast = defineRule({ create(context) {
|
|
900
|
+
let hasEffectEcosystemImport = false;
|
|
901
|
+
return {
|
|
902
|
+
ImportDeclaration(node) {
|
|
903
|
+
const source = getImportSource(node);
|
|
904
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
905
|
+
},
|
|
906
|
+
VariableDeclaration(node) {
|
|
907
|
+
if (hasEffectEcosystemImport && isVariableAsAssertion(node)) report(context, node, "Rule: avoid `as` assertions on decoded model flow. Why: assertions hide schema drift and allow untyped overlays. Fix: decode with the correct schema type and read fields directly.");
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
} });
|
|
911
|
+
const noUnknownBooleanCoercionHelper = defineRule({ create(context) {
|
|
912
|
+
let hasEffectEcosystemImport = false;
|
|
913
|
+
let hasMatchOrElseNull = false;
|
|
914
|
+
const booleanChecks = [];
|
|
915
|
+
const reported = /* @__PURE__ */ new WeakSet();
|
|
916
|
+
const reportBooleanCheck = (node) => {
|
|
917
|
+
if (typeof node !== "object" || node === null || reported.has(node)) return;
|
|
918
|
+
reported.add(node);
|
|
919
|
+
report(context, node, "Rule: avoid local unknown-to-boolean coercion helpers in services. Why: runtime coercion belongs at schema boundary, not in service flow. Fix: decode boolean optionality in schema and read typed booleans in the Effect pipeline.");
|
|
920
|
+
};
|
|
921
|
+
return {
|
|
922
|
+
ImportDeclaration(node) {
|
|
923
|
+
const source = getImportSource(node);
|
|
924
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
925
|
+
},
|
|
926
|
+
BinaryExpression(node) {
|
|
927
|
+
if (!hasEffectEcosystemImport || !isTypeofBooleanCheck(node)) return;
|
|
928
|
+
if (hasMatchOrElseNull) reportBooleanCheck(node);
|
|
929
|
+
else booleanChecks.push(node);
|
|
930
|
+
},
|
|
931
|
+
CallExpression(node) {
|
|
932
|
+
if (!hasEffectEcosystemImport || !isMatchOrElseNullCall(node)) return;
|
|
933
|
+
hasMatchOrElseNull = true;
|
|
934
|
+
for (const check of booleanChecks) reportBooleanCheck(check);
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
} });
|
|
938
|
+
const noFromnullableNullishCoalesce = defineRule({ create(context) {
|
|
939
|
+
let hasEffectEcosystemImport = false;
|
|
940
|
+
return {
|
|
941
|
+
ImportDeclaration(node) {
|
|
942
|
+
const source = getImportSource(node);
|
|
943
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
944
|
+
},
|
|
945
|
+
CallExpression(node) {
|
|
946
|
+
if (hasEffectEcosystemImport && isOptionFromNullableNullishCoalesce(node)) report(context, node, "Rule: avoid nullish re-wrap inside Option.fromNullable. Why: `x ?? null` and `x ?? undefined` add noise and hide source shape. Fix: pass the source directly to Option.fromNullable.");
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
} });
|
|
950
|
+
const noOptionBooleanNormalization = defineRule({ create(context) {
|
|
951
|
+
let hasEffectEcosystemImport = false;
|
|
952
|
+
return {
|
|
953
|
+
ImportDeclaration(node) {
|
|
954
|
+
const source = getImportSource(node);
|
|
955
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
956
|
+
},
|
|
957
|
+
CallExpression(node) {
|
|
958
|
+
if (hasEffectEcosystemImport && isOptionBooleanNormalization(node)) report(context, node, "Rule: avoid repeated Option boolean normalization (`onSome: value === true, onNone: false`). Why: it scatters coercion rules across services. Fix: normalize once at schema boundary and read booleans directly.");
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
} });
|
|
962
|
+
const noStringSentinelReturn = defineRule({ create(context) {
|
|
963
|
+
return { CallExpression(node) {
|
|
964
|
+
if (isEffectMemberCallNamed(node, "succeed") && isStringLiteral(firstArgument(node))) report(context, node, "Rule: avoid returning string tokens. Why: it encodes control flow and forces defensive branching. Fix: return domain values (Option/Either/tagged unions) or real Effect results instead.");
|
|
965
|
+
} };
|
|
966
|
+
} });
|
|
967
|
+
const noStringSentinelConst = defineRule({ create(context) {
|
|
968
|
+
return { VariableDeclaration(node) {
|
|
969
|
+
if (isStringSentinelConst(node)) report(context, node, "Rule: avoid string status constants. Why: they encode control flow and force defensive branching. Fix: use tagged unions, Option/Either, or meaningful domain values instead of string tokens.");
|
|
970
|
+
} };
|
|
971
|
+
} });
|
|
972
|
+
const noEffectAs = defineRule({ create(context) {
|
|
973
|
+
return { CallExpression(node) {
|
|
974
|
+
if (isMemberExpression(node.callee, "Effect", "as")) report(context, node.callee, "Rule: avoid Effect.as wrappers. Why: they can hide meaningful sequencing or value flow. Fix: return the intended value directly or use explicit Effect.map/andThen.");
|
|
975
|
+
} };
|
|
976
|
+
} });
|
|
977
|
+
const noEffectDo = defineRule({ create(context) {
|
|
978
|
+
return { MemberExpression(node) {
|
|
979
|
+
if (isMemberExpression(node, "Effect", "Do")) report(context, node, "Rule: avoid Effect.Do. Why: it hides sequencing behind builder state. Fix: use Effect.gen or a direct pipe.");
|
|
980
|
+
} };
|
|
981
|
+
} });
|
|
982
|
+
function createForbiddenMemberCallRule(objectName, propertyName, message) {
|
|
983
|
+
return defineRule({ create(context) {
|
|
984
|
+
return { CallExpression(node) {
|
|
985
|
+
if (isMemberExpression(node.callee, objectName, propertyName)) report(context, node.callee, message);
|
|
986
|
+
} };
|
|
987
|
+
} });
|
|
988
|
+
}
|
|
989
|
+
const noEffectBind = createForbiddenMemberCallRule("Effect", "bind", "Rule: avoid Effect.bind. Why: it obscures linear data flow behind builder-style binding. Fix: use Effect.gen or a direct pipe with flatMap/map.");
|
|
990
|
+
const noRuntimeRunFork = createForbiddenMemberCallRule("Runtime", "runFork", "Rule: avoid Runtime.runFork. Why: detached fibers hide lifetime and interruption ownership. Fix: run effects through the application runtime boundary.");
|
|
991
|
+
const noEffectAsync = createForbiddenMemberCallRule("Effect", "async", "Rule: avoid Effect.async. Why: manual callback bridges are easy to leak or resume incorrectly. Fix: use scoped Effect APIs or a dedicated platform adapter.");
|
|
992
|
+
const noNestedEffectCall = defineRule({ create(context) {
|
|
993
|
+
return { CallExpression(node) {
|
|
994
|
+
if (hasDeepNestedEffectFirstArgument(node)) report(context, node, "Rule: avoid deeply nested Effect calls (Effect.xx(Effect.yy(Effect.zz(...)))). Why: they hide sequencing and spread flow. Fix: build values first, then run one flat Effect pipeline.");
|
|
995
|
+
} };
|
|
996
|
+
} });
|
|
997
|
+
const noEffectLadder = defineRule({ create(context) {
|
|
998
|
+
return {
|
|
999
|
+
VariableDeclaration(node) {
|
|
1000
|
+
for (const declaration of node.declarations ?? []) if (hasDeepNestedEffectFirstArgument(declaration.init)) report(context, declaration.init, "Rule: avoid nested Effect combinators. Why: they hide sequencing and create laddered control flow. Fix: build context once (Effect.all/Effect.map) and then run a single flat pipeline.");
|
|
1001
|
+
},
|
|
1002
|
+
ReturnStatement(node) {
|
|
1003
|
+
if (hasDeepNestedEffectFirstArgument(node.argument)) report(context, node.argument, "Rule: avoid nested Effect combinators. Why: they hide sequencing and create laddered control flow. Fix: build context once (Effect.all/Effect.map) and then run a single flat pipeline.");
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
} });
|
|
1007
|
+
const noFlatMapLadder = defineRule({ create(context) {
|
|
1008
|
+
return {
|
|
1009
|
+
VariableDeclaration(node) {
|
|
1010
|
+
for (const declaration of node.declarations ?? []) {
|
|
1011
|
+
const message = getFlatMapLadderMessage(declaration.init);
|
|
1012
|
+
if (message) report(context, declaration.init, message);
|
|
1013
|
+
}
|
|
1014
|
+
},
|
|
1015
|
+
ReturnStatement(node) {
|
|
1016
|
+
const message = getFlatMapLadderMessage(node.argument);
|
|
1017
|
+
if (message) report(context, node.argument, message);
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
} });
|
|
1021
|
+
const noPipeLadder = defineRule({ create(context) {
|
|
1022
|
+
return { CallExpression(node) {
|
|
1023
|
+
if (isPipeCall(node) && containsPipeCall(node.arguments)) report(context, node, "Rule: avoid nested pipe() chains. Why: they hide sequencing. Fix: refactor into one flat pipeline with a single decision point.");
|
|
1024
|
+
} };
|
|
1025
|
+
} });
|
|
1026
|
+
const noCallTower = defineRule({ create(context) {
|
|
1027
|
+
return { CallExpression(node) {
|
|
1028
|
+
if (hasNestedEffectCallArgument(node)) report(context, node, "Rule: avoid nested Effect call towers (Effect.fn(Effect.fn(...))). Why: it hides sequencing. Fix: build the inner Effect first, then use pipe/Effect.flatMap/Effect.andThen for a single flat pipeline.");
|
|
1029
|
+
} };
|
|
1030
|
+
} });
|
|
1031
|
+
const noEffectOrElseLadder = defineRule({ create(context) {
|
|
1032
|
+
return { CallExpression(node) {
|
|
1033
|
+
if (hasOrElseSequencingFirstArgument(node)) report(context, node, "Rule: avoid Effect.orElse around sequencing chains. Why: it hides error handling and splits the flow. Fix: move error handling to a single terminal decision after the pipeline.");
|
|
1034
|
+
} };
|
|
1035
|
+
} });
|
|
1036
|
+
const rules = {
|
|
1037
|
+
"no-react-state": noReactState,
|
|
1038
|
+
"no-if-statement": noIfStatement,
|
|
1039
|
+
"no-switch-statement": noSwitchStatement,
|
|
1040
|
+
"no-ternary": noTernary,
|
|
1041
|
+
"no-return-null": noReturnNull,
|
|
1042
|
+
"no-option-as": noOptionAs,
|
|
1043
|
+
"no-effect-never": noEffectNever,
|
|
1044
|
+
"no-arrow-ladder": noArrowLadder,
|
|
1045
|
+
"no-branch-in-object": noBranchInObject,
|
|
1046
|
+
"no-iife-wrapper": noIifeWrapper,
|
|
1047
|
+
"no-return-in-arrow": noReturnInArrow,
|
|
1048
|
+
"no-return-in-callback": noReturnInCallback,
|
|
1049
|
+
"no-effect-fn-generator": noEffectFnGenerator,
|
|
1050
|
+
"no-effect-sync-console": noEffectSyncConsole,
|
|
1051
|
+
"no-nested-effect-gen": noNestedEffectGen,
|
|
1052
|
+
"no-match-void-branch": noMatchVoidBranch,
|
|
1053
|
+
"no-match-effect-branch": noMatchEffectBranch,
|
|
1054
|
+
"warn-effect-sync-wrapper": warnEffectSyncWrapper,
|
|
1055
|
+
"no-effect-side-effect-wrapper": noEffectSideEffectWrapper,
|
|
1056
|
+
"no-effect-all-step-sequencing": noEffectAllStepSequencing,
|
|
1057
|
+
"no-try-catch": noTryCatch,
|
|
1058
|
+
"no-effect-wrapper-alias": noEffectWrapperAlias,
|
|
1059
|
+
"no-manual-effect-channels": noManualEffectChannels,
|
|
1060
|
+
"no-wrapgraphql-catchall": noWrapgraphqlCatchall,
|
|
1061
|
+
"no-render-side-effects": noRenderSideEffects,
|
|
1062
|
+
"no-atom-registry-effect-sync": noAtomRegistryEffectSync,
|
|
1063
|
+
"no-family-collection-read": noFamilyCollectionRead,
|
|
1064
|
+
"no-inline-runtime-provide": noInlineRuntimeProvide,
|
|
1065
|
+
"no-naked-object-state-update": noNakedObjectStateUpdate,
|
|
1066
|
+
"no-effect-succeed-variable": noEffectSucceedVariable,
|
|
1067
|
+
"no-effect-type-alias": noEffectTypeAlias,
|
|
1068
|
+
"no-model-overlay-cast": noModelOverlayCast,
|
|
1069
|
+
"no-unknown-boolean-coercion-helper": noUnknownBooleanCoercionHelper,
|
|
1070
|
+
"no-fromnullable-nullish-coalesce": noFromnullableNullishCoalesce,
|
|
1071
|
+
"no-option-boolean-normalization": noOptionBooleanNormalization,
|
|
1072
|
+
"no-string-sentinel-return": noStringSentinelReturn,
|
|
1073
|
+
"no-string-sentinel-const": noStringSentinelConst,
|
|
1074
|
+
"no-effect-as": noEffectAs,
|
|
1075
|
+
"no-effect-do": noEffectDo,
|
|
1076
|
+
"no-effect-bind": noEffectBind,
|
|
1077
|
+
"no-runtime-runfork": noRuntimeRunFork,
|
|
1078
|
+
"no-effect-async": noEffectAsync,
|
|
1079
|
+
"prevent-dynamic-imports": defineRule({ create(context) {
|
|
1080
|
+
return { ImportExpression(node) {
|
|
1081
|
+
report(context, node, "Rule: avoid dynamic imports. Why: runtime module loading obscures dependency boundaries. Fix: use static imports.");
|
|
1082
|
+
} };
|
|
1083
|
+
} }),
|
|
1084
|
+
"no-nested-effect-call": noNestedEffectCall,
|
|
1085
|
+
"no-effect-ladder": noEffectLadder,
|
|
1086
|
+
"no-flatmap-ladder": noFlatMapLadder,
|
|
1087
|
+
"no-pipe-ladder": noPipeLadder,
|
|
1088
|
+
"no-call-tower": noCallTower,
|
|
1089
|
+
"no-effect-orElse-ladder": noEffectOrElseLadder
|
|
1090
|
+
};
|
|
1091
|
+
const allRules = Object.fromEntries(Object.keys(rules).map((ruleName) => [`linteffect/${ruleName}`, "error"]));
|
|
1092
|
+
const recommended = {
|
|
1093
|
+
jsPlugins: [{
|
|
1094
|
+
name: "linteffect",
|
|
1095
|
+
specifier: "@opsydyn/oxlint-effect"
|
|
1096
|
+
}],
|
|
1097
|
+
rules: allRules
|
|
1098
|
+
};
|
|
1099
|
+
var src_default = definePlugin({
|
|
1100
|
+
meta: { name: "linteffect" },
|
|
1101
|
+
rules
|
|
1102
|
+
});
|
|
1103
|
+
//#endregion
|
|
1104
|
+
export { allRules, src_default as default, recommended };
|
|
1105
|
+
|
|
1106
|
+
//# sourceMappingURL=index.mjs.map
|