@ref0/workspace 0.10.0 → 0.12.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 (37) hide show
  1. package/README.md +171 -1
  2. package/dist/bin.mjs +19 -7
  3. package/dist/lint/generic/ast-fields.mjs +32 -0
  4. package/dist/lint/generic/build-cache-inputs.d.mts +9 -0
  5. package/dist/lint/generic/build-cache-inputs.mjs +147 -0
  6. package/dist/lint/generic/effect-gen-wrappers.d.mts +13 -0
  7. package/dist/lint/generic/effect-gen-wrappers.mjs +100 -0
  8. package/dist/lint/generic/folder-imports.mjs +84 -0
  9. package/dist/lint/generic/folder-layers.d.mts +40 -0
  10. package/dist/lint/generic/folder-layers.mjs +82 -0
  11. package/dist/lint/generic/imports.mjs +34 -0
  12. package/dist/lint/generic/package-graph.d.mts +36 -0
  13. package/dist/lint/generic/package-graph.mjs +111 -0
  14. package/dist/lint/generic/package-imports.mjs +85 -0
  15. package/dist/lint/generic/plugin.d.mts +7 -3
  16. package/dist/lint/generic/plugin.mjs +21 -3
  17. package/dist/lint/generic/public-docs.d.mts +12 -0
  18. package/dist/lint/generic/public-docs.mjs +345 -0
  19. package/dist/lint/generic/pure-effect-fn.mjs +107 -0
  20. package/dist/lint/generic/pure-top-level.d.mts +44 -0
  21. package/dist/lint/generic/pure-top-level.mjs +393 -0
  22. package/dist/lint/generic/rule-options.mjs +17 -0
  23. package/dist/lint/generic/workspace-packages.d.mts +58 -0
  24. package/dist/lint/generic/workspace-packages.mjs +119 -0
  25. package/dist/lint/graph.d.mts +8 -0
  26. package/dist/lint/graph.mjs +3 -0
  27. package/dist/review-record/command.mjs +107 -0
  28. package/dist/review-record/index.d.mts +3 -0
  29. package/dist/review-record/index.mjs +3 -0
  30. package/dist/review-record/review-record.d.mts +33 -0
  31. package/dist/review-record/review-record.mjs +1256 -0
  32. package/dist/review-record/settings.d.mts +40 -0
  33. package/dist/review-record/settings.mjs +103 -0
  34. package/dist/symbols/symbols.mjs +1 -1
  35. package/dist/task-sources.d.mts +16 -0
  36. package/dist/task-sources.mjs +121 -0
  37. package/package.json +13 -1
@@ -0,0 +1,345 @@
1
+ import { decodedOnce } from "./rule-options.mjs";
2
+ import { entryFile, publishedEntries, workspacePackages } from "./workspace-packages.mjs";
3
+ import { readFileSync, statSync } from "node:fs";
4
+ import { dirname, join, resolve } from "node:path";
5
+ import { Schema } from "effect";
6
+ import { defineRule } from "vite-plus/lint/plugins";
7
+ import { parseSync } from "vite-plus";
8
+ // src/lint/generic/public-docs.ts
9
+ const decodeOptions = Schema.decodeUnknownSync(Schema.Tuple([Schema.Struct({
10
+ root: Schema.String,
11
+ packages: Schema.Array(Schema.String),
12
+ apps: Schema.optionalKey(Schema.Array(Schema.String)),
13
+ condition: Schema.String,
14
+ entries: Schema.optionalKey(Schema.Array(Schema.String))
15
+ })]));
16
+ const optionsOf = decodedOnce((options) => decodeOptions(options)[0]);
17
+ /** The file a relative import names, as TypeScript resolves it: as written, as `.ts`, or a folder's index. */
18
+ const fileAt = (from, source) => {
19
+ const path = resolve(dirname(from), source.replace(/\?.*$/, ""));
20
+ return [
21
+ path,
22
+ path.replace(/\.js(x?)$/, ".ts$1"),
23
+ `${path}.ts`,
24
+ `${path}.tsx`,
25
+ join(path, "index.ts"),
26
+ join(path, "index.tsx")
27
+ ].find((candidate) => statSync(candidate, { throwIfNoEntry: false })?.isFile() === true);
28
+ };
29
+ /** The name a module export spells, as an identifier or a string. */
30
+ const spelled = (node) => node.type === "Identifier" ? node.name ?? "" : String(node.value);
31
+ /** The names a declaration binds at the top of its module. */
32
+ const declaredNames = (node) => {
33
+ switch (node.type) {
34
+ case "VariableDeclaration": return node.declarations.flatMap((declarator) => declarator.id.type === "Identifier" ? [declarator.id.name] : []);
35
+ case "FunctionDeclaration":
36
+ case "ClassDeclaration":
37
+ case "TSDeclareFunction":
38
+ case "TSTypeAliasDeclaration":
39
+ case "TSInterfaceDeclaration":
40
+ case "TSEnumDeclaration": return node.id === null ? [] : [node.id.name];
41
+ case "TSModuleDeclaration": return node.id.type === "Identifier" ? [node.id.name] : [];
42
+ default: return [];
43
+ }
44
+ };
45
+ const exportsOf = (path) => {
46
+ const { program } = parseSync(path, readFileSync(path, "utf8"));
47
+ const imported = /* @__PURE__ */ new Map();
48
+ const named = /* @__PURE__ */ new Map();
49
+ const all = [];
50
+ for (const node of program.body) if (node.type === "ImportDeclaration") for (const specifier of node.specifiers ?? []) {
51
+ if (specifier.type !== "ImportSpecifier") continue;
52
+ imported.set(specifier.local.name, {
53
+ kind: "import",
54
+ source: node.source.value,
55
+ name: spelled(specifier.imported)
56
+ });
57
+ }
58
+ else if (node.type === "ExportNamedDeclaration") {
59
+ for (const name of node.declaration === null ? [] : declaredNames(node.declaration)) named.set(name, {
60
+ kind: "local",
61
+ name
62
+ });
63
+ for (const specifier of node.specifiers) {
64
+ const local = spelled(specifier.local);
65
+ const origin = node.source === null ? imported.get(local) ?? {
66
+ kind: "local",
67
+ name: local
68
+ } : {
69
+ kind: "import",
70
+ source: node.source.value,
71
+ name: local
72
+ };
73
+ named.set(spelled(specifier.exported), origin);
74
+ }
75
+ } else if (node.type === "ExportAllDeclaration" && node.exported === null) all.push(node.source.value);
76
+ return {
77
+ named,
78
+ all
79
+ };
80
+ };
81
+ /** The file a module specifier names, from `from`: a relative path or a workspace package's entry. */
82
+ const moduleAt = ({ root, packages, condition }, from, source) => {
83
+ if (source.startsWith(".")) return fileAt(from, source);
84
+ const parts = source.split("/");
85
+ const named = source.startsWith("@") ? 2 : 1;
86
+ const workspacePackage = packages.get(parts.slice(0, named).join("/"));
87
+ const path = workspacePackage === void 0 ? void 0 : entryFile(workspacePackage, [".", ...parts.slice(named)].join("/"), condition);
88
+ return workspacePackage === void 0 || path === void 0 ? void 0 : join(root, workspacePackage.directory, path);
89
+ };
90
+ /**
91
+ * Each declaration a published entry point's exports reach, by file, through re-exports and
92
+ * imports, across relative paths and workspace packages. A name exported from a package outside
93
+ * the workspace is that package's to document.
94
+ */
95
+ const publicDeclarationsOf = (reading, entries) => {
96
+ const found = /* @__PURE__ */ new Map();
97
+ const read = /* @__PURE__ */ new Map();
98
+ const seen = /* @__PURE__ */ new Set();
99
+ const exportsAt = (path) => {
100
+ const kept = read.get(path) ?? exportsOf(path);
101
+ read.set(path, kept);
102
+ return kept;
103
+ };
104
+ const follow = (entry, path, name) => {
105
+ if (seen.has(`${path}\0${name}`)) return;
106
+ seen.add(`${path}\0${name}`);
107
+ const { named, all } = exportsAt(path);
108
+ const origin = named.get(name);
109
+ if (origin?.kind === "local") {
110
+ const names = found.get(path) ?? /* @__PURE__ */ new Map();
111
+ if (!names.has(origin.name)) names.set(origin.name, entry);
112
+ found.set(path, names);
113
+ } else if (origin?.kind === "import") {
114
+ const next = moduleAt(reading, path, origin.source);
115
+ if (next !== void 0) follow(entry, next, origin.name);
116
+ } else for (const next of all.flatMap((source) => moduleAt(reading, path, source) ?? [])) follow(entry, next, name);
117
+ };
118
+ /** Every name the module at `path` exports, through each `export *` too. */
119
+ const namesAt = (path, through) => {
120
+ if (through.has(path)) return [];
121
+ const { named, all } = exportsAt(path);
122
+ const starred = all.flatMap((source) => {
123
+ const next = moduleAt(reading, path, source);
124
+ return next === void 0 ? [] : namesAt(next, /* @__PURE__ */ new Set([...through, path]));
125
+ });
126
+ return [...named.keys(), ...starred.filter((name) => name !== "default")];
127
+ };
128
+ for (const entry of entries) {
129
+ const path = join(reading.root, entry);
130
+ for (const name of namesAt(path, /* @__PURE__ */ new Set())) follow(entry, path, name);
131
+ }
132
+ return {
133
+ found,
134
+ read: new Map([...read.keys()].map((path) => [path, modifiedAt(path)]))
135
+ };
136
+ };
137
+ const modifiedAt = (path) => statSync(path, { throwIfNoEntry: false })?.mtimeMs;
138
+ /** Each entry list's public declarations, with each file's modified time when it was read. */
139
+ const kept = /* @__PURE__ */ new Map();
140
+ /** The public declarations, read again only when a file they were read from has changed. */
141
+ const currentPublicDeclarationsOf = (reading, entries) => {
142
+ const key = [
143
+ reading.root,
144
+ reading.condition,
145
+ ...entries
146
+ ].join("\0");
147
+ const last = kept.get(key);
148
+ if (last !== void 0 && [...last.read].every(([path, at]) => modifiedAt(path) === at)) return last.found;
149
+ const next = publicDeclarationsOf(reading, entries);
150
+ kept.set(key, next);
151
+ return next.found;
152
+ };
153
+ /** The `Schema` constructors whose first argument after its tag holds a schema's fields. */
154
+ const fieldTaking = /* @__PURE__ */ new Set([
155
+ "Class",
156
+ "ErrorClass",
157
+ "Opaque",
158
+ "Struct",
159
+ "TaggedClass",
160
+ "TaggedError",
161
+ "TaggedErrorClass",
162
+ "TaggedStruct"
163
+ ]);
164
+ /**
165
+ * The `Schema` constructor a call's callee names, as `Struct` in `Schema.Struct` and `Class` in
166
+ * `Schema.Class<A>('A')`, which takes the fields in a second call.
167
+ */
168
+ const schemaConstructor = (node) => {
169
+ switch (node.type) {
170
+ case "MemberExpression": return node.object.type === "Identifier" && node.object.name === "Schema" && node.property.type === "Identifier" ? node.property.name : void 0;
171
+ case "CallExpression": return schemaConstructor(node.callee);
172
+ case "TSInstantiationExpression": return schemaConstructor(node.expression);
173
+ default: return;
174
+ }
175
+ };
176
+ /**
177
+ * The fields of each `Schema` call an exported value or class is built from, as a `Struct`'s or a
178
+ * `Class`'s, nested ones too, but not its annotations. It doesn't look inside functions.
179
+ */
180
+ const schemaFieldsIn = (node) => {
181
+ if (node === null || node === void 0) return [];
182
+ switch (node.type) {
183
+ case "CallExpression": {
184
+ const constructor = schemaConstructor(node.callee);
185
+ const object = node.arguments.find((argument) => argument.type !== "Literal");
186
+ return [
187
+ ...constructor !== void 0 && fieldTaking.has(constructor) && object?.type === "ObjectExpression" ? object.properties.filter((property) => property.type === "Property") : [],
188
+ ...schemaFieldsIn(node.callee),
189
+ ...node.arguments.flatMap((argument) => schemaFieldsIn(argument))
190
+ ];
191
+ }
192
+ case "ObjectExpression": return node.properties.flatMap((property) => property.type === "Property" ? schemaFieldsIn(property.value) : []);
193
+ case "ArrayExpression": return node.elements.flatMap((element) => element === null || element.type === "SpreadElement" ? [] : schemaFieldsIn(element));
194
+ case "MemberExpression": return schemaFieldsIn(node.object);
195
+ case "TSInstantiationExpression": return schemaFieldsIn(node.expression);
196
+ case "TSAsExpression":
197
+ case "TSSatisfiesExpression": return schemaFieldsIn(node.expression);
198
+ default: return [];
199
+ }
200
+ };
201
+ /**
202
+ * The members of a type: an object type's, with the members of each object type inside them, and
203
+ * those of each object type it joins, lists or passes as a type argument.
204
+ */
205
+ const typeMembers = (node) => {
206
+ if (node === null || node === void 0) return [];
207
+ switch (node.type) {
208
+ case "TSTypeLiteral": return node.members.flatMap(withNested);
209
+ case "TSUnionType":
210
+ case "TSIntersectionType": return node.types.flatMap(typeMembers);
211
+ case "TSArrayType": return typeMembers(node.elementType);
212
+ case "TSTypeOperator": return typeMembers(node.typeAnnotation);
213
+ case "TSTypeReference": return node.typeArguments?.params.flatMap(typeMembers) ?? [];
214
+ case "TSTupleType": return node.elementTypes.flatMap(typeMembers);
215
+ case "TSNamedTupleMember": return typeMembers(node.elementType);
216
+ case "TSOptionalType":
217
+ case "TSRestType": return typeMembers(node.typeAnnotation);
218
+ case "TSFunctionType":
219
+ case "TSConstructorType": return signatureMembers(node);
220
+ default: return [];
221
+ }
222
+ };
223
+ /** The members of the object types a function type or signature takes and returns. */
224
+ const signatureMembers = (node) => [...node.params.flatMap((param) => {
225
+ const annotation = "typeAnnotation" in param ? param.typeAnnotation : void 0;
226
+ if (annotation === null || annotation === void 0) return [];
227
+ return typeMembers(annotation.type === "TSTypeAnnotation" ? annotation.typeAnnotation : annotation);
228
+ }), ...typeMembers(node.returnType?.typeAnnotation)];
229
+ /** A member, with the members of each object type inside its own type or its signature. */
230
+ const withNested = (member) => {
231
+ if (member.type === "TSMethodSignature" || member.type === "TSCallSignatureDeclaration") return [member, ...signatureMembers(member)];
232
+ return (member.type === "TSPropertySignature" || member.type === "PropertyDefinition") && member.typeAnnotation !== null && member.typeAnnotation !== void 0 ? [member, ...typeMembers(member.typeAnnotation.typeAnnotation)] : [member];
233
+ };
234
+ /** A class's members a caller sees: not private, not its constructor and not its static blocks. */
235
+ const classMembers = (node) => node.body.body.filter((member) => (member.type === "PropertyDefinition" || member.type === "MethodDefinition" && member.kind !== "constructor") && member.accessibility !== "private" && member.key.type !== "PrivateIdentifier");
236
+ /** The members of a public declaration that each need their own doc comment. */
237
+ const membersOf = (node) => {
238
+ switch (node.type) {
239
+ case "TSInterfaceDeclaration": return node.body.body.flatMap(withNested);
240
+ case "TSTypeAliasDeclaration": return typeMembers(node.typeAnnotation);
241
+ case "ClassDeclaration": return [...classMembers(node).flatMap(withNested), ...schemaFieldsIn(node.superClass)];
242
+ case "VariableDeclaration": return node.declarations.flatMap((declarator) => schemaFieldsIn(declarator.init));
243
+ case "TSEnumDeclaration": return node.body.members;
244
+ default: return [];
245
+ }
246
+ };
247
+ /** A member's name as its source spells it, for the message. */
248
+ const memberName = (node) => {
249
+ const key = "key" in node ? node.key : "id" in node ? node.id : void 0;
250
+ return key !== void 0 && key !== null && key.type === "Identifier" ? key.name : "member";
251
+ };
252
+ /** What a member's overloads share: its name, in the type or object that holds it. */
253
+ const overloadKey = (node) => `${node.parent?.start ?? -1}:${memberName(node)}`;
254
+ /**
255
+ * A published package's types, functions and fields are what its users and their agents read, on
256
+ * hover and in its declaration files, often with no source beside them. So each declaration a
257
+ * published entry point exports, and each field and member of it, carries a doc comment, across
258
+ * re-exports from the workspace's other packages too.
259
+ */
260
+ const publicDocsRule = defineRule({
261
+ meta: {
262
+ messages: {
263
+ undocumented: "`{{name}}` is published from {{entry}}: give one of its declarations a doc comment that says what it is for, for the people and agents who read it on hover.",
264
+ undocumentedMember: "`{{owner}}`'s `{{name}}` is published from {{entry}}: give it a doc comment that says what it holds and when it's set."
265
+ },
266
+ schema: [{
267
+ type: "object",
268
+ properties: {
269
+ root: { type: "string" },
270
+ packages: {
271
+ type: "array",
272
+ items: { type: "string" }
273
+ },
274
+ apps: {
275
+ type: "array",
276
+ items: { type: "string" }
277
+ },
278
+ condition: { type: "string" },
279
+ entries: {
280
+ type: "array",
281
+ items: { type: "string" }
282
+ }
283
+ },
284
+ required: [
285
+ "root",
286
+ "packages",
287
+ "condition"
288
+ ],
289
+ additionalProperties: false
290
+ }]
291
+ },
292
+ create(context) {
293
+ const options = optionsOf(context.options);
294
+ const packages = workspacePackages(options);
295
+ const reading = {
296
+ root: options.root,
297
+ packages,
298
+ condition: options.condition
299
+ };
300
+ const entries = options.entries ?? publishedEntries(packages, options.condition);
301
+ const names = currentPublicDeclarationsOf(reading, entries).get(resolve(context.filename));
302
+ if (names === void 0) return {};
303
+ const hasDoc = (node) => context.sourceCode.getCommentsBefore(node).some((comment) => comment.type === "Block" && comment.value.startsWith("*"));
304
+ /** Each published name's declarations, as the statements that hold them. */
305
+ const declarations = /* @__PURE__ */ new Map();
306
+ const checkMembers = (owner, declaration) => {
307
+ const members = membersOf(declaration);
308
+ const documented = new Set(members.filter(hasDoc).map(overloadKey));
309
+ for (const member of members) {
310
+ if (documented.has(overloadKey(member))) continue;
311
+ context.report({
312
+ node: member,
313
+ messageId: "undocumentedMember",
314
+ data: {
315
+ owner,
316
+ name: memberName(member),
317
+ entry: names.get(owner) ?? ""
318
+ }
319
+ });
320
+ }
321
+ };
322
+ const visit = (statement, declaration) => {
323
+ const [owner] = declaredNames(declaration).filter((name) => names.has(name));
324
+ if (owner === void 0) return;
325
+ declarations.set(owner, [...declarations.get(owner) ?? [], statement]);
326
+ checkMembers(owner, declaration);
327
+ };
328
+ return { Program(program) {
329
+ for (const statement of program.body) if (statement.type === "ExportNamedDeclaration" && statement.declaration !== null) visit(statement, statement.declaration);
330
+ else visit(statement, statement);
331
+ for (const [name, [first, ...rest]] of declarations) {
332
+ if (first === void 0 || [first, ...rest].some(hasDoc)) continue;
333
+ context.report({
334
+ node: first,
335
+ messageId: "undocumented",
336
+ data: {
337
+ name,
338
+ entry: names.get(name) ?? ""
339
+ }
340
+ });
341
+ }
342
+ } };
343
+ }
344
+ });
345
+ export { declaredNames, publicDocsRule };
@@ -0,0 +1,107 @@
1
+ import { Predicate } from "effect";
2
+ import { defineRule } from "vite-plus/lint/plugins";
3
+ // src/lint/generic/pure-effect-fn.ts
4
+ /** Block comment body bundlers treat as a pure-call annotation (`@__PURE__` or `#__PURE__`). */
5
+ const pureAnnotation = /^\s*[@#]__PURE__\s*$/;
6
+ /** Whether `value` is a non-array AST node object. */
7
+ const isAstNode = (value) => Predicate.isObjectOrArray(value) && !Array.isArray(value);
8
+ /** Whether `value` is a list of AST nodes. */
9
+ const isAstList = (value) => Array.isArray(value);
10
+ /** Collects `effect/Effect` namespace and direct `fn`/`fnUntraced` bindings from a program body. */
11
+ const collectEffectFnBindings = (body) => {
12
+ const namespaces = /* @__PURE__ */ new Set();
13
+ const direct = /* @__PURE__ */ new Set();
14
+ for (const statement of body) {
15
+ if (!isAstNode(statement) || statement.type !== "ImportDeclaration") continue;
16
+ const source = statement.source;
17
+ const from = isAstNode(source) && Predicate.isString(source.value) ? source.value : void 0;
18
+ if (from !== "effect/Effect" && from !== "effect") continue;
19
+ if (!isAstList(statement.specifiers)) continue;
20
+ for (const specifier of statement.specifiers) {
21
+ if (!isAstNode(specifier)) continue;
22
+ const local = isAstNode(specifier.local) && Predicate.isString(specifier.local.name) ? specifier.local.name : void 0;
23
+ if (local === void 0) continue;
24
+ if (specifier.type === "ImportNamespaceSpecifier") {
25
+ if (from === "effect/Effect") namespaces.add(local);
26
+ } else if (specifier.type === "ImportSpecifier") {
27
+ const imported = isAstNode(specifier.imported) && Predicate.isString(specifier.imported.name) ? specifier.imported.name : void 0;
28
+ if (from === "effect" && imported === "Effect") namespaces.add(local);
29
+ else if (from === "effect/Effect" && (imported === "fn" || imported === "fnUntraced")) direct.add(local);
30
+ }
31
+ }
32
+ }
33
+ return {
34
+ namespaces,
35
+ direct
36
+ };
37
+ };
38
+ /** Whether `callee` names `Effect.fn` / `Effect.fnUntraced` or a direct import of either. */
39
+ const isEffectFnCallee = (callee, bindings) => {
40
+ if (!isAstNode(callee)) return false;
41
+ if (callee.type === "Identifier" && Predicate.isString(callee.name)) return bindings.direct.has(callee.name);
42
+ if (callee.type !== "MemberExpression" || callee.computed === true) return false;
43
+ const object = callee.object;
44
+ const property = callee.property;
45
+ if (!isAstNode(object) || !isAstNode(property)) return false;
46
+ return object.type === "Identifier" && Predicate.isString(object.name) && bindings.namespaces.has(object.name) && property.type === "Identifier" && (property.name === "fn" || property.name === "fnUntraced");
47
+ };
48
+ /**
49
+ * Whether `node` is an outermost `Effect.fn(...)`, `Effect.fn(...)(...)`, or `Effect.fnUntraced(...)`
50
+ * call. The inner call of a curried `Effect.fn('name')(fn)` is skipped because its parent call
51
+ * covers both at the same start offset.
52
+ */
53
+ const isOutermostEffectFnCall = (node, parent, bindings) => {
54
+ if (!isAstNode(node) || node.type !== "CallExpression") return false;
55
+ if (isEffectFnCallee(node.callee, bindings)) return !(isAstNode(parent) && parent.type === "CallExpression" && parent.callee === node);
56
+ return isAstNode(node.callee) && node.callee.type === "CallExpression" && isEffectFnCallee(node.callee.callee, bindings);
57
+ };
58
+ /**
59
+ * Every top-level `Effect.fn` and `Effect.fnUntraced` call in the files a repo turns this on for,
60
+ * its packages' published sources, must carry a bundler pure annotation (`/* @__PURE__ *\/` or
61
+ * `/*#__PURE__*\/`, with or without spaces) so bundlers can drop uncalled functions.
62
+ */
63
+ const pureEffectFnRule = defineRule({
64
+ meta: { messages: { missingPure: "Mark top-level Effect.fn / Effect.fnUntraced with /* @__PURE__ */ so bundlers can tree-shake it when unused." } },
65
+ create(context) {
66
+ let bindings = {
67
+ namespaces: /* @__PURE__ */ new Set(),
68
+ direct: /* @__PURE__ */ new Set()
69
+ };
70
+ let deferredDepth = 0;
71
+ const enterDeferred = () => {
72
+ deferredDepth += 1;
73
+ };
74
+ const exitDeferred = () => {
75
+ deferredDepth -= 1;
76
+ };
77
+ return {
78
+ Program(program) {
79
+ bindings = collectEffectFnBindings(program.body);
80
+ },
81
+ FunctionDeclaration: enterDeferred,
82
+ "FunctionDeclaration:exit": exitDeferred,
83
+ FunctionExpression: enterDeferred,
84
+ "FunctionExpression:exit": exitDeferred,
85
+ ArrowFunctionExpression: enterDeferred,
86
+ "ArrowFunctionExpression:exit": exitDeferred,
87
+ MethodDefinition: enterDeferred,
88
+ "MethodDefinition:exit": exitDeferred,
89
+ PropertyDefinition(node) {
90
+ if (!node.static) enterDeferred();
91
+ },
92
+ "PropertyDefinition:exit"(node) {
93
+ if (!node.static) exitDeferred();
94
+ },
95
+ CallExpression(node) {
96
+ if (deferredDepth > 0) return;
97
+ const callNode = node;
98
+ if (!isOutermostEffectFnCall(callNode, callNode.parent, bindings)) return;
99
+ if (!context.sourceCode.getCommentsBefore(node).some((comment) => comment.type === "Block" && pureAnnotation.test(comment.value))) context.report({
100
+ node,
101
+ messageId: "missingPure"
102
+ });
103
+ }
104
+ };
105
+ }
106
+ });
107
+ export { collectEffectFnBindings, isAstList, isAstNode, isEffectFnCallee, isOutermostEffectFnCall, pureAnnotation, pureEffectFnRule };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * A callee a `/* @__PURE__ *\/` mark may cover at a package's top level. A mark tells a bundler
3
+ * that dropping the call, when nothing reads its result, changes nothing, and no test can see a
4
+ * wrong one: tests run source unbundled, where the mark is a comment. So a repo lists each callee
5
+ * whose call only builds and returns a value, with the reason.
6
+ */
7
+ export interface PureCallee {
8
+ /**
9
+ * Where the callee's name is bound: an import's specifier, such as `effect/Schema`, a source
10
+ * file's path from the root, for a relative import or the file's own top-level name, that path
11
+ * with `#parameters` for a parameter of a function a callee runs, or `globalThis`. An array
12
+ * literal's methods are `globalThis`'s `[].<method>`.
13
+ */
14
+ readonly from: string;
15
+ /**
16
+ * Its name there, with `.` between members, or `*` for any name the module exports, and that
17
+ * name's members only where `chain` lists them, such as `String.check`.
18
+ */
19
+ readonly name: string;
20
+ /**
21
+ * The methods a mark may chain on the call's result, such as a schema's `annotate`. Each runs
22
+ * the functions passed to it, as `runsArguments` reads them, since `pipe` does.
23
+ */
24
+ readonly chain?: ReadonlyArray<string>;
25
+ /** Its call returns a function whose call only builds a value too, such as `Context.Service<Self, Shape>()(key)`. */
26
+ readonly curried?: true;
27
+ /**
28
+ * It calls the functions passed to it, or iterates what it's passed, before it returns, so the
29
+ * mark covers their code too: an arrow's expression is read, and a name, whose code isn't seen,
30
+ * is refused.
31
+ */
32
+ readonly runsArguments?: true;
33
+ /** Why calling it only builds a value: no write outside its result, no I/O, no throw a caller needs. */
34
+ readonly why: string;
35
+ }
36
+ /**
37
+ * What `ref0-generic/pure-top-level` takes: the repo's root, as an absolute path, the callees a
38
+ * mark may cover, and `requireMarks`, which asks each top-level call the list covers for a mark.
39
+ */
40
+ export interface PureTopLevelOptions {
41
+ readonly root: string;
42
+ readonly callees: ReadonlyArray<PureCallee>;
43
+ readonly requireMarks?: boolean;
44
+ }