Skip to content

Commit

Permalink
Fixed case with facory with enforce-store-naming-convention rule (#122)
Browse files Browse the repository at this point in the history
Release v0.9.1
  • Loading branch information
Lonli-Lokli authored Sep 13, 2022
1 parent e55a708 commit f2348df
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.9.1

- Fixed factory usage with `enforce-store-naming-convention`

## v0.9.0

- Add new rule `no-patronum-debug` ([PR #121](https://github.com/effector/eslint-plugin/pull/121) by @raidenmiro)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-effector",
"version": "0.9.0",
"version": "0.9.1",
"description": "Enforcing best practices for Effector",
"keywords": [
"eslint",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,22 @@ module.exports = {
// Store creation with method
const STORE_CREATION_METHODS = ["createStore", "restore", "combine"];
for (const method of STORE_CREATION_METHODS) {
const localMethod = importedFromEffector.get(method);
const localMethod = importedFromEffector.get(method);
if (!localMethod) {
continue;
}

const isEffectorStoreCreation = node.callee.name === localMethod;
if (!isEffectorStoreCreation) {
continue;
}

const parentNode = traverseParentByType(node, "VariableDeclarator", ["Program"]);
const parentNode = traverseParentByType(node, "VariableDeclarator", [
"Program",
]);

const resultSavedInVariable = parentNode.type === "VariableDeclarator";
const resultSavedInVariable =
parentNode?.type === "VariableDeclarator";
if (!resultSavedInVariable) {
continue;
}
Expand Down Expand Up @@ -116,7 +119,8 @@ module.exports = {
return;
}

const resultSavedInVariable = node.parent.type === "VariableDeclarator";
const resultSavedInVariable =
node.parent.type === "VariableDeclarator";

if (!resultSavedInVariable) {
return;
Expand All @@ -141,10 +145,12 @@ module.exports = {
if (
STORE_IN_DOMAIN_CREATION_METHODS.includes(node.callee?.property?.name)
) {
const parentNode = traverseParentByType(node, "VariableDeclarator", [
"Program",
]);

const parentNode = traverseParentByType(node, "VariableDeclarator", ["Program"]);

const resultSavedInVariable = parentNode.type === "VariableDeclarator";
const resultSavedInVariable =
parentNode.type === "VariableDeclarator";
if (!resultSavedInVariable) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ruleTester.run("effector/enforce-store-naming-convention-prefix.test", rule, {
"correct-examples-issue-23.js",
"correct-store-naming-with-handlers.js",
"correct-store-naming-in-domain-with-handlers.js",
"correct-factory.js",
]
.map(readExampleForTheRule)
.map((code) => ({ code })),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createStore } from "effector";

function createStoreEx(initial) {
return createStore(initial instanceof Function ? initial() : initial);
}

export { createStoreEx };

0 comments on commit f2348df

Please sign in to comment.