@murky-web/oxlint-plugin-solid 1.0.0 → 1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@murky-web/oxlint-plugin-solid",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Local Oxlint JS plugin port for Solid rules plus Murky-specific Solid conventions.",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -215,7 +215,7 @@ export default createRule({
215
215
  shouldAssign:
216
216
  "For proper analysis, a variable should be used to capture the result of this function call.",
217
217
  noAsyncTrackedScope:
218
- "This tracked scope should not be async. Solid's reactivity only tracks synchronously.",
218
+ "The reactive variable '{{name}}' is read after an await, so it registers no dependency and this computation will not re-run when it changes. Read every reactive input before the first async gap.",
219
219
  },
220
220
  },
221
221
  defaultOptions: [
@@ -391,6 +391,65 @@ export default createRule({
391
391
  }
392
392
  };
393
393
  /** Performs all analysis and reporting. */
394
+ const asyncGapCache = new Map();
395
+ const ASYNC_GAP_TYPES = new Set(["AwaitExpression", "YieldExpression"]);
396
+ /**
397
+ * Where a function first suspends, or null if it never does.
398
+ *
399
+ * `yield` counts alongside `await`: an async generator driven by `action`
400
+ * suspends there in exactly the same way, and a read afterwards is just as
401
+ * detached. Nested functions are skipped — their gaps are their own, and a
402
+ * callback defined after an await still runs with its own tracking.
403
+ */
404
+ const firstAsyncGapStart = (node) => {
405
+ if (!isFunctionNode(node) || node.async !== true) {
406
+ return null;
407
+ }
408
+ if (asyncGapCache.has(node)) {
409
+ return asyncGapCache.get(node);
410
+ }
411
+
412
+ let earliest = null;
413
+ const pending = [node.body];
414
+ while (pending.length > 0) {
415
+ const current = pending.pop();
416
+ if (!current || typeof current !== "object") {
417
+ continue;
418
+ }
419
+ if (Array.isArray(current)) {
420
+ pending.push(...current);
421
+ continue;
422
+ }
423
+ if (typeof current.type !== "string") {
424
+ continue;
425
+ }
426
+ if (ASYNC_GAP_TYPES.has(current.type)) {
427
+ const start = Array.isArray(current.range)
428
+ ? current.range[0]
429
+ : null;
430
+ if (start !== null && (earliest === null || start < earliest)) {
431
+ earliest = start;
432
+ }
433
+ // An await nested inside this one cannot start earlier.
434
+ continue;
435
+ }
436
+ for (const [key, value] of Object.entries(current)) {
437
+ if (key === "parent") {
438
+ continue;
439
+ }
440
+ if (
441
+ value &&
442
+ typeof value === "object" &&
443
+ !(typeof value.type === "string" && isFunctionNode(value))
444
+ ) {
445
+ pending.push(value);
446
+ }
447
+ }
448
+ }
449
+
450
+ asyncGapCache.set(node, earliest);
451
+ return earliest;
452
+ };
394
453
  const onFunctionExit = (currentScopeNode) => {
395
454
  // If this function is a component, add its props as a reactive variable
396
455
  if (isFunctionNode(currentScopeNode)) {
@@ -416,12 +475,32 @@ export default createRule({
416
475
  ) {
417
476
  return;
418
477
  }
478
+ // Solid 2.0 supports async computations — `createMemo(async () => …)` is
479
+ // the documented shape. What stays synchronous is dependency *tracking*:
480
+ // reads before the first await register, reads after it do not. So the
481
+ // hazard is not the `async` keyword, it is a reactive read on the far side
482
+ // of an async gap, which silently creates no dependency edge and leaves the
483
+ // computation unable to re-run. Solid's development build raises this at
484
+ // runtime; catching it here also covers production, where that check is
485
+ // compiled out.
486
+ const asyncGapStart = firstAsyncGapStart(currentScopeNode);
419
487
  // Iterate through all usages of (derived) signals in the current scope
420
488
  for (const {
421
489
  reference,
422
490
  declarationScope,
423
491
  } of scopeStack.consumeSignalReferencesInScope()) {
424
492
  const identifier = reference.identifier;
493
+ if (
494
+ asyncGapStart !== null &&
495
+ Array.isArray(identifier.range) &&
496
+ identifier.range[0] > asyncGapStart
497
+ ) {
498
+ context.report({
499
+ node: identifier,
500
+ messageId: "noAsyncTrackedScope",
501
+ data: { name: identifier.name },
502
+ });
503
+ }
425
504
  if (reference.isWrite()) {
426
505
  // don't allow reassigning signals
427
506
  context.report({
@@ -810,19 +889,6 @@ export default createRule({
810
889
  const checkForTrackedScopes = (node) => {
811
890
  const pushTrackedScope = (node, expect) => {
812
891
  currentScope().trackedScopes.push({ node, expect });
813
- if (
814
- expect !== "called-function" &&
815
- isFunctionNode(node) &&
816
- node.async
817
- ) {
818
- // From the docs: "[Solid's] approach only tracks synchronously. If you
819
- // have a setTimeout or use an async function in your Effect the code
820
- // that executes async after the fact won't be tracked."
821
- context.report({
822
- node,
823
- messageId: "noAsyncTrackedScope",
824
- });
825
- }
826
892
  };
827
893
  // given some expression, mark any functions within it as tracking scopes, and do not traverse
828
894
  // those functions