From 5f94ae2422592d8d38c99e3b7d19c1a97edad476 Mon Sep 17 00:00:00 2001 From: Igor Kamyshev Date: Fri, 10 Jun 2022 15:46:58 +0700 Subject: [PATCH] mandatory-UseEvent does not warn on effect stores --- .../correct-effect-store-via-useStore.tsx | 16 ++++++++++++++++ rules/mandatory-useEvent/mandatory-useEvent.js | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 rules/mandatory-useEvent/examples/correct-effect-store-via-useStore.tsx diff --git a/rules/mandatory-useEvent/examples/correct-effect-store-via-useStore.tsx b/rules/mandatory-useEvent/examples/correct-effect-store-via-useStore.tsx new file mode 100644 index 0000000..04fac80 --- /dev/null +++ b/rules/mandatory-useEvent/examples/correct-effect-store-via-useStore.tsx @@ -0,0 +1,16 @@ +import React from "react"; +import { useEvent, useStore } from "effector-react"; + +import { fetchFx } from "./model"; + +const Button: React.FC = () => { + const loading = useStore(fetchFx.pending); + + if (loading) { + return null; + } + + return ; +}; + +export { Button }; diff --git a/rules/mandatory-useEvent/mandatory-useEvent.js b/rules/mandatory-useEvent/mandatory-useEvent.js index 9ce9705..f4dac04 100644 --- a/rules/mandatory-useEvent/mandatory-useEvent.js +++ b/rules/mandatory-useEvent/mandatory-useEvent.js @@ -45,7 +45,7 @@ module.exports = { return; } - if (isInsideUseEventCall({ node, context })) { + if (isInsideEffectorHook({ node, context })) { return; } @@ -61,7 +61,7 @@ module.exports = { }, }; -function isInsideUseEventCall({ node, context }) { +function isInsideEffectorHook({ node, context }) { const calleeParentNode = traverseParentByType(node.parent, "CallExpression"); if (!calleeParentNode?.callee) return false; @@ -69,6 +69,6 @@ function isInsideUseEventCall({ node, context }) { return nodeTypeIs.effectorReactHook({ node: calleeParentNode.callee, context, - hook: ["useEvent", "useUnit"], + hook: ["useEvent", "useUnit", "useStore"], }); }