Skip to content

Commit e3831f9

Browse files
authored
Allow creating a Store in a property in enforce-store-naming-convention (#159)
fix(enforce-store-naming-convention): support createStore in property
1 parent 21f4ea6 commit e3831f9

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

rules/enforce-store-naming-convention/enforce-store-naming-convention.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ module.exports = {
9494
}
9595

9696
const parentNode = traverseParentByType(node, "VariableDeclarator", {
97-
stopOnTypes: ["Program", "BlockStatement"],
97+
stopOnTypes: ["Program", "BlockStatement", "Property"],
9898
});
9999

100100
const resultSavedInVariable =
@@ -153,7 +153,7 @@ module.exports = {
153153
STORE_IN_DOMAIN_CREATION_METHODS.includes(node.callee?.property?.name)
154154
) {
155155
const parentNode = traverseParentByType(node, "VariableDeclarator", {
156-
stopOnTypes: ["Program", "BlockStatement"],
156+
stopOnTypes: ["Program", "BlockStatement", "Property"],
157157
});
158158

159159
const resultSavedInVariable =

rules/enforce-store-naming-convention/prefix/enforce-store-naming-convention-prefix.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ ruleTester.run("effector/enforce-store-naming-convention-prefix.test", rule, {
2121
"correct-examples-issue-23.js",
2222
"correct-examples-issue-128.js",
2323
"correct-examples-issue-136.js",
24+
"correct-examples-issue-150.js",
25+
"correct-examples-issue-158.js",
26+
"correct-store-naming-property-domain.js",
2427
"correct-store-naming-with-handlers.js",
2528
"correct-store-naming-in-domain-with-handlers.js",
2629
"correct-factory.js",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { attach, combine, createStore, createEffect } from "effector";
2+
3+
const testFx = attach({
4+
source: createStore(0),
5+
effect: createEffect(),
6+
});
7+
8+
const combineFx = attach({
9+
source: {
10+
value: combine(),
11+
},
12+
effect: createEffect(),
13+
});
14+
15+
const createStoreFx = attach({
16+
source: {
17+
value: createStore(0),
18+
},
19+
effect: createEffect(),
20+
});
21+
22+
export { testFx, combineFx, createStoreFx };
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { createStore } from "effector";
2+
3+
const arrow = ({ store = createStore(0) }) => {
4+
return { store };
5+
};
6+
7+
function declaration({ store = createStore(1) }) {
8+
return { store };
9+
}
10+
11+
export { arrow, declaration };
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { createDomain } from "effector";
2+
import { attach, createEffect } from "effector";
3+
4+
const domain = createDomain();
5+
const effect = createEffect();
6+
7+
const storeFx = attach({
8+
source: domain.store(0),
9+
effect,
10+
});
11+
12+
const createStoreFx = attach({
13+
source: domain.createStore(0),
14+
effect,
15+
});
16+
17+
export { storeFx, createDomain };

0 commit comments

Comments
 (0)