@collective-intelligence/lint 0.1.26 → 0.1.27
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 +74 -8
- package/dist/index.js +273 -44
- package/dist/rule.d.ts +4 -2
- package/dist/rules/effect-actors/effect-actors.d.ts +2 -0
- package/dist/rules/effect-subpath/effect-subpath.d.ts +2 -0
- package/dist/rules/index.d.ts +3 -0
- package/dist/rules/no-run-in-view/no-run-in-view.d.ts +2 -0
- package/package.json +2 -2
- package/skills/ci-solution-structure/references/enforcement.md +18 -14
package/README.md
CHANGED
|
@@ -73,12 +73,15 @@ the `collective-intelligence` pack installs the skill and adds the plugin with
|
|
|
73
73
|
|
|
74
74
|
## Rules
|
|
75
75
|
|
|
76
|
-
| Rule | Enforces
|
|
77
|
-
| -------------------------------- |
|
|
78
|
-
| `ci-solution/package-entrypoint` | An import of another package targets an entrypoint declared in its `package.json` exports.
|
|
79
|
-
| `ci-solution/subpath-imports` | Imports between subpath folders follow the allowed direction.
|
|
80
|
-
| `ci-solution/subpath-entrypoint` | An import from another subpath folder targets the folder or its index file.
|
|
81
|
-
| `ci-solution/subpath-index` | Every subpath folder has an `index.ts` or `index.tsx`.
|
|
76
|
+
| Rule | Enforces | Group |
|
|
77
|
+
| -------------------------------- | -------------------------------------------------------------------------------------------- | ------------------ |
|
|
78
|
+
| `ci-solution/package-entrypoint` | An import of another package targets an entrypoint declared in its `package.json` exports. | Package boundaries |
|
|
79
|
+
| `ci-solution/subpath-imports` | Imports between subpath folders follow the allowed direction. | Solution layout |
|
|
80
|
+
| `ci-solution/subpath-entrypoint` | An import from another subpath folder targets the folder or its index file. | Solution layout |
|
|
81
|
+
| `ci-solution/subpath-index` | Every subpath folder has an `index.ts` or `index.tsx`. | Solution layout |
|
|
82
|
+
| `ci-solution/effect-subpath` | An SDK Effect API comes from the SDK's `/effect` subpath; deprecated SDK paths are reported. | Effect convention |
|
|
83
|
+
| `ci-solution/no-run-in-view` | A view module calls no `fetch` and runs no Effect. | Effect convention |
|
|
84
|
+
| `ci-solution/effect-actors` | XState side-effect actors are `fromEffect` actors. | Effect convention |
|
|
82
85
|
|
|
83
86
|
### Package boundaries
|
|
84
87
|
|
|
@@ -150,6 +153,67 @@ import { rate } from "../domain/rates" // reported
|
|
|
150
153
|
Every subpath folder under `src/` has an `index.ts` or `index.tsx` entrypoint.
|
|
151
154
|
The rule reports each file in a folder that has neither.
|
|
152
155
|
|
|
156
|
+
### Effect convention
|
|
157
|
+
|
|
158
|
+
An app keeps its side effects in XState machines: each side effect is a
|
|
159
|
+
`fromEffect` actor, and views read data through TanStack Query. These rules
|
|
160
|
+
check the parts of that convention that imports and calls show.
|
|
161
|
+
|
|
162
|
+
#### `effect-subpath`
|
|
163
|
+
|
|
164
|
+
A Collective Intelligence SDK (`@collective-intelligence/*`) exposes its Effect
|
|
165
|
+
API at `<sdk>/effect` and `<sdk>/effect/<adapter>`. The rule reports an SDK path
|
|
166
|
+
that names Effect elsewhere: a `<sdk>-effect` package, or an `effect` segment
|
|
167
|
+
below another subpath. It also reports each deprecated SDK path with its
|
|
168
|
+
replacement:
|
|
169
|
+
|
|
170
|
+
| Deprecated path | Replacement |
|
|
171
|
+
| ------------------------------------------------------------------------------ | ---------------------------------------------------------- |
|
|
172
|
+
| `@collective-intelligence/external-apps-server-sdk/runtime/effect` | `@collective-intelligence/external-apps-server-sdk/effect` |
|
|
173
|
+
| `@collective-intelligence/external-apps-server-sdk/persistence/drizzle/effect` | `@collective-intelligence/external-apps-server-sdk/effect` |
|
|
174
|
+
| `@collective-intelligence/external-apps-server-sdk/runtime/next` | `@collective-intelligence/external-apps-server-sdk/next` |
|
|
175
|
+
| `@collective-intelligence/extensions-sdk-backend-effect` | `@collective-intelligence/extensions-sdk-backend/effect` |
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
import { CiClient } from "@collective-intelligence/external-apps-client-sdk/effect" // valid
|
|
179
|
+
import { createClient } from "@collective-intelligence/external-apps-client-sdk" // valid
|
|
180
|
+
import { Realtime } from "@collective-intelligence/external-apps-client-sdk/realtime/effect" // reported
|
|
181
|
+
import { CiRuntime } from "@collective-intelligence/external-apps-server-sdk/runtime/effect" // reported: deprecated
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### `no-run-in-view`
|
|
185
|
+
|
|
186
|
+
A view module is a `.tsx` or `.jsx` file, or a file in the `views/` subpath of a
|
|
187
|
+
solution package. The rule reports a call of the global `fetch` (also
|
|
188
|
+
`globalThis.fetch` and `window.fetch`) and each use of an Effect run function
|
|
189
|
+
(`runPromise`, `runSync`, `runFork` and the other `run*` functions of `Effect`
|
|
190
|
+
and `ManagedRuntime`):
|
|
191
|
+
|
|
192
|
+
- a read from any object, called or passed as a value: `Effect.runPromise(x)`,
|
|
193
|
+
`runtime.runSync(x)`, `x.pipe(Effect.runPromise)`;
|
|
194
|
+
- a key in a destructuring pattern: `const { runFork } = runtime`;
|
|
195
|
+
- a named import from `effect`, `effect/*` or `@effect/*`:
|
|
196
|
+
`import { runPromise } from "effect/Effect"`.
|
|
197
|
+
|
|
198
|
+
A constant name in brackets or quotes counts too: `window["fetch"](url)`,
|
|
199
|
+
``Effect[`runSync`](x)`` and `const { "runFork": fork } = runtime` are reported.
|
|
200
|
+
A local binding named `fetch`, `globalThis` or `window`, a method such as
|
|
201
|
+
`cache.fetch`, a name in brackets that only runtime gives (`Effect[key]`) and an
|
|
202
|
+
object literal key such as `{ runPromise: run }` are not reported. To allow the
|
|
203
|
+
calls in view tests, turn the rule off for the test files in an `overrides`
|
|
204
|
+
entry.
|
|
205
|
+
|
|
206
|
+
#### `effect-actors`
|
|
207
|
+
|
|
208
|
+
The rule reports each `fromPromise`, `fromCallback`, `fromObservable` and
|
|
209
|
+
`fromEventObservable` that an import, a re-export or a namespace import
|
|
210
|
+
(`XState.fromPromise`, `XState["fromPromise"]`) takes from `xstate` or
|
|
211
|
+
`xstate/*`. Make side-effect actors with `fromEffect` from
|
|
212
|
+
`@collective-intelligence/external-apps-client-sdk-react/effect`. Machines and
|
|
213
|
+
`fromTransition` actors have no side effects and are not reported. A local name
|
|
214
|
+
that shadows the namespace import, such as a parameter named `XState`, is not
|
|
215
|
+
reported.
|
|
216
|
+
|
|
153
217
|
## Adding a rule
|
|
154
218
|
|
|
155
219
|
Each rule is a plain Oxlint rule in its own folder, `src/rules/<rule>/`:
|
|
@@ -159,8 +223,10 @@ Each rule is a plain Oxlint rule in its own folder, `src/rules/<rule>/`:
|
|
|
159
223
|
- `group`: the rule group in the table above (add a group to `RuleGroup`
|
|
160
224
|
when no group fits);
|
|
161
225
|
- `rule`: the rule from `defineRule` of `@oxlint/plugins`, with a
|
|
162
|
-
`messages` entry in `meta` for each finding. `
|
|
163
|
-
|
|
226
|
+
`messages` entry in `meta` for each finding. `src/rule.ts` holds the
|
|
227
|
+
shared helpers: `moduleSpecifiers` builds a visitor that checks every
|
|
228
|
+
module specifier, `staticPropertyName` reads a constant property name, and
|
|
229
|
+
`declaredVariable` finds the variable that a name refers to.
|
|
164
230
|
|
|
165
231
|
A rule reads the workspace through `src/workspace/`: `packageOf` and
|
|
166
232
|
`installedPackage` find package manifests, `declaresEntrypoint` checks
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { definePlugin } from "@oxlint/plugins";
|
|
3
3
|
|
|
4
|
-
// src/rules/
|
|
4
|
+
// src/rules/effect-actors/effect-actors.ts
|
|
5
5
|
import { defineRule } from "@oxlint/plugins";
|
|
6
|
-
import path2 from "node:path";
|
|
7
6
|
|
|
8
7
|
// src/rule.ts
|
|
9
8
|
var isStringLiteral = (node) => node?.type === "Literal" && String(node.value) === node.value;
|
|
9
|
+
var staticPropertyName = (key, computed) => {
|
|
10
|
+
if (key.type === "Identifier") {
|
|
11
|
+
return computed ? null : key.name;
|
|
12
|
+
}
|
|
13
|
+
if (isStringLiteral(key)) {
|
|
14
|
+
return key.value;
|
|
15
|
+
}
|
|
16
|
+
if (key.type === "TemplateLiteral" && key.expressions.length === 0) {
|
|
17
|
+
return key.quasis[0]?.value.cooked ?? null;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
};
|
|
21
|
+
var declaredVariable = (sourceCode, node) => {
|
|
22
|
+
for (let scope = sourceCode.getScope(node);scope !== null; scope = scope.upper) {
|
|
23
|
+
const variable = scope.set.get(node.name);
|
|
24
|
+
if (variable !== undefined && variable.defs.length > 0) {
|
|
25
|
+
return variable;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
10
30
|
var moduleSpecifiers = (check) => {
|
|
11
31
|
const visit = (node) => {
|
|
12
32
|
if (isStringLiteral(node)) {
|
|
@@ -34,6 +54,69 @@ var moduleSpecifiers = (check) => {
|
|
|
34
54
|
};
|
|
35
55
|
};
|
|
36
56
|
|
|
57
|
+
// src/rules/effect-actors/effect-actors.ts
|
|
58
|
+
var SIDE_EFFECT_ACTORS = new Set([
|
|
59
|
+
"fromCallback",
|
|
60
|
+
"fromEventObservable",
|
|
61
|
+
"fromObservable",
|
|
62
|
+
"fromPromise"
|
|
63
|
+
]);
|
|
64
|
+
var messages = {
|
|
65
|
+
sideEffectActor: "`{{name}}` makes XState actor logic outside Effect. Make the actor with `fromEffect` from `@collective-intelligence/external-apps-client-sdk-react/effect`."
|
|
66
|
+
};
|
|
67
|
+
var isXState = (source) => source === "xstate" || source.startsWith("xstate/");
|
|
68
|
+
var nameOf = (node) => node.type === "Literal" ? node.value : node.name;
|
|
69
|
+
var isXStateNamespace = (variable) => variable !== null && variable.defs.some(({ node }) => node.type === "ImportNamespaceSpecifier" && node.parent.type === "ImportDeclaration" && isXState(node.parent.source.value));
|
|
70
|
+
var effectActors = {
|
|
71
|
+
group: "effect-convention",
|
|
72
|
+
rule: defineRule({
|
|
73
|
+
create(context) {
|
|
74
|
+
const check = (node, name) => {
|
|
75
|
+
if (name !== null && SIDE_EFFECT_ACTORS.has(name)) {
|
|
76
|
+
context.report({
|
|
77
|
+
data: { name },
|
|
78
|
+
messageId: "sideEffectActor",
|
|
79
|
+
node
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
ExportNamedDeclaration: (node) => {
|
|
85
|
+
if (node.source !== null && isXState(node.source.value)) {
|
|
86
|
+
for (const specifier of node.specifiers) {
|
|
87
|
+
check(specifier, nameOf(specifier.local));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
ImportDeclaration: (node) => {
|
|
92
|
+
if (isXState(node.source.value)) {
|
|
93
|
+
for (const specifier of node.specifiers) {
|
|
94
|
+
if (specifier.type === "ImportSpecifier") {
|
|
95
|
+
check(specifier, nameOf(specifier.imported));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
MemberExpression: (node) => {
|
|
101
|
+
if (node.object.type === "Identifier" && isXStateNamespace(declaredVariable(context.sourceCode, node.object))) {
|
|
102
|
+
check(node, staticPropertyName(node.property, node.computed));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
meta: {
|
|
108
|
+
docs: {
|
|
109
|
+
description: "Require XState side-effect actors to be `fromEffect` actors: no `fromPromise`, `fromCallback` or observable actor logic."
|
|
110
|
+
},
|
|
111
|
+
messages,
|
|
112
|
+
type: "problem"
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// src/rules/effect-subpath/effect-subpath.ts
|
|
118
|
+
import { defineRule as defineRule2 } from "@oxlint/plugins";
|
|
119
|
+
|
|
37
120
|
// src/workspace/package-exports.ts
|
|
38
121
|
var parseExports = (exports) => {
|
|
39
122
|
const subpaths = exports instanceof Object && !Array.isArray(exports) ? Object.entries(exports) : [];
|
|
@@ -75,6 +158,73 @@ var declaresEntrypoint = (target, subpath) => {
|
|
|
75
158
|
return target.exports.get(key) ?? matchPattern(target.exports, key);
|
|
76
159
|
};
|
|
77
160
|
|
|
161
|
+
// src/rules/effect-subpath/effect-subpath.ts
|
|
162
|
+
var SCOPE = "@collective-intelligence/";
|
|
163
|
+
var EFFECT_PACKAGE_SUFFIX = "-effect";
|
|
164
|
+
var DEPRECATED = new Map([
|
|
165
|
+
[
|
|
166
|
+
"@collective-intelligence/external-apps-server-sdk/runtime/effect",
|
|
167
|
+
"@collective-intelligence/external-apps-server-sdk/effect"
|
|
168
|
+
],
|
|
169
|
+
[
|
|
170
|
+
"@collective-intelligence/external-apps-server-sdk/persistence/drizzle/effect",
|
|
171
|
+
"@collective-intelligence/external-apps-server-sdk/effect"
|
|
172
|
+
],
|
|
173
|
+
[
|
|
174
|
+
"@collective-intelligence/external-apps-server-sdk/runtime/next",
|
|
175
|
+
"@collective-intelligence/external-apps-server-sdk/next"
|
|
176
|
+
],
|
|
177
|
+
[
|
|
178
|
+
"@collective-intelligence/extensions-sdk-backend-effect",
|
|
179
|
+
"@collective-intelligence/extensions-sdk-backend/effect"
|
|
180
|
+
]
|
|
181
|
+
]);
|
|
182
|
+
var messages2 = {
|
|
183
|
+
deprecated: "`{{specifier}}` is deprecated. Import `{{replacement}}`.",
|
|
184
|
+
outsideEffect: "`{{specifier}}` imports an SDK Effect API from outside its `/effect` subpath. Import `{{replacement}}`."
|
|
185
|
+
};
|
|
186
|
+
var effectSubpathFor = (specifier) => {
|
|
187
|
+
const parsed = parsePackageSpecifier(specifier);
|
|
188
|
+
if (parsed === null || !parsed.name.startsWith(SCOPE)) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
const { name, subpath } = parsed;
|
|
192
|
+
if (name.endsWith(EFFECT_PACKAGE_SUFFIX)) {
|
|
193
|
+
return `${name.slice(0, -EFFECT_PACKAGE_SUFFIX.length)}/effect`;
|
|
194
|
+
}
|
|
195
|
+
const [first, ...rest] = subpath.split("/");
|
|
196
|
+
return first !== "effect" && rest.includes("effect") ? `${name}/effect` : null;
|
|
197
|
+
};
|
|
198
|
+
var effectSubpath = {
|
|
199
|
+
group: "effect-convention",
|
|
200
|
+
rule: defineRule2({
|
|
201
|
+
create(context) {
|
|
202
|
+
return moduleSpecifiers((node) => {
|
|
203
|
+
const specifier = node.value;
|
|
204
|
+
const deprecated = DEPRECATED.get(specifier);
|
|
205
|
+
const replacement = deprecated ?? effectSubpathFor(specifier);
|
|
206
|
+
if (replacement !== null) {
|
|
207
|
+
const messageId = deprecated === undefined ? "outsideEffect" : "deprecated";
|
|
208
|
+
context.report({ data: { replacement, specifier }, messageId, node });
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
},
|
|
212
|
+
meta: {
|
|
213
|
+
docs: {
|
|
214
|
+
description: "Require the Effect API of a Collective Intelligence SDK to come from its `/effect` subpath, and report deprecated SDK paths."
|
|
215
|
+
},
|
|
216
|
+
messages: messages2,
|
|
217
|
+
type: "problem"
|
|
218
|
+
}
|
|
219
|
+
})
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// src/rules/no-run-in-view/no-run-in-view.ts
|
|
223
|
+
import { defineRule as defineRule3 } from "@oxlint/plugins";
|
|
224
|
+
|
|
225
|
+
// src/workspace/layout.ts
|
|
226
|
+
import path2 from "node:path";
|
|
227
|
+
|
|
78
228
|
// src/workspace/workspace.ts
|
|
79
229
|
import { existsSync, readFileSync } from "node:fs";
|
|
80
230
|
import path from "node:path";
|
|
@@ -110,13 +260,121 @@ var installedPackage = (directory, name) => {
|
|
|
110
260
|
return found;
|
|
111
261
|
};
|
|
112
262
|
|
|
263
|
+
// src/workspace/layout.ts
|
|
264
|
+
var SUBPATHS = [
|
|
265
|
+
"ci",
|
|
266
|
+
"domain",
|
|
267
|
+
"api",
|
|
268
|
+
"server",
|
|
269
|
+
"headless",
|
|
270
|
+
"views"
|
|
271
|
+
];
|
|
272
|
+
var isSubpath = (folder) => SUBPATHS.some((subpath) => subpath === folder);
|
|
273
|
+
var subpathOfSegments = (segments) => {
|
|
274
|
+
const [folder] = segments ?? [];
|
|
275
|
+
return isSubpath(folder) ? folder : null;
|
|
276
|
+
};
|
|
277
|
+
var sourceSegments = (root, target) => {
|
|
278
|
+
const relative = path2.relative(path2.join(root, "src"), target);
|
|
279
|
+
return relative === "" || relative.startsWith("..") || path2.isAbsolute(relative) ? null : relative.split(path2.sep);
|
|
280
|
+
};
|
|
281
|
+
var isSubpathEntrypoint = (segments) => {
|
|
282
|
+
const [, file] = segments;
|
|
283
|
+
return segments.length === 1 || segments.length === 2 && path2.parse(file ?? "").name === "index";
|
|
284
|
+
};
|
|
285
|
+
var layoutFile = (filename) => {
|
|
286
|
+
const owner = packageOf(path2.dirname(filename));
|
|
287
|
+
const segments = owner && sourceSegments(owner.root, filename);
|
|
288
|
+
const subpath = segments && segments.length > 1 ? subpathOfSegments(segments) : null;
|
|
289
|
+
return owner && subpath ? { owner, subpath } : null;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
// src/rules/no-run-in-view/no-run-in-view.ts
|
|
293
|
+
var JSX_FILE = /\.[jt]sx$/u;
|
|
294
|
+
var RUN_FUNCTION = /^run(?:Callback|Fork|Promise|PromiseExit|Sync|SyncExit)(?:With)?$/u;
|
|
295
|
+
var FETCH_OBJECTS = ["globalThis", "window"];
|
|
296
|
+
var isRunFunction = (name) => name !== null && RUN_FUNCTION.test(name);
|
|
297
|
+
var isEffectModule = (source) => source === "effect" || source.startsWith("effect/") || source.startsWith("@effect/");
|
|
298
|
+
var messages3 = {
|
|
299
|
+
fetch: "A view module calls `fetch`. Read data with TanStack Query, or call the API in a `fromEffect` actor.",
|
|
300
|
+
run: "A view module runs an Effect with `{{name}}`. Run the Effect in a `fromEffect` actor."
|
|
301
|
+
};
|
|
302
|
+
var isViewModule = (filename) => JSX_FILE.test(filename) || layoutFile(filename)?.subpath === "views";
|
|
303
|
+
var noRunInView = {
|
|
304
|
+
group: "effect-convention",
|
|
305
|
+
rule: defineRule3({
|
|
306
|
+
create(context) {
|
|
307
|
+
if (!isViewModule(context.filename)) {
|
|
308
|
+
return {};
|
|
309
|
+
}
|
|
310
|
+
const isGlobal = (node, names) => node.type === "Identifier" && names.includes(node.name) && declaredVariable(context.sourceCode, node) === null;
|
|
311
|
+
const isFetch = (callee) => callee.type === "MemberExpression" ? staticPropertyName(callee.property, callee.computed) === "fetch" && isGlobal(callee.object, FETCH_OBJECTS) : isGlobal(callee, ["fetch"]);
|
|
312
|
+
const reportRun = (node, name) => {
|
|
313
|
+
context.report({
|
|
314
|
+
data: { name },
|
|
315
|
+
messageId: "run",
|
|
316
|
+
node
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
return {
|
|
320
|
+
CallExpression: (node) => {
|
|
321
|
+
if (isFetch(node.callee)) {
|
|
322
|
+
context.report({
|
|
323
|
+
messageId: "fetch",
|
|
324
|
+
node
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
ImportDeclaration: (node) => {
|
|
329
|
+
if (!isEffectModule(node.source.value)) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
for (const specifier of node.specifiers) {
|
|
333
|
+
if (specifier.type === "ImportSpecifier") {
|
|
334
|
+
const { imported } = specifier;
|
|
335
|
+
const name = imported.type === "Literal" ? imported.value : imported.name;
|
|
336
|
+
if (RUN_FUNCTION.test(name)) {
|
|
337
|
+
reportRun(specifier, name);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
MemberExpression: (node) => {
|
|
343
|
+
if (isRunFunction(staticPropertyName(node.property, node.computed))) {
|
|
344
|
+
reportRun(node, context.sourceCode.getText(node));
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
ObjectPattern: (node) => {
|
|
348
|
+
for (const property of node.properties) {
|
|
349
|
+
if (property.type === "Property") {
|
|
350
|
+
const name = staticPropertyName(property.key, property.computed);
|
|
351
|
+
if (isRunFunction(name)) {
|
|
352
|
+
reportRun(property, name);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
},
|
|
359
|
+
meta: {
|
|
360
|
+
docs: {
|
|
361
|
+
description: "Disallow `fetch` calls and Effect run functions in view modules; side effects run in `fromEffect` actors."
|
|
362
|
+
},
|
|
363
|
+
messages: messages3,
|
|
364
|
+
type: "problem"
|
|
365
|
+
}
|
|
366
|
+
})
|
|
367
|
+
};
|
|
368
|
+
|
|
113
369
|
// src/rules/package-entrypoint/package-entrypoint.ts
|
|
114
|
-
|
|
370
|
+
import { defineRule as defineRule4 } from "@oxlint/plugins";
|
|
371
|
+
import path3 from "node:path";
|
|
372
|
+
var packageName = (target) => target.name ?? path3.basename(target.root);
|
|
115
373
|
var packageEntrypoint = {
|
|
116
374
|
group: "package-boundaries",
|
|
117
|
-
rule:
|
|
375
|
+
rule: defineRule4({
|
|
118
376
|
create(context) {
|
|
119
|
-
const directory =
|
|
377
|
+
const directory = path3.dirname(context.filename);
|
|
120
378
|
const owner = packageOf(directory);
|
|
121
379
|
if (owner === null) {
|
|
122
380
|
return {};
|
|
@@ -124,7 +382,7 @@ var packageEntrypoint = {
|
|
|
124
382
|
return moduleSpecifiers((node) => {
|
|
125
383
|
const specifier = node.value;
|
|
126
384
|
if (specifier.startsWith(".")) {
|
|
127
|
-
const target = packageOf(
|
|
385
|
+
const target = packageOf(path3.resolve(directory, specifier));
|
|
128
386
|
if (target !== null && target.root !== owner.root) {
|
|
129
387
|
context.report({
|
|
130
388
|
data: { name: packageName(target), specifier },
|
|
@@ -162,43 +420,11 @@ var packageEntrypoint = {
|
|
|
162
420
|
};
|
|
163
421
|
|
|
164
422
|
// src/rules/subpath-entrypoint/subpath-entrypoint.ts
|
|
165
|
-
import { defineRule as
|
|
423
|
+
import { defineRule as defineRule5 } from "@oxlint/plugins";
|
|
166
424
|
import path4 from "node:path";
|
|
167
|
-
|
|
168
|
-
// src/workspace/layout.ts
|
|
169
|
-
import path3 from "node:path";
|
|
170
|
-
var SUBPATHS = [
|
|
171
|
-
"ci",
|
|
172
|
-
"domain",
|
|
173
|
-
"api",
|
|
174
|
-
"server",
|
|
175
|
-
"headless",
|
|
176
|
-
"views"
|
|
177
|
-
];
|
|
178
|
-
var isSubpath = (folder) => SUBPATHS.some((subpath) => subpath === folder);
|
|
179
|
-
var subpathOfSegments = (segments) => {
|
|
180
|
-
const [folder] = segments ?? [];
|
|
181
|
-
return isSubpath(folder) ? folder : null;
|
|
182
|
-
};
|
|
183
|
-
var sourceSegments = (root, target) => {
|
|
184
|
-
const relative = path3.relative(path3.join(root, "src"), target);
|
|
185
|
-
return relative === "" || relative.startsWith("..") || path3.isAbsolute(relative) ? null : relative.split(path3.sep);
|
|
186
|
-
};
|
|
187
|
-
var isSubpathEntrypoint = (segments) => {
|
|
188
|
-
const [, file] = segments;
|
|
189
|
-
return segments.length === 1 || segments.length === 2 && path3.parse(file ?? "").name === "index";
|
|
190
|
-
};
|
|
191
|
-
var layoutFile = (filename) => {
|
|
192
|
-
const owner = packageOf(path3.dirname(filename));
|
|
193
|
-
const segments = owner && sourceSegments(owner.root, filename);
|
|
194
|
-
const subpath = segments && segments.length > 1 ? subpathOfSegments(segments) : null;
|
|
195
|
-
return owner && subpath ? { owner, subpath } : null;
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
// src/rules/subpath-entrypoint/subpath-entrypoint.ts
|
|
199
425
|
var subpathEntrypoint = {
|
|
200
426
|
group: "solution-layout",
|
|
201
|
-
rule:
|
|
427
|
+
rule: defineRule5({
|
|
202
428
|
create(context) {
|
|
203
429
|
const directory = path4.dirname(context.filename);
|
|
204
430
|
const owner = packageOf(directory);
|
|
@@ -235,7 +461,7 @@ var subpathEntrypoint = {
|
|
|
235
461
|
};
|
|
236
462
|
|
|
237
463
|
// src/rules/subpath-imports/subpath-imports.ts
|
|
238
|
-
import { defineRule as
|
|
464
|
+
import { defineRule as defineRule6 } from "@oxlint/plugins";
|
|
239
465
|
import path5 from "node:path";
|
|
240
466
|
var FORBIDDEN_IMPORTS = {
|
|
241
467
|
api: [],
|
|
@@ -247,7 +473,7 @@ var FORBIDDEN_IMPORTS = {
|
|
|
247
473
|
};
|
|
248
474
|
var subpathImports = {
|
|
249
475
|
group: "solution-layout",
|
|
250
|
-
rule:
|
|
476
|
+
rule: defineRule6({
|
|
251
477
|
create(context) {
|
|
252
478
|
const file = layoutFile(context.filename);
|
|
253
479
|
if (file === null) {
|
|
@@ -292,13 +518,13 @@ var subpathImports = {
|
|
|
292
518
|
};
|
|
293
519
|
|
|
294
520
|
// src/rules/subpath-index/subpath-index.ts
|
|
295
|
-
import { defineRule as
|
|
521
|
+
import { defineRule as defineRule7 } from "@oxlint/plugins";
|
|
296
522
|
import { existsSync as existsSync2 } from "node:fs";
|
|
297
523
|
import path6 from "node:path";
|
|
298
524
|
var INDEX_FILES = ["index.ts", "index.tsx"];
|
|
299
525
|
var subpathIndex = {
|
|
300
526
|
group: "solution-layout",
|
|
301
|
-
rule:
|
|
527
|
+
rule: defineRule7({
|
|
302
528
|
create(context) {
|
|
303
529
|
const file = layoutFile(context.filename);
|
|
304
530
|
if (file === null) {
|
|
@@ -332,6 +558,9 @@ var subpathIndex = {
|
|
|
332
558
|
|
|
333
559
|
// src/rules/index.ts
|
|
334
560
|
var rules = {
|
|
561
|
+
"effect-actors": effectActors,
|
|
562
|
+
"effect-subpath": effectSubpath,
|
|
563
|
+
"no-run-in-view": noRunInView,
|
|
335
564
|
"package-entrypoint": packageEntrypoint,
|
|
336
565
|
"subpath-entrypoint": subpathEntrypoint,
|
|
337
566
|
"subpath-imports": subpathImports,
|
package/dist/rule.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { ESTree, Rule, Visitor } from "@oxlint/plugins";
|
|
2
|
-
export type RuleGroup = "package-boundaries" | "solution-layout";
|
|
1
|
+
import type { ESTree, Rule, SourceCode, Variable, Visitor } from "@oxlint/plugins";
|
|
2
|
+
export type RuleGroup = "effect-convention" | "package-boundaries" | "solution-layout";
|
|
3
3
|
export interface LintRule {
|
|
4
4
|
readonly group: RuleGroup;
|
|
5
5
|
readonly rule: Rule;
|
|
6
6
|
}
|
|
7
|
+
export declare const staticPropertyName: (key: ESTree.PropertyKey, computed: boolean) => string | null;
|
|
8
|
+
export declare const declaredVariable: (sourceCode: SourceCode, node: ESTree.IdentifierReference) => Variable | null;
|
|
7
9
|
export declare const moduleSpecifiers: (check: (literal: ESTree.StringLiteral) => void) => Visitor;
|
package/dist/rules/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { LintRule } from "../rule.ts";
|
|
2
2
|
export declare const rules: {
|
|
3
|
+
readonly "effect-actors": LintRule;
|
|
4
|
+
readonly "effect-subpath": LintRule;
|
|
5
|
+
readonly "no-run-in-view": LintRule;
|
|
3
6
|
readonly "package-entrypoint": LintRule;
|
|
4
7
|
readonly "subpath-entrypoint": LintRule;
|
|
5
8
|
readonly "subpath-imports": LintRule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@collective-intelligence/lint",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
4
|
"description": "Oxlint plugin with the Collective Intelligence lint rules: package boundaries and solution package layout.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"typescript": "7.0.2",
|
|
49
49
|
"ultracite": "7.10.7"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "b46c00d8ce76db49b810e7a3f25933ace4f2252f"
|
|
52
52
|
}
|
|
@@ -74,20 +74,24 @@ export default defineConfig({ extends: [recommended] })
|
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
In a repository that Harness Intelligence manages, the `collective-intelligence` pack adds the plugin
|
|
77
|
-
and `ci-solution/package-entrypoint` to the managed lint config of every scope
|
|
78
|
-
|
|
79
|
-
`oxlint.local.ts
|
|
80
|
-
`recommended` as shown.
|
|
81
|
-
|
|
82
|
-
`recommended` enables every rule as an error.
|
|
83
|
-
[package shape](package-shape.md)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
|
87
|
-
|
|
|
88
|
-
| `ci-solution/
|
|
89
|
-
| `ci-solution/subpath-
|
|
90
|
-
| `ci-solution/subpath-
|
|
77
|
+
and `ci-solution/package-entrypoint` to the managed lint config of every scope. Each solution
|
|
78
|
+
package (`packages/<tier>/<name>`) and each app still extends `recommended` in its
|
|
79
|
+
`oxlint.local.ts`, which adds the solution-layout rules and the Effect rules. Outside Harness
|
|
80
|
+
Intelligence, extend `recommended` as shown.
|
|
81
|
+
|
|
82
|
+
`recommended` enables every rule as an error. The package rules enforce the
|
|
83
|
+
[package shape](package-shape.md); the Effect rules keep side effects in `fromEffect` actors of
|
|
84
|
+
XState machines and out of views:
|
|
85
|
+
|
|
86
|
+
| Rule | Enforces |
|
|
87
|
+
| -------------------------------- | -------------------------------------------------------------------------------- |
|
|
88
|
+
| `ci-solution/package-entrypoint` | Cross-package imports target an exported subpath. |
|
|
89
|
+
| `ci-solution/subpath-imports` | The [subpath direction](package-shape.md#subpath-direction). |
|
|
90
|
+
| `ci-solution/subpath-entrypoint` | An import into another subpath targets the folder or its `index` file. |
|
|
91
|
+
| `ci-solution/subpath-index` | Every subpath folder under `src/` has an `index.ts` or `index.tsx`. |
|
|
92
|
+
| `ci-solution/effect-subpath` | An SDK Effect API comes from `<sdk>/effect`; deprecated SDK paths are errors. |
|
|
93
|
+
| `ci-solution/no-run-in-view` | A view module (`.tsx`, `.jsx`, `views/`) calls no `fetch` and runs no Effect. |
|
|
94
|
+
| `ci-solution/effect-actors` | XState side-effect actors are `fromEffect`, not `fromPromise` or `fromCallback`. |
|
|
91
95
|
|
|
92
96
|
`package-entrypoint` finds each package through `node_modules`, so the package manager must link the
|
|
93
97
|
workspace packages. The package documentation is the authority for rule options.
|