@pyreon/lint 0.14.0 → 0.16.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 +9 -7
- package/bin/pyreon-lint.js +2 -0
- package/lib/analysis/cli.js.html +1 -1
- package/lib/analysis/index.js.html +1 -1
- package/lib/cli.js +791 -69
- package/lib/index.js +791 -69
- package/lib/types/index.d.ts +1 -1
- package/package.json +5 -3
- package/src/manifest.ts +6 -6
- package/src/rules/architecture/dev-guard-warnings.ts +56 -6
- package/src/rules/architecture/no-process-dev-gate.ts +141 -62
- package/src/rules/index.ts +25 -2
- package/src/rules/jsx/no-props-destructure.ts +57 -7
- package/src/rules/lifecycle/no-imperative-effect-on-create.ts +278 -0
- package/src/rules/reactivity/no-async-effect.ts +84 -0
- package/src/rules/reactivity/no-signal-call-write.ts +60 -0
- package/src/rules/reactivity/storage-signal-v-forwarding.ts +184 -0
- package/src/rules/ssg/index.ts +3 -0
- package/src/rules/ssg/invalid-loader-export.ts +84 -0
- package/src/rules/ssg/missing-get-static-paths.ts +103 -0
- package/src/rules/ssg/revalidate-not-pure-literal.ts +69 -0
- package/src/runner.ts +8 -8
- package/src/tests/runner.test.ts +547 -9
- package/src/tests/ssg-rules.test.ts +211 -0
- package/src/tests/storage-signal-v-forwarding.test.ts +224 -0
- package/src/types.ts +1 -0
- package/src/utils/validate-options.ts +1 -1
- package/lib/cli.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types/index.d.ts.map +0 -1
package/lib/cli.js
CHANGED
|
@@ -527,9 +527,34 @@ const devGuardWarnings = {
|
|
|
527
527
|
}
|
|
528
528
|
return false;
|
|
529
529
|
}
|
|
530
|
+
function isProcessEnvNodeEnv(node) {
|
|
531
|
+
let n = node;
|
|
532
|
+
if (n?.type === "ChainExpression") n = n.expression;
|
|
533
|
+
if (n?.type !== "MemberExpression") return false;
|
|
534
|
+
if (n.property?.type !== "Identifier" || n.property.name !== "NODE_ENV") return false;
|
|
535
|
+
let envObj = n.object;
|
|
536
|
+
if (envObj?.type === "ChainExpression") envObj = envObj.expression;
|
|
537
|
+
if (envObj?.type !== "MemberExpression") return false;
|
|
538
|
+
if (envObj.property?.type !== "Identifier" || envObj.property.name !== "env") return false;
|
|
539
|
+
const procObj = envObj.object;
|
|
540
|
+
return procObj?.type === "Identifier" && procObj.name === "process";
|
|
541
|
+
}
|
|
542
|
+
function isDevelopmentCheck(node) {
|
|
543
|
+
if (node?.type !== "BinaryExpression") return false;
|
|
544
|
+
if (node.operator !== "!==" && node.operator !== "!=") return false;
|
|
545
|
+
const matches = (a, b) => isProcessEnvNodeEnv(a) && (b?.type === "Literal" || b?.type === "StringLiteral") && b.value === "production";
|
|
546
|
+
return matches(node.left, node.right) || matches(node.right, node.left);
|
|
547
|
+
}
|
|
548
|
+
function isProductionCheck(node) {
|
|
549
|
+
if (node?.type !== "BinaryExpression") return false;
|
|
550
|
+
if (node.operator !== "===" && node.operator !== "==") return false;
|
|
551
|
+
const matches = (a, b) => isProcessEnvNodeEnv(a) && (b?.type === "Literal" || b?.type === "StringLiteral") && b.value === "production";
|
|
552
|
+
return matches(node.left, node.right) || matches(node.right, node.left);
|
|
553
|
+
}
|
|
530
554
|
function containsDevGuard(test) {
|
|
531
555
|
if (!test) return false;
|
|
532
556
|
if (isDevFlag(test)) return true;
|
|
557
|
+
if (isDevelopmentCheck(test)) return true;
|
|
533
558
|
if (test.type === "LogicalExpression" && test.operator === "&&") return containsDevGuard(test.left) || containsDevGuard(test.right);
|
|
534
559
|
if (test.type === "BinaryExpression" && (test.operator === "===" || test.operator === "==")) return isDevFlag(test.left) || isDevFlag(test.right);
|
|
535
560
|
return false;
|
|
@@ -537,13 +562,12 @@ const devGuardWarnings = {
|
|
|
537
562
|
function isEarlyReturnDevGuard(node) {
|
|
538
563
|
if (!node || node.type !== "IfStatement") return false;
|
|
539
564
|
const t = node.test;
|
|
565
|
+
const c = node.consequent;
|
|
566
|
+
if (!(c?.type === "ReturnStatement" || c?.type === "BlockStatement" && c.body.length === 1 && c.body[0]?.type === "ReturnStatement")) return false;
|
|
567
|
+
if (isProductionCheck(t)) return true;
|
|
540
568
|
const arg = t?.type === "UnaryExpression" && t.operator === "!" ? t.argument : null;
|
|
541
569
|
if (!arg) return false;
|
|
542
|
-
|
|
543
|
-
const c = node.consequent;
|
|
544
|
-
if (c?.type === "ReturnStatement") return true;
|
|
545
|
-
if (c?.type === "BlockStatement" && c.body.length === 1 && c.body[0]?.type === "ReturnStatement") return true;
|
|
546
|
-
return false;
|
|
570
|
+
return isDevFlag(arg);
|
|
547
571
|
}
|
|
548
572
|
let devGuardDepth = 0;
|
|
549
573
|
let catchDepth = 0;
|
|
@@ -803,40 +827,48 @@ const noErrorWithoutPrefix = {
|
|
|
803
827
|
//#endregion
|
|
804
828
|
//#region src/rules/architecture/no-process-dev-gate.ts
|
|
805
829
|
/**
|
|
806
|
-
* `pyreon/no-process-dev-gate` — flag
|
|
807
|
-
*
|
|
830
|
+
* `pyreon/no-process-dev-gate` — flag bundler-coupled dev-gate patterns
|
|
831
|
+
* that are dead code or unsupported in some bundlers Pyreon ships to.
|
|
808
832
|
*
|
|
809
|
-
*
|
|
833
|
+
* Pyreon publishes libraries to npm. Consumers compile those libraries
|
|
834
|
+
* with whatever bundler they use — Vite, Webpack (Next.js), Rolldown,
|
|
835
|
+
* esbuild, Rollup, Parcel, Bun. The framework should not ship dev gates
|
|
836
|
+
* that only fire in one bundler.
|
|
810
837
|
*
|
|
811
|
-
*
|
|
812
|
-
*
|
|
813
|
-
*
|
|
838
|
+
* **Two broken patterns this rule catches:**
|
|
839
|
+
*
|
|
840
|
+
* 1. `typeof process !== 'undefined' && process.env.NODE_ENV !== 'production'`
|
|
841
|
+
* The `typeof process` guard isn't replaced by Vite, evaluates to
|
|
842
|
+
* `false` in the browser, and the whole expression is dead. Wrapped
|
|
843
|
+
* dev warnings never fire for users running Vite browser builds.
|
|
814
844
|
*
|
|
815
|
-
*
|
|
816
|
-
*
|
|
817
|
-
*
|
|
818
|
-
*
|
|
845
|
+
* 2. `import.meta.env.DEV` (and the `(import.meta as ViteMeta).env?.DEV`
|
|
846
|
+
* cast variant). Vite/Rolldown literal-replace this at build time, but
|
|
847
|
+
* Webpack/esbuild/Rollup/Parcel/Bun/Node-direct don't. In a Pyreon
|
|
848
|
+
* library shipped to a Next.js (Webpack) app, dev warnings never fire
|
|
849
|
+
* — even in development. PR #200 introduced this pattern as the
|
|
850
|
+
* "correct" replacement for the typeof-process compound; that
|
|
851
|
+
* direction was wrong for library code.
|
|
819
852
|
*
|
|
820
|
-
* The
|
|
821
|
-
*
|
|
853
|
+
* **The bundler-agnostic standard** (used by React, Vue, Preact, Solid,
|
|
854
|
+
* MobX, Redux):
|
|
822
855
|
*
|
|
823
856
|
* ```ts
|
|
824
|
-
*
|
|
825
|
-
* if (!import.meta.env?.DEV) return
|
|
857
|
+
* if (process.env.NODE_ENV !== 'production') console.warn('...')
|
|
826
858
|
* ```
|
|
827
859
|
*
|
|
828
|
-
*
|
|
829
|
-
*
|
|
860
|
+
* Every modern bundler auto-replaces `process.env.NODE_ENV` at consumer
|
|
861
|
+
* build time. No `typeof process` guard needed — bundlers replace the
|
|
862
|
+
* literal regardless of whether `process` is otherwise defined.
|
|
830
863
|
*
|
|
831
864
|
* Reference implementation: `packages/fundamentals/flow/src/layout.ts:warnIgnoredOptions`.
|
|
832
865
|
*
|
|
833
|
-
* **Auto-fix**: replaces the
|
|
834
|
-
*
|
|
835
|
-
* the variable name and downstream usages may need updating in callers.
|
|
866
|
+
* **Auto-fix**: replaces the broken expression with
|
|
867
|
+
* `process.env.NODE_ENV !== 'production'`.
|
|
836
868
|
*
|
|
837
|
-
* **Server-only exemption**: projects configure `exemptPaths` per-file
|
|
838
|
-
* server-only code (Node environments where
|
|
839
|
-
*
|
|
869
|
+
* **Server-only exemption**: projects configure `exemptPaths` per-file
|
|
870
|
+
* for server-only code (Node environments where the typeof-process
|
|
871
|
+
* compound is harmless). Configure in `.pyreonlintrc.json`:
|
|
840
872
|
*
|
|
841
873
|
* {
|
|
842
874
|
* "rules": {
|
|
@@ -851,25 +883,16 @@ const noProcessDevGate = {
|
|
|
851
883
|
meta: {
|
|
852
884
|
id: "pyreon/no-process-dev-gate",
|
|
853
885
|
category: "architecture",
|
|
854
|
-
description: "Forbid `typeof process !== \"undefined\" && process.env.NODE_ENV !== \"production\"`
|
|
886
|
+
description: "Forbid bundler-coupled dev gates: `typeof process !== \"undefined\" && process.env.NODE_ENV !== \"production\"` is dead in Vite browser bundles, and `import.meta.env.DEV` is Vite/Rolldown-only (dead in Webpack/Next.js, esbuild, Rollup, Parcel, Bun). Use bundler-agnostic `process.env.NODE_ENV !== \"production\"` — every modern bundler auto-replaces it at consumer build time.",
|
|
855
887
|
severity: "error",
|
|
856
888
|
fixable: true
|
|
857
889
|
},
|
|
858
890
|
create(context) {
|
|
859
891
|
if (isTestFile(context.getFilePath())) return {};
|
|
860
892
|
if (isPathExempt(context)) return {};
|
|
893
|
+
const REPLACEMENT = `process.env.NODE_ENV !== 'production'`;
|
|
861
894
|
/**
|
|
862
|
-
*
|
|
863
|
-
* `LogicalExpression` whose two sides are:
|
|
864
|
-
*
|
|
865
|
-
* 1. `typeof process !== 'undefined'` (a UnaryExpression on the LHS
|
|
866
|
-
* of a BinaryExpression with operator `!==`)
|
|
867
|
-
* 2. `process.env.NODE_ENV !== 'production'` (a MemberExpression on
|
|
868
|
-
* the LHS of a BinaryExpression with operator `!==`)
|
|
869
|
-
*
|
|
870
|
-
* The order can be either way (process check first or NODE_ENV check
|
|
871
|
-
* first), and the operator can be `&&` or `||` (we only flag `&&`
|
|
872
|
-
* because `||` doesn't make sense as a dev gate).
|
|
895
|
+
* Pattern 1: `typeof process !== 'undefined'`
|
|
873
896
|
*/
|
|
874
897
|
function isTypeofProcessCheck(node) {
|
|
875
898
|
if (node?.type !== "BinaryExpression") return false;
|
|
@@ -878,39 +901,116 @@ const noProcessDevGate = {
|
|
|
878
901
|
const right = node.right;
|
|
879
902
|
if (left?.type !== "UnaryExpression" || left.operator !== "typeof") return false;
|
|
880
903
|
if (left.argument?.type !== "Identifier" || left.argument.name !== "process") return false;
|
|
881
|
-
|
|
882
|
-
return false;
|
|
904
|
+
return (right?.type === "Literal" || right?.type === "StringLiteral") && right.value === "undefined";
|
|
883
905
|
}
|
|
906
|
+
/**
|
|
907
|
+
* Pattern 1: `process.env.NODE_ENV !== 'production'` — also matches
|
|
908
|
+
* optional-chaining variants (`process?.env?.NODE_ENV`,
|
|
909
|
+
* `process.env?.NODE_ENV`). ESTree wraps optional access in a
|
|
910
|
+
* `ChainExpression` whose `.expression` is the underlying
|
|
911
|
+
* `MemberExpression` chain.
|
|
912
|
+
*/
|
|
884
913
|
function isNodeEnvCheck(node) {
|
|
885
914
|
if (node?.type !== "BinaryExpression") return false;
|
|
886
915
|
if (node.operator !== "!==" && node.operator !== "!=") return false;
|
|
887
|
-
|
|
916
|
+
let left = node.left;
|
|
888
917
|
const right = node.right;
|
|
918
|
+
if (left?.type === "ChainExpression") left = left.expression;
|
|
889
919
|
if (left?.type !== "MemberExpression") return false;
|
|
890
920
|
if (left.object?.type !== "MemberExpression") return false;
|
|
891
921
|
if (left.object.object?.type !== "Identifier" || left.object.object.name !== "process") return false;
|
|
892
922
|
if (left.object.property?.type !== "Identifier" || left.object.property.name !== "env") return false;
|
|
893
923
|
if (left.property?.type !== "Identifier" || left.property.name !== "NODE_ENV") return false;
|
|
894
|
-
|
|
895
|
-
return false;
|
|
924
|
+
return (right?.type === "Literal" || right?.type === "StringLiteral") && right.value === "production";
|
|
896
925
|
}
|
|
897
|
-
|
|
926
|
+
/**
|
|
927
|
+
* Match the typeof-process compound: a `LogicalExpression` whose
|
|
928
|
+
* sides are a typeof-process check + a NODE_ENV check, in either
|
|
929
|
+
* order, joined with `&&`.
|
|
930
|
+
*/
|
|
931
|
+
function isTypeofCompound(node) {
|
|
898
932
|
if (node?.type !== "LogicalExpression") return false;
|
|
899
933
|
if (node.operator !== "&&") return false;
|
|
900
934
|
return isTypeofProcessCheck(node.left) && isNodeEnvCheck(node.right) || isNodeEnvCheck(node.left) && isTypeofProcessCheck(node.right);
|
|
901
935
|
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
936
|
+
/**
|
|
937
|
+
* Strip layers an `import.meta.env.DEV` access can hide behind:
|
|
938
|
+
* - `ChainExpression` (optional chaining)
|
|
939
|
+
* - `TSAsExpression` / `TSTypeAssertion` (`(import.meta as ViteMeta)`)
|
|
940
|
+
* - `ParenthesizedExpression` (just parens)
|
|
941
|
+
*/
|
|
942
|
+
function unwrap(node) {
|
|
943
|
+
let n = node;
|
|
944
|
+
while (n) if (n.type === "ChainExpression") n = n.expression;
|
|
945
|
+
else if (n.type === "TSAsExpression" || n.type === "TSTypeAssertion") n = n.expression;
|
|
946
|
+
else if (n.type === "ParenthesizedExpression") n = n.expression;
|
|
947
|
+
else break;
|
|
948
|
+
return n;
|
|
949
|
+
}
|
|
950
|
+
function isImportMeta(node) {
|
|
951
|
+
const n = unwrap(node);
|
|
952
|
+
if (n?.type !== "MetaProperty") return false;
|
|
953
|
+
const meta = n.meta;
|
|
954
|
+
const prop = n.property;
|
|
955
|
+
return meta?.type === "Identifier" && meta.name === "import" && prop?.type === "Identifier" && prop.name === "meta";
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Pattern 2: `import.meta.env.DEV` access (any optional/cast variant).
|
|
959
|
+
* Returns the outermost expression node so the autofix replaces the
|
|
960
|
+
* full `import.meta.env.DEV` access (not just the `.DEV` property).
|
|
961
|
+
*/
|
|
962
|
+
function isImportMetaEnvDev(node) {
|
|
963
|
+
const outer = unwrap(node);
|
|
964
|
+
if (outer?.type !== "MemberExpression") return false;
|
|
965
|
+
if (outer.property?.type !== "Identifier" || outer.property.name !== "DEV") return false;
|
|
966
|
+
const envAccess = unwrap(outer.object);
|
|
967
|
+
if (envAccess?.type !== "MemberExpression") return false;
|
|
968
|
+
if (envAccess.property?.type !== "Identifier" || envAccess.property.name !== "env") return false;
|
|
969
|
+
return isImportMeta(envAccess.object);
|
|
970
|
+
}
|
|
971
|
+
const handledNodes = /* @__PURE__ */ new WeakSet();
|
|
972
|
+
return {
|
|
973
|
+
LogicalExpression(node) {
|
|
974
|
+
if (!isTypeofCompound(node)) return;
|
|
975
|
+
const span = getSpan(node);
|
|
976
|
+
context.report({
|
|
977
|
+
message: "`typeof process !== \"undefined\" && process.env.NODE_ENV !== \"production\"` is dead code in real Vite browser bundles — Vite does not polyfill `process`, so the guard is `false` and any wrapped dev warnings never fire. Use the bundler-agnostic `process.env.NODE_ENV !== \"production\"` (no typeof guard) — every modern bundler replaces it at consumer build time. Reference: `packages/fundamentals/flow/src/layout.ts`.",
|
|
909
978
|
span,
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
979
|
+
fix: {
|
|
980
|
+
span,
|
|
981
|
+
replacement: REPLACEMENT
|
|
982
|
+
}
|
|
983
|
+
});
|
|
984
|
+
},
|
|
985
|
+
ChainExpression(node) {
|
|
986
|
+
if (!isImportMetaEnvDev(node)) return;
|
|
987
|
+
const inner = unwrap(node);
|
|
988
|
+
if (inner) handledNodes.add(inner);
|
|
989
|
+
const span = getSpan(node);
|
|
990
|
+
context.report({
|
|
991
|
+
message: "`import.meta.env.DEV` is Vite/Rolldown-specific. In a Pyreon library shipped to consumers using Webpack (Next.js), esbuild, Rollup, Parcel, or Bun, `import.meta.env.DEV` is undefined and dev warnings never fire — even in development. Use bundler-agnostic `process.env.NODE_ENV !== \"production\"` instead. Reference: `packages/fundamentals/flow/src/layout.ts`.",
|
|
992
|
+
span,
|
|
993
|
+
fix: {
|
|
994
|
+
span,
|
|
995
|
+
replacement: REPLACEMENT
|
|
996
|
+
}
|
|
997
|
+
});
|
|
998
|
+
},
|
|
999
|
+
MemberExpression(node) {
|
|
1000
|
+
if (handledNodes.has(node)) return;
|
|
1001
|
+
if (!isImportMetaEnvDev(node)) return;
|
|
1002
|
+
if (node.property?.name !== "DEV") return;
|
|
1003
|
+
const span = getSpan(node);
|
|
1004
|
+
context.report({
|
|
1005
|
+
message: "`import.meta.env.DEV` is Vite/Rolldown-specific. In a Pyreon library shipped to consumers using Webpack (Next.js), esbuild, Rollup, Parcel, or Bun, `import.meta.env.DEV` is undefined and dev warnings never fire — even in development. Use bundler-agnostic `process.env.NODE_ENV !== \"production\"` instead. Reference: `packages/fundamentals/flow/src/layout.ts`.",
|
|
1006
|
+
span,
|
|
1007
|
+
fix: {
|
|
1008
|
+
span,
|
|
1009
|
+
replacement: REPLACEMENT
|
|
1010
|
+
}
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
914
1014
|
}
|
|
915
1015
|
};
|
|
916
1016
|
|
|
@@ -1612,20 +1712,51 @@ function getDestructuredNames(pattern) {
|
|
|
1612
1712
|
for (const prop of pattern.properties ?? []) if (prop.type === "ObjectProperty" && prop.key?.type === "Identifier") names.push(prop.key.name);
|
|
1613
1713
|
return names;
|
|
1614
1714
|
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Names of HOC / factory call expressions whose first-argument render
|
|
1717
|
+
* function takes Pyreon component props. Destructuring inside these IS
|
|
1718
|
+
* a real reactivity bug — same as destructuring at the component
|
|
1719
|
+
* signature directly. Do NOT add this exemption for these.
|
|
1720
|
+
*
|
|
1721
|
+
* The `callArgFns` exemption is intentionally narrow: it only fires for
|
|
1722
|
+
* generic call arguments where the parent call is NOT one of these
|
|
1723
|
+
* known component-shaped factories.
|
|
1724
|
+
*/
|
|
1725
|
+
const COMPONENT_FACTORY_NAMES = new Set([
|
|
1726
|
+
"createComponent",
|
|
1727
|
+
"defineComponent",
|
|
1728
|
+
"lazy",
|
|
1729
|
+
"memo",
|
|
1730
|
+
"observer",
|
|
1731
|
+
"forwardRef",
|
|
1732
|
+
"rocketstyle",
|
|
1733
|
+
"styled",
|
|
1734
|
+
"attrs",
|
|
1735
|
+
"kinetic"
|
|
1736
|
+
]);
|
|
1737
|
+
function isComponentFactoryCall(call) {
|
|
1738
|
+
if (!call || call.type !== "CallExpression") return false;
|
|
1739
|
+
const callee = call.callee;
|
|
1740
|
+
if (!callee) return false;
|
|
1741
|
+
if (callee.type === "Identifier" && COMPONENT_FACTORY_NAMES.has(callee.name)) return true;
|
|
1742
|
+
return false;
|
|
1743
|
+
}
|
|
1615
1744
|
const noPropsDestructure = {
|
|
1616
1745
|
meta: {
|
|
1617
1746
|
id: "pyreon/no-props-destructure",
|
|
1618
1747
|
category: "jsx",
|
|
1619
1748
|
description: "Disallow destructuring props in component functions — breaks reactive prop tracking. Use props.x or splitProps().",
|
|
1620
1749
|
severity: "error",
|
|
1621
|
-
fixable: false
|
|
1750
|
+
fixable: false,
|
|
1751
|
+
schema: { exemptPaths: "string[]" }
|
|
1622
1752
|
},
|
|
1623
1753
|
create(context) {
|
|
1754
|
+
if (isPathExempt(context)) return {};
|
|
1624
1755
|
let functionDepth = 0;
|
|
1625
|
-
const callArgFns = /* @__PURE__ */ new
|
|
1756
|
+
const callArgFns = /* @__PURE__ */ new WeakMap();
|
|
1626
1757
|
return {
|
|
1627
1758
|
CallExpression(node) {
|
|
1628
|
-
for (const arg of node.arguments ?? []) if (arg?.type === "ArrowFunctionExpression" || arg?.type === "FunctionExpression" || arg?.type === "FunctionDeclaration") callArgFns.
|
|
1759
|
+
for (const arg of node.arguments ?? []) if (arg?.type === "ArrowFunctionExpression" || arg?.type === "FunctionExpression" || arg?.type === "FunctionDeclaration") callArgFns.set(arg, node);
|
|
1629
1760
|
},
|
|
1630
1761
|
ArrowFunctionExpression(node) {
|
|
1631
1762
|
functionDepth++;
|
|
@@ -1657,7 +1788,8 @@ function checkFunction(node, context, depth, callArgFns) {
|
|
|
1657
1788
|
const firstParam = params[0];
|
|
1658
1789
|
if (!isDestructuring(firstParam)) return;
|
|
1659
1790
|
if (depth > 1) return;
|
|
1660
|
-
|
|
1791
|
+
const parentCall = callArgFns.get(node);
|
|
1792
|
+
if (parentCall && !isComponentFactoryCall(parentCall)) return;
|
|
1661
1793
|
const body = node.body;
|
|
1662
1794
|
if (!body) return;
|
|
1663
1795
|
if (containsJSXReturn(body)) {
|
|
@@ -1836,6 +1968,228 @@ const noEffectInMount = {
|
|
|
1836
1968
|
}
|
|
1837
1969
|
};
|
|
1838
1970
|
|
|
1971
|
+
//#endregion
|
|
1972
|
+
//#region src/rules/lifecycle/no-imperative-effect-on-create.ts
|
|
1973
|
+
/**
|
|
1974
|
+
* Imperative APIs whose presence inside an `effect(() => { ... })`
|
|
1975
|
+
* callback signals that the effect is doing setup work that belongs
|
|
1976
|
+
* in `onMount` — not reactive signal tracking. Calls to these inside
|
|
1977
|
+
* an effect at component body level cause the work to run
|
|
1978
|
+
* synchronously during component setup, which is the bug shape #268
|
|
1979
|
+
* surfaced (per-instance effect allocation under load).
|
|
1980
|
+
*
|
|
1981
|
+
* The list is intentionally narrow: each entry is a pattern that
|
|
1982
|
+
* cannot be a pure reactive read. `fetch(...)` triggers IO,
|
|
1983
|
+
* `setTimeout(fn)` schedules a deferred callback, `addEventListener`
|
|
1984
|
+
* mutates a global. None of these track signals; using `effect()` to
|
|
1985
|
+
* run them per-instance is the bug.
|
|
1986
|
+
*
|
|
1987
|
+
* Do NOT add: signal reads (`.value`, `()`), `console.log`, `Math.X`,
|
|
1988
|
+
* `JSON.X` — those are the legitimate reactive-tracking uses of
|
|
1989
|
+
* `effect()`.
|
|
1990
|
+
*/
|
|
1991
|
+
const IMPERATIVE_GLOBAL_CALLS = new Set([
|
|
1992
|
+
"fetch",
|
|
1993
|
+
"setTimeout",
|
|
1994
|
+
"setInterval",
|
|
1995
|
+
"requestAnimationFrame",
|
|
1996
|
+
"requestIdleCallback",
|
|
1997
|
+
"queueMicrotask"
|
|
1998
|
+
]);
|
|
1999
|
+
const IMPERATIVE_MEMBER_METHODS = new Set([
|
|
2000
|
+
"addEventListener",
|
|
2001
|
+
"removeEventListener",
|
|
2002
|
+
"querySelector",
|
|
2003
|
+
"querySelectorAll",
|
|
2004
|
+
"getElementById",
|
|
2005
|
+
"getElementsByClassName",
|
|
2006
|
+
"getElementsByTagName",
|
|
2007
|
+
"getBoundingClientRect",
|
|
2008
|
+
"getComputedStyle",
|
|
2009
|
+
"focus",
|
|
2010
|
+
"blur",
|
|
2011
|
+
"scrollIntoView",
|
|
2012
|
+
"scrollTo",
|
|
2013
|
+
"scrollBy",
|
|
2014
|
+
"requestFullscreen",
|
|
2015
|
+
"play",
|
|
2016
|
+
"pause"
|
|
2017
|
+
]);
|
|
2018
|
+
const IMPERATIVE_BROWSER_OBJECTS = new Set([
|
|
2019
|
+
"document",
|
|
2020
|
+
"window",
|
|
2021
|
+
"navigator",
|
|
2022
|
+
"localStorage",
|
|
2023
|
+
"sessionStorage"
|
|
2024
|
+
]);
|
|
2025
|
+
/**
|
|
2026
|
+
* Constructor names whose presence inside an `effect()` body signals
|
|
2027
|
+
* imperative API setup (observers, workers, network sockets) that
|
|
2028
|
+
* should run from `onMount` — not synchronously per-instance at
|
|
2029
|
+
* component setup time. Observer registration and socket allocation
|
|
2030
|
+
* are unambiguously imperative and never tracked as reactive reads.
|
|
2031
|
+
*/
|
|
2032
|
+
const IMPERATIVE_CONSTRUCTORS = new Set([
|
|
2033
|
+
"IntersectionObserver",
|
|
2034
|
+
"ResizeObserver",
|
|
2035
|
+
"MutationObserver",
|
|
2036
|
+
"PerformanceObserver",
|
|
2037
|
+
"Worker",
|
|
2038
|
+
"SharedWorker",
|
|
2039
|
+
"WebSocket",
|
|
2040
|
+
"EventSource",
|
|
2041
|
+
"BroadcastChannel"
|
|
2042
|
+
]);
|
|
2043
|
+
/**
|
|
2044
|
+
* Returns true when `node` is an immediately-invoked function
|
|
2045
|
+
* expression — i.e. a `CallExpression` whose callee is a function
|
|
2046
|
+
* literal: `(() => { ... })()` or `(function () { ... })()`. The body
|
|
2047
|
+
* runs synchronously at the call site, so for our purposes it should
|
|
2048
|
+
* be walked even though it's structurally a "nested function".
|
|
2049
|
+
*
|
|
2050
|
+
* Parenthesized callees (`(arrow)()`) come through as
|
|
2051
|
+
* `ParenthesizedExpression` wrapping the function — unwrap one level.
|
|
2052
|
+
*/
|
|
2053
|
+
function isIIFE(node) {
|
|
2054
|
+
if (!node || node.type !== "CallExpression") return false;
|
|
2055
|
+
let callee = node.callee;
|
|
2056
|
+
if (callee?.type === "ParenthesizedExpression") callee = callee.expression;
|
|
2057
|
+
return callee?.type === "ArrowFunctionExpression" || callee?.type === "FunctionExpression";
|
|
2058
|
+
}
|
|
2059
|
+
/**
|
|
2060
|
+
* Walk the effect callback body and look for imperative patterns.
|
|
2061
|
+
* Returns the first matching node + a short label describing what was
|
|
2062
|
+
* found, or null when the body is pure reactive tracking.
|
|
2063
|
+
*
|
|
2064
|
+
* Stops at nested function boundaries — code inside a nested function
|
|
2065
|
+
* (e.g. an event handler the effect attaches) is deferred-execution
|
|
2066
|
+
* and doesn't run synchronously at effect setup. The exception is
|
|
2067
|
+
* IIFE callees: those run at the call site, so we descend into them.
|
|
2068
|
+
*/
|
|
2069
|
+
function findImperativePattern(node, insideIIFE = false) {
|
|
2070
|
+
if (!node || typeof node !== "object") return null;
|
|
2071
|
+
if (!insideIIFE && (node.type === "FunctionExpression" || node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression")) return null;
|
|
2072
|
+
if (node.type === "AwaitExpression") return {
|
|
2073
|
+
node,
|
|
2074
|
+
label: "`await` (async work)"
|
|
2075
|
+
};
|
|
2076
|
+
if (node.type === "NewExpression") {
|
|
2077
|
+
const callee = node.callee;
|
|
2078
|
+
if (callee?.type === "Identifier" && IMPERATIVE_CONSTRUCTORS.has(callee.name)) return {
|
|
2079
|
+
node,
|
|
2080
|
+
label: `\`new ${callee.name}(...)\``
|
|
2081
|
+
};
|
|
2082
|
+
}
|
|
2083
|
+
if (node.type === "CallExpression") {
|
|
2084
|
+
const callee = node.callee;
|
|
2085
|
+
if (callee?.type === "Identifier" && IMPERATIVE_GLOBAL_CALLS.has(callee.name)) return {
|
|
2086
|
+
node,
|
|
2087
|
+
label: `\`${callee.name}(...)\``
|
|
2088
|
+
};
|
|
2089
|
+
if (callee?.type === "MemberExpression" && callee.property?.type === "Identifier") {
|
|
2090
|
+
const method = callee.property.name;
|
|
2091
|
+
if (IMPERATIVE_MEMBER_METHODS.has(method)) return {
|
|
2092
|
+
node,
|
|
2093
|
+
label: `\`.${method}(...)\``
|
|
2094
|
+
};
|
|
2095
|
+
if (method === "then" || method === "catch" || method === "finally") return {
|
|
2096
|
+
node,
|
|
2097
|
+
label: `\`.${method}(...)\` (Promise chain)`
|
|
2098
|
+
};
|
|
2099
|
+
const obj = callee.object;
|
|
2100
|
+
if (obj?.type === "Identifier" && IMPERATIVE_BROWSER_OBJECTS.has(obj.name)) return {
|
|
2101
|
+
node,
|
|
2102
|
+
label: `\`${obj.name}.${method}(...)\``
|
|
2103
|
+
};
|
|
2104
|
+
}
|
|
2105
|
+
if (isIIFE(node)) {
|
|
2106
|
+
let calleeFn = callee;
|
|
2107
|
+
if (calleeFn?.type === "ParenthesizedExpression") calleeFn = calleeFn.expression;
|
|
2108
|
+
const body = calleeFn?.body;
|
|
2109
|
+
if (body) {
|
|
2110
|
+
const found = findImperativePattern(body, true);
|
|
2111
|
+
if (found) return found;
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
if (node.type === "MemberExpression" && node.object?.type === "Identifier" && IMPERATIVE_BROWSER_OBJECTS.has(node.object.name) && node.property?.type === "Identifier") return {
|
|
2116
|
+
node,
|
|
2117
|
+
label: `\`${node.object.name}.${node.property.name}\``
|
|
2118
|
+
};
|
|
2119
|
+
for (const key in node) {
|
|
2120
|
+
if (key === "parent" || key === "loc" || key === "range" || key === "type") continue;
|
|
2121
|
+
const value = node[key];
|
|
2122
|
+
if (Array.isArray(value)) for (const child of value) {
|
|
2123
|
+
const found = findImperativePattern(child, false);
|
|
2124
|
+
if (found) return found;
|
|
2125
|
+
}
|
|
2126
|
+
else if (value && typeof value === "object") {
|
|
2127
|
+
const found = findImperativePattern(value, false);
|
|
2128
|
+
if (found) return found;
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
return null;
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* Safe wrapper names — `effect()` calls inside these don't fire
|
|
2135
|
+
* synchronously at component setup, so imperative work in their
|
|
2136
|
+
* callbacks is fine.
|
|
2137
|
+
*
|
|
2138
|
+
* `onMount` / `onUnmount` / `onCleanup` — explicit lifecycle hooks.
|
|
2139
|
+
* `renderEffect` — runs after mount, similar lifecycle.
|
|
2140
|
+
*
|
|
2141
|
+
* `effect` is intentionally NOT in this set — the rule's whole purpose
|
|
2142
|
+
* is to walk an effect's body. A nested effect inside another effect
|
|
2143
|
+
* is a separate problem (`no-nested-effect`), not this rule's concern.
|
|
2144
|
+
*/
|
|
2145
|
+
const SAFE_WRAPPER_NAMES = new Set([
|
|
2146
|
+
"onMount",
|
|
2147
|
+
"onUnmount",
|
|
2148
|
+
"onCleanup",
|
|
2149
|
+
"renderEffect"
|
|
2150
|
+
]);
|
|
2151
|
+
const noImperativeEffectOnCreate = {
|
|
2152
|
+
meta: {
|
|
2153
|
+
id: "pyreon/no-imperative-effect-on-create",
|
|
2154
|
+
category: "lifecycle",
|
|
2155
|
+
description: "Flag `effect()` calls at component body level whose callback does imperative work (DOM access, async/IO, addEventListener, setTimeout) — that work belongs in `onMount`, not in a per-instance reactive effect.",
|
|
2156
|
+
severity: "warn",
|
|
2157
|
+
fixable: false,
|
|
2158
|
+
schema: { exemptPaths: "string[]" }
|
|
2159
|
+
},
|
|
2160
|
+
create(context) {
|
|
2161
|
+
if (isPathExempt(context)) return {};
|
|
2162
|
+
let safeWrapperDepth = 0;
|
|
2163
|
+
return {
|
|
2164
|
+
CallExpression(node) {
|
|
2165
|
+
const callee = node.callee;
|
|
2166
|
+
if (callee?.type === "Identifier") {
|
|
2167
|
+
if (SAFE_WRAPPER_NAMES.has(callee.name)) safeWrapperDepth++;
|
|
2168
|
+
}
|
|
2169
|
+
if (safeWrapperDepth > 0) return;
|
|
2170
|
+
if (!isCallTo(node, "effect")) return;
|
|
2171
|
+
const args = node.arguments;
|
|
2172
|
+
if (!args || args.length === 0) return;
|
|
2173
|
+
const fn = args[0];
|
|
2174
|
+
if (!fn) return;
|
|
2175
|
+
let body = null;
|
|
2176
|
+
if (fn.type === "ArrowFunctionExpression" || fn.type === "FunctionExpression") body = fn.body;
|
|
2177
|
+
if (!body) return;
|
|
2178
|
+
const found = findImperativePattern(body);
|
|
2179
|
+
if (!found) return;
|
|
2180
|
+
context.report({
|
|
2181
|
+
message: `\`effect()\` at component body level contains ${found.label} — imperative work belongs in \`onMount\`. Pyreon's \`effect()\` runs synchronously per instance during component setup; per-instance imperative work (DOM access, IO, scheduling) accumulates O(N) at mount under load (cf. PR #268). Wrap the imperative call in \`onMount(() => { ... })\` and keep \`effect()\` for pure signal-tracking subscriptions.`,
|
|
2182
|
+
span: getSpan(node)
|
|
2183
|
+
});
|
|
2184
|
+
},
|
|
2185
|
+
"CallExpression:exit"(node) {
|
|
2186
|
+
const callee = node.callee;
|
|
2187
|
+
if (callee?.type === "Identifier" && SAFE_WRAPPER_NAMES.has(callee.name)) safeWrapperDepth--;
|
|
2188
|
+
}
|
|
2189
|
+
};
|
|
2190
|
+
}
|
|
2191
|
+
};
|
|
2192
|
+
|
|
1839
2193
|
//#endregion
|
|
1840
2194
|
//#region src/rules/lifecycle/no-missing-cleanup.ts
|
|
1841
2195
|
const NEEDS_CLEANUP = new Set(["setInterval", "addEventListener"]);
|
|
@@ -2023,6 +2377,75 @@ const preferShowOverDisplay = {
|
|
|
2023
2377
|
}
|
|
2024
2378
|
};
|
|
2025
2379
|
|
|
2380
|
+
//#endregion
|
|
2381
|
+
//#region src/rules/reactivity/no-async-effect.ts
|
|
2382
|
+
/**
|
|
2383
|
+
* Disallow async functions passed to `effect()` / `renderEffect()` /
|
|
2384
|
+
* `computed()` (audit bug #1).
|
|
2385
|
+
*
|
|
2386
|
+
* The reactivity tracking context is the SYNCHRONOUS frame around the
|
|
2387
|
+
* callback's top half. Anything after the first `await` runs detached,
|
|
2388
|
+
* so signal reads on the back side aren't tracked and the
|
|
2389
|
+
* effect/computed won't re-run when those signals change. Common
|
|
2390
|
+
* foot-gun:
|
|
2391
|
+
*
|
|
2392
|
+
* effect(async () => {
|
|
2393
|
+
* const id = userId() // tracked ✓
|
|
2394
|
+
* const data = await fetch(...) // boundary
|
|
2395
|
+
* const name = profile() // NOT tracked ✗ — runs once, never again
|
|
2396
|
+
* setName(name)
|
|
2397
|
+
* })
|
|
2398
|
+
*
|
|
2399
|
+
* `computed(async () => …)` is even worse: the computed's value type
|
|
2400
|
+
* becomes `Computed<Promise<T>>`, which silently breaks every consumer
|
|
2401
|
+
* that expects `Computed<T>`. There's no scenario where async makes
|
|
2402
|
+
* sense for a computed.
|
|
2403
|
+
*
|
|
2404
|
+
* The runtime emits a matching dev-mode console.warn for each call
|
|
2405
|
+
* shape (see `packages/core/reactivity/src/effect.ts` and
|
|
2406
|
+
* `computed.ts`); this lint rule surfaces the warning earlier in the
|
|
2407
|
+
* editor / CI loop, before the code even runs.
|
|
2408
|
+
*
|
|
2409
|
+
* Mitigation patterns:
|
|
2410
|
+
* - Read all tracked signals BEFORE any await, then `await` last.
|
|
2411
|
+
* - Use `watch(source, async (val) => …)` — the source is tracked
|
|
2412
|
+
* synchronously; the async callback runs on changes without
|
|
2413
|
+
* needing tracking continuity.
|
|
2414
|
+
* - Split into two effects: one synchronous (track + dispatch), one
|
|
2415
|
+
* async via the dispatch.
|
|
2416
|
+
* - For async derived state, use `createResource` or a
|
|
2417
|
+
* `signal<Promise<T>>` + `effect` pattern, NOT `computed`.
|
|
2418
|
+
*/
|
|
2419
|
+
const REACTIVE_PRIMITIVES = [
|
|
2420
|
+
"effect",
|
|
2421
|
+
"renderEffect",
|
|
2422
|
+
"computed"
|
|
2423
|
+
];
|
|
2424
|
+
const noAsyncEffect = {
|
|
2425
|
+
meta: {
|
|
2426
|
+
id: "pyreon/no-async-effect",
|
|
2427
|
+
category: "reactivity",
|
|
2428
|
+
description: "Disallow async functions in `effect()` / `renderEffect()` / `computed()` — signal reads after the first await are not tracked.",
|
|
2429
|
+
severity: "error",
|
|
2430
|
+
fixable: false
|
|
2431
|
+
},
|
|
2432
|
+
create(context) {
|
|
2433
|
+
return { CallExpression(node) {
|
|
2434
|
+
const calleeName = REACTIVE_PRIMITIVES.find((n) => isCallTo(node, n));
|
|
2435
|
+
if (!calleeName) return;
|
|
2436
|
+
const arg = node.arguments?.[0];
|
|
2437
|
+
if (!arg) return;
|
|
2438
|
+
if ((arg.type === "ArrowFunctionExpression" || arg.type === "FunctionExpression") && arg.async === true) {
|
|
2439
|
+
const remediation = calleeName === "computed" ? "Use `createResource` for async-derived state, or compute synchronously over a signal that holds the awaited value." : "Read all tracked signals before any await, or use `watch(source, asyncCb)` for async-in-callback patterns.";
|
|
2440
|
+
context.report({
|
|
2441
|
+
message: `${calleeName}() callback is async — signal reads after the first \`await\` are NOT tracked. ${remediation}`,
|
|
2442
|
+
span: getSpan(arg)
|
|
2443
|
+
});
|
|
2444
|
+
}
|
|
2445
|
+
} };
|
|
2446
|
+
}
|
|
2447
|
+
};
|
|
2448
|
+
|
|
2026
2449
|
//#endregion
|
|
2027
2450
|
//#region src/rules/reactivity/no-bare-signal-in-jsx.ts
|
|
2028
2451
|
const SKIP_NAMES = new Set([
|
|
@@ -2209,6 +2632,60 @@ const noPeekInTracked = {
|
|
|
2209
2632
|
}
|
|
2210
2633
|
};
|
|
2211
2634
|
|
|
2635
|
+
//#endregion
|
|
2636
|
+
//#region src/rules/reactivity/no-signal-call-write.ts
|
|
2637
|
+
/**
|
|
2638
|
+
* Mirrors the D1 MCP detector (`signal-write-as-call`) at lint time so
|
|
2639
|
+
* editors flag `sig(value)` write attempts as the user types them.
|
|
2640
|
+
*
|
|
2641
|
+
* Bindings are collected in a single top-down pass: oxc visits
|
|
2642
|
+
* VariableDeclaration top-down before nested function bodies, and `const`
|
|
2643
|
+
* is in the TDZ before declaration — so a use site never precedes its
|
|
2644
|
+
* binding's visitor. Scope-blind on purpose: shadowing a signal name
|
|
2645
|
+
* with a non-signal in a nested scope is itself unusual, and the
|
|
2646
|
+
* diagnostic points at the exact call so a human can dismiss the rare
|
|
2647
|
+
* false positive.
|
|
2648
|
+
*
|
|
2649
|
+
* Only `const` declarations qualify — `let`/`var` may be reassigned to a
|
|
2650
|
+
* non-signal value, so a use-site call wouldn't be a reliable
|
|
2651
|
+
* signal-write.
|
|
2652
|
+
*/
|
|
2653
|
+
const noSignalCallWrite = {
|
|
2654
|
+
meta: {
|
|
2655
|
+
id: "pyreon/no-signal-call-write",
|
|
2656
|
+
category: "reactivity",
|
|
2657
|
+
description: "Disallow `sig(value)` write attempts on signal/computed bindings — `signal()` is the read-only callable. Use `sig.set(value)` or `sig.update(fn)`.",
|
|
2658
|
+
severity: "error",
|
|
2659
|
+
fixable: false
|
|
2660
|
+
},
|
|
2661
|
+
create(context) {
|
|
2662
|
+
const bindings = /* @__PURE__ */ new Set();
|
|
2663
|
+
return {
|
|
2664
|
+
VariableDeclaration(node) {
|
|
2665
|
+
if (node.kind !== "const") return;
|
|
2666
|
+
for (const decl of node.declarations ?? []) {
|
|
2667
|
+
if (decl?.type !== "VariableDeclarator") continue;
|
|
2668
|
+
if (decl.id?.type !== "Identifier") continue;
|
|
2669
|
+
const init = decl.init;
|
|
2670
|
+
if (!init) continue;
|
|
2671
|
+
if (!isCallTo(init, "signal") && !isCallTo(init, "computed")) continue;
|
|
2672
|
+
bindings.add(decl.id.name);
|
|
2673
|
+
}
|
|
2674
|
+
},
|
|
2675
|
+
CallExpression(node) {
|
|
2676
|
+
const callee = node.callee;
|
|
2677
|
+
if (!callee || callee.type !== "Identifier") return;
|
|
2678
|
+
if (!bindings.has(callee.name)) return;
|
|
2679
|
+
if (!node.arguments || node.arguments.length === 0) return;
|
|
2680
|
+
context.report({
|
|
2681
|
+
message: `\`${callee.name}(value)\` does NOT write the signal — \`signal()\` is the read-only callable surface and ignores its arguments. Use \`${callee.name}.set(value)\` or \`${callee.name}.update((prev) => …)\`.`,
|
|
2682
|
+
span: getSpan(node)
|
|
2683
|
+
});
|
|
2684
|
+
}
|
|
2685
|
+
};
|
|
2686
|
+
}
|
|
2687
|
+
};
|
|
2688
|
+
|
|
2212
2689
|
//#endregion
|
|
2213
2690
|
//#region src/rules/reactivity/no-signal-in-loop.ts
|
|
2214
2691
|
const noSignalInLoop = {
|
|
@@ -2460,6 +2937,99 @@ const preferComputed = {
|
|
|
2460
2937
|
}
|
|
2461
2938
|
};
|
|
2462
2939
|
|
|
2940
|
+
//#endregion
|
|
2941
|
+
//#region src/rules/reactivity/storage-signal-v-forwarding.ts
|
|
2942
|
+
function isDirectDelegation(rhs) {
|
|
2943
|
+
if (!rhs) return false;
|
|
2944
|
+
if (rhs.type === "MemberExpression" && rhs.property?.name === "direct") return true;
|
|
2945
|
+
if (rhs.type === "ArrowFunctionExpression" || rhs.type === "FunctionExpression") {
|
|
2946
|
+
const body = rhs.body;
|
|
2947
|
+
if (!body) return false;
|
|
2948
|
+
if (body.type !== "BlockStatement") return isDirectCall(body);
|
|
2949
|
+
const stmts = body.body;
|
|
2950
|
+
if (!stmts || stmts.length !== 1) return false;
|
|
2951
|
+
const stmt = stmts[0];
|
|
2952
|
+
if (stmt.type !== "ReturnStatement") return false;
|
|
2953
|
+
return isDirectCall(stmt.argument);
|
|
2954
|
+
}
|
|
2955
|
+
return false;
|
|
2956
|
+
}
|
|
2957
|
+
function isDirectCall(expr) {
|
|
2958
|
+
if (!expr || expr.type !== "CallExpression") return false;
|
|
2959
|
+
const callee = expr.callee;
|
|
2960
|
+
return Boolean(callee && callee.type === "MemberExpression" && callee.property?.name === "direct");
|
|
2961
|
+
}
|
|
2962
|
+
function getStringLiteralValue(node) {
|
|
2963
|
+
if (!node) return null;
|
|
2964
|
+
if (node.type === "Literal" && typeof node.value === "string") return node.value;
|
|
2965
|
+
if (node.type === "StringLiteral" && typeof node.value === "string") return node.value;
|
|
2966
|
+
return null;
|
|
2967
|
+
}
|
|
2968
|
+
const storageSignalVForwarding = {
|
|
2969
|
+
meta: {
|
|
2970
|
+
id: "pyreon/storage-signal-v-forwarding",
|
|
2971
|
+
category: "reactivity",
|
|
2972
|
+
description: "Signal-wrapper callables delegating `.direct` to a base signal must also forward the internal `_v` field. Without forwarding, the compiler-emitted `_bindText` fast path reads `undefined` and renders empty text post-hydration.",
|
|
2973
|
+
severity: "error",
|
|
2974
|
+
fixable: false
|
|
2975
|
+
},
|
|
2976
|
+
create(context) {
|
|
2977
|
+
const stack = [];
|
|
2978
|
+
const enter = () => {
|
|
2979
|
+
stack.push({
|
|
2980
|
+
directAssigns: /* @__PURE__ */ new Map(),
|
|
2981
|
+
vForwards: /* @__PURE__ */ new Set()
|
|
2982
|
+
});
|
|
2983
|
+
};
|
|
2984
|
+
const exit = () => {
|
|
2985
|
+
const scope = stack.pop();
|
|
2986
|
+
if (!scope) return;
|
|
2987
|
+
for (const [name, node] of scope.directAssigns) {
|
|
2988
|
+
if (scope.vForwards.has(name)) continue;
|
|
2989
|
+
context.report({
|
|
2990
|
+
message: `Signal wrapper '${name}' delegates \`.direct\` to a base signal but does not forward \`_v\`. The compiler-emitted \`_bindText\` fast path reads \`${name}._v\` directly — without forwarding, the binding writes \`''\` on initial render AND every subscriber notification, even after \`.set()\` calls. Add: \`Object.defineProperty(${name}, '_v', { get: () => sig._v, configurable: true })\` in the same scope. Reference: \`packages/fundamentals/storage/src/local.ts:createStorageSignal\` for the canonical shape.`,
|
|
2991
|
+
span: getSpan(node)
|
|
2992
|
+
});
|
|
2993
|
+
}
|
|
2994
|
+
};
|
|
2995
|
+
return {
|
|
2996
|
+
Program: enter,
|
|
2997
|
+
"Program:exit": exit,
|
|
2998
|
+
FunctionDeclaration: enter,
|
|
2999
|
+
"FunctionDeclaration:exit": exit,
|
|
3000
|
+
FunctionExpression: enter,
|
|
3001
|
+
"FunctionExpression:exit": exit,
|
|
3002
|
+
ArrowFunctionExpression: enter,
|
|
3003
|
+
"ArrowFunctionExpression:exit": exit,
|
|
3004
|
+
AssignmentExpression(node) {
|
|
3005
|
+
const scope = stack[stack.length - 1];
|
|
3006
|
+
if (!scope) return;
|
|
3007
|
+
const left = node.left;
|
|
3008
|
+
if (left?.type !== "MemberExpression") return;
|
|
3009
|
+
if (left.object?.type !== "Identifier") return;
|
|
3010
|
+
const objName = left.object.name;
|
|
3011
|
+
const propName = left.property?.name ?? getStringLiteralValue(left.property);
|
|
3012
|
+
if (propName === "direct" && isDirectDelegation(node.right)) scope.directAssigns.set(objName, node);
|
|
3013
|
+
else if (propName === "_v") scope.vForwards.add(objName);
|
|
3014
|
+
},
|
|
3015
|
+
CallExpression(node) {
|
|
3016
|
+
const scope = stack[stack.length - 1];
|
|
3017
|
+
if (!scope) return;
|
|
3018
|
+
const callee = node.callee;
|
|
3019
|
+
if (!callee || callee.type !== "MemberExpression") return;
|
|
3020
|
+
if (callee.object?.type !== "Identifier" || callee.object.name !== "Object") return;
|
|
3021
|
+
if (callee.property?.name !== "defineProperty") return;
|
|
3022
|
+
const args = node.arguments;
|
|
3023
|
+
if (!args || args.length < 2) return;
|
|
3024
|
+
const target = args[0];
|
|
3025
|
+
if (target?.type !== "Identifier") return;
|
|
3026
|
+
if (getStringLiteralValue(args[1]) !== "_v") return;
|
|
3027
|
+
scope.vForwards.add(target.name);
|
|
3028
|
+
}
|
|
3029
|
+
};
|
|
3030
|
+
}
|
|
3031
|
+
};
|
|
3032
|
+
|
|
2463
3033
|
//#endregion
|
|
2464
3034
|
//#region src/rules/router/no-href-navigation.ts
|
|
2465
3035
|
const EXTERNAL_PREFIXES = [
|
|
@@ -2701,6 +3271,151 @@ function isPathComparison(node) {
|
|
|
2701
3271
|
return false;
|
|
2702
3272
|
}
|
|
2703
3273
|
|
|
3274
|
+
//#endregion
|
|
3275
|
+
//#region src/rules/ssg/invalid-loader-export.ts
|
|
3276
|
+
const ROUTES_PATH_RE$2 = /[/\\]routes[/\\]/;
|
|
3277
|
+
function isLikelyCallable(node) {
|
|
3278
|
+
if (!node) return false;
|
|
3279
|
+
if (node.type === "ArrowFunctionExpression") return true;
|
|
3280
|
+
if (node.type === "FunctionExpression") return true;
|
|
3281
|
+
if (node.type === "Identifier") return true;
|
|
3282
|
+
if (node.type === "CallExpression") return true;
|
|
3283
|
+
if (node.type === "MemberExpression") return true;
|
|
3284
|
+
if (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression") return isLikelyCallable(node.expression);
|
|
3285
|
+
return false;
|
|
3286
|
+
}
|
|
3287
|
+
const invalidLoaderExport = {
|
|
3288
|
+
meta: {
|
|
3289
|
+
id: "pyreon/invalid-loader-export",
|
|
3290
|
+
category: "ssg",
|
|
3291
|
+
description: "`export const loader` must be a function — non-callable exports crash the SSR runtime with `loader is not a function`.",
|
|
3292
|
+
severity: "error",
|
|
3293
|
+
fixable: false
|
|
3294
|
+
},
|
|
3295
|
+
create(context) {
|
|
3296
|
+
const filePath = context.getFilePath();
|
|
3297
|
+
if (!ROUTES_PATH_RE$2.test(filePath)) return {};
|
|
3298
|
+
return { ExportNamedDeclaration(node) {
|
|
3299
|
+
const decl = node.declaration;
|
|
3300
|
+
if (!decl) return;
|
|
3301
|
+
if (decl.type !== "VariableDeclaration") return;
|
|
3302
|
+
for (const declarator of decl.declarations ?? []) {
|
|
3303
|
+
if (declarator.type !== "VariableDeclarator") continue;
|
|
3304
|
+
const id = declarator.id;
|
|
3305
|
+
if (id?.type !== "Identifier" || id.name !== "loader") continue;
|
|
3306
|
+
const init = declarator.init;
|
|
3307
|
+
if (!init) continue;
|
|
3308
|
+
if (isLikelyCallable(init)) continue;
|
|
3309
|
+
context.report({
|
|
3310
|
+
message: "`export const loader` must be a function (arrow, function expression, or identifier reference). Got a non-callable expression — the SSR runtime will crash with `TypeError: loader is not a function`. If you meant to export static data, use `export const meta = { ... }` instead.",
|
|
3311
|
+
span: getSpan(init)
|
|
3312
|
+
});
|
|
3313
|
+
}
|
|
3314
|
+
} };
|
|
3315
|
+
}
|
|
3316
|
+
};
|
|
3317
|
+
|
|
3318
|
+
//#endregion
|
|
3319
|
+
//#region src/rules/ssg/missing-get-static-paths.ts
|
|
3320
|
+
const ROUTES_PATH_RE$1 = /[/\\]routes[/\\]/;
|
|
3321
|
+
const API_PATH_RE = /[/\\]routes[/\\]api[/\\]/;
|
|
3322
|
+
const DYNAMIC_FILENAME_RE = /\[.+\]\.(tsx?|jsx?)$/;
|
|
3323
|
+
const SPECIAL_ROUTE_RE = /[/\\]_(layout|error|loading|404|not-found)\./;
|
|
3324
|
+
const missingGetStaticPaths = {
|
|
3325
|
+
meta: {
|
|
3326
|
+
id: "pyreon/missing-get-static-paths",
|
|
3327
|
+
category: "ssg",
|
|
3328
|
+
description: "Dynamic route files (`[id].tsx`, `[...slug].tsx`) should export `getStaticPaths` — under `mode: \"ssg\"` the SSG plugin silently skips routes without it.",
|
|
3329
|
+
severity: "warn",
|
|
3330
|
+
fixable: false
|
|
3331
|
+
},
|
|
3332
|
+
create(context) {
|
|
3333
|
+
const filePath = context.getFilePath();
|
|
3334
|
+
if (!ROUTES_PATH_RE$1.test(filePath)) return {};
|
|
3335
|
+
if (API_PATH_RE.test(filePath)) return {};
|
|
3336
|
+
if (!DYNAMIC_FILENAME_RE.test(filePath)) return {};
|
|
3337
|
+
if (SPECIAL_ROUTE_RE.test(filePath)) return {};
|
|
3338
|
+
let hasGetStaticPaths = false;
|
|
3339
|
+
let hasDefaultExport = false;
|
|
3340
|
+
let programSpan = null;
|
|
3341
|
+
return {
|
|
3342
|
+
Program(node) {
|
|
3343
|
+
programSpan = {
|
|
3344
|
+
start: node.start ?? 0,
|
|
3345
|
+
end: node.end ?? 0
|
|
3346
|
+
};
|
|
3347
|
+
},
|
|
3348
|
+
ExportNamedDeclaration(node) {
|
|
3349
|
+
const decl = node.declaration;
|
|
3350
|
+
if (!decl) return;
|
|
3351
|
+
if (decl.type === "VariableDeclaration") for (const declarator of decl.declarations ?? []) {
|
|
3352
|
+
if (declarator.type !== "VariableDeclarator") continue;
|
|
3353
|
+
const id = declarator.id;
|
|
3354
|
+
if (id?.type === "Identifier" && id.name === "getStaticPaths") hasGetStaticPaths = true;
|
|
3355
|
+
}
|
|
3356
|
+
else if (decl.type === "FunctionDeclaration") {
|
|
3357
|
+
if (decl.id?.name === "getStaticPaths") hasGetStaticPaths = true;
|
|
3358
|
+
}
|
|
3359
|
+
},
|
|
3360
|
+
ExportDefaultDeclaration() {
|
|
3361
|
+
hasDefaultExport = true;
|
|
3362
|
+
},
|
|
3363
|
+
"Program:exit"() {
|
|
3364
|
+
if (!hasDefaultExport) return;
|
|
3365
|
+
if (hasGetStaticPaths || !programSpan) return;
|
|
3366
|
+
context.report({
|
|
3367
|
+
message: "Dynamic route file is missing `export const getStaticPaths` — under `mode: \"ssg\"` the SSG plugin silently skips this route, so the dist won't contain prerendered HTML. Either add `export const getStaticPaths = () => [{ params: { ... } }, ...]` enumerating the concrete values, OR declare the route as runtime-only by switching to `mode: \"ssr\"` / `mode: \"isr\"`.",
|
|
3368
|
+
span: {
|
|
3369
|
+
start: programSpan.start,
|
|
3370
|
+
end: Math.min(programSpan.start + 1, programSpan.end)
|
|
3371
|
+
}
|
|
3372
|
+
});
|
|
3373
|
+
}
|
|
3374
|
+
};
|
|
3375
|
+
}
|
|
3376
|
+
};
|
|
3377
|
+
|
|
3378
|
+
//#endregion
|
|
3379
|
+
//#region src/rules/ssg/revalidate-not-pure-literal.ts
|
|
3380
|
+
const ROUTES_PATH_RE = /[/\\]routes[/\\]/;
|
|
3381
|
+
function isLiteralOk(node) {
|
|
3382
|
+
if (!node) return false;
|
|
3383
|
+
if (node.type === "Literal" && typeof node.value === "number") return true;
|
|
3384
|
+
if (node.type === "NumericLiteral" && typeof node.value === "number") return true;
|
|
3385
|
+
if (node.type === "Literal" && node.value === false) return true;
|
|
3386
|
+
if (node.type === "BooleanLiteral" && node.value === false) return true;
|
|
3387
|
+
return false;
|
|
3388
|
+
}
|
|
3389
|
+
const revalidateNotPureLiteral = {
|
|
3390
|
+
meta: {
|
|
3391
|
+
id: "pyreon/revalidate-not-pure-literal",
|
|
3392
|
+
category: "ssg",
|
|
3393
|
+
description: "`export const revalidate = X` must be a numeric literal or `false` — non-literal forms are silently dropped from the build-time ISR manifest (PR I limitation).",
|
|
3394
|
+
severity: "error",
|
|
3395
|
+
fixable: false
|
|
3396
|
+
},
|
|
3397
|
+
create(context) {
|
|
3398
|
+
const filePath = context.getFilePath();
|
|
3399
|
+
if (!ROUTES_PATH_RE.test(filePath)) return {};
|
|
3400
|
+
return { ExportNamedDeclaration(node) {
|
|
3401
|
+
const decl = node.declaration;
|
|
3402
|
+
if (!decl || decl.type !== "VariableDeclaration") return;
|
|
3403
|
+
for (const declarator of decl.declarations ?? []) {
|
|
3404
|
+
if (declarator.type !== "VariableDeclarator") continue;
|
|
3405
|
+
const id = declarator.id;
|
|
3406
|
+
if (id?.type !== "Identifier" || id.name !== "revalidate") continue;
|
|
3407
|
+
const init = declarator.init;
|
|
3408
|
+
if (!init) continue;
|
|
3409
|
+
if (isLiteralOk(init)) continue;
|
|
3410
|
+
context.report({
|
|
3411
|
+
message: "`export const revalidate` must be a numeric literal (e.g. `60`, `3600`) or `false` — non-literal expressions (variable references, math, function calls, template literals) are silently dropped from the build-time ISR manifest. Inline the value: `export const revalidate = 60`.",
|
|
3412
|
+
span: getSpan(init)
|
|
3413
|
+
});
|
|
3414
|
+
}
|
|
3415
|
+
} };
|
|
3416
|
+
}
|
|
3417
|
+
};
|
|
3418
|
+
|
|
2704
3419
|
//#endregion
|
|
2705
3420
|
//#region src/rules/ssr/no-mismatch-risk.ts
|
|
2706
3421
|
const noMismatchRisk = {
|
|
@@ -3291,6 +4006,7 @@ const preferCx = {
|
|
|
3291
4006
|
//#endregion
|
|
3292
4007
|
//#region src/rules/index.ts
|
|
3293
4008
|
const allRules = [
|
|
4009
|
+
noAsyncEffect,
|
|
3294
4010
|
noBareSignalInJsx,
|
|
3295
4011
|
noContextDestructure,
|
|
3296
4012
|
noSignalInLoop,
|
|
@@ -3301,6 +4017,8 @@ const allRules = [
|
|
|
3301
4017
|
preferComputed,
|
|
3302
4018
|
noEffectAssignment,
|
|
3303
4019
|
noSignalLeak,
|
|
4020
|
+
noSignalCallWrite,
|
|
4021
|
+
storageSignalVForwarding,
|
|
3304
4022
|
noMapInJsx,
|
|
3305
4023
|
useByNotKey,
|
|
3306
4024
|
noClassName,
|
|
@@ -3316,6 +4034,7 @@ const allRules = [
|
|
|
3316
4034
|
noMountInEffect,
|
|
3317
4035
|
noEffectInMount,
|
|
3318
4036
|
noDomInSetup,
|
|
4037
|
+
noImperativeEffectOnCreate,
|
|
3319
4038
|
noLargeForWithoutBy,
|
|
3320
4039
|
noEffectInFor,
|
|
3321
4040
|
noEagerImport,
|
|
@@ -3349,7 +4068,10 @@ const allRules = [
|
|
|
3349
4068
|
noHrefNavigation,
|
|
3350
4069
|
noImperativeNavigateInRender,
|
|
3351
4070
|
noMissingFallback,
|
|
3352
|
-
preferUseIsActive
|
|
4071
|
+
preferUseIsActive,
|
|
4072
|
+
invalidLoaderExport,
|
|
4073
|
+
missingGetStaticPaths,
|
|
4074
|
+
revalidateNotPureLiteral
|
|
3353
4075
|
];
|
|
3354
4076
|
|
|
3355
4077
|
//#endregion
|
|
@@ -3587,8 +4309,8 @@ function lintFile(filePath, sourceText, rules, config, cache, configDiagnosticsS
|
|
|
3587
4309
|
const [severity, options] = Array.isArray(entry) ? [entry[0], entry[1] ?? {}] : [entry, {}];
|
|
3588
4310
|
if (severity === "off") continue;
|
|
3589
4311
|
const cacheKey = `${rule.meta.id}::${JSON.stringify(options)}`;
|
|
3590
|
-
let
|
|
3591
|
-
if (!
|
|
4312
|
+
let validation = VALIDATION_CACHE.get(cacheKey);
|
|
4313
|
+
if (!validation) {
|
|
3592
4314
|
const { errors, warnings } = validateRuleOptions(rule, options);
|
|
3593
4315
|
const configDiags = [];
|
|
3594
4316
|
for (const message of warnings) configDiags.push({
|
|
@@ -3601,16 +4323,16 @@ function lintFile(filePath, sourceText, rules, config, cache, configDiagnosticsS
|
|
|
3601
4323
|
severity: "error",
|
|
3602
4324
|
message
|
|
3603
4325
|
});
|
|
3604
|
-
|
|
4326
|
+
validation = {
|
|
3605
4327
|
ok: errors.length === 0,
|
|
3606
4328
|
diagnostics: configDiags
|
|
3607
4329
|
};
|
|
3608
|
-
VALIDATION_CACHE.set(cacheKey,
|
|
4330
|
+
VALIDATION_CACHE.set(cacheKey, validation);
|
|
3609
4331
|
}
|
|
3610
|
-
if (
|
|
3611
|
-
for (const d of
|
|
3612
|
-
} else for (const d of
|
|
3613
|
-
if (!
|
|
4332
|
+
if (validation.diagnostics.length > 0) if (configDiagnosticsSink) {
|
|
4333
|
+
for (const d of validation.diagnostics) if (!configDiagnosticsSink.some((x) => x.ruleId === d.ruleId && x.message === d.message)) configDiagnosticsSink.push(d);
|
|
4334
|
+
} else for (const d of validation.diagnostics) (d.severity === "error" ? console.error : console.warn)(`[pyreon-lint] ${d.message}`);
|
|
4335
|
+
if (!validation.ok) continue;
|
|
3614
4336
|
const ctx = createRuleContext(rule, severity, options, diagnostics, lineIndex, sourceText, filePath);
|
|
3615
4337
|
allCallbacks.push(rule.create(ctx));
|
|
3616
4338
|
}
|