@fictjs/eslint-plugin 0.0.13 → 0.0.14
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/dist/index.cjs +12 -1
- package/dist/index.js +12 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -637,6 +637,12 @@ var isInConditional = (ancestors) => ancestors.some(
|
|
|
637
637
|
"LogicalExpression"
|
|
638
638
|
].includes(ancestor.type)
|
|
639
639
|
);
|
|
640
|
+
var isDirectStateDeclaration = (node, ancestors) => {
|
|
641
|
+
const parent = ancestors[ancestors.length - 1];
|
|
642
|
+
if (!parent || parent.type !== "VariableDeclarator") return false;
|
|
643
|
+
if (parent.init !== node) return false;
|
|
644
|
+
return parent.id?.type === "Identifier";
|
|
645
|
+
};
|
|
640
646
|
var rule8 = {
|
|
641
647
|
meta: {
|
|
642
648
|
type: "problem",
|
|
@@ -647,7 +653,8 @@ var rule8 = {
|
|
|
647
653
|
messages: {
|
|
648
654
|
moduleScope: "$state must be declared inside a component or hook function body (not at module scope).",
|
|
649
655
|
componentOnly: "$state should only be used inside a component function (PascalCase or JSX-returning) or a hook (useX).",
|
|
650
|
-
topLevel: "$state must be at the top level of the component or hook body (not inside conditionals or nested functions)."
|
|
656
|
+
topLevel: "$state must be at the top level of the component or hook body (not inside conditionals or nested functions).",
|
|
657
|
+
declarationOnly: "$state() must be assigned directly to a variable (e.g. let count = $state(0))."
|
|
651
658
|
},
|
|
652
659
|
schema: []
|
|
653
660
|
},
|
|
@@ -656,6 +663,10 @@ var rule8 = {
|
|
|
656
663
|
CallExpression(node) {
|
|
657
664
|
if (node.callee.type !== "Identifier" || node.callee.name !== "$state") return;
|
|
658
665
|
const ancestors = context.sourceCode.getAncestors(node);
|
|
666
|
+
if (!isDirectStateDeclaration(node, ancestors)) {
|
|
667
|
+
context.report({ node, messageId: "declarationOnly" });
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
659
670
|
const functionAncestors = ancestors.filter(
|
|
660
671
|
(ancestor) => ["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"].includes(
|
|
661
672
|
ancestor.type
|
package/dist/index.js
CHANGED
|
@@ -601,6 +601,12 @@ var isInConditional = (ancestors) => ancestors.some(
|
|
|
601
601
|
"LogicalExpression"
|
|
602
602
|
].includes(ancestor.type)
|
|
603
603
|
);
|
|
604
|
+
var isDirectStateDeclaration = (node, ancestors) => {
|
|
605
|
+
const parent = ancestors[ancestors.length - 1];
|
|
606
|
+
if (!parent || parent.type !== "VariableDeclarator") return false;
|
|
607
|
+
if (parent.init !== node) return false;
|
|
608
|
+
return parent.id?.type === "Identifier";
|
|
609
|
+
};
|
|
604
610
|
var rule8 = {
|
|
605
611
|
meta: {
|
|
606
612
|
type: "problem",
|
|
@@ -611,7 +617,8 @@ var rule8 = {
|
|
|
611
617
|
messages: {
|
|
612
618
|
moduleScope: "$state must be declared inside a component or hook function body (not at module scope).",
|
|
613
619
|
componentOnly: "$state should only be used inside a component function (PascalCase or JSX-returning) or a hook (useX).",
|
|
614
|
-
topLevel: "$state must be at the top level of the component or hook body (not inside conditionals or nested functions)."
|
|
620
|
+
topLevel: "$state must be at the top level of the component or hook body (not inside conditionals or nested functions).",
|
|
621
|
+
declarationOnly: "$state() must be assigned directly to a variable (e.g. let count = $state(0))."
|
|
615
622
|
},
|
|
616
623
|
schema: []
|
|
617
624
|
},
|
|
@@ -620,6 +627,10 @@ var rule8 = {
|
|
|
620
627
|
CallExpression(node) {
|
|
621
628
|
if (node.callee.type !== "Identifier" || node.callee.name !== "$state") return;
|
|
622
629
|
const ancestors = context.sourceCode.getAncestors(node);
|
|
630
|
+
if (!isDirectStateDeclaration(node, ancestors)) {
|
|
631
|
+
context.report({ node, messageId: "declarationOnly" });
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
623
634
|
const functionAncestors = ancestors.filter(
|
|
624
635
|
(ancestor) => ["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"].includes(
|
|
625
636
|
ancestor.type
|