Skip to content

Commit

Permalink
Allow creating a Store in a property in `enforce-store-naming-conve…
Browse files Browse the repository at this point in the history
…ntion` (#159)

fix(enforce-store-naming-convention): support createStore in property
  • Loading branch information
kireevmp authored Mar 19, 2024
1 parent 21f4ea6 commit e3831f9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module.exports = {
}

const parentNode = traverseParentByType(node, "VariableDeclarator", {
stopOnTypes: ["Program", "BlockStatement"],
stopOnTypes: ["Program", "BlockStatement", "Property"],
});

const resultSavedInVariable =
Expand Down Expand Up @@ -153,7 +153,7 @@ module.exports = {
STORE_IN_DOMAIN_CREATION_METHODS.includes(node.callee?.property?.name)
) {
const parentNode = traverseParentByType(node, "VariableDeclarator", {
stopOnTypes: ["Program", "BlockStatement"],
stopOnTypes: ["Program", "BlockStatement", "Property"],
});

const resultSavedInVariable =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ ruleTester.run("effector/enforce-store-naming-convention-prefix.test", rule, {
"correct-examples-issue-23.js",
"correct-examples-issue-128.js",
"correct-examples-issue-136.js",
"correct-examples-issue-150.js",
"correct-examples-issue-158.js",
"correct-store-naming-property-domain.js",
"correct-store-naming-with-handlers.js",
"correct-store-naming-in-domain-with-handlers.js",
"correct-factory.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { attach, combine, createStore, createEffect } from "effector";

const testFx = attach({
source: createStore(0),
effect: createEffect(),
});

const combineFx = attach({
source: {
value: combine(),
},
effect: createEffect(),
});

const createStoreFx = attach({
source: {
value: createStore(0),
},
effect: createEffect(),
});

export { testFx, combineFx, createStoreFx };
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createStore } from "effector";

const arrow = ({ store = createStore(0) }) => {
return { store };
};

function declaration({ store = createStore(1) }) {
return { store };
}

export { arrow, declaration };
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createDomain } from "effector";
import { attach, createEffect } from "effector";

const domain = createDomain();
const effect = createEffect();

const storeFx = attach({
source: domain.store(0),
effect,
});

const createStoreFx = attach({
source: domain.createStore(0),
effect,
});

export { storeFx, createDomain };

0 comments on commit e3831f9

Please sign in to comment.